All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand
@ 2023-06-06  7:19 Daniel Machon
  2023-06-06  7:19 ` [PATCH iproute2-next v3 01/12] dcb: app: add new dcbnl attribute field Daniel Machon
                   ` (12 more replies)
  0 siblings, 13 replies; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon, Petr Machata

========================================================================               
Introduction:
========================================================================

This series introduces a new DCB subcommand: rewr, which is used to
configure the in-kernel DCB rewrite table [1].

Rewrite support is added as a separate DCB subcommand, rather than an
APP opt-in flag or similar. This goes in line with what we did to dcbnl,
where rewrite is a separate object.  Obviously this requires a bit more
code to implement the new command, but much of the existing dcb-app code
(especially the bookkeeping code) can be reused. In some cases a little
adaptation is needed.

========================================================================
dcb-rewr parameters:
========================================================================

Initially, I have only made support for the prio-pcp and prio-dscp
parameters, as DSCP and PCP  are the only selectors that currently have
a user [2] and to be honest, I am not even sure it makes sense to add
dgram, stream, ethtype rewrite support - At least the rewriter of Sparx5
does not support this. Any input here is much appreciated!

Examples:

Rewrite DSCP to 63 for packets with priority 1
$ dcb rewr add dev eth0 prio-dscp 1:63

Rewrite PCP 7 and DEI to 1 for packets with priority 1
$ dcb rewr add dev eth0 prio-pcp 1:7de

A new manpage has been added, to cover the new dcb-rewr subcommand, and
its parameters. Also I took the liberty to clean up a few things in the
dcb-app manpage.

========================================================================               
Patch overview:
========================================================================

Patch  #1 Adds a new field 'attr' to the dcb_app_table struct, which is
          used to distinguish app and rewrite tables.

Patch  #2 Replaces uses of %d with %u for unsigned int.

Patch  #3 Moves colon out of callback functions.

Patch  #4 Renames protocl print functions from _key to _pid

Patch  #5 Modifies the _print_filtered() function for dcb-rewr reuse, by
          introducing new callbacks.

Patch  #6 Modifies existing dcb-app function dcb_app_table_remove_replaced 
          for reuse by dcb-rewr

Patch  #7 Expose dcb-app functions required by dcb-rewr.

Patch  #8 Adds the new dcb-rewr subcommand with initial support for
          prio-pcp and prio-dscp rewrite.

Patch  #9 Introduces symbol for max DSCP value and updates accordingly.

Patch #10 Adds the dcb-rewr.8 manpage
Patch #11 Adds references to dcb-apptrust and dcb-rewr in the dcb.8
          manpage.

Patch #12 Cleans up the dcb-app.8 manpage.

[1] https://elixir.bootlin.com/linux/v6.4-rc1/source/net/dcb/dcbnl.c#L181
[2] https://elixir.bootlin.com/linux/v6.4-rc1/source/drivers/net/ethernet/microchip/sparx5/sparx5_dcb.c#L380

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
Changes in v3:
- Split #2 into four patches (%d->%u, :, renaming, prototype change).
- Moved publication of functions in #3 to patches where they are used.
- Added new patch #7 that exposes dcb-app functions required by dcb-rewr.
- Got rid of #4 and copied over dcb_app_parse_mapping_cb to dcb-rewr instead.
- Added new patch #9 for DCB_APP_MAX_DSCP
- Link to v2: https://lore.kernel.org/r/20230510-dcb-rewr-v2-0-9f38e688117e@microchip.com

Changes in v2:
- Got rid of patch #1 that introduced dcb_app.h - expose in individual patches. 
- Changed to callbacks for printing APP and rewrite entries. Also fixed %d to be %u.
- Changed to callbacks for removing replaced table entries for APP and rewrite.
- Changed to callbacks for pushing APP and rewrite entries to the table.
- Got rid of extra spaces in dcb-rewr helps, and reordered some parameters for dcb_parse_mapping.
- Rephrased 'that that' sentence in dcb-app.8 and dcb-rewr.8
- Link to v1: https://lore.kernel.org/r/20230510-dcb-rewr-v1-0-83adc1f93356@microchip.com

---
Daniel Machon (12):
      dcb: app: add new dcbnl attribute field
      dcb: app: replace occurrences of %d with %u for printing unsigned int
      dcb: app: move colon printing out of callbacks
      dcb: app: rename dcb_app_print_key_*() functions
      dcb: app: modify dcb_app_print_filtered() for dcb-rewr reuse
      dcb: app: modify dcb_app_table_remove_replaced() for dcb-rewr reuse
      dcb: app: expose functions required by dcb-rewr
      dcb: rewr: add new dcb-rewr subcommand
      dcb: rewr: add symbol for max DSCP value
      man: dcb-rewr: add new manpage for dcb-rewr
      man: dcb: add additional references under 'SEE ALSO'
      man: dcb-app: clean up a few mistakes

 dcb/Makefile        |   3 +-
 dcb/dcb.c           |   4 +-
 dcb/dcb.h           |  54 ++++++++
 dcb/dcb_app.c       | 154 +++++++++++-----------
 dcb/dcb_rewr.c      | 363 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/man8/dcb-app.8  |  10 +-
 man/man8/dcb-rewr.8 | 206 +++++++++++++++++++++++++++++
 man/man8/dcb.8      |   4 +-
 8 files changed, 718 insertions(+), 80 deletions(-)
---
base-commit: e0c7a04f1dfd7ca05e0725663489c6406d169b9c
change-id: 20230510-dcb-rewr-534b7ab637eb

Best regards,
-- 
Daniel Machon <daniel.machon@microchip.com>


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 01/12] dcb: app: add new dcbnl attribute field
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06 15:00   ` Petr Machata
  2023-06-06  7:19 ` [PATCH iproute2-next v3 02/12] dcb: app: replace occurrences of %d with %u for printing unsigned int Daniel Machon
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon

Add a new field 'attr' to the dcb_app_table struct, in order to inject
different dcbnl get/set attributes for APP and rewrite.

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

diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index eeb78e70f63f..8073415ad084 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -71,6 +71,7 @@ static void dcb_app_help(void)
 struct dcb_app_table {
 	struct dcb_app *apps;
 	size_t n_apps;
+	int attr;
 };
 
 enum ieee_attrs_app dcb_app_attr_type_get(__u8 selector)
