linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* swapping interface names (again)
@ 2006-06-24  1:58 MS Colclough
  2006-06-24  7:59 ` Marco d'Itri
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: MS Colclough @ 2006-06-24  1:58 UTC (permalink / raw)
  To: linux-hotplug

Sorry to labour this point.  I understand that swapping eth0 and eth1
(should that prove necessary because of the initial ordering) can be
done by an application like ifrename, by making use of a temporary name
and invoking dev_change_name() in the kernel.  But does the recent
answer:
On 2006-06-15 06:29, Kay Sievers wrote:
...
 > You probably try to rename the interface to an already existing
 > name. If you want to swap names, you have to give one interface
 > a temporary name first.

imply that the whole process can be done by some udev rules that run
at boot time?  If so, how please?

Personally, I am happier with meaningful names, which I know how to
substitute using udev, but we have some users (and scripts!) who
would be happier with the old names, nailed to particular interfaces.

Thanks,
Mark
Zenwalk udev warrior

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: swapping interface names (again)
  2006-06-24  1:58 swapping interface names (again) MS Colclough
@ 2006-06-24  7:59 ` Marco d'Itri
  2006-06-24 20:02 ` juuso.alasuutari
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Marco d'Itri @ 2006-06-24  7:59 UTC (permalink / raw)
  To: linux-hotplug

On Jun 24, MS Colclough <m.s.colclough@bham.ac.uk> wrote:

> imply that the whole process can be done by some udev rules that run
> at boot time?  If so, how please?
Look at the Debian package for a simple script which generates rules on
demand.

-- 
ciao,
Marco

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: swapping interface names (again)
  2006-06-24  1:58 swapping interface names (again) MS Colclough
  2006-06-24  7:59 ` Marco d'Itri
@ 2006-06-24 20:02 ` juuso.alasuutari
  2006-06-25  3:07 ` Alexander E. Patrakov
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: juuso.alasuutari @ 2006-06-24 20:02 UTC (permalink / raw)
  To: linux-hotplug

I accidentally only sent my message to Marco. Here it is for the list also:

Quoting Marco d'Itri <md@Linux.IT>:

> On Jun 24, MS Colclough <m.s.colclough@bham.ac.uk> wrote:
>
> > imply that the whole process can be done by some udev rules that run
> > at boot time?  If so, how please?
> Look at the Debian package for a simple script which generates rules on
> demand.

It's of course easy to write a script that creates something like
z99-network.rules. But what should it contain?

If I have eth0 and eth1, and want to swap their names, I first need to rename
them to e.g. tempeth0 and tempeth1, and then to eth1 and eth0. But what kind of
rule would recognise when all temporary names are created and apply the final
ones?

udevmonitor doesn't show any event where the interface is renamed. The last line
is "add@/class/net/eth0", even though that interface was renamed tempeth0 by a
rule.

I tried to catch the renaming event with 'KERNEL="tempeth0", NAME="eth1"' and
'NAME="tempeth0", NAME="eth1"', but they didn't work. And even if they did,
how could I be sure that the original eth1 wasn't still around messing things
up? Both temp interface names would need to be set.

Any ideas?

Thanks,
Juuso

----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: swapping interface names (again)
  2006-06-24  1:58 swapping interface names (again) MS Colclough
  2006-06-24  7:59 ` Marco d'Itri
  2006-06-24 20:02 ` juuso.alasuutari
@ 2006-06-25  3:07 ` Alexander E. Patrakov
  2006-06-25  8:35 ` Marco d'Itri
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Alexander E. Patrakov @ 2006-06-25  3:07 UTC (permalink / raw)
  To: linux-hotplug

juuso.alasuutari@tamperelainen.org wrote:
> I accidentally only sent my message to Marco. Here it is for the list also:
> 
> Quoting Marco d'Itri <md@Linux.IT>:
> 
>> On Jun 24, MS Colclough <m.s.colclough@bham.ac.uk> wrote:
>>
>>> imply that the whole process can be done by some udev rules that run
>>> at boot time?  If so, how please?
>> Look at the Debian package for a simple script which generates rules on
>> demand.
> 
> It's of course easy to write a script that creates something like
> z99-network.rules. But what should it contain?
> 
> If I have eth0 and eth1, and want to swap their names, I first need to rename
> them to e.g. tempeth0 and tempeth1, and then to eth1 and eth0. But what kind of
> rule would recognise when all temporary names are created and apply the final
> ones?

