]> git.proxmox.com Git - ovs.git/blame - datapath/dp_notify.c
datapath: backport: ovs: use nla_put_u64_64bit()
[ovs.git] / datapath / dp_notify.c
CommitLineData
064af421 1/*
e0edde6f 2 * Copyright (c) 2007-2012 Nicira, Inc.
a14bc59f 3 *
a9a29d22
JG
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
064af421
BP
17 */
18
064af421 19#include <linux/netdevice.h>
f14d8083 20#include <net/genetlink.h>
11aa8dff
PS
21#include <net/net_namespace.h>
22#include <net/netns/generic.h>
064af421
BP
23
24#include "datapath.h"
f2459fe7
JG
25#include "vport-internal_dev.h"
26#include "vport-netdev.h"
064af421 27
cd2a59e9
PS
28static void dp_detach_port_notify(struct vport *vport)
29{
30 struct sk_buff *notify;
31 struct datapath *dp;
32
33 dp = vport->dp;
cb25142c 34 notify = ovs_vport_cmd_build_info(vport, 0, 0, OVS_VPORT_CMD_DEL);
cd2a59e9
PS
35 ovs_dp_detach_port(vport);
36 if (IS_ERR(notify)) {
cb25142c
PS
37 genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
38 GROUP_ID(&ovs_dp_vport_multicast_group),
39 PTR_ERR(notify));
cd2a59e9
PS
40 return;
41 }
42
cb25142c
PS
43 genlmsg_multicast_netns(&dp_vport_genl_family,
44 ovs_dp_get_net(dp), notify, 0,
45 GROUP_ID(&ovs_dp_vport_multicast_group),
cd2a59e9
PS
46 GFP_KERNEL);
47}
48
49void ovs_dp_notify_wq(struct work_struct *work)
50{
51 struct ovs_net *ovs_net = container_of(work, struct ovs_net, dp_notify_work);
52 struct datapath *dp;
53
54 ovs_lock();
55 list_for_each_entry(dp, &ovs_net->dps, list_node) {
56 int i;
57
58 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
59 struct vport *vport;
60 struct hlist_node *n;
61
62 hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node) {
1e41fa16 63 if (vport->ops->type == OVS_VPORT_TYPE_INTERNAL)
cd2a59e9
PS
64 continue;
65
e23775f2 66 if (!(vport->dev->priv_flags & IFF_OVS_DATAPATH))
cd2a59e9
PS
67 dp_detach_port_notify(vport);
68 }
69 }
70 }
71 ovs_unlock();
72}
73
d295e8e9 74static int dp_device_event(struct notifier_block *unused, unsigned long event,
5fe0ec3d 75 void *ptr)
064af421 76{
cd2a59e9 77 struct ovs_net *ovs_net;
54af97ad 78 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
cd2a59e9 79 struct vport *vport = NULL;
0515ceb3 80
cd2a59e9 81 if (!ovs_is_internal_dev(dev))
850b6b3b 82 vport = ovs_netdev_get_vport(dev);
f2459fe7 83
63db6ec3
JG
84 if (!vport)
85 return NOTIFY_DONE;
f2459fe7 86
cd2a59e9 87 if (event == NETDEV_UNREGISTER) {
8e04c6e1
AS
88 /* upper_dev_unlink and decrement promisc immediately */
89 ovs_netdev_detach_dev(vport);
90
91 /* schedule vport destroy, dev_put and genl notification */
cd2a59e9 92 ovs_net = net_generic(dev_net(dev), ovs_net_id);
533e96e7 93 queue_work(system_wq, &ovs_net->dp_notify_work);
064af421 94 }
5fe0ec3d 95
064af421
BP
96 return NOTIFY_DONE;
97}
98
850b6b3b 99struct notifier_block ovs_dp_device_notifier = {
064af421
BP
100 .notifier_call = dp_device_event
101};