@@ -583,7 +584,7 @@ static int dcb_app_get(struct dcb *dcb, const char *dev, struct dcb_app_table *t
 	void *payload;
 	int ret;
 
-	ret = dcb_get_attribute_va(dcb, dev, DCB_ATTR_IEEE_APP_TABLE, &payload, &payload_len);
+	ret = dcb_get_attribute_va(dcb, dev, tab->attr, &payload, &payload_len);
 	if (ret != 0)
 		return ret;
 
@@ -606,7 +607,7 @@ static int dcb_app_add_del_cb(struct dcb *dcb, struct nlmsghdr *nlh, void *data)
 	struct nlattr *nest;
 	size_t i;
 
-	nest = mnl_attr_nest_start(nlh, DCB_ATTR_IEEE_APP_TABLE);
+	nest = mnl_attr_nest_start(nlh, add_del->tab->attr);
 
 	for (i = 0; i < add_del->tab->n_apps; i++) {
 		const struct dcb_app *app = &add_del->tab->apps[i];
@@ -715,7 +716,7 @@ static int dcb_cmd_app_parse_add_del(struct dcb *dcb, const char *dev,
 
 static int dcb_cmd_app_add(struct dcb *dcb, const char *dev, int argc, char **argv)
 {
-	struct dcb_app_table tab = {};
+	struct dcb_app_table tab = { .attr = DCB_ATTR_IEEE_APP_TABLE };
 	int ret;
 
 	ret = dcb_cmd_app_parse_add_del(dcb, dev, argc, argv, &tab);
@@ -729,7 +730,7 @@ static int dcb_cmd_app_add(struct dcb *dcb, const char *dev, int argc, char **ar
 
 static int dcb_cmd_app_del(struct dcb *dcb, const char *dev, int argc, char **argv)
 {
-	struct dcb_app_table tab = {};
+	struct dcb_app_table tab = { .attr = DCB_ATTR_IEEE_APP_TABLE };
 	int ret;
 
 	ret = dcb_cmd_app_parse_add_del(dcb, dev, argc, argv, &tab);
@@ -743,7 +744,7 @@ static int dcb_cmd_app_del(struct dcb *dcb, const char *dev, int argc, char **ar
 
 static int dcb_cmd_app_show(struct dcb *dcb, const char *dev, int argc, char **argv)
 {
-	struct dcb_app_table tab = {};
+	struct dcb_app_table tab = { .attr = DCB_ATTR_IEEE_APP_TABLE };
 	int ret;
 
 	ret = dcb_app_get(dcb, dev, &tab);
@@ -795,7 +796,7 @@ out:
 
 static int dcb_cmd_app_flush(struct dcb *dcb, const char *dev, int argc, char **argv)
 {
-	struct dcb_app_table tab = {};
+	struct dcb_app_table tab = { .attr = DCB_ATTR_IEEE_APP_TABLE };
 	int ret;
 
 	ret = dcb_app_get(dcb, dev, &tab);
@@ -848,9 +849,9 @@ out:
 
 static int dcb_cmd_app_replace(struct dcb *dcb, const char *dev, int argc, char **argv)
 {
-	struct dcb_app_table orig = {};
-	struct dcb_app_table tab = {};
-	struct dcb_app_table new = {};
+	struct dcb_app_table orig = { .attr = DCB_ATTR_IEEE_APP_TABLE };
+	struct dcb_app_table tab = { .attr = DCB_ATTR_IEEE_APP_TABLE };
+	struct dcb_app_table new = { .attr = DCB_ATTR_IEEE_APP_TABLE };
 	int ret;
 
 	ret = dcb_app_get(dcb, dev, &orig);

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 02/12] dcb: app: replace occurrences of %d with %u for printing unsigned int
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
  2023-06-06  7:19 ` [PATCH iproute2-next v3 01/12] dcb: app: add new dcbnl attribute field Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06  9:29   ` Petr Machata
  2023-06-06  7:19 ` [PATCH iproute2-next v3 03/12] dcb: app: move colon printing out of callbacks Daniel Machon
                   ` (10 subsequent siblings)
  12 siblings, 1 reply; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon

In preparation for changing the prototype of dcb_app_print_filtered(),
replace occurrences of %d for printing unsigned integer, with %u as it
ought to be.

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

diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index 8073415ad084..644c37d36ffb 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -405,7 +405,7 @@ static bool dcb_app_is_port(const struct dcb_app *app)
 
 static int dcb_app_print_key_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)
@@ -420,14 +420,14 @@ static int dcb_app_print_key_dscp(__u16 protocol)
 
 	if (!is_json_context() && name != NULL)
 		return print_string(PRINT_FP, NULL, "%s:", name);
-	return print_uint(PRINT_ANY, NULL, "%d:", protocol);
+	return print_uint(PRINT_ANY, NULL, "%u:", protocol);
 }
 
 static int dcb_app_print_key_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]);
 }
@@ -454,7 +454,7 @@ 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_uint(PRINT_ANY, NULL, "%u ", app->priority);
 		close_json_array(PRINT_JSON, NULL);
 	}
 
@@ -519,7 +519,7 @@ static void dcb_app_print_default_prio(const struct dcb_app_table *tab)
 			print_string(PRINT_FP, NULL, "default-prio ", NULL);
 			first = false;
 		}
-		print_uint(PRINT_ANY, NULL, "%d ", tab->apps[i].priority);
+		print_uint(PRINT_ANY, NULL, "%u ", tab->apps[i].priority);
 	}
 
 	if (!first) {
@@ -550,13 +550,13 @@ static int dcb_app_get_table_attr_cb(const struct nlattr *attr, void *data)
 
 	if (!dcb_app_attr_type_validate(type)) {
 		fprintf(stderr,
-			"Unknown attribute in DCB_ATTR_IEEE_APP_TABLE: %d\n",
+			"Unknown attribute in DCB_ATTR_IEEE_APP_TABLE: %u\n",
 			type);
 		return MNL_CB_OK;
 	}
 	if (mnl_attr_get_payload_len(attr) < sizeof(struct dcb_app)) {
 		fprintf(stderr,
-			"%s payload expected to have size %zd, not %d\n",
+			"%s payload expected to have size %zu, not %u\n",
 			ieee_attrs_app_names[type], sizeof(struct dcb_app),
 			mnl_attr_get_payload_len(attr));
 		return MNL_CB_OK;

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 03/12] dcb: app: move colon printing out of callbacks
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
  2023-06-06  7:19 ` [PATCH iproute2-next v3 01/12] dcb: app: add new dcbnl attribute field Daniel Machon
  2023-06-06  7:19 ` [PATCH iproute2-next v3 02/12] dcb: app: replace occurrences of %d with %u for printing unsigned int Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06  9:32   ` Petr Machata
  2023-06-06  7:19 ` [PATCH iproute2-next v3 04/12] dcb: app: rename dcb_app_print_key_*() functions Daniel Machon
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon

In preparation for changing the prototype of dcb_app_print_filtered(),
move the colon printing out of the callbacks, and into
dcb_app_print_filtered().

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

diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index 644c37d36ffb..ed7930ae7b37 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -405,12 +405,12 @@ static bool dcb_app_is_port(const struct dcb_app *app)
 
 static int dcb_app_print_key_dec(__u16 protocol)
 {
-	return print_uint(PRINT_ANY, NULL, "%u:", protocol);
+	return print_uint(PRINT_ANY, NULL, "%u", protocol);
 }
 
 static int dcb_app_print_key_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)
@@ -419,17 +419,17 @@ static int dcb_app_print_key_dscp(__u16 protocol)
 
 
 	if (!is_json_context() && name != NULL)
-		return print_string(PRINT_FP, NULL, "%s:", name);
-	return print_uint(PRINT_ANY, NULL, "%u:", 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)
 {
 	/* Print in numerical form, if protocol value is out-of-range */
 	if (protocol > DCB_APP_PCP_MAX)
-		return print_uint(PRINT_ANY, NULL, "%u:", 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,
@@ -454,7 +454,7 @@ 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, "%u ", app->priority);
+		print_uint(PRINT_ANY, NULL, ":%u ", app->priority);
 		close_json_array(PRINT_JSON, NULL);
 	}
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 04/12] dcb: app: rename dcb_app_print_key_*() functions
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (2 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 03/12] dcb: app: move colon printing out of callbacks Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06  9:34   ` Petr Machata
  2023-06-06  7:19 ` [PATCH iproute2-next v3 05/12] dcb: app: modify dcb_app_print_filtered() for dcb-rewr reuse Daniel Machon
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon

In preparation for changing the prototype of dcb_app_print_filtered(),
rename the _print_key_*() functions to _print_pid_*(), as the protocol
can both be key and value with the introduction of dcb-rewr.

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

diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index ed7930ae7b37..a8f3424db9f7 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -403,17 +403,17 @@ 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, "%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);
 }
 
-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);
 
@@ -423,7 +423,7 @@ static int dcb_app_print_key_dscp(__u16 protocol)
 	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)
@@ -466,7 +466,7 @@ static void dcb_app_print_filtered(const struct dcb_app_table *tab,
 
 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_hex,
 			       "ethtype_prio", "ethtype-prio");
 }
 
@@ -474,8 +474,8 @@ 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->numeric ? dcb_app_print_pid_dec
+					    : dcb_app_print_pid_pcp,
 			       "pcp_prio", "pcp-prio");
 }
 
@@ -483,26 +483,26 @@ 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->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_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_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_dec,
 			       "port_prio", "port-prio");
 }
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 05/12] dcb: app: modify dcb_app_print_filtered() for dcb-rewr reuse
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (3 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 04/12] dcb: app: rename dcb_app_print_key_*() functions Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06 14:08   ` Petr Machata
  2023-06-06  7:19 ` [PATCH iproute2-next v3 06/12] dcb: app: modify dcb_app_table_remove_replaced() " Daniel Machon
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon

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.

Also, printing the colon is now expected to be handled by the
print_pid_prio() callback.

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

diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index a8f3424db9f7..aa248cc40bdf 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -434,7 +434,9 @@ static int dcb_app_print_pid_pcp(__u16 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 +455,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, ":%u ", app->priority);
+		print_pid_prio(print_pid, app);
+		print_string(PRINT_ANY, NULL, "%s", " ");
 		close_json_array(PRINT_JSON, NULL);
 	}
 
@@ -464,9 +466,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_pid_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 +484,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_pid_dec
-					    : dcb_app_print_pid_pcp,
+			       dcb_app_print_pid_prio,
+			       dcb->numeric ? dcb_app_print_pid_dec :
+					      dcb_app_print_pid_pcp,
 			       "pcp_prio", "pcp-prio");
 }
 
