Patchwork netdev: generate kobject uevent on network state transitions

login
register
mail settings
Submitter stephen hemminger
Date Nov. 24, 2008, 11:03 p.m.
Message ID <20081124150347.73050f98@extreme>
Download mbox | patch
Permalink /patch/10534/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

stephen hemminger - Nov. 24, 2008, 11:03 p.m.
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(+)

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Kay Sievers - Nov. 25, 2008, 3:08 a.m.
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
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marcel Holtmann - Nov. 25, 2008, 3:51 a.m.
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

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
stephen hemminger - Nov. 25, 2008, 4:14 a.m.
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...

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - Nov. 25, 2008, 9:09 a.m.
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?
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marcel Holtmann - Nov. 26, 2008, 5:24 a.m.
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

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Kay Sievers - Nov. 26, 2008, 12:09 p.m.
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
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

--- 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);