From: Scott Parlane <hidden> Date: 2012-06-09 07:59:46
From: Scott Parlane <redacted>
if IP_PNP_RENAME_DEV is set, the first interface to be configured
automatically by the kernel during boot will be renamed.
IP_PNP_DEV_NEWNAME is the name to give the autoconfigured device.
No changes will be made to any interface that is not autoconfigured.
This allows the assurance of the boot device name, without the need
for an initramfs.
Signed-off-by: Scott Parlane <redacted>
---
net/ipv4/Kconfig | 17 +++++++++++++++++
net/ipv4/ipconfig.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 0 deletions(-)
@@ -86,6 +86,10 @@#if defined(IPCONFIG_BOOTP) || defined(IPCONFIG_RARP)#define IPCONFIG_DYNAMIC#endif+#if defined(CONFIG_IP_PNP_RENAME_DEV)+#define IPCONFIG_RENAME_DEV+#define IPCONFIG_DEV_NEWNAME CONFIG_IP_PNP_DEV_NEWNAME+#endif/* Define the friendly delay before and after opening net devices */#define CONF_POST_OPEN 10 /* After opening: 10 msecs */
@@ -360,6 +364,37 @@ static int __init ic_setup_if(void)memset(&ir,0,sizeof(ir));strcpy(ir.ifr_ifrn.ifrn_name,ic_dev->name);+#ifdef IPCONFIG_RENAME_DEV+if((err=ic_dev_ioctl(SIOCGIFFLAGS,&ir))<0){+pr_err("IP-Config: Unable to get interface flags (1,%d).\n",+err);+return-1;+}+ir.ifr_flags&=~IFF_UP;+if((err=ic_dev_ioctl(SIOCSIFFLAGS,&ir))<0){+pr_err("IP-Config: Unable to set interface flags (1,%d).\n",+err);+return-1;+}+strcpy(ir.ifr_newname,IPCONFIG_DEV_NEWNAME);+if((err=ic_dev_ioctl(SIOCSIFNAME,&ir))<0){+pr_err("IP-Config: Unable to change boot interface name to %s (%d).\n",+IPCONFIG_DEV_NEWNAME,err);+return-1;+}+strcpy(ir.ifr_ifrn.ifrn_name,IPCONFIG_DEV_NEWNAME);+if((err=ic_dev_ioctl(SIOCGIFFLAGS,&ir))<0){+pr_err("IP-Config: Unable to get interface flags (2,%d).\n",+err);+return-1;+}+ir.ifr_flags|=IFF_UP;+if((err=ic_dev_ioctl(SIOCSIFFLAGS,&ir))<0){+pr_err("IP-Config: Unable to set interface flags (2,%d).\n",+err);+return-1;+}+#endifset_sockaddr(sin,ic_myaddr,0);if((err=ic_devinet_ioctl(SIOCSIFADDR,&ir))<0){pr_err("IP-Config: Unable to set interface address (%d)\n",
From: Scott Parlane <hidden> Date: 2012-06-10 15:54:16
Hi David,
Can you please deliver this patch (my apologies if you have already).
We have been running it for several months on ~80 x86 machines
(against 3.3.0-gentoo)
and have had no issues related to it.
It applied cleanly to tovalds.git and net.git when I created it.
Please let me know if it requires any changes,
I believe I complied with the coding style present in the file.
Kind Regards,
Scott
On Sat, 2012-06-09 at 19:48 +1200, Scott Parlane wrote:
quoted hunk
From: Scott Parlane <redacted>
if IP_PNP_RENAME_DEV is set, the first interface to be configured
automatically by the kernel during boot will be renamed.
IP_PNP_DEV_NEWNAME is the name to give the autoconfigured device.
No changes will be made to any interface that is not autoconfigured.
This allows the assurance of the boot device name, without the need
for an initramfs.
Signed-off-by: Scott Parlane <redacted>
---
net/ipv4/Kconfig | 17 +++++++++++++++++
net/ipv4/ipconfig.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 0 deletions(-)
@@ -86,6 +86,10 @@#if defined(IPCONFIG_BOOTP) || defined(IPCONFIG_RARP)#define IPCONFIG_DYNAMIC#endif+#if defined(CONFIG_IP_PNP_RENAME_DEV)+#define IPCONFIG_RENAME_DEV+#define IPCONFIG_DEV_NEWNAME CONFIG_IP_PNP_DEV_NEWNAME+#endif/* Define the friendly delay before and after opening net devices */#define CONF_POST_OPEN 10 /* After opening: 10 msecs */
@@ -360,6 +364,37 @@ static int __init ic_setup_if(void)memset(&ir,0,sizeof(ir));strcpy(ir.ifr_ifrn.ifrn_name,ic_dev->name);+#ifdef IPCONFIG_RENAME_DEV+if((err=ic_dev_ioctl(SIOCGIFFLAGS,&ir))<0){+pr_err("IP-Config: Unable to get interface flags (1,%d).\n",+err);+return-1;+}+ir.ifr_flags&=~IFF_UP;+if((err=ic_dev_ioctl(SIOCSIFFLAGS,&ir))<0){+pr_err("IP-Config: Unable to set interface flags (1,%d).\n",+err);+return-1;+}+strcpy(ir.ifr_newname,IPCONFIG_DEV_NEWNAME);+if((err=ic_dev_ioctl(SIOCSIFNAME,&ir))<0){+pr_err("IP-Config: Unable to change boot interface name to %s (%d).\n",+IPCONFIG_DEV_NEWNAME,err);+return-1;+}+strcpy(ir.ifr_ifrn.ifrn_name,IPCONFIG_DEV_NEWNAME);+if((err=ic_dev_ioctl(SIOCGIFFLAGS,&ir))<0){+pr_err("IP-Config: Unable to get interface flags (2,%d).\n",+err);+return-1;+}+ir.ifr_flags|=IFF_UP;+if((err=ic_dev_ioctl(SIOCSIFFLAGS,&ir))<0){+pr_err("IP-Config: Unable to set interface flags (2,%d).\n",+err);+return-1;+}+#endifset_sockaddr(sin,ic_myaddr,0);if((err=ic_devinet_ioctl(SIOCSIFADDR,&ir))<0){pr_err("IP-Config: Unable to set interface address (%d)\n",
From: David Miller <davem@davemloft.net> Date: 2012-06-11 03:25:16
From: Scott Parlane <redacted>
Date: Sat, 9 Jun 2012 19:48:07 +1200
From: Scott Parlane <redacted>
if IP_PNP_RENAME_DEV is set, the first interface to be configured
automatically by the kernel during boot will be renamed.
IP_PNP_DEV_NEWNAME is the name to give the autoconfigured device.
No changes will be made to any interface that is not autoconfigured.
This allows the assurance of the boot device name, without the need
for an initramfs.
Signed-off-by: Scott Parlane <redacted>
Making this a compile time option makes absolutely no sense at all.
Assuming this feature is desirable at all (which is a big IF), it
should be a kernel command line option.
From: Scott Parlane <redacted>
Date: Sat, 9 Jun 2012 19:48:07 +1200
quoted
From: Scott Parlane <redacted>
if IP_PNP_RENAME_DEV is set, the first interface to be configured
automatically by the kernel during boot will be renamed.
IP_PNP_DEV_NEWNAME is the name to give the autoconfigured device.
No changes will be made to any interface that is not autoconfigured.
This allows the assurance of the boot device name, without the need
for an initramfs.
Signed-off-by: Scott Parlane <redacted>
Making this a compile time option makes absolutely no sense at all.
Assuming this feature is desirable at all (which is a big IF), it
should be a kernel command line option.
My comment re how many devices was a reference to the level of testing,
not the usage, however I see it was probably moot given any person with
sufficient
knowledge of the area would see it works as described.
(unless I did something i haven't seen yet)
[background of this solution]
In our configuration we load the same kernel on to a number of testboxes,
each of which has several ethernet interfaces and serial ports
(for communicating with our devices under test)
They use nfsroot which prevents udev rules from working correctly
(because you cant take down the interface to rename it)
Previously we were using an initramfs that would rename the interface,
just before mounting the real root.
However a recent change to glibc prevents busybox's nfs utils from working,
so I made this patch to get the kernel to do it, and remove the need for
the initramfs
(which just slows our boot process anyways)
In our case, we run a custom kernel, and have this option turned on, with a
suitable name so that we can identify the boot interface.
While I agree that being able to configure it from the command line would
be useful,
I would rather that I could (if I wanted) configure it at compile time to
default,
purely because it means there is one less thing my admins need to deal
worry about
or can change in the pxelinux config. (every testbox has a unique cmdline,
because of
how our nfsroot mount points work)
Please let me know if you want me to extend it to support command line
configuration,
and what configuration you would like to trigger it.
Kind Regards,
Scott
From: David Miller <davem@davemloft.net> Date: 2012-06-11 10:10:56
From: scott@scottnz.com
Date: Mon, 11 Jun 2012 21:58:45 +1200
They use nfsroot which prevents udev rules from working correctly
(because you cant take down the interface to rename it)
This is why I hate nfsroot as implemented in the kernel.
Do this right and use an initial ramdisk, then you won't have
this huge disconnect between different device names due to
lack of udev.
Thanks, you've confirmed that this patch is totally inappropriate.
From: scott@scottnz.com
Date: Mon, 11 Jun 2012 21:58:45 +1200
quoted
They use nfsroot which prevents udev rules from working correctly
(because you cant take down the interface to rename it)
This is why I hate nfsroot as implemented in the kernel.
The same is true for root over nfs as configured by the initramfs,
conviently there is a small window where you can interfere with it
(at the initramfs stage), or I should say there-was,
its not available anymore, specifically because glibc dropped the sunrpc
code. (This is probably an artifact of gentoo's initramfs more than anything,
but it was the last distro that I could find to network boot without fully
RYO)
Do this right and use an initial ramdisk, then you won't have
this huge disconnect between different device names due to
lack of udev.
Thanks, you've confirmed that this patch is totally inappropriate.
So be it, we will continue to run it, because its the simpliest way to
get what we want done (and most of our software developers can deal
with kernel code, more so than libc)
Regards,
Scott