@@ -483,26 +494,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_pid_dec
-					    : dcb_app_print_pid_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_pid_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_pid_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_pid_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


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 06/12] dcb: app: modify dcb_app_table_remove_replaced() for dcb-rewr reuse
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (4 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 05/12] dcb: app: modify dcb_app_print_filtered() for dcb-rewr reuse Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06 13:10   ` Petr Machata
  2023-06-06  7:19 ` [PATCH iproute2-next v3 07/12] dcb: app: expose functions required by dcb-rewr Daniel Machon
                   ` (6 subsequent siblings)
  12 siblings, 1 reply; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon

When doing a replace command, entries are checked against selector and
protocol. Rewrite requires the check to be against selector and
priority.

Adapt the existing dcb_app_table_remove_replace function for this, by
using callback functions for selector, pid and prio checks.

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

diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index aa248cc40bdf..4b309016fb65 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -153,8 +153,16 @@ static void dcb_app_table_remove_existing(struct dcb_app_table *a,
 	a->n_apps = ja;
 }
 
+static bool dcb_app_pid_eq(const struct dcb_app *aa, const struct dcb_app *ab)
+{
+	return aa->selector == ab->selector &&
+	       aa->protocol == ab->protocol;
+}
+
 static void dcb_app_table_remove_replaced(struct dcb_app_table *a,
-					  const struct dcb_app_table *b)
+				   const struct dcb_app_table *b,
+				   bool (*key_eq)(const struct dcb_app *aa,
+						  const struct dcb_app *ab))
 {
 	size_t ia, ja;
 	size_t ib;
@@ -167,13 +175,13 @@ static void dcb_app_table_remove_replaced(struct dcb_app_table *a,
 		for (ib = 0; ib < b->n_apps; ib++) {
 			const struct dcb_app *ab = &b->apps[ib];
 
-			if (aa->selector == ab->selector &&
-			    aa->protocol == ab->protocol)
+			if (key_eq(aa, ab))
 				present = true;
 			else
 				continue;
 
-			if (aa->priority == ab->priority) {
+			if (aa->protocol == ab->protocol &&
+			    aa->priority == ab->priority) {
 				found = true;
 				break;
 			}
@@ -892,7 +900,7 @@ static int dcb_cmd_app_replace(struct dcb *dcb, const char *dev, int argc, char
 	}
 
 	/* Remove the obsolete entries. */
-	dcb_app_table_remove_replaced(&orig, &tab);
+	dcb_app_table_remove_replaced(&orig, &tab, dcb_app_pid_eq);
 	ret = dcb_app_add_del(dcb, dev, DCB_CMD_IEEE_DEL, &orig, NULL);
 	if (ret != 0) {
 		fprintf(stderr, "Could not remove replaced APP entries\n");

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 07/12] dcb: app: expose functions required by dcb-rewr
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (5 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 06/12] dcb: app: modify dcb_app_table_remove_replaced() " Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06 13:11   ` Petr Machata
  2023-06-06  7:19 ` [PATCH iproute2-next v3 08/12] dcb: rewr: add new dcb-rewr subcommand Daniel Machon
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon

In preparation for the dcb-rewr implementation, expose required
functions, and structs.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 dcb/dcb.h     | 49 ++++++++++++++++++++++++++++++++++++++++++++
 dcb/dcb_app.c | 66 +++++++++++++++++++++++------------------------------------
 2 files changed, 75 insertions(+), 40 deletions(-)

diff --git a/dcb/dcb.h b/dcb/dcb.h
index d40664f29dad..82ad72bc9ff3 100644
--- a/dcb/dcb.h
+++ b/dcb/dcb.h
@@ -56,11 +56,60 @@ void dcb_print_array_kw(const __u8 *array, size_t array_size,
 
 /* dcb_app.c */
 
+struct dcb_app_table {
+	struct dcb_app *apps;
+	size_t n_apps;
+	int attr;
+};
+
+struct dcb_app_parse_mapping {
+	__u8 selector;
+	struct dcb_app_table *tab;
+	int err;
+};
+
+#define DCB_APP_PCP_MAX 15
+
 int dcb_cmd_app(struct dcb *dcb, int argc, char **argv);
+
+int dcb_app_get(struct dcb *dcb, const char *dev, struct dcb_app_table *tab);
+int dcb_app_add_del(struct dcb *dcb, const char *dev, int command,
+		    const struct dcb_app_table *tab,
+		    bool (*filter)(const struct dcb_app *));
+
+bool dcb_app_is_dscp(const struct dcb_app *app);
+bool dcb_app_is_pcp(const struct dcb_app *app);
+
+int dcb_app_print_pid_dscp(__u16 protocol);
+int dcb_app_print_pid_pcp(__u16 protocol);
+int dcb_app_print_pid_dec(__u16 protocol);
+void dcb_app_print_filtered(const struct dcb_app_table *tab,
+			    bool (*filter)(const struct dcb_app *),
+			    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);
+
 enum ieee_attrs_app dcb_app_attr_type_get(__u8 selector);
 bool dcb_app_attr_type_validate(enum ieee_attrs_app type);
 bool dcb_app_selector_validate(enum ieee_attrs_app type, __u8 selector);
 
+int dcb_app_table_push(struct dcb_app_table *tab, struct dcb_app *app);
+int dcb_app_table_copy(struct dcb_app_table *a,
+		       const struct dcb_app_table *b);
+void dcb_app_table_sort(struct dcb_app_table *tab);
+void dcb_app_table_fini(struct dcb_app_table *tab);
+void dcb_app_table_remove_existing(struct dcb_app_table *a,
+				   const struct dcb_app_table *b);
+void dcb_app_table_remove_replaced(struct dcb_app_table *a,
+				   const struct dcb_app_table *b,
+				   bool (*key_eq)(const struct dcb_app *aa,
+						  const struct dcb_app *ab));
+
+int dcb_app_parse_pcp(__u32 *key, const char *arg);
+int dcb_app_parse_dscp(__u32 *key, const char *arg);
+
 /* dcb_apptrust.c */
 
 int dcb_cmd_apptrust(struct dcb *dcb, int argc, char **argv);
diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index 4b309016fb65..9c2727eff7d8 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -10,8 +10,6 @@
 #include "utils.h"
 #include "rt_names.h"
 
-#define DCB_APP_PCP_MAX 15
-
 static const char *const pcp_names[DCB_APP_PCP_MAX + 1] = {
 	"0nd", "1nd", "2nd", "3nd", "4nd", "5nd", "6nd", "7nd",
 	"0de", "1de", "2de", "3de", "4de", "5de", "6de", "7de"
@@ -68,12 +66,6 @@ static void dcb_app_help(void)
 	dcb_app_help_add();
 }
 
-struct dcb_app_table {
-	struct dcb_app *apps;
-	size_t n_apps;
-	int attr;
-};
-
 enum ieee_attrs_app dcb_app_attr_type_get(__u8 selector)
 {
 	switch (selector) {
@@ -106,12 +98,12 @@ bool dcb_app_selector_validate(enum ieee_attrs_app type, __u8 selector)
 	return dcb_app_attr_type_get(selector) == type;
 }
 
-static void dcb_app_table_fini(struct dcb_app_table *tab)
+void dcb_app_table_fini(struct dcb_app_table *tab)
 {
 	free(tab->apps);
 }
 
-static int dcb_app_table_push(struct dcb_app_table *tab, struct dcb_app *app)
+int dcb_app_table_push(struct dcb_app_table *tab, struct dcb_app *app)
 {
 	struct dcb_app *apps = realloc(tab->apps, (tab->n_apps + 1) * sizeof(*tab->apps));
 
@@ -125,8 +117,8 @@ static int dcb_app_table_push(struct dcb_app_table *tab, struct dcb_app *app)
 	return 0;
 }
 
-static void dcb_app_table_remove_existing(struct dcb_app_table *a,
-					  const struct dcb_app_table *b)
+void dcb_app_table_remove_existing(struct dcb_app_table *a,
+				   const struct dcb_app_table *b)
 {
 	size_t ia, ja;
 	size_t ib;
@@ -159,7 +151,7 @@ static bool dcb_app_pid_eq(const struct dcb_app *aa, const struct dcb_app *ab)
 	       aa->protocol == ab->protocol;
 }
 
-static void dcb_app_table_remove_replaced(struct dcb_app_table *a,
+void dcb_app_table_remove_replaced(struct dcb_app_table *a,
 				   const struct dcb_app_table *b,
 				   bool (*key_eq)(const struct dcb_app *aa,
 						  const struct dcb_app *ab))
@@ -198,8 +190,8 @@ static void dcb_app_table_remove_replaced(struct dcb_app_table *a,
 	a->n_apps = ja;
 }
 
-static int dcb_app_table_copy(struct dcb_app_table *a,
-			      const struct dcb_app_table *b)
+int dcb_app_table_copy(struct dcb_app_table *a,
+		       const struct dcb_app_table *b)
 {
 	size_t i;
 	int ret;
@@ -226,17 +218,11 @@ static int dcb_app_cmp_cb(const void *a, const void *b)
 	return dcb_app_cmp(a, b);
 }
 
-static void dcb_app_table_sort(struct dcb_app_table *tab)
+void dcb_app_table_sort(struct dcb_app_table *tab)
 {
 	qsort(tab->apps, tab->n_apps, sizeof(*tab->apps), dcb_app_cmp_cb);
 }
 
-struct dcb_app_parse_mapping {
-	__u8 selector;
-	struct dcb_app_table *tab;
-	int err;
-};
-
 static void dcb_app_parse_mapping_cb(__u32 key, __u64 value, void *data)
 {
 	struct dcb_app_parse_mapping *pm = data;
@@ -269,7 +255,7 @@ static int dcb_app_parse_mapping_ethtype_prio(__u32 key, char *value, void *data
 				 dcb_app_parse_mapping_cb, data);
 }
 
-static int dcb_app_parse_pcp(__u32 *key, const char *arg)
+int dcb_app_parse_pcp(__u32 *key, const char *arg)
 {
 	int i;
 
@@ -295,7 +281,7 @@ static int dcb_app_parse_mapping_pcp_prio(__u32 key, char *value, void *data)
 				 dcb_app_parse_mapping_cb, data);
 }
 
-static int dcb_app_parse_dscp(__u32 *key, const char *arg)
+int dcb_app_parse_dscp(__u32 *key, const char *arg)
 {
 	if (parse_mapping_num_all(key, arg) == 0)
 		return 0;
@@ -386,12 +372,12 @@ static bool dcb_app_is_default(const struct dcb_app *app)
 	       app->protocol == 0;
 }
 
-static bool dcb_app_is_dscp(const struct dcb_app *app)
+bool dcb_app_is_dscp(const struct dcb_app *app)
 {
 	return app->selector == IEEE_8021QAZ_APP_SEL_DSCP;
 }
 
-static bool dcb_app_is_pcp(const struct dcb_app *app)
+bool dcb_app_is_pcp(const struct dcb_app *app)
 {
 	return app->selector == DCB_APP_SEL_PCP;
 }
@@ -411,7 +397,7 @@ static bool dcb_app_is_port(const struct dcb_app *app)
 	return app->selector == IEEE_8021QAZ_APP_SEL_ANY;
 }
 
-static int dcb_app_print_pid_dec(__u16 protocol)
+int dcb_app_print_pid_dec(__u16 protocol)
 {
 	return print_uint(PRINT_ANY, NULL, "%u", protocol);
 }
@@ -421,7 +407,7 @@ static int dcb_app_print_pid_hex(__u16 protocol)
 	return print_uint(PRINT_ANY, NULL, "%x", protocol);
 }
 
-static int dcb_app_print_pid_dscp(__u16 protocol)
+int dcb_app_print_pid_dscp(__u16 protocol)
 {
 	const char *name = rtnl_dsfield_get_name(protocol << 2);
 
@@ -431,7 +417,7 @@ static int dcb_app_print_pid_dscp(__u16 protocol)
 	return print_uint(PRINT_ANY, NULL, "%u", protocol);
 }
 
-static int dcb_app_print_pid_pcp(__u16 protocol)
+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)
@@ -440,13 +426,13 @@ static int dcb_app_print_pid_pcp(__u16 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 *),
-				   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)
+void dcb_app_print_filtered(const struct dcb_app_table *tab,
+			    bool (*filter)(const struct dcb_app *),
+			    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)
 {
 	bool first = true;
 	size_t i;
@@ -601,7 +587,7 @@ static int dcb_app_get_table_attr_cb(const struct nlattr *attr, void *data)
 	return MNL_CB_OK;
 }
 
-static int dcb_app_get(struct dcb *dcb, const char *dev, struct dcb_app_table *tab)
+int dcb_app_get(struct dcb *dcb, const char *dev, struct dcb_app_table *tab)
 {
 	uint16_t payload_len;
 	void *payload;
@@ -644,9 +630,9 @@ static int dcb_app_add_del_cb(struct dcb *dcb, struct nlmsghdr *nlh, void *data)
 	return 0;
 }
 
-static int dcb_app_add_del(struct dcb *dcb, const char *dev, int command,
-			   const struct dcb_app_table *tab,
-			   bool (*filter)(const struct dcb_app *))
+int dcb_app_add_del(struct dcb *dcb, const char *dev, int command,
+		    const struct dcb_app_table *tab,
+		    bool (*filter)(const struct dcb_app *))
 {
 	struct dcb_app_add_del add_del = {
 		.tab = tab,

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 08/12] dcb: rewr: add new dcb-rewr subcommand
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (6 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 07/12] dcb: app: expose functions required by dcb-rewr Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06 13:17   ` Petr Machata
  2023-06-06  7:19 ` [PATCH iproute2-next v3 09/12] dcb: rewr: add symbol for max DSCP value Daniel Machon
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon

Add a new subcommand 'rewr' for configuring the in-kernel DCB rewrite
table. The rewrite table of the kernel is similar to the APP table,
therefore, much of the existing bookkeeping code from dcb-app, can be
reused in the dcb-rewr implementation.

Initially, only support for configuring PCP and DSCP-based rewrite has
been added.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 dcb/Makefile   |   3 +-
 dcb/dcb.c      |   4 +-
 dcb/dcb.h      |   4 +
 dcb/dcb_rewr.c | 363 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 372 insertions(+), 2 deletions(-)

diff --git a/dcb/Makefile b/dcb/Makefile
index dd41a559a0c8..10794c9dc19f 100644
--- a/dcb/Makefile
+++ b/dcb/Makefile
@@ -8,7 +8,8 @@ DCBOBJ = dcb.o \
          dcb_ets.o \
          dcb_maxrate.o \
          dcb_pfc.o \
-         dcb_apptrust.o
+         dcb_apptrust.o \
+         dcb_rewr.o
 TARGETS += dcb
 LDLIBS += -lm
 
diff --git a/dcb/dcb.c b/dcb/dcb.c
index 9b996abac529..fe0a0f04143d 100644
--- a/dcb/dcb.c
+++ b/dcb/dcb.c
@@ -470,7 +470,7 @@ static void dcb_help(void)
 	fprintf(stderr,
 		"Usage: dcb [ OPTIONS ] OBJECT { COMMAND | help }\n"
 		"       dcb [ -f | --force ] { -b | --batch } filename [ -n | --netns ] netnsname\n"
-		"where  OBJECT := { app | apptrust | buffer | dcbx | ets | maxrate | pfc }\n"
+		"where  OBJECT := { app | apptrust | buffer | dcbx | ets | maxrate | pfc | rewr }\n"
 		"       OPTIONS := [ -V | --Version | -i | --iec | -j | --json\n"
 		"                  | -N | --Numeric | -p | --pretty\n"
 		"                  | -s | --statistics | -v | --verbose]\n");
@@ -485,6 +485,8 @@ static int dcb_cmd(struct dcb *dcb, int argc, char **argv)
 		return dcb_cmd_app(dcb, argc - 1, argv + 1);
 	} else if (strcmp(*argv, "apptrust") == 0) {
 		return dcb_cmd_apptrust(dcb, argc - 1, argv + 1);
+	} else if (strcmp(*argv, "rewr") == 0) {
+		return dcb_cmd_rewr(dcb, argc - 1, argv + 1);
 	} else if (matches(*argv, "buffer") == 0) {
 		return dcb_cmd_buffer(dcb, argc - 1, argv + 1);
 	} else if (matches(*argv, "dcbx") == 0) {
diff --git a/dcb/dcb.h b/dcb/dcb.h
index 82ad72bc9ff3..ff11a122ba37 100644
--- a/dcb/dcb.h
+++ b/dcb/dcb.h
@@ -54,6 +54,10 @@ void dcb_print_array_on_off(const __u8 *array, size_t size);
 void dcb_print_array_kw(const __u8 *array, size_t array_size,
 			const char *const kw[], size_t kw_size);
 
+/* dcp_rewr.c */
+
+int dcb_cmd_rewr(struct dcb *dcb, int argc, char **argv);
+
 /* dcb_app.c */
 
 struct dcb_app_table {
diff --git a/dcb/dcb_rewr.c b/dcb/dcb_rewr.c
new file mode 100644
index 000000000000..facbdbe664a4
--- /dev/null
+++ b/dcb/dcb_rewr.c
@@ -0,0 +1,363 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <errno.h>
+#include <linux/dcbnl.h>
+#include <stdio.h>
+
+#include "dcb.h"
+#include "utils.h"
+
+static void dcb_rewr_help_add(void)
+{
+	fprintf(stderr,
+		"Usage: dcb rewr { add | del | replace } dev STRING\n"
+		"           [ prio-pcp PRIO:PCP ]\n"
+		"           [ prio-dscp PRIO:DSCP ]\n"
+		"\n"
+		" where PRIO := { 0 .. 7 }\n"
+		"       PCP  := { 0(nd/de) .. 7(nd/de) }\n"
+		"       DSCP := { 0 .. 63 }\n"
+		"\n"
+	);
+}
+
+static void dcb_rewr_help_show_flush(void)
+{
+	fprintf(stderr,
+		"Usage: dcb rewr { show | flush } dev STRING\n"
+		"           [ prio-pcp ]\n"
+		"           [ prio-dscp ]\n"
+		"\n"
+	);
+}
+
+static void dcb_rewr_help(void)
+{
+	fprintf(stderr,
+		"Usage: dcb rewr help\n"
+		"\n"
+	);
+	dcb_rewr_help_show_flush();
+	dcb_rewr_help_add();
+}
+
+static void dcb_rewr_parse_mapping_cb(__u32 key, __u64 value, void *data)
+{
+	struct dcb_app_parse_mapping *pm = data;
+	struct dcb_app app = {
+		.selector = pm->selector,
+		.priority = key,
+		.protocol = value,
+	};
+
+	if (pm->err)
+		return;
+
+	pm->err = dcb_app_table_push(pm->tab, &app);
+}
+
+static int dcb_rewr_parse_mapping_prio_pcp(__u32 key, char *value, void *data)
+{
+	__u32 pcp;
+
+	if (dcb_app_parse_pcp(&pcp, value))
+		return -EINVAL;
+
+	return dcb_parse_mapping("PRIO", key, IEEE_8021QAZ_MAX_TCS - 1,
+				 "PCP", pcp, DCB_APP_PCP_MAX,
+				 dcb_rewr_parse_mapping_cb, data);
+}
+
+static int dcb_rewr_parse_mapping_prio_dscp(__u32 key, char *value, void *data)
+{
+	__u32 dscp;
+
+	if (dcb_app_parse_dscp(&dscp, value))
+		return -EINVAL;
+
+	return dcb_parse_mapping("PRIO", key, IEEE_8021QAZ_MAX_TCS - 1,
+				 "DSCP", dscp, 63,
+				 dcb_rewr_parse_mapping_cb, data);
+}
+
+static void dcb_rewr_print_prio_pid(int (*print_pid)(__u16 protocol),
+				    const struct dcb_app *app)
+{
+	print_uint(PRINT_ANY, NULL, "%u:", app->priority);
+	print_pid(app->protocol);
+}
+
+static void dcb_rewr_print_prio_pcp(const struct dcb *dcb,
+				    const struct dcb_app_table *tab)
+{
+	dcb_app_print_filtered(tab, dcb_app_is_pcp,
+			       dcb_rewr_print_prio_pid,
+			       dcb->numeric ? dcb_app_print_pid_dec :
+					      dcb_app_print_pid_pcp,
+			       "prio_pcp", "prio-pcp");
+}
+
+static void dcb_rewr_print_prio_dscp(const struct dcb *dcb,
+				     const struct dcb_app_table *tab)
+{
+	dcb_app_print_filtered(tab, dcb_app_is_dscp,
+			       dcb_rewr_print_prio_pid,
+			       dcb->numeric ? dcb_app_print_pid_dec :
+					      dcb_app_print_pid_dscp,
+			       "prio_dscp", "prio-dscp");
+}
+
+static void dcb_rewr_print(const struct dcb *dcb,
+			   const struct dcb_app_table *tab)
+{
+	dcb_rewr_print_prio_pcp(dcb, tab);
+	dcb_rewr_print_prio_dscp(dcb, tab);
+}
+
+static bool dcb_rewr_prio_eq(const struct dcb_app *aa, const struct dcb_app *ab)
+{
+	return aa->selector == ab->selector &&
+	       aa->priority == ab->priority;
+}
+
+static int dcb_cmd_rewr_parse_add_del(struct dcb *dcb, const char *dev,
+				      int argc, char **argv,
+				      struct dcb_app_table *tab)
+{
+	struct dcb_app_parse_mapping pm = {
+		.tab = tab,
+	};
+	int ret;
+
+	if (!argc) {
+		dcb_rewr_help_add();
+		return 0;
+	}
+
+	do {
+		if (strcmp(*argv, "help") == 0) {
+			dcb_rewr_help_add();
+			return 0;
+		} else if (strcmp(*argv, "prio-pcp") == 0) {
+			NEXT_ARG();
+			pm.selector = DCB_APP_SEL_PCP;
+			ret = parse_mapping(&argc, &argv, false,
+					    &dcb_rewr_parse_mapping_prio_pcp,
+					    &pm);
+		} else if (strcmp(*argv, "prio-dscp") == 0) {
+			NEXT_ARG();
+			pm.selector = IEEE_8021QAZ_APP_SEL_DSCP;
+			ret = parse_mapping(&argc, &argv, false,
+					    &dcb_rewr_parse_mapping_prio_dscp,
+					    &pm);
+		} else {
+			fprintf(stderr, "What is \"%s\"?\n", *argv);
+			dcb_rewr_help_add();
+			return -EINVAL;
+		}
+
+		if (ret != 0) {
+			fprintf(stderr, "Invalid mapping %s\n", *argv);
+			return ret;
+		}
+		if (pm.err)
+			return pm.err;
+	} while (argc > 0);
+
+	return 0;
+}
+
+static int dcb_cmd_rewr_add(struct dcb *dcb, const char *dev, int argc,
+			    char **argv)
+{
+	struct dcb_app_table tab = { .attr = DCB_ATTR_DCB_REWR_TABLE };
+	int ret;
+
+	ret = dcb_cmd_rewr_parse_add_del(dcb, dev, argc, argv, &tab);
+	if (ret != 0)
+		return ret;
+
+	ret = dcb_app_add_del(dcb, dev, DCB_CMD_IEEE_SET, &tab, NULL);
+	dcb_app_table_fini(&tab);
+	return ret;
+}
+
+static int dcb_cmd_rewr_del(struct dcb *dcb, const char *dev, int argc,
+			    char **argv)
+{
+	struct dcb_app_table tab = { .attr = DCB_ATTR_DCB_REWR_TABLE };
+	int ret;
+
+	ret = dcb_cmd_rewr_parse_add_del(dcb, dev, argc, argv, &tab);
+	if (ret != 0)
+		return ret;
+
+	ret = dcb_app_add_del(dcb, dev, DCB_CMD_IEEE_DEL, &tab, NULL);
+	dcb_app_table_fini(&tab);
+	return ret;
+}
+
+static int dcb_cmd_rewr_replace(struct dcb *dcb, const char *dev, int argc,
+				char **argv)
+{
+	struct dcb_app_table orig = { .attr = DCB_ATTR_DCB_REWR_TABLE };
+	struct dcb_app_table tab = { .attr = DCB_ATTR_DCB_REWR_TABLE };
+	struct dcb_app_table new = { .attr = DCB_ATTR_DCB_REWR_TABLE };
+	int ret;
+
+	ret = dcb_app_get(dcb, dev, &orig);
+	if (ret != 0)
+		return ret;
+
+	ret = dcb_cmd_rewr_parse_add_del(dcb, dev, argc, argv, &tab);
+	if (ret != 0)
+		goto out;
+
+	/* Attempts to add an existing entry would be rejected, so drop
+	 * these entries from tab.
+	 */
+	ret = dcb_app_table_copy(&new, &tab);
+	if (ret != 0)
+		goto out;
+	dcb_app_table_remove_existing(&new, &orig);
+
+	ret = dcb_app_add_del(dcb, dev, DCB_CMD_IEEE_SET, &new, NULL);
+	if (ret != 0) {
+		fprintf(stderr, "Could not add new rewrite entries\n");
+		goto out;
+	}
+
+	/* Remove the obsolete entries. */
+	dcb_app_table_remove_replaced(&orig, &tab, dcb_rewr_prio_eq);
+	ret = dcb_app_add_del(dcb, dev, DCB_CMD_IEEE_DEL, &orig, NULL);
+	if (ret != 0) {
+		fprintf(stderr, "Could not remove replaced rewrite entries\n");
+		goto out;
+	}
+
+out:
+	dcb_app_table_fini(&new);
+	dcb_app_table_fini(&tab);
+	dcb_app_table_fini(&orig);
+	return 0;
+}
+
+static int dcb_cmd_rewr_show(struct dcb *dcb, const char *dev, int argc,
+			     char **argv)
+{
+	struct dcb_app_table tab = { .attr = DCB_ATTR_DCB_REWR_TABLE };
+	int ret;
+
+	ret = dcb_app_get(dcb, dev, &tab);
+	if (ret != 0)
+		return ret;
+
+	dcb_app_table_sort(&tab);
+
+	open_json_object(NULL);
+
+	if (!argc) {
+		dcb_rewr_print(dcb, &tab);
+		goto out;
+	}
+
+	do {
+		if (strcmp(*argv, "help") == 0) {
+			dcb_rewr_help_show_flush();
+			goto out;
+		} else if (strcmp(*argv, "prio-pcp") == 0) {
+			dcb_rewr_print_prio_pcp(dcb, &tab);
+		} else if (strcmp(*argv, "prio-dscp") == 0) {
+			dcb_rewr_print_prio_dscp(dcb, &tab);
+		} else {
+			fprintf(stderr, "What is \"%s\"?\n", *argv);
+			dcb_rewr_help_show_flush();
+			ret = -EINVAL;
+			goto out;
+		}
+
+		NEXT_ARG_FWD();
+	} while (argc > 0);
+
+out:
+	close_json_object();
+	dcb_app_table_fini(&tab);
+	return ret;
+}
+
+static int dcb_cmd_rewr_flush(struct dcb *dcb, const char *dev, int argc,
+			      char **argv)
+{
+	struct dcb_app_table tab = { .attr = DCB_ATTR_DCB_REWR_TABLE };
+	int ret;
+
+	ret = dcb_app_get(dcb, dev, &tab);
+	if (ret != 0)
+		return ret;
+
+	if (!argc) {
+		ret = dcb_app_add_del(dcb, dev, DCB_CMD_IEEE_DEL, &tab,
+				      NULL);
+		goto out;
+	}
+
+	do {
+		if (strcmp(*argv, "help") == 0) {
+			dcb_rewr_help_show_flush();
+			goto out;
+		} else if (strcmp(*argv, "prio-pcp") == 0) {
+			ret = dcb_app_add_del(dcb, dev, DCB_CMD_IEEE_DEL, &tab,
+					      &dcb_app_is_pcp);
+			if (ret != 0)
+				goto out;
+		} else if (strcmp(*argv, "prio-dscp") == 0) {
+			ret = dcb_app_add_del(dcb, dev, DCB_CMD_IEEE_DEL, &tab,
+					      &dcb_app_is_dscp);
+			if (ret != 0)
+				goto out;
+		} else {
+			fprintf(stderr, "What is \"%s\"?\n", *argv);
+			dcb_rewr_help_show_flush();
+			ret = -EINVAL;
+			goto out;
+		}
+
+		NEXT_ARG_FWD();
+	} while (argc > 0);
+
+out:
+	dcb_app_table_fini(&tab);
+	return ret;
+}
+
+int dcb_cmd_rewr(struct dcb *dcb, int argc, char **argv)
+{
+	if (!argc || strcmp(*argv, "help") == 0) {
+		dcb_rewr_help();
+		return 0;
+	} else if (strcmp(*argv, "show") == 0) {
+		NEXT_ARG_FWD();
+		return dcb_cmd_parse_dev(dcb, argc, argv, dcb_cmd_rewr_show,
+					 dcb_rewr_help_show_flush);
+	} else if (strcmp(*argv, "flush") == 0) {
+		NEXT_ARG_FWD();
+		return dcb_cmd_parse_dev(dcb, argc, argv, dcb_cmd_rewr_flush,
+					 dcb_rewr_help_show_flush);
+	} else if (strcmp(*argv, "add") == 0) {
+		NEXT_ARG_FWD();
+		return dcb_cmd_parse_dev(dcb, argc, argv, dcb_cmd_rewr_add,
+					 dcb_rewr_help_add);
+	} else if (strcmp(*argv, "del") == 0) {
+		NEXT_ARG_FWD();
+		return dcb_cmd_parse_dev(dcb, argc, argv, dcb_cmd_rewr_del,
+					 dcb_rewr_help_add);
+	} else if (strcmp(*argv, "replace") == 0) {
+		NEXT_ARG_FWD();
+		return dcb_cmd_parse_dev(dcb, argc, argv, dcb_cmd_rewr_replace,
+					 dcb_rewr_help_add);
+	} else {
+		fprintf(stderr, "What is \"%s\"?\n", *argv);
+		dcb_rewr_help();
+		return -EINVAL;
+	}
+}

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 09/12] dcb: rewr: add symbol for max DSCP value
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (7 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 08/12] dcb: rewr: add new dcb-rewr subcommand Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06 13:14   ` Petr Machata
  2023-06-06  7:19 ` [PATCH iproute2-next v3 10/12] man: dcb-rewr: add new manpage for dcb-rewr Daniel Machon
                   ` (3 subsequent siblings)
  12 siblings, 1 reply; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon

A symbol, DCB_APP_PCP_MAX, for maximum PCP value, already exists. Lets
add a symbol DCB_APP_DSCP_MAX and update accordingly.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 dcb/dcb.h      | 1 +
 dcb/dcb_app.c  | 2 +-
 dcb/dcb_rewr.c | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/dcb/dcb.h b/dcb/dcb.h
index ff11a122ba37..b2e8e89f7701 100644
--- a/dcb/dcb.h
+++ b/dcb/dcb.h
@@ -73,6 +73,7 @@ struct dcb_app_parse_mapping {
 };
 
 #define DCB_APP_PCP_MAX 15
+#define DCB_APP_DSCP_MAX 63
 
 int dcb_cmd_app(struct dcb *dcb, int argc, char **argv);
 
diff --git a/dcb/dcb_app.c b/dcb/dcb_app.c
index 9c2727eff7d8..7040e62cbb47 100644
--- a/dcb/dcb_app.c
+++ b/dcb/dcb_app.c
@@ -306,7 +306,7 @@ static int dcb_app_parse_mapping_dscp_prio(__u32 key, char *value, void *data)
 	if (get_u8(&prio, value, 0))
 		return -EINVAL;
 
-	return dcb_parse_mapping("DSCP", key, 63,
+	return dcb_parse_mapping("DSCP", key, DCB_APP_DSCP_MAX,
 				 "PRIO", prio, IEEE_8021QAZ_MAX_TCS - 1,
 				 dcb_app_parse_mapping_cb, data);
 }
