Skip to content

Commit 0c5e145

Browse files
liuhangbinPaolo Abeni
authored andcommitted
bonding: fix incorrect MAC address setting to receive NS messages
When validation on the backup slave is enabled, we need to validate the Neighbor Solicitation (NS) messages received on the backup slave. To receive these messages, the correct destination MAC address must be added to the slave. However, the target in bonding is a unicast address, which we cannot use directly. Instead, we should first convert it to a Solicited-Node Multicast Address and then derive the corresponding MAC address. Fix the incorrect MAC address setting on both slave_set_ns_maddr() and slave_set_ns_maddrs(). Since the two function names are similar. Add some description for the functions. Also only use one mac_addr variable in slave_set_ns_maddr() to save some code and logic. Fixes: 8eb3616 ("bonding: add ns target multicast address to slave device") Acked-by: Jay Vosburgh <jv@jvosburgh.net> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20250306023923.38777-2-liuhangbin@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent f5d83cf commit 0c5e145

1 file changed

Lines changed: 47 additions & 8 deletions

File tree

drivers/net/bonding/bond_options.c

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,10 +1242,28 @@ static bool slave_can_set_ns_maddr(const struct bonding *bond, struct slave *sla
12421242
slave->dev->flags & IFF_MULTICAST;
12431243
}
12441244

1245+
/**
1246+
* slave_set_ns_maddrs - add/del all NS mac addresses for slave
1247+
* @bond: bond device
1248+
* @slave: slave device
1249+
* @add: add or remove all the NS mac addresses
1250+
*
1251+
* This function tries to add or delete all the NS mac addresses on the slave
1252+
*
1253+
* Note, the IPv6 NS target address is the unicast address in Neighbor
1254+
* Solicitation (NS) message. The dest address of NS message should be
1255+
* solicited-node multicast address of the target. The dest mac of NS message
1256+
* is converted from the solicited-node multicast address.
1257+
*
1258+
* This function is called when
1259+
* * arp_validate changes
1260+
* * enslaving, releasing new slaves
1261+
*/
12451262
static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool add)
12461263
{
12471264
struct in6_addr *targets = bond->params.ns_targets;
12481265
char slot_maddr[MAX_ADDR_LEN];
1266+
struct in6_addr mcaddr;
12491267
int i;
12501268

12511269
if (!slave_can_set_ns_maddr(bond, slave))
@@ -1255,7 +1273,8 @@ static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool
12551273
if (ipv6_addr_any(&targets[i]))
12561274
break;
12571275

1258-
if (!ndisc_mc_map(&targets[i], slot_maddr, slave->dev, 0)) {
1276+
addrconf_addr_solict_mult(&targets[i], &mcaddr);
1277+
if (!ndisc_mc_map(&mcaddr, slot_maddr, slave->dev, 0)) {
12591278
if (add)
12601279
dev_mc_add(slave->dev, slot_maddr);
12611280
else
@@ -1278,23 +1297,43 @@ void bond_slave_ns_maddrs_del(struct bonding *bond, struct slave *slave)
12781297
slave_set_ns_maddrs(bond, slave, false);
12791298
}
12801299

1300+
/**
1301+
* slave_set_ns_maddr - set new NS mac address for slave
1302+
* @bond: bond device
1303+
* @slave: slave device
1304+
* @target: the new IPv6 target
1305+
* @slot: the old IPv6 target in the slot
1306+
*
1307+
* This function tries to replace the old mac address to new one on the slave.
1308+
*
1309+
* Note, the target/slot IPv6 address is the unicast address in Neighbor
1310+
* Solicitation (NS) message. The dest address of NS message should be
1311+
* solicited-node multicast address of the target. The dest mac of NS message
1312+
* is converted from the solicited-node multicast address.
1313+
*
1314+
* This function is called when
1315+
* * An IPv6 NS target is added or removed.
1316+
*/
12811317
static void slave_set_ns_maddr(struct bonding *bond, struct slave *slave,
12821318
struct in6_addr *target, struct in6_addr *slot)
12831319
{
1284-
char target_maddr[MAX_ADDR_LEN], slot_maddr[MAX_ADDR_LEN];
1320+
char mac_addr[MAX_ADDR_LEN];
1321+
struct in6_addr mcast_addr;
12851322

12861323
if (!bond->params.arp_validate || !slave_can_set_ns_maddr(bond, slave))
12871324
return;
12881325

1289-
/* remove the previous maddr from slave */
1326+
/* remove the previous mac addr from slave */
1327+
addrconf_addr_solict_mult(slot, &mcast_addr);
12901328
if (!ipv6_addr_any(slot) &&
1291-
!ndisc_mc_map(slot, slot_maddr, slave->dev, 0))
1292-
dev_mc_del(slave->dev, slot_maddr);
1329+
!ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0))
1330+
dev_mc_del(slave->dev, mac_addr);
12931331

1294-
/* add new maddr on slave if target is set */
1332+
/* add new mac addr on slave if target is set */
1333+
addrconf_addr_solict_mult(target, &mcast_addr);
12951334
if (!ipv6_addr_any(target) &&
1296-
!ndisc_mc_map(target, target_maddr, slave->dev, 0))
1297-
dev_mc_add(slave->dev, target_maddr);
1335+
!ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0))
1336+
dev_mc_add(slave->dev, mac_addr);
12981337
}
12991338

13001339
static void _bond_options_ns_ip6_target_set(struct bonding *bond, int slot,

0 commit comments

Comments
 (0)