sit: fix percpu stats accounting
authorEric Dumazet <eric.dumazet@gmail.com>
Tue, 28 Sep 2010 02:17:58 +0000 (02:17 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 29 Sep 2010 20:25:21 +0000 (13:25 -0700)
commit 15fc1f7056ebd (sit: percpu stats accounting) forgot the fallback
tunnel case (sit0), and can crash pretty fast.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/sit.c

index 011ecf55d34e9a6659e3522978ebf693bcea6092..2cb646079237017a83a4671a12c7d1d2cdc976b6 100644 (file)
@@ -1160,7 +1160,7 @@ static int ipip6_tunnel_init(struct net_device *dev)
        return 0;
 }
 
-static void __net_init ipip6_fb_tunnel_init(struct net_device *dev)
+static int __net_init ipip6_fb_tunnel_init(struct net_device *dev)
 {
        struct ip_tunnel *tunnel = netdev_priv(dev);
        struct iphdr *iph = &tunnel->parms.iph;
@@ -1175,8 +1175,12 @@ static void __net_init ipip6_fb_tunnel_init(struct net_device *dev)
        iph->ihl                = 5;
        iph->ttl                = 64;
 
+       dev->tstats = alloc_percpu(struct pcpu_tstats);
+       if (!dev->tstats)
+               return -ENOMEM;
        dev_hold(dev);
        sitn->tunnels_wc[0]     = tunnel;
+       return 0;
 }
 
 static struct xfrm_tunnel sit_handler __read_mostly = {
@@ -1220,7 +1224,10 @@ static int __net_init sit_init_net(struct net *net)
        }
        dev_net_set(sitn->fb_tunnel_dev, net);
 
-       ipip6_fb_tunnel_init(sitn->fb_tunnel_dev);
+       err = ipip6_fb_tunnel_init(sitn->fb_tunnel_dev);
+       if (err)
+               goto err_dev_free;
+
        ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn);
 
        if ((err = register_netdev(sitn->fb_tunnel_dev)))
@@ -1230,7 +1237,8 @@ static int __net_init sit_init_net(struct net *net)
 
 err_reg_dev:
        dev_put(sitn->fb_tunnel_dev);
-       free_netdev(sitn->fb_tunnel_dev);
+err_dev_free:
+       ipip6_dev_free(sitn->fb_tunnel_dev);
 err_alloc_dev:
        return err;
 }