Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * drivers/net/team/team_mode_random.c - Random mode for team
 4 * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
 
 
 
 
 
 5 */
 6
 7#include <linux/kernel.h>
 8#include <linux/types.h>
 9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/skbuff.h>
12#include <linux/if_team.h>
13
14static bool rnd_transmit(struct team *team, struct sk_buff *skb)
15{
16	struct team_port *port;
17	int port_index;
18
19	port_index = get_random_u32_below(team->en_port_count);
20	port = team_get_port_by_index_rcu(team, port_index);
21	if (unlikely(!port))
22		goto drop;
23	port = team_get_first_port_txable_rcu(team, port);
24	if (unlikely(!port))
25		goto drop;
26	if (team_dev_queue_xmit(team, port, skb))
27		return false;
28	return true;
29
30drop:
31	dev_kfree_skb_any(skb);
32	return false;
33}
34
35static const struct team_mode_ops rnd_mode_ops = {
36	.transmit		= rnd_transmit,
37	.port_enter		= team_modeop_port_enter,
38	.port_change_dev_addr	= team_modeop_port_change_dev_addr,
39};
40
41static const struct team_mode rnd_mode = {
42	.kind		= "random",
43	.owner		= THIS_MODULE,
44	.ops		= &rnd_mode_ops,
45	.lag_tx_type	= NETDEV_LAG_TX_TYPE_RANDOM,
46};
47
48static int __init rnd_init_module(void)
49{
50	return team_mode_register(&rnd_mode);
51}
52
53static void __exit rnd_cleanup_module(void)
54{
55	team_mode_unregister(&rnd_mode);
56}
57
58module_init(rnd_init_module);
59module_exit(rnd_cleanup_module);
60
61MODULE_LICENSE("GPL v2");
62MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
63MODULE_DESCRIPTION("Random mode for team");
64MODULE_ALIAS_TEAM_MODE("random");
v4.6
 
 1/*
 2 * drivers/net/team/team_mode_random.c - Random mode for team
 3 * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
 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
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/skbuff.h>
16#include <linux/if_team.h>
17
18static bool rnd_transmit(struct team *team, struct sk_buff *skb)
19{
20	struct team_port *port;
21	int port_index;
22
23	port_index = prandom_u32_max(team->en_port_count);
24	port = team_get_port_by_index_rcu(team, port_index);
25	if (unlikely(!port))
26		goto drop;
27	port = team_get_first_port_txable_rcu(team, port);
28	if (unlikely(!port))
29		goto drop;
30	if (team_dev_queue_xmit(team, port, skb))
31		return false;
32	return true;
33
34drop:
35	dev_kfree_skb_any(skb);
36	return false;
37}
38
39static const struct team_mode_ops rnd_mode_ops = {
40	.transmit		= rnd_transmit,
41	.port_enter		= team_modeop_port_enter,
42	.port_change_dev_addr	= team_modeop_port_change_dev_addr,
43};
44
45static const struct team_mode rnd_mode = {
46	.kind		= "random",
47	.owner		= THIS_MODULE,
48	.ops		= &rnd_mode_ops,
49	.lag_tx_type	= NETDEV_LAG_TX_TYPE_RANDOM,
50};
51
52static int __init rnd_init_module(void)
53{
54	return team_mode_register(&rnd_mode);
55}
56
57static void __exit rnd_cleanup_module(void)
58{
59	team_mode_unregister(&rnd_mode);
60}
61
62module_init(rnd_init_module);
63module_exit(rnd_cleanup_module);
64
65MODULE_LICENSE("GPL v2");
66MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
67MODULE_DESCRIPTION("Random mode for team");
68MODULE_ALIAS("team-mode-random");