aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/ipv4/ip_gre.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 50972b397a9a..d729ca820931 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -39,6 +39,8 @@
39#include <net/dsfield.h> 39#include <net/dsfield.h>
40#include <net/inet_ecn.h> 40#include <net/inet_ecn.h>
41#include <net/xfrm.h> 41#include <net/xfrm.h>
42#include <net/net_namespace.h>
43#include <net/netns/generic.h>
42 44
43#ifdef CONFIG_IPV6 45#ifdef CONFIG_IPV6
44#include <net/ipv6.h> 46#include <net/ipv6.h>
@@ -122,6 +124,10 @@ static void ipgre_tunnel_setup(struct net_device *dev);
122 124
123static int ipgre_fb_tunnel_init(struct net_device *dev); 125static int ipgre_fb_tunnel_init(struct net_device *dev);
124 126
127static int ipgre_net_id;
128struct ipgre_net {
129};
130
125static struct net_device *ipgre_fb_tunnel_dev; 131static struct net_device *ipgre_fb_tunnel_dev;
126 132
127/* Tunnel hash table */ 133/* Tunnel hash table */
@@ -1275,6 +1281,40 @@ static struct net_protocol ipgre_protocol = {
1275 .err_handler = ipgre_err, 1281 .err_handler = ipgre_err,
1276}; 1282};
1277 1283
1284static int ipgre_init_net(struct net *net)
1285{
1286 int err;
1287 struct ipgre_net *ign;
1288
1289 err = -ENOMEM;
1290 ign = kmalloc(sizeof(struct ipgre_net), GFP_KERNEL);
1291 if (ign == NULL)
1292 goto err_alloc;
1293
1294 err = net_assign_generic(net, ipgre_net_id, ign);
1295 if (err < 0)
1296 goto err_assign;
1297
1298 return 0;
1299
1300err_assign:
1301 kfree(ign);
1302err_alloc:
1303 return err;
1304}
1305
1306static void ipgre_exit_net(struct net *net)
1307{
1308 struct ipgre_net *ign;
1309
1310 ign = net_generic(net, ipgre_net_id);
1311 kfree(ign);
1312}
1313
1314static struct pernet_operations ipgre_net_ops = {
1315 .init = ipgre_init_net,
1316 .exit = ipgre_exit_net,
1317};
1278 1318
1279/* 1319/*
1280 * And now the modules code and kernel interface. 1320 * And now the modules code and kernel interface.
@@ -1302,6 +1342,10 @@ static int __init ipgre_init(void)
1302 1342
1303 if ((err = register_netdev(ipgre_fb_tunnel_dev))) 1343 if ((err = register_netdev(ipgre_fb_tunnel_dev)))
1304 goto err2; 1344 goto err2;
1345
1346 err = register_pernet_gen_device(&ipgre_net_id, &ipgre_net_ops);
1347 if (err < 0)
1348 goto err3;
1305out: 1349out:
1306 return err; 1350 return err;
1307err2: 1351err2:
@@ -1309,6 +1353,9 @@ err2:
1309err1: 1353err1:
1310 inet_del_protocol(&ipgre_protocol, IPPROTO_GRE); 1354 inet_del_protocol(&ipgre_protocol, IPPROTO_GRE);
1311 goto out; 1355 goto out;
1356err3:
1357 unregister_netdevice(ipgre_fb_tunnel_dev);
1358 goto err1;
1312} 1359}
1313 1360
1314static void __exit ipgre_destroy_tunnels(void) 1361static void __exit ipgre_destroy_tunnels(void)
@@ -1333,6 +1380,8 @@ static void __exit ipgre_fini(void)
1333 rtnl_lock(); 1380 rtnl_lock();
1334 ipgre_destroy_tunnels(); 1381 ipgre_destroy_tunnels();
1335 rtnl_unlock(); 1382 rtnl_unlock();
1383
1384 unregister_pernet_gen_device(ipgre_net_id, &ipgre_net_ops);
1336} 1385}
1337 1386
1338module_init(ipgre_init); 1387module_init(ipgre_init);