Don't look at the Debian package. It is very likely to contain this problem, 
because for my single-card setup, Debian udev 0.093-1 writes:

# This file was automatically generated by the /lib/udev/write_net_rules
# program, probably run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.

# PCI device 10ec:8139 (8139too)
SUBSYSTEM="net", DRIVER="?*", SYSFS{address}="00:e0:4c:7c:4a:d3", NAME="eth0"

Of course this will break if I a new card in such a way (read: PCI slot) so that 
without this rule it becomes eth0. Then this rule will attempt to rename my old 
card to eth0, and boom... there is already eth0.

And I don't know any solution that allows eth%d as a final name.

-- 
Alexander E. Patrakov

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: swapping interface names (again)
  2006-06-24  1:58 swapping interface names (again) MS Colclough
                   ` (2 preceding siblings ...)
  2006-06-25  3:07 ` Alexander E. Patrakov
@ 2006-06-25  8:35 ` Marco d'Itri
  2006-06-25 12:18 ` juuso.alasuutari
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Marco d'Itri @ 2006-06-25  8:35 UTC (permalink / raw)
  To: linux-hotplug

On Jun 25, "Alexander E. Patrakov" <patrakov@ums.usu.ru> wrote:

> Don't look at the Debian package. It is very likely to contain this problem, 
> because for my single-card setup, Debian udev 0.093-1 writes:
It's not, because there is an Ubuntu-derived patch which prevents this.
I have been shipping it since february with no issues, so maybe it's
time to consider merging it.

-- 
ciao,
Marco

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: swapping interface names (again)
  2006-06-24  1:58 swapping interface names (again) MS Colclough
                   ` (3 preceding siblings ...)
  2006-06-25  8:35 ` Marco d'Itri
@ 2006-06-25 12:18 ` juuso.alasuutari
  2006-06-25 12:21 ` Marco d'Itri
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: juuso.alasuutari @ 2006-06-25 12:18 UTC (permalink / raw)
  To: linux-hotplug

Quoting Marco d'Itri <md@Linux.IT>:

> On Jun 25, "Alexander E. Patrakov" <patrakov@ums.usu.ru> wrote:
>
> > Don't look at the Debian package. It is very likely to contain this
> problem,
> > because for my single-card setup, Debian udev 0.093-1 writes:
> It's not, because there is an Ubuntu-derived patch which prevents this.
> I have been shipping it since february with no issues, so maybe it's
> time to consider merging it.

That would be useful. Does the patch really allow normal interface naming rules
(as described in the Writing udev rules document) to bind to existing names
without any extra steps needed, or have I not understood this correctly?

I'd be happy to try the patch, but I'm not C-literate and couldn't tell from the
debian diff which parts of it are relevant for this feature. Is the patch
available as separate file somewhere?

Juuso

----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: swapping interface names (again)
  2006-06-24  1:58 swapping interface names (again) MS Colclough
                   ` (4 preceding siblings ...)
  2006-06-25 12:18 ` juuso.alasuutari
