Merge branch 'master' of /repos/git/net-next-2.6
[safe/jmp/linux-2.6] / net / ipv6 / netfilter / ip6table_mangle.c
index 27a5e8b..9bc483f 100644 (file)
@@ -21,7 +21,7 @@ MODULE_DESCRIPTION("ip6tables mangle table");
                            (1 << NF_INET_LOCAL_OUT) | \
                            (1 << NF_INET_POST_ROUTING))
 
-static struct
+static const struct
 {
        struct ip6t_replace repl;
        struct ip6t_standard entries[5];
@@ -57,27 +57,38 @@ static struct
        .term = IP6T_ERROR_INIT,                /* ERROR */
 };
 
-static struct xt_table packet_mangler = {
+static const struct xt_table packet_mangler = {
        .name           = "mangle",
        .valid_hooks    = MANGLE_VALID_HOOKS,
-       .lock           = __RW_LOCK_UNLOCKED(packet_mangler.lock),
        .me             = THIS_MODULE,
-       .af             = AF_INET6,
+       .af             = NFPROTO_IPV6,
 };
 
 /* The work comes in here from netfilter.c. */
 static unsigned int
-ip6t_route_hook(unsigned int hook,
+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, init_net.ipv6.ip6table_mangle);
+       return ip6t_do_table(skb, hook, in, out,
+                            dev_net(in)->ipv6.ip6table_mangle);
 }
 
 static unsigned int
-ip6t_local_hook(unsigned int hook,
+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,
@@ -91,8 +102,8 @@ ip6t_local_hook(unsigned int hook,
 
 #if 0
        /* root is playing with raw sockets. */
-       if (skb->len < sizeof(struct iphdr)
-           || ip_hdrlen(skb) < sizeof(struct iphdr)) {
+       if (skb->len < sizeof(struct iphdr) ||
+           ip_hdrlen(skb) < sizeof(struct iphdr)) {
                if (net_ratelimit())
                        printk("ip6t_hook: happy cracking.\n");
                return NF_ACCEPT;
@@ -108,13 +119,14 @@ ip6t_local_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, init_net.ipv6.ip6table_mangle);
+       ret = ip6t_do_table(skb, hook, in, out,
+                           dev_net(out)->ipv6.ip6table_mangle);
 
-       if (ret != NF_DROP && ret != NF_STOLEN
-               && (memcmp(&ipv6_hdr(skb)->saddr, &saddr, sizeof(saddr))
-                   || memcmp(&ipv6_hdr(skb)->daddr, &daddr, sizeof(daddr))
-                   || skb->mark != mark
-                   || ipv6_hdr(skb)->hop_limit != hop_limit))
+       if (ret != NF_DROP && ret != NF_STOLEN &&
+           (memcmp(&ipv6_hdr(skb)->saddr, &saddr, sizeof(saddr)) ||
+            memcmp(&ipv6_hdr(skb)->daddr, &daddr, sizeof(daddr)) ||
+            skb->mark != mark ||
+            ipv6_hdr(skb)->hop_limit != hop_limit))
                return ip6_route_me_harder(skb) == 0 ? ret : NF_DROP;
 
        return ret;
@@ -122,37 +134,37 @@ ip6t_local_hook(unsigned int hook,
 
 static struct nf_hook_ops ip6t_ops[] __read_mostly = {
        {
-               .hook           = ip6t_route_hook,
+               .hook           = ip6t_in_hook,
                .owner          = THIS_MODULE,
-               .pf             = PF_INET6,
+               .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_PRE_ROUTING,
                .priority       = NF_IP6_PRI_MANGLE,
        },
        {
-               .hook           = ip6t_local_hook,
+               .hook           = ip6t_in_hook,
                .owner          = THIS_MODULE,
-               .pf             = PF_INET6,
+               .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP6_PRI_MANGLE,
        },
        {
-               .hook           = ip6t_route_hook,
+               .hook           = ip6t_in_hook,
                .owner          = THIS_MODULE,
-               .pf             = PF_INET6,
+               .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_FORWARD,
                .priority       = NF_IP6_PRI_MANGLE,
        },
        {
-               .hook           = ip6t_local_hook,
+               .hook           = ip6t_local_out_hook,
                .owner          = THIS_MODULE,
-               .pf             = PF_INET6,
+               .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP6_PRI_MANGLE,
        },
        {
-               .hook           = ip6t_route_hook,
+               .hook           = ip6t_post_routing_hook,
                .owner          = THIS_MODULE,
-               .pf             = PF_INET6,
+               .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_POST_ROUTING,
                .priority       = NF_IP6_PRI_MANGLE,
        },
@@ -170,7 +182,7 @@ static int __net_init ip6table_mangle_net_init(struct net *net)
 
 static void __net_exit ip6table_mangle_net_exit(struct net *net)
 {
-       ip6t_unregister_table(net->ipv6.ip6table_mangle);
+       ip6t_unregister_table(net, net->ipv6.ip6table_mangle);
 }
 
 static struct pernet_operations ip6table_mangle_net_ops = {