Skip to contentSkip to conversation

dcb: Support APP, DCBX objects

PATCH Applied Petr Machata 2 participants 9 messages Jan 2, 2021 – Jan 18, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover dcb: Support APP, DCBX objects

Add support to the dcb tool for the following two DCB objects:

- APP, which allows configuration of traffic prioritization rules based on several possible packet headers.

- DCBX, which is a 1-byte bitfield of flags that configure whether the DCBX protocol is implemented in the device or in the host, and which version of the protocol should be used.

Patch #1 adds a new helper for finding a name of a given dsfield value. This is useful for APP DSCP-to-priority rules, which can use human-readable DSCP names.

Patches #2, #3 and #4 extend existing interfaces for, respectively, parsing of the X:Y mappings, for setting a DCB object, and for getting a DCB object.

In patch #5, support for the command line argument -N / --Numeric is added. The APP tool later uses it to decide whether to format DSCP values as human-readable strings or as plain numbers.

Patches #6 and #7 add the subtools themselves and their man pages.

v2:
- Two patches dropped and sent to iproute2 branch as "dcb: Fixes". This patch set now depends on that one.
- Patch #5:
- Make it -N / --Numeric instead of -n / --no-nice-names
- Rename the flag from no_nice_names to numeric as well
- Patch #6:
- Adjust to s/no_nice_names/numeric/ from another patch.

Petr Machata (7):
lib: rt_names: Add rtnl_dsfield_get_name()
lib: Generalize parse_mapping()
dcb: Generalize dcb_set_attribute()
dcb: Generalize dcb_get_attribute()
dcb: Support -N to suppress translation to human-readable names
dcb: Add a subtool for the DCB APP object
dcb: Add a subtool for the DCBX object

 dcb/Makefile        |   8 +-
 dcb/dcb.c           | 193 +++++++++--
 dcb/dcb.h           |  20 ++
 dcb/dcb_app.c       | 796 ++++++++++++++++++++++++++++++++++++++++++++
 dcb/dcb_dcbx.c      | 192 +++++++++++
 include/rt_names.h  |   1 +
 include/utils.h     |   5 +
 lib/rt_names.c      |  20 +-
 lib/utils.c         |  37 +-
 man/man8/dcb-app.8  | 237 +++++++++++++
 man/man8/dcb-dcbx.8 | 108 ++++++
 man/man8/dcb.8      |  12 +-
 12 files changed, 1591 insertions(+), 38 deletions(-)
 create mode 100644 dcb/dcb_app.c
 create mode 100644 dcb/dcb_dcbx.c
 create mode 100644 man/man8/dcb-app.8
 create mode 100644 man/man8/dcb-dcbx.8
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/7 lib: rt_names: Add rtnl_dsfield_get_name()

For formatting DSCP (not full dsfield), it would be handy to be able to just get the name from the name table, and not get any of the remaining cruft related to formatting. Add a new entry point to just fetch the name table string uninterpreted. Use it from rtnl_dsfield_n2a().

---
 include/rt_names.h |  1 +
 lib/rt_names.c     | 20 ++++++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
include/rt_names.h +1 -0
index 990ed7f22e69..1835f3be2bed 100644
@@ -9,6 +9,7 @@ const char *rtnl_rtscope_n2a(int id, char *buf, int len);
 const char *rtnl_rttable_n2a(__u32 id, char *buf, int len);
 const char *rtnl_rtrealm_n2a(int id, char *buf, int len);
 const char *rtnl_dsfield_n2a(int id, char *buf, int len);
+const char *rtnl_dsfield_get_name(int id);
 const char *rtnl_group_n2a(int id, char *buf, int len);
 
 int rtnl_rtprot_a2n(__u32 *id, const char *arg);
lib/rt_names.c +16 -4
index ca0680a12150..b976471d7979 100644
@@ -479,18 +479,30 @@ static void rtnl_rtdsfield_initialize(void)
 
 const char *rtnl_dsfield_n2a(int id, char *buf, int len)
 {
+	const char *name;
+
 	if (id < 0 || id >= 256) {
 		snprintf(buf, len, "%d", id);
 		return buf;
 	}
+	if (!numeric) {
+		name = rtnl_dsfield_get_name(id);
+		if (name != NULL)
+			return name;
+	}
+	snprintf(buf, len, "0x%02x", id);
+	return buf;
+}
+
+const char *rtnl_dsfield_get_name(int id)
+{
+	if (id < 0 || id >= 256)
+		return NULL;
 	if (!rtnl_rtdsfield_tab[id]) {
 		if (!rtnl_rtdsfield_init)
 			rtnl_rtdsfield_initialize();
 	}
-	if (!numeric && rtnl_rtdsfield_tab[id])
-		return rtnl_rtdsfield_tab[id];
-	snprintf(buf, len, "0x%02x", id);
-	return buf;
+	return rtnl_rtdsfield_tab[id];
 }
 
 
