netfilter: xtables: compact table hook functions (1/2)
authorJan Engelhardt <jengelh@medozas.de>
Sat, 13 Jun 2009 04:46:36 +0000 (06:46 +0200)
committerJan Engelhardt <jengelh@medozas.de>
Wed, 10 Feb 2010 15:44:58 +0000 (16:44 +0100)
This patch combines all the per-hook functions in a given table into
a single function. Together with the 2nd patch, further
simplifications are possible up to the point of output code reduction.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
net/ipv4/netfilter/arptable_filter.c
net/ipv4/netfilter/iptable_filter.c
net/ipv4/netfilter/iptable_mangle.c
net/ipv4/netfilter/iptable_raw.c
net/ipv4/netfilter/iptable_security.c
net/ipv6/netfilter/ip6table_filter.c
net/ipv6/netfilter/ip6table_mangle.c
net/ipv6/netfilter/ip6table_raw.c
net/ipv6/netfilter/ip6table_security.c

index 97337601827a9752df2c1f92f37489009805aa84..e9d823b149cd5bbe47f76a263cf6cf444004fdf9 100644 (file)
@@ -53,43 +53,37 @@ static const struct xt_table packet_filter = {
 };
 
 /* The work comes in here from netfilter.c */
-static unsigned int arpt_in_hook(unsigned int hook,
-                                struct sk_buff *skb,
-                                const struct net_device *in,
-                                const struct net_device *out,
-                                int (*okfn)(struct sk_buff *))
+static unsigned int
+arptable_filter_hook(unsigned int hook, struct sk_buff *skb,
+                    const struct net_device *in, const struct net_device *out,
+                    int (*okfn)(struct sk_buff *))
 {
-       return arpt_do_table(skb, hook, in, out,
-                            dev_net(in)->ipv4.arptable_filter);
-}
+       if (hook == NF_ARP_OUT)
+               return arpt_do_table(skb, hook, in, out,
+                                    dev_net(out)->ipv4.arptable_filter);
 
