Skip to content

Commit faeeb31

Browse files
jarodwilsondavem330
authored andcommitted
bonding: attempt to better support longer hw addresses
People are using bonding over Infiniband IPoIB connections, and who knows what else. Infiniband has a hardware address length of 20 octets (INFINIBAND_ALEN), and the network core defines a MAX_ADDR_LEN of 32. Various places in the bonding code are currently hard-wired to 6 octets (ETH_ALEN), such as the 3ad code, which I've left untouched here. Besides, only alb is currently possible on Infiniband links right now anyway, due to commit 1533e77, so the alb code is where most of the changes are. One major component of this change is the addition of a bond_hw_addr_copy function that takes a length argument, instead of using ether_addr_copy everywhere that hardware addresses need to be copied about. The other major component of this change is converting the bonding code from using struct sockaddr for address storage to struct sockaddr_storage, as the former has an address storage space of only 14, while the latter is 128 minus a few, which is necessary to support bonding over device with up to MAX_ADDR_LEN octet hardware addresses. Additionally, this probably fixes up some memory corruption issues with the current code, where it's possible to write an infiniband hardware address into a sockaddr declared on the stack. Lightly tested on a dual mlx4 IPoIB setup, which properly shows a 20-octet hardware address now: $ cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active) Primary Slave: mlx4_ib0 (primary_reselect always) Currently Active Slave: mlx4_ib0 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 100 Down Delay (ms): 100 Slave Interface: mlx4_ib0 MII Status: up Speed: Unknown Duplex: Unknown Link Failure Count: 0 Permanent HW addr: 80:00:02:08:fe:80:00:00:00:00:00:00:e4:1d:2d:03:00:1d:67:01 Slave queue ID: 0 Slave Interface: mlx4_ib1 MII Status: up Speed: Unknown Duplex: Unknown Link Failure Count: 0 Permanent HW addr: 80:00:02:09:fe:80:00:00:00:00:00:01:e4:1d:2d:03:00:1d:67:02 Slave queue ID: 0 Also tested with a standard 1Gbps NIC bonding setup (with a mix of e1000 and e1000e cards), running LNST's bonding tests. CC: Jay Vosburgh <j.vosburgh@gmail.com> CC: Veaceslav Falico <vfalico@gmail.com> CC: Andy Gospodarek <andy@greyhouse.net> CC: netdev@vger.kernel.org Signed-off-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 148cbab commit faeeb31

4 files changed

Lines changed: 108 additions & 68 deletions

File tree

‎drivers/net/bonding/bond_alb.c‎

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,8 @@ static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
687687
/* the arp must be sent on the selected rx channel */
688688
tx_slave = rlb_choose_channel(skb, bond);
689689
if (tx_slave)
690-
ether_addr_copy(arp->mac_src, tx_slave->dev->dev_addr);
690+
bond_hw_addr_copy(arp->mac_src, tx_slave->dev->dev_addr,
691+
tx_slave->dev->addr_len);
691692
netdev_dbg(bond->dev, "Server sent ARP Reply packet\n");
692693
} else if (arp->op_code == htons(ARPOP_REQUEST)) {
693694
/* Create an entry in the rx_hashtbl for this client as a
@@ -1017,22 +1018,23 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[],
10171018
rcu_read_unlock();
10181019
}
10191020

1020-
static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[])
1021+
static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[],
1022+
unsigned int len)
10211023
{
10221024
struct net_device *dev = slave->dev;
1023-
struct sockaddr s_addr;
1025+
struct sockaddr_storage ss;
10241026

10251027
if (BOND_MODE(slave->bond) == BOND_MODE_TLB) {
1026-
memcpy(dev->dev_addr, addr, dev->addr_len);
1028+
memcpy(dev->dev_addr, addr, len);
10271029
return 0;
10281030
}
10291031

10301032
/* for rlb each slave must have a unique hw mac addresses so that
10311033
* each slave will receive packets destined to a different mac
10321034
*/
1033-
memcpy(s_addr.sa_data, addr, dev->addr_len);
1034-
s_addr.sa_family = dev->type;
1035-
if (dev_set_mac_address(dev, &s_addr)) {
1035+
memcpy(ss.__data, addr, len);
1036+
ss.ss_family = dev->type;
1037+
if (dev_set_mac_address(dev, (struct sockaddr *)&ss)) {
10361038
netdev_err(slave->bond->dev, "dev_set_mac_address of dev %s failed! ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n",
10371039
dev->name);
10381040
return -EOPNOTSUPP;
@@ -1046,11 +1048,14 @@ static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[])
10461048
*/
10471049
static void alb_swap_mac_addr(struct slave *slave1, struct slave *slave2)
10481050
{
1049-
u8 tmp_mac_addr[ETH_ALEN];
1051+
u8 tmp_mac_addr[MAX_ADDR_LEN];
10501052

1051-
ether_addr_copy(tmp_mac_addr, slave1->dev->dev_addr);
1052-
alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr);
1053-
alb_set_slave_mac_addr(slave2, tmp_mac_addr);
1053+
bond_hw_addr_copy(tmp_mac_addr, slave1->dev->dev_addr,
1054+
slave1->dev->addr_len);
1055+
alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr,
1056+
slave2->dev->addr_len);
1057+
alb_set_slave_mac_addr(slave2, tmp_mac_addr,
1058+
slave1->dev->addr_len);
10541059

10551060
}
10561061

