netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@linux-foundation.org>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: <netdev@vger.kernel.org>, <containers@lists.osdl.org>,
	<openib-general@openib.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Subject: Re: [PATCH RFC 2/31] net: Implement a place holder network namespace
Date: Thu, 25 Jan 2007 11:29:32 -0800	[thread overview]
Message-ID: <20070125112932.3506751e@freekitty> (raw)
In-Reply-To: <11697516332484-git-send-email-ebiederm@xmission.com>

On Thu, 25 Jan 2007 12:00:04 -0700
"Eric W. Biederman" <ebiederm@xmission.com> wrote:

> From: Eric W. Biederman <ebiederm@xmission.com> - unquoted
> 
> Many of the changes to the network stack will simply be adding a
> network namespace parameter to function calls or moving variables
> from globals to being per network namespace.  When those variables
> have initializers that cannot statically compute the proper value,
> a function that runs at the creation and destruction of network
> namespaces will need to be registered, and the logic will need to
> be changed to accomidate that.
> 
> Adding unconditional support for these functions ensures that even when
> everything else is compiled out the modified network stack logic will
> continue to run correctly.
> 
> This patch adds struct pernet_operations that has an init (constructor)
> and an exit (destructor) method.  When registered the init method
> is called for every existing namespace, and when unregistered the
> exit method is called for every existing namespace.  When a new
> network namespace is created all of the init methods are called
> in the order in which they were registered, and when a network namespace
> is destroyed the exit methods are called in the reverse order in
> which they were registered.
> 
> There are two distinct types of pernet_operations recognized: subsys and
> device.  At creation all subsys init functions are called before device
> init functions, and at destruction all device exit functions are called
> before subsys exit function.  For other ordering the preservation
> of the order of registration combined with the various kinds of
> kernel initcalls should be sufficient.
> 
> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>

> +
> +static inline net_t get_net(net_t net) { return net; }
> +static inline void put_net(net_t net) {}
> +static inline net_t hold_net(net_t net) { return net; }
> +static inline void release_net(net_t net) {} 
> +
> +#define __per_net_start	((char *)0)
> +#define __per_net_end	((char *)0

Don't use these use NULL

> +
> +static inline int copy_net(int flags, struct task_struct *tsk) { return 0; }
> +
> +/* Don't let the list of network namespaces change */
> +static inline void net_lock(void) {}
> +static inline void net_unlock(void) {}

Don't make all one line, or use #define instead.


> +
> +#define for_each_net(VAR) if (1)
> +
> +extern net_t net_template;
> +
> +#define NET_CREATE	0x0001	/* A network namespace has been created */
> +#define NET_DESTROY	0x0002	/* A network namespace is being destroyed */
> +
> +struct pernet_operations {
> +	struct list_head list;
> +	int (*init)(net_t net);
> +	void (*exit)(net_t net);
> +};
> +
> +extern int register_pernet_subsys(struct pernet_operations *);
> +extern void unregister_pernet_subsys(struct pernet_operations *);
> +extern int register_pernet_device(struct pernet_operations *);
> +extern void unregister_pernet_device(struct pernet_operations *);
> +
> +#endif /* __NET_NET_NAMESPACE_H */
> diff --git a/net/core/Makefile b/net/core/Makefile
> index 73272d5..554dbdc 100644
> --- a/net/core/Makefile
> +++ b/net/core/Makefile
> @@ -3,7 +3,7 @@
>  #
>  
>  obj-y := sock.o request_sock.o skbuff.o iovec.o datagram.o stream.o scm.o \
> -	 gen_stats.o gen_estimator.o
> +	 gen_stats.o gen_estimator.o net_namespace.o
>  
>  obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
>  
> diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> new file mode 100644
> index 0000000..4ae266d
> --- /dev/null
> +++ b/net/core/net_namespace.c
> @@ -0,0 +1,149 @@
> +#include <linux/rtnetlink.h>
> +#include <net/net_namespace.h>
> +
> +/*
> + *	Our network namespace constructor/destructor lists
> + */
> +
> +static LIST_HEAD(pernet_list);
> +static struct list_head *first_device = &pernet_list;
> +static DEFINE_MUTEX(net_mutex);
> +net_t net_template;
> +
> +static int register_pernet_operations(struct list_head *list,
> +				      struct pernet_operations *ops)
> +{
> +	net_t net, undo_net;
> +	int error;
> +
> +	error = 0;
> +	list_add_tail(&ops->list, list);
> +	for_each_net(net) {
> +		if (ops->init) {
> +			error = ops->init(net);
> +			if (error)
> +				goto out_undo;
> +		}
> +	}
> +out:
> +	return error;
> +
> +out_undo:
> +	/* If I have an error cleanup all namespaces I initialized */
> +	list_del(&ops->list);
> +	for_each_net(undo_net) {
> +		if (net_eq(undo_net, net))
> +			goto undone;
> +		if (ops->exit)
> +			ops->exit(undo_net);
> +	}
> +undone:
> +	goto out;
> +}
> +
> +static void unregister_pernet_operations(struct pernet_operations *ops)
> +{
> +	net_t net;
> +
> +	list_del(&ops->list);
> +	for_each_net(net) 
> +		if (ops->exit)
> +			ops->exit(net);
> +}
> +
>

