1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/netdevice.h>
20#include <net/genetlink.h>
21#include <net/netns/generic.h>
22
23#include "datapath.h"
24#include "vport-internal_dev.h"
25#include "vport-netdev.h"
26
27static 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 genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
38 0, PTR_ERR(notify));
39 return;
40 }
41
42 genlmsg_multicast_netns(&dp_vport_genl_family,
43 ovs_dp_get_net(dp), notify, 0,
44 0, GFP_KERNEL);
45}
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) {
61 if (vport->ops->type == OVS_VPORT_TYPE_INTERNAL)
62 continue;
63
64 if (!(vport->dev->priv_flags & IFF_OVS_DATAPATH))
65 dp_detach_port_notify(vport);
66 }
67 }
68 }
69 ovs_unlock();
70}
71
72static int dp_device_event(struct notifier_block *unused, unsigned long event,
73 void *ptr)
74{
75 struct ovs_net *ovs_net;
76 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
77 struct vport *vport = NULL;
78
79 if (!ovs_is_internal_dev(dev))
80 vport = ovs_netdev_get_vport(dev);
81
82 if (!vport)
83 return NOTIFY_DONE;
84
85 if (event == NETDEV_UNREGISTER) {
86
87 ovs_netdev_detach_dev(vport);
88
89
90 ovs_net = net_generic(dev_net(dev), ovs_net_id);
91 queue_work(system_wq, &ovs_net->dp_notify_work);
92 }
93
94 return NOTIFY_DONE;
95}
96
97struct notifier_block ovs_dp_device_notifier = {
98 .notifier_call = dp_device_event
99};
100