@@ -1177,7 +1182,8 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
11771182
/* Try setting slave mac to bond address and fall-through
11781183
* to code handling that situation below...
11791184
*/
1180-
alb_set_slave_mac_addr(slave, bond->dev->dev_addr);
1185+
alb_set_slave_mac_addr(slave, bond->dev->dev_addr,
1186+
bond->dev->addr_len);
11811187
}
11821188

11831189
/* The slave's address is equal to the address of the bond.
@@ -1202,7 +1208,8 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
12021208
}
12031209

12041210
if (free_mac_slave) {
1205-
alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr);
1211+
alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr,
1212+
free_mac_slave->dev->addr_len);
12061213

12071214
netdev_warn(bond->dev, "the hw address of slave %s is in use by the bond; giving it the hw address of %s\n",
12081215
slave->dev->name, free_mac_slave->dev->name);
@@ -1234,21 +1241,23 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
12341241
{
12351242
struct slave *slave, *rollback_slave;
12361243
struct list_head *iter;
1237-
struct sockaddr sa;
1238-
char tmp_addr[ETH_ALEN];
1244+
struct sockaddr_storage ss;
1245+
char tmp_addr[MAX_ADDR_LEN];
12391246
int res;
12401247

12411248
if (bond->alb_info.rlb_enabled)
12421249
return 0;
12431250

12441251
bond_for_each_slave(bond, slave, iter) {
12451252
/* save net_device's current hw address */
1246-
ether_addr_copy(tmp_addr, slave->dev->dev_addr);
1253+
bond_hw_addr_copy(tmp_addr, slave->dev->dev_addr,
1254+
slave->dev->addr_len);
12471255

12481256
res = dev_set_mac_address(slave->dev, addr);
12491257

12501258
/* restore net_device's hw address */
1251-
ether_addr_copy(slave->dev->dev_addr, tmp_addr);
1259+
bond_hw_addr_copy(slave->dev->dev_addr, tmp_addr,
1260+
slave->dev->addr_len);
12521261

12531262
if (res)
12541263
goto unwind;
@@ -1257,16 +1266,19 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
12571266
return 0;
12581267

12591268
unwind:
1260-
memcpy(sa.sa_data, bond->dev->dev_addr, bond->dev->addr_len);
1261-
sa.sa_family = bond->dev->type;
1269+
memcpy(ss.__data, bond->dev->dev_addr, bond->dev->addr_len);
1270+
ss.ss_family = bond->dev->type;
12621271

12631272
/* unwind from head to the slave that failed */
12641273
bond_for_each_slave(bond, rollback_slave, iter) {
12651274
if (rollback_slave == slave)
12661275
break;
1267-
ether_addr_copy(tmp_addr, rollback_slave->dev->dev_addr);
1268-
dev_set_mac_address(rollback_slave->dev, &sa);
1269-
ether_addr_copy(rollback_slave->dev->dev_addr, tmp_addr);
1276+
bond_hw_addr_copy(tmp_addr, rollback_slave->dev->dev_addr,
1277+
rollback_slave->dev->addr_len);
1278+
dev_set_mac_address(rollback_slave->dev,
1279+
(struct sockaddr *)&ss);
1280+
bond_hw_addr_copy(rollback_slave->dev->dev_addr, tmp_addr,
1281+
rollback_slave->dev->addr_len);
12701282
}
12711283