diff --git a/dcb/dcb_rewr.c b/dcb/dcb_rewr.c
index facbdbe664a4..5bb649adce24 100644
--- a/dcb/dcb_rewr.c
+++ b/dcb/dcb_rewr.c
@@ -76,7 +76,7 @@ static int dcb_rewr_parse_mapping_prio_dscp(__u32 key, char *value, void *data)
 		return -EINVAL;
 
 	return dcb_parse_mapping("PRIO", key, IEEE_8021QAZ_MAX_TCS - 1,
-				 "DSCP", dscp, 63,
+				 "DSCP", dscp, DCB_APP_DSCP_MAX,
 				 dcb_rewr_parse_mapping_cb, data);
 }
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 10/12] man: dcb-rewr: add new manpage for dcb-rewr
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (8 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 09/12] dcb: rewr: add symbol for max DSCP value Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06  7:19 ` [PATCH iproute2-next v3 11/12] man: dcb: add additional references under 'SEE ALSO' Daniel Machon
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon, Petr Machata

Add a new manpage for dcb-rewr. Most of the content is copied over from
dcb-app, as the same set of commands and parameters (in reverse) applies
to dcb-rewr.

Reviewed-by: Petr Machata <me@pmachata.org>
Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 man/man8/dcb-rewr.8 | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 206 insertions(+)

diff --git a/man/man8/dcb-rewr.8 b/man/man8/dcb-rewr.8
new file mode 100644
index 000000000000..03b59cf4837c
--- /dev/null
+++ b/man/man8/dcb-rewr.8
@@ -0,0 +1,206 @@
+.TH DCB-REWR 8 "15 may 2023" "iproute2" "Linux"
+.SH NAME
+dcb-rewr \- show / manipulate the rewrite table of
+the DCB (Data Center Bridging) subsystem
+.SH SYNOPSIS
+.sp
+.ad l
+.in +8
+
+.ti -8
+.B dcb
+.RI "[ " OPTIONS " ] "
+.B rewr
+.RI "{ " COMMAND " | " help " }"
+.sp
+
+.ti -8
+.B dcb rewr " { " show " | " flush " } " dev
+.RI DEV
+.RB "[ " prio-dscp " ]"
+.RB "[ " prio-pcp " ]"
+
+.ti -8
+.B dcb rewr " { " add " | " del " | " replace " } " dev
+.RI DEV
+.RB "[ " prio-dscp " " \fIDSCP-MAP\fB " ]"
+.RB "[ " prio-pcp " " \fIPCP-MAP\fB " ]"
+
+.ti -8
+.IR DSCP-MAP " := [ " DSCP-MAP " ] " DSCP-MAPPING
+
+.ti -8
+.IR DSCP-MAPPING " := " \fIPRIO \fB:\fR "{ " DSCP " | " \fBall\fR " }"
+
+.ti -8
+.IR PCP-MAP " := [ " PCP-MAP " ] " PCP-MAPPING
+
+.ti -8
+.IR PCP-MAPPING " := " \fIPRIO \fB:\fR PCP\fR
+
+.ti -8
+.IR DSCP " := { " \fB0\fR " .. " \fB63\fR " }"
+
+.ti -8
+.IR PCP " := { " \fB0(nd/de)\fR " .. " \fB7(nd/de)\fR " }"
+
+.ti -8
+.IR PRIO " := { " \fB0\fR " .. " \fB7\fR " }"
+
+.SH DESCRIPTION
+
+.B dcb rewr
+is used to configure the rewrite table, in the DCB (Data Center Bridging)
+subsystem.  The rewrite table is used to rewrite certain values in the packet
+headers, based on packet priority.
+
+DCB rewrite entries are, like DCB APP entries, 3-tuples of selector, protocol
+ID, and priority. Selector is an enumeration that picks one of the
+prioritization namespaces. Currently, only the DSCP and PCP selector namespaces
+are supported by dcb rewr.
+
+The rewrite table is a list of DCB rewrite rules, that applies to packets
+with matching priority.  Notably, it is valid to have conflicting rewrite
+assignment for the same selector and priority. For example, the set of two
+rewrite entries (DSCP, 10, 1) and (DSCP, 11, 1), where packets with priority 1
+should have its DSCP value rewritten to both 10 and 11, form a well-defined
+rewrite table.
+.B dcb rewr
+tool allows low-level management of the rewrite table by adding and deleting
+individual rewrite 3-tuples through
+.B add
+and
+.B del
+commands. On the other hand, the command
+.B replace
+does what one would typically want in this situation--first adds the new
+configuration, and then removes the obsolete one, so that only one
+rewrite rule is in effect for a given selector and priority.
+
+.SH COMMANDS
+
+.TP
+.B show
+Display all entries with a given selector. When no selector is given, shows all
+rewrite table entries categorized per selector.
+
+.TP
+.B flush
+Remove all entries with a given selector. When no selector is given, removes all
+rewrite table entries.
+
+.TP
+.B add
+.TQ
+.B del
+Add and, respectively, remove individual rewrite 3-tuples to and from the DCB
+rewrite table.
+
+.TP
+.B replace
+Take the list of entries mentioned as parameter, and add those that are not
+present in the rewrite table yet. Then remove those entries, whose selector and
+priority have been mentioned as parameter, but not with the exact same
+protocol ID. This has the effect of, for the given selector and priority,
+causing that the table only contains the protocol ID (or ID's) given as
+parameter.
+
+.SH PARAMETERS
+
+The following table shows parameters in a way that they would be used with
+\fBadd\fR, \fBdel\fR and \fBreplace\fR commands. For \fBshow\fR and
+\fBflush\fR, the parameter name is to be used as a simple keyword without
+further arguments.
+
+.TP
+.B prio-dscp \fIDSCP-MAP
+\fIDSCP-MAP\fR uses the array parameter syntax, see
+.BR dcb (8)
+for details. Keys are priorities, values are DSCP points for traffic
+with matching priority. DSCP points can be written either directly as numeric
+values, or using symbolic names specified in
+.B /etc/iproute2/rt_dsfield
+(however note that the file specifies full 8-bit dsfield values, whereas
+.B dcb rewr
+will only use the higher six bits).
+.B dcb rewr show
+will similarly format DSCP values as symbolic names if possible. The
+command line option
+.B -N
+turns the show translation off.
+
+.TP
+.B prio-pcp \fIPCP-MAP
+\fIPCP-MAP\fR uses the array parameter syntax, see
+.BR dcb (8)
+for details. Keys are priorities. Values are PCP/DEI for traffic with
+matching priority. PCP/DEI values are written as a combination of numeric- and
+symbolic values, to accommodate for both. PCP always in numeric form e.g 0 ..
+7 and DEI in symbolic form e.g 'de' (drop-eligible), indicating that the DEI
+bit is 1 or 'nd' (not-drop-eligible), indicating that the DEI bit is 0.  In
+combination 1:2de translates to a mapping of priority 1 to PCP=2 and DEI=1.
+
+.SH EXAMPLE & USAGE
+
+Add a rule to rewrite DSCP to 0, 24 and 48 for traffic with priority 0, 3 and
+6, respectively:
+.P
+# dcb rewr add dev eth0 prio-dscp 0:0 3:24 6:48
+
+Add a rule to rewrite DSCP to 25 for traffic with priority 3:
+.P
+# dcb rewr add dev eth0 prio-dscp 3:25
+.br
+# dcb rewr show dev eth0 prio-dscp
+.br
+prio-dscp 0:0 3:CS3 3:25 6:CS6
+.br
+# dcb -N rewr show dev eth0 prio-dscp
+.br
+prio-dscp 0:0 3:24 3:25 6:48
+
+Reconfigure the table so that only one rule exists for rewriting traffic with
+priority 3.
+
+.P
+# dcb rewr replace dev eth0 prio-dscp 3:26
+.br
+# dcb rewr -N show dev eth0 prio-dscp
+.br
+prio-dscp 0:0 3:26 6:48
+
+Flush all DSCP rules:
+
+.P
+# dcb rewr flush dev eth0 prio-dscp
+.br
+# dcb rewr show dev eth0 prio-dscp
+.br
+(nothing)
+
+Add a rule to rewrite PCP to 1 and DEI to 0 for traffic with priority 1 and a
+rule to rewrite PCP to 2 and DEI to 1 for traffic with priority 2:
+
+.P
+# dcb rewr add dev eth0 prio-pcp 1:1nd 2:2de
+.br
+# dcb rewr show dev eth0 prio-pcp
+.br
+prio-pcp 1:1nd 2:2de
+
+.SH EXIT STATUS
+Exit status is 0 if command was successful or a positive integer upon failure.
+
+.SH SEE ALSO
+.BR dcb (8)
+.BR dcb-app (8)
+.BR dcb-apptrust (8)
+
+.SH REPORTING BUGS
+Report any bugs to the Network Developers mailing list
+.B <netdev@vger.kernel.org>
+where the development and maintenance is primarily done.  You do not have to be
+subscribed to the list to send a message there.
+
+.SH AUTHOR
+Daniel Machon <daniel.machon@microchip.com>

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 11/12] man: dcb: add additional references under 'SEE ALSO'
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (9 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 10/12] man: dcb-rewr: add new manpage for dcb-rewr Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-06  7:19 ` [PATCH iproute2-next v3 12/12] man: dcb-app: clean up a few mistakes Daniel Machon
  2023-06-09 21:50 ` [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand patchwork-bot+netdevbpf
  12 siblings, 0 replies; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon, Petr Machata

Add dcb-apptrust and dcb-rewr to the 'SEE ALSO' section of the dcb
manpage.

Reviewed-by: Petr Machata <me@pmachata.org>
Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 man/man8/dcb.8 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/man/man8/dcb.8 b/man/man8/dcb.8
index 24944b73816b..a1d6505e93b4 100644
--- a/man/man8/dcb.8
+++ b/man/man8/dcb.8
@@ -140,10 +140,12 @@ Exit status is 0 if command was successful or a positive integer upon failure.
 
 .SH SEE ALSO
 .BR dcb-app (8),
+.BR dcb-apptrust (8),
 .BR dcb-buffer (8),
 .BR dcb-ets (8),
 .BR dcb-maxrate (8),
-.BR dcb-pfc (8)
+.BR dcb-pfc (8),
+.BR dcb-rewr (8)
 .br
 
 .SH REPORTING BUGS

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH iproute2-next v3 12/12] man: dcb-app: clean up a few mistakes
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (10 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 11/12] man: dcb: add additional references under 'SEE ALSO' Daniel Machon
@ 2023-06-06  7:19 ` Daniel Machon
  2023-06-09 21:50 ` [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand patchwork-bot+netdevbpf
  12 siblings, 0 replies; 23+ messages in thread
From: Daniel Machon @ 2023-06-06  7:19 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, stephen, petrm, UNGLinuxDriver, daniel.machon, Petr Machata

While referencing the dcb-app manpage, I spotted a few mistakes. Lets
fix them.

Reviewed-by: Petr Machata <me@pmachata.org>
Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 man/man8/dcb-app.8 | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/man/man8/dcb-app.8 b/man/man8/dcb-app.8
index ecb38591168e..be505a0be308 100644
--- a/man/man8/dcb-app.8
+++ b/man/man8/dcb-app.8
@@ -1,4 +1,4 @@
-.TH DCB-ETS 8 "6 December 2020" "iproute2" "Linux"
+.TH DCB-APP 8 "6 December 2020" "iproute2" "Linux"
 .SH NAME
 dcb-app \- show / manipulate application priority table of
 the DCB (Data Center Bridging) subsystem
@@ -26,7 +26,7 @@ the DCB (Data Center Bridging) subsystem
 .RB "[ " pcp-prio " ]"
 
 .ti -8
-.B dcb ets " { " add " | " del " | " replace " } " dev
+.B dcb app " { " add " | " del " | " replace " } " dev
 .RI DEV
 .RB "[ " default-prio " " \fIPRIO-LIST\fB " ]"
 .RB "[ " ethtype-prio " " \fIET-MAP\fB " ]"
@@ -106,7 +106,7 @@ individual APP 3-tuples through
 .B add
 and
 .B del
-commands. On the other other hand, the command
+commands. On the other hand, the command
 .B replace
 does what one would typically want in this situation--first adds the new
 configuration, and then removes the obsolete one, so that only one
@@ -184,7 +184,7 @@ for details. Keys are DSCP points, values are priorities assigned to
 traffic with matching DSCP. DSCP points can be written either directly as
 numeric values, or using symbolic names specified in
 .B /etc/iproute2/rt_dsfield
-(however note that that file specifies full 8-bit dsfield values, whereas
+(however note that the file specifies full 8-bit dsfield values, whereas
 .B dcb app
 will only use the higher six bits).
 .B dcb app show
@@ -230,7 +230,7 @@ priority 4:
 .P
 # dcb app replace dev eth0 dscp-prio 24:4
 .br
-# dcb app show dev eth0 dscp-prio
+# dcb app -N show dev eth0 dscp-prio
 .br
 dscp-prio 0:0 24:4 48:6
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 02/12] dcb: app: replace occurrences of %d with %u for printing unsigned int
  2023-06-06  7:19 ` [PATCH iproute2-next v3 02/12] dcb: app: replace occurrences of %d with %u for printing unsigned int Daniel Machon
