LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   detect wired connection with udev? (https://www.linuxquestions.org/questions/linux-kernel-70/detect-wired-connection-with-udev-606568/)

bioe007 12-13-2007 12:11 PM

detect wired connection with udev?
 
Hi I've been trying to figure out a way to detect when eth0 is plugged in using udev.

when unplugged:

Code:

dmesg | grep eth0 | tail -1
tg3: eth0: Link is down.

and then when plugged back in:

Code:

dmesg | grep eth0 | tail -2
tg3: eth0: Link is up at 100 Mbps, full duplex.
tg3: eth0: Flow control is on for TX and on for RX.

it seems to me some event is happening with eth* (wlan0 shows similar stuff) that udev should be able to detect, but I'm not sure what to put in the rule, what I'm currently trying:

Code:

KERNEL=="eth0", RUN+="/etc/rc.d/rc.inetmon"
Doesn't work. where rc.inetmon checks dmesg refreshes routing based on the state of eth0. rc.inetmon is +x and has shebang as line #1. I've also tried:


Code:

KERNEL=="eth0", RUN+="/etc/rc.d/rc.inet1 restart"
to simply restart the service, no luck there either.

I know there is netplug but imo a daemon should not be added if udev can do this already.

thanks for looking.

btw- dell d820, core duo, adapter is Broadcomm ( BCM5752), linux 2.6.22.9, zenwalk 4.8

jailbait 12-13-2007 12:46 PM

Can you get what you want by using the ifconfig command with no parameters?

ifconfig

-----------------
Steve Stites

bioe007 12-13-2007 01:24 PM

thanks for the reply, I'm not sure I understand how I'd do that without a daemon.

It seems to me - my problem is not getting udev to recognize when the cable is unplugged/replugged.

polling ifconfig is more a daemon-like approach, isn't it?

I'm looking for some udev event (kernel message, sysfs attribute) that a udev rule can use to detect activity of the eth0 interface.

Then I'd make it run a script to reroute traffic to include/exclude it and/or que the wireless interface to start up.

osor 12-13-2007 01:47 PM

Quote:

Originally Posted by bioe007 (Post 2989646)
I'm looking for some udev event (kernel message, sysfs attribute) that a udev rule can use to detect activity of the eth0 interface.

I don’t think udev can do this (which is precisely why ifplugd and netplugd were written in the first place).

If you want to see all udev events as they occur, try something like this (this gives you the kernel-side events, the udev-side events and a matchable environment):
Code:

udevmonitor -keu

bioe007 12-13-2007 03:15 PM

Quote:

I don’t think udev can do this
I think you're right, I tried udevmonitor +/- plug and no events are show up - my misunderstanding that dmesg=uevents.

at the risk of derailing my op, I have now tried ifplugd :

Code:

if gcc -DHAVE_CONFIG_H -I. -I. -I..    -D_REENTRANT  -DSYSCONFDIR="\"/etc\"" -D_GNU_SOURCE -march=prescott -O2 -pipe -fomit-frame-pointer -mfpmath=sse -msse3 -pipe -W -Wall -Wno-unused-parameter -MT interface.o -MD -MP -MF ".deps/interface.Tpo" -c -o interface.o interface.c; \
        then mv -f ".deps/interface.Tpo" ".deps/interface.Po"; else rm -f ".deps/interface.Tpo"; exit 1; fi
In file included from interface.c:27:
/usr/include/sys/types.h:62: error: conflicting types for 'dev_t'
/usr/include/linux/types.h:22: error: previous declaration of 'dev_t' was here
/usr/include/sys/types.h:67: error: conflicting types for 'gid_t'
/usr/include/linux/types.h:54: error: previous declaration of 'gid_t' was here
/usr/include/sys/types.h:72: error: conflicting types for 'mode_t'
/usr/include/linux/types.h:24: error: previous declaration of 'mode_t' was here
/usr/include/sys/types.h:77: error: conflicting types for 'nlink_t'
/usr/include/linux/types.h:25: error: previous declaration of 'nlink_t' was here
/usr/include/sys/types.h:82: error: conflicting types for 'uid_t'
/usr/include/linux/types.h:53: error: previous declaration of 'uid_t' was here
In file included from /usr/include/sys/types.h:133,
                from interface.c:27:
/usr/include/time.h:105: error: conflicting types for 'timer_t'
/usr/include/linux/types.h:31: error: previous declaration of 'timer_t' was here
In file included from /usr/include/sys/types.h:220,
                from interface.c:27:
/usr/include/sys/select.h:78: error: conflicting types for 'fd_set'
/usr/include/linux/types.h:21: error: previous declaration of 'fd_set' was here
In file included from interface.c:27:
/usr/include/sys/types.h:235: error: conflicting types for 'blkcnt_t'
/usr/include/linux/types.h:152: error: previous declaration of 'blkcnt_t' was here
interface.c: In function 'interface_detect_beat_mii':
interface.c:106: warning: dereferencing type-punned pointer will break strict-aliasing rules
interface.c:115: warning: dereferencing type-punned pointer will break strict-aliasing rules
interface.c: In function 'interface_detect_beat_priv':
interface.c:134: warning: dereferencing type-punned pointer will break strict-aliasing rules
interface.c:143: warning: dereferencing type-punned pointer will break strict-aliasing rules
make[3]: *** [interface.o] Error 1
make[3]: Leaving directory `/mnt/data/software/source/ifplugd/ifplugd-0.28/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/mnt/data/software/source/ifplugd/ifplugd-0.28/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/mnt/data/software/source/ifplugd/ifplugd-0.28'
make: *** [all] Error 2

and netplug:
Code:

$ make
make: bk: Command not found
make: bk: Command not found
cc -march=prescott -O2 -pipe -fomit-frame-pointer -mfpmath=sse -msse3 -Wall -Werror -std=gnu99 -DNP_ETC_DIR='"/etc/netplug"' -DNP_SCRIPT_DIR='"/etc/netplug.d"' -ggdb3 -O3 -DNP_VERSION='"1.2.9"'  -c -o netlink.o netlink.c
cc1: warnings being treated as errors
netlink.c: In function 'netlink_open':
netlink.c:289: warning: pointer targets in passing argument 3 of 'getsockname' differ in signedness
make: *** [netlink.o] Error 1

^ netplug lacked configure, Makefile.in, configure.ac/in so generating those myself and can get ./configure but build still breaks the same way.

-ed- nevermind, got netplug to build.


All times are GMT -5. The time now is 09:42 AM.