LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 12-13-2007, 01:11 PM   #1
bioe007
Member
 
Registered: Apr 2006
Location: lynnwood, wa - usa
Distribution: archlinux
Posts: 654

Rep: Reputation: 30
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

Last edited by bioe007; 12-13-2007 at 01:31 PM. Reason: wrong snip from lspci
 
Old 12-13-2007, 01:46 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,579

Rep: Reputation: 187Reputation: 187
Can you get what you want by using the ifconfig command with no parameters?

ifconfig

-----------------
Steve Stites
 
Old 12-13-2007, 02:24 PM   #3
bioe007
Member
 
Registered: Apr 2006
Location: lynnwood, wa - usa
Distribution: archlinux
Posts: 654

Original Poster
Rep: Reputation: 30
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.
 
Old 12-13-2007, 02:47 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Quote:
Originally Posted by bioe007 View Post
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
 
Old 12-13-2007, 04:15 PM   #5
bioe007
Member
 
Registered: Apr 2006
Location: lynnwood, wa - usa
Distribution: archlinux
Posts: 654

Original Poster
Rep: Reputation: 30
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.

Last edited by bioe007; 12-13-2007 at 05:47 PM. Reason: fixed problem
 
  


Reply

Tags
networking, udev


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware 11 Kernel 2.6.17.13 (huge26.s) does not detect my partitions. udev? femol Slackware 5 02-21-2007 12:47 PM
No internet on wired connection for no reason dzapffe19 Ubuntu 6 02-08-2007 04:07 AM
Cannot make a wired connection with KNetworManager Blade2006 Suse/Novell 0 08-02-2006 03:25 AM
suse 9.3 no (wired or wireless) intrernet connection k0rson Linux - Wireless Networking 2 11-14-2005 06:45 PM
Wireless vs wired connection on same laptop rps63ifid Fedora 7 02-02-2005 10:38 PM


All times are GMT -5. The time now is 04:07 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration