linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] network devices generating uevents?
@ 2008-11-22  7:41 Stephen Hemminger
  2008-11-22 14:08 ` Kay Sievers
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Stephen Hemminger @ 2008-11-22  7:41 UTC (permalink / raw)
  To: linux-hotplug

Perhaps the following would make it easier for applications to
track network device events without having to use netlink.
Compile tested only so far. The implementation is almost trivial...

--- a/net/core/Makefile	2008-11-21 12:25:31.000000000 -0800
+++ b/net/core/Makefile	2008-11-21 13:32:30.000000000 -0800
@@ -17,3 +17,4 @@ obj-$(CONFIG_NET_PKTGEN) += pktgen.o
 obj-$(CONFIG_NETPOLL) += netpoll.o
 obj-$(CONFIG_NET_DMA) += user_dma.o
 obj-$(CONFIG_FIB_RULES) += fib_rules.o
+obj-$(CONFIG_HOTPLUG) += uevent.o
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/net/core/uevent.c	2008-11-21 13:42:13.000000000 -0800
@@ -0,0 +1,45 @@
+/*
+ * Linux network device event notification
+ *
+ * Author:
+ *	Stephen Hemminger <shemminger@vyatta.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/netdevice.h>
+#include <linux/kobject.h>
+#include <linux/notifier.h>
+
+static int netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
+{
+	struct net_device *netdev = ptr;
+
+	switch (event) {
+	case NETDEV_UNREGISTER:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_REMOVE);
+		break;
+	case NETDEV_REGISTER:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_ADD);
+		break;
+	case NETDEV_UP:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_ONLINE);
+		break;
+	case NETDEV_DOWN:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_OFFLINE);
+		break;
+	case NETDEV_CHANGE:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_CHANGE);
+		break;
+	}
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block netdev_uevent_notifier = {
+	.notifier_call	= netdev_event,
+};
+
+static int __init netdev_uevent_init(void)
+{
+	return register_netdevice_notifier(&netdev_uevent_notifier);
+}
+device_initcall(netdev_uevent_init);

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

* Re: [RFC] network devices generating uevents?
  2008-11-22  7:41 [RFC] network devices generating uevents? Stephen Hemminger
@ 2008-11-22 14:08 ` Kay Sievers
  2008-11-22 19:22 ` Karl O. Pinc
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 18+ messages in thread
From: Kay Sievers @ 2008-11-22 14:08 UTC (permalink / raw)
  To: linux-hotplug

On Sat, Nov 22, 2008 at 08:41, Stephen Hemminger <shemminger@vyatta.com> wrote:
> Perhaps the following would make it easier for applications to
> track network device events without having to use netlink.

Sure, that might be useful.

These events can not happen at a high frequency, at any time, right?
We are sure that things like UP/DOWN/CHANGE can not happen at a high
frequency, maybe in some failure situation?

Uevents are pretty expensive, every single of them may fork a
/sbin/hotplug process, or a udev event process, regardless if anybody
is listening to these events or not.

We can do that only if we can be sure, that there are never things
like "storms of events", which would cause a pretty high system load,
and can even crash non-udev systems with out-of-memory, caused by the
stateless non-managed (disabled by udev) /sbin/hotplug scripts.

> --- /dev/null   1970-01-01 00:00:00.000000000 +0000
> +++ b/net/core/uevent.c 2008-11-21 13:42:13.000000000 -0800
> @@ -0,0 +1,45 @@
> +/*
> + * Linux network device event notification

> +       switch (event) {
> +       case NETDEV_UNREGISTER:
> +               kobject_uevent(&netdev->dev.kobj, KOBJ_REMOVE);
> +               break;
> +       case NETDEV_REGISTER:
> +               kobject_uevent(&netdev->dev.kobj, KOBJ_ADD);
> +               break;

Isn't UNREGISTER/REGISTER happening at the same as the device itself
being created or going away? We usually do not allow any driver code
to send "add/remove" events for any "struct device", because they are
handled by the driver core itself.

Along with the core-created events, wouldn't this create a sequence of
add->add->remove->remove? This would confuse userspace tools, which
can expect that an "add" will never be followed by another "add".

Thanks,
Kay

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

* Re: [RFC] network devices generating uevents?
  2008-11-22  7:41 [RFC] network devices generating uevents? Stephen Hemminger
  2008-11-22 14:08 ` Kay Sievers
@ 2008-11-22 19:22 ` Karl O. Pinc
  2008-11-23  2:13 ` Marcel Holtmann
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 18+ messages in thread
From: Karl O. Pinc @ 2008-11-22 19:22 UTC (permalink / raw)
  To: linux-hotplug


On 11/22/2008 08:08:35 AM, Kay Sievers wrote:
> On Sat, Nov 22, 2008 at 08:41, Stephen Hemminger
> <shemminger@vyatta.com> wrote:
> > Perhaps the following would make it easier for applications to
> > track network device events without having to use netlink.

> These events can not happen at a high frequency, at any time, right?
> We are sure that things like UP/DOWN/CHANGE can not happen at a high
> frequency, maybe in some failure situation?

