Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 90742
b: refs/heads/master
c: 79d1760
h: refs/heads/master
v: v3
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Apr 16, 2008
1 parent 084e8e8 commit 0bfbdaa
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 17515408a15fa51c553e67c415502e785145cd7f
refs/heads/master: 79d1760491a25bfc70aeac363142cadd3f1cda71
53 changes: 52 additions & 1 deletion trunk/drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <linux/if_tun.h>
#include <linux/crc32.h>
#include <net/net_namespace.h>
#include <net/netns/generic.h>

#include <asm/system.h>
#include <asm/uaccess.h>
Expand Down Expand Up @@ -106,6 +107,11 @@ struct tun_struct {

/* Network device part of the driver */

static unsigned int tun_net_id;
struct tun_net {
struct list_head dev_list;
};

static LIST_HEAD(tun_dev_list);
static const struct ethtool_ops tun_ethtool_ops;

Expand Down Expand Up @@ -909,16 +915,60 @@ static const struct ethtool_ops tun_ethtool_ops = {
.set_rx_csum = tun_set_rx_csum
};

static int tun_init_net(struct net *net)
{
struct tun_net *tn;

tn = kmalloc(sizeof(*tn), GFP_KERNEL);
if (tn == NULL)
return -ENOMEM;

INIT_LIST_HEAD(&tn->dev_list);

if (net_assign_generic(net, tun_net_id, tn)) {
kfree(tn);
return -ENOMEM;
}

return 0;
}

static void tun_exit_net(struct net *net)
{
struct tun_net *tn;

tn = net_generic(net, tun_net_id);
kfree(tn);
}

static struct pernet_operations tun_net_ops = {
.init = tun_init_net,
.exit = tun_exit_net,
};

static int __init tun_init(void)
{
int ret = 0;

printk(KERN_INFO "tun: %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
printk(KERN_INFO "tun: %s\n", DRV_COPYRIGHT);

ret = register_pernet_gen_device(&tun_net_id, &tun_net_ops);
if (ret) {
printk(KERN_ERR "tun: Can't register pernet ops\n");
goto err_pernet;
}

ret = misc_register(&tun_miscdev);
if (ret)
if (ret) {
printk(KERN_ERR "tun: Can't register misc device %d\n", TUN_MINOR);
goto err_misc;
}
return 0;

err_misc:
unregister_pernet_gen_device(tun_net_id, &tun_net_ops);
err_pernet:
return ret;
}

Expand All @@ -935,6 +985,7 @@ static void tun_cleanup(void)
}
rtnl_unlock();

unregister_pernet_gen_device(tun_net_id, &tun_net_ops);
}

module_init(tun_init);
Expand Down

0 comments on commit 0bfbdaa

Please sign in to comment.