12721284
return res;
@@ -1582,7 +1594,8 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
15821594
{
15831595
int res;
15841596

1585-
res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr);
1597+
res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr,
1598+
slave->dev->addr_len);
15861599
if (res)
15871600
return res;
15881601

@@ -1696,17 +1709,20 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
16961709
* and thus filter bond->dev_addr's packets, so force bond's mac
16971710
*/
16981711
if (BOND_MODE(bond) == BOND_MODE_TLB) {
1699-
struct sockaddr sa;
1700-
u8 tmp_addr[ETH_ALEN];
1712+
struct sockaddr_storage ss;
1713+
u8 tmp_addr[MAX_ADDR_LEN];
17011714

1702-
ether_addr_copy(tmp_addr, new_slave->dev->dev_addr);
1715+
bond_hw_addr_copy(tmp_addr, new_slave->dev->dev_addr,
1716+
new_slave->dev->addr_len);
17031717

1704-
memcpy(sa.sa_data, bond->dev->dev_addr, bond->dev->addr_len);
1705-
sa.sa_family = bond->dev->type;
1718+
bond_hw_addr_copy(ss.__data, bond->dev->dev_addr,
1719+
bond->dev->addr_len);
1720+
ss.ss_family = bond->dev->type;
17061721
/* we don't care if it can't change its mac, best effort */
1707-
dev_set_mac_address(new_slave->dev, &sa);
1722+
dev_set_mac_address(new_slave->dev, (struct sockaddr *)&ss);
17081723

1709-
ether_addr_copy(new_slave->dev->dev_addr, tmp_addr);
1724+
bond_hw_addr_copy(new_slave->dev->dev_addr, tmp_addr,
1725+
new_slave->dev->addr_len);
17101726
}
17111727