@ 2006-06-25 12:21 ` Marco d'Itri
  2006-06-25 14:39 ` MS Colclough
  2006-06-26  7:46 ` Scott James Remnant
  7 siblings, 0 replies; 9+ messages in thread
From: Marco d'Itri @ 2006-06-25 12:21 UTC (permalink / raw)
  To: linux-hotplug

On Jun 25, juuso.alasuutari@tamperelainen.org wrote:

> That would be useful. Does the patch really allow normal interface naming rules
> (as described in the Writing udev rules document) to bind to existing names
> without any extra steps needed, or have I not understood this correctly?
Yes.

> I'd be happy to try the patch, but I'm not C-literate and couldn't tell from the
> debian diff which parts of it are relevant for this feature. Is the patch
> available as separate file somewhere?
zcat udev*.diff.gz | patch -p1
cd debian/patches/

-- 
ciao,
Marco

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: swapping interface names (again)
  2006-06-24  1:58 swapping interface names (again) MS Colclough
                   ` (5 preceding siblings ...)
  2006-06-25 12:21 ` Marco d'Itri
@ 2006-06-25 14:39 ` MS Colclough
  2006-06-26  7:46 ` Scott James Remnant
  7 siblings, 0 replies; 9+ messages in thread
From: MS Colclough @ 2006-06-25 14:39 UTC (permalink / raw)
  To: linux-hotplug

I also found the Ubuntu patch (70-ifrename.patch).  Taking just the part
that deals with the rename_net_if() function, I found it to be exactly
what I want.  A pair of rules like
... SYSFS{address}="00:16:17:5a:e5:7e", NAME="eth0"
... SYSFS{address}="00:40:95:46:f4:16", NAME="eth1"
enforce the necessary stability, swapping the kernel names on occasions
when that proves necessary.

I would certainly like to see this merged with udev.  It's certainly
better than me telling users "you can have any names you like, except
those you are used to".

Thanks,   Mark

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: swapping interface names (again)
  2006-06-24  1:58 swapping interface names (again) MS Colclough
                   ` (6 preceding siblings ...)
  2006-06-25 14:39 ` MS Colclough
@ 2006-06-26  7:46 ` Scott James Remnant
  7 siblings, 0 replies; 9+ messages in thread
From: Scott James Remnant @ 2006-06-26  7:46 UTC (permalink / raw)
  To: linux-hotplug


