netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Machon <daniel.machon@microchip.com>
To: <netdev@vger.kernel.org>
Cc: <dsahern@kernel.org>, <stephen@networkplumber.org>,
	<petrm@nvidia.com>, <UNGLinuxDriver@microchip.com>,
	<daniel.machon@microchip.com>
Subject: [PATCH iproute2-next v2 2/8] dcb: app: modify dcb-app print functions for dcb-rewr reuse
Date: Thu, 25 May 2023 20:10:22 +0200	[thread overview]
Message-ID: <20230510-dcb-rewr-v2-2-9f38e688117e@microchip.com> (raw)
In-Reply-To: <20230510-dcb-rewr-v2-0-9f38e688117e@microchip.com>

Where dcb-app requires protocol to be the printed key, dcb-rewr requires
it to be the priority. Adapt existing dcb-app print functions for this.

dcb_app_print_filtered() has been modified, to take two callbacks; one
for printing the entire string (pid and prio), and one for the pid type
(dec, hex, dscp, pcp). This saves us for making one dedicated function
for each pid type for both app and rewr.

dcb_app_print_key_*() functions have been renamed to
dcb_app_print_pid_*() to align with new situation. Also, none of them
will print the colon anymore.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 dcb/dcb_app.c | 58 ++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 22 deletions(-)

diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index 8073415ad084..1e36541bec61 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -403,38 +403,39 @@ static bool dcb_app_is_port(const struct dcb_app *app)
 	return app->selector == IEEE_8021QAZ_APP_SEL_ANY;
 }
 
-static int dcb_app_print_key_dec(__u16 protocol)
+static int dcb_app_print_pid_dec(__u16 protocol)
 {
-	return print_uint(PRINT_ANY, NULL, "%d:", protocol);
+	return print_uint(PRINT_ANY, NULL, "%u", protocol);
 }
 
-static int dcb_app_print_key_hex(__u16 protocol)
+static int dcb_app_print_pid_hex(__u16 protocol)
 {
-	return print_uint(PRINT_ANY, NULL, "%x:", protocol);
+	return print_uint(PRINT_ANY, NULL, "%x", protocol);
 }
 
-static int dcb_app_print_key_dscp(__u16 protocol)
+static int dcb_app_print_pid_dscp(__u16 protocol)
 {
 	const char *name = rtnl_dsfield_get_name(protocol << 2);
 
-
 	if (!is_json_context() && name != NULL)
-		return print_string(PRINT_FP, NULL, "%s:", name);
-	return print_uint(PRINT_ANY, NULL, "%d:", protocol);
+		return print_string(PRINT_FP, NULL, "%s", name);
+	return print_uint(PRINT_ANY, NULL, "%u", protocol);
 }
 
-static int dcb_app_print_key_pcp(__u16 protocol)
+static int dcb_app_print_pid_pcp(__u16 protocol)
 {
 	/* Print in numerical form, if protocol value is out-of-range */
 	if (protocol > DCB_APP_PCP_MAX)
-		return print_uint(PRINT_ANY, NULL, "%d:", protocol);
+		return print_uint(PRINT_ANY, NULL, "%u", protocol);
 
-	return print_string(PRINT_ANY, NULL, "%s:", pcp_names[protocol]);
+	return print_string(PRINT_ANY, NULL, "%s", pcp_names[protocol]);
 }
 
 static void dcb_app_print_filtered(const struct dcb_app_table *tab,
 				   bool (*filter)(const struct dcb_app *),
-				   int (*print_key)(__u16 protocol),
+				   void (*print_pid_prio)(int (*print_pid)(__u16),
+							  const struct dcb_app *),
+				   int (*print_pid)(__u16 protocol),
 				   const char *json_name,
 				   const char *fp_name)
 {
@@ -453,8 +454,8 @@ static void dcb_app_print_filtered(const struct dcb_app_table *tab,
 		}
 
 		open_json_array(PRINT_JSON, NULL);
-		print_key(app->protocol);
-		print_uint(PRINT_ANY, NULL, "%d ", app->priority);
+		print_pid_prio(print_pid, app);
+		print_string(PRINT_ANY, NULL, "%s", " ");
 		close_json_array(PRINT_JSON, NULL);
 	}
 
@@ -464,9 +465,17 @@ static void dcb_app_print_filtered(const struct dcb_app_table *tab,
 	}
 }
 