At _any_ time might be too strict a criteria.
You could certainly have a high rate of carrier acquire/loss
if, for example, the ethernet plug was not all the way plugged
in and there was vibration.  But of course you could get the
same thing with a usb mass storage device under the same
conditions so I'm not sure that this example crosses
the line.  I've seen strange things happen when cables
are laid in places where people walk over them.  (!)

Could there be a problem with rapid fluctuation of wireless
signal levels if, e.g., somebody's running a vacuum cleaner
nearby?

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                  -- Robert A. Heinlein

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

* Re: [RFC] network devices generating uevents?
  2008-11-22  7:41 [RFC] network devices generating uevents? Stephen Hemminger
  2008-11-22 14:08 ` Kay Sievers
  2008-11-22 19:22 ` Karl O. Pinc
@ 2008-11-23  2:13 ` Marcel Holtmann
  2008-11-23  6:32 ` Stephen Hemminger
  2008-11-23 16:13 ` Kay Sievers
  4 siblings, 0 replies; 18+ messages in thread
From: Marcel Holtmann @ 2008-11-23  2:13 UTC (permalink / raw)
  To: linux-hotplug

Hi Kay,

>> Perhaps the following would make it easier for applications to
>> track network device events without having to use netlink.
>
> Sure, that might be useful.
>
> These events can not happen at a high frequency, at any time, right?
> We are sure that things like UP/DOWN/CHANGE can not happen at a high
> frequency, maybe in some failure situation?
>
> Uevents are pretty expensive, every single of them may fork a
> /sbin/hotplug process, or a udev event process, regardless if anybody
> is listening to these events or not.
>
> We can do that only if we can be sure, that there are never things
> like "storms of events", which would cause a pretty high system load,
> and can even crash non-udev systems with out-of-memory, caused by the
> stateless non-managed (disabled by udev) /sbin/hotplug scripts.

I was looking into the same thing the other day. And just getting the  
interface up/down events via uevent is pretty useful. I am also  
interested in getting the carrier signal of Ethernet cards via a  
CHANGE event.

If you look at the RTNL messages, it doesn't happen that often, but  
the NEWLINK messages are maybe a little bit too much and we should  
restrict it to event that really matter. So up/down are user triggered  
event normally. So that should be safe. I would be a little bit  
worried about the CHANGE event. Here we might wanna restrict it to a  
subset of possible changes inside the network device.

Regards

Marcel


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

* Re: [RFC] network devices generating uevents?
  2008-11-22  7:41 [RFC] network devices generating uevents? Stephen Hemminger
                   ` (2 preceding siblings ...)
  2008-11-23  2:13 ` Marcel Holtmann
@ 2008-11-23  6:32 ` Stephen Hemminger
  2008-11-23 16:13 ` Kay Sievers
  4 siblings, 0 replies; 18+ messages in thread
From: Stephen Hemminger @ 2008-11-23  6:32 UTC (permalink / raw)
  To: linux-hotplug

On Sun, 23 Nov 2008 03:13:29 +0100
Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Kay,
> 
> >> Perhaps the following would make it easier for applications to
> >> track network device events without having to use netlink.
> >
> > Sure, that might be useful.
> >
> > These events can not happen at a high frequency, at any time, right?
> > We are sure that things like UP/DOWN/CHANGE can not happen at a high
> > frequency, maybe in some failure situation?
> >
> > Uevents are pretty expensive, every single of them may fork a
> > /sbin/hotplug process, or a udev event process, regardless if anybody
> > is listening to these events or not.
> >
> > We can do that only if we can be sure, that there are never things
> > like "storms of events", which would cause a pretty high system load,
> > and can even crash non-udev systems with out-of-memory, caused by the
> > stateless non-managed (disabled by udev) /sbin/hotplug scripts.
> 
> I was looking into the same thing the other day. And just getting the  
> interface up/down events via uevent is pretty useful. I am also  
> interested in getting the carrier signal of Ethernet cards via a  
> CHANGE event.
> 
> If you look at the RTNL messages, it doesn't happen that often, but  
> the NEWLINK messages are maybe a little bit too much and we should  
> restrict it to event that really matter. So up/down are user triggered  
> event normally. So that should be safe. I would be a little bit  
> worried about the CHANGE event. Here we might wanna restrict it to a  
> subset of possible changes inside the network device.
> 
> Regards
> 
> Marcel
> 

The events are carrier events are sampled by the linkwatch mechanism already, to eliminate
too active bouncing. The other events only happen when administrator does
something like add new device or take it on/off line.

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

* Re: [RFC] network devices generating uevents?
  2008-11-22  7:41 [RFC] network devices generating uevents? Stephen Hemminger
                   ` (3 preceding siblings ...)
  2008-11-23  6:32 ` Stephen Hemminger
@ 2008-11-23 16:13 ` Kay Sievers
  2008-11-24 19:45   ` [PATCH] netdev: generate kobject uevent on network events Stephen Hemminger
  4 siblings, 1 reply; 18+ messages in thread
From: Kay Sievers @ 2008-11-23 16:13 UTC (permalink / raw)
  To: linux-hotplug

On Sun, Nov 23, 2008 at 07:32, Stephen Hemminger <shemminger@vyatta.com> wrote:
> On Sun, 23 Nov 2008 03:13:29 +0100
> Marcel Holtmann <marcel@holtmann.org> wrote:
>> >> Perhaps the following would make it easier for applications to
>> >> track network device events without having to use netlink.
>> >
>> > Sure, that might be useful.
>> >
>> > These events can not happen at a high frequency, at any time, right?
>> > We are sure that things like UP/DOWN/CHANGE can not happen at a high
>> > frequency, maybe in some failure situation?
>> >
>> > Uevents are pretty expensive, every single of them may fork a
>> > /sbin/hotplug process, or a udev event process, regardless if anybody
>> > is listening to these events or not.
>> >
>> > We can do that only if we can be sure, that there are never things
>> > like "storms of events", which would cause a pretty high system load,
>> > and can even crash non-udev systems with out-of-memory, caused by the
>> > stateless non-managed (disabled by udev) /sbin/hotplug scripts.
>>
>> I was looking into the same thing the other day. And just getting the
>> interface up/down events via uevent is pretty useful. I am also
>> interested in getting the carrier signal of Ethernet cards via a
>> CHANGE event.
>>
>> If you look at the RTNL messages, it doesn't happen that often, but
>> the NEWLINK messages are maybe a little bit too much and we should
>> restrict it to event that really matter. So up/down are user triggered
>> event normally. So that should be safe. I would be a little bit
>> worried about the CHANGE event. Here we might wanna restrict it to a
>> subset of possible changes inside the network device.

> The events are carrier events are sampled by the linkwatch mechanism already, to eliminate
> too active bouncing. The other events only happen when administrator does
> something like add new device or take it on/off line.

Sounds good! I just wanted to make sure, that we are safe here. Every
other month someone comes up with the idea to pass errors, like I/O
failures over uevents, which just can't scale if we have many devices,
like thousands of block devices , which may all fail at the same time.

The patch looks fine besides the additional "add/remove" events, which
should not be send by the net core.
"udevadm monitor" looks like this here:
  UEVENT remove   /devices/pci0000:00/0000:00:1c.0/0000:02:00.0/net/eth0 (net)
  UEVENT remove   /devices/pci0000:00/0000:00:1c.0/0000:02:00.0/net/eth0 (net)
  UEVENT remove   /module/e1000e (module)
  UEVENT add      /module/e1000e (module)
  UEVENT add      /devices/pci0000:00/0000:00:1c.0/0000:02:00.0/net/eth0 (net)
  UEVENT add      /devices/pci0000:00/0000:00:1c.0/0000:02:00.0/net/eth0 (net)

If it makes things easier for possible consumers of these events, we
may want to add environment variables to the event like CARRIER=0,
CARRIER=1, or something that classifies the "change", or whatever else
may fit here? There is kobject_uevent_env() which would accept an
envp[], NULL terminated, string array.

Thanks,
Kay

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

* [PATCH] netdev: generate kobject uevent on network events.
  2008-11-23 16:13 ` Kay Sievers
