team_mode_broadcast.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * drivers/net/team/team_mode_broadcast.c - Broadcast mode for team
  4. * Copyright (c) 2012 Jiri Pirko <jpirko@redhat.com>
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <linux/module.h>
  9. #include <linux/init.h>
  10. #include <linux/errno.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/if_team.h>
  13. static bool bc_transmit(struct team *team, struct sk_buff *skb)
  14. {
  15. struct team_port *cur;
  16. struct team_port *last = NULL;
  17. struct sk_buff *skb2;
  18. bool ret;
  19. bool sum_ret = false;
  20. list_for_each_entry_rcu(cur, &team->port_list, list) {
  21. if (team_port_txable(cur)) {
  22. if (last) {
  23. skb2 = skb_clone(skb, GFP_ATOMIC);
  24. if (skb2) {
  25. ret = !team_dev_queue_xmit(team, last,
  26. skb2);
  27. if (!sum_ret)
  28. sum_ret = ret;
  29. }
  30. }
  31. last = cur;
  32. }
  33. }
  34. if (last) {
  35. ret = !team_dev_queue_xmit(team, last, skb);
  36. if (!sum_ret)
  37. sum_ret = ret;
  38. }
  39. return sum_ret;
  40. }
  41. static const struct team_mode_ops bc_mode_ops = {
  42. .transmit = bc_transmit,
  43. .port_enter = team_modeop_port_enter,
  44. .port_change_dev_addr = team_modeop_port_change_dev_addr,
  45. };
  46. static const struct team_mode bc_mode = {
  47. .kind = "broadcast",
  48. .owner = THIS_MODULE,
  49. .ops = &bc_mode_ops,
  50. .lag_tx_type = NETDEV_LAG_TX_TYPE_BROADCAST,
  51. };
  52. static int __init bc_init_module(void)
  53. {
  54. return team_mode_register(&bc_mode);
  55. }
  56. static void __exit bc_cleanup_module(void)
  57. {
  58. team_mode_unregister(&bc_mode);
  59. }
  60. module_init(bc_init_module);
  61. module_exit(bc_cleanup_module);
  62. MODULE_LICENSE("GPL v2");
  63. MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
  64. MODULE_DESCRIPTION("Broadcast mode for team");
  65. MODULE_ALIAS_TEAM_MODE("broadcast");