Skip to contentSkip to conversation

netbase: don't start udhcpc if kernel assigned IP statically

RFC PATCH In review Denys Dmytriyenko 4 participants 9 messages Sep 21, 2009 – Sep 22, 2009

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 netbase: don't start udhcpc if kernel assigned IP statically

---
 recipes/netbase/netbase/interfaces |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
recipes/netbase/netbase/interfaces +2 -0
index c615642..bae03dd 100644
@@ -52,6 +52,8 @@ iface atml0 inet dhcp
 # Wired or wireless interfaces
 auto eth0
 iface eth0 inet dhcp
+        pre-up /bin/grep -v -e "ip=[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" /proc/cmdline > /dev/null
+
 iface eth1 inet dhcp
 
 # Ethernet/RNDIS gadget (g_ether)
Signature · 1 line
1.6.3.3
#1 lore raw

recipes/netbase/netbase/interfaces iface atml0 inet dhcp · line 56

Quoted 3 lines · Denys Dmytriyenko

iface eth0 inet dhcp

recipes/netbase/netbase/interfaces +2 -0
+        pre-up /bin/grep -v -e "ip=[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" /proc/cmdline > /dev/null
+

This is pretty gruesome. It will introduce an extra two fork+exec's worth of overhead to every "ifup eth0" for everybody, and it also fails to check that the ip= parameter actually corresponded to eth0 (i.e. it would stop eth0 coming up even if the parameter was specifying an address for eth1).

It seems like there must be a better way of solving this problem. How about just teaching "ifup -a" to spot interfaces that are already up and leave them alone?

p.

#2 lore raw
Quoted 10 lines · Phil Blundell

recipes/netbase/netbase/interfaces iface atml0 inet dhcp · line 56

Quoted 3 lines · Denys Dmytriyenko

iface eth0 inet dhcp

recipes/netbase/netbase/interfaces +2 -0
+        pre-up /bin/grep -v -e "ip=[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" /proc/cmdline > /dev/null
+

This is pretty gruesome. It will introduce an extra two fork+exec's worth of overhead to every "ifup eth0" for everybody, and it also fails to check that the ip= parameter actually corresponded to eth0 (i.e. it would stop eth0 coming up even if the parameter was specifying an address for eth1).

I would agree it's a quick and dirty fix, that's why it's RFC :)

As in my case we only have eth0, I didn't bother touching eth1 or any other interface.

Also, while the proper and complete format for the ip= parameter is:
ip=<ipaddr>:<serverip>:<gatewayip>:<netmask>:<hostname>:<iface>:<state>

Many users just specify the IP address on the command line:
ip=<ipaddr>

In this case the IP would be assigned to the first available interface, so it is harder to do it from the /etc/network/interfaces file using pre-up...

Quoted 3 lines

It seems like there must be a better way of solving this problem. How about just teaching "ifup -a" to spot interfaces that are already up and leave them alone?

Won't work for the case of kernel-acquired DHCP address, i.e. kernel level autoconfig, aka IP_PNP, aka ip=dhcp command line.

From ifup perspective the interface is up and IP is assigned, but we need to start udhcpc to re-acquire and keep the lease, as kernel can't do this.

Speaking of which, I am working on a fix for udhcpc to also properly handle this case - it needs to be started with -r <ip> to request the same IP that kernel received, instead of asking for any available... Some DHCP servers are stupid and give a different IP, killing NFS/TCP mounted rootfs...

So, the discussion is still open - please send your comments/suggestions. Thanks.

Signature · 1 line
Denys
#3 lore raw
Quoted 8 lines · Denys Dmytriyenko
Quoted 3 lines · Phil Blundell

It seems like there must be a better way of solving this problem. How about just teaching "ifup -a" to spot interfaces that are already up and leave them alone?

Won't work for the case of kernel-acquired DHCP address, i.e. kernel level autoconfig, aka IP_PNP, aka ip=dhcp command line.

It was done in past, but removed. With one of new wpa_supplicant versions, wireless stopped to work. wpa_supplicant turns up any wireless interface immediately. (Well, WPA wireless still needs debugging. It works with about 50% probability.)

What about parsing of kernel parameters during the boot and then doing something.

Signature · 2 lines
Stanislav Brabec
http://www.penguin.cz/~utx/zaurus
#4 lore raw
In reply to Denys Dmytriyenko
Quoted 7 lines · Denys Dmytriyenko
Quoted 3 lines · Phil Blundell

It seems like there must be a better way of solving this problem. How about just teaching "ifup -a" to spot interfaces that are already up and leave them alone?

Won't work for the case of kernel-acquired DHCP address, i.e. kernel level autoconfig, aka IP_PNP, aka ip=dhcp command line.

True, but your original patch won't help with this situation either (since "ip=dhcp" won't match the regex). I think this is a different problem and probably requires a different solution: the ideal thing would be for the kernel to set a flag on the interface to say that it needs to be taken over by a DHCP client, or alternatively to invoke the DHCP client itself via the hotplug mechanism. Failing that you could arrange for the startup scripts to poke around at /proc/cmdline and try to second-guess what the kernel has done, although that would be rather less satisfactory.

p.

#5 lore raw
Quoted 11 lines · Phil Blundell
Quoted 7 lines · Denys Dmytriyenko
Quoted 3 lines · Phil Blundell

It seems like there must be a better way of solving this problem. How about just teaching "ifup -a" to spot interfaces that are already up and leave them alone?

Won't work for the case of kernel-acquired DHCP address, i.e. kernel level autoconfig, aka IP_PNP, aka ip=dhcp command line.

True, but your original patch won't help with this situation either (since "ip=dhcp" won't match the regex). I think this is a different

Not true. The default is to start udhcpc always. I just cover one case to prevent it from starting when ip=x.x.x.x

Quoted 7 lines

problem and probably requires a different solution: the ideal thing would be for the kernel to set a flag on the interface to say that it needs to be taken over by a DHCP client, or alternatively to invoke the DHCP client itself via the hotplug mechanism. Failing that you could arrange for the startup scripts to poke around at /proc/cmdline and try to second-guess what the kernel has done, although that would be rather less satisfactory.

#6 lore raw
Quoted 7 lines · Denys Dmytriyenko
Quoted 6 lines · Phil Blundell
Quoted 5 lines · Denys Dmytriyenko
Quoted 3 lines · Phil Blundell

It seems like there must be a better way of solving this problem. How about just teaching "ifup -a" to spot interfaces that are already up and leave them alone?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Won't work for the case of kernel-acquired DHCP address, i.e. kernel level autoconfig, aka IP_PNP, aka ip=dhcp command line.

True, but your original patch won't help with this situation either (since "ip=dhcp" won't match the regex). I think this is a different

Not true. The default is to start udhcpc always. I just cover one case to prevent it from starting when ip=x.x.x.x

Right, but as you said in your other mail, in the case where the kernel has already claimed a dhcp lease you want to start udhcpc with different arguments to the usual ones. So, although your original patch admittedly doesn't make that situation any worse, it also doesn't make it much better either.

I still think that this:

Quoted 7 lines
Quoted 7 lines

problem and probably requires a different solution: the ideal thing would be for the kernel to set a flag on the interface to say that it needs to be taken over by a DHCP client, or alternatively to invoke the DHCP client itself via the hotplug mechanism. Failing that you could arrange for the startup scripts to poke around at /proc/cmdline and try to second-guess what the kernel has done, although that would be rather less satisfactory.

together with the thing I mentioned earlier, is the right way to solve this kind of issue in general.

Poking at /proc/cmdline from the pre-up command has another downside as well, namely that if you bring the interface down it will then be impossible to get it back up again because the command line will still have the "ip=" bits in it even though they are no longer relevant.

p.

#7 lore raw
Quoted 14 lines · Phil Blundell
Quoted 13 lines · Denys Dmytriyenko
Quoted 11 lines · Phil Blundell
Quoted 7 lines · Denys Dmytriyenko
Quoted 3 lines · Phil Blundell

It seems like there must be a better way of solving this problem. How about just teaching "ifup -a" to spot interfaces that are already up and leave them alone?

Won't work for the case of kernel-acquired DHCP address, i.e. kernel level autoconfig, aka IP_PNP, aka ip=dhcp command line.

True, but your original patch won't help with this situation either (since "ip=dhcp" won't match the regex). I think this is a different

Quoted 8 lines
Quoted 2 lines

Not true. The default is to start udhcpc always. I just cover one case to prevent it from starting when ip=x.x.x.x

Right, but as you said in your other mail, in the case where the kernel has already claimed a dhcp lease you want to start udhcpc with different arguments to the usual ones. So, although your original patch admittedly doesn't make that situation any worse, it also doesn't make it much better either.

Correct. As I was thinking on adding the check for kernel acquired DHCP lease somewhere inside the udhcpc code or script, it appears to be quite independent from this patch to pre-up...

Quoted 10 lines

I still think that this:

Quoted 7 lines
Quoted 7 lines

problem and probably requires a different solution: the ideal thing would be for the kernel to set a flag on the interface to say that it needs to be taken over by a DHCP client, or alternatively to invoke the DHCP client itself via the hotplug mechanism. Failing that you could arrange for the startup scripts to poke around at /proc/cmdline and try to second-guess what the kernel has done, although that would be rather less satisfactory.

Quoted 7 lines

together with the thing I mentioned earlier, is the right way to solve this kind of issue in general.

Poking at /proc/cmdline from the pre-up command has another downside as well, namely that if you bring the interface down it will then be impossible to get it back up again because the command line will still have the "ip=" bits in it even though they are no longer relevant.

Fair enough, I will try to figure out a better way of fixing it for all the possible cases... Thanks.

Signature · 1 line
Denys
Acked-by on v1 1/1
#8 lore raw
In reply to Denys Dmytriyenko
Quoted 2 lines · Denys Dmytriyenko
Quoted 17 lines
---
  recipes/netbase/netbase/interfaces |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)
recipes/netbase/netbase/interfaces +2 -0
index c615642..bae03dd 100644
@@ -52,6 +52,8 @@ iface atml0 inet dhcp
  # Wired or wireless interfaces
  auto eth0
  iface eth0 inet dhcp
+        pre-up /bin/grep -v -e "ip=[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" /proc/cmdline>  /dev/null
+
  iface eth1 inet dhcp
 
  # Ethernet/RNDIS gadget (g_ether)