diff options
Diffstat (limited to 'tap.c')
| -rw-r--r-- | tap.c | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -900,6 +900,28 @@ append: return in->count; } +/** + * tap6_is_fragment() - Determine if header type indicates a fragment, log it + * @nh: Next extension header type + * @now: Current timestamp + * + * Return: true if @nh indicates a fragment header, false otherwise + */ +static bool tap6_is_fragment(uint8_t nh, const struct timespec *now) +{ + if (nh == IPPROTO_FRAGMENT) { + static unsigned num_dropped; + + num_dropped++; + warn_ratelimit(now, "Can't process IPv6 fragments (%u dropped)", + num_dropped); + + return true; + } + + return false; +} + #define IPV6_NH_OPT(nh) \ ((nh) == 0 || (nh) == 43 || (nh) == 44 || (nh) == 50 || \ (nh) == 51 || (nh) == 60 || (nh) == 135 || (nh) == 139 || \ @@ -910,11 +932,13 @@ append: * @data: IPv6 packet * @proto: Filled with L4 protocol number * @dlen: Data length (payload excluding header extensions), set on return + * @now: Current timestamp * * Return: true if the L4 header is found and @data, @proto, @dlen are set, * false on error. Outputs are indeterminate on failure. */ -static bool ipv6_l4hdr(struct iov_tail *data, uint8_t *proto, size_t *dlen) +static bool ipv6_l4hdr(struct iov_tail *data, uint8_t *proto, size_t *dlen, + const struct timespec *now) { struct ipv6_opt_hdr o_storage; const struct ipv6_opt_hdr *o; @@ -931,10 +955,16 @@ static bool ipv6_l4hdr(struct iov_tail *data, uint8_t *proto, size_t *dlen) if (!IPV6_NH_OPT(nh)) goto found; + if (tap6_is_fragment(nh, now)) + return false; + while ((o = IOV_PEEK_HEADER(data, o_storage))) { nh = o->nexthdr; hdrlen = (o->hdrlen + 1) * 8; + if (tap6_is_fragment(nh, now)) + return false; + iov_drop_header(data, hdrlen); if (!IPV6_NH_OPT(nh)) @@ -1003,7 +1033,7 @@ resume: if (plen != check) continue; - if (!ipv6_l4hdr(&data, &proto, &l4len)) + if (!ipv6_l4hdr(&data, &proto, &l4len, now)) continue; if (tap_filter_address(now, AF_INET6, saddr, daddr)) |