@ 2008-11-24 19:45   ` Stephen Hemminger
  2008-11-24 19:55     ` Kay Sievers
  2008-11-24 20:06     ` Ben Hutchings
  0 siblings, 2 replies; 18+ messages in thread
From: Stephen Hemminger @ 2008-11-24 19:45 UTC (permalink / raw)
  To: Kay Sievers, David Miller; +Cc: Marcel Holtmann, linux-hotplug, netdev

It is easier for some applications to deal with text based interfaces
like uevent, rather than using netlink to listen for events.

Note, this does not deal with network namespaces but that is a generic
problem that already exists with kobjects (see rename events).

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

---
 net/core/Makefile |    1 
 net/core/uevent.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

--- a/net/core/Makefile	2008-11-24 08:40:10.000000000 -0800
+++ b/net/core/Makefile	2008-11-24 08:51:01.000000000 -0800
@@ -17,3 +17,4 @@ obj-$(CONFIG_NET_PKTGEN) += pktgen.o
 obj-$(CONFIG_NETPOLL) += netpoll.o
 obj-$(CONFIG_NET_DMA) += user_dma.o
 obj-$(CONFIG_FIB_RULES) += fib_rules.o
+obj-$(CONFIG_HOTPLUG) += uevent.o
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/net/core/uevent.c	2008-11-24 09:06:50.000000000 -0800
@@ -0,0 +1,60 @@
+/*
+ * Linux network device event notification
+ *
+ * Author:
+ *	Stephen Hemminger <shemminger@vyatta.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/netdevice.h>
+#include <linux/kobject.h>
+#include <linux/notifier.h>
+
+/*
+ * Generate uevent in response to nework device changes.
+ * NB: KOBJ_MOVE is already genereated by kobject_rename
+ */
+static int netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
+{
+	struct net_device *netdev = ptr;
+
+	switch (event) {
+	case NETDEV_UNREGISTER:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_REMOVE);
+		break;
+	case NETDEV_REGISTER:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_ADD);
+		break;
+	case NETDEV_UP:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_ONLINE);
+		break;
+	case NETDEV_DOWN:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_OFFLINE);
+		break;
+	case NETDEV_CHANGE:
+		if (netif_running(netdev)) {
+			char str[64] = "DEVSTATE=UP";
+			char *envp[2] = { str, NULL };
+
+			if (netif_oper_up(netdev))
+				strcat(str, ",RUNNING");
+			if (netif_carrier_ok(netdev))
+				strcat(str, ",LOWER_UP");
+			if (netif_dormant(netdev))
+				strcat(str, ",DORMANT");
+			kobject_uevent_env(&netdev->dev.kobj, KOBJ_CHANGE, envp);
+		}
+		break;
+	}
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block netdev_uevent_notifier = {
+	.notifier_call	= netdev_event,
+};
+
+static int __init netdev_uevent_init(void)
+{
+	return register_netdevice_notifier(&netdev_uevent_notifier);
+}
+device_initcall(netdev_uevent_init);


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

* Re: [PATCH] netdev: generate kobject uevent on network events.
  2008-11-24 19:45   ` [PATCH] netdev: generate kobject uevent on network events Stephen Hemminger
