Patch: Backport of link state notification to 2.4.20rc1
Subsystems (3)
Hi,
having the link state notification stuff in 2.4 is still a major goal for me. I've taken the 2.5 implementation Jamal and I have worked out, removed the semantic changes towards RFC2863 and replaced the workqueue with a combination of timer and kevent.
Different to my previous 2.4.18 version this patch needs neither its own kernel thread nor does it touch the in kernel IFF_RUNNING flag anymore, so it is quite non-intrusive: Drivers that implement netif_carrier_on()/netif_carrier_off() will use the notifications, the rest won't be harmed.
Even though David and Alexey seem to be busy with ipsec stuff, I don't want to wait any longer to post the patch for public review. I've done succesful tests with a hacked starfire (trivial three-liner, coming the next days) and vlan driver. I was not able to check SMP compatibility.
I know of other people on this list who want to have this feature in 2.4, too. Please be so kind and test the patch on your machines. If no objections arise, I'm going to submit this for 2.4 inclusion.
Cheers, Stefan
Documentation/Configure.help +12 -0
@@ -26011,6 +26011,18 @@ would like kernel messages to be formatted into GDB $O packets so that GDB prints them as program output, say 'Y'. +Device link state notification +CONFIG_LINKWATCH + When this option is enabled, the kernel will forward changes in the + operative ("RUNNING") state of an interface via the netlink socket. + This is most useful when running linux as a router. + + Note that currently not many drivers support this, compliant ones + can be found by watching the the RUNNING flag in ifconfig output + that should follow operative state. + + If unsure, say 'N'. + 802.1Q VLAN Support CONFIG_VLAN_8021Q Select this and you will be able to create 802.1Q VLAN interfaces on your
include/linux/netdevice.h +16 -1
@@ -207,7 +207,8 @@ __LINK_STATE_PRESENT, __LINK_STATE_SCHED, __LINK_STATE_NOCARRIER, - __LINK_STATE_RX_SCHED + __LINK_STATE_RX_SCHED, + __LINK_STATE_LINKWATCH_PENDING };
@@ -630,6 +631,10 @@* who is responsible for serialization of these calls. */ +#ifdef CONFIG_LINKWATCH +extern void linkwatch_fire_event (struct net_device *dev); +#endif +static inline int netif_carrier_ok (struct net_device *dev) {return !test_bit (__LINK_STATE_NOCARRIER, &dev->state);
@@ -639,14 +644,24 @@static inline void netif_carrier_on (struct net_device *dev) { +#ifdef CONFIG_LINKWATCH +if (test_and_clear_bit (__LINK_STATE_NOCARRIER, &dev->state)) +linkwatch_fire_event (dev); +#else clear_bit (__LINK_STATE_NOCARRIER, &dev->state); +#endif if (netif_running (dev))__netdev_watchdog_up (dev); }static inline void netif_carrier_off (struct net_device *dev) { +#ifdef CONFIG_LINKWATCH +if (!test_and_set_bit (__LINK_STATE_NOCARRIER, &dev->state)) +linkwatch_fire_event (dev); +#else set_bit (__LINK_STATE_NOCARRIER, &dev->state); +#endif }/* Hot-plugging. */
net/Config.in +1 -0
@@ -48,6 +48,7 @@ bool ' Per-VC IP filter kludge' CONFIG_ATM_BR2684_IPFILTER fi fi + bool 'Device link state notification (EXPERIMENTAL)' CONFIG_LINKWATCH fi tristate '802.1Q VLAN Support' CONFIG_VLAN_8021Q
net/core/Makefile +2 -0
@@ -31,4 +31,6 @@ # Ugly. I wish all wireless drivers were moved in drivers/net/wireless obj-$(CONFIG_NET_PCMCIA_RADIO) += wireless.o +obj-$(CONFIG_LINKWATCH) += link_watch.o + include $(TOPDIR)/Rules.make
net/core/dev.c +22 -0
@@ -194,6 +194,12 @@#endif +#ifdef CONFIG_LINKWATCH +extern void linkwatch_init (void ); +extern void linkwatch_run_queue (void ); +#endif + +/****************************************************************************************** Protocol management and registration routines
@@ -2628,6 +2634,18 @@/* Rebroadcast unregister notification */ notifier_call_chain (&netdev_chain,NETDEV_UNREGISTER , dev); } + +#ifdef CONFIG_LINKWATCH +if (test_bit (__LINK_STATE_LINKWATCH_PENDING, &dev->state)) { +/* We must not have linkwatch events pending +* on unregister. If this happens, we simply +* run the queue unscheduled, resulting in a +* noop for this device +*/ +linkwatch_run_queue (); + } +#endif + current->state =TASK_INTERRUPTIBLE ;schedule_timeout (HZ /4 ); current->state =TASK_RUNNING ;
@@ -2675,6 +2693,10 @@dv_init ();#endif /* CONFIG_NET_DIVERT */ +#ifdef CONFIG_LINKWATCH +linkwatch_init (); +#endif +/* * Initialise the packet receive queues. */
net/core/link_watch.c +149 -0
149 lines not on this page · raw message
net/netsyms.c +4 -0
@@ -591,6 +591,10 @@EXPORT_SYMBOL (softnet_data); +#ifdef CONFIG_LINKWATCH +EXPORT_SYMBOL (linkwatch_fire_event); +#endif +#if defined(CONFIG_NET_RADIO ) || defined(CONFIG_NET_PCMCIA_RADIO )#include <net/iw_handler.h> EXPORT_SYMBOL (wireless_send_event);
Quoted 6 lines · Stefan Rompf
Hi,
having the link state notification stuff in 2.4 is still a major goal for me. I've taken the 2.5 implementation Jamal and I have worked out, removed the semantic changes towards RFC2863 and replaced the workqueue with a combination of timer and kevent.
By the way, is the 2.5 implementation going in? Would sure be lovely.
Signature · 2 lines
http://www.PowerDNS.com Versatile DNS Software & Services http://lartc.org Linux Advanced Routing & Traffic Control HOWTO
Hi,
Quoted 1 line · bert hubert
By the way, is the 2.5 implementation going in? Would sure be lovely.
it should be somewhere in David's inbox waiting for his evaluation.
Stefan
Re: Patch: Backport of link state notification to 2.4.20
In reply to Stefan RompfHi David,
attached is the recent backport of link state notification for the stable kernel series. The feature is optional and can be configured away to nothing, and tested on several systems.
I'd really like to have it in 2.4.21, and as your the one to decide before Marcelo gets it, can you have a look?
Stefan
Documentation/Configure.help +12 -0
@@ -26011,6 +26011,18 @@ would like kernel messages to be formatted into GDB $O packets so that GDB prints them as program output, say 'Y'. +Device link state notification +CONFIG_LINKWATCH + When this option is enabled, the kernel will forward changes in the + operative ("RUNNING") state of an interface via the netlink socket. + This is most useful when running linux as a router. + + Note that currently not many drivers support this, compliant ones + can be found by watching the RUNNING flag in ifconfig output that + should follow operative state. + + If unsure, say 'N'. + 802.1Q VLAN Support CONFIG_VLAN_8021Q Select this and you will be able to create 802.1Q VLAN interfaces on your
include/linux/netdevice.h +16 -1
@@ -207,7 +207,8 @@ __LINK_STATE_PRESENT, __LINK_STATE_SCHED, __LINK_STATE_NOCARRIER, - __LINK_STATE_RX_SCHED + __LINK_STATE_RX_SCHED, + __LINK_STATE_LINKWATCH_PENDING };
@@ -630,6 +631,10 @@* who is responsible for serialization of these calls. */ +#ifdef CONFIG_LINKWATCH +extern void linkwatch_fire_event (struct net_device *dev); +#endif +static inline int netif_carrier_ok (struct net_device *dev) {return !test_bit (__LINK_STATE_NOCARRIER, &dev->state);
@@ -639,14 +644,24 @@static inline void netif_carrier_on (struct net_device *dev) { +#ifdef CONFIG_LINKWATCH +if (test_and_clear_bit (__LINK_STATE_NOCARRIER, &dev->state)) +linkwatch_fire_event (dev); +#else clear_bit (__LINK_STATE_NOCARRIER, &dev->state); +#endif if (netif_running (dev))__netdev_watchdog_up (dev); }static inline void netif_carrier_off (struct net_device *dev) { +#ifdef CONFIG_LINKWATCH +if (!test_and_set_bit (__LINK_STATE_NOCARRIER, &dev->state)) +linkwatch_fire_event (dev); +#else set_bit (__LINK_STATE_NOCARRIER, &dev->state); +#endif }/* Hot-plugging. */
net/Config.in +1 -0
@@ -48,6 +48,7 @@ bool ' Per-VC IP filter kludge' CONFIG_ATM_BR2684_IPFILTER fi fi + bool 'Device link state notification (EXPERIMENTAL)' CONFIG_LINKWATCH fi tristate '802.1Q VLAN Support' CONFIG_VLAN_8021Q
net/core/Makefile +2 -0
@@ -31,4 +31,6 @@ # Ugly. I wish all wireless drivers were moved in drivers/net/wireless obj-$(CONFIG_NET_PCMCIA_RADIO) += wireless.o +obj-$(CONFIG_LINKWATCH) += link_watch.o + include $(TOPDIR)/Rules.make
net/core/dev.c +22 -0
@@ -194,6 +194,12 @@#endif +#ifdef CONFIG_LINKWATCH +extern void linkwatch_init (void ); +extern void linkwatch_run_queue (void ); +#endif + +/****************************************************************************************** Protocol management and registration routines
@@ -2628,6 +2634,18 @@/* Rebroadcast unregister notification */ notifier_call_chain (&netdev_chain,NETDEV_UNREGISTER , dev); } + +#ifdef CONFIG_LINKWATCH +if (test_bit (__LINK_STATE_LINKWATCH_PENDING, &dev->state)) { +/* We must not have linkwatch events pending +* on unregister. If this happens, we simply +* run the queue unscheduled, resulting in a +* noop for this device +*/ +linkwatch_run_queue (); + } +#endif + current->state =TASK_INTERRUPTIBLE ;schedule_timeout (HZ /4 ); current->state =TASK_RUNNING ;
@@ -2675,6 +2693,10 @@dv_init ();#endif /* CONFIG_NET_DIVERT */ +#ifdef CONFIG_LINKWATCH +linkwatch_init (); +#endif +/* * Initialise the packet receive queues. */
net/core/link_watch.c +149 -0
149 lines not on this page · raw message
net/netsyms.c +4 -0
@@ -591,6 +591,10 @@EXPORT_SYMBOL (softnet_data); +#ifdef CONFIG_LINKWATCH +EXPORT_SYMBOL (linkwatch_fire_event); +#endif +#if defined(CONFIG_NET_RADIO ) || defined(CONFIG_NET_PCMCIA_RADIO )#include <net/iw_handler.h> EXPORT_SYMBOL (wireless_send_event);
Re: Patch: Backport of link state notification to 2.4.20
Quoted 6 lines · Stefan Rompf
Hi David,
attached is the recent backport of link state notification for the stable kernel series. The feature is optional and can be configured away to nothing, and tested on several systems.
It might be a backport, but I haven't seen a 2.5.x version posted in a while. If this is going into the stable series, it should already be merged in 2.5.x at the same time, if not first.
Quoted 2 lines
I'd really like to have it in 2.4.21, and as your the one to decide before Marcelo gets it, can you have a look?
s/before/if/ :)
comments follow. note these are all minor objections: I think the patch needs revising, but I also think it is ok overall and support its eventual inclusion [after tidying]. Not that my opinion matters much here compared to DaveM's (and Jamal's and Alexey's and...)...
overall, I have one question: how does netdev_state_change(dev) propagate link status to userspace? Via the IFF_RUNNING flag's presence/absence when IFF_UP is true?
include/linux/netdevice.h line 636
Quoted 10 lines
diff -uNr
linux-2.4.20rc1/include/linux/netdevice.hlinux/include/linux/netdevice.hinclude/linux/netdevice.h +3
-0@@ -630,6 +631,10 @@* who is responsible for serialization of these calls. */ +#ifdef CONFIG_LINKWATCH +extern void linkwatch_fire_event (struct net_device *dev); +#endif
remove the ifdef, not needed and ifdefs are discouraged in all Linux code.
net/Config.in line 51
Quoted 8 lines
diff -uNr linux-2.4.20rc1/net/Config.in linux/net/Config.in
net/Config.in +1
-0@@ -48,6 +48,7 @@ bool ' Per-VC IP filter kludge' CONFIG_ATM_BR2684_IPFILTER fi fi + bool 'Device link state notification (EXPERIMENTAL)' CONFIG_LINKWATCH
ifyou mark it experimental, then it should be
dep_bool ... CONFIG_LINKWATCH $CONFIG_EXPERIMENTAL
net/core/Makefile line 36
Quoted 10 lines
diff -uNr linux-2.4.20rc1/net/core/Makefile linux/net/core/Makefile
net/core/Makefile +2
-0@@ -31,4 +31,6 @@ # Ugly. I wish all wireless drivers were moved in drivers/net/wireless obj-$(CONFIG_NET_PCMCIA_RADIO) += wireless.o +obj-$(CONFIG_LINKWATCH) += link_watch.o + include $(TOPDIR)/Rules.make
add it to export-objs too (because of below change)
net/core/dev.c line 200
Quoted 11 lines
diff -uNr
linux-2.4.20rc1/net/core/dev.clinux/net/core/dev.cnet/core/dev.c +4
-0@@ -194,6 +194,12 @@#endif +#ifdef CONFIG_LINKWATCH +extern void linkwatch_init (void ); +extern void linkwatch_run_queue (void ); +#endif
ug :)
the ifdef can be killed, and the prototypes should be in netdevice.h (or any other header), not in mainline code.
net/core/dev.c line 2698
Quoted 7 lines
net/core/dev.c +3
-0@@ -2675,6 +2693,10 @@dv_init ();#endif /* CONFIG_NET_DIVERT */ +#ifdef CONFIG_LINKWATCH +linkwatch_init (); +#endif
no need for an ifdef, make linkwatch_init() a no-op static inline for the !CONFIG_LINKWATCH case.
net/core/dev.c line 2700
Quoted 2 lines
net/core/dev.c +2
-0+static unsigned long linkwatch_flags =0 ; +static unsigned long linkwatch_nextevent =0 ;
statics are automatically initialized to zero, don't do it explicitly. you waste a couple bytes in the kernel image storing a zero value.
net/core/dev.c
Quoted 9 lines
net/core/dev.c +9
-0+ +static void linkwatch_event (void *dummy); +static void linkwatch_timer (unsigned long dummy); + +static struct tq_struct linkwatch_tq; +static struct timer_list linkwatch_ti; + +static LIST_HEAD (lweventlist); +static spinlock_t lweventlist_lock =SPIN_LOCK_UNLOCKED ;
why initialize some complex structs programmatically and some explicitly? IMO for consistency you should initialize lweventlist_lock in linkwatch_init(). (or vice versa)
net/core/dev.c
Quoted 8 lines
net/core/dev.c +8
-0+/* Must be called with the rtnl semaphore held */ +void linkwatch_run_queue (void ) { +LIST_HEAD (head); +struct list_head *n, *next; + +spin_lock_irq (&lweventlist_lock); +list_splice_init (&lweventlist, &head); +spin_unlock_irq (&lweventlist_lock);
spin_lock_irq{save,restore} would probably better serve you here...
net/core/dev.c
Quoted 10 lines
net/core/dev.c +10
-0+ +list_for_each_safe (n, next, &head) { + struct lw_event *event = list_entry(n, struct lw_event, list); +struct net_device *dev = event->dev; + +if (event == &singleevent) { +clear_bit (LW_SE_USED , &linkwatch_flags); + }else { +kfree (event); + }
style: braces not needed
net/core/dev.c
Quoted 9 lines
net/core/dev.c +9
-0+ +/* We are about to handle this device, +* so new events can be accepted +*/ +clear_bit (__LINK_STATE_LINKWATCH_PENDING, &dev->state); + +if (dev->flags &IFF_UP ) { +netdev_state_change (dev); + }
likewise. (pointlessly makes code longer)
Quoted 5 lines
net/core/dev.c +5
-0+ +dev_put (dev); + } +} +
net/core/dev.c
Quoted 10 lines
net/core/dev.c +10
-0+ +static void linkwatch_event (void *dummy) +{ +/* Limit the number of linkwatch events to one +* per second so that a runaway driver does not +* cause a storm of messages on the netlink +* socket +*/ + linkwatch_nextevent = jiffies +HZ ; +clear_bit (LW_RUNNING , &linkwatch_flags);
the high availability folks would prefer a half-second (HZ >> 1).
net/core/dev.c
Quoted 5 lines
net/core/dev.c +5
-0+void __init linkwatch_init (void ) { + linkwatch_ti.function = linkwatch_timer; +init_timer (&linkwatch_ti); +INIT_TQUEUE (&linkwatch_tq, linkwatch_event,NULL ); +}
set the timer function after the initialize the timer :)
net/netsyms.c line 596
Quoted 11 lines
+
diff -uNrlinux-2.4.20rc1/net/netsyms.clinux/net/netsyms.cnet/netsyms.c +3
-0@@ -591,6 +591,10 @@EXPORT_SYMBOL (softnet_data); +#ifdef CONFIG_LINKWATCH +EXPORT_SYMBOL (linkwatch_fire_event); +#endif
move this to link_watch.c so that the featureset is fully encapsulated.
Jeff
Re: Patch: Backport of link state notification to 2.4.20
Quoted 10 lines · Jeff Garzik
Quoted 6 lines · Stefan Rompf
Hi David,
attached is the recent backport of link state notification for the stable kernel series. The feature is optional and can be configured away to nothing, and tested on several systems.
It might be a backport, but I haven't seen a 2.5.x version posted in a while. If this is going into the stable series, it should already be merged in 2.5.x at the same time, if not first.
...and of course this email arrives immediately in my inbox ;-)
Which leads to the question: why CONFIG_LINKWATCH in 2.4 but not 2.5?
Let's do the same in both kernels unless there is a good reason not to...