Skip to content

Commit ae46f18

Browse files
edumazetdavem330
authored andcommitted
bonding: propagate transmit status
Currently, bonding always returns NETDEV_TX_OK to its caller. It is worth trying to be more accurate : TCP for instance can have different recovery strategies if it can have more precise status, if packet was dropped by slave qdisc. This is especially important when host is under stress. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Jay Vosburgh <j.vosburgh@gmail.com> Cc: Veaceslav Falico <vfalico@gmail.com> Cc: Andy Gospodarek <andy@greyhouse.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f78ed22 commit ae46f18

3 files changed

Lines changed: 32 additions & 48 deletions

File tree

‎drivers/net/bonding/bond_alb.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,8 +1318,7 @@ static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond,
13181318
tx_slave->dev->dev_addr);
13191319
}
13201320

1321-
bond_dev_queue_xmit(bond, skb, tx_slave->dev);
1322-
goto out;
1321+
return bond_dev_queue_xmit(bond, skb, tx_slave->dev);
13231322
}
13241323

13251324
if (tx_slave && bond->params.tlb_dynamic_lb) {
@@ -1329,9 +1328,7 @@ static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond,
13291328
}
13301329

13311330
/* no suitable interface, frame not sent */
1332-
bond_tx_drop(bond->dev, skb);
1333-
out:
1334-
return NETDEV_TX_OK;
1331+
return bond_tx_drop(bond->dev, skb);
13351332
}
13361333

13371334
netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev)

‎drivers/net/bonding/bond_main.c‎

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ const char *bond_mode_name(int mode)
287287
* @skb: hw accel VLAN tagged skb to transmit
288288
* @slave_dev: slave that is supposed to xmit this skbuff
289289
*/
290-
void bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
290+
netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
291291
struct net_device *slave_dev)
292292
{
293293
skb->dev = slave_dev;
@@ -297,9 +297,9 @@ void bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
297297
skb_set_queue_mapping(skb, qdisc_skb_cb(skb)->slave_dev_queue_mapping);
298298

299299
if (unlikely(netpoll_tx_running(bond->dev)))
300-
bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
301-
else
302-
dev_queue_xmit(skb);
300+
return bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
301+
302+
return dev_queue_xmit(skb);
303303
}
304304

305305
/* In the following 2 functions, bond_vlan_rx_add_vid and bond_vlan_rx_kill_vid,
@@ -3932,7 +3932,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
39323932
* it fails, it tries to find the first available slave for transmission.
39333933
* The skb is consumed in all cases, thus the function is void.
39343934
*/
3935-
static void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id)
3935+
static netdev_tx_t bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id)
39363936
{
39373937
struct list_head *iter;
39383938
struct slave *slave;
@@ -3941,10 +3941,8 @@ static void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int sl
39413941
/* Here we start from the slave with slave_id */
39423942
bond_for_each_slave_rcu(bond, slave, iter) {
39433943
if (--i < 0) {
3944-
if (bond_slave_can_tx(slave)) {
3945-
bond_dev_queue_xmit(bond, skb, slave->dev);
3946-
return;
3947-
}
3944+
if (bond_slave_can_tx(slave))
3945+
return bond_dev_queue_xmit(bond, skb, slave->dev);
39483946
}
39493947
}
39503948

@@ -3953,13 +3951,11 @@ static void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int sl
39533951
bond_for_each_slave_rcu(bond, slave, iter) {
39543952
if (--i < 0)
39553953
break;
3956-
if (bond_slave_can_tx(slave)) {
3957-
bond_dev_queue_xmit(bond, skb, slave->dev);
3958-
return;
3959-
}
3954+
if (bond_slave_can_tx(slave))
3955+
return bond_dev_queue_xmit(bond, skb, slave->dev);
39603956
}
39613957
/* no slave that can tx has been found */
3962-
bond_tx_drop(bond->dev, skb);
3958+
return bond_tx_drop(bond->dev, skb);
39633959
}
39643960

39653961
/**
@@ -4020,22 +4016,18 @@ static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb,
40204016
if (iph->protocol == IPPROTO_IGMP) {
40214017
slave = rcu_dereference(bond->curr_active_slave);
40224018
if (slave)
4023-
bond_dev_queue_xmit(bond, skb, slave->dev);
4024-
else
4025-
bond_xmit_slave_id(bond, skb, 0);
4026-
return NETDEV_TX_OK;
4019+
return bond_dev_queue_xmit(bond, skb, slave->dev);
4020+
return bond_xmit_slave_id(bond, skb, 0);
40274021
}
40284022
}
40294023

40304024
non_igmp:
40314025
slave_cnt = READ_ONCE(bond->slave_cnt);
40324026
if (likely(slave_cnt)) {
40334027
slave_id = bond_rr_gen_slave_id(bond);
4034-
bond_xmit_slave_id(bond, skb, slave_id % slave_cnt);
4035-
} else {
4036-
bond_tx_drop(bond_dev, skb);
4028+
return bond_xmit_slave_id(bond, skb, slave_id % slave_cnt);
40374029
}
4038-
return NETDEV_TX_OK;
4030+
return bond_tx_drop(bond_dev, skb);
40394031
}
40404032

40414033
/* In active-backup mode, we know that bond->curr_active_slave is always valid if
@@ -4049,11 +4041,9 @@ static netdev_tx_t bond_xmit_activebackup(struct sk_buff *skb,
40494041

40504042
slave = rcu_dereference(bond->curr_active_slave);
40514043
if (slave)
4052-
bond_dev_queue_xmit(bond, skb, slave->dev);
4053-
else
4054-
bond_tx_drop(bond_dev, skb);
4044+
return bond_dev_queue_xmit(bond, skb, slave->dev);
40554045

4056-
return NETDEV_TX_OK;
4046+
return bond_tx_drop(bond_dev, skb);
40574047
}
40584048

40594049
/* Use this to update slave_array when (a) it's not appropriate to update
@@ -4196,12 +4186,9 @@ static netdev_tx_t bond_3ad_xor_xmit(struct sk_buff *skb,
41964186
count = slaves ? READ_ONCE(slaves->count) : 0;
41974187
if (likely(count)) {
41984188
slave = slaves->arr[bond_xmit_hash(bond, skb) % count];
4199-
bond_dev_queue_xmit(bond, skb, slave->dev);
4200-
} else {
4201-
bond_tx_drop(dev, skb);
4189+
return bond_dev_queue_xmit(bond, skb, slave->dev);
42024190
}
4203-
4204-
return NETDEV_TX_OK;
4191+
return bond_tx_drop(dev, skb);
42054192
}
42064193

42074194
/* in broadcast mode, we send everything to all usable interfaces. */
@@ -4227,11 +4214,9 @@ static netdev_tx_t bond_xmit_broadcast(struct sk_buff *skb,
42274214
}
42284215
}
42294216
if (slave && bond_slave_is_up(slave) && slave->link == BOND_LINK_UP)
4230-
bond_dev_queue_xmit(bond, skb, slave->dev);
4231-
else
4232-
bond_tx_drop(bond_dev, skb);
4217+
return bond_dev_queue_xmit(bond, skb, slave->dev);
42334218

4234-
return NETDEV_TX_OK;
4219+
return bond_tx_drop(bond_dev, skb);
42354220
}
42364221

42374222
/*------------------------- Device initialization ---------------------------*/
@@ -4310,8 +4295,7 @@ static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev
43104295
/* Should never happen, mode already checked */
43114296
netdev_err(dev, "Unknown bonding mode %d\n", BOND_MODE(bond));
43124297
WARN_ON_ONCE(1);
4313-
bond_tx_drop(dev, skb);
4314-
return NETDEV_TX_OK;
4298+
return bond_tx_drop(dev, skb);
43154299
}
43164300
}
43174301

@@ -4330,7 +4314,7 @@ static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
43304314
if (bond_has_slaves(bond))
43314315
ret = __bond_start_xmit(skb, dev);
43324316
else
4333-
bond_tx_drop(dev, skb);
4317+
ret = bond_tx_drop(dev, skb);
43344318
rcu_read_unlock();
43354319

43364320
return ret;

‎include/net/bonding.h‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,17 @@ static inline unsigned long slave_last_rx(struct bonding *bond,
504504
}
505505

506506
#ifdef CONFIG_NET_POLL_CONTROLLER
507-
static inline void bond_netpoll_send_skb(const struct slave *slave,
507+
static inline netdev_tx_t bond_netpoll_send_skb(const struct slave *slave,
508508
struct sk_buff *skb)
509509
{
510-
netpoll_send_skb(slave->np, skb);
510+
return netpoll_send_skb(slave->np, skb);
511511
}
512512
#else
513-
static inline void bond_netpoll_send_skb(const struct slave *slave,
513+
static inline netdev_tx_t bond_netpoll_send_skb(const struct slave *slave,
514514
struct sk_buff *skb)
515515
{
516+
BUG();
517+
return NETDEV_TX_OK;
516518
}
517519
#endif
518520

@@ -606,7 +608,7 @@ struct bond_net {
606608
};
607609

608610
int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave);
609-
void bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
611+
netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
610612
int bond_create(struct net *net, const char *name);
611613
int bond_create_sysfs(struct bond_net *net);
612614
void bond_destroy_sysfs(struct bond_net *net);
@@ -739,10 +741,11 @@ extern struct bond_parm_tbl ad_select_tbl[];
739741
/* exported from bond_netlink.c */
740742
extern struct rtnl_link_ops bond_link_ops;
741743

742-
static inline void bond_tx_drop(struct net_device *dev, struct sk_buff *skb)
744+
static inline netdev_tx_t bond_tx_drop(struct net_device *dev, struct sk_buff *skb)
743745
{
744746
atomic_long_inc(&dev->tx_dropped);
745747
dev_kfree_skb_any(skb);
748+
return NET_XMIT_DROP;
746749
}
747750

748751
#endif /* _NET_BONDING_H */

0 commit comments

Comments
 (0)