From 77bd7953fbde5cd9c3bda4a4ce43eeca1ea7e20d Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 24 Feb 2010 00:29:55 +0100 Subject: [PATCH] length2: guard off IPv6-only functions --- extensions/xt_length2.c | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/extensions/xt_length2.c b/extensions/xt_length2.c index a329cbd..8de6ca5 100644 --- a/extensions/xt_length2.c +++ b/extensions/xt_length2.c @@ -136,6 +136,30 @@ static bool xtlength_layer7(unsigned int *length, const struct sk_buff *skb, } } +static bool +length2_mt(const struct sk_buff *skb, const struct xt_match_param *par) +{ + const struct xt_length_mtinfo2 *info = par->matchinfo; + const struct iphdr *iph = ip_hdr(skb); + unsigned int len = 0; + bool hit = true; + + if (info->flags & XT_LENGTH_LAYER3) + len = ntohs(iph->tot_len); + else if (info->flags & XT_LENGTH_LAYER4) + len = ntohs(iph->tot_len) - par->thoff; + else if (info->flags & XT_LENGTH_LAYER5) + hit = xtlength_layer5(&len, skb, iph->protocol, par->thoff); + else if (info->flags & XT_LENGTH_LAYER7) + hit = xtlength_layer7(&len, skb, iph->protocol, par->thoff); + if (!hit) + return false; + + return (len >= info->min && len <= info->max) ^ + !!(info->flags & XT_LENGTH_INVERT); +} + +#ifdef WITH_IPV6 /** * llayer4_proto - figure out the L4 protocol in an IPv6 packet * @skb: skb pointer @@ -173,30 +197,6 @@ llayer4_proto(const struct sk_buff *skb, unsigned int *offset, bool *hotdrop) return NEXTHDR_MAX; } -static bool -length2_mt(const struct sk_buff *skb, const struct xt_match_param *par) -{ - const struct xt_length_mtinfo2 *info = par->matchinfo; - const struct iphdr *iph = ip_hdr(skb); - unsigned int len = 0; - bool hit = true; - - if (info->flags & XT_LENGTH_LAYER3) - len = ntohs(iph->tot_len); - else if (info->flags & XT_LENGTH_LAYER4) - len = ntohs(iph->tot_len) - par->thoff; - else if (info->flags & XT_LENGTH_LAYER5) - hit = xtlength_layer5(&len, skb, iph->protocol, par->thoff); - else if (info->flags & XT_LENGTH_LAYER7) - hit = xtlength_layer7(&len, skb, iph->protocol, par->thoff); - if (!hit) - return false; - - return (len >= info->min && len <= info->max) ^ - !!(info->flags & XT_LENGTH_INVERT); -} - -#ifdef WITH_IPV6 static bool length2_mt6(const struct sk_buff *skb, const struct xt_match_param *par) {