1 /*
2  *	Device event handling
3  *	Linux ethernet bridge
4  *
5  *	Authors:
6  *	Lennert Buytenhek		<buytenh@gnu.org>
7  *
8  *	$Id: br_notify.c,v 1.2 2000/02/21 15:51:34 davem Exp $
9  *
10  *	This program is free software; you can redistribute it and/or
11  *	modify it under the terms of the GNU General Public License
12  *	as published by the Free Software Foundation; either version
13  *	2 of the License, or (at your option) any later version.
14  */
15 
16 #include <linux/kernel.h>
17 #include <linux/if_bridge.h>
18 #include "br_private.h"
19 
20 static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr);
21 
22 struct notifier_block br_device_notifier =
23 {
24 	br_device_event,
25 	NULL,
26 	0
27 };
28 
br_device_event(struct notifier_block * unused,unsigned long event,void * ptr)29 static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
30 {
31 	struct net_device *dev;
32 	struct net_bridge_port *p;
33 
34 	dev = ptr;
35 	p = dev->br_port;
36 
37 	if (p == NULL)
38 		return NOTIFY_DONE;
39 
40 	switch (event)
41 	{
42 	case NETDEV_CHANGEADDR:
43 		read_lock(&p->br->lock);
44 		br_fdb_changeaddr(p, dev->dev_addr);
45 		br_stp_recalculate_bridge_id(p->br);
46 		read_unlock(&p->br->lock);
47 		break;
48 
49 	case NETDEV_GOING_DOWN:
50 		/* extend the protocol to send some kind of notification? */
51 		break;
52 
53 	case NETDEV_DOWN:
54 		if (p->br->dev.flags & IFF_UP) {
55 			read_lock(&p->br->lock);
56 			br_stp_disable_port(dev->br_port);
57 			read_unlock(&p->br->lock);
58 		}
59 		break;
60 
61 	case NETDEV_UP:
62 		if (p->br->dev.flags & IFF_UP) {
63 			read_lock(&p->br->lock);
64 			br_stp_enable_port(dev->br_port);
65 			read_unlock(&p->br->lock);
66 		}
67 		break;
68 
69 	case NETDEV_UNREGISTER:
70 		br_del_if(dev->br_port->br, dev);
71 		break;
72 	}
73 
74 	return NOTIFY_DONE;
75 }
76