From: Benjamin Thery <benjamin.thery@bull.net>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: netdev@vger.kernel.org, containers@lists.osdl.org,
openib-general@openib.org
Subject: Re: [PATCH RFC 17/31] net: Factor out __dev_alloc_name from dev_alloc_name
Date: Mon, 05 Mar 2007 16:29:49 +0100 [thread overview]
Message-ID: <45EC376D.9080808@bull.net> (raw)
In-Reply-To: <11697516361051-git-send-email-ebiederm@xmission.com>
Hello Eric,
See comments about __dev_alloc_name() below.
Regards,
Benjamin
Eric W. Biederman wrote:
> From: Eric W. Biederman <ebiederm@xmission.com> - unquoted
>
> When forcibly changing the network namespace of a device
> I need something that can generate a name for the device
> in the new namespace without overwriting the old name.
>
> __dev_alloc_name provides me that functionality.
>
> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
> ---
> net/core/dev.c | 44 +++++++++++++++++++++++++++++++++-----------
> 1 files changed, 33 insertions(+), 11 deletions(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 32fe905..fc0d2af 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -655,9 +655,10 @@ int dev_valid_name(const char *name)
> }
>
> /**
> - * dev_alloc_name - allocate a name for a device
> - * @dev: device
> + * __dev_alloc_name - allocate a name for a device
> + * @net: network namespace to allocate the device name in
> * @name: name format string
> + * @buf: scratch buffer and result name string
> *
> * Passed a format string - eg "lt%d" it will try and find a suitable
> * id. It scans list of devices to build up a free map, then chooses
> @@ -668,18 +669,13 @@ int dev_valid_name(const char *name)
> * Returns the number of the unit assigned or a negative errno code.
> */
>
> -int dev_alloc_name(struct net_device *dev, const char *name)
> +static int __dev_alloc_name(net_t net, const char *name, char buf[IFNAMSIZ])
IMHO the third parameter should be: char *buf
Indeed using "char buf[IFNAMSIZ]" is misleading because later in the
routine sizeof(buf) is used (with an expected result of IFNAMSIZ).
Unfortunately this is no longer the case: sizeof(buf) value is only 4
now (buf is pointer parameter).
This corrupts the registration of network devices (now I understand
why only one of my e1000 showed up after each reboot :).
Also sizeof(buf) should be replaced by IFNAMSIZ in this new routine.
(See below)
> {
> int i = 0;
> - char buf[IFNAMSIZ];
> const char *p;
> const int max_netdevices = 8*PAGE_SIZE;
> long *inuse;
> struct net_device *d;
> - net_t net;
> -
> - BUG_ON(null_net(dev->nd_net));
> - net = dev->nd_net;
>
> p = strnchr(name, IFNAMSIZ-1, '%');
> if (p) {
> @@ -713,10 +709,8 @@ int dev_alloc_name(struct net_device *dev, const char *name)
> }
>
> snprintf(buf, sizeof(buf), name, i);
Replace "snprintf(buf, IFNAMSIZ, name, i);" or i will never be
appended to name and all your ethernet devices will all try to
register the name "eth".
There is another occurence of "snprintf(buf, sizeof(buf), ...)" to
replace in the for loop above.
> - if (!__dev_get_by_name(net, buf)) {
> - strlcpy(dev->name, buf, IFNAMSIZ);
> + if (!__dev_get_by_name(net, buf))
> return i;
> - }
>
> /* It is possible to run out of possible slots
> * when the name is long and there isn't enough space left
> @@ -725,6 +719,34 @@ int dev_alloc_name(struct net_device *dev, const char *name)
> return -ENFILE;
> }
>
> +/**
> + * dev_alloc_name - allocate a name for a device
> + * @dev: device
> + * @name: name format string
> + *
> + * Passed a format string - eg "lt%d" it will try and find a suitable
> + * id. It scans list of devices to build up a free map, then chooses
> + * the first empty slot. The caller must hold the dev_base or rtnl lock
> + * while allocating the name and adding the device in order to avoid
> + * duplicates.
> + * Limited to bits_per_byte * page size devices (ie 32K on most platforms).
> + * Returns the number of the unit assigned or a negative errno code.
> + */
> +
> +int dev_alloc_name(struct net_device *dev, const char *name)
> +{
> + char buf[IFNAMSIZ];
> + net_t net;
> + int ret;
> +
> + BUG_ON(null_net(dev->nd_net));
> + net = dev->nd_net;
> + ret = __dev_alloc_name(net, name, buf);
> + if (ret >= 0)
> + strlcpy(dev->name, buf, IFNAMSIZ);
> + return ret;
> +}
> +
>
> /**
> * dev_change_name - change name of a device
--
B e n j a m i n T h e r y - BULL/DT/Open Software R&D
http://www.bull.com
next prev parent reply other threads:[~2007-03-05 15:31 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
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 [this message]
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=45EC376D.9080808@bull.net \
--to=benjamin.thery@bull.net \
--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).