]> git.proxmox.com Git - ovs.git/blob - datapath/dp_notify.c
Fix ovs-dpctl-top by removing 3 wrong hunks in py3-compat.patch.
[ovs.git] / datapath / dp_notify.c
1 /*
2 * Copyright (c) 2007-2012 Nicira, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301, USA
17 */
18
19 #include <linux/netdevice.h>
20 #include <net/genetlink.h>
21 #include <net/net_namespace.h>
22 #include <net/netns/generic.h>
23
24 #include "datapath.h"
25 #include "vport-internal_dev.h"
26 #include "vport-netdev.h"
27
28 static void dp_detach_port_notify(struct vport *vport)
29 {
30 struct sk_buff *notify;
31 struct datapath *dp;
32
33 dp = vport->dp;
34 notify = ovs_vport_cmd_build_info(vport, ovs_dp_get_net(dp),
35 0, 0, OVS_VPORT_CMD_DEL);
36 ovs_dp_detach_port(vport);
37 if (IS_ERR(notify)) {
38 genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
39 GROUP_ID(&ovs_dp_vport_multicast_group),
40 PTR_ERR(notify));
41 return;
42 }
43
44 genlmsg_multicast_netns(&dp_vport_genl_family,
45 ovs_dp_get_net(dp), notify, 0,
46 GROUP_ID(&ovs_dp_vport_multicast_group),
47 GFP_KERNEL);
48 }
49
50 void ovs_dp_notify_wq(struct work_struct *work)
51 {
52 struct ovs_net *ovs_net = container_of(work, struct ovs_net, dp_notify_work);
53 struct datapath *dp;
54
55 ovs_lock();
56 list_for_each_entry(dp, &ovs_net->dps, list_node) {
57 int i;
58
59 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
60 struct vport *vport;
61 struct hlist_node *n;
62
63 hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node) {
64 if (vport->ops->type == OVS_VPORT_TYPE_INTERNAL)
65 continue;
66
67 if (!(vport->dev->priv_flags & IFF_OVS_DATAPATH))
68 dp_detach_port_notify(vport);
69 }
70 }
71 }
72 ovs_unlock();
73 }
74
75 static int dp_device_event(struct notifier_block *unused, unsigned long event,
76 void *ptr)
77 {
78 struct ovs_net *ovs_net;
79 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
80 struct vport *vport = NULL;
81
82 if (!ovs_is_internal_dev(dev))
83 vport = ovs_netdev_get_vport(dev);
84
85 if (!vport)
86 return NOTIFY_DONE;
87
88 if (event == NETDEV_UNREGISTER) {
89 /* upper_dev_unlink and decrement promisc immediately */
90 ovs_netdev_detach_dev(vport);
91
92 /* schedule vport destroy, dev_put and genl notification */
93 ovs_net = net_generic(dev_net(dev), ovs_net_id);
94 queue_work(system_wq, &ovs_net->dp_notify_work);
95 }
96
97 return NOTIFY_DONE;
98 }
99
100 struct notifier_block ovs_dp_device_notifier = {
101 .notifier_call = dp_device_event
102 };