17121728
/* curr_active_slave must be set before calling alb_swap_mac_addr */
@@ -1716,7 +1732,8 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
17161732
alb_fasten_mac_swap(bond, swap_slave, new_slave);
17171733
} else {
17181734
/* set the new_slave to the bond mac address */
1719-
alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr);
1735+
alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr,
1736+
bond->dev->addr_len);
17201737
alb_send_learning_packets(new_slave, bond->dev->dev_addr,
17211738
false);
17221739
}
@@ -1726,19 +1743,19 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
17261743
int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
17271744
{
17281745
struct bonding *bond = netdev_priv(bond_dev);
1729-
struct sockaddr *sa = addr;
1746+
struct sockaddr_storage *ss = addr;
17301747
struct slave *curr_active;
17311748
struct slave *swap_slave;
17321749
int res;
17331750

1734-
if (!is_valid_ether_addr(sa->sa_data))
1751+
if (!is_valid_ether_addr(ss->__data))
17351752
return -EADDRNOTAVAIL;
17361753

17371754
res = alb_set_mac_address(bond, addr);
17381755
if (res)
17391756
return res;
17401757

1741-
memcpy(bond_dev->dev_addr, sa->sa_data, bond_dev->addr_len);
1758+
bond_hw_addr_copy(bond_dev->dev_addr, ss->__data, bond_dev->addr_len);
17421759

17431760
/* If there is no curr_active_slave there is nothing else to do.
17441761
* Otherwise we'll need to pass the new address to it and handle
@@ -1754,7 +1771,8 @@ int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
17541771
alb_swap_mac_addr(swap_slave, curr_active);
17551772
alb_fasten_mac_swap(bond, swap_slave, curr_active);
17561773
} else {
1757-
alb_set_slave_mac_addr(curr_active, bond_dev->dev_addr);
1774+
alb_set_slave_mac_addr(curr_active, bond_dev->dev_addr,
1775+
bond_dev->addr_len);
17581776

17591777
alb_send_learning_packets(curr_active,
17601778
bond_dev->dev_addr, false);

‎drivers/net/bonding/bond_main.c‎

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ static void bond_do_fail_over_mac(struct bonding *bond,
645645
struct slave *new_active,
646646
struct slave *old_active)
647647
{
648-
u8 tmp_mac[ETH_ALEN];
649-
struct sockaddr saddr;
648+
u8 tmp_mac[MAX_ADDR_LEN];
649+
struct sockaddr_storage ss;
650650
int rv;
651651

652652
switch (bond->params.fail_over_mac) {
@@ -666,16 +666,20 @@ static void bond_do_fail_over_mac(struct bonding *bond,
666666
old_active = bond_get_old_active(bond, new_active);
667667

668668
if (old_active) {
669-
ether_addr_copy(tmp_mac, new_active->dev->dev_addr);
670-
ether_addr_copy(saddr.sa_data,
671-
old_active->dev->dev_addr);
672-
saddr.sa_family = new_active->dev->type;
669+
bond_hw_addr_copy(tmp_mac, new_active->dev->dev_addr,
670+
new_active->dev->addr_len);
671+
bond_hw_addr_copy(ss.__data,
672+
old_active->dev->dev_addr,
673+
old_active->dev->addr_len);
674+
ss.ss_family = new_active->dev->type;
673675
} else {
674-
ether_addr_copy(saddr.sa_data, bond->dev->dev_addr);
675-
saddr.sa_family = bond->dev->type;
676+
bond_hw_addr_copy(ss.__data, bond->dev->dev_addr,
677+
bond->dev->addr_len);
678+
ss.ss_family = bond->dev->type;
676679
}
677680

678-
rv = dev_set_mac_address(new_active->dev, &saddr);
681+
rv = dev_set_mac_address(new_active->dev,
682+
(struct sockaddr *)&ss);
679683
if (rv) {
680684
netdev_err(bond->dev, "Error %d setting MAC of slave %s\n",
681685
-rv, new_active->dev->name);
@@ -685,10 +689,12 @@ static void bond_do_fail_over_mac(struct bonding *bond,
685689
if (!old_active)
686690
goto out;
687691

688-
ether_addr_copy(saddr.sa_data, tmp_mac);
689-
saddr.sa_family = old_active->dev->type;
692+
bond_hw_addr_copy(ss.__data, tmp_mac,
693+
new_active->dev->addr_len);
694+
ss.ss_family = old_active->dev->type;
690695

691-
rv = dev_set_mac_address(old_active->dev, &saddr);
696+
rv = dev_set_mac_address(old_active->dev,
697+
(struct sockaddr *)&ss);
692698
if (rv)
693699
netdev_err(bond->dev, "Error %d setting MAC of slave %s\n",
694700
-rv, new_active->dev->name);
@@ -1184,7 +1190,8 @@ static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
11841190
kfree_skb(skb);
11851191
return RX_HANDLER_CONSUMED;
11861192
}
1187-
ether_addr_copy(eth_hdr(skb)->h_dest, bond->dev->dev_addr);
1193+
bond_hw_addr_copy(eth_hdr(skb)->h_dest, bond->dev->dev_addr,
1194+
bond->dev->addr_len);
11881195
}
11891196

11901197
return ret;
@@ -1323,7 +1330,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
13231330
struct bonding *bond = netdev_priv(bond_dev);
13241331
const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
13251332
struct slave *new_slave = NULL, *prev_slave;
1326-
struct sockaddr addr;
1333+
struct sockaddr_storage ss;
13271334
int link_reporting;
13281335
int res = 0, i;
13291336

@@ -1474,16 +1481,17 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
14741481
* that need it, and for restoring it upon release, and then
14751482
* set it to the master's address
14761483
*/
1477-
ether_addr_copy(new_slave->perm_hwaddr, slave_dev->dev_addr);
1484+
bond_hw_addr_copy(new_slave->perm_hwaddr, slave_dev->dev_addr,
1485+
slave_dev->addr_len);
14781486

14791487
if (!bond->params.fail_over_mac ||
14801488
BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
14811489
/* Set slave to master's mac address. The application already
14821490
* set the master's mac address to that of the first slave
14831491
*/
1484-
memcpy(addr.sa_data, bond_dev->dev_addr, bond_dev->addr_len);
1485-
addr.sa_family = slave_dev->type;
1486-
res = dev_set_mac_address(slave_dev, &addr);
1492+
memcpy(ss.__data, bond_dev->dev_addr, bond_dev->addr_len);
1493+
ss.ss_family = slave_dev->type;
1494+
res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss);
14871495
if (res) {
14881496
netdev_dbg(bond_dev, "Error %d calling set_mac_address\n", res);
14891497
goto err_restore_mtu;
@@ -1767,9 +1775,10 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
17671775
* MAC if this slave's MAC is in use by the bond, or at
17681776
* least print a warning.
17691777
*/
1770-
ether_addr_copy(addr.sa_data, new_slave->perm_hwaddr);
1771-
addr.sa_family = slave_dev->type;
1772-
dev_set_mac_address(slave_dev, &addr);
1778+
bond_hw_addr_copy(ss.__data, new_slave->perm_hwaddr,
1779+
new_slave->dev->addr_len);
1780+
ss.ss_family = slave_dev->type;
1781+
dev_set_mac_address(slave_dev, (struct sockaddr *)&ss);
17731782
}
17741783

17751784
err_restore_mtu:
@@ -1812,7 +1821,7 @@ static int __bond_release_one(struct net_device *bond_dev,
18121821
{
18131822
struct bonding *bond = netdev_priv(bond_dev);
18141823
struct slave *slave, *oldcurrent;
1815-
struct sockaddr addr;
1824+
struct sockaddr_storage ss;
18161825
int old_flags = bond_dev->flags;
18171826
netdev_features_t old_features = bond_dev->features;
18181827

@@ -1947,9 +1956,10 @@ static int __bond_release_one(struct net_device *bond_dev,
19471956
if (bond->params.fail_over_mac != BOND_FOM_ACTIVE ||
19481957
BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
19491958
/* restore original ("permanent") mac address */
1950-
ether_addr_copy(addr.sa_data, slave->perm_hwaddr);
1951-
addr.sa_family = slave_dev->type;
1952-
dev_set_mac_address(slave_dev, &addr);
1959+
bond_hw_addr_copy(ss.__data, slave->perm_hwaddr,
1960+
slave->dev->addr_len);
1961+
ss.ss_family = slave_dev->type;
1962+
dev_set_mac_address(slave_dev, (struct sockaddr *)&ss);
19531963
}
19541964

19551965
dev_set_mtu(slave_dev, slave->original_mtu);
@@ -3626,7 +3636,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
36263636
{
36273637
struct bonding *bond = netdev_priv(bond_dev);
36283638
struct slave *slave, *rollback_slave;
3629-
struct sockaddr *sa = addr, tmp_sa;
3639+
struct sockaddr_storage *ss = addr, tmp_ss;
36303640
struct list_head *iter;
36313641
int res = 0;
36323642

@@ -3643,7 +3653,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
36433653
BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
36443654
return 0;
36453655

3646-
if (!is_valid_ether_addr(sa->sa_data))
3656+
if (!is_valid_ether_addr(ss->__data))
36473657
return -EADDRNOTAVAIL;
36483658

36493659
bond_for_each_slave(bond, slave, iter) {
@@ -3662,12 +3672,12 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
36623672
}
36633673

36643674
/* success */
3665-
memcpy(bond_dev->dev_addr, sa->sa_data, bond_dev->addr_len);
3675+
memcpy(bond_dev->dev_addr, ss->__data, bond_dev->addr_len);
36663676
return 0;
36673677

36683678
unwind:
3669-
memcpy(tmp_sa.sa_data, bond_dev->dev_addr, bond_dev->addr_len);
3670-
tmp_sa.sa_family = bond_dev->type;
3679+
memcpy(tmp_ss.__data, bond_dev->dev_addr, bond_dev->addr_len);
3680+
tmp_ss.ss_family = bond_dev->type;
36713681

36723682
/* unwind from head to the slave that failed */
36733683
bond_for_each_slave(bond, rollback_slave, iter) {
@@ -3676,7 +3686,8 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
36763686
if (rollback_slave == slave)
36773687
break;
36783688

3679-
tmp_res = dev_set_mac_address(rollback_slave->dev, &tmp_sa);
3689+
tmp_res = dev_set_mac_address(rollback_slave->dev,
3690+
(struct sockaddr *)&tmp_ss);
36803691
if (tmp_res) {
36813692
netdev_dbg(bond_dev, "unwind err %d dev %s\n",
36823693
tmp_res, rollback_slave->dev->name);

‎drivers/net/bonding/bond_procfs.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ static void bond_info_show_slave(struct seq_file *seq,
183183
seq_printf(seq, "Link Failure Count: %u\n",
184184
slave->link_failure_count);
185185

186-
seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr);
186+
seq_printf(seq, "Permanent HW addr: %*phC\n",
187+
slave->dev->addr_len, slave->perm_hwaddr);
187188
seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
188189

189190
if (BOND_MODE(bond) == BOND_MODE_8023AD) {

0 commit comments

Comments
 (0)