ipv4: Don't drop redirected route cache entry unless PTMU actually expired
[safe/jmp/linux-2.6] / net / ipv4 / ipip.c
index 3bd6998..2f302d3 100644 (file)
 #define HASH_SIZE  16
 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
 
-static int ipip_net_id;
+static int ipip_net_id __read_mostly;
 struct ipip_net {
        struct ip_tunnel *tunnels_r_l[HASH_SIZE];
        struct ip_tunnel *tunnels_r[HASH_SIZE];
@@ -130,7 +130,6 @@ struct ipip_net {
        struct net_device *fb_tunnel_dev;
 };
 
-static void ipip_fb_tunnel_init(struct net_device *dev);
 static void ipip_tunnel_init(struct net_device *dev);
 static void ipip_tunnel_setup(struct net_device *dev);
 
@@ -446,25 +445,27 @@ static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
                goto tx_error;
        }
 
-       if (tiph->frag_off)
+       df |= old_iph->frag_off & htons(IP_DF);
+
+       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 (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;
+               }
 
-       df |= (old_iph->frag_off&htons(IP_DF));
+               if (skb_dst(skb))
+                       skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
 
-       if ((old_iph->frag_off&htons(IP_DF)) && mtu < ntohs(old_iph->tot_len)) {
-               icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
-               ip_rt_put(rt);
-               goto tx_error;
+               if ((old_iph->frag_off & htons(IP_DF)) &&
+                   mtu < ntohs(old_iph->tot_len)) {
+                       icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
+                                 htonl(mtu));
+                       ip_rt_put(rt);
+                       goto tx_error;
+               }
        }
 
        if (tunnel->err_count > 0) {
@@ -728,7 +729,7 @@ static void ipip_tunnel_init(struct net_device *dev)
        ipip_tunnel_bind_dev(dev);
 }
 
-static void ipip_fb_tunnel_init(struct net_device *dev)
+static void __net_init ipip_fb_tunnel_init(struct net_device *dev)
 {
        struct ip_tunnel *tunnel = netdev_priv(dev);
        struct iphdr *iph = &tunnel->parms.iph;
@@ -754,33 +755,27 @@ static struct xfrm_tunnel ipip_handler = {
 static const char banner[] __initconst =
        KERN_INFO "IPv4 over IPv4 tunneling driver\n";
 
-static void ipip_destroy_tunnels(struct ipip_net *ipn)
+static void ipip_destroy_tunnels(struct ipip_net *ipn, struct list_head *head)
 {
        int prio;
 
        for (prio = 1; prio < 4; prio++) {
                int h;
                for (h = 0; h < HASH_SIZE; h++) {
-                       struct ip_tunnel *t;
-                       while ((t = ipn->tunnels[prio][h]) != NULL)
-                               unregister_netdevice(t->dev);
+                       struct ip_tunnel *t = ipn->tunnels[prio][h];
+
+                       while (t != NULL) {
+                               unregister_netdevice_queue(t->dev, head);
+                               t = t->next;
+                       }
                }
        }
 }
 
-static int ipip_init_net(struct net *net)
+static int __net_init ipip_init_net(struct net *net)
 {
+       struct ipip_net *ipn = net_generic(net, ipip_net_id);
        int err;
-       struct ipip_net *ipn;
-
-       err = -ENOMEM;
-       ipn = kzalloc(sizeof(struct ipip_net), GFP_KERNEL);
-       if (ipn == NULL)
-               goto err_alloc;
-
-       err = net_assign_generic(net, ipip_net_id, ipn);
-       if (err < 0)
-               goto err_assign;
 
        ipn->tunnels[0] = ipn->tunnels_wc;
        ipn->tunnels[1] = ipn->tunnels_l;
@@ -807,27 +802,26 @@ err_reg_dev:
        free_netdev(ipn->fb_tunnel_dev);
 err_alloc_dev:
        /* nothing */
-err_assign:
-       kfree(ipn);
-err_alloc:
        return err;
 }
 
-static void ipip_exit_net(struct net *net)
+static void __net_exit ipip_exit_net(struct net *net)
 {
-       struct ipip_net *ipn;
+       struct ipip_net *ipn = net_generic(net, ipip_net_id);
+       LIST_HEAD(list);
 
-       ipn = net_generic(net, ipip_net_id);
        rtnl_lock();
-       ipip_destroy_tunnels(ipn);
-       unregister_netdevice(ipn->fb_tunnel_dev);
+       ipip_destroy_tunnels(ipn, &list);
+       unregister_netdevice_queue(ipn->fb_tunnel_dev, &list);
+       unregister_netdevice_many(&list);
        rtnl_unlock();
-       kfree(ipn);
 }
 
 static struct pernet_operations ipip_net_ops = {
        .init = ipip_init_net,
        .exit = ipip_exit_net,
+       .id   = &ipip_net_id,
+       .size = sizeof(struct ipip_net),
 };
 
 static int __init ipip_init(void)
@@ -836,15 +830,14 @@ static int __init ipip_init(void)
 
        printk(banner);
 
-       if (xfrm4_tunnel_register(&ipip_handler, AF_INET)) {
+       err = register_pernet_device(&ipip_net_ops);
+       if (err < 0)
+               return err;
+       err = xfrm4_tunnel_register(&ipip_handler, AF_INET);
+       if (err < 0) {
+               unregister_pernet_device(&ipip_net_ops);
                printk(KERN_INFO "ipip init: can't register tunnel\n");
-               return -EAGAIN;
        }
-
-       err = register_pernet_gen_device(&ipip_net_id, &ipip_net_ops);
-       if (err)
-               xfrm4_tunnel_deregister(&ipip_handler, AF_INET);
-
        return err;
 }
 
@@ -853,7 +846,7 @@ static void __exit ipip_fini(void)
        if (xfrm4_tunnel_deregister(&ipip_handler, AF_INET))
                printk(KERN_INFO "ipip close: can't deregister tunnel\n");
 
-       unregister_pernet_gen_device(ipip_net_id, &ipip_net_ops);
+       unregister_pernet_device(&ipip_net_ops);
 }
 
 module_init(ipip_init);