@ 2023-06-06  9:29   ` Petr Machata
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Machata @ 2023-06-06  9:29 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver


Daniel Machon <daniel.machon@microchip.com> writes:

> In preparation for changing the prototype of dcb_app_print_filtered(),
> replace occurrences of %d for printing unsigned integer, with %u as it
> ought to be.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>

Nice, thanks!

Reviewed-by: Petr Machata <me@pmachata.org>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 03/12] dcb: app: move colon printing out of callbacks
  2023-06-06  7:19 ` [PATCH iproute2-next v3 03/12] dcb: app: move colon printing out of callbacks Daniel Machon
@ 2023-06-06  9:32   ` Petr Machata
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Machata @ 2023-06-06  9:32 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver


Daniel Machon <daniel.machon@microchip.com> writes:

> In preparation for changing the prototype of dcb_app_print_filtered(),
> move the colon printing out of the callbacks, and into
> dcb_app_print_filtered().
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>

Reviewed-by: Petr Machata <me@pmachata.org>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 04/12] dcb: app: rename dcb_app_print_key_*() functions
  2023-06-06  7:19 ` [PATCH iproute2-next v3 04/12] dcb: app: rename dcb_app_print_key_*() functions Daniel Machon
@ 2023-06-06  9:34   ` Petr Machata
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Machata @ 2023-06-06  9:34 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver


Daniel Machon <daniel.machon@microchip.com> writes:

> In preparation for changing the prototype of dcb_app_print_filtered(),
> rename the _print_key_*() functions to _print_pid_*(), as the protocol
> can both be key and value with the introduction of dcb-rewr.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>

Reviewed-by: Petr Machata <me@pmachata.org>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 06/12] dcb: app: modify dcb_app_table_remove_replaced() for dcb-rewr reuse
  2023-06-06  7:19 ` [PATCH iproute2-next v3 06/12] dcb: app: modify dcb_app_table_remove_replaced() " Daniel Machon
@ 2023-06-06 13:10   ` Petr Machata
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Machata @ 2023-06-06 13:10 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver


Daniel Machon <daniel.machon@microchip.com> writes:

> When doing a replace command, entries are checked against selector and
> protocol. Rewrite requires the check to be against selector and
> priority.
>
> Adapt the existing dcb_app_table_remove_replace function for this, by
> using callback functions for selector, pid and prio checks.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>

Reviewed-by: Petr Machata <me@pmachata.org>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 07/12] dcb: app: expose functions required by dcb-rewr
  2023-06-06  7:19 ` [PATCH iproute2-next v3 07/12] dcb: app: expose functions required by dcb-rewr Daniel Machon
@ 2023-06-06 13:11   ` Petr Machata
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Machata @ 2023-06-06 13:11 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver


Daniel Machon <daniel.machon@microchip.com> writes:

> In preparation for the dcb-rewr implementation, expose required
> functions, and structs.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>

Reviewed-by: Petr Machata <me@pmachata.org>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 09/12] dcb: rewr: add symbol for max DSCP value
  2023-06-06  7:19 ` [PATCH iproute2-next v3 09/12] dcb: rewr: add symbol for max DSCP value Daniel Machon
@ 2023-06-06 13:14   ` Petr Machata
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Machata @ 2023-06-06 13:14 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver


Daniel Machon <daniel.machon@microchip.com> writes:

> A symbol, DCB_APP_PCP_MAX, for maximum PCP value, already exists. Lets
> add a symbol DCB_APP_DSCP_MAX and update accordingly.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>

Reviewed-by: Petr Machata <me@pmachata.org>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 08/12] dcb: rewr: add new dcb-rewr subcommand
  2023-06-06  7:19 ` [PATCH iproute2-next v3 08/12] dcb: rewr: add new dcb-rewr subcommand Daniel Machon
