blob: ef4feec6cd845e67903706f448ccc5d1a8f96556 [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)) {
37 netlink_set_err(ovs_dp_get_net(dp)->genl_sock, 0,
38 ovs_dp_vport_multicast_group.id,
39 PTR_ERR(notify));
40 return;
41 }
42
43 genlmsg_multicast_netns(ovs_dp_get_net(dp), notify, 0,
44 ovs_dp_vport_multicast_group.id,
45 GFP_KERNEL);
46}
47
48void ovs_dp_notify_wq(struct work_struct *work)
49{
50 struct ovs_net *ovs_net = container_of(work, struct ovs_net, dp_notify_work);
51 struct datapath *dp;
52
53 ovs_lock();
54 list_for_each_entry(dp, &ovs_net->dps, list_node) {
55 int i;
56
57 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
58 struct vport *vport;
59 struct hlist_node *n;
60
61 hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node) {
62 struct netdev_vport *netdev_vport;
63
64 if (vport->ops->type != OVS_VPORT_TYPE_NETDEV)
65 continue;
66
67 netdev_vport = netdev_vport_priv(vport);
68 if (netdev_vport->dev->reg_state == NETREG_UNREGISTERED ||
69 netdev_vport->dev->reg_state == NETREG_UNREGISTERING)
70 dp_detach_port_notify(vport);
71 }
72 }
73 }
74 ovs_unlock();
75}
76
Jesse Grossccb13522011-10-25 19:26:31 -070077static int dp_device_event(struct notifier_block *unused, unsigned long event,
78 void *ptr)
79{
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070080 struct ovs_net *ovs_net;
Jesse Grossccb13522011-10-25 19:26:31 -070081 struct net_device *dev = ptr;
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070082 struct vport *vport = NULL;
Jesse Grossccb13522011-10-25 19:26:31 -070083
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070084 if (!ovs_is_internal_dev(dev))
Jesse Grossccb13522011-10-25 19:26:31 -070085 vport = ovs_netdev_get_vport(dev);
86
87 if (!vport)
88 return NOTIFY_DONE;
89
Pravin B Shelar8e4e1712013-04-15 13:23:03 -070090 if (event == NETDEV_UNREGISTER) {
91 ovs_net = net_generic(dev_net(dev), ovs_net_id);
92 queue_work(system_wq, &ovs_net->dp_notify_work);
Jesse Grossccb13522011-10-25 19:26:31 -070093 }
94
95 return NOTIFY_DONE;
96}
97
98struct notifier_block ovs_dp_device_notifier = {
99 .notifier_call = dp_device_event
100};