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 UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1 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:10.10.10.20 Bcast:10.10.255.255 Mask:255.255.0.0 inet6 addr: fe80::2a0:ccff:fed4:d1e6/64 Scope:Link UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1 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 1.4.3.10 sys-apps/ifplugd-0.13-r1
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.
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.
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:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0 UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1 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 UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1 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
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.
I found the bug again I was referencing to. It is Bug 28362 and it is the very same problem.
Created attachment 30710 [details, diff] Fixes net.ethx so an interface is only considered up if it has an address
Mark, 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 gui
Adding net.eth0 to summary so this shows up on my radar
*** Bug 28362 has been marked as a duplicate of this bug. ***
is this still an issue wiht ifplugd-0.25 ?
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/ifplugdupdown.sh. 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/ifplugdupdown.sh preup() { ifplugd_preup "${1}" } postdown() { ifplugd_postdown "${1}" } Unfortunately, if one is also using the wireless configuration script available in the forums (http://forums.gentoo.org/viewtopic.php?t=122435), 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.
Created attachment 32079 [details] /etc/init.d/ifplugdupdown.sh, contains ifpulgd_preup and ifplugd_postdown
Created attachment 32080 [details, diff] Patch for /etc/init.d/ifplugd to call ifplugd_preup and ifplugd_postdown
Hmmm. 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? Thanks!
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.
I can confirm that derf's solution works on boot-up and when I unplug and plug the cable back in.
Using derf's solution, I get the following warning message upon every env-update. * /etc/init.d/ifplugdupdown.sh is invalid (should not end with '.sh') Why is that? I have other scripts ending in .sh in /etc/init.d/, like wireless.sh. Renaming ifplugdupdown.sh to ifplugupdown (and removing .sh from the relevant code locations) makes the message go away.
That's because the first line reads: #!/sbin/runscript 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).
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.
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. Regards, - Brian
Created attachment 37685 [details, diff] patches /etc/init.d/net.eth0 to use udhcpc
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.
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.
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
Fixed in baselayout-1.11.6