View previous topic :: View next topic |
Author |
Message |
sgarcia Apprentice
Joined: 21 May 2003 Posts: 254 Location: Bakersfield, CA
|
Posted: Tue Apr 06, 2004 8:53 pm Post subject: Two interfaces (LAN and WiFi) in laptop |
|
|
My laptop has two interfaces -- eth0, which is a standard LAN interface, and eth1, which is a WiFi card.
Both are set to startup using DHCP, and both work fine. However, only one is ever hooked up at a time -- that is to say, I only plug in the CAT5 if there isn't a WiFi access point around. Sometimes, of course, I start up with no interfaces hooked up, completely standalone.
This does mean that the startup scripts always take a long time to bring the system up, since *one* of them always hangs on the inactive interface until it times out. That's a pain, but one I can live with. It sorta comes with the territory (although KNOPPIX is able to background the DHCP negotiations without holding up the show...)
The problem is that a *lot* of other scripts depend on the net scripts coming up. During initial startup this doesn't seem to be a problem, but if I need to restart one of these services by hand later, the script always tries to restart the inactive interface again, resulting in several more minutes of waiting for the DHCP to time out.
Is there a way to design this "need net" dependency to check to make sure at least one interface is up, and only attempt to start net services if *no* interfaces are running?
Also, can someone tell me how these dependencies are written in? I'm trying to get ntpd to start on this laptop, and even after commenting out the "need net" and "use dns logger" lines from both the "ntpd" and the "ntp-client" scripts, running "/etc/init.d/ntpd start" *still* tries to start the net services again. |
|
Back to top |
|
|
UberLord Retired Dev
Joined: 18 Sep 2003 Posts: 6835 Location: Blighty
|
|
Back to top |
|
|
sgarcia Apprentice
Joined: 21 May 2003 Posts: 254 Location: Bakersfield, CA
|
Posted: Sun Apr 11, 2004 9:57 pm Post subject: |
|
|
Hmm. That sounds interesting. Does this mean that you don't have any net.* entries in the default runlevel? Just ifplugd?
For Gentoo, does this mean that you would change all init scripts that have "need net" in them to instead say something like "need ifplugd"? |
|
Back to top |
|
|
russo79 n00b
Joined: 22 May 2003 Posts: 27
|
Posted: Tue Apr 20, 2004 7:25 pm Post subject: |
|
|
Yes, you need to :
Change the /etc/conf.d/ifplugd file according to your configuration...
Then :
Code: |
rc-update del net.eth0
rc-update del net.eth1
rc-update add ifplugd default
|
if you have problems (specially when using dhcp) , try to modify your /usr/sbin/ifplugd.action
Here is mine :
Code: |
#!/bin/sh
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-x86/sys-apps/ifplugd/files/ifplugd.action,v 1.2 2003/03/21 15:58:05 wmertens Exp $
#
# Gentoo-specific ifplugd.action
#
# This file gets called by ifplugd when it wants to bring an interface
# up or down.
#
case "$2" in
up)
state=start
dhcpcd $1
;;
down)
state=stop
/sbin/ifconfig $1 down
kill `cat /var/run/dhcpcd-$1.pid`
;;
*)
echo "$0: wrong arguments"
echo "Call with <interface> <up|down>"
exit 1
;;
esac
# [ -x /etc/init.d/net.$1 ] && /etc/init.d/net.$1 --quiet $state
exit 0
|
Hope this helps...
Last edited by russo79 on Fri Feb 18, 2005 9:54 pm; edited 1 time in total |
|
Back to top |
|
|
Toertel n00b
Joined: 11 Mar 2004 Posts: 4
|
Posted: Wed Apr 21, 2004 9:49 am Post subject: |
|
|
Regarding problems with DHCP. I had such (dhcpcd was never executed) and solved the problem by changing only one line in /etc/init.d/net.eth0:
Before:
Code: |
status_IFACE="$(ifconfig ${1} 2>${devnull} | gawk '$1 == "UP" {print "up"}')"
|
After:
Code: |
status_IFACE="$(ifconfig ${1} 2>${devnull} | gawk '/addr:/{a=1}/ UP /{ if (a == 1) print "up" }')"
|
The result is that an interface is only seen as "up" when ifconfig says it is UP and it has an IP address. IMHO a cleaner solution. What do you think? |
|
Back to top |
|
|
UberLord Retired Dev
Joined: 18 Sep 2003 Posts: 6835 Location: Blighty
|
|
Back to top |
|
|
Toertel n00b
Joined: 11 Mar 2004 Posts: 4
|
Posted: Thu Apr 22, 2004 12:53 pm Post subject: |
|
|
I just filed a bug report proposing the solution I mentioned above. The issue has already been reported multiple times. I added my report to bug 44013 and 34484. |
|
Back to top |
|
|
ronmon Veteran
Joined: 15 Apr 2002 Posts: 1043 Location: Key West, FL
|
Posted: Thu Apr 22, 2004 2:10 pm Post subject: |
|
|
Nice solution people, ifplugd sets up and runs great.
I didn't have to edit ifplugd.action, but did replace the net.eth* line with Toertel's. There was no discernible delay while booting my iBook with or without the network cable plugged in and all services started without errors. An Airport card is on the way and should be here this afternoon. I'll post my experience with that later. _________________ Ask Questions the Smart Way - by ESR |
|
Back to top |
|
|
sgarcia Apprentice
Joined: 21 May 2003 Posts: 254 Location: Bakersfield, CA
|
Posted: Fri Apr 23, 2004 12:56 am Post subject: |
|
|
This is great. I've hacked at my scripts for a month now trying to get them to behave like this.
Not only can I boot without delay with only a single interface running, I can even fire it up with no network in sight. That's *never* happened!
Thanks! |
|
Back to top |
|
|
kurifu Tux's lil' helper
Joined: 28 Jul 2003 Posts: 77
|
Posted: Sat May 01, 2004 3:09 am Post subject: |
|
|
Hrml... well the script that russo provided was very helpful if getting my interfaces to go up and down properly. One thing I should point out though is that it seems that eth1 (my WLAN) will never actually go down.
Code: |
tail -f /var/log/messages
|
Shows that when eth0 goes up and down it reports finding and our loosing a link beat, and e100_watchdog reports link up or link down. My eth1 device reports AP Out of Range and AP in Range, but it never actually looses an IP address in the process, this makes me wonder if it will work well when moving from 1 device to a nother without shutting down (though that is not likely to happen). I may experiment one day and find out.
Another thing is that my PCMCIA card manager services seem to complain about devices already being brought up or down now that I am using ifplugd, probably a simple dependency error in the init script, I will take a look into that later and likely just send the output to /dev/null to make it be quiet. |
|
Back to top |
|
|
kurifu Tux's lil' helper
Joined: 28 Jul 2003 Posts: 77
|
Posted: Sat May 01, 2004 5:20 am Post subject: Want one device to override the other? |
|
|
Here is a small change that will allow you to override interface eth1 if you know your gateway. If you do not know it, you could change the scipt to pull it from a call to route, or some such anyway, this is simple, but post something more robust if you would like.
Code: |
#!/bin/sh
#File: /usr/sbin/ifplugd.action
case "$2" in
up)
state=start
dhcpcd $1
#bring down the gateway for eth1 if eth0 going up
/sbin/route del default gw 192.168.1.1 dev eth1
echo "gateway for eth1 going down" >> /tmp/ifplugd_log
;;
down)
state=stop
/sbin/ifconfig $1 down
kill `cat /var/run/dhcpcd-$1.pid`
#if eth0 is oging down, bring eth1 back up
case "$1" in
eth0)
/sbin/route add default gw 192.168.1.1 dev eth1
echo "gateway for eth1 going up" >> /tmp/ifplugd_log
;;
esac
;;
*)
echo "$0: wrong arguments"
echo "Call with <interface> <up|down>"
exit 1
;;
esac
#Just dump some debugging stuff to a file
echo "ifplugd action: $2 $1" >> /tmp/ifplugd_log
exit 0
|
|
|
Back to top |
|
|
teedog Apprentice
Joined: 09 Mar 2004 Posts: 211
|
Posted: Mon May 31, 2004 10:15 pm Post subject: |
|
|
Toertel wrote: | Regarding problems with DHCP. I had such (dhcpcd was never executed) and solved the problem by changing only one line in /etc/init.d/net.eth0:
Before:
Code: |
status_IFACE="$(ifconfig ${1} 2>${devnull} | gawk '$1 == "UP" {print "up"}')"
|
After:
Code: |
status_IFACE="$(ifconfig ${1} 2>${devnull} | gawk '/addr:/{a=1}/ UP /{ if (a == 1) print "up" }')"
|
The result is that an interface is only seen as "up" when ifconfig says it is UP and it has an IP address. IMHO a cleaner solution. What do you think? |
According to derf, the above patch is still flawed.
"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."
Scroll to the bottom of this page for derf's solution:
https://bugs.gentoo.org/show_bug.cgi?id=34484 |
|
Back to top |
|
|
|