View previous topic :: View next topic |
Author |
Message |
dbcm n00b
Joined: 08 Feb 2004 Posts: 11 Location: Portugal
|
Posted: Fri Jun 11, 2004 11:24 am Post subject: tired of waiting for dhcpcd? mii-tool is our friend. |
|
|
i've made a patch to /etc/init.d/net.eth0 file that test the link connection before the dhcpcd is launched, you need mii-tool from sys-apps/net-tools package.
the dhcpcd -t(imeout) flag is great but some dhcp daemons from hell take +/- 40s to give the IP.
Code: |
--- net.eth0-2004-06-11 2004-06-11 12:16:44.586640080 +0100
+++ net.eth0 2004-06-10 01:52:22.000000000 +0100
@@ -52,6 +52,7 @@
local i iface="${1//\./_}"
status_IFACE="$(ifconfig ${1} 2>${devnull} | gawk '$1 == "UP" {print "up"}')"
+ link_IFACE="$(mii-tool ${1} 2>${devnull} | gawk '$2 == "no" {print "no"}')"
eval vlans_IFACE=\"\$\{iface_${iface}_vlans\}\"
eval ifconfig_IFACE=( \"\$\{ifconfig_$iface\[@\]\}\" )
eval dhcpcd_IFACE=\"\$\{dhcpcd_$iface\}\"
@@ -105,6 +106,10 @@
if [[ ${status_IFACE} == up ]]; then
einfo "Keeping kernel configuration for ${IFACE}"
else
+ if [[ ${link_IFACE} == no ]]; then
+ eerror "NO LINK DETECTED FOR ${IFACE}"
+ return 1
+ else
ebegin "Bringing ${IFACE} up via DHCP"
/sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE}
retval=$?
@@ -131,6 +136,7 @@
fi
fi
fi
+ fi
if [[ ${#ifconfig_IFACE[@]} -gt 1 ]]; then
einfo " Adding aliases"
|
other trick:
if you have more than one eth, don't cp the file. link instead.
ln -s /etc/init.d/net.eth0 /etc/init.d/net.eth1 |
|
Back to top |
|
|
jftuga Tux's lil' helper
Joined: 21 Jan 2004 Posts: 139 Location: Athens, GA
|
Posted: Fri Jun 11, 2004 12:18 pm Post subject: |
|
|
Great idea! I wonder why no one else has ever thought of doing this before. It seems so obvious.
Kudos,
-John |
|
Back to top |
|
|
tweakt Tux's lil' helper
Joined: 16 Sep 2003 Posts: 92 Location: Boston, MA. USA
|
Posted: Fri Jun 11, 2004 4:32 pm Post subject: |
|
|
Even better: sys-apps/ifplugd
Basically it will automatically bring up the interface when the cable is connected, and bring it down when disconnected. So instead of putting net.eth0 in the default runlevel, you just put ifplugd. The newest version also works for wireless.
I've only found one glitch. By modifying a line in /etc/init.d/net.eth0 it helps interaction with dhcp. ifplugd keeps the interface up and the net script skip dhcp if the interface is up, so I changed it so it will always execute 'dhcpcd -q' to either start dhcp or re-aquire a (a possibly different) lease. |
|
Back to top |
|
|
ryceck Apprentice
Joined: 13 Jan 2004 Posts: 195
|
Posted: Fri Jun 11, 2004 6:18 pm Post subject: |
|
|
tweakt wrote: | Even better: sys-apps/ifplugd
Basically it will automatically bring up the interface when the cable is connected, and bring it down when disconnected. So instead of putting net.eth0 in the default runlevel, you just put ifplugd. The newest version also works for wireless.
I've only found one glitch. By modifying a line in /etc/init.d/net.eth0 it helps interaction with dhcp. ifplugd keeps the interface up and the net script skip dhcp if the interface is up, so I changed it so it will always execute 'dhcpcd -q' to either start dhcp or re-aquire a (a possibly different) lease. |
OMG HOW UNBELIEVABLY MAGNIFICENT!!!!!!!!!!!
thnx for this tip |
|
Back to top |
|
|
dbcm n00b
Joined: 08 Feb 2004 Posts: 11 Location: Portugal
|
Posted: Sat Jun 12, 2004 12:20 pm Post subject: |
|
|
my patch with ifplugd is a good idea
my patch don't put the boot waiting for dhcpcd timeout when the eth is not with link |
|
Back to top |
|
|
tweakt Tux's lil' helper
Joined: 16 Sep 2003 Posts: 92 Location: Boston, MA. USA
|
Posted: Sat Jun 12, 2004 3:53 pm Post subject: |
|
|
That's what ifplugd does, only better. It won't start the interface (dhcp) until a link is detected, which will also work anytime after booting. |
|
Back to top |
|
|
tweakt Tux's lil' helper
Joined: 16 Sep 2003 Posts: 92 Location: Boston, MA. USA
|
Posted: Wed Jun 16, 2004 1:38 am Post subject: |
|
|
To followup...
The patch to the net scripts I'm referring to involves the if/then around starting DHCP:
Code: |
--- net.eth0.orig 2004-06-15 21:30:12.625701751 -0400
+++ /etc/init.d/net.eth0 2004-06-15 21:31:44.200165096 -0400
@@ -101,34 +101,29 @@
ifconfig ${IFACE} up &>${devnull}
eend $? || return $?
else
- # Check that eth0 was not brought up by the kernel ...
- if [[ ${status_IFACE} == up ]]; then
- einfo "Keeping kernel configuration for ${IFACE}"
- else
- ebegin "Bringing ${IFACE} up via DHCP"
- /sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE}
- retval=$?
- eend $retval
- if [[ $retval == 0 ]]; then
- # DHCP succeeded, show address retrieved
- i=$(ifconfig ${IFACE} | grep -m1 -o 'inet addr:[^ ]*' |
- cut -d: -f2)
- [[ -n ${i} ]] && einfo " ${IFACE} received address ${i}"
- elif [[ -n "${ifconfig_fallback_IFACE}" ]]; then
- # DHCP failed, try fallback.
- # Show the address, but catch if this interface will be inet6 only
- i=${ifconfig_fallback_IFACE%% *}
- if [[ ${i} == *.*.*.* ]]; then
- ebegin "Using fallback configuration (${i}) for ${IFACE}"
- else
- ebegin "Using fallback configuration for ${IFACE}"
- fi
- ifconfig ${IFACE} ${ifconfig_fallback_IFACE} >${devnull} && \
- ifconfig ${IFACE} up &>${devnull}
- eend $? || return $?
+ ebegin "Bringing ${IFACE} up via DHCP"
+ /sbin/dhcpcd -n ${dhcpcd_IFACE} ${IFACE}
+ retval=$?
+ eend $retval
+ if [[ $retval == 0 ]]; then
+ # DHCP succeeded, show address retrieved
+ i=$(ifconfig ${IFACE} | grep -m1 -o 'inet addr:[^ ]*' |
+ cut -d: -f2)
+ [[ -n ${i} ]] && einfo " ${IFACE} received address ${i}"
+ elif [[ -n "${ifconfig_fallback_IFACE}" ]]; then
+ # DHCP failed, try fallback.
+ # Show the address, but catch if this interface will be inet6 only
+ i=${ifconfig_fallback_IFACE%% *}
+ if [[ ${i} == *.*.*.* ]]; then
+ ebegin "Using fallback configuration (${i}) for ${IFACE}"
else
- return $retval
+ ebegin "Using fallback configuration for ${IFACE}"
fi
+ ifconfig ${IFACE} ${ifconfig_fallback_IFACE} >${devnull} && \
+ ifconfig ${IFACE} up &>${devnull}
+ eend $? || return $?
+ else
+ return $retval
fi
fi
|
When using ifplugd, the interface seems to remain up after the link goes down (cable unplugged, etc). When reconnected, this script is run again, but you can see here, dhcp will not be restarted. So, for example, if you've moved to a different subnet, you'll be stuck. The solution is to always re-run dhcp, and use the '-n' switch. Then dhcp will start if it's not running, or renew the lease if it's still running. Problem solved. |
|
Back to top |
|
|
CoinCoin Tux's lil' helper
Joined: 30 Apr 2004 Posts: 100 Location: France
|
Posted: Wed Jun 16, 2004 7:05 am Post subject: |
|
|
erm... stupid question, but how to apply such a patch? how do I merge the file?
I am trying to get a dynamic IP with my routed IP modem, at boot time after synchro. I think that ifplugd can be of any help. _________________ J'aime la bière, même si la recette n'est pas libre. |
|
Back to top |
|
|
ryceck Apprentice
Joined: 13 Jan 2004 Posts: 195
|
Posted: Wed Jun 16, 2004 7:58 am Post subject: |
|
|
CoinCoin wrote: | erm... stupid question, but how to apply such a patch? how do I merge the file?
I am trying to get a dynamic IP with my routed IP modem, at boot time after synchro. I think that ifplugd can be of any help. |
Just get ifplugd and stuff it in boot runlevel, remove net.eth0 from all runlevels and ur problem should be solved.
For my laptop ifplugd works like a charm |
|
Back to top |
|
|
fuhreal n00b
Joined: 29 Apr 2004 Posts: 66 Location: Toronto
|
Posted: Thu Jul 01, 2004 11:30 pm Post subject: |
|
|
This sounds like a great idea, however i'm not sure how to install these things. if i download the ifplugd and install it, what more needs to be done ? Edit my net.eth* scripts to include all the + lines that you all have posted ? I was actually planing to just remove my dhcpd startup from boot as i hate waiting almost a minute when i don't have my eth plugged into my laptop.... So anyhow... is that all i need to do to get this up n running? |
|
Back to top |
|
|
ag_x Tux's lil' helper
Joined: 11 Jun 2004 Posts: 142 Location: Self Sarkarm.
|
Posted: Sat Jul 17, 2004 4:18 am Post subject: |
|
|
fuhreal wrote: | This sounds like a great idea, however i'm not sure how to install these things. if i download the ifplugd and install it, what more needs to be done ? |
ifplugd is a daemon,you have to add it in the default runlevel . Code: | rc-update add ifplugd default |
|
|
Back to top |
|
|
wswartzendruber Veteran
Joined: 23 Mar 2004 Posts: 1261 Location: Idaho, USA
|
Posted: Fri Aug 06, 2004 2:43 pm Post subject: |
|
|
When I disconnect it, the logs show the beat as down, but then it says it has found a beat and brings it back up. What to do? |
|
Back to top |
|
|
wswartzendruber Veteran
Joined: 23 Mar 2004 Posts: 1261 Location: Idaho, USA
|
Posted: Fri Aug 06, 2004 2:50 pm Post subject: |
|
|
dhcpcd exits with error code 10 |
|
Back to top |
|
|
matrixhax0r n00b
Joined: 23 Jun 2004 Posts: 63
|
Posted: Fri Aug 06, 2004 8:08 pm Post subject: |
|
|
With the new baselayout, try:
/etc/conf.d/net:
Code: |
preup() {
# Test for link on the interface prior to bringing it up. This
# only works on some network adapters and requires the ethtool
# package to be installed.
#if ethtool $1 | grep -q 'Link detected: no'; then
if mii-diag $1 | grep -q 'Link status: not established' > /dev/null; then
ewarn "No link on $1, aborting configuration"
return 1
fi
# Remember to return 0 on success
return 0
}
|
And also usefull if you want to have your clock syncronized (you might need to emerge somethings):
Code: |
postup() {
# # This function could be used, for example, to register with a
# # dynamic DNS service. Another possibility would be to
# # send/receive mail once the interface is brought up.
rdate -s time.nist.gov
hwclock -w
#
# # Enable this function with the next line if you want to use bonding.
# # Remember to uncomment the preup_bonding function!
# #postup_bonding $1
#
# # Return 0 for success (ignored)
return 0
}
|
|
|
Back to top |
|
|
|