netfilter: xtables: compact table hook functions (1/2)
[safe/jmp/linux-2.6] / net / ipv6 / sit.c
index 2362a33..10207cc 100644 (file)
 #define HASH_SIZE  16
 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
 
-static void ipip6_fb_tunnel_init(struct net_device *dev);
 static void ipip6_tunnel_init(struct net_device *dev);
 static void ipip6_tunnel_setup(struct net_device *dev);
 
-static int sit_net_id;
+static int sit_net_id __read_mostly;
 struct sit_net {
        struct ip_tunnel *tunnels_r_l[HASH_SIZE];
        struct ip_tunnel *tunnels_r[HASH_SIZE];
@@ -637,6 +636,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
        struct iphdr  *tiph = &tunnel->parms.iph;
        struct ipv6hdr *iph6 = ipv6_hdr(skb);
        u8     tos = tunnel->parms.iph.tos;
+       __be16 df = tiph->frag_off;
        struct rtable *rt;                      /* Route to the other host */
        struct net_device *tdev;                        /* Device to other host */
        struct iphdr  *iph;                     /* Our new IP header */
@@ -726,25 +726,28 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
                goto tx_error;
        }
 
-       if (tiph->frag_off)
+       if (df) {
                mtu = dst_mtu(&rt->u.dst) - sizeof(struct iphdr);
-       else
-               mtu = skb_dst(skb) ? dst_mtu(skb_dst(skb)) : dev->mtu;
 
-       if (mtu < 68) {
-               stats->collisions++;
-               ip_rt_put(rt);
-               goto tx_error;
-       }
-       if (mtu < IPV6_MIN_MTU)
-               mtu = IPV6_MIN_MTU;
-       if (tunnel->parms.iph.daddr && skb_dst(skb))
-               skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
+               if (mtu < 68) {
+                       stats->collisions++;
+                       ip_rt_put(rt);
+                       goto tx_error;
+               }
 
-       if (skb->len > mtu) {
-               icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
-               ip_rt_put(rt);
-               goto tx_error;
+               if (mtu < IPV6_MIN_MTU) {
+                       mtu = IPV6_MIN_MTU;
+                       df = 0;
+               }
+
+               if (tunnel->parms.iph.daddr && skb_dst(skb))
+                       skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
+
+               if (skb->len > mtu) {
+                       icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
+                       ip_rt_put(rt);
+                       goto tx_error;
+               }
        }
 
        if (tunnel->err_count > 0) {
@@ -792,11 +795,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
        iph                     =       ip_hdr(skb);
        iph->version            =       4;
        iph->ihl                =       sizeof(struct iphdr)>>2;
-       if (mtu > IPV6_MIN_MTU)
-               iph->frag_off   =       tiph->frag_off;
-       else
-               iph->frag_off   =       0;
-
+       iph->frag_off           =       df;
        iph->protocol           =       IPPROTO_IPV6;
        iph->tos                =       INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
        iph->daddr              =       rt->rt_dst;
@@ -1120,7 +1119,7 @@ static void ipip6_tunnel_init(struct net_device *dev)
        ipip6_tunnel_bind_dev(dev);
 }
 
-static void ipip6_fb_tunnel_init(struct net_device *dev)
+static void __net_init ipip6_fb_tunnel_init(struct net_device *dev)
 {
        struct ip_tunnel *tunnel = netdev_priv(dev);
        struct iphdr *iph = &tunnel->parms.iph;
@@ -1145,7 +1144,7 @@ static struct xfrm_tunnel sit_handler = {
        .priority       =       1,
 };
 
-static void sit_destroy_tunnels(struct sit_net *sitn, struct list_head *head)
+static void __net_exit sit_destroy_tunnels(struct sit_net *sitn, struct list_head *head)
 {
        int prio;
 
@@ -1162,19 +1161,10 @@ static void sit_destroy_tunnels(struct sit_net *sitn, struct list_head *head)
        }
 }
 
-static int sit_init_net(struct net *net)
+static int __net_init sit_init_net(struct net *net)
 {
+       struct sit_net *sitn = net_generic(net, sit_net_id);
        int err;
-       struct sit_net *sitn;
-
-       err = -ENOMEM;
-       sitn = kzalloc(sizeof(struct sit_net), GFP_KERNEL);
-       if (sitn == NULL)
-               goto err_alloc;
-
-       err = net_assign_generic(net, sit_net_id, sitn);
-       if (err < 0)
-               goto err_assign;
 
        sitn->tunnels[0] = sitn->tunnels_wc;
        sitn->tunnels[1] = sitn->tunnels_l;
@@ -1201,37 +1191,33 @@ err_reg_dev:
        dev_put(sitn->fb_tunnel_dev);
        free_netdev(sitn->fb_tunnel_dev);
 err_alloc_dev:
-       /* nothing */
-err_assign:
-       kfree(sitn);
-err_alloc:
        return err;
 }
 
-static void sit_exit_net(struct net *net)
+static void __net_exit sit_exit_net(struct net *net)
 {
-       struct sit_net *sitn;
+       struct sit_net *sitn = net_generic(net, sit_net_id);
        LIST_HEAD(list);
 
-       sitn = net_generic(net, sit_net_id);
        rtnl_lock();
        sit_destroy_tunnels(sitn, &list);
        unregister_netdevice_queue(sitn->fb_tunnel_dev, &list);
        unregister_netdevice_many(&list);
        rtnl_unlock();
-       kfree(sitn);
 }
 
 static struct pernet_operations sit_net_ops = {
        .init = sit_init_net,
        .exit = sit_exit_net,
+       .id   = &sit_net_id,
+       .size = sizeof(struct sit_net),
 };
 
 static void __exit sit_cleanup(void)
 {
        xfrm4_tunnel_deregister(&sit_handler, AF_INET6);
 
-       unregister_pernet_gen_device(sit_net_id, &sit_net_ops);
+       unregister_pernet_device(&sit_net_ops);
        rcu_barrier(); /* Wait for completion of call_rcu()'s */
 }
 
@@ -1246,7 +1232,7 @@ static int __init sit_init(void)
                return -EAGAIN;
        }
 
-       err = register_pernet_gen_device(&sit_net_id, &sit_net_ops);
+       err = register_pernet_device(&sit_net_ops);
        if (err < 0)
                xfrm4_tunnel_deregister(&sit_handler, AF_INET6);