Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 2 | /* |
| 3 | * drivers/net/team/team_mode_broadcast.c - Broadcast mode for team |
| 4 | * Copyright (c) 2012 Jiri Pirko <jpirko@redhat.com> |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 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/errno.h> |
| 12 | #include <linux/netdevice.h> |
| 13 | #include <linux/if_team.h> |
| 14 | |
| 15 | static bool bc_transmit(struct team *team, struct sk_buff *skb) |
| 16 | { |
| 17 | struct team_port *cur; |
| 18 | struct team_port *last = NULL; |
| 19 | struct sk_buff *skb2; |
| 20 | bool ret; |
| 21 | bool sum_ret = false; |
| 22 | |
| 23 | list_for_each_entry_rcu(cur, &team->port_list, list) { |
| 24 | if (team_port_txable(cur)) { |
| 25 | if (last) { |
| 26 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 27 | if (skb2) { |
Jiri Pirko | 403f43c | 2012-11-21 02:34:45 +0000 | [diff] [blame] | 28 | ret = !team_dev_queue_xmit(team, last, |
| 29 | skb2); |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 30 | if (!sum_ret) |
| 31 | sum_ret = ret; |
| 32 | } |
| 33 | } |
| 34 | last = cur; |
| 35 | } |
| 36 | } |
| 37 | if (last) { |
Jiri Pirko | 403f43c | 2012-11-21 02:34:45 +0000 | [diff] [blame] | 38 | ret = !team_dev_queue_xmit(team, last, skb); |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 39 | if (!sum_ret) |
| 40 | sum_ret = ret; |
| 41 | } |
| 42 | return sum_ret; |
| 43 | } |
| 44 | |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 45 | static const struct team_mode_ops bc_mode_ops = { |
| 46 | .transmit = bc_transmit, |
Jiri Pirko | acbba0d | 2013-03-06 01:31:12 +0000 | [diff] [blame] | 47 | .port_enter = team_modeop_port_enter, |
| 48 | .port_change_dev_addr = team_modeop_port_change_dev_addr, |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | static const struct team_mode bc_mode = { |
| 52 | .kind = "broadcast", |
| 53 | .owner = THIS_MODULE, |
| 54 | .ops = &bc_mode_ops, |
Jiri Pirko | 8fd7285 | 2015-12-03 12:12:13 +0100 | [diff] [blame] | 55 | .lag_tx_type = NETDEV_LAG_TX_TYPE_BROADCAST, |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | static int __init bc_init_module(void) |
| 59 | { |
| 60 | return team_mode_register(&bc_mode); |
| 61 | } |
| 62 | |
| 63 | static void __exit bc_cleanup_module(void) |
| 64 | { |
| 65 | team_mode_unregister(&bc_mode); |
| 66 | } |
| 67 | |
| 68 | module_init(bc_init_module); |
| 69 | module_exit(bc_cleanup_module); |
| 70 | |
| 71 | MODULE_LICENSE("GPL v2"); |
| 72 | MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>"); |
| 73 | MODULE_DESCRIPTION("Broadcast mode for team"); |
Zhang Shengju | 3a5f899 | 2017-06-01 15:37:02 +0800 | [diff] [blame] | 74 | MODULE_ALIAS_TEAM_MODE("broadcast"); |