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 7 #include <linux/kernel.h> 8 #include <linux/types.h> 9 #include <linux/module.h> 10 #include <linux/init.h> 11 #include <linux/netdevice.h> 12 #include <linux/if_team.h> 13 14 static bool bc_transmit(struct team *team, struct sk_buff *skb) 15 { 16 struct team_port *cur; 17 struct team_port *last = NULL; 18 struct sk_buff *skb2; 19 bool ret; 20 bool sum_ret = false; 21 22 list_for_each_entry_rcu(cur, &team->port_list, list) { 23 if (team_port_txable(cur)) { 24 if (last) { 25 skb2 = skb_clone(skb, GFP_ATOMIC); 26 if (skb2) { 27 ret = !team_dev_queue_xmit(team, last, 28 skb2); 29 if (!sum_ret) 30 sum_ret = ret; 31 } 32 } 33 last = cur; 34 } 35 } 36 if (last) { 37 ret = !team_dev_queue_xmit(team, last, skb); 38 if (!sum_ret) 39 sum_ret = ret; 40 } else { 41 dev_kfree_skb_any(skb); 42 } 43 return sum_ret; 44 } 45 46 static const struct team_mode_ops bc_mode_ops = { 47 .transmit = bc_transmit, 48 .port_enter = team_modeop_port_enter, 49 .port_change_dev_addr = team_modeop_port_change_dev_addr, 50 }; 51 52 static const struct team_mode bc_mode = { 53 .kind = "broadcast", 54 .owner = THIS_MODULE, 55 .ops = &bc_mode_ops, 56 .lag_tx_type = NETDEV_LAG_TX_TYPE_BROADCAST, 57 }; 58 59 static int __init bc_init_module(void) 60 { 61 return team_mode_register(&bc_mode); 62 } 63 64 static void __exit bc_cleanup_module(void) 65 { 66 team_mode_unregister(&bc_mode); 67 } 68 69 module_init(bc_init_module); 70 module_exit(bc_cleanup_module); 71 72 MODULE_LICENSE("GPL v2"); 73 MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>"); 74 MODULE_DESCRIPTION("Broadcast mode for team"); 75 MODULE_ALIAS_TEAM_MODE("broadcast"); 76