@ 2008-11-24 19:55     ` Kay Sievers
  2008-11-24 20:06       ` Stephen Hemminger
  2008-11-24 20:06     ` Ben Hutchings
  1 sibling, 1 reply; 18+ messages in thread
From: Kay Sievers @ 2008-11-24 19:55 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: David Miller, Marcel Holtmann, linux-hotplug, netdev

On Mon, Nov 24, 2008 at 20:45, Stephen Hemminger <shemminger@vyatta.com> wrote:
> It is easier for some applications to deal with text based interfaces
> like uevent, rather than using netlink to listen for events.
>
> Note, this does not deal with network namespaces but that is a generic
> problem that already exists with kobjects (see rename events).
>
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
>
> ---
>  net/core/Makefile |    1
>  net/core/uevent.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 62 insertions(+)
>
> --- a/net/core/Makefile 2008-11-24 08:40:10.000000000 -0800
> +++ b/net/core/Makefile 2008-11-24 08:51:01.000000000 -0800
> @@ -17,3 +17,4 @@ obj-$(CONFIG_NET_PKTGEN) += pktgen.o
>  obj-$(CONFIG_NETPOLL) += netpoll.o
>  obj-$(CONFIG_NET_DMA) += user_dma.o
>  obj-$(CONFIG_FIB_RULES) += fib_rules.o
> +obj-$(CONFIG_HOTPLUG) += uevent.o
> --- /dev/null   1970-01-01 00:00:00.000000000 +0000
> +++ b/net/core/uevent.c 2008-11-24 09:06:50.000000000 -0800
> @@ -0,0 +1,60 @@
> +/*
> + * Linux network device event notification
> + *
> + * Author:
> + *     Stephen Hemminger <shemminger@vyatta.com>
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/netdevice.h>
> +#include <linux/kobject.h>
> +#include <linux/notifier.h>
> +
> +/*
> + * Generate uevent in response to nework device changes.
> + * NB: KOBJ_MOVE is already genereated by kobject_rename
> + */
> +static int netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
> +{
> +       struct net_device *netdev = ptr;
> +
> +       switch (event) {
> +       case NETDEV_UNREGISTER:
> +               kobject_uevent(&netdev->dev.kobj, KOBJ_REMOVE);
> +               break;
> +       case NETDEV_REGISTER:
> +               kobject_uevent(&netdev->dev.kobj, KOBJ_ADD);
> +               break;

Did you do anything else to prevent the duplicated add/remove events?
The core does send these already. I replied with a "udevadm monitor"
output to your earlier mail. Don't you see the duplicates on your box?

Thanks,
Kay

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

* Re: [PATCH] netdev: generate kobject uevent on network events.
  2008-11-24 19:45   ` [PATCH] netdev: generate kobject uevent on network events Stephen Hemminger
  2008-11-24 19:55     ` Kay Sievers
@ 2008-11-24 20:06     ` Ben Hutchings
  2008-11-24 23:03       ` [PATCH] netdev: generate kobject uevent on network state Stephen Hemminger
  1 sibling, 1 reply; 18+ messages in thread
From: Ben Hutchings @ 2008-11-24 20:06 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Kay Sievers, David Miller, Marcel Holtmann, linux-hotplug, netdev

On Mon, 2008-11-24 at 11:45 -0800, Stephen Hemminger wrote:
[...]
> +	case NETDEV_CHANGE:
> +		if (netif_running(netdev)) {
> +			char str[64] = "DEVSTATE=UP";
> +			char *envp[2] = { str, NULL };
> +
> +			if (netif_oper_up(netdev))
> +				strcat(str, ",RUNNING");
> +			if (netif_carrier_ok(netdev))
> +				strcat(str, ",LOWER_UP");
> +			if (netif_dormant(netdev))
> +				strcat(str, ",DORMANT");
> +			kobject_uevent_env(&netdev->dev.kobj, KOBJ_CHANGE, envp);
> +		}
> +		break;

Unless I'm much mistaken, NETDEV_CHANGE should only be generated when
netif_running() is true, so the test is redundant.

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


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

* Re: [PATCH] netdev: generate kobject uevent on network events.
  2008-11-24 19:55     ` Kay Sievers
@ 2008-11-24 20:06       ` Stephen Hemminger
  2008-11-25  8:39         ` David Miller
  0 siblings, 1 reply; 18+ messages in thread
From: Stephen Hemminger @ 2008-11-24 20:06 UTC (permalink / raw)
  To: Kay Sievers; +Cc: David Miller, Marcel Holtmann, linux-hotplug, netdev