Signature · 1 line
2.26.2
#2 lore raw

PATCH v2 2/7 lib: Generalize parse_mapping()

In reply to Petr Machata

The function parse_mapping() assumes the key is a number, with a single configurable exception, which is using "all" to mean "all possible keys". If a caller wishes to use symbolic names instead of numbers, they cannot reuse this function.

To facilitate reuse in these situations, convert parse_mapping() into a helper, parse_mapping_gen(), which instead of an allow-all boolean takes a generic key-parsing callback. Rewrite parse_mapping() in terms of this newly-added helper and add a pair of key parsers, one for just numbers, another for numbers and the keyword "all". Publish the latter as well.

---
 include/utils.h |  5 +++++
 lib/utils.c     | 37 +++++++++++++++++++++++++++++++------
 2 files changed, 36 insertions(+), 6 deletions(-)
include/utils.h +5 -0
index 1704392525a2..f1403f7306a0 100644
@@ -331,6 +331,11 @@ int parse_one_of(const char *msg, const char *realval, const char * const *list,
 		 size_t len, int *p_err);
 bool parse_on_off(const char *msg, const char *realval, int *p_err);
 
+int parse_mapping_num_all(__u32 *keyp, const char *key);
+int parse_mapping_gen(int *argcp, char ***argvp,
+		      int (*key_cb)(__u32 *keyp, const char *key),
+		      int (*mapping_cb)(__u32 key, char *value, void *data),
+		      void *mapping_cb_data);
 int parse_mapping(int *argcp, char ***argvp, bool allow_all,
 		  int (*mapping_cb)(__u32 key, char *value, void *data),
 		  void *mapping_cb_data);
lib/utils.c +31 -6
index de875639c608..90e58fa309d5 100644
@@ -1878,9 +1878,10 @@ bool parse_on_off(const char *msg, const char *realval, int *p_err)
 	return parse_one_of(msg, realval, values_on_off, ARRAY_SIZE(values_on_off), p_err);
 }
 
