From nobody Mon Oct 6 06:36:18 2025 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 009D620127B; Thu, 24 Jul 2025 08:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753345030; cv=none; b=H3jvqYpN3rv6AICyuYJqEQYOoYNjpEltf0VVByVe2Kl9LdVLW6MxJPPuV7L3WL3Ej1Zl6mFJ12E6EbUIWaaGXp7WsWacL7sxY4BpkeSXg07bIiSFwpvjgnAAMhajg6Ko0w9VOF8ZpkpwBwVsjp7YIcG7MdC9prv6jdcvLbv/fIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753345030; c=relaxed/simple; bh=Xl0w1IpxiSoHGG+zVHXmZ/2nRC2G/Xtt3KJMC/MMALo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PziwqQiRaJKP9oBLyR/4BV5g7eyTD3RfSZiLZ3QfoYyPVWiM9++1uM3B525aENja6qzSq9QRB+1BAfHZ/NIMXiDTvo5Ccv6oOe+/ZtAmESkRmTfMFkdLkFHCBYRMjGGaD762xnIQHvsOsoJLMXJIwaD679Iw1/+oM+I9kJnDbV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hf6pOeWY; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hf6pOeWY" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-b1fd59851baso576437a12.0; Thu, 24 Jul 2025 01:17:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753345028; x=1753949828; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c7cWMJvMn47eS4XEI88F/UAG7iToiVpJXFUIoi55Q00=; b=Hf6pOeWYpoRzC4QPUBNU3DJ5wmdxg3TFNOlfMKChcGqvfV29jwJY+lJaxaP/XtuFuA NigIxLCMXONAHGCqlY3rfNPsiRtEQZz+pAcO/b7ca6AmrhNOjMqvPW9aI24LTnA3yQOi HKG9TH5f5fXJq0DhN677G6C5amIA+Z13aTPAd7CPv76WMptafupYia4SB4sYYGOpEHVv PH8/d/mUgvJMXeLig9f1QFQ/rgKwJtv/vBbcBTQ60aPsWDuYAAYEmVwni9/Cq1sCJBvZ bpjqRX1F/mGcgn0IKYInqtfDEOeYXLbKQYed/2jTQGxKFfxlA8+cnDXBdIVsRW6MsD+Z USsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753345028; x=1753949828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c7cWMJvMn47eS4XEI88F/UAG7iToiVpJXFUIoi55Q00=; b=vCx4pBHImER1zHcOUtm9r17yGvSCwJ5pbSbSVBLyM8cmRaVnS0/iOHXlwf47hNxQ5R lqBmIKzPrbN4FX52x6yMDJTb10YJD3WjAJw/Vt7szKnsMeOdY+YRc8fN1aJslOUcgo3Q kWLpx2mBVD2tamrLEvBrNs8DW+Yqa4T79venrQ/Hlc3PugpQKWhJYhEWY5Wvq9BCVJlc A6m3XJ79W8I0DZiAnUL/s1Q7TAH1DDGwqsk6HN8ICr1KV6kUjI7lb+1gbiRpsQtcb8hE QH4i7+Kos61FSk/jhw+kTOJiq5zqVJZtaRvMvijE6dTpSDvFUArtJbMMSJeOUrtHbqx4 VmFw== X-Forwarded-Encrypted: i=1; AJvYcCU7BssCENU/M0lwe4qwGsKq5uR32PSvH6KmXjKnzpG2cFkkFh5HADTw61o44gGmdNFcKQ74lgyZQmw=@vger.kernel.org, AJvYcCUG71aT8fh+faSB5dws8o8E08sjZRw4AFUQvMxA25uEAH7aUAAf/nkQtoA7f067zp7EmUdBGgzuYTfdtMc1vSeg@vger.kernel.org, AJvYcCWayfHZVwZDzRR+1SW1cln3sWNEIpRmfaJHLP26FAiOX5gNvK4MdjcYX2l3RdLyAZ5QzMc2aX1VgfhC/8tD@vger.kernel.org X-Gm-Message-State: AOJu0Yz5PZNrp2c4Q27zghTr0mngNywJf+QzNXViKetL1gR3J8Iv9tTh nk6tZB7HxEzjoLunTj43UyYPkjMYXq5Z1/r68KsMnLX0TA/PSxxleiTx7aaWOd5X X-Gm-Gg: ASbGncsptwaBjeudNKwwirYKKylL5dC1FCYJrjJStOSQpyd35P2/y0Ubnf5fziAphmw H3c/YyyLfWjre9WZ7UgrXDwyjNXr3omgn4OWzOjyMNAAxNNGtC4rli/lWYn7pX6j0sXmS5mv0Ib 8E2SCgfvsXdsEiHorIcPAnw/Lt73GHuU/xvan41Uy1LauEY9MyFy46yhdFqiHpoHnb2OJD+8Rdw Z+F7xheen6d7YhWcam8rrkuRtkWha8u9qxgtrQVrNnhZc8oPTgv/rOC9nDPfw0O4AElA88Fj9Gt jdZs+I71TZXZccUnyfXZJwR3F/qmxinbMEu40UYbYzXxcu4zsCTfsFke7AquTql3Toc8hiQRDTX wL6BAi2SjMrxG6M5b0Xri6ua28JPRnE1osF7FJTolp+ZaYdw= X-Google-Smtp-Source: AGHT+IHXcLv2NnmgB7Lyqg/CA9F/BVNQ5fO2HiaSvawtrYEm9cplDWfhJeb2KgMlBinDg3EAVERjmg== X-Received: by 2002:a05:6a20:7349:b0:232:3141:5879 with SMTP id adf61e73a8af0-23d4912949amr8688192637.33.1753345027967; Thu, 24 Jul 2025 01:17:07 -0700 (PDT) Received: from localhost.localdomain ([209.132.188.88]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-761adb7bbeesm1074704b3a.24.2025.07.24.01.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jul 2025 01:17:07 -0700 (PDT) From: Hangbin Liu To: netdev@vger.kernel.org Cc: Jay Vosburgh , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Nikolay Aleksandrov , Simon Horman , Shuah Khan , Jonathan Corbet , Petr Machata , Amit Cohen , Vladimir Oltean , Alessandro Zanni , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Hangbin Liu Subject: [PATCH net-next 1/3] bonding: add support for per-port LACP actor priority Date: Thu, 24 Jul 2025 08:16:30 +0000 Message-ID: <20250724081632.12921-2-liuhangbin@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250724081632.12921-1-liuhangbin@gmail.com> References: <20250724081632.12921-1-liuhangbin@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a new option ad_actor_port_prio, allowing users to set the actor port priority on a per-port basis in LACPDU. This priority can be used in future enhancements to influence aggregator selection via ad_select policy. Signed-off-by: Hangbin Liu --- Documentation/networking/bonding.rst | 9 +++++++ drivers/net/bonding/bond_3ad.c | 2 ++ drivers/net/bonding/bond_netlink.c | 16 +++++++++++++ drivers/net/bonding/bond_options.c | 35 ++++++++++++++++++++++++++++ include/net/bond_3ad.h | 1 + include/net/bond_options.h | 1 + include/uapi/linux/if_link.h | 1 + 7 files changed, 65 insertions(+) diff --git a/Documentation/networking/bonding.rst b/Documentation/networkin= g/bonding.rst index a4c1291d2561..5e105e7ac8e6 100644 --- a/Documentation/networking/bonding.rst +++ b/Documentation/networking/bonding.rst @@ -193,6 +193,15 @@ ad_actor_sys_prio This parameter has effect only in 802.3ad mode and is available through SysFs interface. =20 +ad_actor_port_prio + + In an AD system, this specifies the port priority. The allowed range + is 1 - 65535. If the value is not specified, it takes 255 as the + default value. + + This parameter has effect only in 802.3ad mode and is available through + netlink interface. + ad_actor_system =20 In an AD system, this specifies the mac-address for the actor in diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index c6807e473ab7..4a1b2f01fe37 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c @@ -436,6 +436,7 @@ static void __ad_actor_update_port(struct port *port) =20 port->actor_system =3D BOND_AD_INFO(bond).system.sys_mac_addr; port->actor_system_priority =3D BOND_AD_INFO(bond).system.sys_priority; + port->actor_port_priority =3D SLAVE_AD_INFO(port->slave)->port_priority; } =20 /* Conversions */ @@ -2197,6 +2198,7 @@ void bond_3ad_bind_slave(struct slave *slave) port->actor_admin_port_key =3D bond->params.ad_user_port_key << 6; ad_update_actor_keys(port, false); /* actor system is the bond's system */ + SLAVE_AD_INFO(slave)->port_priority =3D port->actor_port_priority; __ad_actor_update_port(port); /* tx timer(to verify that no more than MAX_TX_IN_SECOND * lacpdu's are sent in one second) diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_= netlink.c index ac5e402c34bc..ad91b93cbdac 100644 --- a/drivers/net/bonding/bond_netlink.c +++ b/drivers/net/bonding/bond_netlink.c @@ -28,6 +28,7 @@ static size_t bond_get_slave_size(const struct net_device= *bond_dev, nla_total_size(sizeof(u8)) + /* IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE= */ nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_ST= ATE */ nla_total_size(sizeof(s32)) + /* IFLA_BOND_SLAVE_PRIO */ + nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_AD_ACTOR_PORT_PRIO */ 0; } =20 @@ -77,6 +78,10 @@ static int bond_fill_slave_info(struct sk_buff *skb, ad_port->partner_oper.port_state)) goto nla_put_failure; } + + if (nla_put_u16(skb, IFLA_BOND_SLAVE_AD_ACTOR_PORT_PRIO, + SLAVE_AD_INFO(slave)->port_priority)) + goto nla_put_failure; } =20 return 0; @@ -129,6 +134,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MA= X + 1] =3D { static const struct nla_policy bond_slave_policy[IFLA_BOND_SLAVE_MAX + 1] = =3D { [IFLA_BOND_SLAVE_QUEUE_ID] =3D { .type =3D NLA_U16 }, [IFLA_BOND_SLAVE_PRIO] =3D { .type =3D NLA_S32 }, + [IFLA_BOND_SLAVE_AD_ACTOR_PORT_PRIO] =3D { .type =3D NLA_U16 }, }; =20 static int bond_validate(struct nlattr *tb[], struct nlattr *data[], @@ -179,6 +185,16 @@ static int bond_slave_changelink(struct net_device *bo= nd_dev, return err; } =20 + if (data[IFLA_BOND_SLAVE_AD_ACTOR_PORT_PRIO]) { + u16 ad_prio =3D nla_get_u16(data[IFLA_BOND_SLAVE_AD_ACTOR_PORT_PRIO]); + + bond_opt_slave_initval(&newval, &slave_dev, ad_prio); + err =3D __bond_opt_set(bond, BOND_OPT_AD_ACTOR_PORT_PRIO, &newval, + data[IFLA_BOND_SLAVE_AD_ACTOR_PORT_PRIO], extack); + if (err) + return err; + } + return 0; } =20 diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_= options.c index 91893c29b899..2b8606b4e4f5 100644 --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -79,6 +79,8 @@ static int bond_option_tlb_dynamic_lb_set(struct bonding = *bond, const struct bond_opt_value *newval); static int bond_option_ad_actor_sys_prio_set(struct bonding *bond, const struct bond_opt_value *newval); +static int bond_option_ad_actor_port_prio_set(struct bonding *bond, + const struct bond_opt_value *newval); static int bond_option_ad_actor_system_set(struct bonding *bond, const struct bond_opt_value *newval); static int bond_option_ad_user_port_key_set(struct bonding *bond, @@ -221,6 +223,12 @@ static const struct bond_opt_value bond_ad_actor_sys_p= rio_tbl[] =3D { { NULL, -1, 0}, }; =20 +static const struct bond_opt_value bond_ad_actor_port_prio_tbl[] =3D { + { "minval", 1, BOND_VALFLAG_MIN}, + { "maxval", 65535, BOND_VALFLAG_MAX}, + { NULL, -1, 0}, +}; + static const struct bond_opt_value bond_ad_user_port_key_tbl[] =3D { { "minval", 0, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT}, { "maxval", 1023, BOND_VALFLAG_MAX}, @@ -476,6 +484,13 @@ static const struct bond_option bond_opts[BOND_OPT_LAS= T] =3D { .values =3D bond_ad_actor_sys_prio_tbl, .set =3D bond_option_ad_actor_sys_prio_set, }, + [BOND_OPT_AD_ACTOR_PORT_PRIO] =3D { + .id =3D BOND_OPT_AD_ACTOR_PORT_PRIO, + .name =3D "ad_actor_port_prio", + .unsuppmodes =3D BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), + .values =3D bond_ad_actor_port_prio_tbl, + .set =3D bond_option_ad_actor_port_prio_set, + }, [BOND_OPT_AD_ACTOR_SYSTEM] =3D { .id =3D BOND_OPT_AD_ACTOR_SYSTEM, .name =3D "ad_actor_system", @@ -1793,6 +1808,26 @@ static int bond_option_ad_actor_sys_prio_set(struct = bonding *bond, return 0; } =20 +static int bond_option_ad_actor_port_prio_set(struct bonding *bond, + const struct bond_opt_value *newval) +{ + struct slave *slave; + + slave =3D bond_slave_get_rtnl(newval->slave_dev); + if (!slave) { + netdev_dbg(bond->dev, "%s called on NULL slave\n", __func__); + return -ENODEV; + } + + netdev_dbg(newval->slave_dev, "Setting ad_actor_port_prio to %llu\n", + newval->value); + + SLAVE_AD_INFO(slave)->port_priority =3D newval->value; + bond_3ad_update_ad_actor_settings(bond); + + return 0; +} + static int bond_option_ad_actor_system_set(struct bonding *bond, const struct bond_opt_value *newval) { diff --git a/include/net/bond_3ad.h b/include/net/bond_3ad.h index 2053cd8e788a..bf551ca70359 100644 --- a/include/net/bond_3ad.h +++ b/include/net/bond_3ad.h @@ -274,6 +274,7 @@ struct ad_slave_info { struct port port; /* 802.3ad port structure */ struct bond_3ad_stats stats; u16 id; + u16 port_priority; }; =20 static inline const char *bond_3ad_churn_desc(churn_state_t state) diff --git a/include/net/bond_options.h b/include/net/bond_options.h index 18687ccf0638..4aee1935e0e7 100644 --- a/include/net/bond_options.h +++ b/include/net/bond_options.h @@ -77,6 +77,7 @@ enum { BOND_OPT_NS_TARGETS, BOND_OPT_PRIO, BOND_OPT_COUPLED_CONTROL, + BOND_OPT_AD_ACTOR_PORT_PRIO, BOND_OPT_LAST }; =20 diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 3ad2d5d98034..79bcbbc264a7 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -1562,6 +1562,7 @@ enum { IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE, IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE, IFLA_BOND_SLAVE_PRIO, + IFLA_BOND_SLAVE_AD_ACTOR_PORT_PRIO, __IFLA_BOND_SLAVE_MAX, }; =20 --=20 2.46.0 From nobody Mon Oct 6 06:36:18 2025 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F37B220127B; Thu, 24 Jul 2025 08:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753345037; cv=none; b=PVxIlcbKzBNlSdxKmDrUbiu/9zs+3BtegbR+xHF/bmoPMrmGRQANrZAofxdiQB39bZjEmWkCILM93QHdkap6DbVjEjfgzz8Ejjgmu/MjDdAJNzGnzg0WjTZvZZ0TPD4/Z4O5Vis2YuFmm97DBW7vlRWqXUjMqy/Xn3CJ+XjRo9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753345037; c=relaxed/simple; bh=X9luu04fMOJ7fBr1sPQ+y9wsUOVz6Vo6plU++In+zA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MzXXOjZBniMIPNTVM8mxRs9sibXyhQRLsoZzZ60DN3YARw+btJfTPjAx40VpA8gIM+y83GXEu5NX6p6Z9eNT+xM9flyNRrBV0OhFgsHwRhTM22LA5aTQ/WT9UbjkidXIgfIsdIBRg8Fe5GAuUx1OXWJn/XmQWWvWJT8yYDjb12Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MmGQMxas; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MmGQMxas" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7426c44e014so619452b3a.3; Thu, 24 Jul 2025 01:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753345035; x=1753949835; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O6LMsfHLIpKIArigfFgHi7q/1uwSP7ojeqycHGuMcPU=; b=MmGQMxaspH9z79AGX3n/BFwdxLZDbLeq9P9JhrDXVEGtQe0zTqY2/Fuhr9h3s/SFG8 0cWiiXHKqisOVkxbeRGu8xU63ZdOh4Cnymp6uySZDJp5jGFaawQRwxpSUizVSapDvgJo C6FRSCyAJqZEm4HNkLJAw2sVGSOSCEQjlYDOzwVOCVsS0l5Kq80fuHtjdJlN4pnJz4Co hOOloRXKexTFlNLlC6vMFX2fgbzl7LoJRw7Nwq3rx/jgs4ad2vPyJ/5D+6PZw2j8w+CZ QPHrEU96xnoHty0udORv6W7WIkf2KPDLml9g9vyxqI3vy7FhUwzMGKUjwDdoBKYAw46x jycQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753345035; x=1753949835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O6LMsfHLIpKIArigfFgHi7q/1uwSP7ojeqycHGuMcPU=; b=BJwku7uYyVt3bqudx8D6jWNvxAUmVpHOLvePUGhnUHXOnOB7/RjJf5MfkK1MfpxyzN xhcAe+p1SKlhmYq4kvFXpSIrrDRDSUphEB2fIaz0J2omKpqHgdZpyuKWOIIWscfPmUh/ cP784o+c66SuultA9tb639lKnUo6p+axZCoswb3eeo6SRZhcCM1O2xDgFhc+G2JDrMdz 9kGnSTQtnrfaPUS3rlMXn6Yn+PYyExpffMOS4hMzbEu3vCcLm8b5evvOyVWIv9iWvIYu ppyj4htE6iswE6xWc/TlCfMCH0LF2PrBaDeyXt70vpxfgIIKRo9EYgI3cys7kEw+SjP4 ZfpQ== X-Forwarded-Encrypted: i=1; AJvYcCU5mjbj3kigRxZcng3B75y48xTp6kvf6iViX+Ky+x2OxdVrEYJn7gw53xQQZL8Nsv/cDrwzBQuaDoZ4coNw@vger.kernel.org, AJvYcCVTDrmh9Ops+fMFLxIPv+oyHUlyeOkgggKIwi/xQ7l54pupwghOhcK25PS7+SovL0xESKDcIZ/9KfRVr6H/eh2w@vger.kernel.org, AJvYcCVoiykngIkCohndeSfBMWJicn4W3WNgV7w+mXe6WozZ6V4LYuBBAq3OuqRLZOi0KoS0YKYVcd7umyU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1EmE7RvnqZqgzZoNudryW1VtXcq8MlX9F+e7lyT6QL9t1hZUL aTJKEdZxnrWuch27RPV9GfiNyFlD5iMqAL/XMPsuQ1DXH3yPZLX0mmXyYR7fAkQ3 X-Gm-Gg: ASbGncvyt0LbC2mcAAIpwrQOdIG68ZGfGFI8MU27yTIRBN0uJGXLr7KdTe3EP1jx4AQ z+p5jIQzanczxNd0TL4ft7S5xmg2gXZ7aJD59lqqNvmteAyg6OeP9U8Bb4PBydhHuX2KVWSuiM4 t92WjQzvv9cqRZl/xliTdLN0EoYwJOxWiKIXb4uC69B3UKnMwnukjITo/ZW2FURTO6DGoFDp0LA 5cYoU5O4eQahGd566fbe8kV0LahSJm1HJBXGNwcKeJASb5OITcz03UH90ZUj9e2VfexGUHgezII f3Lrd6YORuPgNA5rr4C7fbIX0U7SwCfvugMZ5LbhsTnjWoJ5dFtdC0uB1ysVPODIJYaj6UzlrJQ ldfjh5fHWblQzwmuFvdLCrA+wlDEgLh80s8VbD2dvQCkdVfI= X-Google-Smtp-Source: AGHT+IGTDblVYTvdY+9K+d2w6/YOegYxn76AqrB/KFLUQIuMVH8krKT1K6So44Imi3w1nWhGAtguWw== X-Received: by 2002:a05:6a20:3d83:b0:21f:a6c9:34d with SMTP id adf61e73a8af0-23d48fec363mr9232902637.1.1753345034945; Thu, 24 Jul 2025 01:17:14 -0700 (PDT) Received: from localhost.localdomain ([209.132.188.88]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-761adb7bbeesm1074704b3a.24.2025.07.24.01.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jul 2025 01:17:14 -0700 (PDT) From: Hangbin Liu To: netdev@vger.kernel.org Cc: Jay Vosburgh , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Nikolay Aleksandrov , Simon Horman , Shuah Khan , Jonathan Corbet , Petr Machata , Amit Cohen , Vladimir Oltean , Alessandro Zanni , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Hangbin Liu Subject: [PATCH net-next 2/3] bonding: support aggregator selection based on port priority Date: Thu, 24 Jul 2025 08:16:31 +0000 Message-ID: <20250724081632.12921-3-liuhangbin@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250724081632.12921-1-liuhangbin@gmail.com> References: <20250724081632.12921-1-liuhangbin@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that per-port actor priority is supported via ad_actor_port_prio, enable a new ad_select policy to choose the aggregator based on port priority. This allows users to influence aggregator selection by assigning higher or lower priorities to individual ports. Signed-off-by: Hangbin Liu --- Documentation/networking/bonding.rst | 9 ++++++++- drivers/net/bonding/bond_3ad.c | 29 ++++++++++++++++++++++++++++ drivers/net/bonding/bond_options.c | 1 + include/net/bond_3ad.h | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/bonding.rst b/Documentation/networkin= g/bonding.rst index 5e105e7ac8e6..a234ec12ece7 100644 --- a/Documentation/networking/bonding.rst +++ b/Documentation/networking/bonding.rst @@ -250,7 +250,14 @@ ad_select ports (slaves). Reselection occurs as described under the "bandwidth" setting, above. =20 - The bandwidth and count selection policies permit failover of + prio or 3 + + The active aggregator is chosen by the highest total sum of + actor port priorities across its active ports. Note this + priority is ad_actor_port_prio, not per port prio, which is + used for primary reselect. + + The bandwidth, count and prio selection policies permit failover of 802.3ad aggregations when partial failure of the active aggregator occurs. This keeps the aggregator with the highest availability (either in bandwidth or in number of ports) active at all times. diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index 4a1b2f01fe37..6f8a406ed34a 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c @@ -747,6 +747,20 @@ static int __agg_active_ports(struct aggregator *agg) return active; } =20 +static unsigned int __agg_ports_priority(struct aggregator *agg) +{ + struct port *port; + unsigned int prio =3D 0; + + for (port =3D agg->lag_ports; port; + port =3D port->next_port_in_aggregator) { + if (port->is_enabled) + prio +=3D port->actor_port_priority; + } + + return prio; +} + /** * __get_agg_bandwidth - get the total bandwidth of an aggregator * @aggregator: the aggregator we're looking at @@ -1695,6 +1709,9 @@ static struct aggregator *ad_agg_selection_test(struc= t aggregator *best, * BOND_AD_COUNT: Select by count of ports. If count is equal, * select by bandwidth. * + * BOND_AD_PRIO: Select by total priority of ports. If priority + * is equal, select by count. + * * BOND_AD_STABLE, BOND_AD_BANDWIDTH: Select by bandwidth. */ if (!best) @@ -1713,6 +1730,14 @@ static struct aggregator *ad_agg_selection_test(stru= ct aggregator *best, return best; =20 switch (__get_agg_selection_mode(curr->lag_ports)) { + case BOND_AD_PRIO: + if (__agg_ports_priority(curr) > __agg_ports_priority(best)) + return curr; + + if (__agg_ports_priority(curr) < __agg_ports_priority(best)) + return best; + + fallthrough; case BOND_AD_COUNT: if (__agg_active_ports(curr) > __agg_active_ports(best)) return curr; @@ -1778,6 +1803,10 @@ static int agg_device_up(const struct aggregator *ag= g) * (slaves), and reselect whenever a link state change takes place or the * set of slaves in the bond changes. * + * BOND_AD_PRIO: select the aggregator with highest total priority of ports + * (slaves), and reselect whenever a link state change takes place or the + * set of slaves in the bond changes. + * * FIXME: this function MUST be called with the first agg in the bond, or * __get_active_agg() won't work correctly. This function should be better * called with the bond itself, and retrieve the first agg from it. diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_= options.c index 2b8606b4e4f5..708ca1f18a00 100644 --- a/drivers/net/bonding/bond_options.c +++ b/drivers/net/bonding/bond_options.c @@ -163,6 +163,7 @@ static const struct bond_opt_value bond_ad_select_tbl[]= =3D { { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT}, { "bandwidth", BOND_AD_BANDWIDTH, 0}, { "count", BOND_AD_COUNT, 0}, + { "prio", BOND_AD_PRIO, 0}, { NULL, -1, 0}, }; =20 diff --git a/include/net/bond_3ad.h b/include/net/bond_3ad.h index bf551ca70359..34495df965f0 100644 --- a/include/net/bond_3ad.h +++ b/include/net/bond_3ad.h @@ -26,6 +26,7 @@ enum { BOND_AD_STABLE =3D 0, BOND_AD_BANDWIDTH =3D 1, BOND_AD_COUNT =3D 2, + BOND_AD_PRIO =3D 3, }; =20 /* rx machine states(43.4.11 in the 802.3ad standard) */ --=20 2.46.0 From nobody Mon Oct 6 06:36:18 2025 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE46E275108; Thu, 24 Jul 2025 08:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753345044; cv=none; b=Q3XlFHo1XYcdG2yjo1848g48VQfBX1vEP93B/uT76c7uiEWo8oTZqm8I3f5z4uv55QUVJmjy4zJLrLBvprb/wzC4S+qMjUKtdCmb5iYrpixvxL1HYpCa9sHXm5C51U1k2oBWKmQ11QpF14Jk+Pwd6ZdIe0YUnMneDe52iS61+sU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753345044; c=relaxed/simple; bh=MTLT+lV2JBdNmKXaYJ4ZG4ljY/MiMAjjGFtyVb/rW0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ccgqWAoZA0uXlOPEgNEr60CiOwbHm8W/y/XSILdVIQ7Qtiy9x4etgR3CZBYyS1eId5hT+4QHwuniuKiYiGVE2JUipf/OMeksY6O24dayWQwNgJL4Onwjpk0rmRNd1lFLg6fqe7TzzVc25lrkYjs2gwvmzKk2BJGrwj6KiPZToVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=e7ixM7ZV; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e7ixM7ZV" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-75b5be236deso661534b3a.0; Thu, 24 Jul 2025 01:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753345042; x=1753949842; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jij+PHwZT95YPs+MTYNdJ41MK7aCYN1i16ExsqGoWoA=; b=e7ixM7ZVlAjk5muFRDwodYOauJ05EXCL3pSZmMfUSNtl8ZwkDp26SgJoNGd8gx9YyH gWqE0Eh1IEfy+wwV3rm0FyGtd6rGsoJNzt4BR9GV7V3PoY73jWgkBlkZXXFJtYukdHFz VHs7jWo/lRHVDFoCyEKf+ruKSYPCVLcwPdRFelUKHyGgZykin83QaMYW1fJwOuDICEYb d+1YQb5rCWzz6beRGP3kco/V72KhYtXycHCNuP9b/zoiQgS2V4xCd4mtVTLZsp/S9rxw NypvWZ2ZDCX8UgaaDcxQKp0E+AszQpgPjIKAWztA1E1AabH2BWU+a21LsJrN0fdC07LM DRPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753345042; x=1753949842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jij+PHwZT95YPs+MTYNdJ41MK7aCYN1i16ExsqGoWoA=; b=NykoKrv3uXh6gVWMRvoo3UUzd27J8YH9H0s21YbKb4jmXuaxTLS7cHzrTaAfm9mha+ U8Fq7oFE6z/yN8rf8qs/b3fOqrD/m2Va7xuBsrp3YdTOpTzmwlXlNmXAuAu+bMy1O8n1 Zmd0y8Kf+t7BQ15nG6f5DJefRuh5n0bdwI9BKFUxx+4uQGUJaaOAeIL+Sljlggd7fD5W UZ4atULEWKN56sWGNZ2ajewSutz2VRJxhGALhHVBGImrcc22jadz2sMNUHsxowTh4yQU K7B7ppzt81hDCNNp2Mo43E2ZMMDnZsvckBBSa9Dw9O3UjaK6sDN73PsXyZRliJRH7U4K f7hw== X-Forwarded-Encrypted: i=1; AJvYcCWqoDyY/vBCZuidqgSWcvIAIQF67aUTZ8In4TtwQ9Zo7pazLbi9++2qMwLI+pLOnL24ALEoGpbaQkE=@vger.kernel.org, AJvYcCX7acDiWVeuuE0068cStlb85lCDgEtCQbXDBiE5s46YD6PufWMeJZDFCvDl9QUbCm0ktUCpOUDL7UtGBdh3/8Ca@vger.kernel.org, AJvYcCXhOEDP6jso1D2oExynthQ4QCbWg0uMpJ5BpoRsc/OMAjLedg19GxpyS5WLNDlNHh3S632E5uqrcDLDSRkc@vger.kernel.org X-Gm-Message-State: AOJu0Ywy9OZEQ07XSqatCxtWnpZf0MtRIxn3KLVPCmJPVLxEfamjk149 nJqlO6QnVMQ2q5HrJBNuHGMBXVShSYMKeMWvUS/UDBwM4lXF8j38akL2DVQ14Ipy X-Gm-Gg: ASbGncvRGwiCpRRfDpUa7symkNM7g0rqPMNVdcatYpHjhp0iHd/aaour0xPcZZOlWN0 R2u5ZkiEycgl/DosWaLg8mrUlaJj+fMh0wyeSnGpjm5vI9yJg25g5cEzaUv9h+HVBCMw587b5qi 69W/I7+ABVa+YpWd8+ugp94zbTRDFVCDTf9iGU0qFPiqil+EVRBwRcniU85q/zBwHKY3kz5Aqu7 c19oFIkZ03B1N6MHiDo97IfOdLH5xVe/hIRq8jOn+VD34ZwxQ7YKZDrdVLW1Vi1VsOtiS+45SAB 4EcZ357k4Cb2v4uugQbpgJ/1ClxjkvP630GsHp4uF0KfCDBwqRchh9DhNgPDoyq/wOKzMJpP0po g/RHWfSz1A2nogaTTekr79x2MlO3+/rOjhzxrJxe7vBcZbVk= X-Google-Smtp-Source: AGHT+IG7o3xn5h0i2rZGdHetDDcR0Hu2ewY93q2gD+ugrQIMAHSSbaUTHJHe7hr7X3bCbDKiAOPqSA== X-Received: by 2002:a05:6a00:a589:b0:747:aa79:e2f5 with SMTP id d2e1a72fcca58-76031771dd1mr8605525b3a.0.1753345041938; Thu, 24 Jul 2025 01:17:21 -0700 (PDT) Received: from localhost.localdomain ([209.132.188.88]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-761adb7bbeesm1074704b3a.24.2025.07.24.01.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jul 2025 01:17:21 -0700 (PDT) From: Hangbin Liu To: netdev@vger.kernel.org Cc: Jay Vosburgh , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Nikolay Aleksandrov , Simon Horman , Shuah Khan , Jonathan Corbet , Petr Machata , Amit Cohen , Vladimir Oltean , Alessandro Zanni , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Hangbin Liu Subject: [PATCH net-next 3/3] selftests: bonding: add test for LACP actor port priority Date: Thu, 24 Jul 2025 08:16:32 +0000 Message-ID: <20250724081632.12921-4-liuhangbin@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250724081632.12921-1-liuhangbin@gmail.com> References: <20250724081632.12921-1-liuhangbin@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a selftest to verify that per-port actor priority (ad_actor_port_prio) is correctly applied and affects aggregator selection as expected. Move cmd_jq from forwarding/lib.sh to net/lib.sh. Signed-off-by: Hangbin Liu --- .../selftests/drivers/net/bonding/Makefile | 3 +- .../drivers/net/bonding/bond_lacp_prio.sh | 73 +++++++++++++++++++ tools/testing/selftests/net/forwarding/lib.sh | 24 ------ tools/testing/selftests/net/lib.sh | 24 ++++++ 4 files changed, 99 insertions(+), 25 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/bonding/bond_lacp_p= rio.sh diff --git a/tools/testing/selftests/drivers/net/bonding/Makefile b/tools/t= esting/selftests/drivers/net/bonding/Makefile index 2b10854e4b1e..32617a834a6b 100644 --- a/tools/testing/selftests/drivers/net/bonding/Makefile +++ b/tools/testing/selftests/drivers/net/bonding/Makefile @@ -10,7 +10,8 @@ TEST_PROGS :=3D \ mode-2-recovery-updelay.sh \ bond_options.sh \ bond-eth-type-change.sh \ - bond_macvlan_ipvlan.sh + bond_macvlan_ipvlan.sh \ + bond_lacp_prio.sh =20 TEST_FILES :=3D \ lag_lib.sh \ diff --git a/tools/testing/selftests/drivers/net/bonding/bond_lacp_prio.sh = b/tools/testing/selftests/drivers/net/bonding/bond_lacp_prio.sh new file mode 100755 index 000000000000..a3f939d12143 --- /dev/null +++ b/tools/testing/selftests/drivers/net/bonding/bond_lacp_prio.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Testing if bond lacp per port priority works + +lib_dir=3D$(dirname "$0") +# shellcheck disable=3DSC1091 +source "$lib_dir"/../../../net/lib.sh + +# create client, switch, backup switch netns +setup_ns c_ns s_ns b_ns +defer cleanup_all_ns + +# setup links +# shellcheck disable=3DSC2154 +ip -n "${c_ns}" link add eth0 type veth peer name eth0 netns "${s_ns}" +ip -n "${c_ns}" link add eth1 type veth peer name eth1 netns "${s_ns}" +# shellcheck disable=3DSC2154 +ip -n "${c_ns}" link add eth2 type veth peer name eth0 netns "${b_ns}" +ip -n "${c_ns}" link add eth3 type veth peer name eth1 netns "${b_ns}" + +ip -n "${c_ns}" link add bond0 type bond mode 802.3ad miimon 100 lacp_rate= fast ad_select prio +ip -n "${s_ns}" link add bond0 type bond mode 802.3ad miimon 100 lacp_rate= fast +ip -n "${b_ns}" link add bond0 type bond mode 802.3ad miimon 100 lacp_rate= fast + +ip -n "${c_ns}" link set eth0 master bond0 +ip -n "${c_ns}" link set eth1 master bond0 +ip -n "${c_ns}" link set eth2 master bond0 +ip -n "${c_ns}" link set eth3 master bond0 +ip -n "${s_ns}" link set eth0 master bond0 +ip -n "${s_ns}" link set eth1 master bond0 +ip -n "${b_ns}" link set eth0 master bond0 +ip -n "${b_ns}" link set eth1 master bond0 + +ip -n "${c_ns}" link set bond0 up +ip -n "${s_ns}" link set bond0 up +ip -n "${b_ns}" link set bond0 up + +# set ad actor port priority, default 255 +ip -n "${c_ns}" link set eth0 type bond_slave ad_actor_port_prio 1000 +prio=3D$(cmd_jq "ip -n ${c_ns} -d -j link show eth0" ".[].linkinfo.info_sl= ave_data.ad_actor_port_prio") +[ "$prio" -ne 1000 ] && RET=3D1 +ip -n "${c_ns}" link set eth2 type bond_slave ad_actor_port_prio 10 +prio=3D$(cmd_jq "ip -n ${c_ns} -d -j link show eth2" ".[].linkinfo.info_sl= ave_data.ad_actor_port_prio") +[ "$prio" -ne 10 ] && RET=3D1 +log_test "bond 802.3ad" "ad_actor_port_prio setting" + +# Trigger link state change to reselect the aggregator +ip -n "${c_ns}" link set eth1 down +ip -n "${c_ns}" link set eth1 up +# the active agg should be connect to switch +bond_agg_id=3D$(cmd_jq "ip -n ${c_ns} -d -j link show bond0" ".[].linkinfo= .info_data.ad_info.aggregator") +eth0_agg_id=3D$(cmd_jq "ip -n ${c_ns} -d -j link show eth0" ".[].linkinfo.= info_slave_data.ad_aggregator_id") +if [ "${bond_agg_id}" -ne "${eth0_agg_id}" ]; then + RET=3D1 +fi + +# Change the actor port prio and re-test +ip -n "${c_ns}" link set eth0 type bond_slave ad_actor_port_prio 10 +ip -n "${c_ns}" link set eth2 type bond_slave ad_actor_port_prio 1000 +# Trigger link state change to reselect the aggregator +ip -n "${c_ns}" link set eth1 down +ip -n "${c_ns}" link set eth1 up +# now the active agg should be connect to backup switch +bond_agg_id=3D$(cmd_jq "ip -n ${c_ns} -d -j link show bond0" ".[].linkinfo= .info_data.ad_info.aggregator") +eth2_agg_id=3D$(cmd_jq "ip -n ${c_ns} -d -j link show eth2" ".[].linkinfo.= info_slave_data.ad_aggregator_id") +# shellcheck disable=3DSC2034 +if [ "${bond_agg_id}" -ne "${eth2_agg_id}" ]; then + RET=3D1 +fi +log_test "bond 802.3ad" "ad_actor_port_prio switch" + +exit "${EXIT_STATUS}" diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/= selftests/net/forwarding/lib.sh index 508f3c700d71..09b63c6f3dbd 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -551,30 +551,6 @@ wait_for_dev() fi } =20 -cmd_jq() -{ - local cmd=3D$1 - local jq_exp=3D$2 - local jq_opts=3D$3 - local ret - local output - - output=3D"$($cmd)" - # it the command fails, return error right away - ret=3D$? - if [[ $ret -ne 0 ]]; then - return $ret - fi - output=3D$(echo $output | jq -r $jq_opts "$jq_exp") - ret=3D$? - if [[ $ret -ne 0 ]]; then - return $ret - fi - echo $output - # return success only in case of non-empty output - [ ! -z "$output" ] -} - pre_cleanup() { if [ "${PAUSE_ON_CLEANUP}" =3D "yes" ]; then diff --git a/tools/testing/selftests/net/lib.sh b/tools/testing/selftests/n= et/lib.sh index 006fdadcc4b9..4c278829e04c 100644 --- a/tools/testing/selftests/net/lib.sh +++ b/tools/testing/selftests/net/lib.sh @@ -616,3 +616,27 @@ wait_local_port_listen() sleep 0.1 done } + +cmd_jq() +{ + local cmd=3D$1 + local jq_exp=3D$2 + local jq_opts=3D$3 + local ret + local output + + output=3D"$($cmd)" + # it the command fails, return error right away + ret=3D$? + if [[ $ret -ne 0 ]]; then + return $ret + fi + output=3D$(echo $output | jq -r $jq_opts "$jq_exp") + ret=3D$? + if [[ $ret -ne 0 ]]; then + return $ret + fi + echo $output + # return success only in case of non-empty output + [ ! -z "$output" ] +} --=20 2.46.0