Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/team/team_mode_broadcast.c - Broadcast mode for team |
| 3 | * Copyright (c) 2012 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 | |
| 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 | |
| 19 | static bool bc_transmit(struct team *team, struct sk_buff *skb) |
| 20 | { |
| 21 | struct team_port *cur; |
| 22 | struct team_port *last = NULL; |
| 23 | struct sk_buff *skb2; |
| 24 | bool ret; |
| 25 | bool sum_ret = false; |
| 26 | |
| 27 | list_for_each_entry_rcu(cur, &team->port_list, list) { |
| 28 | if (team_port_txable(cur)) { |
| 29 | if (last) { |
| 30 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 31 | if (skb2) { |
Jiri Pirko | bd2d083 | 2012-07-17 05:22:36 +0000 | [diff] [blame] | 32 | ret = team_dev_queue_xmit(team, last, |
| 33 | skb2); |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 34 | if (!sum_ret) |
| 35 | sum_ret = ret; |
| 36 | } |
| 37 | } |
| 38 | last = cur; |
| 39 | } |
| 40 | } |
| 41 | if (last) { |
Jiri Pirko | bd2d083 | 2012-07-17 05:22:36 +0000 | [diff] [blame] | 42 | ret = team_dev_queue_xmit(team, last, skb); |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 43 | if (!sum_ret) |
| 44 | sum_ret = ret; |
| 45 | } |
| 46 | return sum_ret; |
| 47 | } |
| 48 | |
| 49 | static int bc_port_enter(struct team *team, struct team_port *port) |
| 50 | { |
Jiri Pirko | 1d76efe | 2012-08-17 04:00:48 +0000 | [diff] [blame^] | 51 | return team_port_set_team_dev_addr(port); |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Jiri Pirko | 1d76efe | 2012-08-17 04:00:48 +0000 | [diff] [blame^] | 54 | static void bc_port_change_dev_addr(struct team *team, struct team_port *port) |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 55 | { |
Jiri Pirko | 1d76efe | 2012-08-17 04:00:48 +0000 | [diff] [blame^] | 56 | team_port_set_team_dev_addr(port); |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static const struct team_mode_ops bc_mode_ops = { |
| 60 | .transmit = bc_transmit, |
| 61 | .port_enter = bc_port_enter, |
Jiri Pirko | 1d76efe | 2012-08-17 04:00:48 +0000 | [diff] [blame^] | 62 | .port_change_dev_addr = bc_port_change_dev_addr, |
Jiri Pirko | 5fc8899 | 2012-07-11 05:34:03 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | static const struct team_mode bc_mode = { |
| 66 | .kind = "broadcast", |
| 67 | .owner = THIS_MODULE, |
| 68 | .ops = &bc_mode_ops, |
| 69 | }; |
| 70 | |
| 71 | static int __init bc_init_module(void) |
| 72 | { |
| 73 | return team_mode_register(&bc_mode); |
| 74 | } |
| 75 | |
| 76 | static void __exit bc_cleanup_module(void) |
| 77 | { |
| 78 | team_mode_unregister(&bc_mode); |
| 79 | } |
| 80 | |
| 81 | module_init(bc_init_module); |
| 82 | module_exit(bc_cleanup_module); |
| 83 | |
| 84 | MODULE_LICENSE("GPL v2"); |
| 85 | MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>"); |
| 86 | MODULE_DESCRIPTION("Broadcast mode for team"); |
| 87 | MODULE_ALIAS("team-mode-broadcast"); |