team_mode_roundrobin.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * drivers/net/team/team_mode_roundrobin.c - Round-robin mode for team
  3. * Copyright (c) 2011 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. struct rr_priv {
  18. unsigned int sent_packets;
  19. };
  20. static struct rr_priv *rr_priv(struct team *team)
  21. {
  22. return (struct rr_priv *) &team->mode_priv;
  23. }
  24. static bool rr_transmit(struct team *team, struct sk_buff *skb)
  25. {
  26. struct team_port *port;
  27. int port_index;
  28. port_index = team_num_to_port_index(team,
  29. rr_priv(team)->sent_packets++);
  30. port = team_get_port_by_index_rcu(team, port_index);
  31. if (unlikely(!port))
  32. goto drop;
  33. port = team_get_first_port_txable_rcu(team, port);
  34. if (unlikely(!port))
  35. goto drop;
  36. if (team_dev_queue_xmit(team, port, skb))
  37. return false;
  38. return true;
  39. drop:
  40. dev_kfree_skb_any(skb);
  41. return false;
  42. }
  43. static const struct team_mode_ops rr_mode_ops = {
  44. .transmit = rr_transmit,
  45. .port_enter = team_modeop_port_enter,
  46. .port_change_dev_addr = team_modeop_port_change_dev_addr,
  47. };
  48. static const struct team_mode rr_mode = {
  49. .kind = "roundrobin",
  50. .owner = THIS_MODULE,
  51. .priv_size = sizeof(struct rr_priv),
  52. .ops = &rr_mode_ops,
  53. .lag_tx_type = NETDEV_LAG_TX_TYPE_ROUNDROBIN,
  54. };
  55. static int __init rr_init_module(void)
  56. {
  57. return team_mode_register(&rr_mode);
  58. }
  59. static void __exit rr_cleanup_module(void)
  60. {
  61. team_mode_unregister(&rr_mode);
  62. }
  63. module_init(rr_init_module);
  64. module_exit(rr_cleanup_module);
  65. MODULE_LICENSE("GPL v2");
  66. MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
  67. MODULE_DESCRIPTION("Round-robin mode for team");
  68. MODULE_ALIAS_TEAM_MODE("roundrobin");