dp_notify.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2007-2012 Nicira, Inc.
  3. *
  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
  17. */
  18. #include <linux/netdevice.h>
  19. #include <net/genetlink.h>
  20. #include <net/netns/generic.h>
  21. #include "datapath.h"
  22. #include "vport-internal_dev.h"
  23. #include "vport-netdev.h"
  24. static void dp_detach_port_notify(struct vport *vport)
  25. {
  26. struct sk_buff *notify;
  27. struct datapath *dp;
  28. dp = vport->dp;
  29. notify = ovs_vport_cmd_build_info(vport, 0, 0,
  30. OVS_VPORT_CMD_DEL);
  31. ovs_dp_detach_port(vport);
  32. if (IS_ERR(notify)) {
  33. genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
  34. 0, PTR_ERR(notify));
  35. return;
  36. }
  37. genlmsg_multicast_netns(&dp_vport_genl_family,
  38. ovs_dp_get_net(dp), notify, 0,
  39. 0, GFP_KERNEL);
  40. }
  41. void ovs_dp_notify_wq(struct work_struct *work)
  42. {
  43. struct ovs_net *ovs_net = container_of(work, struct ovs_net, dp_notify_work);
  44. struct datapath *dp;
  45. ovs_lock();
  46. list_for_each_entry(dp, &ovs_net->dps, list_node) {
  47. int i;
  48. for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
  49. struct vport *vport;
  50. struct hlist_node *n;
  51. hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node) {
  52. struct netdev_vport *netdev_vport;
  53. if (vport->ops->type != OVS_VPORT_TYPE_NETDEV)
  54. continue;
  55. netdev_vport = netdev_vport_priv(vport);
  56. if (!(netdev_vport->dev->priv_flags & IFF_OVS_DATAPATH))
  57. dp_detach_port_notify(vport);
  58. }
  59. }
  60. }
  61. ovs_unlock();
  62. }
  63. static int dp_device_event(struct notifier_block *unused, unsigned long event,
  64. void *ptr)
  65. {
  66. struct ovs_net *ovs_net;
  67. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  68. struct vport *vport = NULL;
  69. if (!ovs_is_internal_dev(dev))
  70. vport = ovs_netdev_get_vport(dev);
  71. if (!vport)
  72. return NOTIFY_DONE;
  73. if (event == NETDEV_UNREGISTER) {
  74. /* upper_dev_unlink and decrement promisc immediately */
  75. ovs_netdev_detach_dev(vport);
  76. /* schedule vport destroy, dev_put and genl notification */
  77. ovs_net = net_generic(dev_net(dev), ovs_net_id);
  78. queue_work(system_wq, &ovs_net->dp_notify_work);
  79. }
  80. return NOTIFY_DONE;
  81. }
  82. struct notifier_block ovs_dp_device_notifier = {
  83. .notifier_call = dp_device_event
  84. };