1
2
3
4
5
6
7
8
9
10
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/errno.h>
16#include <linux/netdevice.h>
17#include <linux/if_team.h>
18
19struct rr_priv {
20 unsigned int sent_packets;
21};
22
23static struct rr_priv *rr_priv(struct team *team)
24{
25 return (struct rr_priv *) &team->mode_priv;
26}
27
28static bool rr_transmit(struct team *team, struct sk_buff *skb)
29{
30 struct team_port *port;
31 int port_index;
32
33 port_index = team_num_to_port_index(team,
34 rr_priv(team)->sent_packets++);
35 port = team_get_port_by_index_rcu(team, port_index);
36 if (unlikely(!port))
37 goto drop;
38 port = team_get_first_port_txable_rcu(team, port);
39 if (unlikely(!port))
40 goto drop;
41 if (team_dev_queue_xmit(team, port, skb))
42 return false;
43 return true;
44
45drop:
46 dev_kfree_skb_any(skb);
47 return false;
48}
49
50static const struct team_mode_ops rr_mode_ops = {
51 .transmit = rr_transmit,
52 .port_enter = team_modeop_port_enter,
53 .port_change_dev_addr = team_modeop_port_change_dev_addr,
54};
55
56static const struct team_mode rr_mode = {
57 .kind = "roundrobin",
58 .owner = THIS_MODULE,
59 .priv_size = sizeof(struct rr_priv),
60 .ops = &rr_mode_ops,
61};
62
63static int __init rr_init_module(void)
64{
65 return team_mode_register(&rr_mode);
66}
67
68static void __exit rr_cleanup_module(void)
69{
70 team_mode_unregister(&rr_mode);
71}
72
73module_init(rr_init_module);
74module_exit(rr_cleanup_module);
75
76MODULE_LICENSE("GPL v2");
77MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
78MODULE_DESCRIPTION("Round-robin mode for team");
79MODULE_ALIAS("team-mode-roundrobin");
80