xdp/parsing_helpers: Check IP protocol version when parsing

Add a check that the protocol version field matches the expected value when
parsing IPv4 and IPv6 headers. This makes it possible to parse an IP header
that we don't know the version of (such as on interfaces that don't use an
Ethernet header).

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
This commit is contained in:
Toke Høiland-Jørgensen
2021-06-18 00:54:57 +02:00
parent 942f028cce
commit dabfe929ae

View File

@@ -184,6 +184,9 @@ static __always_inline int parse_ip6hdr(struct hdr_cursor *nh,
if (ip6h + 1 > data_end)
return -1;
if (ip6h->version != 6)
return -1;
nh->pos = ip6h + 1;
*ip6hdr = ip6h;
@@ -200,6 +203,9 @@ static __always_inline int parse_iphdr(struct hdr_cursor *nh,
if (iph + 1 > data_end)
return -1;
if (iph->version != 4)
return -1;
hdrsize = iph->ihl * 4;
/* Sanity check packet field is valid */
if(hdrsize < sizeof(*iph))