[-- Attachment #1.1.1: Type: text/plain, Size: 701 bytes --]

On Sun, 2006-06-25 at 10:35 +0200, Marco d'Itri wrote:

> On Jun 25, "Alexander E. Patrakov" <patrakov@ums.usu.ru> wrote:
> 
> > Don't look at the Debian package. It is very likely to contain this problem, 
> > because for my single-card setup, Debian udev 0.093-1 writes:
> It's not, because there is an Ubuntu-derived patch which prevents this.
> I have been shipping it since february with no issues, so maybe it's
> time to consider merging it.
> 
That patch is normally sent out with my occasional "Ubuntu Collection"
mails (one is due soon as we're getting back up to date with upstream
post-release), here it is applied to 093.

Scott
-- 
Scott James Remnant
scott@ubuntu.com

[-- Attachment #1.1.2: Type: text/x-patch, Size: 3800 bytes --]

diff -ruNp udev-093~/udev_device.c udev-093/udev_device.c
--- udev-093~/udev_device.c	2006-05-29 10:18:16.000000000 +0100
+++ udev-093/udev_device.c	2006-06-07 14:08:43.000000000 +0100
@@ -30,6 +30,8 @@
 #include <sys/socket.h>
 #include <net/if.h>
 #include <linux/sockios.h>
+#include <errno.h>
+#include <ctype.h>
 
 #include "udev.h"
 #include "udev_rules.h"
@@ -102,10 +104,97 @@ static int rename_net_if(struct udevice 
 	strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
 
 	retval = ioctl(sk, SIOCSIFNAME, &ifr);
-	if (retval != 0)
-		err("error changing net interface name: %s", strerror(errno));
+	if (retval != 0) {
+		if (errno != EEXIST) {
+			err("error changing net interface name: %s", strerror(errno));
+			goto error;
+		}
+
+		/* Destination interface already exits.
+		 * First rename our interface to something temporary in case
+		 * we're trying to swap with that one. */
+		strlcpy(ifr.ifr_newname, udev->dev->kernel_name, IFNAMSIZ);
+		strlcat(ifr.ifr_newname, "_ifrename", IFNAMSIZ);
+
+		retval = ioctl(sk, SIOCSIFNAME, &ifr);
+		if (retval != 0) {
+			err("error changing net interface name: %s", strerror(errno));
+			goto error;
+		}
+
+		/* Now we loop until our target interface goes away. */
+		strlcpy(ifr.ifr_name, ifr.ifr_newname, IFNAMSIZ);
+		strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
+		while ((retval = ioctl(sk, SIOCSIFNAME, &ifr)) != 0) {
+			if (errno != EEXIST) {
+				err("error changing net interface name: %s", strerror(errno));
+				break;
+			}
+
+			usleep(50000);
+		}
+	}
+
+error:
 	close(sk);
+	return retval;
+}
+
+static int rename_net_if_increment(struct udevice *udev)
+{
+	struct ifreq ifr;
+	char *ptr, *end;
+	int dev = 0, sk, retval;
+
+	info("changing net interface name from '%s' to first matching '%s'", udev->dev->kernel_name, udev->name);
+	if (udev->test_run)
+		return 0;
+
+
+	/* Split the name up */
+	ptr = udev->name;
+	while (*ptr && *ptr != '*')
+		ptr++;
+
+	end = ptr + 1;
+	if (isdigit(*end))
+		dev = atoi(end);
 
+	while (isdigit(*end))
+		end++;
+
+
+	sk = socket(PF_INET, SOCK_DGRAM, 0);
+	if (sk < 0) {
+		err("error opening socket: %s", strerror(errno));
+		return -1;
+	}
+
+	memset(&ifr, 0x00, sizeof(struct ifreq));
+	strlcpy(ifr.ifr_name, udev->dev->kernel_name, IFNAMSIZ);
+
+	do {
+		strncpy(ifr.ifr_newname, udev->name, ptr - udev->name);
+		sprintf(ifr.ifr_newname + (ptr - udev->name), "%d%s",
+			dev, end);
+
+		retval = ioctl(sk, SIOCSIFNAME, &ifr);
+		if (retval == 0) {
+			strlcpy(udev->name, ifr.ifr_newname, sizeof(udev->name));
+			break;
+		}
+
+		if (errno != EEXIST) {
+			err("error changing net interface name: %s", strerror(errno));
+			goto error;
+		}
+
+		/* Try the next one */
+		dev++;
+	} while (1);
+
+error:
+	close(sk);
 	return retval;
 }
 
@@ -159,7 +248,11 @@ int udev_device_event(struct udev_rules 
 		if (strcmp(udev->name, udev->dev->kernel_name) != 0) {
 			char *pos;
 
-			retval = rename_net_if(udev);
+			if (strchr(udev->name, '*')) {
+				retval = rename_net_if_increment(udev);
+			} else {
+				retval = rename_net_if(udev);
+			}
 			if (retval != 0)
 				goto exit;
 			info("renamed netif to '%s'", udev->name);
diff -ruNp udev-093~/udev_utils_string.c udev-093/udev_utils_string.c
--- udev-093~/udev_utils_string.c	2006-06-07 14:01:18.000000000 +0100
+++ udev-093/udev_utils_string.c	2006-06-07 14:06:24.000000000 +0100
@@ -241,7 +241,7 @@ int replace_untrusted_chars(char *str)
 		if ((str[i] >= '0' && str[i] <= '9') ||
 		    (str[i] >= 'A' && str[i] <= 'Z') ||
 		    (str[i] >= 'a' && str[i] <= 'z') ||
-		    strchr("#$%+-./:=?@_,", str[i])) {
+		    strchr("#$%+-./:=?*@_,", str[i])) {
 			i++;
 			continue;
 		}

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 191 bytes --]

[-- Attachment #2: Type: text/plain, Size: 300 bytes --]

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

[-- Attachment #3: Type: text/plain, Size: 226 bytes --]

_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-06-26  7:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-24  1:58 swapping interface names (again) MS Colclough
2006-06-24  7:59 ` Marco d'Itri
2006-06-24 20:02 ` juuso.alasuutari
2006-06-25  3:07 ` Alexander E. Patrakov
2006-06-25  8:35 ` Marco d'Itri
2006-06-25 12:18 ` juuso.alasuutari
2006-06-25 12:21 ` Marco d'Itri
2006-06-25 14:39 ` MS Colclough
2006-06-26  7:46 ` Scott James Remnant

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).