-int parse_mapping(int *argcp, char ***argvp, bool allow_all,
-		  int (*mapping_cb)(__u32 key, char *value, void *data),
-		  void *mapping_cb_data)
+int parse_mapping_gen(int *argcp, char ***argvp,
+		      int (*key_cb)(__u32 *keyp, const char *key),
+		      int (*mapping_cb)(__u32 key, char *value, void *data),
+		      void *mapping_cb_data)
 {
 	int argc = *argcp;
 	char **argv = *argvp;
@@ -1894,9 +1895,7 @@ int parse_mapping(int *argcp, char ***argvp, bool allow_all,
 			break;
 		*colon = '\0';
 
-		if (allow_all && matches(*argv, "all") == 0) {
-			key = (__u32) -1;
-		} else if (get_u32(&key, *argv, 0)) {
+		if (key_cb(&key, *argv)) {
 			ret = 1;
 			break;
 		}
@@ -1912,3 +1911,29 @@ int parse_mapping(int *argcp, char ***argvp, bool allow_all,
 	*argvp = argv;
 	return ret;
 }
+
+static int parse_mapping_num(__u32 *keyp, const char *key)
+{
+	return get_u32(keyp, key, 0);
+}
+
+int parse_mapping_num_all(__u32 *keyp, const char *key)
+{
+	if (matches(key, "all") == 0) {
+		*keyp = (__u32) -1;
+		return 0;
+	}
+	return parse_mapping_num(keyp, key);
+}
+
+int parse_mapping(int *argcp, char ***argvp, bool allow_all,
+		  int (*mapping_cb)(__u32 key, char *value, void *data),
+		  void *mapping_cb_data)
+{
+	if (allow_all)
+		return parse_mapping_gen(argcp, argvp, parse_mapping_num_all,
+					 mapping_cb, mapping_cb_data);
+	else
+		return parse_mapping_gen(argcp, argvp, parse_mapping_num,
+					 mapping_cb, mapping_cb_data);
+}
Signature · 1 line
2.26.2
#3 lore raw

PATCH v2 3/7 dcb: Generalize dcb_set_attribute()

In reply to Petr Machata

The function dcb_set_attribute() takes a fully-formed payload as an argument. For callers that need to build a nested attribute, such as is the case for DCB APP table, this is not great, because with libmnl, they would need to construct a separate netlink message just to pluck out the payload and hand it over to this function.

Currently, dcb_set_attribute() also always wraps the payload in an DCB_ATTR_IEEE container, because that is what all the dcb subtools so far needed. But that is not appropriate for DCBX in particular, and in fact a handful other attributes, as well as any CEE payloads.

Instead, generalize this code by adding parameters for constructing a custom payload and for fetching the response from a custom response attribute. Then add dcb_set_attribute_va(), which takes a callback to invoke in the right place for the nest to be built, and dcb_set_attribute_bare(), which is similar to dcb_set_attribute(), but does not encapsulate the payload in an IEEE container. Rewrite dcb_set_attribute() compatibly in terms of the new functions.

---
 dcb/dcb.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 dcb/dcb.h |  7 ++++
 2 files changed, 98 insertions(+), 8 deletions(-)
dcb/dcb.c +91 -8
index 6640deef5688..9bbbbfa74619 100644
@@ -94,12 +94,17 @@ static int dcb_get_attribute_cb(const struct nlmsghdr *nlh, void *data)
 	return mnl_attr_parse(nlh, sizeof(struct dcbmsg), dcb_get_attribute_attr_cb, data);
 }
 
+struct dcb_set_attribute_response {
+	int response_attr;
+};
+
 static int dcb_set_attribute_attr_cb(const struct nlattr *attr, void *data)
 {
+	struct dcb_set_attribute_response *resp = data;
 	uint16_t len;
 	uint8_t err;
 
-	if (mnl_attr_get_type(attr) != DCB_ATTR_IEEE)
+	if (mnl_attr_get_type(attr) != resp->response_attr)
 		return MNL_CB_OK;
 
 	len = mnl_attr_get_payload_len(attr);
@@ -172,19 +177,23 @@ int dcb_get_attribute(struct dcb *dcb, const char *dev, int attr, void *data, si
 	return 0;
 }
 
-int dcb_set_attribute(struct dcb *dcb, const char *dev, int attr, const void *data, size_t data_len)
+static int __dcb_set_attribute(struct dcb *dcb, int command, const char *dev,
+			       int (*cb)(struct dcb *, struct nlmsghdr *, void *),
+			       void *data, int response_attr)
 {
+	struct dcb_set_attribute_response resp = {
+		.response_attr = response_attr,
+	};
 	struct nlmsghdr *nlh;
-	struct nlattr *nest;
 	int ret;
 
-	nlh = dcb_prepare(dcb, dev, RTM_SETDCB, DCB_CMD_IEEE_SET);
+	nlh = dcb_prepare(dcb, dev, RTM_SETDCB, command);
 
-	nest = mnl_attr_nest_start(nlh, DCB_ATTR_IEEE);
-	mnl_attr_put(nlh, attr, data_len, data);
-	mnl_attr_nest_end(nlh, nest);
+	ret = cb(dcb, nlh, data);
+	if (ret)
+		return ret;
 
-	ret = dcb_talk(dcb, nlh, dcb_set_attribute_cb, NULL);
+	ret = dcb_talk(dcb, nlh, dcb_set_attribute_cb, &resp);
 	if (ret) {
 		perror("Attribute write");
 		return ret;
@@ -192,6 +201,80 @@ int dcb_set_attribute(struct dcb *dcb, const char *dev, int attr, const void *da
 	return 0;
 }
 
+struct dcb_set_attribute_ieee_cb {
+	int (*cb)(struct dcb *dcb, struct nlmsghdr *nlh, void *data);
+	void *data;
+};
+
+static int dcb_set_attribute_ieee_cb(struct dcb *dcb, struct nlmsghdr *nlh, void *data)
+{
+	struct dcb_set_attribute_ieee_cb *ieee_data = data;
+	struct nlattr *nest;
+	int ret;
+
+	nest = mnl_attr_nest_start(nlh, DCB_ATTR_IEEE);
+	ret = ieee_data->cb(dcb, nlh, ieee_data->data);
+	if (ret)
+		return ret;
+	mnl_attr_nest_end(nlh, nest);
+
+	return 0;
+}
+
+int dcb_set_attribute_va(struct dcb *dcb, int command, const char *dev,
+			 int (*cb)(struct dcb *dcb, struct nlmsghdr *nlh, void *data),
+			 void *data)
+{
+	struct dcb_set_attribute_ieee_cb ieee_data = {
+		.cb = cb,
+		.data = data,
+	};
+
+	return __dcb_set_attribute(dcb, command, dev,
+				   &dcb_set_attribute_ieee_cb, &ieee_data,
+				   DCB_ATTR_IEEE);
+}
+
+struct dcb_set_attribute {
+	int attr;
+	const void *data;
+	size_t data_len;
+};
+
+static int dcb_set_attribute_put(struct dcb *dcb, struct nlmsghdr *nlh, void *data)
+{
+	struct dcb_set_attribute *dsa = data;
+
+	mnl_attr_put(nlh, dsa->attr, dsa->data_len, dsa->data);
+	return 0;
+}
+
+int dcb_set_attribute(struct dcb *dcb, const char *dev, int attr, const void *data, size_t data_len)
+{
+	struct dcb_set_attribute dsa = {
+		.attr = attr,
+		.data = data,
+		.data_len = data_len,
+	};
+
+	return dcb_set_attribute_va(dcb, DCB_CMD_IEEE_SET, dev,
+				    &dcb_set_attribute_put, &dsa);
+}
+
+int dcb_set_attribute_bare(struct dcb *dcb, int command, const char *dev,
+			   int attr, const void *data, size_t data_len,
+			   int response_attr)
+{
+	struct dcb_set_attribute dsa = {
+		.attr = attr,
+		.data = data,
+		.data_len = data_len,
+	};
+
+	return __dcb_set_attribute(dcb, command, dev,
+				   &dcb_set_attribute_put, &dsa, response_attr);
+}
+
 void dcb_print_array_u8(const __u8 *array, size_t size)
 {
 	SPRINT_BUF(b);
dcb/dcb.h +7 -0
index 388a4204b95c..da14937c8925 100644
@@ -2,6 +2,7 @@
 #ifndef __DCB_H__
 #define __DCB_H__ 1
 
+#include <libmnl/libmnl.h>
 #include <stdbool.h>
 #include <stddef.h>
 
@@ -32,6 +33,12 @@ int dcb_get_attribute(struct dcb *dcb, const char *dev, int attr,
 		      void *data, size_t data_len);
 int dcb_set_attribute(struct dcb *dcb, const char *dev, int attr,
 		      const void *data, size_t data_len);
+int dcb_set_attribute_va(struct dcb *dcb, int command, const char *dev,
+			 int (*cb)(struct dcb *dcb, struct nlmsghdr *nlh, void *data),
+			 void *data);
+int dcb_set_attribute_bare(struct dcb *dcb, int command, const char *dev,
+			   int attr, const void *data, size_t data_len,
+			   int response_attr);
 
 void dcb_print_named_array(const char *json_name, const char *fp_name,
 			   const __u8 *array, size_t size,
Signature · 1 line
2.26.2
#4 lore raw

PATCH v2 4/7 dcb: Generalize dcb_get_attribute()

In reply to Petr Machata

The function dcb_get_attribute() assumes that the caller knows the exact size of the looked-for payload. It also assumes that the response comes wrapped in an DCB_ATTR_IEEE nest. The former assumption does not hold for the IEEE APP table, which has variable size. The latter one does not hold for DCBX, which is not IEEE-nested, and also for any CEE attributes, which would come CEE-nested.

Factor out the payload extractor from the current dcb_get_attribute() code, and put into a helper. Then rewrite dcb_get_attribute() compatibly in terms of the new function. Introduce dcb_get_attribute_va() as a thin wrapper for IEEE-nested access, and dcb_get_attribute_bare() for access to attributes that are not nested.

---
 dcb/dcb.c | 79 ++++++++++++++++++++++++++++++++++++++++++++-----------
 dcb/dcb.h |  4 +++
 2 files changed, 68 insertions(+), 15 deletions(-)
dcb/dcb.c +64 -15
index 9bbbbfa74619..89f9b0ec7ef9 100644
@@ -59,25 +59,19 @@ static void dcb_free(struct dcb *dcb)
 struct dcb_get_attribute {
 	struct dcb *dcb;
 	int attr;
-	void *data;
-	size_t data_len;
+	void *payload;
+	__u16 payload_len;
 };
 
 static int dcb_get_attribute_attr_ieee_cb(const struct nlattr *attr, void *data)
 {
 	struct dcb_get_attribute *ga = data;
-	uint16_t len;
 
 	if (mnl_attr_get_type(attr) != ga->attr)
 		return MNL_CB_OK;
 
-	len = mnl_attr_get_payload_len(attr);
-	if (len != ga->data_len) {
-		fprintf(stderr, "Wrong len %d, expected %zd\n", len, ga->data_len);
-		return MNL_CB_ERROR;
-	}
-
-	memcpy(ga->data, mnl_attr_get_payload(attr), ga->data_len);
+	ga->payload = mnl_attr_get_payload(attr);
+	ga->payload_len = mnl_attr_get_payload_len(attr);
 	return MNL_CB_STOP;
 }
 
@@ -94,6 +88,16 @@ static int dcb_get_attribute_cb(const struct nlmsghdr *nlh, void *data)
 	return mnl_attr_parse(nlh, sizeof(struct dcbmsg), dcb_get_attribute_attr_cb, data);
 }
 
+static int dcb_get_attribute_bare_cb(const struct nlmsghdr *nlh, void *data)
+{
+	/* Bare attributes (e.g. DCB_ATTR_DCBX) are not wrapped inside an IEEE
+	 * container, so this does not have to go through unpacking in
+	 * dcb_get_attribute_attr_cb().
+	 */
+	return mnl_attr_parse(nlh, sizeof(struct dcbmsg),
+			      dcb_get_attribute_attr_ieee_cb, data);
+}
+
 struct dcb_set_attribute_response {
 	int response_attr;
 };
@@ -155,25 +159,70 @@ static struct nlmsghdr *dcb_prepare(struct dcb *dcb, const char *dev,
 	return nlh;
 }
 
-int dcb_get_attribute(struct dcb *dcb, const char *dev, int attr, void *data, size_t data_len)
+static int __dcb_get_attribute(struct dcb *dcb, int command,
+			       const char *dev, int attr,
+			       void **payload_p, __u16 *payload_len_p,
+			       int (*get_attribute_cb)(const struct nlmsghdr *nlh,
+						       void *data))
 {
 	struct dcb_get_attribute ga;
 	struct nlmsghdr *nlh;
 	int ret;
 
-	nlh = dcb_prepare(dcb, dev, RTM_GETDCB, DCB_CMD_IEEE_GET);
+	nlh = dcb_prepare(dcb, dev, RTM_GETDCB, command);
 
 	ga = (struct dcb_get_attribute) {
 		.dcb = dcb,
 		.attr = attr,
-		.data = data,
-		.data_len = data_len,
+		.payload = NULL,
 	};
-	ret = dcb_talk(dcb, nlh, dcb_get_attribute_cb, &ga);
+	ret = dcb_talk(dcb, nlh, get_attribute_cb, &ga);
 	if (ret) {
 		perror("Attribute read");
 		return ret;
 	}
+	if (ga.payload == NULL) {
+		perror("Attribute not found");
+		return -ENOENT;
+	}
+
+	*payload_p = ga.payload;
+	*payload_len_p = ga.payload_len;
+	return 0;
+}
+
+int dcb_get_attribute_va(struct dcb *dcb, const char *dev, int attr,
+			 void **payload_p, __u16 *payload_len_p)
+{
+	return __dcb_get_attribute(dcb, DCB_CMD_IEEE_GET, dev, attr,
+				   payload_p, payload_len_p,
+				   dcb_get_attribute_cb);
+}
+
+int dcb_get_attribute_bare(struct dcb *dcb, int cmd, const char *dev, int attr,
+			   void **payload_p, __u16 *payload_len_p)
+{
+	return __dcb_get_attribute(dcb, cmd, dev, attr,
+				   payload_p, payload_len_p,
+				   dcb_get_attribute_bare_cb);
+}
+
+int dcb_get_attribute(struct dcb *dcb, const char *dev, int attr, void *data, size_t data_len)
+{
+	__u16 payload_len;
+	void *payload;
+	int ret;
+
+	ret = dcb_get_attribute_va(dcb, dev, attr, &payload, &payload_len);
+	if (ret)
+		return ret;
+
+	if (payload_len != data_len) {
+		fprintf(stderr, "Wrong len %d, expected %zd\n", payload_len, data_len);
+		return -EINVAL;
+	}
+
+	memcpy(data, payload, data_len);
 	return 0;
 }
 
dcb/dcb.h +4 -0
index da14937c8925..8c7327a43588 100644
@@ -33,9 +33,13 @@ int dcb_get_attribute(struct dcb *dcb, const char *dev, int attr,
 		      void *data, size_t data_len);
 int dcb_set_attribute(struct dcb *dcb, const char *dev, int attr,
 		      const void *data, size_t data_len);
+int dcb_get_attribute_va(struct dcb *dcb, const char *dev, int attr,
+			 void **payload_p, __u16 *payload_len_p);
 int dcb_set_attribute_va(struct dcb *dcb, int command, const char *dev,
 			 int (*cb)(struct dcb *dcb, struct nlmsghdr *nlh, void *data),
 			 void *data);
+int dcb_get_attribute_bare(struct dcb *dcb, int cmd, const char *dev, int attr,
+			   void **payload_p, __u16 *payload_len_p);
 int dcb_set_attribute_bare(struct dcb *dcb, int command, const char *dev,
 			   int attr, const void *data, size_t data_len,
 			   int response_attr);
Signature · 1 line
2.26.2
#5 lore raw

PATCH v2 5/7 dcb: Support -N to suppress translation to human-readable names

In reply to Petr Machata

Some DSCP values can be translated to symbolic names. That may not be always desirable. Introduce a command-line option similar to other tools, -N or --Numeric, to suppress this translation.

---

Notes:
v2:
- Make it -N / --Numeric instead of -n / --no-nice-names
- Rename the flag from no_nice_names to numeric as well

 dcb/dcb.c      | 9 +++++++--
 dcb/dcb.h      | 1 +
 man/man8/dcb.8 | 5 +++++
 3 files changed, 13 insertions(+), 2 deletions(-)
dcb/dcb.c +7 -2
index 89f9b0ec7ef9..cc5103da84a8 100644
@@ -467,7 +467,8 @@ static void dcb_help(void)
 		"       dcb [ -f | --force ] { -b | --batch } filename [ -n | --netns ] netnsname\n"
 		"where  OBJECT := { buffer | ets | maxrate | pfc }\n"
 		"       OPTIONS := [ -V | --Version | -i | --iec | -j | --json\n"
-		"                  | -p | --pretty | -s | --statistics | -v | --verbose]\n");
+		"                  | -N | --Numeric | -p | --pretty\n"
+		"                  | -s | --statistics | -v | --verbose]\n");
 }
 
 static int dcb_cmd(struct dcb *dcb, int argc, char **argv)
@@ -509,6 +510,7 @@ int main(int argc, char **argv)
 		{ "batch",		required_argument,	NULL, 'b' },
 		{ "iec",		no_argument,		NULL, 'i' },
 		{ "json",		no_argument,		NULL, 'j' },
+		{ "Numeric",		no_argument,		NULL, 'N' },
 		{ "pretty",		no_argument,		NULL, 'p' },
 		{ "statistics",		no_argument,		NULL, 's' },
 		{ "netns",		required_argument,	NULL, 'n' },
@@ -528,7 +530,7 @@ int main(int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	while ((opt = getopt_long(argc, argv, "b:fhijn:psvV",
+	while ((opt = getopt_long(argc, argv, "b:fhijn:psvNV",
 				  long_options, NULL)) >= 0) {
 
 		switch (opt) {
@@ -545,6 +547,9 @@ int main(int argc, char **argv)
 		case 'j':
 			dcb->json_output = true;
 			break;
+		case 'N':
+			dcb->numeric = true;
+			break;
 		case 'p':
 			pretty = true;
 			break;
dcb/dcb.h +1 -0
index 8c7327a43588..37657c594a78 100644
@@ -14,6 +14,7 @@ struct dcb {
 	bool json_output;
 	bool stats;
 	bool use_iec;
+	bool numeric;
 };
 
 int dcb_parse_mapping(const char *what_key, __u32 key, __u32 max_key,
man/man8/dcb.8 +5 -0
index 7293bb303577..1e161eb37a58 100644
@@ -59,6 +59,11 @@ the 1000-based ones (K, M, B).
 .BR "\-j" , " --json"
 Generate JSON output.
 
+.TP
+.BR "\-N" , " --Numeric"
+If the subtool in question translates numbers to symbolic names in some way,
+suppress this translation.
+
 .TP
 .BR "\-p" , " --pretty"
 When combined with -j generate a pretty JSON output.
Signature · 1 line
2.26.2
#6 lore raw

PATCH v2 6/7 dcb: Add a subtool for the DCB APP object

In reply to Petr Machata

DCB APP interfaces are standardized in 802.1q-2018, and allow configuration of traffic prioritization rules based on several possible headers.

Add a dcb subtool for maintenance and display of the APP table. For example:

    # dcb app add dev eni1np1 dscp-prio 0:0 CS3:3 CS6:6
    # dcb app show dev eni1np1
    dscp-prio 0:0 CS3:3 CS6:6
    # dcb app add dev eni1np1 dscp-prio CS3:4
    # dcb app show dev eni1np1
    dscp-prio 0:0 CS3:3 CS3:4 CS6:6
    # dcb app replace dev eni1np1 dscp-prio CS3:5
    # dcb app show dev eni1np1
    dscp-prio 0:0 CS3:5 CS6:6

---

Notes:
v2:
- Adjust to s/no_nice_names/numeric/ from another patch.
- s/-N/-n/ in man page

 dcb/Makefile       |   7 +-
 dcb/dcb.c          |   4 +-
 dcb/dcb.h          |   4 +
 dcb/dcb_app.c      | 796 +++++++++++++++++++++++++++++++++++++++++++++
 man/man8/dcb-app.8 | 237 ++++++++++++++
 man/man8/dcb.8     |   7 +-
 6 files changed, 1052 insertions(+), 3 deletions(-)
 create mode 100644 dcb/dcb_app.c
 create mode 100644 man/man8/dcb-app.8
dcb/Makefile +6 -1
index 4add954b4bba..13d45f2b96b1 100644
@@ -5,7 +5,12 @@ TARGETS :=
 
 ifeq ($(HAVE_MNL),y)
 
-DCBOBJ = dcb.o dcb_buffer.o dcb_ets.o dcb_maxrate.o dcb_pfc.o
+DCBOBJ = dcb.o \
+         dcb_app.o \
+         dcb_buffer.o \
+         dcb_ets.o \
+         dcb_maxrate.o \
+         dcb_pfc.o
 TARGETS += dcb
 
 endif
dcb/dcb.c +3 -1
index cc5103da84a8..644059c44ee7 100644
@@ -465,7 +465,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 := { buffer | ets | maxrate | pfc }\n"
+		"where  OBJECT := { app | buffer | ets | maxrate | pfc }\n"
 		"       OPTIONS := [ -V | --Version | -i | --iec | -j | --json\n"
 		"                  | -N | --Numeric | -p | --pretty\n"
 		"                  | -s | --statistics | -v | --verbose]\n");
@@ -476,6 +476,8 @@ static int dcb_cmd(struct dcb *dcb, int argc, char **argv)
 	if (!argc || matches(*argv, "help") == 0) {
 		dcb_help();
 		return 0;
+	} else if (matches(*argv, "app") == 0) {
+		return dcb_cmd_app(dcb, argc - 1, argv + 1);
 	} else if (matches(*argv, "buffer") == 0) {
 		return dcb_cmd_buffer(dcb, argc - 1, argv + 1);
 	} else if (matches(*argv, "ets") == 0) {
dcb/dcb.h +4 -0
index 37657c594a78..92eada169cd0 100644
@@ -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);
 
+/* dcb_app.c */
+
+int dcb_cmd_app(struct dcb *dcb, int argc, char **argv);
+
 /* dcb_buffer.c */
 
 int dcb_cmd_buffer(struct dcb *dcb, int argc, char **argv);
dcb/dcb_app.c new file +796 -0

796 lines not on this page · raw message

man/man8/dcb-app.8 new file +237 -0

237 lines not on this page · raw message

man/man8/dcb.8 +6 -1
index 1e161eb37a58..24944b73816b 100644
@@ -9,7 +9,7 @@ dcb \- show / manipulate DCB (Data Center Bridging) settings
 .ti -8
 .B dcb
 .RI "[ " OPTIONS " ] "
-.RB "{ " buffer " | " ets " | " maxrate " | " pfc " }"
+.RB "{ " app " | " buffer " | " ets " | " maxrate " | " pfc " }"
 .RI "{ " COMMAND " | " help " }"
 .sp
 
@@ -75,6 +75,10 @@ part of the "show" output.
 
 .SH OBJECTS
 
+.TP
+.B app
+- Configuration of application priority table
+
 .TP
 .B buffer
 - Configuration of port buffers
@@ -135,6 +139,7 @@ other values:
 Exit status is 0 if command was successful or a positive integer upon failure.
 
 .SH SEE ALSO
+.BR dcb-app (8),
 .BR dcb-buffer (8),
 .BR dcb-ets (8),
 .BR dcb-maxrate (8),
Signature · 1 line
2.26.2
#7 lore raw

PATCH v2 7/7 dcb: Add a subtool for the DCBX object

In reply to Petr Machata

The Linux DCBX object is a 1-byte bitfield of flags that configure whether the DCBX protocol is implemented in the device or in the host, and which version of the protocol should be used. Add a tool to access the per-port Linux DCBX object.

For example:

	# dcb dcbx set dev eni1np1 host ieee
	# dcb dcbx show dev eni1np1
	host ieee
---
 dcb/Makefile        |   1 +
 dcb/dcb.c           |   4 +-
 dcb/dcb.h           |   4 +
 dcb/dcb_dcbx.c      | 192 ++++++++++++++++++++++++++++++++++++++++++++
 man/man8/dcb-dcbx.8 | 108 +++++++++++++++++++++++++
 5 files changed, 308 insertions(+), 1 deletion(-)
 create mode 100644 dcb/dcb_dcbx.c
 create mode 100644 man/man8/dcb-dcbx.8
dcb/Makefile +1 -0
index 13d45f2b96b1..02d5d044cf09 100644
@@ -8,6 +8,7 @@ ifeq ($(HAVE_MNL),y)
 DCBOBJ = dcb.o \
          dcb_app.o \
          dcb_buffer.o \
+         dcb_dcbx.o \
          dcb_ets.o \
          dcb_maxrate.o \
          dcb_pfc.o
dcb/dcb.c +3 -1
index 644059c44ee7..64a9ef02d256 100644
@@ -465,7 +465,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 | buffer | ets | maxrate | pfc }\n"
+		"where  OBJECT := { app | buffer | dcbx | ets | maxrate | pfc }\n"
 		"       OPTIONS := [ -V | --Version | -i | --iec | -j | --json\n"
 		"                  | -N | --Numeric | -p | --pretty\n"
 		"                  | -s | --statistics | -v | --verbose]\n");
@@ -480,6 +480,8 @@ static int dcb_cmd(struct dcb *dcb, int argc, char **argv)
 		return dcb_cmd_app(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) {
+		return dcb_cmd_dcbx(dcb, argc - 1, argv + 1);
 	} else if (matches(*argv, "ets") == 0) {
 		return dcb_cmd_ets(dcb, argc - 1, argv + 1);
 	} else if (matches(*argv, "maxrate") == 0) {
dcb/dcb.h +4 -0
index 92eada169cd0..244c3d3c30e3 100644
@@ -62,6 +62,10 @@ int dcb_cmd_app(struct dcb *dcb, int argc, char **argv);
 
 int dcb_cmd_buffer(struct dcb *dcb, int argc, char **argv);
 
+/* dcb_dcbx.c */
+
+int dcb_cmd_dcbx(struct dcb *dcb, int argc, char **argv);
+
 /* dcb_ets.c */
 
 int dcb_cmd_ets(struct dcb *dcb, int argc, char **argv);
dcb/dcb_dcbx.c new file +192 -0

192 lines not on this page · raw message

man/man8/dcb-dcbx.8 new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
2.26.2
Applied
#8 lore raw
In reply to Petr Machata
Quoted 17 lines · Petr Machata

Add support to the dcb tool for the following two DCB objects:

- APP, which allows configuration of traffic prioritization rules based on several possible packet headers.

- DCBX, which is a 1-byte bitfield of flags that configure whether the DCBX protocol is implemented in the device or in the host, and which version of the protocol should be used.

Patch #1 adds a new helper for finding a name of a given dsfield value. This is useful for APP DSCP-to-priority rules, which can use human-readable DSCP names.

Patches #2, #3 and #4 extend existing interfaces for, respectively, parsing of the X:Y mappings, for setting a DCB object, and for getting a DCB object.

Quoted 6 lines

In patch #5, support for the command line argument -N / --Numeric is added. The APP tool later uses it to decide whether to format DSCP values as human-readable strings or as plain numbers.

Patches #6 and #7 add the subtools themselves and their man pages.

applied to iproute2-next.