public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] netdev/uevent
@ 2006-02-21 23:48 Thomas Ogrisegg
  2006-02-22  0:17 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Ogrisegg @ 2006-02-21 23:48 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 791 bytes --]

This patch adds userspace notification for register/unregister and
plug/unplug events for netdevices. It calls kobject_uevent to let
userspace applications (via netlink-interface) know that e.g. the
ethernet-cable was plugged in (or plugged out) and thus the ethernet
device may have to be reconfigured.

Common scenario:
A userspace application is notified that the ethernet cable was plugged
out and later plugged in. It now checks whether the ethernet card is now
connected to an other network and reassigns it's IP-Address via DHCP.

BTW: Of course I know that the constant KOBJ_ONLINE actually has an other
meaning than what I used it for. I just didn't want to introduce a new
constant and it just seems perfect for my purpose.

Signed-off-by: Thomas Ogrisegg <tom-lkml@lkml.fnord.at>

[-- Attachment #2: netdev_uevent.diff --]
[-- Type: text/plain, Size: 1843 bytes --]

diff -uNr -X linux-2.6.15/Documentation/dontdiff linux-2.6.15/net/core/dev.c linux-2.6.15.4/net/core/dev.c
--- linux-2.6.15/net/core/dev.c	2006-01-03 04:21:10.000000000 +0100
+++ linux-2.6.15.4/net/core/dev.c	2006-02-21 20:14:27.000000000 +0100
@@ -104,6 +104,7 @@
 #include <linux/highmem.h>
 #include <linux/init.h>
 #include <linux/kmod.h>
+#include <linux/kobject_uevent.h>
 #include <linux/module.h>
 #include <linux/kallsyms.h>
 #include <linux/netpoll.h>
@@ -742,6 +743,34 @@
 }
 
 /**
+ *	netdev_uevent - notify userspace of netdev events
+ *	@dev: device
+ *	@event: event for device
+ *
+ *	Called to notify userspace of (de-)registering and status events
+ *	of netdevices
+ */
+static inline void
+netdev_uevent(struct net_device *dev, int event)
+{
+	kobject_action_t action = 0;
+
+	switch (event) {
+	case NETDEV_CHANGE:
+		action = netif_carrier_ok (dev) ? KOBJ_ONLINE : KOBJ_OFFLINE;
+		break;
+	case NETDEV_REGISTER:
+		action = KOBJ_ADD;
+		break;
+	case NETDEV_UNREGISTER:
+		action = KOBJ_REMOVE;
+		break;
+	}
+	if (action)
+		kobject_uevent (&dev->class_dev.kobj, action, NULL);
+}
+
+/**
  *	netdev_features_change - device changes fatures
  *	@dev: device to cause notification
  *
@@ -765,6 +794,7 @@
 {
 	if (dev->flags & IFF_UP) {
 		notifier_call_chain(&netdev_chain, NETDEV_CHANGE, dev);
+		netdev_uevent(dev, NETDEV_CHANGE);
 		rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
 	}
 }
@@ -2937,6 +2967,7 @@
 			if (err)
 				printk(KERN_ERR "%s: failed sysfs registration (%d)\n",
 				       dev->name, err);
+			netdev_uevent (dev, NETDEV_REGISTER);
 			dev->reg_state = NETREG_REGISTERED;
 			break;
 
@@ -3108,6 +3139,7 @@
 	   this device. They should clean all the things.
 	*/
 	notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