+static void dcb_app_print_pid_prio(int (*print_pid)(__u16 protocol),
+				   const struct dcb_app *app)
+{
+	print_pid(app->protocol);
+	print_uint(PRINT_ANY, NULL, ":%u", app->priority);
+}
+
 static void dcb_app_print_ethtype_prio(const struct dcb_app_table *tab)
 {
-	dcb_app_print_filtered(tab, dcb_app_is_ethtype,  dcb_app_print_key_hex,
+	dcb_app_print_filtered(tab, dcb_app_is_ethtype,
+			       dcb_app_print_pid_prio, dcb_app_print_pid_hex,
 			       "ethtype_prio", "ethtype-prio");
 }
 
@@ -474,8 +483,9 @@ static void dcb_app_print_pcp_prio(const struct dcb *dcb,
 				   const struct dcb_app_table *tab)
 {
 	dcb_app_print_filtered(tab, dcb_app_is_pcp,
-			       dcb->numeric ? dcb_app_print_key_dec
-					    : dcb_app_print_key_pcp,
+			       dcb_app_print_pid_prio,
+			       dcb->numeric ? dcb_app_print_pid_dec :
+					      dcb_app_print_pid_pcp,
 			       "pcp_prio", "pcp-prio");
 }
 
@@ -483,26 +493,30 @@ static void dcb_app_print_dscp_prio(const struct dcb *dcb,
 				    const struct dcb_app_table *tab)
 {
 	dcb_app_print_filtered(tab, dcb_app_is_dscp,
-			       dcb->numeric ? dcb_app_print_key_dec
-					    : dcb_app_print_key_dscp,
+			       dcb_app_print_pid_prio,
+			       dcb->numeric ? dcb_app_print_pid_dec :
+					      dcb_app_print_pid_dscp,
 			       "dscp_prio", "dscp-prio");
 }
 
 static void dcb_app_print_stream_port_prio(const struct dcb_app_table *tab)
 {
-	dcb_app_print_filtered(tab, dcb_app_is_stream_port, dcb_app_print_key_dec,
+	dcb_app_print_filtered(tab, dcb_app_is_stream_port,
+			       dcb_app_print_pid_prio, dcb_app_print_pid_dec,
 			       "stream_port_prio", "stream-port-prio");
 }
 
 static void dcb_app_print_dgram_port_prio(const struct dcb_app_table *tab)
 {
-	dcb_app_print_filtered(tab, dcb_app_is_dgram_port, dcb_app_print_key_dec,
+	dcb_app_print_filtered(tab, dcb_app_is_dgram_port,
+			       dcb_app_print_pid_prio, dcb_app_print_pid_dec,
 			       "dgram_port_prio", "dgram-port-prio");
 }
 
 static void dcb_app_print_port_prio(const struct dcb_app_table *tab)
 {
-	dcb_app_print_filtered(tab, dcb_app_is_port, dcb_app_print_key_dec,
+	dcb_app_print_filtered(tab, dcb_app_is_port,
+			       dcb_app_print_pid_prio, dcb_app_print_pid_dec,
 			       "port_prio", "port-prio");
 }
 

-- 
2.34.1


  parent reply	other threads:[~2023-05-25 18:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 18:10 [PATCH iproute2-next v2 0/8] Introduce new dcb-rewr subcommand Daniel Machon
2023-05-25 18:10 ` [PATCH iproute2-next v2 1/8] dcb: app: add new dcbnl attribute field Daniel Machon
2023-05-25 18:10 ` Daniel Machon [this message]
2023-05-29 17:09   ` [PATCH iproute2-next v2 2/8] dcb: app: modify dcb-app print functions for dcb-rewr reuse Petr Machata
2023-05-30  8:01     ` Daniel Machon
2023-05-31  8:31     ` Daniel Machon
2023-05-31 11:26       ` Petr Machata
2023-05-31 14:28         ` David Ahern
2023-05-25 18:10 ` [PATCH iproute2-next v2 3/8] dcb: app: modify dcb_app_table_remove_replaced() " Daniel Machon
2023-05-29 17:00   ` Petr Machata
2023-05-30  8:03     ` Daniel Machon
2023-05-30 20:29     ` Petr Machata
2023-05-25 18:10 ` [PATCH iproute2-next v2 4/8] dcb: app: modify dcb_app_parse_mapping_cb " Daniel Machon
2023-05-30 19:50   ` Petr Machata
2023-05-31  8:12     ` Daniel Machon
2023-05-31 11:05       ` Petr Machata
2023-05-25 18:10 ` [PATCH iproute2-next v2 5/8] dcb: rewr: add new dcb-rewr subcommand Daniel Machon
2023-05-30 19:58   ` Petr Machata
2023-05-31  8:14     ` Daniel Machon
2023-05-25 18:10 ` [PATCH iproute2-next v2 6/8] man: dcb-rewr: add new manpage for dcb-rewr Daniel Machon
2023-05-30 19:47   ` Petr Machata
2023-05-25 18:10 ` [PATCH iproute2-next v2 7/8] man: dcb: add additional references under 'SEE ALSO' Daniel Machon
2023-05-30 19:39   ` Petr Machata
2023-05-25 18:10 ` [PATCH iproute2-next v2 8/8] man: dcb-app: clean up a few mistakes Daniel Machon
2023-05-30 19:37   ` Petr Machata

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=20230510-dcb-rewr-v2-2-9f38e688117e@microchip.com \
    --to=daniel.machon@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=dsahern@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=petrm@nvidia.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;
as well as URLs for NNTP newsgroup(s).