Skip to content

Commit 78a646c

Browse files
NikAleksandrovdavem330
authored andcommitted
bonding: simplify broadcast_xmit function
We don't need to start from the curr_active_slave as the frame will be sent to all eligible slaves anyway, so we remove the unnecessary local variables, checks and comments, and make it use the standard list API. This has the nice side-effect that later when it's converted to RCU a race condition will be avoided which could lead to double packet tx. Signed-off-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 71bc3b2 commit 78a646c

File tree

1 file changed

+16
-36
lines changed

1 file changed

+16
-36
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,52 +3910,32 @@ static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
39103910
return NETDEV_TX_OK;
39113911
}
39123912

3913-
/*
3914-
* in broadcast mode, we send everything to all usable interfaces.
3915-
*/
3913+
/* in broadcast mode, we send everything to all usable interfaces. */
39163914
static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev)
39173915
{
39183916
struct bonding *bond = netdev_priv(bond_dev);
3919-
struct slave *slave, *start_at;
3920-
struct net_device *tx_dev = NULL;
3921-
int i;
3922-
int res = 1;
3923-
3924-
start_at = bond->curr_active_slave;
3925-
if (!start_at)
3926-
goto out;
3917+
struct slave *slave = NULL;
39273918

3928-
bond_for_each_slave_from(bond, slave, i, start_at) {
3929-
if (IS_UP(slave->dev) &&
3930-
(slave->link == BOND_LINK_UP) &&
3931-
bond_is_active_slave(slave)) {
3932-
if (tx_dev) {
3933-
struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
3934-
if (!skb2) {
3935-
pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n",
3936-
bond_dev->name);
3937-
continue;
3938-
}
3919+
bond_for_each_slave(bond, slave) {
3920+
if (bond_is_last_slave(bond, slave))
3921+
break;
3922+
if (IS_UP(slave->dev) && slave->link == BOND_LINK_UP) {
3923+
struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
39393924

3940-
res = bond_dev_queue_xmit(bond, skb2, tx_dev);
3941-
if (res) {
3942-
kfree_skb(skb2);
3943-
continue;
3944-
}
3925+
if (!skb2) {
3926+
pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n",
3927+
bond_dev->name);
3928+
continue;
39453929
}
3946-
tx_dev = slave->dev;
3930+
/* bond_dev_queue_xmit always returns 0 */
3931+
bond_dev_queue_xmit(bond, skb2, slave->dev);
39473932
}
39483933
}
3949-
3950-
if (tx_dev)
3951-
res = bond_dev_queue_xmit(bond, skb, tx_dev);
3952-
3953-
out:
3954-
if (res)
3955-
/* no suitable interface, frame not sent */
3934+
if (slave && IS_UP(slave->dev) && slave->link == BOND_LINK_UP)
3935+
bond_dev_queue_xmit(bond, skb, slave->dev);
3936+
else
39563937
kfree_skb(skb);
39573938

3958-
/* frame sent to all suitable interfaces */
39593939
return NETDEV_TX_OK;
39603940
}
39613941

0 commit comments

Comments
 (0)