team_mode_broadcast.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * drivers/net/team/team_mode_broadcast.c - Broadcast mode for team
  3. * Copyright (c) 2012 Jiri Pirko <jpirko@redhat.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/errno.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/if_team.h>
  17. static bool bc_transmit(struct team *team, struct sk_buff *skb)
  18. {
  19. struct team_port *cur;
  20. struct team_port *last = NULL;
  21. struct sk_buff *skb2;
  22. bool ret;
  23. bool sum_ret = false;
  24. list_for_each_entry_rcu(cur, &team->port_list, list) {
  25. if (team_port_txable(cur)) {
  26. if (last) {
  27. skb2 = skb_clone(skb, GFP_ATOMIC);
  28. if (skb2) {
  29. ret = !team_dev_queue_xmit(team, last,
  30. skb2);
  31. if (!sum_ret)
  32. sum_ret = ret;
  33. }
  34. }
  35. last = cur;
  36. }
  37. }
  38. if (last) {
  39. ret = !team_dev_queue_xmit(team, last, skb);
  40. if (!sum_ret)
  41. sum_ret = ret;
  42. }
  43. return sum_ret;
  44. }
  45. static int bc_port_enter(struct team *team, struct team_port *port)
  46. {
  47. return team_port_set_team_dev_addr(port);
  48. }
  49. static void bc_port_change_dev_addr(struct team *team, struct team_port *port)
  50. {
  51. team_port_set_team_dev_addr(port);
  52. }
  53. static const struct team_mode_ops bc_mode_ops = {
  54. .transmit = bc_transmit,
  55. .port_enter = bc_port_enter,
  56. .port_change_dev_addr = bc_port_change_dev_addr,
  57. };
  58. static const struct team_mode bc_mode = {
  59. .kind = "broadcast",
  60. .owner = THIS_MODULE,
  61. .ops = &bc_mode_ops,
  62. };
  63. static int __init bc_init_module(void)
  64. {
  65. return team_mode_register(&bc_mode);
  66. }
  67. static void __exit bc_cleanup_module(void)
  68. {
  69. team_mode_unregister(&bc_mode);
  70. }
  71. module_init(bc_init_module);
  72. module_exit(bc_cleanup_module);
  73. MODULE_LICENSE("GPL v2");
  74. MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
  75. MODULE_DESCRIPTION("Broadcast mode for team");
  76. MODULE_ALIAS("team-mode-broadcast");