On Mon, 24 Nov 2008 20:55:02 +0100
"Kay Sievers" <kay.sievers@vrfy.org> wrote:

> On Mon, Nov 24, 2008 at 20:45, Stephen Hemminger <shemminger@vyatta.com> wrote:
> > It is easier for some applications to deal with text based interfaces
> > like uevent, rather than using netlink to listen for events.
> >
> > Note, this does not deal with network namespaces but that is a generic
> > problem that already exists with kobjects (see rename events).
> >
> > Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> >
> > ---
> >  net/core/Makefile |    1
> >  net/core/uevent.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 62 insertions(+)
> >
> > --- a/net/core/Makefile 2008-11-24 08:40:10.000000000 -0800
> > +++ b/net/core/Makefile 2008-11-24 08:51:01.000000000 -0800
> > @@ -17,3 +17,4 @@ obj-$(CONFIG_NET_PKTGEN) += pktgen.o
> >  obj-$(CONFIG_NETPOLL) += netpoll.o
> >  obj-$(CONFIG_NET_DMA) += user_dma.o
> >  obj-$(CONFIG_FIB_RULES) += fib_rules.o
> > +obj-$(CONFIG_HOTPLUG) += uevent.o
> > --- /dev/null   1970-01-01 00:00:00.000000000 +0000
> > +++ b/net/core/uevent.c 2008-11-24 09:06:50.000000000 -0800
> > @@ -0,0 +1,60 @@
> > +/*
> > + * Linux network device event notification
> > + *
> > + * Author:
> > + *     Stephen Hemminger <shemminger@vyatta.com>
> > + */
> > +
> > +#include <linux/kernel.h>
> > +#include <linux/netdevice.h>
> > +#include <linux/kobject.h>
> > +#include <linux/notifier.h>
> > +
> > +/*
> > + * Generate uevent in response to nework device changes.
> > + * NB: KOBJ_MOVE is already genereated by kobject_rename
> > + */
> > +static int netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
> > +{
> > +       struct net_device *netdev = ptr;
> > +
> > +       switch (event) {
> > +       case NETDEV_UNREGISTER:
> > +               kobject_uevent(&netdev->dev.kobj, KOBJ_REMOVE);
> > +               break;
> > +       case NETDEV_REGISTER:
> > +               kobject_uevent(&netdev->dev.kobj, KOBJ_ADD);
> > +               break;
> 
> Did you do anything else to prevent the duplicated add/remove events?
> The core does send these already. I replied with a "udevadm monitor"
> output to your earlier mail. Don't you see the duplicates on your box?
> 
> Thanks,
> Kay

okay, then i'll just take it out of here.

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

* [PATCH] netdev: generate kobject uevent on network state
  2008-11-24 20:06     ` Ben Hutchings
@ 2008-11-24 23:03       ` Stephen Hemminger
  2008-11-25  3:08         ` [PATCH] netdev: generate kobject uevent on network state transitions Kay Sievers
  2008-11-25  3:51         ` Marcel Holtmann
  0 siblings, 2 replies; 18+ messages in thread
From: Stephen Hemminger @ 2008-11-24 23:03 UTC (permalink / raw)
  Cc: Ben Hutchings, Kay Sievers, David Miller, Marcel Holtmann,
	linux-hotplug, netdev

It is easier for some applications to deal with text based interfaces
like uevent, rather than using netlink to listen for events.

Note, this does not deal with network namespaces but that is a generic
problem that already exists with kobjects (see rename events).

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

---
 net/core/Makefile |    1 
 net/core/uevent.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

--- a/net/core/Makefile	2008-11-24 12:07:18.000000000 -0800
+++ b/net/core/Makefile	2008-11-24 12:07:22.000000000 -0800
@@ -17,3 +17,4 @@ obj-$(CONFIG_NET_PKTGEN) += pktgen.o
 obj-$(CONFIG_NETPOLL) += netpoll.o
 obj-$(CONFIG_NET_DMA) += user_dma.o
 obj-$(CONFIG_FIB_RULES) += fib_rules.o
+obj-$(CONFIG_HOTPLUG) += uevent.o
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/net/core/uevent.c	2008-11-24 12:11:46.000000000 -0800
@@ -0,0 +1,55 @@
+/*
+ * Linux network device event notification
+ *
+ * Author:
+ *	Stephen Hemminger <shemminger@vyatta.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/netdevice.h>
+#include <linux/kobject.h>
+#include <linux/notifier.h>
+
+/*
+ * Generate uevent in response to network device state changes.
+ * Other events are already handled by device subsystem.
+ */
+static int netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
+{
+	struct net_device *netdev = ptr;
+
+	switch (event) {
+	case NETDEV_UP:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_ONLINE);
+		break;
+
+	case NETDEV_DOWN:
+		kobject_uevent(&netdev->dev.kobj, KOBJ_OFFLINE);
+		break;
+
+	case NETDEV_CHANGE: {
+		char str[64] = "DEVSTATE=UP";
+		char *envp[2] = { str, NULL };
+
+		if (netif_oper_up(netdev))
+			strcat(str, ",RUNNING");
+		if (netif_carrier_ok(netdev))
+			strcat(str, ",LOWER_UP");
+		if (netif_dormant(netdev))
+			strcat(str, ",DORMANT");
+		kobject_uevent_env(&netdev->dev.kobj, KOBJ_CHANGE, envp);
+		break;
+		}
+	}
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block netdev_uevent_notifier = {
+	.notifier_call	= netdev_event,
+};
+
+static int __init netdev_uevent_init(void)
+{
+	return register_netdevice_notifier(&netdev_uevent_notifier);
+}
+device_initcall(netdev_uevent_init);

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

* Re: [PATCH] netdev: generate kobject uevent on network state transitions
  2008-11-24 23:03       ` [PATCH] netdev: generate kobject uevent on network state Stephen Hemminger
@ 2008-11-25  3:08         ` Kay Sievers
  2008-11-25  3:51         ` Marcel Holtmann
  1 sibling, 0 replies; 18+ messages in thread
From: Kay Sievers @ 2008-11-25  3:08 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Ben Hutchings, David Miller, Marcel Holtmann, linux-hotplug,
	netdev

On Tue, Nov 25, 2008 at 00:03, Stephen Hemminger <shemminger@vyatta.com> wrote:
> It is easier for some applications to deal with text based interfaces
> like uevent, rather than using netlink to listen for events.
>
> Note, this does not deal with network namespaces but that is a generic
> problem that already exists with kobjects (see rename events).
>
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

Works fine here.

Thanks,
Kay

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

* Re: [PATCH] netdev: generate kobject uevent on network state transitions
  2008-11-24 23:03       ` [PATCH] netdev: generate kobject uevent on network state Stephen Hemminger
  2008-11-25  3:08         ` [PATCH] netdev: generate kobject uevent on network state transitions Kay Sievers
@ 2008-11-25  3:51         ` Marcel Holtmann
  2008-11-25  4:14           ` [PATCH] netdev: generate kobject uevent on network state Stephen Hemminger
  1 sibling, 1 reply; 18+ messages in thread
From: Marcel Holtmann @ 2008-11-25  3:51 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Ben Hutchings, Kay Sievers, David Miller, linux-hotplug, netdev

Hi Stephen,

> It is easier for some applications to deal with text based interfaces
> like uevent, rather than using netlink to listen for events.
>
> Note, this does not deal with network namespaces but that is a generic
> problem that already exists with kobjects (see rename events).
>
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
>
> ---
> net/core/Makefile |    1
> net/core/uevent.c |   61 ++++++++++++++++++++++++++++++++++++++++++++ 
> ++++++++++
> 2 files changed, 62 insertions(+)
>
> --- a/net/core/Makefile	2008-11-24 12:07:18.000000000 -0800
> +++ b/net/core/Makefile	2008-11-24 12:07:22.000000000 -0800
> @@ -17,3 +17,4 @@ obj-$(CONFIG_NET_PKTGEN) += pktgen.o
> obj-$(CONFIG_NETPOLL) += netpoll.o
> obj-$(CONFIG_NET_DMA) += user_dma.o
> obj-$(CONFIG_FIB_RULES) += fib_rules.o
> +obj-$(CONFIG_HOTPLUG) += uevent.o
> --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> +++ b/net/core/uevent.c	2008-11-24 12:11:46.000000000 -0800
> @@ -0,0 +1,55 @@
> +/*
> + * Linux network device event notification
> + *
> + * Author:
> + *	Stephen Hemminger <shemminger@vyatta.com>
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/netdevice.h>
> +#include <linux/kobject.h>
> +#include <linux/notifier.h>
> +
> +/*
> + * Generate uevent in response to network device state changes.
> + * Other events are already handled by device subsystem.
> + */
> +static int netdev_event(struct notifier_block *this, unsigned long  
> event, void *ptr)
> +{
> +	struct net_device *netdev = ptr;
> +
> +	switch (event) {
> +	case NETDEV_UP:
> +		kobject_uevent(&netdev->dev.kobj, KOBJ_ONLINE);
> +		break;
> +
> +	case NETDEV_DOWN:
> +		kobject_uevent(&netdev->dev.kobj, KOBJ_OFFLINE);
> +		break;
> +
> +	case NETDEV_CHANGE: {
> +		char str[64] = "DEVSTATE=UP";
> +		char *envp[2] = { str, NULL };
> +
> +		if (netif_oper_up(netdev))
> +			strcat(str, ",RUNNING");
> +		if (netif_carrier_ok(netdev))
> +			strcat(str, ",LOWER_UP");
> +		if (netif_dormant(netdev))
> +			strcat(str, ",DORMANT");
> +		kobject_uevent_env(&netdev->dev.kobj, KOBJ_CHANGE, envp);
> +		break;

do we wanna copy just what ifconfig shows or do we might be a more  
intelligent and have separate variables like RUNNING=1 etc.?

Regards

Marcel


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

* Re: [PATCH] netdev: generate kobject uevent on network state
  2008-11-25  3:51         ` Marcel Holtmann
@ 2008-11-25  4:14           ` Stephen Hemminger
  2008-11-25  9:09             ` David Miller
  0 siblings, 1 reply; 18+ messages in thread
From: Stephen Hemminger @ 2008-11-25  4:14 UTC (permalink / raw)
  To: Marcel Holtmann
  Cc: Ben Hutchings, Kay Sievers, David Miller, linux-hotplug, netdev

On Tue, 25 Nov 2008 04:51:53 +0100
Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Stephen,
> 
> > It is easier for some applications to deal with text based interfaces
> > like uevent, rather than using netlink to listen for events.
> >
> > Note, this does not deal with network namespaces but that is a generic
> > problem that already exists with kobjects (see rename events).
> >
> > Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> >
> > ---
> > net/core/Makefile |    1
> > net/core/uevent.c |   61 ++++++++++++++++++++++++++++++++++++++++++++ 
> > ++++++++++
> > 2 files changed, 62 insertions(+)
> >
> > --- a/net/core/Makefile	2008-11-24 12:07:18.000000000 -0800
> > +++ b/net/core/Makefile	2008-11-24 12:07:22.000000000 -0800
> > @@ -17,3 +17,4 @@ obj-$(CONFIG_NET_PKTGEN) += pktgen.o
> > obj-$(CONFIG_NETPOLL) += netpoll.o
> > obj-$(CONFIG_NET_DMA) += user_dma.o
> > obj-$(CONFIG_FIB_RULES) += fib_rules.o
> > +obj-$(CONFIG_HOTPLUG) += uevent.o
> > --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> > +++ b/net/core/uevent.c	2008-11-24 12:11:46.000000000 -0800
> > @@ -0,0 +1,55 @@
> > +/*
> > + * Linux network device event notification
> > + *
> > + * Author:
> > + *	Stephen Hemminger <shemminger@vyatta.com>
> > + */
> > +
> > +#include <linux/kernel.h>
> > +#include <linux/netdevice.h>
> > +#include <linux/kobject.h>
> > +#include <linux/notifier.h>
> > +
> > +/*
> > + * Generate uevent in response to network device state changes.
> > + * Other events are already handled by device subsystem.
> > + */
> > +static int netdev_event(struct notifier_block *this, unsigned long  
> > event, void *ptr)
> > +{
> > +	struct net_device *netdev = ptr;
> > +
> > +	switch (event) {
> > +	case NETDEV_UP:
> > +		kobject_uevent(&netdev->dev.kobj, KOBJ_ONLINE);
> > +		break;
> > +
> > +	case NETDEV_DOWN:
> > +		kobject_uevent(&netdev->dev.kobj, KOBJ_OFFLINE);
> > +		break;
> > +
> > +	case NETDEV_CHANGE: {
> > +		char str[64] = "DEVSTATE=UP";
> > +		char *envp[2] = { str, NULL };
> > +
> > +		if (netif_oper_up(netdev))
> > +			strcat(str, ",RUNNING");
> > +		if (netif_carrier_ok(netdev))
> > +			strcat(str, ",LOWER_UP");
> > +		if (netif_dormant(netdev))
> > +			strcat(str, ",DORMANT");
> > +		kobject_uevent_env(&netdev->dev.kobj, KOBJ_CHANGE, envp);
> > +		break;
> 
> do we wanna copy just what ifconfig shows or do we might be a more  
> intelligent and have separate variables like RUNNING=1 etc.?
> 
> Regards
> 
> Marcel

Was arbitrary choice to just use same flags as existing ifconfig.
What ever feels best I guess...


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

* Re: [PATCH] netdev: generate kobject uevent on network events.
  2008-11-24 20:06       ` Stephen Hemminger
@ 2008-11-25  8:39         ` David Miller
  0 siblings, 0 replies; 18+ messages in thread
From: David Miller @ 2008-11-25  8:39 UTC (permalink / raw)
  To: shemminger; +Cc: kay.sievers, marcel, linux-hotplug, netdev

From: Stephen Hemminger <shemminger@vyatta.com>
Date: Mon, 24 Nov 2008 12:06:45 -0800

> On Mon, 24 Nov 2008 20:55:02 +0100
> "Kay Sievers" <kay.sievers@vrfy.org> wrote:
> 
> > Did you do anything else to prevent the duplicated add/remove events?
> > The core does send these already. I replied with a "udevadm monitor"
> > output to your earlier mail. Don't you see the duplicates on your box?
> > 
> > Thanks,
> > Kay
> 
> okay, then i'll just take it out of here.

I'll wait for the updated patch then.

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

* Re: [PATCH] netdev: generate kobject uevent on network state
  2008-11-25  4:14           ` [PATCH] netdev: generate kobject uevent on network state Stephen Hemminger
@ 2008-11-25  9:09             ` David Miller
  2008-11-26  5:24               ` [PATCH] netdev: generate kobject uevent on network state transitions Marcel Holtmann
  0 siblings, 1 reply; 18+ messages in thread
From: David Miller @ 2008-11-25  9:09 UTC (permalink / raw)
  To: shemminger; +Cc: marcel, bhutchings, kay.sievers, linux-hotplug, netdev

From: Stephen Hemminger <shemminger@vyatta.com>
Date: Mon, 24 Nov 2008 20:14:40 -0800

> On Tue, 25 Nov 2008 04:51:53 +0100
> Marcel Holtmann <marcel@holtmann.org> wrote:
> 
> > > It is easier for some applications to deal with text based interfaces
> > > like uevent, rather than using netlink to listen for events.
> > >
> > > Note, this does not deal with network namespaces but that is a generic
> > > problem that already exists with kobjects (see rename events).
> > >
> > > Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
 ...
> > do we wanna copy just what ifconfig shows or do we might be a more  
> > intelligent and have separate variables like RUNNING=1 etc.?
> 
> Was arbitrary choice to just use same flags as existing ifconfig.
> What ever feels best I guess...

So what do folks want me to do here?  Should I put Stephen's
latest patch in, or do we want to make some kind of flags change?

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

* Re: [PATCH] netdev: generate kobject uevent on network state transitions
  2008-11-25  9:09             ` David Miller
@ 2008-11-26  5:24               ` Marcel Holtmann
  2008-11-26 12:09                 ` Kay Sievers
  0 siblings, 1 reply; 18+ messages in thread
From: Marcel Holtmann @ 2008-11-26  5:24 UTC (permalink / raw)
  To: David Miller; +Cc: shemminger, bhutchings, kay.sievers, linux-hotplug, netdev

Hi Dave,

>>>> It is easier for some applications to deal with text based  
>>>> interfaces
>>>> like uevent, rather than using netlink to listen for events.
>>>>
>>>> Note, this does not deal with network namespaces but that is a  
>>>> generic
>>>> problem that already exists with kobjects (see rename events).
>>>>
>>>> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> ...
>>> do we wanna copy just what ifconfig shows or do we might be a more
>>> intelligent and have separate variables like RUNNING=1 etc.?
>>
>> Was arbitrary choice to just use same flags as existing ifconfig.
>> What ever feels best I guess...
>
> So what do folks want me to do here?  Should I put Stephen's
> latest patch in, or do we want to make some kind of flags change?

I am thinking of using per value variables. My personal choice.

Kay, any pointers or opinions from you?

Regards

Marcel


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

* Re: [PATCH] netdev: generate kobject uevent on network state transitions
  2008-11-26  5:24               ` [PATCH] netdev: generate kobject uevent on network state transitions Marcel Holtmann
@ 2008-11-26 12:09                 ` Kay Sievers
  0 siblings, 0 replies; 18+ messages in thread
From: Kay Sievers @ 2008-11-26 12:09 UTC (permalink / raw)
  To: Marcel Holtmann
  Cc: David Miller, shemminger, bhutchings, linux-hotplug, netdev

On Wed, Nov 26, 2008 at 06:24, Marcel Holtmann <marcel@holtmann.org> wrote:
>>>>> It is easier for some applications to deal with text based interfaces
>>>>> like uevent, rather than using netlink to listen for events.
>>>>>
>>>>> Note, this does not deal with network namespaces but that is a generic
>>>>> problem that already exists with kobjects (see rename events).
>>>>>
>>>>> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
>> ...
>>>> do we wanna copy just what ifconfig shows or do we might be a more
>>>> intelligent and have separate variables like RUNNING=1 etc.?
>>>
>>> Was arbitrary choice to just use same flags as existing ifconfig.
>>> What ever feels best I guess...
>>
>> So what do folks want me to do here?  Should I put Stephen's
>> latest patch in, or do we want to make some kind of flags change?
>
> I am thinking of using per value variables. My personal choice.
>
> Kay, any pointers or opinions from you?

As long as we can match values with fnmatch(), it should all work fine.

Bitmasks are fine if represented as binary strings, otherwise, like
for hex strings, the fnmatch() looks really weird.

As long as no string value in the list is contained in another value,
like matching for RUNNING, IS_RUNNING, RUNNING2 would be, it's fine to
stuff them all in one string just separated by comma. If they can ever
overlap, we would need to add the comma also to the beginning and end
of the string, to be able to put it into the match string like
"*,RUNNING,*", to avoid wrong matches by partial string matches.

I leave it up to you, I'm fighting with really weird things in some
other subsystems, so all of the possible options here for the net
events look pretty to me, and should work fine, compared to some stuff
I'm used to. :)

Thanks,
Kay

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

end of thread, other threads:[~2008-11-26 12:09 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-22  7:41 [RFC] network devices generating uevents? Stephen Hemminger
2008-11-22 14:08 ` Kay Sievers
2008-11-22 19:22 ` Karl O. Pinc
2008-11-23  2:13 ` Marcel Holtmann
2008-11-23  6:32 ` Stephen Hemminger
2008-11-23 16:13 ` Kay Sievers
2008-11-24 19:45   ` [PATCH] netdev: generate kobject uevent on network events Stephen Hemminger
2008-11-24 19:55     ` Kay Sievers
2008-11-24 20:06       ` Stephen Hemminger
2008-11-25  8:39         ` David Miller
2008-11-24 20:06     ` Ben Hutchings
2008-11-24 23:03       ` [PATCH] netdev: generate kobject uevent on network state Stephen Hemminger
2008-11-25  3:08         ` [PATCH] netdev: generate kobject uevent on network state transitions Kay Sievers
2008-11-25  3:51         ` Marcel Holtmann
2008-11-25  4:14           ` [PATCH] netdev: generate kobject uevent on network state Stephen Hemminger
2008-11-25  9:09             ` David Miller
2008-11-26  5:24               ` [PATCH] netdev: generate kobject uevent on network state transitions Marcel Holtmann
2008-11-26 12:09                 ` Kay Sievers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).