Skip to content

Commit c26bc92

Browse files
committed
Fix ipv4 options parsing and bit numbering
RFC 5102 and its Errata[1] several times messed with a bit numbering. "Options are mapped to bits according to their option numbers. Option number X is mapped to bit X." But actually it's in inverted order. "A misunderstand arose as to whether bits were assigned in host order or network order - so clarify that the bits are assigned from the least significant to the most significant, ie right-to-left rather than left-to-right." That's about bit numbering in diagram. So final correct options mask is (from Errata 2944): 0 1 2 3 4 5 6 7 +------+------+------+------+------+------+------+------+ | | EXP | to be assigned by IANA | QS | UMP | ... +------+------+------+------+------+------+------+------+ 8 9 10 11 12 13 14 15 +------+------+------+------+------+------+------+------+ ... | DPS |NSAPA | SDB |RTRALT|ADDEXT| TR | EIP |IMITD | ... +------+------+------+------+------+------+------+------+ 16 17 18 19 20 21 22 23 +------+------+------+------+------+------+------+------+ ... |ENCODE| VISA | FINN | MTUR | MTUP | ZSU | SSR | SID | ... +------+------+------+------+------+------+------+------+ 24 25 26 27 28 29 30 31 +------+------+------+------+------+------+------+------+ ... | RR |CIPSO |E-SEC | TS | LSR | SEC | NOP | EOOL | +------+------+------+------+------+------+------+------+ Link: https://www.rfc-editor.org/errata/rfc5102 Fixes: f631ed5 ("IPv6 support, and IP options support for v9/IPFIX.") Signed-off-by: ABC <[email protected]>
1 parent 0561c72 commit c26bc92

File tree

1 file changed

+17
-47
lines changed

1 file changed

+17
-47
lines changed

ipt_NETFLOW.c

+17-47
Original file line numberDiff line numberDiff line change
@@ -4769,39 +4769,7 @@ static inline __u16 observed_hdrs(const __u8 currenthdr)
47694769
return SetXBit(3); /* Unknown header. */
47704770
}
47714771

4772-
/* http://www.iana.org/assignments/ip-parameters/ip-parameters.xhtml */
4773-
static const __u8 ip4_opt_table[] = {
4774-
[7] = 0, /* RR */ /* parsed manually because of 0 */
4775-
[134] = 1, /* CIPSO */
4776-
[133] = 2, /* E-SEC */
4777-
[68] = 3, /* TS */
4778-
[131] = 4, /* LSR */
4779-
[130] = 5, /* SEC */
4780-
[1] = 6, /* NOP */
4781-
[0] = 7, /* EOOL */
4782-
[15] = 8, /* ENCODE */
4783-
[142] = 9, /* VISA */
4784-
[205] = 10, /* FINN */
4785-
[12] = 11, /* MTUR */
4786-
[11] = 12, /* MTUP */
4787-
[10] = 13, /* ZSU */
4788-
[137] = 14, /* SSR */
4789-
[136] = 15, /* SID */
4790-
[151] = 16, /* DPS */
4791-
[150] = 17, /* NSAPA */
4792-
[149] = 18, /* SDB */
4793-
[147] = 19, /* ADDEXT */
4794-
[148] = 20, /* RTRALT */
4795-
[82] = 21, /* TR */
4796-
[145] = 22, /* EIP */
4797-
[144] = 23, /* IMITD */
4798-
[30] = 25, /* EXP */
4799-
[94] = 25, /* EXP */
4800-
[158] = 25, /* EXP */
4801-
[222] = 25, /* EXP */
4802-
[25] = 30, /* QS */
4803-
[152] = 31, /* UMP */
4804-
};
4772+
/* https://www.iana.org/assignments/ip-parameters/ip-parameters.xhtml */
48054773
/* Parse IPv4 Options array int ipv4Options IPFIX value. */
48064774
static inline __u32 ip4_options(const u_int8_t *p, const unsigned int optsize)
48074775
{
@@ -4810,20 +4778,22 @@ static inline __u32 ip4_options(const u_int8_t *p, const unsigned int optsize)
48104778

48114779
for (i = 0; likely(i < optsize); ) {
48124780
u_int8_t op = p[i++];
4813-
4814-
if (op == 7) /* RR: bit 0 */
4815-
ret |= 1;
4816-
else if (likely(op < ARRAY_SIZE(ip4_opt_table))) {
4817-
/* Btw, IANA doc is messed up in a crazy way:
4818-
* http://www.ietf.org/mail-archive/web/ipfix/current/msg06008.html (2011)
4819-
* I decided to follow IANA _text_ description from
4820-
* http://www.iana.org/assignments/ipfix/ipfix.xhtml (2013-09-18)
4821-
*
4822-
* Set proper bit for htonl later. */
4823-
if (ip4_opt_table[op])
4824-
ret |= 1 << (31 - ip4_opt_table[op]);
4825-
}
4826-
if (likely(i >= optsize || op == 0))
4781+
u_int8_t nn = op & 0x17; /* 5 bits option number */
4782+
4783+
/*
4784+
* "Note that for identifying an option not just the 5-bit Option
4785+
* Number, but all 8 bits of the Option Type need to match one
4786+
* of the IPv4 options specified at
4787+
* http://www.iana.org/assignments/ip-parameters.
4788+
*
4789+
* Options are mapped to bits according to their option numbers.
4790+
* Option number X is mapped to bit X." - In inverted order, see
4791+
* RFC 5102 Errata 2944.
4792+
*/
4793+
4794+
if (likely(nn < 32))
4795+
ret |= 1 << (31 - nn);
4796+
if (i >= optsize || op == 0) /* 0 is EOOL. */
48274797
break;
48284798
else if (unlikely(op == 1))
48294799
continue;

0 commit comments

Comments
 (0)