+	netdev_uevent (dev, NETDEV_UNREGISTER);
 	
 	/*
 	 *	Flush the multicast chain

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] netdev/uevent
  2006-02-21 23:48 [PATCH] netdev/uevent Thomas Ogrisegg
@ 2006-02-22  0:17 ` Greg KH
  2006-02-22  8:37   ` Thomas Ogrisegg
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2006-02-22  0:17 UTC (permalink / raw)
  To: Thomas Ogrisegg; +Cc: linux-kernel

On Wed, Feb 22, 2006 at 12:48:07AM +0100, Thomas Ogrisegg wrote:
> This patch adds userspace notification for register/unregister and
> plug/unplug events for netdevices. It calls kobject_uevent to let
> userspace applications (via netlink-interface) know that e.g. the
> ethernet-cable was plugged in (or plugged out) and thus the ethernet
> device may have to be reconfigured.
> 
> Common scenario:
> A userspace application is notified that the ethernet cable was plugged
> out and later plugged in. It now checks whether the ethernet card is now
> connected to an other network and reassigns it's IP-Address via DHCP.
> 
> BTW: Of course I know that the constant KOBJ_ONLINE actually has an other
> meaning than what I used it for. I just didn't want to introduce a new
> constant and it just seems perfect for my purpose.
> 
> Signed-off-by: Thomas Ogrisegg <tom-lkml@lkml.fnord.at>

Hm, I thought ethtool and netlink already handled this kind of event
just fine.  Why would you add a uevent too?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] netdev/uevent
  2006-02-22  0:17 ` Greg KH
@ 2006-02-22  8:37   ` Thomas Ogrisegg
  2006-02-22 17:53     ` Greg KH
  2006-02-22 17:54     ` Chris Wright
  0 siblings, 2 replies; 6+ messages in thread
From: Thomas Ogrisegg @ 2006-02-22  8:37 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel

On Tue, Feb 21, 2006 at 04:17:07PM -0800, Greg KH wrote:
> On Wed, Feb 22, 2006 at 12:48:07AM +0100, Thomas Ogrisegg wrote:
> > This patch adds userspace notification for register/unregister and
> > plug/unplug events for netdevices. It calls kobject_uevent to let
> > userspace applications (via netlink-interface) know that e.g. the
> > ethernet-cable was plugged in (or plugged out) and thus the ethernet
> > device may have to be reconfigured.
[...]
> > Signed-off-by: Thomas Ogrisegg <tom-lkml@lkml.fnord.at>
> Hm, I thought ethtool and netlink already handled this kind of event
> just fine.  Why would you add a uevent too?

What do you mean with "ethtool and netlink"? At least the current
release of ethtool does not seem to have any netlink support.

Is there currently any possibility for a program to get notified when
a netdevice link becomes ready (or the opposite)? I don't see any interface
(besides polling /sys).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] netdev/uevent
  2006-02-22  8:37   ` Thomas Ogrisegg
@ 2006-02-22 17:53     ` Greg KH
  2006-02-22 17:54     ` Chris Wright
  1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2006-02-22 17:53 UTC (permalink / raw)
  To: Thomas Ogrisegg; +Cc: linux-kernel

On Wed, Feb 22, 2006 at 09:37:51AM +0100, Thomas Ogrisegg wrote:
> On Tue, Feb 21, 2006 at 04:17:07PM -0800, Greg KH wrote:
> > On Wed, Feb 22, 2006 at 12:48:07AM +0100, Thomas Ogrisegg wrote:
> > > This patch adds userspace notification for register/unregister and
> > > plug/unplug events for netdevices. It calls kobject_uevent to let
> > > userspace applications (via netlink-interface) know that e.g. the
> > > ethernet-cable was plugged in (or plugged out) and thus the ethernet
> > > device may have to be reconfigured.
> [...]
> > > Signed-off-by: Thomas Ogrisegg <tom-lkml@lkml.fnord.at>
> > Hm, I thought ethtool and netlink already handled this kind of event
> > just fine.  Why would you add a uevent too?
> 
> What do you mean with "ethtool and netlink"? At least the current
> release of ethtool does not seem to have any netlink support.

That should have been "or", sorry.

> Is there currently any possibility for a program to get notified when
> a netdevice link becomes ready (or the opposite)? I don't see any interface
> (besides polling /sys).

Try asking on the netdev mailing list, I'm sure it must come up there a
lot.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] netdev/uevent
  2006-02-22  8:37   ` Thomas Ogrisegg
  2006-02-22 17:53     ` Greg KH
@ 2006-02-22 17:54     ` Chris Wright
  1 sibling, 0 replies; 6+ messages in thread
From: Chris Wright @ 2006-02-22 17:54 UTC (permalink / raw)
  To: Thomas Ogrisegg; +Cc: Greg KH, linux-kernel

* Thomas Ogrisegg (tom-lkml@lkml.fnord.at) wrote:
> Is there currently any possibility for a program to get notified when
> a netdevice link becomes ready (or the opposite)? I don't see any interface
> (besides polling /sys).

Yes, there's a netlink socket that already communicates these changes.
Routing daemons typically consume this information.  The netdev notifier
chain should end up generating these events via rtmsg_ifinfo.

thanks,
-chris

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] netdev/uevent
@ 2006-02-22 22:37 Stefan Rompf
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Rompf @ 2006-02-22 22:37 UTC (permalink / raw)
  To: Thomas Ogrisegg, linux-kernel

Thomas Ogrisegg wrote:

> What do you mean with "ethtool and netlink"? At least the current
> release of ethtool does not seem to have any netlink support.

You can listen to RTMGRP_LINK on NETLINK_ROUTE. IFF_RUNNING will give you the 
link state information you're looking for.

For you application scenario: I'm working on a DHCP client that uses this 
netlink information, so don't invent the wheel twice ;-)

Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-02-22 22:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-21 23:48 [PATCH] netdev/uevent Thomas Ogrisegg
2006-02-22  0:17 ` Greg KH
2006-02-22  8:37   ` Thomas Ogrisegg
2006-02-22 17:53     ` Greg KH
2006-02-22 17:54     ` Chris Wright
  -- strict thread matches above, loose matches on Subject: below --
2006-02-22 22:37 Stefan Rompf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox