Skip to contentSkip to conversation

tunnel: support propagating lower device state

PATCH In review Stephen Hemminger 2 participants 3 messages Dec 27, 2014 – Dec 30, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tunnel: support propagating lower device state

This patch allows propagating the carrier state from lower device to the upper tunnel device. This is similar to how stacked transfer works for VLAN devices.

---
 include/net/ip_tunnels.h |    2 
 net/ipv4/ip_tunnel.c     |  123 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 122 insertions(+), 3 deletions(-)
include/net/ip_tunnels.h +2 -0
@@ -54,6 +54,7 @@ struct ip_tunnel_dst {
 struct ip_tunnel {
 	struct ip_tunnel __rcu	*next;
 	struct hlist_node hash_node;
+	struct hlist_node link_node;
 	struct net_device	*dev;
 	struct net		*net;	/* netns for packet i/o */
 
@@ -115,6 +116,7 @@ struct tnl_ptk_info {
 struct ip_tunnel_net {
 	struct net_device *fb_tunnel_dev;
 	struct hlist_head tunnels[IP_TNL_HASH_SIZE];
+	struct hlist_head *lower_dev;
 };
 
 struct ip_tunnel_encap_ops {
net/ipv4/ip_tunnel.c +120 -3

174 lines not on this page · raw message

#1 lore raw
Quoted 20 lines · Stephen Hemminger
net/ipv4/ip_tunnel.c +9 -0
@@ -982,8 +1045,17 @@ int ip_tunnel_init_net(struct net *net,
        for (i = 0; i < IP_TNL_HASH_SIZE; i++)
                INIT_HLIST_HEAD(&itn->tunnels[i]);
 
+       itn->lower_dev = kcalloc(NETDEV_HASHENTRIES, sizeof(struct hlist_head),
+                                GFP_KERNEL);
+       if (!itn->lower_dev) {
+               kfree(itn->tunnels);
+               return -ENOMEM;
+       }
+
        if (!ops) {
                itn->fb_tunnel_dev = NULL;
+               kfree(itn->tunnels);
+               kfree(itn->lower_dev);
                return 0;
        }
 
@@ -1003,7 +1075,12 @@ int ip_tunnel_init_net(struct net *net,
        }

net/ipv4/ip_tunnel.c int ip_tunnel_init_net(struct net *net, · line 1084

Quoted 10 lines
net/ipv4/ip_tunnel.c +6 -1
        rtnl_unlock();
 
-       return PTR_ERR_OR_ZERO(itn->fb_tunnel_dev);
+       if (IS_ERR(itn->fb_tunnel_dev)) {
+               kfree(itn->tunnels);
+               return PTR_ERR(itn->fb_tunnel_dev);
+       }
+       return 0;
+
 }

Are you sure we really need to free itn->tunnels on failure path? It is not allocated inside ip_tunnel_init_net() anyway.

#2 lore raw
Quoted 4 lines · Cong Wang

Are you sure we really need to free itn->tunnels on failure path? It is not allocated inside ip_tunnel_init_net() anyway.

Also you seem to forget to kfree() itn->lower_dev in ip_tunnel_delete_net().