Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 34484 - [PATCH] sys-apps/ifplugd doesn't work with dhcp (net.eth0)
Summary: [PATCH] sys-apps/ifplugd doesn't work with dhcp (net.eth0)
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
Keywords: InVCS
: 28362 (view as bug list)
Depends on:
Blocks: 66472
  Show dependency tree
Reported: 2003-11-26 17:24 UTC by Malte S. Stretz
Modified: 2004-11-08 11:00 UTC (History)
9 users (show)

See Also:
Package list:
Runtime testing required: ---

patch against ifplugd.action (out,794 bytes, patch)
2003-11-26 17:26 UTC, Malte S. Stretz
Details | Diff
Fixes net.ethx so an interface is only considered up if it has an address (net.ethx.diff,192 bytes, patch)
2004-05-04 08:02 UTC, Guilherme Barile
Details | Diff
/etc/init.d/, contains ifpulgd_preup and ifplugd_postdown (,2.72 KB, text/plain)
2004-05-26 09:00 UTC, derf
Patch for /etc/init.d/ifplugd to call ifplugd_preup and ifplugd_postdown (ifplugd.patch,1.39 KB, patch)
2004-05-26 09:01 UTC, derf
Details | Diff
patches /etc/init.d/net.eth0 to use udhcpc (net.eth0.patch,1.20 KB, patch)
2004-08-18 12:40 UTC, Brian G. Peterson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Malte S. Stretz 2003-11-26 17:24:35 UTC
The init script called by ifplugd.action won't configure the interface controlled by ifplugd because 
ifplugd itself sets up a dummy interface and the net.* check for an already existing interface in 
dhcp mode. 

Reproducible: Always
Steps to Reproduce:
1. Configure ethX to use dhcp 
2. Let ethX be handled by ifplugd 
3. (Re-)Connect your network cable 
4. Check out ifconfig 
Actual Results:  
eth0      Link encap:Ethernet  HWaddr 00:A0:CC:D4:D1:ff 
          inet6 addr: fe80::2a0:ccff:fed4:d1e6/64 Scope:Link 
          RX packets:177 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:182 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:100 
          RX bytes:98875 (96.5 Kb)  TX bytes:18311 (17.8 Kb) 
          Interrupt:9 Base address:0xd000 

Expected Results:  
eth0      Link encap:Ethernet  HWaddr 00:A0:CC:D4:D1:ff 
          inet addr:  Bcast:  Mask: 
          inet6 addr: fe80::2a0:ccff:fed4:d1e6/64 Scope:Link 
          RX packets:179 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:193 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:100 
          RX bytes:99581 (97.2 Kb)  TX bytes:20661 (20.1 Kb) 
          Interrupt:9 Base address:0xd000 

System uname: 2.4.20-gentoo-r8 i686 mobile AMD Athlon(tm) XP 1900+ 
Gentoo Base System version 
Comment 1 Malte S. Stretz 2003-11-26 17:26:23 UTC
Created attachment 21341 [details, diff]
patch against ifplugd.action

This patch makes ifplugd.action take down the interface before the init script
is called (on start only). Also addssome more error checking.
Comment 2 Daniel Jimenez 2004-03-13 09:47:19 UTC
Another alternative is to add "-a -mm" to ARGS in /etc/conf.d/ifplugd. 

Although this way ifplugd will have to depend on sys-apps/net-tool.
Comment 3 Guilherme Barile 2004-03-28 17:34:24 UTC
This patch does not work on my intel e100 board. Even when you call "ifconfig eth0 down" with ifplugd running, the interface doesn't come down.
Maybe changing the net.* scripts on /etc/init.d would fix it:
status_IFACE="$(ifconfig | gawk -v IFACE="${iface}" '$0 ~ /Link/ { if ($1 == IFACE) print "up" }')" 

Below are the difference between the up interface and the configured interface (I guess "Link" isn't a good test ... probably "addr:" or something (I couldn't fix it myself)

eth0      Link encap:Ethernet  HWaddr 00:00:39:DE:8D:DB
          inet addr:  Bcast:  Mask:
          RX packets:1494 errors:0 dropped:0 overruns:0 frame:0
          TX packets:519 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:372059 (363.3 Kb)  TX bytes:57013 (55.6 Kb)
          Interrupt:11 Base address:0xdf40 Memory:fceff000-fceff038

