Patch: Device operative state notification against 2.5.7
Subsystems (2)
Hi Linus,
attached you find a patch against Linux 2.5.7 that revives the IFF_RUNNING flag in the dev->flags element. Some time ago, Alexey has replaced IFF_RUNNING by a bit in dev->state, AFAIK because of locking reasons.
When enabled, a thread is compiled into the kernel that scans the network device list on every netif_carrier_on()/_off() called by a device driver and mirrors the !LINK_STATE_NOCARRIER bit of dev->state into IFF_RUNNING. If these values differ for a device, a netlink message is broadcasted. This allows user processes to be notified about operative state changes. Actually, I've written some patches for the zebra routing daemon so that it stops using an interface while the driver thinks that it is down.
There are still drivers left that play with IFF_RUNNING directly, but I think they can be updated during 2.5 development cycle. The patch seems to be stable, I've also submitted a 2.4 version for the -ac tree.
Cheers, Stefan
include/linux/netdevice.h +16 -0
@@ -210,6 +210,12 @@ __LINK_STATE_RX_SCHED }; +/* This gets called by netif_carrier_on()/_off() whenever +* state of an interface changes +*/ +#ifdef CONFIG_LINKWATCH +extern void wake_linkwatch_thread (void ); +#endif /* * This structure holds at boot time configured netdevice settings. They
@@ -639,14 +645,24 @@static inline void netif_carrier_on (struct net_device *dev) { +#ifdef CONFIG_LINKWATCH +if (test_and_clear_bit (__LINK_STATE_NOCARRIER, &dev->state)) +wake_linkwatch_thread (); +#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)) +wake_linkwatch_thread (); +#else set_bit (__LINK_STATE_NOCARRIER, &dev->state); +#endif }/* Hot-plugging. */
net/Config.help +8 -0
@@ -385,6 +385,14 @@ subnetwork boundaries. These shortcut connections bypass routers enhancing overall network performance. +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 maintain an administrative state, a few even break this + option. Compliant drivers change the RUNNING flag in ifconfig output + depending on operative state. If unsure, say 'N'. + CONFIG_ECONET Econet is a fairly old and slow networking protocol mainly used by Acorn computers to access file and print servers. It uses native
net/Config.in +3 -0
@@ -46,6 +46,9 @@ fi fi tristate '802.1Q VLAN Support' CONFIG_VLAN_8021Q +if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then + bool 'Device link state notification (EXPERIMENTAL)' CONFIG_LINKWATCH +fi comment ' ' tristate 'The IPX protocol' CONFIG_IPX
net/core/Makefile +2 -0
@@ -30,4 +30,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 +14 -2
@@ -720,6 +720,12 @@*/ dev->flags |=IFF_UP ; +if (netif_carrier_ok (dev)) { + dev->flags |=IFF_RUNNING ; + }else { + dev->flags &= ~IFF_RUNNING ; + } +set_bit (__LINK_STATE_START, &dev->state);/*
@@ -826,7 +832,7 @@* Device is now down. */ - dev->flags &= ~IFF_UP ; + dev->flags &= ~(IFF_UP |IFF_RUNNING );#ifdef CONFIG_NET_FASTROUTE dev_clear_fastroute (dev);#endif
@@ -2668,7 +2674,9 @@#ifdef CONFIG_NET_DIVERT extern void dv_init (void );#endif /* CONFIG_NET_DIVERT */ - +#ifdef CONFIG_LINKWATCH +extern void linkwatch_init (void ); +#endif /* CONFIG_LINKWATCH */ /* * Callers must hold the rtnl semaphore. See the comment at the
@@ -2811,6 +2819,10 @@*/ net_device_init (); + +#ifdef CONFIG_LINKWATCH +linkwatch_init (); +#endif /* CONFIG_LINKWATCH */ return 0 ; }
net/core/link_watch.c +106 -0
106 lines not on this page · raw message
net/netsyms.c +4 -0
@@ -596,4 +596,8 @@EXPORT_SYMBOL (wireless_send_event);#endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */ +#ifdef CONFIG_LINKWATCH +EXPORT_SYMBOL (wake_linkwatch_thread); +#endif +#endif /* CONFIG_NET */