You should use RCU for this because registering/unregistering network
namespaces is obviously a much rarer occurrence than referencing them.
-- 
Stephen Hemminger <shemminger@linux-foundation.org>

  reply	other threads:[~2007-01-25 19:35 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-25 18:55 [RFC PATCH 0/31] An introduction and A path for merging network namespace work Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 1/31] net: Add net_namespace_type.h to allow for per network namespace variables Eric W. Biederman
2007-01-25 20:30   ` Stephen Hemminger
2007-01-25 20:53     ` Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 2/31] net: Implement a place holder network namespace Eric W. Biederman
2007-01-25 19:29   ` Stephen Hemminger [this message]
2007-01-25 20:31     ` Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 3/31] net: Add a network namespace parameter to tasks Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 4/31] net: Add a network namespace tag to struct net_device Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 5/31] net: Add a network namespace parameter to struct sock Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 6/31] net: Add a helper to get a reference to the initial network namespace Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 7/31] net: Make /proc/net per " Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 8/31] net: Make /sys/class/net handle multiple network namespaces Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 9/31] net: Implement the per network namespace sysctl infrastructure Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 10/31] net: Make socket creation namespace safe Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 11/31] net: Initialize the network namespace of network devices Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 12/31] net: Make packet reception network namespace safe Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 13/31] net: Make device event notification " Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 14/31] net: Support multiple network namespaces with netlink Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 15/31] net: Make the loopback device per network namespace Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 16/31] net: Make the device list and device lookups per namespace Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 17/31] net: Factor out __dev_alloc_name from dev_alloc_name Eric W. Biederman
2007-03-05 15:29   ` Benjamin Thery
2007-01-25 19:00 ` [PATCH RFC 18/31] net: Implment network device movement between namespaces Eric W. Biederman
2007-02-28 14:35   ` Daniel Lezcano
2007-02-28 15:12     ` Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 19/31] net: sysfs interface support for moving devices between network namespaces Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 20/31] net: Implement CONFIG_NET_NS Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 21/31] net: Implement the guts of the network namespace infrastructure Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 22/31] net: Add network namespace clone support Eric W. Biederman
2007-02-28 14:42   ` Daniel Lezcano
2007-02-28 15:05     ` Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 23/31] net: Modify all rtnetlink methods to only work in the initial namespace Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 24/31] net: Make rtnetlink network namespace aware Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 25/31] net: Make wireless netlink event generation handle multiple network namespaces Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 26/31] net: Make the netlink methods in rtnetlink " Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 27/31] net: Make the xfrm sysctls per network namespace Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 28/31] net: Make the SOMAXCONN sysctl " Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 29/31] net: Make AF_PACKET handle multiple network namespaces Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 30/31] net: Make AF_UNIX per network namespace safe Eric W. Biederman
2007-01-25 19:00 ` [PATCH RFC 31/31] net: Add etun driver Eric W. Biederman
2007-01-25 19:47   ` Ben Greear
2007-01-25 20:25     ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070125112932.3506751e@freekitty \
    --to=shemminger@linux-foundation.org \
    --cc=containers@lists.osdl.org \
    --cc=ebiederm@xmission.com \
    --cc=netdev@vger.kernel.org \
    --cc=openib-general@openib.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).