eth0      Link encap:Ethernet  HWaddr 00:00:39:DE:8D:DB
          RX packets:1338 errors:0 dropped:0 overruns:0 frame:0
          TX packets:493 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:354005 (345.7 Kb)  TX bytes:53624 (52.3 Kb)
          Interrupt:11 Base address:0xdf40 Memory:fceff000-fceff038
Comment 4 Mark Jonas 2004-04-22 05:48:46 UTC
I'ld like to propose the following solution to the problem which works just fine for me (saw something similar in a different bug report I'm not able to find any more):

init.d/net.eth0,v 1.37 before:
status_IFACE="$(ifconfig ${1} 2>${devnull} | gawk '$1 == "UP" {print "up"}')"

init.d/net.eth0,v 1.37 after:
status_IFACE="$(ifconfig ${1} 2>${devnull} | gawk '/addr:/{a=1}/ UP /{ if (a == 1) print "up" }')"

With this patch an interface is only considered to be up if ifconfig reports UP and an address.

Adding "-a -mm" to ARGS in /etc/conf.d/ifplugd did not work for me, too.

Please note that Bug 44013 reports the very same problem.
Comment 5 Mark Jonas 2004-04-27 01:33:17 UTC
I found the bug again I was referencing to. It is Bug 28362 and it is the very same problem.
Comment 6 Guilherme Barile 2004-05-04 08:02:53 UTC
Created attachment 30710 [details, diff]
Fixes net.ethx so an interface is only considered up if it has an address
Comment 7 Guilherme Barile 2004-05-04 08:04:59 UTC
  I've tested your patch and it works fine ... just have to make sure it works also for inet6 addresses (guess so, but I don't use it so can't tell).
  I created a diff file from the current net.eth0 and uploaded it ... let's hope more people test it and it gets to the main distro soon :)
  Thanks a lot

Comment 8 Aron Griffis (RETIRED) gentoo-dev 2004-05-07 16:09:37 UTC
Adding net.eth0 to summary so this shows up on my radar
Comment 9 Aron Griffis (RETIRED) gentoo-dev 2004-05-07 16:11:52 UTC
*** Bug 28362 has been marked as a duplicate of this bug. ***
Comment 10 Martin Holzer (RETIRED) gentoo-dev 2004-05-18 08:11:15 UTC
is this still an issue wiht ifplugd-0.25 ?
Comment 11 derf 2004-05-26 08:59:05 UTC
I am using ifplugd-0.25.

Patching net.eth0 in the suggested manner doesn't really solve the problem. When the cable gets unplugged, net.eth0 just takes the interface down again, so ifplugd will never notice if it is ever plugged back in.

On my system, I've added two pieces to the /etc/conf.d/net preup and postdown functions. Both are encapsulated in a file /etc/init.d/

This file defines two functions:
ifplugd_postdown, which deconfigures an interface that was just brought down, and then brings it back up. This also needs to delete the default IPv6 address that gets added to the interface after it is brought up again, or the next function will think the interface is configured (since it will already have an address).

ifplugd_preup, which takes the interface down so that it can be configured. This allows the existing net.eth0 script to detect that the interface is down without an issue, AND it allows the default IPv6 address to be added back when the interface is brought up to be configured. It also will not take down an interface that already has an address of some kind, using the awk check previously posted for this bug.

Both functions respect the INTERFACES variable defined in /etc/conf.d/ifplugd, so that other interfaces are unaffected.

The reason these functions are encapsulated in a separate file is that they are also called from /etc/init.d/ifplugd when it is started and stopped, to ensure the interface is up and listening in the first place, and to take an unconfigured interface down when ifplugd stops.

In /etc/conf.d/net, the following lines need to be added:

source /etc/init.d/

