* [PATCH net-2.6.26 1/3][TUN][NETNS]: Introduce the tun_net structure.
@ 2008-04-02 13:50 Pavel Emelyanov
2008-04-10 10:29 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Emelyanov @ 2008-04-02 13:50 UTC (permalink / raw)
To: Maxim Krasnyansky, David Miller; +Cc: Linux Netdev List, devel
This is the first step in making tuntap devices work in net
namespaces. The structure mentioned is pointed by struct net
and tun driver will fill this one on load. It will contain only
the tun devices list.
So declare this structure and introduce net init and exit hooks.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
drivers/net/tun.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
include/net/net_namespace.h | 4 ++++
2 files changed, 46 insertions(+), 1 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 7b816a0..3d518b1 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -72,6 +72,9 @@ static int debug;
#endif
/* Network device part of the driver */
+struct tun_net {
+ struct list_head dev_list;
+};
static LIST_HEAD(tun_dev_list);
static const struct ethtool_ops tun_ethtool_ops;
@@ -788,6 +791,29 @@ static struct miscdevice tun_miscdev = {
.fops = &tun_fops,
};
+/* pernet operations */
+
+static int tun_init_net(struct net *net)
+{
+ net->tun = kmalloc(sizeof(struct tun_net), GFP_KERNEL);
+ if (net->tun == NULL)
+ return -ENOMEM;
+
+ INIT_LIST_HEAD(&net->tun->dev_list);
+ return 0;
+}
+
+static void tun_exit_net(struct net *net)
+{
+ kfree(net->tun);
+ net->tun = NULL;
+}
+
+static struct pernet_operations tun_net_ops = {
+ .init = tun_init_net,
+ .exit = tun_exit_net,
+};
+
/* ethtool interface */
static int tun_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
@@ -880,9 +906,23 @@ static int __init tun_init(void)
printk(KERN_INFO "tun: %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
printk(KERN_INFO "tun: %s\n", DRV_COPYRIGHT);
+ ret = register_pernet_device(&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_device(&tun_net_ops);
+err_pernet:
return ret;
}
@@ -899,6 +939,7 @@ static void tun_cleanup(void)
}
rtnl_unlock();
+ unregister_pernet_device(&tun_net_ops);
}
module_init(tun_init);
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index c01d45f..52616fa 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -19,6 +19,7 @@ struct proc_dir_entry;
struct net_device;
struct sock;
struct ctl_table_header;
+struct tun_net;
struct net {
atomic_t count; /* To decided when the network
@@ -57,6 +58,9 @@ struct net {
#ifdef CONFIG_NETFILTER
struct netns_xt xt;
#endif
+
+ /* modules private data */
+ struct tun_net *tun;
};
#ifdef CONFIG_NET
--
1.5.3.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-2.6.26 1/3][TUN][NETNS]: Introduce the tun_net structure.
2008-04-02 13:50 [PATCH net-2.6.26 1/3][TUN][NETNS]: Introduce the tun_net structure Pavel Emelyanov
@ 2008-04-10 10:29 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2008-04-10 10:29 UTC (permalink / raw)
To: xemul; +Cc: maxk, netdev, devel
From: Pavel Emelyanov <xemul@openvz.org>
Date: Wed, 02 Apr 2008 17:50:21 +0400
> This is the first step in making tuntap devices work in net
> namespaces. The structure mentioned is pointed by struct net
> and tun driver will fill this one on load. It will contain only
> the tun devices list.
>
> So declare this structure and introduce net init and exit hooks.
>
> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
I don't want struct net to become a dumping ground for
everything and anything that is networking and might
want to be namespace aware.
We are at the point where some kind of dynamic registry
is in order, don't you think?
I'm dropping these patches for now.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-04-10 10:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-02 13:50 [PATCH net-2.6.26 1/3][TUN][NETNS]: Introduce the tun_net structure Pavel Emelyanov
2008-04-10 10:29 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).