[NETFILTER]: Use nf_register_hooks for multiple registrations
[firefly-linux-kernel-4.4.55.git] / net / sched / sch_ingress.c
index f8b9f1cdf738a8362ab77472a83721b62767fa3d..f4af9b604f3f09899e4789f10a6cc6d033b6309c 100644 (file)
@@ -9,21 +9,14 @@
 
 #include <linux/module.h>
 #include <linux/types.h>
+#include <linux/list.h>
 #include <linux/skbuff.h>
-#include <linux/netdevice.h>
 #include <linux/rtnetlink.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv6.h>
 #include <linux/netfilter.h>
-#include <linux/smp.h>
 #include <net/netlink.h>
 #include <net/pkt_sched.h>
-#include <asm/byteorder.h>
-#include <asm/uaccess.h>
-#include <linux/kmod.h>
-#include <linux/stat.h>
-#include <linux/interrupt.h>
-#include <linux/list.h>
 
 
 #undef DEBUG_INGRESS
@@ -165,36 +158,16 @@ static int ingress_enqueue(struct sk_buff *skb,struct Qdisc *sch)
                        break;
                case TC_ACT_RECLASSIFY:
                case TC_ACT_OK:
-               case TC_ACT_UNSPEC:
-               default:
                        skb->tc_index = TC_H_MIN(res.classid);
+               default:
                        result = TC_ACT_OK;
                        break;
        }
-/* backward compat */
-#else
-#ifdef CONFIG_NET_CLS_POLICE
-       switch (result) {
-               case TC_POLICE_SHOT:
-               result = NF_DROP;
-               sch->qstats.drops++;
-               break;
-               case TC_POLICE_RECLASSIFY: /* DSCP remarking here ? */
-               case TC_POLICE_OK:
-               case TC_POLICE_UNSPEC:
-               default:
-               sch->bstats.packets++;
-               sch->bstats.bytes += skb->len;
-               result = NF_ACCEPT;
-               break;
-       }
-
 #else
        D2PRINTK("Overriding result to ACCEPT\n");
        result = NF_ACCEPT;
        sch->bstats.packets++;
        sch->bstats.bytes += skb->len;
-#endif
 #endif
 
        return result;
@@ -232,20 +205,19 @@ static unsigned int ingress_drop(struct Qdisc *sch)
 #ifndef CONFIG_NET_CLS_ACT
 #ifdef CONFIG_NETFILTER
 static unsigned int
-ing_hook(unsigned int hook, struct sk_buff **pskb,
+ing_hook(unsigned int hook, struct sk_buff *skb,
                             const struct net_device *indev,
                             const struct net_device *outdev,
                             int (*okfn)(struct sk_buff *))
 {
 
        struct Qdisc *q;
-       struct sk_buff *skb = *pskb;
        struct net_device *dev = skb->dev;
        int fwres=NF_ACCEPT;
 
        DPRINTK("ing_hook: skb %s dev=%s len=%u\n",
                skb->sk ? "(owned)" : "(unowned)",
-               skb->dev ? (*pskb)->dev->name : "(no dev)",
+               skb->dev ? skb->dev->name : "(no dev)",
                skb->len);
 
        if (dev->qdisc_ingress) {
@@ -259,20 +231,21 @@ ing_hook(unsigned int hook, struct sk_buff **pskb,
 }
 
 /* after ipt_filter */
-static struct nf_hook_ops ing_ops = {
-       .hook           = ing_hook,
-       .owner          = THIS_MODULE,
-       .pf             = PF_INET,
-       .hooknum        = NF_IP_PRE_ROUTING,
-       .priority       = NF_IP_PRI_FILTER + 1,
-};
-
-static struct nf_hook_ops ing6_ops = {
-       .hook           = ing_hook,
-       .owner          = THIS_MODULE,
-       .pf             = PF_INET6,
-       .hooknum        = NF_IP6_PRE_ROUTING,
-       .priority       = NF_IP6_PRI_FILTER + 1,
+static struct nf_hook_ops ing_ops[] = {
+       {
+               .hook           = ing_hook,
+               .owner          = THIS_MODULE,
+               .pf             = PF_INET,
+               .hooknum        = NF_INET_PRE_ROUTING,
+               .priority       = NF_IP_PRI_FILTER + 1,
+       },
+       {
+               .hook           = ing_hook,
+               .owner          = THIS_MODULE,
+               .pf             = PF_INET6,
+               .hooknum        = NF_INET_PRE_ROUTING,
+               .priority       = NF_IP6_PRI_FILTER + 1,
+       },
 };
 
 #endif
@@ -296,17 +269,11 @@ static int ingress_init(struct Qdisc *sch,struct rtattr *opt)
 #ifndef CONFIG_NET_CLS_ACT
 #ifdef CONFIG_NETFILTER
        if (!nf_registered) {
-               if (nf_register_hook(&ing_ops) < 0) {
+               if (nf_register_hooks(ing_ops, ARRAY_SIZE(ing_ops)) < 0) {
                        printk("ingress qdisc registration error \n");
                        return -EINVAL;
                }
                nf_registered++;
-
-               if (nf_register_hook(&ing6_ops) < 0) {
-                       printk("IPv6 ingress qdisc registration error, " \
-                           "disabling IPv6 support.\n");
-               } else
-                       nf_registered++;
        }
 #endif
 #endif
@@ -366,7 +333,7 @@ rtattr_failure:
        return -1;
 }
 
-static struct Qdisc_class_ops ingress_class_ops = {
+static const struct Qdisc_class_ops ingress_class_ops = {
        .graft          =       ingress_graft,
        .leaf           =       ingress_leaf,
        .get            =       ingress_get,
@@ -380,7 +347,7 @@ static struct Qdisc_class_ops ingress_class_ops = {
        .dump           =       NULL,
 };
 
-static struct Qdisc_ops ingress_qdisc_ops = {
+static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
        .next           =       NULL,
        .cl_ops         =       &ingress_class_ops,
        .id             =       "ingress",
@@ -413,11 +380,8 @@ static void __exit ingress_module_exit(void)
        unregister_qdisc(&ingress_qdisc_ops);
 #ifndef CONFIG_NET_CLS_ACT
 #ifdef CONFIG_NETFILTER
-       if (nf_registered) {
-               nf_unregister_hook(&ing_ops);
-               if (nf_registered > 1)
-                       nf_unregister_hook(&ing6_ops);
-       }
+       if (nf_registered)
+               nf_unregister_hooks(ing_ops, ARRAY_SIZE(ing_ops));
 #endif
 #endif
 }