diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2008-04-16 04:08:53 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-04-16 04:08:53 -0400 |
commit | 59a4c7594bcecef27f072a599e9fb3b18754fc60 (patch) | |
tree | b3098e132ce5373261b8f8ca1a5bb948c07eeaad /net/ipv4 | |
parent | 4597a0ce0849eaa62fc9083c21943e0c434e4135 (diff) |
[GRE]: Introduce empty ipgre_net structure and net init/exit ops.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/ip_gre.c | 49 |
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 | ||
123 | static int ipgre_fb_tunnel_init(struct net_device *dev); | 125 | static int ipgre_fb_tunnel_init(struct net_device *dev); |
124 | 126 | ||
127 | static int ipgre_net_id; | ||
128 | struct ipgre_net { | ||
129 | }; | ||
130 | |||
125 | static struct net_device *ipgre_fb_tunnel_dev; | 131 | static 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 | ||
1284 | static 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 | |||
1300 | err_assign: | ||
1301 | kfree(ign); | ||
1302 | err_alloc: | ||
1303 | return err; | ||
1304 | } | ||
1305 | |||
1306 | static 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 | |||
1314 | static 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; | ||
1305 | out: | 1349 | out: |
1306 | return err; | 1350 | return err; |
1307 | err2: | 1351 | err2: |
@@ -1309,6 +1353,9 @@ err2: | |||
1309 | err1: | 1353 | err1: |
1310 | inet_del_protocol(&ipgre_protocol, IPPROTO_GRE); | 1354 | inet_del_protocol(&ipgre_protocol, IPPROTO_GRE); |
1311 | goto out; | 1355 | goto out; |
1356 | err3: | ||
1357 | unregister_netdevice(ipgre_fb_tunnel_dev); | ||
1358 | goto err1; | ||
1312 | } | 1359 | } |
1313 | 1360 | ||
1314 | static void __exit ipgre_destroy_tunnels(void) | 1361 | static 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 | ||
1338 | module_init(ipgre_init); | 1387 | module_init(ipgre_init); |