netfilter: xtables: change xt_match.checkentry return type
[firefly-linux-kernel-4.4.55.git] / net / ipv6 / netfilter / ip6t_hbh.c
index 26654b26d7fafd3f2d20103484498b2098d30461..1b294317707bdaf2ed0b3399bbd965dc726ebb27 100644 (file)
@@ -6,7 +6,7 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
-
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 #include <linux/module.h>
 #include <linux/skbuff.h>
 #include <linux/ipv6.h>
@@ -41,15 +41,14 @@ MODULE_ALIAS("ip6t_dst");
  *     5       -> RTALERT 2 x x
  */
 
+static struct xt_match hbh_mt6_reg[] __read_mostly;
+
 static bool
-hbh_mt6(const struct sk_buff *skb, const struct net_device *in,
-        const struct net_device *out, const struct xt_match *match,
-        const void *matchinfo, int offset, unsigned int protoff,
-        bool *hotdrop)
+hbh_mt6(const struct sk_buff *skb, const struct xt_match_param *par)
 {
        struct ipv6_opt_hdr _optsh;
        const struct ipv6_opt_hdr *oh;
-       const struct ip6t_opts *optinfo = matchinfo;
+       const struct ip6t_opts *optinfo = par->matchinfo;
        unsigned int temp;
        unsigned int ptr;
        unsigned int hdrlen = 0;
@@ -61,16 +60,18 @@ hbh_mt6(const struct sk_buff *skb, const struct net_device *in,
        unsigned int optlen;
        int err;
 
-       err = ipv6_find_hdr(skb, &ptr, match->data, NULL);
+       err = ipv6_find_hdr(skb, &ptr,
+                           (par->match == &hbh_mt6_reg[0]) ?
+                           NEXTHDR_HOP : NEXTHDR_DEST, NULL);
        if (err < 0) {
                if (err != -ENOENT)
-                       *hotdrop = true;
+                       *par->hotdrop = true;
                return false;
        }
 
        oh = skb_header_pointer(skb, ptr, sizeof(_optsh), &_optsh);
        if (oh == NULL) {
-               *hotdrop = true;
+               *par->hotdrop = true;
                return false;
        }
 
@@ -163,21 +164,17 @@ hbh_mt6(const struct sk_buff *skb, const struct net_device *in,
        return false;
 }
 
-/* Called when user tries to insert an entry of this type. */
-static bool
-hbh_mt6_check(const char *tablename, const void *entry,
-              const struct xt_match *match, void *matchinfo,
-              unsigned int hook_mask)
+static int hbh_mt6_check(const struct xt_mtchk_param *par)
 {
-       const struct ip6t_opts *optsinfo = matchinfo;
+       const struct ip6t_opts *optsinfo = par->matchinfo;
 
        if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) {
-               pr_debug("ip6t_opts: unknown flags %X\n", optsinfo->invflags);
+               pr_debug("unknown flags %X\n", optsinfo->invflags);
                return false;
        }
 
        if (optsinfo->flags & IP6T_OPTS_NSTRICT) {
-               pr_debug("ip6t_opts: Not strict - not implemented");
+               pr_debug("Not strict - not implemented");
                return false;
        }
 
@@ -186,22 +183,21 @@ hbh_mt6_check(const char *tablename, const void *entry,
 
 static struct xt_match hbh_mt6_reg[] __read_mostly = {
        {
+               /* Note, hbh_mt6 relies on the order of hbh_mt6_reg */
                .name           = "hbh",
-               .family         = AF_INET6,
+               .family         = NFPROTO_IPV6,
                .match          = hbh_mt6,
                .matchsize      = sizeof(struct ip6t_opts),
                .checkentry     = hbh_mt6_check,
                .me             = THIS_MODULE,
-               .data           = NEXTHDR_HOP,
        },
        {
                .name           = "dst",
-               .family         = AF_INET6,
+               .family         = NFPROTO_IPV6,
                .match          = hbh_mt6,
                .matchsize      = sizeof(struct ip6t_opts),
                .checkentry     = hbh_mt6_check,
                .me             = THIS_MODULE,
-               .data           = NEXTHDR_DEST,
        },
 };