diff --git a/examples/networking/http_filter/http-parse-complete.c b/examples/networking/http_filter/http-parse-complete.c index 61bb0f0a3a55..dff16b940f02 100644 --- a/examples/networking/http_filter/http-parse-complete.c +++ b/examples/networking/http_filter/http-parse-complete.c @@ -56,6 +56,19 @@ int http_filter(struct __sk_buff *skb) { struct Key key; struct Leaf zero = {0}; + //calculate ip header length + //value to multiply * 4 + //e.g. ip->hlen = 5 ; IP Header Length = 5 x 4 byte = 20 byte + ip_header_length = ip->hlen << 2; //SHL 2 -> *4 multiply + + //check ip header length against minimum + if (ip_header_length < sizeof(*ip)) { + goto DROP; + } + + //shift cursor forward for dynamic ip header size + void *_ = cursor_advance(cursor, (ip_header_length-sizeof(*ip))); + struct tcp_t *tcp = cursor_advance(cursor, sizeof(*tcp)); //retrieve ip src/dest and port src/dest of current packet @@ -65,11 +78,6 @@ int http_filter(struct __sk_buff *skb) { key.dst_port = tcp->dst_port; key.src_port = tcp->src_port; - //calculate ip header length - //value to multiply * 4 - //e.g. ip->hlen = 5 ; IP Header Length = 5 x 4 byte = 20 byte - ip_header_length = ip->hlen << 2; //SHL 2 -> *4 multiply - //calculate tcp header length //value to multiply *4 //e.g. tcp->offset = 5 ; TCP Header Length = 5 x 4 byte = 20 byte diff --git a/examples/networking/http_filter/http-parse-simple.c b/examples/networking/http_filter/http-parse-simple.c index d9229b494b7f..b4e49ccbf31d 100644 --- a/examples/networking/http_filter/http-parse-simple.c +++ b/examples/networking/http_filter/http-parse-simple.c @@ -34,13 +34,21 @@ int http_filter(struct __sk_buff *skb) { u32 payload_offset = 0; u32 payload_length = 0; - struct tcp_t *tcp = cursor_advance(cursor, sizeof(*tcp)); - //calculate ip header length //value to multiply * 4 //e.g. ip->hlen = 5 ; IP Header Length = 5 x 4 byte = 20 byte ip_header_length = ip->hlen << 2; //SHL 2 -> *4 multiply + //check ip header length against minimum + if (ip_header_length < sizeof(*ip)) { + goto DROP; + } + + //shift cursor forward for dynamic ip header size + void *_ = cursor_advance(cursor, (ip_header_length-sizeof(*ip))); + + struct tcp_t *tcp = cursor_advance(cursor, sizeof(*tcp)); + //calculate tcp header length //value to multiply *4 //e.g. tcp->offset = 5 ; TCP Header Length = 5 x 4 byte = 20 byte