netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] (1/5) replay netdev notifier events on registration
@ 2004-01-13 18:58 Stephen Hemminger
  2004-01-14  0:36 ` David S. Miller
  0 siblings, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2004-01-13 18:58 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev

Several protocols register for network device notification to detect new new network devices;
but then have to walk the device list to capture the devices that are already up.
This leaves a exposed window between when the notifier is registered and when the list walk
occurs. Also, in several cases, there is a different code path for the pre-existing and
new devices which leads to bug exposure.

The solution is to replay the registration and up events for existing devices into the
new notifier.

All notifiers in 2.6.1 have been audited and the other patches fix places
where protocols were doing there own registered device discovery loop.

Thanks to Al Viro for the suggestion.

diff -Nru a/net/core/dev.c b/net/core/dev.c
--- a/net/core/dev.c	Thu Dec 18 15:32:11 2003
+++ b/net/core/dev.c	Thu Dec 18 15:32:11 2003
@@ -946,11 +946,29 @@
  *	The notifier passed is linked into the kernel structures and must
  *	not be reused until it has been unregistered. A negative errno code
  *	is returned on a failure.
+ *
+ * 	When registered all registration and up events are replayed
+ *	to the new notifier to allow device to have a race free 
+ *	view of the network device list.
  */
 
 int register_netdevice_notifier(struct notifier_block *nb)
 {
-	return notifier_chain_register(&netdev_chain, nb);
+	struct net_device *dev;
+	int err;
+
+	rtnl_lock();
+	err = notifier_chain_register(&netdev_chain, nb);
+	if (!err) {
+		for (dev = dev_base; dev; dev = dev->next) {
+			nb->notifier_call(nb, NETDEV_REGISTER, dev);
+
+			if (dev->flags & IFF_UP) 
+				nb->notifier_call(nb, NETDEV_UP, dev);
+		}
+	}
+	rtnl_unlock();
+	return err;
 }
 
 /**

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

end of thread, other threads:[~2004-01-16  3:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-13 18:58 [PATCH] (1/5) replay netdev notifier events on registration Stephen Hemminger
2004-01-14  0:36 ` David S. Miller
2004-01-15  0:40   ` [PATCH] decnet initialization race Stephen Hemminger
2004-01-15  8:45     ` David S. Miller
2004-01-15  0:43   ` [PATH] atm/clip device discovery on init not needed Stephen Hemminger
2004-01-15  8:44     ` David S. Miller
2004-01-15 22:59     ` Stephen Hemminger
2004-01-15 23:00       ` David S. Miller
2004-01-15  0:44   ` [PATCH] (1/5) replay netdev notifier events on registration Stephen Hemminger
2004-01-15  8:42     ` David S. Miller
2004-01-15 18:16       ` Stephen Hemminger
2004-01-15 19:51         ` David S. Miller
2004-01-16  3:19       ` chas williams

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