netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Tourrilhes <jt@bougret.hpl.hp.com>
To: Jeff Garzik <jgarzik@pobox.com>,
	"David S. Miller" <davem@redhat.com>,
	netdev@oss.sgi.com,
	Linux kernel mailing list <linux-kernel@vger.kernel.org>
Subject: [PATCH 2.6.X] SIOCSIFNAME wilcard support
Date: Mon, 12 Jan 2004 15:43:32 -0800	[thread overview]
Message-ID: <20040112234332.GA1785@bougret.hpl.hp.com> (raw)

	Hi Jeff & Dave,

	The trivial patch below implement SIOCSIFNAME wilcard
support. With the appropriate version of nameif (please ask me), you
can do binding of this kind :

------------------------------------------------
# AMD Lance cards (pcnet32)
amd*		00:10:83:*
# Intersil PrismGT cards (prism54)
wlan*		00:04:E2:*
------------------------------------------------
	Of course, this make sense mostly for wireless cards. There is
currently lot's od debate about the use of 'ethX' and 'wlanX' names
for wireless driver, and some confusion resulting from that. Each
driver use a different naming style, and some have module parameters
to change the name prefix. Therefore, I think most distro and driver
authors would benefit from such a feature.
	It would also enable to emulate the naming conventions of
*BSD, but I don't know if I should list that as an argument ;-)

	I've run this patch for a while without any adverse
effect. Please forward upstream ;-)

	Jean

P.S. : Don't miss the second part of the change, we absolutely need to
return the new name to user space.

-------------------------------------------------------------

diff -u -p linux/net/core/dev.j1.c linux/net/core/dev.c
--- linux/net/core/dev.j1.c	Wed Dec  3 18:39:09 2003
+++ linux/net/core/dev.c	Wed Dec  3 18:54:36 2003
@@ -2344,15 +2344,29 @@ static int dev_ifsioc(struct ifreq *ifr,
 			if (dev->flags & IFF_UP)
 				return -EBUSY;
 			ifr->ifr_newname[IFNAMSIZ-1] = '\0';
-			if (__dev_get_by_name(ifr->ifr_newname))
-				return -EEXIST;
-			err = class_device_rename(&dev->class_dev, 
-						  ifr->ifr_newname);
-			if (!err) {
+			/* Check if name contains a wildcard */
+			if (strchr(ifr->ifr_newname, '%')) {
+				int ret;
+				/* Find a free name based on format.
+				 * dev_alloc_name() replaces "%d" with at max
+				 * 2 digits, so no name overflow. - Jean II */
+				ret = dev_alloc_name(dev, ifr->ifr_newname);
+				if (ret < 0)
+					return ret;
+				/* Copy the new name back to caller. */
+				strncpy(ifr->ifr_newname, dev->name, IFNAMSIZ);
+			} else {
+				if (__dev_get_by_name(ifr->ifr_newname))
+					return -EEXIST;
 				strlcpy(dev->name, ifr->ifr_newname, IFNAMSIZ);
-
+			}
+			err = class_device_rename(&dev->class_dev, dev->name);
+			if (!err) {
 				notifier_call_chain(&netdev_chain,
 						    NETDEV_CHANGENAME, dev);
+			} else {
+				/* Restore original name */
+				strlcpy(dev->name, ifr->ifr_name, IFNAMSIZ);
 			}
 			return err;
 
@@ -2485,6 +2499,7 @@ int dev_ioctl(unsigned int cmd, void *ar
 		 *	- require strict serialization.
 		 *	- return a value
 		 */
+		case SIOCSIFNAME:
 		case SIOCGMIIPHY:
 		case SIOCGMIIREG:
 			if (!capable(CAP_NET_ADMIN))
@@ -2518,7 +2533,6 @@ int dev_ioctl(unsigned int cmd, void *ar
 		case SIOCDELMULTI:
 		case SIOCSIFHWBROADCAST:
 		case SIOCSIFTXQLEN:
-		case SIOCSIFNAME:
 		case SIOCSMIIREG:
 		case SIOCBONDENSLAVE:
 		case SIOCBONDRELEASE:

             reply	other threads:[~2004-01-12 23:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-12 23:43 Jean Tourrilhes [this message]
2004-01-13 22:22 ` [PATCH 2.6.X] SIOCSIFNAME wilcard suppor & name validation Stephen Hemminger
2004-01-13 22:27   ` Jean Tourrilhes
2004-01-14  0:21   ` David S. Miller
2004-01-15  0:13     ` Stephen Hemminger
2004-01-15  0:17       ` Jean Tourrilhes
2004-01-15  8:49       ` David S. Miller

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=20040112234332.GA1785@bougret.hpl.hp.com \
    --to=jt@bougret.hpl.hp.com \
    --cc=davem@redhat.com \
    --cc=jgarzik@pobox.com \
    --cc=jt@hpl.hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@oss.sgi.com \
    /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).