-static unsigned int arpt_out_hook(unsigned int hook,
-                                 struct sk_buff *skb,
-                                 const struct net_device *in,
-                                 const struct net_device *out,
-                                 int (*okfn)(struct sk_buff *))
-{
+       /* INPUT/FORWARD: */
        return arpt_do_table(skb, hook, in, out,
-                            dev_net(out)->ipv4.arptable_filter);
+                            dev_net(in)->ipv4.arptable_filter);
 }
 
 static struct nf_hook_ops arpt_ops[] __read_mostly = {
        {
-               .hook           = arpt_in_hook,
+               .hook           = arptable_filter_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_ARP,
                .hooknum        = NF_ARP_IN,
                .priority       = NF_IP_PRI_FILTER,
        },
        {
-               .hook           = arpt_out_hook,
+               .hook           = arptable_filter_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_ARP,
                .hooknum        = NF_ARP_OUT,
                .priority       = NF_IP_PRI_FILTER,
        },
        {
-               .hook           = arpt_in_hook,
+               .hook           = arptable_filter_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_ARP,
                .hooknum        = NF_ARP_FORWARD,
index dee90eb8aa47eceace5a04114a052cf0b83f4274..5369833ad56acb9589119d77bb9efac8eeb5c7d7 100644 (file)
@@ -60,61 +60,43 @@ static const struct xt_table packet_filter = {
        .af             = NFPROTO_IPV4,
 };
 
-/* The work comes in here from netfilter.c. */
 static unsigned int
-ipt_local_in_hook(unsigned int hook,
-                 struct sk_buff *skb,
-                 const struct net_device *in,
-                 const struct net_device *out,
-                 int (*okfn)(struct sk_buff *))
+iptable_filter_hook(unsigned int hook, struct sk_buff *skb,
+                   const struct net_device *in, const struct net_device *out,
+                   int (*okfn)(struct sk_buff *))
 {
-       return ipt_do_table(skb, hook, in, out,
-                           dev_net(in)->ipv4.iptable_filter);
-}
+       if (hook == NF_INET_LOCAL_OUT) {
+               if (skb->len < sizeof(struct iphdr) ||
+                   ip_hdrlen(skb) < sizeof(struct iphdr))
+                       /* root is playing with raw sockets. */
+                       return NF_ACCEPT;
+
+               return ipt_do_table(skb, hook, in, out,
+                                   dev_net(out)->ipv4.iptable_filter);
+       }
 
-static unsigned int
-ipt_hook(unsigned int hook,
-        struct sk_buff *skb,
-        const struct net_device *in,
-        const struct net_device *out,
-        int (*okfn)(struct sk_buff *))
-{
+       /* LOCAL_IN/FORWARD: */
        return ipt_do_table(skb, hook, in, out,
                            dev_net(in)->ipv4.iptable_filter);
 }
 
-static unsigned int
-ipt_local_out_hook(unsigned int hook,
-                  struct sk_buff *skb,
-                  const struct net_device *in,
-                  const struct net_device *out,
-                  int (*okfn)(struct sk_buff *))
-{
-       /* root is playing with raw sockets. */
-       if (skb->len < sizeof(struct iphdr) ||
-           ip_hdrlen(skb) < sizeof(struct iphdr))
-               return NF_ACCEPT;
-       return ipt_do_table(skb, hook, in, out,
-                           dev_net(out)->ipv4.iptable_filter);
-}
-
 static struct nf_hook_ops ipt_ops[] __read_mostly = {
        {
-               .hook           = ipt_local_in_hook,
+               .hook           = iptable_filter_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP_PRI_FILTER,
        },
        {
-               .hook           = ipt_hook,
+               .hook           = iptable_filter_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_FORWARD,
                .priority       = NF_IP_PRI_FILTER,
        },
        {
-               .hook           = ipt_local_out_hook,
+               .hook           = iptable_filter_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_OUT,
index e07bf242343a831f3031aec5ba6ddddba117f89d..4e699cd275c61c4c926778d632308d3a1973ee95 100644 (file)
@@ -71,51 +71,6 @@ static const struct xt_table packet_mangler = {
        .af             = NFPROTO_IPV4,
 };
 
-/* The work comes in here from netfilter.c. */
-static unsigned int
-ipt_pre_routing_hook(unsigned int hook,
-                    struct sk_buff *skb,
-                    const struct net_device *in,
-                    const struct net_device *out,
-                    int (*okfn)(struct sk_buff *))
-{
-       return ipt_do_table(skb, hook, in, out,
-                           dev_net(in)->ipv4.iptable_mangle);
-}
-
-static unsigned int
-ipt_post_routing_hook(unsigned int hook,
-                     struct sk_buff *skb,
-                     const struct net_device *in,
-                     const struct net_device *out,
-                     int (*okfn)(struct sk_buff *))
-{
-       return ipt_do_table(skb, hook, in, out,
-                           dev_net(out)->ipv4.iptable_mangle);
-}
-
-static unsigned int
-ipt_local_in_hook(unsigned int hook,
-                 struct sk_buff *skb,
-                 const struct net_device *in,
-                 const struct net_device *out,
-                 int (*okfn)(struct sk_buff *))
-{
-       return ipt_do_table(skb, hook, in, out,
-                           dev_net(in)->ipv4.iptable_mangle);
-}
-
-static unsigned int
-ipt_forward_hook(unsigned int hook,
-        struct sk_buff *skb,
-        const struct net_device *in,
-        const struct net_device *out,
-        int (*okfn)(struct sk_buff *))
-{
-       return ipt_do_table(skb, hook, in, out,
-                           dev_net(in)->ipv4.iptable_mangle);
-}
-
 static unsigned int
 ipt_local_hook(unsigned int hook,
                   struct sk_buff *skb,
@@ -158,37 +113,53 @@ ipt_local_hook(unsigned int hook,
        return ret;
 }
 
+/* The work comes in here from netfilter.c. */
+static unsigned int
+iptable_mangle_hook(unsigned int hook,
+                    struct sk_buff *skb,
+                    const struct net_device *in,
+                    const struct net_device *out,
+                    int (*okfn)(struct sk_buff *))
+{
+       if (hook == NF_INET_LOCAL_OUT)
+               return ipt_local_hook(hook, skb, in, out, okfn);
+
+       /* PREROUTING/INPUT/FORWARD: */
+       return ipt_do_table(skb, hook, in, out,
+                           dev_net(in)->ipv4.iptable_mangle);
+}
+
 static struct nf_hook_ops ipt_ops[] __read_mostly = {
        {
-               .hook           = ipt_pre_routing_hook,
+               .hook           = iptable_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_PRE_ROUTING,
                .priority       = NF_IP_PRI_MANGLE,
        },
        {
-               .hook           = ipt_local_in_hook,
+               .hook           = iptable_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP_PRI_MANGLE,
        },
        {
-               .hook           = ipt_forward_hook,
+               .hook           = iptable_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_FORWARD,
                .priority       = NF_IP_PRI_MANGLE,
        },
        {
-               .hook           = ipt_local_hook,
+               .hook           = iptable_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP_PRI_MANGLE,
        },
        {
-               .hook           = ipt_post_routing_hook,
+               .hook           = iptable_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_POST_ROUTING,
index 40f2b9f611a289fef11f442961d5ed2b71798d7c..2c55575e89f5447619f8d648cceba6d7a9a13d5f 100644 (file)
@@ -45,23 +45,15 @@ static const struct xt_table packet_raw = {
 
 /* The work comes in here from netfilter.c. */
 static unsigned int
-ipt_hook(unsigned int hook,
-        struct sk_buff *skb,
-        const struct net_device *in,
-        const struct net_device *out,
-        int (*okfn)(struct sk_buff *))
+iptable_raw_hook(unsigned int hook, struct sk_buff *skb,
+                const struct net_device *in, const struct net_device *out,
+                int (*okfn)(struct sk_buff *))
 {
-       return ipt_do_table(skb, hook, in, out,
-                           dev_net(in)->ipv4.iptable_raw);
-}
+       if (hook == NF_INET_PRE_ROUTING)
+               return ipt_do_table(skb, hook, in, out,
+                                   dev_net(in)->ipv4.iptable_raw);
 
-static unsigned int
-ipt_local_hook(unsigned int hook,
-              struct sk_buff *skb,
-              const struct net_device *in,
-              const struct net_device *out,
-              int (*okfn)(struct sk_buff *))
-{
+       /* OUTPUT: */
        /* root is playing with raw sockets. */
        if (skb->len < sizeof(struct iphdr) ||
            ip_hdrlen(skb) < sizeof(struct iphdr))
@@ -73,14 +65,14 @@ ipt_local_hook(unsigned int hook,
 /* 'raw' is the very first table. */
 static struct nf_hook_ops ipt_ops[] __read_mostly = {
        {
-               .hook = ipt_hook,
+               .hook = iptable_raw_hook,
                .pf = NFPROTO_IPV4,
                .hooknum = NF_INET_PRE_ROUTING,
                .priority = NF_IP_PRI_RAW,
                .owner = THIS_MODULE,
        },
        {
-               .hook = ipt_local_hook,
+               .hook = iptable_raw_hook,
                .pf = NFPROTO_IPV4,
                .hooknum = NF_INET_LOCAL_OUT,
                .priority = NF_IP_PRI_RAW,
index 7ce2366e4305e6cac8ceb65e31ca9772cafaa756..1c666bab3269e667c6cb04a23ebd79dea816c6be 100644 (file)
@@ -65,59 +65,43 @@ static const struct xt_table security_table = {
 };
 
 static unsigned int
-ipt_local_in_hook(unsigned int hook,
-                 struct sk_buff *skb,
-                 const struct net_device *in,
-                 const struct net_device *out,
-                 int (*okfn)(struct sk_buff *))
+iptable_security_hook(unsigned int hook, struct sk_buff *skb,
+                     const struct net_device *in,
+                     const struct net_device *out,
+                     int (*okfn)(struct sk_buff *))
 {
-       return ipt_do_table(skb, hook, in, out,
-                           dev_net(in)->ipv4.iptable_security);
-}
+       if (hook == NF_INET_LOCAL_OUT) {
+               if (skb->len < sizeof(struct iphdr) ||
+                   ip_hdrlen(skb) < sizeof(struct iphdr))
+                       /* Somebody is playing with raw sockets. */
+                       return NF_ACCEPT;
 
-static unsigned int
-ipt_forward_hook(unsigned int hook,
-                struct sk_buff *skb,
-                const struct net_device *in,
-                const struct net_device *out,
-                int (*okfn)(struct sk_buff *))
-{
-       return ipt_do_table(skb, hook, in, out,
-                           dev_net(in)->ipv4.iptable_security);
-}
+               return ipt_do_table(skb, hook, in, out,
+                                   dev_net(out)->ipv4.iptable_security);
+       }
 
-static unsigned int
-ipt_local_out_hook(unsigned int hook,
-                  struct sk_buff *skb,
-                  const struct net_device *in,
-                  const struct net_device *out,
-                  int (*okfn)(struct sk_buff *))
-{
-       /* Somebody is playing with raw sockets. */
-       if (skb->len < sizeof(struct iphdr) ||
-           ip_hdrlen(skb) < sizeof(struct iphdr))
-               return NF_ACCEPT;
+       /* INPUT/FORWARD: */
        return ipt_do_table(skb, hook, in, out,
-                           dev_net(out)->ipv4.iptable_security);
+                           dev_net(in)->ipv4.iptable_security);
 }
 
 static struct nf_hook_ops ipt_ops[] __read_mostly = {
        {
-               .hook           = ipt_local_in_hook,
+               .hook           = iptable_security_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP_PRI_SECURITY,
        },
        {
-               .hook           = ipt_forward_hook,
+               .hook           = iptable_security_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_FORWARD,
                .priority       = NF_IP_PRI_SECURITY,
        },
        {
-               .hook           = ipt_local_out_hook,
+               .hook           = iptable_security_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_OUT,
index 33ddfe53e18db4a3112b46ad493ea429526f95d4..38074e933f67fadbd4e15d477d93f6f7ca00e6f7 100644 (file)
@@ -60,54 +60,36 @@ static const struct xt_table packet_filter = {
 
 /* The work comes in here from netfilter.c. */
 static unsigned int
-ip6t_in_hook(unsigned int hook,
-                  struct sk_buff *skb,
-                  const struct net_device *in,
-                  const struct net_device *out,
-                  int (*okfn)(struct sk_buff *))
+ip6table_filter_hook(unsigned int hook, struct sk_buff *skb,
+                    const struct net_device *in, const struct net_device *out,
+                    int (*okfn)(struct sk_buff *))
 {
-       return ip6t_do_table(skb, hook, in, out,
-                            dev_net(in)->ipv6.ip6table_filter);
-}
-
-static unsigned int
-ip6t_local_out_hook(unsigned int hook,
-                  struct sk_buff *skb,
-                  const struct net_device *in,
-                  const struct net_device *out,
-                  int (*okfn)(struct sk_buff *))
-{
-#if 0
-       /* root is playing with raw sockets. */
-       if (skb->len < sizeof(struct iphdr) ||
-           ip_hdrlen(skb) < sizeof(struct iphdr)) {
-               if (net_ratelimit())
-                       printk("ip6t_hook: happy cracking.\n");
-               return NF_ACCEPT;
-       }
-#endif
+       if (hook == NF_INET_LOCAL_OUT)
+               return ip6t_do_table(skb, hook, in, out,
+                                    dev_net(out)->ipv6.ip6table_filter);
 
+       /* INPUT/FORWARD: */
        return ip6t_do_table(skb, hook, in, out,
-                            dev_net(out)->ipv6.ip6table_filter);
+                            dev_net(in)->ipv6.ip6table_filter);
 }
 
 static struct nf_hook_ops ip6t_ops[] __read_mostly = {
        {
-               .hook           = ip6t_in_hook,
+               .hook           = ip6table_filter_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP6_PRI_FILTER,
        },
        {
-               .hook           = ip6t_in_hook,
+               .hook           = ip6table_filter_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_FORWARD,
                .priority       = NF_IP6_PRI_FILTER,
        },
        {
-               .hook           = ip6t_local_out_hook,
+               .hook           = ip6table_filter_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_OUT,
index 9bc483f000e56c210ea3d91a6fa0f55450e76c09..405ac1f76390a07c028d6dbdc2ae715bd6848e08 100644 (file)
@@ -64,33 +64,9 @@ static const struct xt_table packet_mangler = {
        .af             = NFPROTO_IPV6,
 };
 
-/* The work comes in here from netfilter.c. */
-static unsigned int
-ip6t_in_hook(unsigned int hook,
-        struct sk_buff *skb,
-        const struct net_device *in,
-        const struct net_device *out,
-        int (*okfn)(struct sk_buff *))
-{
-       return ip6t_do_table(skb, hook, in, out,
-                            dev_net(in)->ipv6.ip6table_mangle);
-}
-
-static unsigned int
-ip6t_post_routing_hook(unsigned int hook,
-               struct sk_buff *skb,
-               const struct net_device *in,
-               const struct net_device *out,
-               int (*okfn)(struct sk_buff *))
-{
-       return ip6t_do_table(skb, hook, in, out,
-                            dev_net(out)->ipv6.ip6table_mangle);
-}
-
 static unsigned int
 ip6t_local_out_hook(unsigned int hook,
                   struct sk_buff *skb,
-                  const struct net_device *in,
                   const struct net_device *out,
                   int (*okfn)(struct sk_buff *))
 {
@@ -119,7 +95,7 @@ ip6t_local_out_hook(unsigned int hook,
        /* flowlabel and prio (includes version, which shouldn't change either */
        flowlabel = *((u_int32_t *)ipv6_hdr(skb));
 
-       ret = ip6t_do_table(skb, hook, in, out,
+       ret = ip6t_do_table(skb, hook, NULL, out,
                            dev_net(out)->ipv6.ip6table_mangle);
 
        if (ret != NF_DROP && ret != NF_STOLEN &&
@@ -132,37 +108,51 @@ ip6t_local_out_hook(unsigned int hook,
        return ret;
 }
 
+/* The work comes in here from netfilter.c. */
+static unsigned int
+ip6table_mangle_hook(unsigned int hook, struct sk_buff *skb,
+                    const struct net_device *in, const struct net_device *out,
+                    int (*okfn)(struct sk_buff *))
+{
+       if (hook == NF_INET_LOCAL_OUT)
+               return ip6t_local_out_hook(hook, skb, out, okfn);
+
+       /* INPUT/FORWARD */
+       return ip6t_do_table(skb, hook, in, out,
+                            dev_net(in)->ipv6.ip6table_mangle);
+}
+
 static struct nf_hook_ops ip6t_ops[] __read_mostly = {
        {
-               .hook           = ip6t_in_hook,
+               .hook           = ip6table_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_PRE_ROUTING,
                .priority       = NF_IP6_PRI_MANGLE,
        },
        {
-               .hook           = ip6t_in_hook,
+               .hook           = ip6table_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP6_PRI_MANGLE,
        },
        {
-               .hook           = ip6t_in_hook,
+               .hook           = ip6table_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_FORWARD,
                .priority       = NF_IP6_PRI_MANGLE,
        },
        {
-               .hook           = ip6t_local_out_hook,
+               .hook           = ip6table_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP6_PRI_MANGLE,
        },
        {
-               .hook           = ip6t_post_routing_hook,
+               .hook           = ip6table_mangle_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_POST_ROUTING,
index 4c90b552e4336e293edc1e7f1e912d4e59a87588..985e27cf1e0c02d0924cbe34c20eb99fc25b0d4c 100644 (file)
@@ -44,37 +44,29 @@ static const struct xt_table packet_raw = {
 
 /* The work comes in here from netfilter.c. */
 static unsigned int
-ip6t_pre_routing_hook(unsigned int hook,
-        struct sk_buff *skb,
-        const struct net_device *in,
-        const struct net_device *out,
-        int (*okfn)(struct sk_buff *))
+ip6table_raw_hook(unsigned int hook, struct sk_buff *skb,
+                 const struct net_device *in, const struct net_device *out,
+                 int (*okfn)(struct sk_buff *))
 {
-       return ip6t_do_table(skb, hook, in, out,
-                            dev_net(in)->ipv6.ip6table_raw);
-}
+       if (hook == NF_INET_PRE_ROUTING)
+               return ip6t_do_table(skb, hook, in, out,
+                                    dev_net(in)->ipv6.ip6table_raw);
 
-static unsigned int
-ip6t_local_out_hook(unsigned int hook,
-        struct sk_buff *skb,
-        const struct net_device *in,
-        const struct net_device *out,
-        int (*okfn)(struct sk_buff *))
-{
+       /* OUTPUT: */
        return ip6t_do_table(skb, hook, in, out,
                             dev_net(out)->ipv6.ip6table_raw);
 }
 
 static struct nf_hook_ops ip6t_ops[] __read_mostly = {
        {
-         .hook = ip6t_pre_routing_hook,
+         .hook = ip6table_raw_hook,
          .pf = NFPROTO_IPV6,
          .hooknum = NF_INET_PRE_ROUTING,
          .priority = NF_IP6_PRI_FIRST,
          .owner = THIS_MODULE,
        },
        {
-         .hook = ip6t_local_out_hook,
+         .hook = ip6table_raw_hook,
          .pf = NFPROTO_IPV6,
          .hooknum = NF_INET_LOCAL_OUT,
          .priority = NF_IP6_PRI_FIRST,
index baa8d4ef3b0a6283842effc5e95e0a2576e71499..835858929358f0ba86bb5341e0f380e4429d9545 100644 (file)
@@ -64,56 +64,37 @@ static const struct xt_table security_table = {
 };
 
 static unsigned int
-ip6t_local_in_hook(unsigned int hook,
-                  struct sk_buff *skb,
-                  const struct net_device *in,
-                  const struct net_device *out,
-                  int (*okfn)(struct sk_buff *))
+ip6table_security_hook(unsigned int hook, struct sk_buff *skb,
+                      const struct net_device *in,
+                      const struct net_device *out,
+                      int (*okfn)(struct sk_buff *))
 {
-       return ip6t_do_table(skb, hook, in, out,
-                            dev_net(in)->ipv6.ip6table_security);
-}
+       if (hook == NF_INET_LOCAL_OUT)
+               return ip6t_do_table(skb, hook, in, out,
+                                    dev_net(out)->ipv6.ip6table_security);
 
-static unsigned int
-ip6t_forward_hook(unsigned int hook,
-                 struct sk_buff *skb,
-                 const struct net_device *in,
-                 const struct net_device *out,
-                 int (*okfn)(struct sk_buff *))
-{
+       /* INPUT/FORWARD: */
        return ip6t_do_table(skb, hook, in, out,
                             dev_net(in)->ipv6.ip6table_security);
 }
 
-static unsigned int
-ip6t_local_out_hook(unsigned int hook,
-                   struct sk_buff *skb,
-                   const struct net_device *in,
-                   const struct net_device *out,
-                   int (*okfn)(struct sk_buff *))
-{
-       /* TBD: handle short packets via raw socket */
-       return ip6t_do_table(skb, hook, in, out,
-                            dev_net(out)->ipv6.ip6table_security);
-}
-
 static struct nf_hook_ops ip6t_ops[] __read_mostly = {
        {
-               .hook           = ip6t_local_in_hook,
+               .hook           = ip6table_security_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP6_PRI_SECURITY,
        },
        {
-               .hook           = ip6t_forward_hook,
+               .hook           = ip6table_security_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_FORWARD,
                .priority       = NF_IP6_PRI_SECURITY,
        },
        {
-               .hook           = ip6t_local_out_hook,
+               .hook           = ip6table_security_hook,
                .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_OUT,