blob: 653d073bae4533acf80d63fec54ed604249d83f0 [file] [log] [blame]
Jesse Grossccb13522011-10-25 19:26:31 -07001/*
Raju Subramaniancaf2ee12012-05-03 18:55:23 -07002 * Copyright (c) 2007-2012 Nicira, Inc.
Jesse Grossccb13522011-10-25 19:26:31 -07003 *
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>
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070021#include <net/netns/generic.h>
Jesse Grossccb13522011-10-25 19:26:31 -070022
23#include "datapath.h"
24#include "vport-internal_dev.h"
25#include "vport-netdev.h"
26
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070027static void dp_detach_port_notify(struct vport *vport)
28{
29 struct sk_buff *notify;
30 struct datapath *dp;
31
32 dp = vport->dp;
33 notify = ovs_vport_cmd_build_info(vport, 0, 0,
34 OVS_VPORT_CMD_DEL);
35 ovs_dp_detach_port(vport);
36 if (IS_ERR(notify)) {
Johannes Berg68eb5502013-11-19 15:19:38 +010037 genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010038 0, PTR_ERR(notify));
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070039 return;
40 }
41
Johannes Berg68eb5502013-11-19 15:19:38 +010042 genlmsg_multicast_netns(&dp_vport_genl_family,
43 ovs_dp_get_net(dp), notify, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010044 0, GFP_KERNEL);
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070045}
46
47void ovs_dp_notify_wq(struct work_struct *work)
48{
49 struct ovs_net *ovs_net = container_of(work, struct ovs_net, dp_notify_work);
50 struct datapath *dp;
51
52 ovs_lock();
53 list_for_each_entry(dp, &ovs_net->dps, list_node) {
54 int i;
55
56 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
57 struct vport *vport;
58 struct hlist_node *n;
59
60 hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node) {
Paolo Abeni13175302015-12-01 18:33:36 +010061 if (vport->ops->type == OVS_VPORT_TYPE_INTERNAL)
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070062 continue;
63
Thomas Grafbe4ace62015-07-21 10:44:04 +020064 if (!(vport->dev->priv_flags & IFF_OVS_DATAPATH))
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070065 dp_detach_port_notify(vport);
66 }
67 }
68 }
69 ovs_unlock();
70}
71
Jesse Grossccb13522011-10-25 19:26:31 -070072static int dp_device_event(struct notifier_block *unused, unsigned long event,
73 void *ptr)
74{
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070075 struct ovs_net *ovs_net;
Jiri Pirko351638e2013-05-28 01:30:21 +000076 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070077 struct vport *vport = NULL;
Jesse Grossccb13522011-10-25 19:26:31 -070078
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070079 if (!ovs_is_internal_dev(dev))
Jesse Grossccb13522011-10-25 19:26:31 -070080 vport = ovs_netdev_get_vport(dev);
81
82 if (!vport)
83 return NOTIFY_DONE;
84
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070085 if (event == NETDEV_UNREGISTER) {
Alexei Starovoitovb07c2652013-10-15 14:54:11 -070086 /* upper_dev_unlink and decrement promisc immediately */
87 ovs_netdev_detach_dev(vport);
88
89 /* schedule vport destroy, dev_put and genl notification */
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070090 ovs_net = net_generic(dev_net(dev), ovs_net_id);
91 queue_work(system_wq, &ovs_net->dp_notify_work);
Jesse Grossccb13522011-10-25 19:26:31 -070092 }
93
94 return NOTIFY_DONE;
95}
96
97struct notifier_block ovs_dp_device_notifier = {
98 .notifier_call = dp_device_event
99};