gre: don't allow to add the same tunnel twice
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Fri, 11 Apr 2014 13:51:18 +0000 (15:51 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 12 Apr 2014 21:03:11 +0000 (17:03 -0400)
Before the patch, it was possible to add two times the same tunnel:
ip l a gre1 type gre remote 10.16.0.121 local 10.16.0.249
ip l a gre2 type gre remote 10.16.0.121 local 10.16.0.249

It was possible, because ip_tunnel_newlink() calls ip_tunnel_find() with the
argument dev->type, which was set only later (when calling ndo_init handler
in register_netdevice()). Let's set this type in the setup handler, which is
called before newlink handler.

Introduced by commit c54419321455 ("GRE: Refactor GRE tunneling code.").

CC: Pravin B Shelar <pshelar@nicira.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ip_gre.c

index ec4f762efda50918254329d9cccfd493533fae4b..94213c89156511d86682b2c3e034f9e5b6ef5ccb 100644 (file)
@@ -463,6 +463,7 @@ static const struct net_device_ops ipgre_netdev_ops = {
 static void ipgre_tunnel_setup(struct net_device *dev)
 {
        dev->netdev_ops         = &ipgre_netdev_ops;
+       dev->type               = ARPHRD_IPGRE;
        ip_tunnel_setup(dev, ipgre_net_id);
 }
 
@@ -501,7 +502,6 @@ static int ipgre_tunnel_init(struct net_device *dev)
        memcpy(dev->dev_addr, &iph->saddr, 4);
        memcpy(dev->broadcast, &iph->daddr, 4);
 
-       dev->type               = ARPHRD_IPGRE;
        dev->flags              = IFF_NOARP;
        dev->priv_flags         &= ~IFF_XMIT_DST_RELEASE;
        dev->addr_len           = 4;