Subject: How to detect net cable plug-in
To: None <firstname.lastname@example.org>
From: Brian Grayson (home) <email@example.com>
Date: 10/14/2003 00:42:00
I wanted to get my laptop to auto-launch dhclient when I plug a
cable in. I first posted about this on netbsd-users, where Todd
Vierling pointed me to ifwatchd, which almost does what I want after
a bit of hacking. But my troubles have forced me to turn to tech-net!
Here's what I did to ifwatchd, and how things would ideally work:
- ifwatchd monitors the link status (RTM_IFINFO messages). When it
detects a link going up, it launches dhclient (it runs whatever
script you specify).
Here's the problem:
- dhclient, when run on an ex0 interface, causes the link to go down
and then up again (ifi_link_state twiddles)
- this causes another RTM_IFINFO message (rt_ifmsg() in
dev/mii/mii_physubr.c) for both the down and up
- these secondary RTM_IFINFO messages are indistinguishable from the
first ones, so ifwatchd thinks it's time to launch dhclient again.
So, is it possible for me to modify ifwatchd, possibly with kernel
mods, so that this will work properly? I could make ifwatchd enter a
state machine once it launches the carrier-detected script, but it
appears that the state machine would have to be device-specific, as
I've already seen that ex0 and tlp0 alter the carrier/ifi_link_state
Or, the more fundamental question is, can one detect the actual
status of the wire (carrier or no) independently from whether the
interface is up or down? For tlp0, the answer seems to be yes, while
for ex0, the answer seems to be no (with the kernel as written today).