hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/drivers/net/bonding/bond_alb.c
....@@ -1,22 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
3
- *
4
- * This program is free software; you can redistribute it and/or modify it
5
- * under the terms of the GNU General Public License as published by the
6
- * Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful, but
10
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
- * for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License along
15
- * with this program; if not, see <http://www.gnu.org/licenses/>.
16
- *
17
- * The full GNU General Public License is included in this distribution in the
18
- * file called LICENSE.
19
- *
204 */
215
226 #include <linux/skbuff.h>
....@@ -311,7 +295,7 @@
311295 if (arp->op_code == htons(ARPOP_REPLY)) {
312296 /* update rx hash table for this ARP */
313297 rlb_update_entry_from_arp(bond, arp);
314
- netdev_dbg(bond->dev, "Server received an ARP Reply from client\n");
298
+ slave_dbg(bond->dev, slave->dev, "Server received an ARP Reply from client\n");
315299 }
316300 out:
317301 return RX_HANDLER_ANOTHER;
....@@ -453,8 +437,9 @@
453437 client_info->slave->dev->dev_addr,
454438 client_info->mac_dst);
455439 if (!skb) {
456
- netdev_err(client_info->slave->bond->dev,
457
- "failed to create an ARP packet\n");
440
+ slave_err(client_info->slave->bond->dev,
441
+ client_info->slave->dev,
442
+ "failed to create an ARP packet\n");
458443 continue;
459444 }
460445
....@@ -671,10 +656,10 @@
671656 return NULL;
672657 arp = (struct arp_pkt *)skb_network_header(skb);
673658
674
- /* Don't modify or load balance ARPs that do not originate locally
675
- * (e.g.,arrive via a bridge).
659
+ /* Don't modify or load balance ARPs that do not originate
660
+ * from the bond itself or a VLAN directly above the bond.
676661 */
677
- if (!bond_slave_has_mac_rx(bond, arp->mac_src))
662
+ if (!bond_slave_has_mac_rcu(bond, arp->mac_src))
678663 return NULL;
679664
680665 if (arp->op_code == htons(ARPOP_REPLY)) {
....@@ -683,14 +668,15 @@
683668 if (tx_slave)
684669 bond_hw_addr_copy(arp->mac_src, tx_slave->dev->dev_addr,
685670 tx_slave->dev->addr_len);
686
- netdev_dbg(bond->dev, "Server sent ARP Reply packet\n");
671
+ netdev_dbg(bond->dev, "(slave %s): Server sent ARP Reply packet\n",
672
+ tx_slave ? tx_slave->dev->name : "NULL");
687673 } else if (arp->op_code == htons(ARPOP_REQUEST)) {
688674 /* Create an entry in the rx_hashtbl for this client as a
689675 * place holder.
690676 * When the arp reply is received the entry will be updated
691677 * with the correct unicast address of the client.
692678 */
693
- rlb_choose_channel(skb, bond, arp);
679
+ tx_slave = rlb_choose_channel(skb, bond, arp);
694680
695681 /* The ARP reply packets must be delayed so that
696682 * they can cancel out the influence of the ARP request.
....@@ -703,7 +689,8 @@
703689 * updated with their assigned mac.
704690 */
705691 rlb_req_update_subnet_clients(bond, arp->ip_src);
706
- netdev_dbg(bond->dev, "Server sent ARP Request packet\n");
692
+ netdev_dbg(bond->dev, "(slave %s): Server sent ARP Request packet\n",
693
+ tx_slave ? tx_slave->dev->name : "NULL");
707694 }
708695
709696 return tx_slave;
....@@ -939,9 +926,8 @@
939926 skb->priority = TC_PRIO_CONTROL;
940927 skb->dev = slave->dev;
941928
942
- netdev_dbg(slave->bond->dev,
943
- "Send learning packet: dev %s mac %pM vlan %d\n",
944
- slave->dev->name, mac_addr, vid);
929
+ slave_dbg(slave->bond->dev, slave->dev,
930
+ "Send learning packet: mac %pM vlan %d\n", mac_addr, vid);
945931
946932 if (vid)
947933 __vlan_hwaccel_put_tag(skb, vlan_proto, vid);
....@@ -956,9 +942,10 @@
956942 bool strict_match;
957943 };
958944
959
-static int alb_upper_dev_walk(struct net_device *upper, void *_data)
945
+static int alb_upper_dev_walk(struct net_device *upper,
946
+ struct netdev_nested_priv *priv)
960947 {
961
- struct alb_walk_data *data = _data;
948
+ struct alb_walk_data *data = (struct alb_walk_data *)priv->data;
962949 bool strict_match = data->strict_match;
963950 struct bonding *bond = data->bond;
964951 struct slave *slave = data->slave;
....@@ -966,7 +953,7 @@
966953 struct bond_vlan_tag *tags;
967954
968955 if (is_vlan_dev(upper) &&
969
- bond->nest_level == vlan_get_encap_level(upper) - 1) {
956
+ bond->dev->lower_level == upper->lower_level - 1) {
970957 if (upper->addr_assign_type == NET_ADDR_STOLEN) {
971958 alb_send_lp_vid(slave, mac_addr,
972959 vlan_dev_vlan_proto(upper),
....@@ -997,6 +984,7 @@
997984 bool strict_match)
998985 {
999986 struct bonding *bond = bond_get_bond_by_slave(slave);
987
+ struct netdev_nested_priv priv;
1000988 struct alb_walk_data data = {
1001989 .strict_match = strict_match,
1002990 .mac_addr = mac_addr,
....@@ -1004,6 +992,7 @@
1004992 .bond = bond,
1005993 };
1006994
995
+ priv.data = (void *)&data;
1007996 /* send untagged */
1008997 alb_send_lp_vid(slave, mac_addr, 0, 0);
1009998
....@@ -1011,7 +1000,7 @@
10111000 * for that device.
10121001 */
10131002 rcu_read_lock();
1014
- netdev_walk_all_upper_dev_rcu(bond->dev, alb_upper_dev_walk, &data);
1003
+ netdev_walk_all_upper_dev_rcu(bond->dev, alb_upper_dev_walk, &priv);
10151004 rcu_read_unlock();
10161005 }
10171006
....@@ -1031,9 +1020,8 @@
10311020 */
10321021 memcpy(ss.__data, addr, len);
10331022 ss.ss_family = dev->type;
1034
- if (dev_set_mac_address(dev, (struct sockaddr *)&ss)) {
1035
- 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",
1036
- dev->name);
1023
+ if (dev_set_mac_address(dev, (struct sockaddr *)&ss, NULL)) {
1024
+ slave_err(slave->bond->dev, dev, "dev_set_mac_address on slave failed! ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n");
10371025 return -EOPNOTSUPP;
10381026 }
10391027 return 0;
....@@ -1208,12 +1196,11 @@
12081196 alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr,
12091197 free_mac_slave->dev->addr_len);
12101198
1211
- netdev_warn(bond->dev, "the hw address of slave %s is in use by the bond; giving it the hw address of %s\n",
1212
- slave->dev->name, free_mac_slave->dev->name);
1199
+ slave_warn(bond->dev, slave->dev, "the slave hw address is in use by the bond; giving it the hw address of %s\n",
1200
+ free_mac_slave->dev->name);
12131201
12141202 } else if (has_bond_addr) {
1215
- netdev_err(bond->dev, "the hw address of slave %s is in use by the bond; couldn't find a slave with a free hw address to give it (this should not have happened)\n",
1216
- slave->dev->name);
1203
+ slave_err(bond->dev, slave->dev, "the slave hw address is in use by the bond; couldn't find a slave with a free hw address to give it (this should not have happened)\n");
12171204 return -EFAULT;
12181205 }
12191206
....@@ -1222,8 +1209,8 @@
12221209
12231210 /**
12241211 * alb_set_mac_address
1225
- * @bond:
1226
- * @addr:
1212
+ * @bond: bonding we're working on
1213
+ * @addr: MAC address to set
12271214 *
12281215 * In TLB mode all slaves are configured to the bond's hw address, but set
12291216 * their dev_addr field to different addresses (based on their permanent hw
....@@ -1250,7 +1237,7 @@
12501237 bond_hw_addr_copy(tmp_addr, slave->dev->dev_addr,
12511238 slave->dev->addr_len);
12521239
1253
- res = dev_set_mac_address(slave->dev, addr);
1240
+ res = dev_set_mac_address(slave->dev, addr, NULL);
12541241
12551242 /* restore net_device's hw address */
12561243 bond_hw_addr_copy(slave->dev->dev_addr, tmp_addr,
....@@ -1273,7 +1260,7 @@
12731260 bond_hw_addr_copy(tmp_addr, rollback_slave->dev->dev_addr,
12741261 rollback_slave->dev->addr_len);
12751262 dev_set_mac_address(rollback_slave->dev,
1276
- (struct sockaddr *)&ss);
1263
+ (struct sockaddr *)&ss, NULL);
12771264 bond_hw_addr_copy(rollback_slave->dev->dev_addr, tmp_addr,
12781265 rollback_slave->dev->addr_len);
12791266 }
....@@ -1292,12 +1279,12 @@
12921279 return res;
12931280
12941281 if (rlb_enabled) {
1295
- bond->alb_info.rlb_enabled = 1;
12961282 res = rlb_initialize(bond);
12971283 if (res) {
12981284 tlb_deinitialize(bond);
12991285 return res;
13001286 }
1287
+ bond->alb_info.rlb_enabled = 1;
13011288 } else {
13021289 bond->alb_info.rlb_enabled = 0;
13031290 }
....@@ -1334,8 +1321,7 @@
13341321 tx_slave->dev->dev_addr);
13351322 }
13361323
1337
- bond_dev_queue_xmit(bond, skb, tx_slave->dev);
1338
- goto out;
1324
+ return bond_dev_queue_xmit(bond, skb, tx_slave->dev);
13391325 }
13401326
13411327 if (tx_slave && bond->params.tlb_dynamic_lb) {
....@@ -1345,16 +1331,14 @@
13451331 }
13461332
13471333 /* no suitable interface, frame not sent */
1348
- bond_tx_drop(bond->dev, skb);
1349
-out:
1350
- return NETDEV_TX_OK;
1334
+ return bond_tx_drop(bond->dev, skb);
13511335 }
13521336
1353
-netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1337
+struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
1338
+ struct sk_buff *skb)
13541339 {
1355
- struct bonding *bond = netdev_priv(bond_dev);
1356
- struct ethhdr *eth_data;
13571340 struct slave *tx_slave = NULL;
1341
+ struct ethhdr *eth_data;
13581342 u32 hash_index;
13591343
13601344 skb_reset_mac_header(skb);
....@@ -1376,7 +1360,7 @@
13761360 struct bond_up_slave *slaves;
13771361 unsigned int count;
13781362
1379
- slaves = rcu_dereference(bond->slave_arr);
1363
+ slaves = rcu_dereference(bond->usable_slaves);
13801364 count = slaves ? READ_ONCE(slaves->count) : 0;
13811365 if (likely(count))
13821366 tx_slave = slaves->arr[hash_index %
....@@ -1385,20 +1369,29 @@
13851369 break;
13861370 }
13871371 }
1372
+ return tx_slave;
1373
+}
1374
+
1375
+netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1376
+{
1377
+ struct bonding *bond = netdev_priv(bond_dev);
1378
+ struct slave *tx_slave;
1379
+
1380
+ tx_slave = bond_xmit_tlb_slave_get(bond, skb);
13881381 return bond_do_alb_xmit(skb, bond, tx_slave);
13891382 }
13901383
1391
-netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1384
+struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
1385
+ struct sk_buff *skb)
13921386 {
1393
- struct bonding *bond = netdev_priv(bond_dev);
1394
- struct ethhdr *eth_data;
13951387 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1396
- struct slave *tx_slave = NULL;
13971388 static const __be32 ip_bcast = htonl(0xffffffff);
1398
- int hash_size = 0;
1399
- bool do_tx_balance = true;
1400
- u32 hash_index = 0;
1389
+ struct slave *tx_slave = NULL;
14011390 const u8 *hash_start = NULL;
1391
+ bool do_tx_balance = true;
1392
+ struct ethhdr *eth_data;
1393
+ u32 hash_index = 0;
1394
+ int hash_size = 0;
14021395
14031396 skb_reset_mac_header(skb);
14041397 eth_data = eth_hdr(skb);
....@@ -1510,14 +1503,22 @@
15101503 struct bond_up_slave *slaves;
15111504 unsigned int count;
15121505
1513
- slaves = rcu_dereference(bond->slave_arr);
1506
+ slaves = rcu_dereference(bond->usable_slaves);
15141507 count = slaves ? READ_ONCE(slaves->count) : 0;
15151508 if (likely(count))
15161509 tx_slave = slaves->arr[bond_xmit_hash(bond, skb) %
15171510 count];
15181511 }
15191512 }
1513
+ return tx_slave;
1514
+}
15201515
1516
+netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1517
+{
1518
+ struct bonding *bond = netdev_priv(bond_dev);
1519
+ struct slave *tx_slave = NULL;
1520
+
1521
+ tx_slave = bond_xmit_alb_slave_get(bond, skb);
15211522 return bond_do_alb_xmit(skb, bond, tx_slave);
15221523 }
15231524
....@@ -1754,7 +1755,8 @@
17541755 bond->dev->addr_len);
17551756 ss.ss_family = bond->dev->type;
17561757 /* we don't care if it can't change its mac, best effort */
1757
- dev_set_mac_address(new_slave->dev, (struct sockaddr *)&ss);
1758
+ dev_set_mac_address(new_slave->dev, (struct sockaddr *)&ss,
1759
+ NULL);
17581760
17591761 bond_hw_addr_copy(new_slave->dev->dev_addr, tmp_addr,
17601762 new_slave->dev->addr_len);