mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
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:
@@ -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))
|
||||
|
Reference in New Issue
Block a user