@ 2023-06-06 13:17   ` Petr Machata
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Machata @ 2023-06-06 13:17 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver


Daniel Machon <daniel.machon@microchip.com> writes:

> Add a new subcommand 'rewr' for configuring the in-kernel DCB rewrite
> table. The rewrite table of the kernel is similar to the APP table,
> therefore, much of the existing bookkeeping code from dcb-app, can be
> reused in the dcb-rewr implementation.
>
> Initially, only support for configuring PCP and DSCP-based rewrite has
> been added.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>

Reviewed-by: Petr Machata <me@pmachata.org>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 05/12] dcb: app: modify dcb_app_print_filtered() for dcb-rewr reuse
  2023-06-06  7:19 ` [PATCH iproute2-next v3 05/12] dcb: app: modify dcb_app_print_filtered() for dcb-rewr reuse Daniel Machon
@ 2023-06-06 14:08   ` Petr Machata
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Machata @ 2023-06-06 14:08 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver


Daniel Machon <daniel.machon@microchip.com> writes:

> 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.
>
> Also, printing the colon is now expected to be handled by the
> print_pid_prio() callback.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>

Reviewed-by: Petr Machata <me@pmachata.org>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 01/12] dcb: app: add new dcbnl attribute field
  2023-06-06  7:19 ` [PATCH iproute2-next v3 01/12] dcb: app: add new dcbnl attribute field Daniel Machon
@ 2023-06-06 15:00   ` Petr Machata
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Machata @ 2023-06-06 15:00 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver


Daniel Machon <daniel.machon@microchip.com> writes:

> Add a new field 'attr' to the dcb_app_table struct, in order to inject
> different dcbnl get/set attributes for APP and rewrite.
>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>

Reviewed-by: Petr Machata <me@pmachata.org>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand
  2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
                   ` (11 preceding siblings ...)
  2023-06-06  7:19 ` [PATCH iproute2-next v3 12/12] man: dcb-app: clean up a few mistakes Daniel Machon
@ 2023-06-09 21:50 ` patchwork-bot+netdevbpf
  12 siblings, 0 replies; 23+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-09 21:50 UTC (permalink / raw)
  To: Daniel Machon; +Cc: netdev, dsahern, stephen, petrm, UNGLinuxDriver, me

Hello:

This series was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:

On Tue, 6 Jun 2023 09:19:35 +0200 you wrote:
> ========================================================================
> Introduction:
> ========================================================================
> 
> This series introduces a new DCB subcommand: rewr, which is used to
> configure the in-kernel DCB rewrite table [1].
> 
> [...]

Here is the summary with links:
  - [iproute2-next,v3,01/12] dcb: app: add new dcbnl attribute field
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=1b276ffad53d
  - [iproute2-next,v3,02/12] dcb: app: replace occurrences of %d with %u for printing unsigned int
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=503e150007a1
  - [iproute2-next,v3,03/12] dcb: app: move colon printing out of callbacks
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=00d59f4013b8
  - [iproute2-next,v3,04/12] dcb: app: rename dcb_app_print_key_*() functions
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=b4a52658a06f
  - [iproute2-next,v3,05/12] dcb: app: modify dcb_app_print_filtered() for dcb-rewr reuse
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=a245bfe1c0c6
  - [iproute2-next,v3,06/12] dcb: app: modify dcb_app_table_remove_replaced() for dcb-rewr reuse
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=369a2df62a0d
  - [iproute2-next,v3,07/12] dcb: app: expose functions required by dcb-rewr
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=1be8ab537824
  - [iproute2-next,v3,08/12] dcb: rewr: add new dcb-rewr subcommand
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=1b2680f4696b
  - [iproute2-next,v3,09/12] dcb: rewr: add symbol for max DSCP value
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=19919442f1b1
  - [iproute2-next,v3,10/12] man: dcb-rewr: add new manpage for dcb-rewr
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=e97dcb5b150d
  - [iproute2-next,v3,11/12] man: dcb: add additional references under 'SEE ALSO'
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=9a3b4f7a5dee
  - [iproute2-next,v3,12/12] man: dcb-app: clean up a few mistakes
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=05241f063005

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2023-06-09 21:50 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06  7:19 [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand Daniel Machon
2023-06-06  7:19 ` [PATCH iproute2-next v3 01/12] dcb: app: add new dcbnl attribute field Daniel Machon
2023-06-06 15:00   ` Petr Machata
2023-06-06  7:19 ` [PATCH iproute2-next v3 02/12] dcb: app: replace occurrences of %d with %u for printing unsigned int Daniel Machon
2023-06-06  9:29   ` Petr Machata
2023-06-06  7:19 ` [PATCH iproute2-next v3 03/12] dcb: app: move colon printing out of callbacks Daniel Machon
2023-06-06  9:32   ` Petr Machata
2023-06-06  7:19 ` [PATCH iproute2-next v3 04/12] dcb: app: rename dcb_app_print_key_*() functions Daniel Machon
2023-06-06  9:34   ` Petr Machata
2023-06-06  7:19 ` [PATCH iproute2-next v3 05/12] dcb: app: modify dcb_app_print_filtered() for dcb-rewr reuse Daniel Machon
2023-06-06 14:08   ` Petr Machata
2023-06-06  7:19 ` [PATCH iproute2-next v3 06/12] dcb: app: modify dcb_app_table_remove_replaced() " Daniel Machon
2023-06-06 13:10   ` Petr Machata
2023-06-06  7:19 ` [PATCH iproute2-next v3 07/12] dcb: app: expose functions required by dcb-rewr Daniel Machon
2023-06-06 13:11   ` Petr Machata
2023-06-06  7:19 ` [PATCH iproute2-next v3 08/12] dcb: rewr: add new dcb-rewr subcommand Daniel Machon
2023-06-06 13:17   ` Petr Machata
2023-06-06  7:19 ` [PATCH iproute2-next v3 09/12] dcb: rewr: add symbol for max DSCP value Daniel Machon
2023-06-06 13:14   ` Petr Machata
2023-06-06  7:19 ` [PATCH iproute2-next v3 10/12] man: dcb-rewr: add new manpage for dcb-rewr Daniel Machon
2023-06-06  7:19 ` [PATCH iproute2-next v3 11/12] man: dcb: add additional references under 'SEE ALSO' Daniel Machon
2023-06-06  7:19 ` [PATCH iproute2-next v3 12/12] man: dcb-app: clean up a few mistakes Daniel Machon
2023-06-09 21:50 ` [PATCH iproute2-next v3 00/12] Introduce new dcb-rewr subcommand patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.