preup() {
        ifplugd_preup "${1}"

postdown() {
        ifplugd_postdown "${1}"

Unfortunately, if one is also using the wireless configuration script available in the forums (, which also defines the preup function, or you have your own version of these functions, a patch for this will not cleanly apply.

There needs to be a good way to add (and remove!) pre/post up/down functionality for individual ebuilds without tromping all over each other.

Other than that, this solution is entirely encapsulated if ifplugd files, and does not require integration with the rest of the system.
Comment 12 derf 2004-05-26 09:00:19 UTC
Created attachment 32079 [details]
/etc/init.d/, contains ifpulgd_preup and ifplugd_postdown
Comment 13 derf 2004-05-26 09:01:09 UTC
Created attachment 32080 [details, diff]
Patch for /etc/init.d/ifplugd to call ifplugd_preup and ifplugd_postdown
Comment 14 Wout Mertens (RETIRED) gentoo-dev 2004-05-26 22:55:49 UTC

To recapitulate:
1. On some configurations, ifplugd needs to keep the interface up, or it can't detect the cable.

2. Others with proper hardware just specify the correct flag and there is no problem.

3. If you try to obtain an IP address with net.eth0, it will not do so if the interface is already up. Patch provided.

4. If the cable is removed, and net.eth0 is called to release the IP address, it will bring the interface down completely.

5. Ifplugd doesn't bring it back up? Derf, are you sure? Using dhcpcd directly should have the same effect...

6. Other scripts use preup and postdown as well.

Because of 2, I don't think we should force the interface up always. Checks should be in place.
Because of 6, I don't think we should put the extra code in preup and postdown. I propose that the code is just put directly in /usr/sbin/ifplugd.action instead.
Because of 5, I don't know if it is needed though.

Derf, can you please doublecheck if your changes are really needed and apply them to the action script instead?

Comment 15 derf 2004-05-27 09:54:52 UTC
With auto="yes" in /etc/init.d/ifplugd, it does indeed bring the interface up automatically... which also assigns it a default IPv6 address. There's no way for the scripts to tell the difference between an already configured interface and one a default address.
Comment 16 teedog 2004-05-31 16:57:51 UTC
I can confirm that derf's solution works on boot-up and when I unplug and plug the cable back in.
Comment 17 teedog 2004-06-01 12:05:21 UTC
Using derf's solution, I get the following warning message upon every env-update.
* /etc/init.d/ is invalid (should not end with '.sh')
Why is that?  I have other scripts ending in .sh in /etc/init.d/, like  Renaming to ifplugupdown (and removing .sh from the relevant code locations) makes the message go away.
Comment 18 derf 2004-07-03 21:28:42 UTC
That's because the first line reads:


Which confuses Gentoo into thinking it's an initscript. Copy/paste error.

Removing the line makes the error message go away (it wasn't used, as the script was never executed directly; mine's not even marked executable).
Comment 19 Wout Mertens (RETIRED) gentoo-dev 2004-07-06 02:38:13 UTC
I still don't think Derf's solution is the right one.

The problem is that net.eth0 makes the wrong assumptions, and because of that takes the wrong code path.

Therefore, these assumptions need to be fixed. Bringing down an interface just so the false assumptions work is wrong.
Comment 20 Brian G. Peterson 2004-08-18 12:39:07 UTC
After running into this same problem for both eth0 and wlan0, I decided to try udhcp as an alternative to dhcpcd.  udhcpc kindly leaves the interface 'up' but unconfigured when it loses the link.  So, it is much friendlier to ifplugd.

My suggestion is to consider using udhcp preferencially to dhcpcd.  It is work noting here that udhcp is under active development and improvement, while dhcpcd has bben stagnant sinnce 2002.

I'll attach a unified diff patch file for /etc/init.d/net.eth0 that makes the change.


 - Brian
Comment 21 Brian G. Peterson 2004-08-18 12:40:22 UTC
Created attachment 37685 [details, diff]
patches /etc/init.d/net.eth0 to use udhcpc
Comment 22 derf 2004-08-21 23:14:09 UTC
Well, I always thought the fact that Gentoo hard-codes a dhcp client was kind of ironic for a distribution that claims to offer its users all these choices (especially when compared to, to use an example I'm familiar with, Debian, which does not). But that's a whole different bug.
Comment 23 Henning C. Nielsen 2004-09-17 09:46:55 UTC
I also think net.eth0 is making the wrong assumptions, and therefore has top priority to be fixed first.

Because this is Gentoo you should also be able to use any dhcp client you want, but in any way net.eth0 is still making wrong assumptions.

This should IMHO be fixed as soon as possible. The patch provided here looks to be fine for now.

The interfaces are not online unless they have an ip-address.

Just my two cent.
Comment 24 Roy Marples (RETIRED) gentoo-dev 2004-11-05 09:52:39 UTC
I think I've got ifplugd working nicely with dhcpcd, pump, dhclient and udhcpc :)

Code is in CVS and should be in baselayout-1.11.6 when it gets released
Comment 25 Roy Marples (RETIRED) gentoo-dev 2004-11-08 11:00:59 UTC
Fixed in baselayout-1.11.6