dp_notify.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2007-2012 Nicira, Inc.
  4. */
  5. #include <linux/netdevice.h>
  6. #include <net/genetlink.h>
  7. #include <net/netns/generic.h>
  8. #include "datapath.h"
  9. #include "vport-internal_dev.h"
  10. #include "vport-netdev.h"
  11. static void dp_detach_port_notify(struct vport *vport)
  12. {
  13. struct sk_buff *notify;
  14. struct datapath *dp;
  15. dp = vport->dp;
  16. notify = ovs_vport_cmd_build_info(vport, ovs_dp_get_net(dp),
  17. 0, 0, OVS_VPORT_CMD_DEL);
  18. ovs_dp_detach_port(vport);
  19. if (IS_ERR(notify)) {
  20. genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
  21. 0, PTR_ERR(notify));
  22. return;
  23. }
  24. genlmsg_multicast_netns(&dp_vport_genl_family,
  25. ovs_dp_get_net(dp), notify, 0,
  26. 0, GFP_KERNEL);
  27. }
  28. void ovs_dp_notify_wq(struct work_struct *work)
  29. {
  30. struct ovs_net *ovs_net = container_of(work, struct ovs_net, dp_notify_work);
  31. struct datapath *dp;
  32. ovs_lock();
  33. list_for_each_entry(dp, &ovs_net->dps, list_node) {
  34. int i;
  35. for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
  36. struct vport *vport;
  37. struct hlist_node *n;
  38. hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node) {
  39. if (vport->ops->type == OVS_VPORT_TYPE_INTERNAL)
  40. continue;
  41. if (!(netif_is_ovs_port(vport->dev)))
  42. dp_detach_port_notify(vport);
  43. }
  44. }
  45. }
  46. ovs_unlock();
  47. }
  48. static int dp_device_event(struct notifier_block *unused, unsigned long event,
  49. void *ptr)
  50. {
  51. struct ovs_net *ovs_net;
  52. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  53. struct vport *vport = NULL;
  54. if (!ovs_is_internal_dev(dev))
  55. vport = ovs_netdev_get_vport(dev);
  56. if (!vport)
  57. return NOTIFY_DONE;
  58. if (event == NETDEV_UNREGISTER) {
  59. /* upper_dev_unlink and decrement promisc immediately */
  60. ovs_netdev_detach_dev(vport);
  61. /* schedule vport destroy, dev_put and genl notification */
  62. ovs_net = net_generic(dev_net(dev), ovs_net_id);
  63. queue_work(system_wq, &ovs_net->dp_notify_work);
  64. }
  65. return NOTIFY_DONE;
  66. }
  67. struct notifier_block ovs_dp_device_notifier = {
  68. .notifier_call = dp_device_event
  69. };