Thomas Gleixner | c942299 | 2019-05-29 07:12:43 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jesse Gross | ccb1352 | 2011-10-25 19:26:31 -0700 | [diff] [blame] | 2 | /* |
Raju Subramanian | caf2ee1 | 2012-05-03 18:55:23 -0700 | [diff] [blame] | 3 | * Copyright (c) 2007-2012 Nicira, Inc. |
Jesse Gross | ccb1352 | 2011-10-25 19:26:31 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/netdevice.h> |
| 7 | #include <net/genetlink.h> |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 8 | #include <net/netns/generic.h> |
Jesse Gross | ccb1352 | 2011-10-25 19:26:31 -0700 | [diff] [blame] | 9 | |
| 10 | #include "datapath.h" |
| 11 | #include "vport-internal_dev.h" |
| 12 | #include "vport-netdev.h" |
| 13 | |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 14 | static void dp_detach_port_notify(struct vport *vport) |
| 15 | { |
| 16 | struct sk_buff *notify; |
| 17 | struct datapath *dp; |
| 18 | |
| 19 | dp = vport->dp; |
Jiri Benc | 9354d45 | 2017-11-02 17:04:37 -0200 | [diff] [blame] | 20 | notify = ovs_vport_cmd_build_info(vport, ovs_dp_get_net(dp), |
| 21 | 0, 0, OVS_VPORT_CMD_DEL); |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 22 | ovs_dp_detach_port(vport); |
| 23 | if (IS_ERR(notify)) { |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 24 | genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 25 | 0, PTR_ERR(notify)); |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 26 | return; |
| 27 | } |
| 28 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 29 | genlmsg_multicast_netns(&dp_vport_genl_family, |
| 30 | ovs_dp_get_net(dp), notify, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 31 | 0, GFP_KERNEL); |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void ovs_dp_notify_wq(struct work_struct *work) |
| 35 | { |
| 36 | struct ovs_net *ovs_net = container_of(work, struct ovs_net, dp_notify_work); |
| 37 | struct datapath *dp; |
| 38 | |
| 39 | ovs_lock(); |
| 40 | list_for_each_entry(dp, &ovs_net->dps, list_node) { |
| 41 | int i; |
| 42 | |
| 43 | for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) { |
| 44 | struct vport *vport; |
| 45 | struct hlist_node *n; |
| 46 | |
| 47 | hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node) { |
Paolo Abeni | 1317530 | 2015-12-01 18:33:36 +0100 | [diff] [blame] | 48 | if (vport->ops->type == OVS_VPORT_TYPE_INTERNAL) |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 49 | continue; |
| 50 | |
Taehee Yoo | 44e3725 | 2019-07-06 01:05:46 +0900 | [diff] [blame^] | 51 | if (!(netif_is_ovs_port(vport->dev))) |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 52 | dp_detach_port_notify(vport); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | ovs_unlock(); |
| 57 | } |
| 58 | |
Jesse Gross | ccb1352 | 2011-10-25 19:26:31 -0700 | [diff] [blame] | 59 | static int dp_device_event(struct notifier_block *unused, unsigned long event, |
| 60 | void *ptr) |
| 61 | { |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 62 | struct ovs_net *ovs_net; |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 63 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 64 | struct vport *vport = NULL; |
Jesse Gross | ccb1352 | 2011-10-25 19:26:31 -0700 | [diff] [blame] | 65 | |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 66 | if (!ovs_is_internal_dev(dev)) |
Jesse Gross | ccb1352 | 2011-10-25 19:26:31 -0700 | [diff] [blame] | 67 | vport = ovs_netdev_get_vport(dev); |
| 68 | |
| 69 | if (!vport) |
| 70 | return NOTIFY_DONE; |
| 71 | |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 72 | if (event == NETDEV_UNREGISTER) { |
Alexei Starovoitov | b07c265 | 2013-10-15 14:54:11 -0700 | [diff] [blame] | 73 | /* upper_dev_unlink and decrement promisc immediately */ |
| 74 | ovs_netdev_detach_dev(vport); |
| 75 | |
| 76 | /* schedule vport destroy, dev_put and genl notification */ |
Pravin B Shelar | 8e4e171 | 2013-04-15 13:23:03 -0700 | [diff] [blame] | 77 | ovs_net = net_generic(dev_net(dev), ovs_net_id); |
| 78 | queue_work(system_wq, &ovs_net->dp_notify_work); |
Jesse Gross | ccb1352 | 2011-10-25 19:26:31 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | return NOTIFY_DONE; |
| 82 | } |
| 83 | |
| 84 | struct notifier_block ovs_dp_device_notifier = { |
| 85 | .notifier_call = dp_device_event |
| 86 | }; |