public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Mohsin Bashir <mohsin.bashr@gmail.com>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org, stephen@networkplumber.org,
	pabeni@redhat.com, kuba@kernel.org, ernis@linux.microsoft.com,
	mohsin.bashr@gmail.com
Subject: [PATCH iproute2-next 4/5] netshaper: Make handle id optional for node scope
Date: Thu, 30 Apr 2026 18:16:10 -0700	[thread overview]
Message-ID: <20260501011611.3533573-5-mohsin.bashr@gmail.com> (raw)
In-Reply-To: <20260501011611.3533573-1-mohsin.bashr@gmail.com>

Make handle id optional for node scope so that omitting it tells
the kernel to create a new node and assign an id automatically,
while providing it updates an existing node. Queue scope still
requires an explicit id since it maps to a specific TX queue.
Only send the handle id in the netlink message when the user
explicitly provides one.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>
---
 netshaper/netshaper.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/netshaper/netshaper.c b/netshaper/netshaper.c
index 53a5eae3..fc68e735 100644
--- a/netshaper/netshaper.c
+++ b/netshaper/netshaper.c
@@ -152,6 +152,7 @@ static int do_cmd(int argc, char **argv, int cmd)
 	__u64 bw_max_bps = 0, bw_min_bps = 0;
 	__u32 handle_id = 0, weight = 0;
 	bool handle_present = false;
+	bool has_handle_id = false;
 	struct nlmsghdr *answer;
 	int err, ifindex = -1;
 
@@ -193,18 +194,8 @@ static int do_cmd(int argc, char **argv, int cmd)
 				return -1;
 			}
 
-			if (handle_scope == NET_SHAPER_SCOPE_NETDEV) {
-				/* For netdev scope, id is optional */
-				if (argc > 1 && strcmp(argv[1], "id") == 0) {
-					NEXT_ARG();
-					NEXT_ARG();
-					if (get_unsigned(&handle_id, *argv, 10)) {
-						fprintf(stderr, "Invalid handle id\n");
-						return -1;
-					}
-				}
-			} else {
-				/* For queue/node scope, id is required */
+			if (handle_scope == NET_SHAPER_SCOPE_QUEUE) {
+				/* For queue scope, id is required */
 				NEXT_ARG();
 				if (strcmp(*argv, "id") != 0) {
 					fprintf(stderr, "What is \"%s\"\n", *argv);
@@ -216,6 +207,16 @@ static int do_cmd(int argc, char **argv, int cmd)
 					fprintf(stderr, "Invalid handle id\n");
 					return -1;
 				}
+				has_handle_id = true;
+			} else if (argc > 1 && strcmp(argv[1], "id") == 0) {
+				/* For netdev and node scope, id is optional */
+				NEXT_ARG();
+				NEXT_ARG();
+				if (get_unsigned(&handle_id, *argv, 10)) {
+					fprintf(stderr, "Invalid handle id\n");
+					return -1;
+				}
+				has_handle_id = true;
 			}
 		} else {
 			fprintf(stderr, "What is \"%s\"\n", *argv);
@@ -240,7 +241,8 @@ static int do_cmd(int argc, char **argv, int cmd)
 	struct rtattr *handle = addattr_nest(&req.n, sizeof(req),
 					     NET_SHAPER_A_HANDLE | NLA_F_NESTED);
 	addattr32(&req.n, sizeof(req), NET_SHAPER_A_HANDLE_SCOPE, handle_scope);
-	addattr32(&req.n, sizeof(req), NET_SHAPER_A_HANDLE_ID, handle_id);
+	if (has_handle_id)
+		addattr32(&req.n, sizeof(req), NET_SHAPER_A_HANDLE_ID, handle_id);
 	addattr_nest_end(&req.n, handle);
 
 	if (has_bw_max)
-- 
2.52.0


  parent reply	other threads:[~2026-05-01  1:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01  1:16 [PATCH iproute2-next 0/5] netshaper: Extend netshaper support Mohsin Bashir
2026-05-01  1:16 ` [PATCH iproute2-next 1/5] netshaper: Extract parse_scope() and parse_rate() helpers Mohsin Bashir
2026-05-01 17:47   ` David Ahern
2026-05-01  1:16 ` [PATCH iproute2-next 2/5] netshaper: Add bw-min and weight parameter support Mohsin Bashir
2026-05-01 17:50   ` David Ahern
2026-05-01  1:16 ` [PATCH iproute2-next 3/5] netshaper: Extend show output with parent, bw-min and weight Mohsin Bashir
2026-05-01  1:16 ` Mohsin Bashir [this message]
2026-05-01  1:16 ` [PATCH iproute2-next 5/5] netshaper: Add group command for creating scheduling hierarchies Mohsin Bashir
2026-05-01 15:17 ` [PATCH iproute2-next 0/5] netshaper: Extend netshaper support Stephen Hemminger
2026-05-01 21:13   ` Mohsin Bashir
2026-05-01 17:52 ` David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260501011611.3533573-5-mohsin.bashr@gmail.com \
    --to=mohsin.bashr@gmail.com \
    --cc=dsahern@kernel.org \
    --cc=ernis@linux.microsoft.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox