Merge "master" into "next".
[sliver-openvswitch.git] / datapath / dp_notify.c
1 /*
2  * Distributed under the terms of the GNU GPL version 2.
3  * Copyright (c) 2007, 2008, 2009 Nicira Networks.
4  *
5  * Significant portions of this file may be copied from parts of the Linux
6  * kernel, by Linus Torvalds and others.
7  */
8
9 /* Handle changes to managed devices */
10
11 #include <linux/netdevice.h>
12
13 #include "datapath.h"
14 #include "dp_dev.h"
15
16 static int dp_device_event(struct notifier_block *unused, unsigned long event, 
17                 void *ptr) 
18 {
19         struct net_device *dev = ptr;
20         struct net_bridge_port *p;
21         struct datapath *dp;
22
23         if (is_dp_dev(dev)) {
24                 struct dp_dev *dp_dev = dp_dev_priv(dev);
25                 p = dp_dev->dp->ports[dp_dev->port_no];
26         } else {
27                 p = dev->br_port;
28         }
29         if (!p)
30                 return NOTIFY_DONE;
31         dp = p->dp;
32
33         switch (event) {
34         case NETDEV_UNREGISTER:
35                 mutex_lock(&dp->mutex);
36                 dp_del_port(p);
37                 mutex_unlock(&dp->mutex);
38                 break;
39
40         case NETDEV_CHANGENAME:
41                 if (p->port_no != ODPP_LOCAL) {
42                         mutex_lock(&dp->mutex);
43                         dp_sysfs_del_if(p);
44                         dp_sysfs_add_if(p);
45                         mutex_unlock(&dp->mutex);
46                 }
47                 break;
48
49         case NETDEV_CHANGEMTU:
50                 if (!is_dp_dev(dev)) {
51                         mutex_lock(&dp->mutex);
52                         set_dp_devs_mtu(dp, dev);
53                         mutex_unlock(&dp->mutex);
54                 }
55                 break;
56         }
57         return NOTIFY_DONE;
58 }
59
60 struct notifier_block dp_device_notifier = {
61         .notifier_call = dp_device_event
62 };