Skip to contentSkip to conversation

SIOCSIFNAME wildcard support (re-resend)

PATCH Applied Jean Tourrilhes 2 participants 3 messages Feb 9, 2005 – Feb 16, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 SIOCSIFNAME wildcard support (re-resend)

Hi all,

Just to make sure everybody seen it twice...

Jean

----- Forwarded message from jt -----

Subject: [PATCH 2.4] SIOCSIFNAME wildcard support (resend)
E-mail: [email protected]

Hi Marcelo,

I did not receive any feedback on this e-mail, so I assume it
was lost on the way. Would you mind pushing that in 2.4.x ?

	Thanks...

	Jean

----- Forwarded message from jt -----

Subject: [PATCH 2.4] SIOCSIFNAME wildcard support
E-mail: [email protected]

Hi Marcelo,

This patch adds wildcard support for the SIOCSIFNAME ioctl,
like what was done in 2.6.1. SIOCSIFNAME allow a user space tool to change network interface names (such as nameif, ifrename, or ip link), this patch allow those tools to specify a pattern, such as "eth%d" or "wlan%d", and the kernel use the lowest available slot.
The reason I'm sending you this patch is that I've got some
2.4.X users who requested the feature...
This patch was initially done for 2.4.23, and I rediffed and
retested with 2.4.29. It's somewhat different from the patch Stephen and me added to 2.6.1, because the netdev init code is different and also this patch is more conservative.

	Have fun...

	Jean

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

net/core/dev.c renamed from net/core/dev.j1.c +21 -5
diff -u -p linux/net/core/dev.j1.c linux/net/core/dev.c
@@ -2179,10 +2179,26 @@ static int dev_ifsioc(struct ifreq *ifr,
 		case SIOCSIFNAME:
 			if (dev->flags&IFF_UP)
 				return -EBUSY;
-			if (__dev_get_by_name(ifr->ifr_newname))
-				return -EEXIST;
-			memcpy(dev->name, ifr->ifr_newname, IFNAMSIZ);
-			dev->name[IFNAMSIZ-1] = 0;
+			/* Check if name contains a wildcard */
+			if (strchr(ifr->ifr_newname, '%')) {
+				char format[IFNAMSIZ + 1];
+				int ret;
+				memcpy(format, ifr->ifr_newname, IFNAMSIZ);
+				format[IFNAMSIZ-1] = 0;
+				/* 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, format);
+				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;
+				memcpy(dev->name, ifr->ifr_newname, IFNAMSIZ);
+				dev->name[IFNAMSIZ-1] = 0;
+			}
 			notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev);
 			return 0;
 
@@ -2315,6 +2331,7 @@ int dev_ioctl(unsigned int cmd, void *ar
 		 *	- return a value
 		 */
 		 
+		case SIOCSIFNAME:
 		case SIOCGMIIPHY:
 		case SIOCGMIIREG:
 			if (!capable(CAP_NET_ADMIN))
@@ -2350,7 +2367,6 @@ int dev_ioctl(unsigned int cmd, void *ar
 		case SIOCDELMULTI:
 		case SIOCSIFHWBROADCAST:
 		case SIOCSIFTXQLEN:
-		case SIOCSIFNAME:
 		case SIOCSMIIREG:
 		case SIOCBONDENSLAVE:
 		case SIOCBONDRELEASE:
maintainer Applied
#1 lore raw
Quoted 1 line · On Tue, 8 Feb 2005 16:27:47 -0800 Jean Tourrilhes <[email protected]> wrote:

Just to make sure everybody seen it twice...

Applied, thanks for being so patient as I was processing my huge networking patch backlog after moving last weekend.

#2 lore raw
Quoted 7 lines · David S. Miller
Quoted 1 line · On Tue, 8 Feb 2005 16:27:47 -0800 Jean Tourrilhes <[email protected]> wrote:

Just to make sure everybody seen it twice...

Applied, thanks for being so patient as I was processing my huge networking patch backlog after moving last weekend.

Don't worry, people complain about me being so slow ;-)

Jean