0001
0002
0003
0004
0005
0006 #include <linux/netdevice.h>
0007 #include <net/genetlink.h>
0008 #include <net/netns/generic.h>
0009
0010 #include "datapath.h"
0011 #include "vport-internal_dev.h"
0012 #include "vport-netdev.h"
0013
0014 static void dp_detach_port_notify(struct vport *vport)
0015 {
0016 struct sk_buff *notify;
0017 struct datapath *dp;
0018
0019 dp = vport->dp;
0020 notify = ovs_vport_cmd_build_info(vport, ovs_dp_get_net(dp),
0021 0, 0, OVS_VPORT_CMD_DEL);
0022 ovs_dp_detach_port(vport);
0023 if (IS_ERR(notify)) {
0024 genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
0025 0, PTR_ERR(notify));
0026 return;
0027 }
0028
0029 genlmsg_multicast_netns(&dp_vport_genl_family,
0030 ovs_dp_get_net(dp), notify, 0,
0031 0, GFP_KERNEL);
0032 }
0033
0034 void ovs_dp_notify_wq(struct work_struct *work)
0035 {
0036 struct ovs_net *ovs_net = container_of(work, struct ovs_net, dp_notify_work);
0037 struct datapath *dp;
0038
0039 ovs_lock();
0040 list_for_each_entry(dp, &ovs_net->dps, list_node) {
0041 int i;
0042
0043 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
0044 struct vport *vport;
0045 struct hlist_node *n;
0046
0047 hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node) {
0048 if (vport->ops->type == OVS_VPORT_TYPE_INTERNAL)
0049 continue;
0050
0051 if (!(netif_is_ovs_port(vport->dev)))
0052 dp_detach_port_notify(vport);
0053 }
0054 }
0055 }
0056 ovs_unlock();
0057 }
0058
0059 static int dp_device_event(struct notifier_block *unused, unsigned long event,
0060 void *ptr)
0061 {
0062 struct ovs_net *ovs_net;
0063 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
0064 struct vport *vport = NULL;
0065
0066 if (!ovs_is_internal_dev(dev))
0067 vport = ovs_netdev_get_vport(dev);
0068
0069 if (!vport)
0070 return NOTIFY_DONE;
0071
0072 if (event == NETDEV_UNREGISTER) {
0073
0074 ovs_netdev_detach_dev(vport);
0075
0076
0077 ovs_net = net_generic(dev_net(dev), ovs_net_id);
0078 queue_work(system_wq, &ovs_net->dp_notify_work);
0079 }
0080
0081 return NOTIFY_DONE;
0082 }
0083
0084 struct notifier_block ovs_dp_device_notifier = {
0085 .notifier_call = dp_device_event
0086 };