aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMartin KaFai Lau <kafai@fb.com>2015-09-15 17:30:05 -0400
committerDavid S. Miller <davem@davemloft.net>2015-09-15 17:53:04 -0400
commita3c119d392d7d7c68865fe76f5732ca9b8164d68 (patch)
tree1fe4dfa29c0e14c0fe0b97807633a9d81238ffb1 /net
parente8684c88774c0ddfeefdbed0aa469b25b9962f3e (diff)
ipv6: Refactor common ip6gre_tunnel_init codes
It is a prep work to fix the dst_entry refcnt bugs in ip6_tunnel. This patch refactors some common init codes used by both ip6gre_tunnel_init and ip6gre_tap_init. Signed-off-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/ipv6/ip6_gre.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 4038c694ec03..af60d46129c1 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1245,7 +1245,7 @@ static void ip6gre_tunnel_setup(struct net_device *dev)
1245 netif_keep_dst(dev); 1245 netif_keep_dst(dev);
1246} 1246}
1247 1247
1248static int ip6gre_tunnel_init(struct net_device *dev) 1248static int ip6gre_tunnel_init_common(struct net_device *dev)
1249{ 1249{
1250 struct ip6_tnl *tunnel; 1250 struct ip6_tnl *tunnel;
1251 1251
@@ -1255,16 +1255,30 @@ static int ip6gre_tunnel_init(struct net_device *dev)
1255 tunnel->net = dev_net(dev); 1255 tunnel->net = dev_net(dev);
1256 strcpy(tunnel->parms.name, dev->name); 1256 strcpy(tunnel->parms.name, dev->name);
1257 1257
1258 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1259 if (!dev->tstats)
1260 return -ENOMEM;
1261
1262 return 0;
1263}
1264
1265static int ip6gre_tunnel_init(struct net_device *dev)
1266{
1267 struct ip6_tnl *tunnel;
1268 int ret;
1269
1270 ret = ip6gre_tunnel_init_common(dev);
1271 if (ret)
1272 return ret;
1273
1274 tunnel = netdev_priv(dev);
1275
1258 memcpy(dev->dev_addr, &tunnel->parms.laddr, sizeof(struct in6_addr)); 1276 memcpy(dev->dev_addr, &tunnel->parms.laddr, sizeof(struct in6_addr));
1259 memcpy(dev->broadcast, &tunnel->parms.raddr, sizeof(struct in6_addr)); 1277 memcpy(dev->broadcast, &tunnel->parms.raddr, sizeof(struct in6_addr));
1260 1278
1261 if (ipv6_addr_any(&tunnel->parms.raddr)) 1279 if (ipv6_addr_any(&tunnel->parms.raddr))
1262 dev->header_ops = &ip6gre_header_ops; 1280 dev->header_ops = &ip6gre_header_ops;
1263 1281
1264 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1265 if (!dev->tstats)
1266 return -ENOMEM;
1267
1268 return 0; 1282 return 0;
1269} 1283}
1270 1284
@@ -1460,19 +1474,16 @@ static void ip6gre_netlink_parms(struct nlattr *data[],
1460static int ip6gre_tap_init(struct net_device *dev) 1474static int ip6gre_tap_init(struct net_device *dev)
1461{ 1475{
1462 struct ip6_tnl *tunnel; 1476 struct ip6_tnl *tunnel;
1477 int ret;
1463 1478
1464 tunnel = netdev_priv(dev); 1479 ret = ip6gre_tunnel_init_common(dev);
1480 if (ret)
1481 return ret;
1465 1482
1466 tunnel->dev = dev; 1483 tunnel = netdev_priv(dev);
1467 tunnel->net = dev_net(dev);
1468 strcpy(tunnel->parms.name, dev->name);
1469 1484
1470 ip6gre_tnl_link_config(tunnel, 1); 1485 ip6gre_tnl_link_config(tunnel, 1);
1471 1486
1472 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1473 if (!dev->tstats)
1474 return -ENOMEM;
1475
1476 return 0; 1487 return 0;
1477} 1488}
1478 1489