dp_notify.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "datapath.h"
  21. #include "vport-internal_dev.h"
  22. #include "vport-netdev.h"
  23. static int dp_device_event(struct notifier_block *unused, unsigned long event,
  24. void *ptr)
  25. {
  26. struct net_device *dev = ptr;
  27. struct vport *vport;
  28. if (ovs_is_internal_dev(dev))
  29. vport = ovs_internal_dev_get_vport(dev);
  30. else
  31. vport = ovs_netdev_get_vport(dev);
  32. if (!vport)
  33. return NOTIFY_DONE;
  34. switch (event) {
  35. case NETDEV_UNREGISTER:
  36. if (!ovs_is_internal_dev(dev)) {
  37. struct sk_buff *notify;
  38. struct datapath *dp = vport->dp;
  39. notify = ovs_vport_cmd_build_info(vport, 0, 0,
  40. OVS_VPORT_CMD_DEL);
  41. ovs_dp_detach_port(vport);
  42. if (IS_ERR(notify)) {
  43. netlink_set_err(ovs_dp_get_net(dp)->genl_sock, 0,
  44. ovs_dp_vport_multicast_group.id,
  45. PTR_ERR(notify));
  46. break;
  47. }
  48. genlmsg_multicast_netns(ovs_dp_get_net(dp), notify, 0,
  49. ovs_dp_vport_multicast_group.id,
  50. GFP_KERNEL);
  51. }
  52. break;
  53. }
  54. return NOTIFY_DONE;
  55. }
  56. struct notifier_block ovs_dp_device_notifier = {
  57. .notifier_call = dp_device_event
  58. };