datapath: Merge "struct dp_port" into "struct vport".
[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, 2010 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 "vport-internal_dev.h"
15 #include "vport-netdev.h"
16
17 static int dp_device_event(struct notifier_block *unused, unsigned long event,
18                 void *ptr)
19 {
20         struct net_device *dev = ptr;
21         struct vport *vport;
22         struct datapath *dp;
23
24         if (is_internal_dev(dev))
25                 vport = internal_dev_get_vport(dev);
26         else
27                 vport = netdev_get_vport(dev);
28
29         if (!vport)
30                 return NOTIFY_DONE;
31
32         dp = vport->dp;
33
34         switch (event) {
35         case NETDEV_UNREGISTER:
36                 mutex_lock(&dp->mutex);
37                 dp_detach_port(vport);
38                 mutex_unlock(&dp->mutex);
39                 break;
40
41         case NETDEV_CHANGENAME:
42                 if (vport->port_no != ODPP_LOCAL) {
43                         mutex_lock(&dp->mutex);
44                         dp_sysfs_del_if(vport);
45                         dp_sysfs_add_if(vport);
46                         mutex_unlock(&dp->mutex);
47                 }
48                 break;
49
50         case NETDEV_CHANGEMTU:
51                 if (!is_internal_dev(dev))
52                         set_internal_devs_mtu(dp);
53                 break;
54         }
55         return NOTIFY_DONE;
56 }
57
58 struct notifier_block dp_device_notifier = {
59         .notifier_call = dp_device_event
60 };