# udev detection of network cable disconnect

## donnysp

Hello,

I have an HP Mini-note laptop with this Gentoo installed:

Linux badger 2.6.25-gentoo-r7 #15 SMP Mon Aug 18 10:13:02 BST 2008 i686 VIA C7-M Processor 1200MHz CentaurHauls GNU/Linux

I am trying to use udev to detect the network cable disconnect. I have this file:

/etc/udev/rules.d/90-network.rules

Which contains this rule:

SUBSYSTEM=="net", ACTION=="remove", RUN+="net.sh %k stop"

I have set the udev_log configuration parameter to "debug" and nothing is logged when I pull out the cable, nor is /lib/udev/net.sh executed. I do get this in /var/log/messages though:

tg3: eth0: Link is down.

Which I assume is being logged from the tg3 driver compiled into my kernel.

On reconnect I get this:

tg3: eth0: Link is up at 100 Mbps, full duplex.

So. How can I get /lib/udev/net.sh to run?

Thanks in advance,

DonnySP

----------

## depontius

Wouldn't it be simpler to use "ifplugd"?

I believe it already does exactly what you want, and there's a script that gets called on plug/unplug events, which you can tweak.

----------

## donnysp

Thanks for the info, I'd never heard of ifplugd before.

I'd still like to know why udev doesn't seem to be doing what it is supposed to. If I can get it to work then that's one less daemon.

I've just realised that I should probably of asked about my _original_ problem that I am trying to use udev to fix:

I have a wired eth0 and a wireless wlan0. Both are up (as in /etc/init.d/net.XXX start) and I can ssh into my machine via either interface. When I unplug the network cable I get "Destination host unreachable" when trying to ping from the machine (i.e. wlan0 not working.) If I then do /etc/init.d/net.eth0 stop  the wlan0 interface starts to work.

Any ideas?

Thanks.

----------

## depontius

I believe that this is the type of scenario ifplugd (and the simpler but less versatile alternative, netplug) was meant to handle.  The other thing it can do is stop those pesky dhcp timeouts.  I have mine set up to control eth0 with ifplugd, but not ath0, because I want explicit control over the latter - I don't want it turning itself on.

Uberlord (Ray Marples, former developer) is the expert on this stuff.

----------

## cyrillic

 *donnysp wrote:*   

> I'd still like to know why udev doesn't seem to be doing what it is supposed to. If I can get it to work then that's one less daemon. 

 

Udev will "do its thing" when you plug/unplug the network card.

As mentioned before, cable in/out events are best handled by ifplugd.

----------

## donnysp

A-ha. The penny drops.

Thanks.

----------

