Skip to contentSkip to conversation

(4/4) dlci netdevice event handling

PATCH New Stephen Hemminger 1 participant 2 messages Sep 8, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 (4/4) dlci netdevice event handling

Since dlci device is a pseudo device built on top of sdla, change it to handle unregister events and delete itself.

drivers/net/wan/dlci.c +28 -2
diff -Nru a/drivers/net/wan/dlci.c b/drivers/net/wan/dlci.c
@@ -509,20 +509,46 @@
 
 }
 
-int __init init_dlci(void)
+/* if slave is unregistering, then cleanup master */
+static int dlci_dev_event(struct notifier_block *unused,
+			  unsigned long event, void *ptr)
+{
+	struct net_device *dev = (struct net_device *) ptr;
+
+	if (event == NETDEV_UNREGISTER) {
+		struct dlci_local *dlp;
+
+		list_for_each_entry(dlp, &dlci_devs, list) {
+			if (dlp->slave == dev) {
+				unregister_netdevice(dlp->master);
+				dev_put(dlp->slave);
+				break;
+			}
+		}
+	}
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block dlci_notifier = {
+	.notifier_call = dlci_dev_event,
+};
+
+static int __init init_dlci(void)
 {
 	dlci_ioctl_set(dlci_ioctl);
+	register_netdevice_notifier(&dlci_notifier);
 
 	printk("%s.\n", version);
 
 	return 0;
 }
 
-void __exit dlci_exit(void)
+static void __exit dlci_exit(void)
 {
 	struct dlci_local	*dlp, *nxt;
 	
 	dlci_ioctl_set(NULL);
+	unregister_netdevice_notifier(&dlci_notifier);
 
 	rtnl_lock();
 	list_for_each_entry_safe(dlp, nxt, &dlci_devs, list) {
#1 lore raw

PATCH 1/1 (5/4) dlci netdevice event handling

One more patch, found this in testing
-- need to delete device from list when unregistered
because of callback.

drivers/net/wan/dlci.c +1 -0
diff -Nru a/drivers/net/wan/dlci.c b/drivers/net/wan/dlci.c
@@ -520,6 +520,7 @@
 
 		list_for_each_entry(dlp, &dlci_devs, list) {
 			if (dlp->slave == dev) {
+				list_del(&dlp->list);
 				unregister_netdevice(dlp->master);
 				dev_put(dlp->slave);
 				break;