hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/net/bonding/bond_netlink.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * drivers/net/bond/bond_netlink.c - Netlink interface for bonding
34 * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
45 * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
106 */
117
128 #include <linux/module.h>
....@@ -112,6 +108,7 @@
112108 [IFLA_BOND_AD_ACTOR_SYSTEM] = { .type = NLA_BINARY,
113109 .len = ETH_ALEN },
114110 [IFLA_BOND_TLB_DYNAMIC_LB] = { .type = NLA_U8 },
111
+ [IFLA_BOND_PEER_NOTIF_DELAY] = { .type = NLA_U32 },
115112 };
116113
117114 static const struct nla_policy bond_slave_policy[IFLA_BOND_SLAVE_MAX + 1] = {
....@@ -216,6 +213,14 @@
216213
217214 bond_opt_initval(&newval, downdelay);
218215 err = __bond_opt_set(bond, BOND_OPT_DOWNDELAY, &newval);
216
+ if (err)
217
+ return err;
218
+ }
219
+ if (data[IFLA_BOND_PEER_NOTIF_DELAY]) {
220
+ int delay = nla_get_u32(data[IFLA_BOND_PEER_NOTIF_DELAY]);
221
+
222
+ bond_opt_initval(&newval, delay);
223
+ err = __bond_opt_set(bond, BOND_OPT_PEER_NOTIF_DELAY, &newval);
219224 if (err)
220225 return err;
221226 }
....@@ -497,6 +502,7 @@
497502 nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_USER_PORT_KEY */
498503 nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_ACTOR_SYSTEM */
499504 nla_total_size(sizeof(u8)) + /* IFLA_BOND_TLB_DYNAMIC_LB */
505
+ nla_total_size(sizeof(u32)) + /* IFLA_BOND_PEER_NOTIF_DELAY */
500506 0;
501507 }
502508
....@@ -539,13 +545,17 @@
539545 bond->params.downdelay * bond->params.miimon))
540546 goto nla_put_failure;
541547
548
+ if (nla_put_u32(skb, IFLA_BOND_PEER_NOTIF_DELAY,
549
+ bond->params.peer_notif_delay * bond->params.miimon))
550
+ goto nla_put_failure;
551
+
542552 if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier))
543553 goto nla_put_failure;
544554
545555 if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
546556 goto nla_put_failure;
547557
548
- targets = nla_nest_start(skb, IFLA_BOND_ARP_IP_TARGET);
558
+ targets = nla_nest_start_noflag(skb, IFLA_BOND_ARP_IP_TARGET);
549559 if (!targets)
550560 goto nla_put_failure;
551561
....@@ -643,7 +653,7 @@
643653 if (!bond_3ad_get_active_agg_info(bond, &info)) {
644654 struct nlattr *nest;
645655
646
- nest = nla_nest_start(skb, IFLA_BOND_AD_INFO);
656
+ nest = nla_nest_start_noflag(skb, IFLA_BOND_AD_INFO);
647657 if (!nest)
648658 goto nla_put_failure;
649659
....@@ -674,6 +684,71 @@
674684 return -EMSGSIZE;
675685 }
676686
687
+static size_t bond_get_linkxstats_size(const struct net_device *dev, int attr)
688
+{
689
+ switch (attr) {
690
+ case IFLA_STATS_LINK_XSTATS:
691
+ case IFLA_STATS_LINK_XSTATS_SLAVE:
692
+ break;
693
+ default:
694
+ return 0;
695
+ }
696
+
697
+ return bond_3ad_stats_size() + nla_total_size(0);
698
+}
699
+
700
+static int bond_fill_linkxstats(struct sk_buff *skb,
701
+ const struct net_device *dev,
702
+ int *prividx, int attr)
703
+{
704
+ struct nlattr *nla __maybe_unused;
705
+ struct slave *slave = NULL;
706
+ struct nlattr *nest, *nest2;
707
+ struct bonding *bond;
708
+
709
+ switch (attr) {
710
+ case IFLA_STATS_LINK_XSTATS:
711
+ bond = netdev_priv(dev);
712
+ break;
713
+ case IFLA_STATS_LINK_XSTATS_SLAVE:
714
+ slave = bond_slave_get_rtnl(dev);
715
+ if (!slave)
716
+ return 0;
717
+ bond = slave->bond;
718
+ break;
719
+ default:
720
+ return -EINVAL;
721
+ }
722
+
723
+ nest = nla_nest_start_noflag(skb, LINK_XSTATS_TYPE_BOND);
724
+ if (!nest)
725
+ return -EMSGSIZE;
726
+ if (BOND_MODE(bond) == BOND_MODE_8023AD) {
727
+ struct bond_3ad_stats *stats;
728
+
729
+ if (slave)
730
+ stats = &SLAVE_AD_INFO(slave)->stats;
731
+ else
732
+ stats = &BOND_AD_INFO(bond).stats;
733
+
734
+ nest2 = nla_nest_start_noflag(skb, BOND_XSTATS_3AD);
735
+ if (!nest2) {
736
+ nla_nest_end(skb, nest);
737
+ return -EMSGSIZE;
738
+ }
739
+
740
+ if (bond_3ad_stats_fill(skb, stats)) {
741
+ nla_nest_cancel(skb, nest2);
742
+ nla_nest_end(skb, nest);
743
+ return -EMSGSIZE;
744
+ }
745
+ nla_nest_end(skb, nest2);
746
+ }
747
+ nla_nest_end(skb, nest);
748
+
749
+ return 0;
750
+}
751
+
677752 struct rtnl_link_ops bond_link_ops __read_mostly = {
678753 .kind = "bond",
679754 .priv_size = sizeof(struct bonding),
....@@ -688,6 +763,8 @@
688763 .get_num_tx_queues = bond_get_num_tx_queues,
689764 .get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number
690765 as for TX queues */
766
+ .fill_linkxstats = bond_fill_linkxstats,
767
+ .get_linkxstats_size = bond_get_linkxstats_size,
691768 .slave_maxtype = IFLA_BOND_SLAVE_MAX,
692769 .slave_policy = bond_slave_policy,
693770 .slave_changelink = bond_slave_changelink,