netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2 0/4] Add support for dpipe's global header formatting
@ 2017-09-07 14:26 Arkadi Sharshevsky
  2017-09-07 14:26 ` [PATCH iproute2 1/4] devlink: Make match/action parsing more flexible Arkadi Sharshevsky
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Arkadi Sharshevsky @ 2017-09-07 14:26 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, jiri, mlxsw, andrew, Arkadi Sharshevsky

Some dpipe's global header values need special formatting, for example
Ethernet and IP addresses. This patchset adds support for IPv4/6 and
Ethernet's special format.

Arkadi Sharshevsky (4):
  devlink: Make match/action parsing more flexible
  devlink: Add support for special format protocol headers
  devlink: Update devlink UAPI file
  devlink: Add support for protocol IPv4/IPv6/Ethernet special formats

 devlink/devlink.c       | 319 +++++++++++++++++++++++++++++++++++++-----------
 include/linux/devlink.h |  18 +++
 2 files changed, 265 insertions(+), 72 deletions(-)

-- 
2.4.11

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

* [PATCH iproute2 1/4] devlink: Make match/action parsing more flexible
  2017-09-07 14:26 [PATCH iproute2 0/4] Add support for dpipe's global header formatting Arkadi Sharshevsky
@ 2017-09-07 14:26 ` Arkadi Sharshevsky
  2017-09-07 14:26 ` [PATCH iproute2 2/4] devlink: Add support for special format protocol headers Arkadi Sharshevsky
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Arkadi Sharshevsky @ 2017-09-07 14:26 UTC (permalink / raw)
  To: netdev
  Cc: davem, stephen, jiri, mlxsw, andrew, Arkadi Sharshevsky, Jiri Pirko

This patch decouples the match/action parsing from printing. This is
done as a preparation for adding the ability to print global header
values, for example print IPv4 address, which require special formatting.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/devlink.c | 127 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 80 insertions(+), 47 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 8f11f86..36a2b36 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -3077,27 +3077,42 @@ static const char
 	}
 }
 
-static void pr_out_dpipe_action(struct dpipe_ctx *ctx,
-				uint32_t header_id, uint32_t field_id,
-				uint32_t action_type, bool global)
+struct dpipe_op_info {
+	uint32_t header_id;
+	uint32_t field_id;
+	bool header_global;
+};
+
+struct dpipe_action {
+	struct dpipe_op_info info;
+	uint32_t type;
+};
+
+static void pr_out_dpipe_action(struct dpipe_action *action,
+				struct dpipe_ctx *ctx)
 {
+	struct dpipe_op_info *op_info = &action->info;
 	const char *mapping;
 
-	pr_out_str(ctx->dl, "type", dpipe_action_type_e2s(action_type));
-	pr_out_str(ctx->dl, "header", dpipe_header_id2s(ctx, header_id,
-							global));
-	pr_out_str(ctx->dl, "field", dpipe_field_id2s(ctx, header_id, field_id,
-						      global));
-	mapping = dpipe_mapping_get(ctx, header_id, field_id, global);
+	pr_out_str(ctx->dl, "type",
+		   dpipe_action_type_e2s(action->type));
+	pr_out_str(ctx->dl, "header",
+		   dpipe_header_id2s(ctx, op_info->header_id,
+				     op_info->header_global));
+	pr_out_str(ctx->dl, "field",
+		   dpipe_field_id2s(ctx, op_info->header_id,
+				    op_info->field_id,
+				    op_info->header_global));
+	mapping = dpipe_mapping_get(ctx, op_info->header_id,
+				    op_info->field_id,
+				    op_info->header_global);
 	if (mapping)
 		pr_out_str(ctx->dl, "mapping", mapping);
 }
 
-static int dpipe_action_show(struct dpipe_ctx *ctx, struct nlattr *nl)
+static int dpipe_action_parse(struct dpipe_action *action, struct nlattr *nl)
 {
 	struct nlattr *nla_action[DEVLINK_ATTR_MAX + 1] = {};
-	uint32_t header_id, field_id, action_type;
-	bool global;
 	int err;
 
 	err = mnl_attr_parse_nested(nl, attr_cb, nla_action);
@@ -3111,12 +3126,11 @@ static int dpipe_action_show(struct dpipe_ctx *ctx, struct nlattr *nl)
 		return -EINVAL;
 	}
 
-	header_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_HEADER_ID]);
-	field_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_FIELD_ID]);
-	action_type = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_ACTION_TYPE]);
-	global = !!mnl_attr_get_u8(nla_action[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);
+	action->type = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_ACTION_TYPE]);
+	action->info.header_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_HEADER_ID]);
+	action->info.field_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_FIELD_ID]);
+	action->info.header_global = !!mnl_attr_get_u8(nla_action[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);
 
-	pr_out_dpipe_action(ctx, header_id, field_id, action_type, global);
 	return 0;
 }
 
@@ -3124,16 +3138,18 @@ static int dpipe_table_actions_show(struct dpipe_ctx *ctx,
 				    struct nlattr *nla_actions)
 {
 	struct nlattr *nla_action;
+	struct dpipe_action action;
 
 	mnl_attr_for_each_nested(nla_action, nla_actions) {
 		pr_out_entry_start(ctx->dl);
-		if (dpipe_action_show(ctx, nla_action))
-			goto err_action_show;
+		if (dpipe_action_parse(&action, nla_action))
+			goto err_action_parse;
+		pr_out_dpipe_action(&action, ctx);
 		pr_out_entry_end(ctx->dl);
 	}
 	return 0;
 
-err_action_show:
+err_action_parse:
 	pr_out_entry_end(ctx->dl);
 	return -EINVAL;
 }
@@ -3149,28 +3165,38 @@ dpipe_match_type_e2s(enum devlink_dpipe_match_type match_type)
 	}
 }
 
-static void pr_out_dpipe_match(struct dpipe_ctx *ctx,
-			       uint32_t header_id, uint32_t field_id,
-			       uint32_t match_type, bool global)
+struct dpipe_match {
+	struct dpipe_op_info info;
+	uint32_t type;
+};
+
+static void pr_out_dpipe_match(struct dpipe_match *match,
+			       struct dpipe_ctx *ctx)
 {
+	struct dpipe_op_info *op_info = &match->info;
 	const char *mapping;
 
-	pr_out_str(ctx->dl, "type", dpipe_match_type_e2s(match_type));
-	pr_out_str(ctx->dl, "header", dpipe_header_id2s(ctx, header_id,
-							global));
-	pr_out_str(ctx->dl, "field", dpipe_field_id2s(ctx, header_id, field_id,
-						      global));
-	mapping = dpipe_mapping_get(ctx, header_id, field_id, global);
+	pr_out_str(ctx->dl, "type",
+		   dpipe_match_type_e2s(match->type));
+	pr_out_str(ctx->dl, "header",
+		   dpipe_header_id2s(ctx, op_info->header_id,
+				     op_info->header_global));
+	pr_out_str(ctx->dl, "field",
+		   dpipe_field_id2s(ctx, op_info->header_id,
+				    op_info->field_id,
+				    op_info->header_global));
+	mapping = dpipe_mapping_get(ctx, op_info->header_id,
+				    op_info->field_id,
+				    op_info->header_global);
 	if (mapping)
 		pr_out_str(ctx->dl, "mapping", mapping);
-
 }
 
-static int dpipe_match_show(struct dpipe_ctx *ctx, struct nlattr *nl)
+static int dpipe_match_parse(struct dpipe_match *match,
+			     struct nlattr *nl)
+
 {
 	struct nlattr *nla_match[DEVLINK_ATTR_MAX + 1] = {};
-	uint32_t header_id, field_id, match_type;
-	bool global;
 	int err;
 
 	err = mnl_attr_parse_nested(nl, attr_cb, nla_match);
@@ -3184,12 +3210,11 @@ static int dpipe_match_show(struct dpipe_ctx *ctx, struct nlattr *nl)
 		return -EINVAL;
 	}
 
-	match_type = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_MATCH_TYPE]);
-	header_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_HEADER_ID]);
-	field_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_FIELD_ID]);
-	global = !!mnl_attr_get_u8(nla_match[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);
+	match->type = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_MATCH_TYPE]);
+	match->info.header_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_HEADER_ID]);
+	match->info.field_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_FIELD_ID]);
+	match->info.header_global = !!mnl_attr_get_u8(nla_match[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);
 
-	pr_out_dpipe_match(ctx, header_id, field_id, match_type, global);
 	return 0;
 }
 
@@ -3197,16 +3222,18 @@ static int dpipe_table_matches_show(struct dpipe_ctx *ctx,
 				    struct nlattr *nla_matches)
 {
 	struct nlattr *nla_match;
+	struct dpipe_match match;
 
 	mnl_attr_for_each_nested(nla_match, nla_matches) {
 		pr_out_entry_start(ctx->dl);
-		if (dpipe_match_show(ctx, nla_match))
-			goto err_match_show;
+		if (dpipe_match_parse(&match, nla_match))
+			goto err_match_parse;
+		pr_out_dpipe_match(&match, ctx);
 		pr_out_entry_end(ctx->dl);
 	}
 	return 0;
 
-err_match_show:
+err_match_parse:
 	pr_out_entry_end(ctx->dl);
 	return -EINVAL;
 }
@@ -3382,6 +3409,7 @@ static int dpipe_entry_match_value_show(struct dpipe_ctx *ctx,
 					struct nlattr *nl)
 {
 	struct nlattr *nla_match_value[DEVLINK_ATTR_MAX + 1] = {};
+	struct dpipe_match match;
 	int err;
 
 	err = mnl_attr_parse_nested(nl, attr_cb, nla_match_value);
@@ -3394,16 +3422,18 @@ static int dpipe_entry_match_value_show(struct dpipe_ctx *ctx,
 	}
 
 	pr_out_entry_start(ctx->dl);
-	if (dpipe_match_show(ctx, nla_match_value[DEVLINK_ATTR_DPIPE_MATCH]))
-		goto err_match_show;
+	if (dpipe_match_parse(&match,
+			      nla_match_value[DEVLINK_ATTR_DPIPE_MATCH]))
+		goto err_match_parse;
+	pr_out_dpipe_match(&match, ctx);
 	if (dpipe_entry_value_show(ctx, nla_match_value))
 		goto err_value_show;
 	pr_out_entry_end(ctx->dl);
 
 	return 0;
 
-err_match_show:
 err_value_show:
+err_match_parse:
 	pr_out_entry_end(ctx->dl);
 	return -EINVAL;
 }
@@ -3412,6 +3442,7 @@ static int dpipe_entry_action_value_show(struct dpipe_ctx *ctx,
 					 struct nlattr *nl)
 {
 	struct nlattr *nla_action_value[DEVLINK_ATTR_MAX + 1] = {};
+	struct dpipe_action action;
 	int err;
 
 	err = mnl_attr_parse_nested(nl, attr_cb, nla_action_value);
@@ -3424,16 +3455,18 @@ static int dpipe_entry_action_value_show(struct dpipe_ctx *ctx,
 	}
 
 	pr_out_entry_start(ctx->dl);
-	if (dpipe_action_show(ctx, nla_action_value[DEVLINK_ATTR_DPIPE_ACTION]))
-		goto err_action_show;
+	if (dpipe_action_parse(&action,
+			       nla_action_value[DEVLINK_ATTR_DPIPE_ACTION]))
+		goto err_action_parse;
+	pr_out_dpipe_action(&action, ctx);
 	if (dpipe_entry_value_show(ctx, nla_action_value))
 		goto err_value_show;
 	pr_out_entry_end(ctx->dl);
 
 	return 0;
 
-err_action_show:
 err_value_show:
+err_action_parse:
 	pr_out_entry_end(ctx->dl);
 	return -EINVAL;
 }
-- 
2.4.11

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

* [PATCH iproute2 2/4] devlink: Add support for special format protocol headers
  2017-09-07 14:26 [PATCH iproute2 0/4] Add support for dpipe's global header formatting Arkadi Sharshevsky
  2017-09-07 14:26 ` [PATCH iproute2 1/4] devlink: Make match/action parsing more flexible Arkadi Sharshevsky
@ 2017-09-07 14:26 ` Arkadi Sharshevsky
  2017-09-07 14:26 ` [PATCH iproute2 3/4] devlink: Update devlink UAPI file Arkadi Sharshevsky
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Arkadi Sharshevsky @ 2017-09-07 14:26 UTC (permalink / raw)
  To: netdev
  Cc: davem, stephen, jiri, mlxsw, andrew, Arkadi Sharshevsky, Jiri Pirko

In case of global header (protocol header), the header:field ids are used
to perform lookup for special format printer. In case no printer existence
fallback to plain value printing.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/devlink.c | 119 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 94 insertions(+), 25 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 36a2b36..b87de38 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -3372,9 +3372,89 @@ static int cmd_dpipe_table_set(struct dl *dl)
 	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
 }
 
-static int dpipe_entry_value_show(struct dpipe_ctx *ctx,
-				  struct nlattr **nla_match_value)
+enum dpipe_value_type {
+	DPIPE_VALUE_TYPE_VALUE,
+	DPIPE_VALUE_TYPE_MASK,
+};
+
+static const char *
+dpipe_value_type_e2s(enum dpipe_value_type type)
+{
+	switch (type) {
+	case DPIPE_VALUE_TYPE_VALUE:
+		return "value";
+	case DPIPE_VALUE_TYPE_MASK:
+		return "value_mask";
+	default:
+		return "<unknown>";
+	}
+}
+
+struct dpipe_field_printer {
+	unsigned int field_id;
+	void (*printer)(struct dpipe_ctx *, enum dpipe_value_type, void *);
+};
+
+struct dpipe_header_printer {
+	struct dpipe_field_printer *printers;
+	unsigned int printers_count;
+	unsigned int header_id;
+};
+
+static struct dpipe_header_printer *dpipe_header_printers[] = {};
+
+static int dpipe_print_prot_header(struct dpipe_ctx *ctx,
+				   struct dpipe_op_info *info,
+				   enum dpipe_value_type type,
+				   void *value)
 {
+	unsigned int header_printers_count = ARRAY_SIZE(dpipe_header_printers);
+	struct dpipe_header_printer *header_printer;
+	struct dpipe_field_printer *field_printer;
+	unsigned int field_printers_count;
+	int j;
+	int i;
+
+	for (i = 0; i < header_printers_count; i++) {
+		header_printer = dpipe_header_printers[i];
+		if (header_printer->header_id != info->header_id)
+			continue;
+		field_printers_count = header_printer->printers_count;
+		for (j = 0; j < field_printers_count; j++) {
+			field_printer = &header_printer->printers[j];
+			if (field_printer->field_id != info->field_id)
+				continue;
+			field_printer->printer(ctx, type, value);
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static void __pr_out_entry_value(struct dpipe_ctx *ctx,
+				 void *value,
+				 unsigned int value_len,
+				 struct dpipe_op_info *info,
+				 enum dpipe_value_type type)
+{
+	if (info->header_global &&
+	    !dpipe_print_prot_header(ctx, info, type, value))
+		return;
+
+	if (value_len == sizeof(uint32_t)) {
+		uint32_t *value_32 = value;
+
+		pr_out_uint(ctx->dl, dpipe_value_type_e2s(type), *value_32);
+	}
+}
+
+static void pr_out_dpipe_entry_value(struct dpipe_ctx *ctx,
+				     struct nlattr **nla_match_value,
+				     struct dpipe_op_info *info)
+{
+	void *value, *value_mask;
+	uint32_t value_mapping;
 	uint16_t value_len;
 	bool mask, mapping;
 
@@ -3382,27 +3462,20 @@ static int dpipe_entry_value_show(struct dpipe_ctx *ctx,
 	mapping = !!nla_match_value[DEVLINK_ATTR_DPIPE_VALUE_MAPPING];
 
 	value_len = mnl_attr_get_payload_len(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE]);
-	if (value_len == sizeof(uint32_t)) {
-		uint32_t value, value_mask, value_mapping;
-
-		if (mapping) {
-			value_mapping = mnl_attr_get_u32(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE_MAPPING]);
-			pr_out_uint(ctx->dl, "mapping_value", value_mapping);
-		}
-
-		if (mask) {
-			value_mask = mnl_attr_get_u32(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE_MASK]);
-			pr_out_uint(ctx->dl, "mask_value", value_mask);
-		}
+	value = mnl_attr_get_payload(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE]);
 
-		value = mnl_attr_get_u32(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE]);
-		pr_out_uint(ctx->dl, "value", value);
+	if (mapping) {
+		value_mapping = mnl_attr_get_u32(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE_MAPPING]);
+		pr_out_uint(ctx->dl, "mapping_value", value_mapping);
+	}
 
-	} else {
-		return -EINVAL;
+	if (mask) {
+		value_mask = mnl_attr_get_payload(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE]);
+		__pr_out_entry_value(ctx, value_mask, value_len, info,
+				     DPIPE_VALUE_TYPE_MASK);
 	}
 
-	return 0;
+	__pr_out_entry_value(ctx, value, value_len, info, DPIPE_VALUE_TYPE_VALUE);
 }
 
 static int dpipe_entry_match_value_show(struct dpipe_ctx *ctx,
@@ -3426,13 +3499,11 @@ static int dpipe_entry_match_value_show(struct dpipe_ctx *ctx,
 			      nla_match_value[DEVLINK_ATTR_DPIPE_MATCH]))
 		goto err_match_parse;
 	pr_out_dpipe_match(&match, ctx);
-	if (dpipe_entry_value_show(ctx, nla_match_value))
-		goto err_value_show;
+	pr_out_dpipe_entry_value(ctx, nla_match_value, &match.info);
 	pr_out_entry_end(ctx->dl);
 
 	return 0;
 
-err_value_show:
 err_match_parse:
 	pr_out_entry_end(ctx->dl);
 	return -EINVAL;
@@ -3459,13 +3530,11 @@ static int dpipe_entry_action_value_show(struct dpipe_ctx *ctx,
 			       nla_action_value[DEVLINK_ATTR_DPIPE_ACTION]))
 		goto err_action_parse;
 	pr_out_dpipe_action(&action, ctx);
-	if (dpipe_entry_value_show(ctx, nla_action_value))
-		goto err_value_show;
+	pr_out_dpipe_entry_value(ctx, nla_action_value, &action.info);
 	pr_out_entry_end(ctx->dl);
 
 	return 0;
 
-err_value_show:
 err_action_parse:
 	pr_out_entry_end(ctx->dl);
 	return -EINVAL;
-- 
2.4.11

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

* [PATCH iproute2 3/4] devlink: Update devlink UAPI file
  2017-09-07 14:26 [PATCH iproute2 0/4] Add support for dpipe's global header formatting Arkadi Sharshevsky
  2017-09-07 14:26 ` [PATCH iproute2 1/4] devlink: Make match/action parsing more flexible Arkadi Sharshevsky
  2017-09-07 14:26 ` [PATCH iproute2 2/4] devlink: Add support for special format protocol headers Arkadi Sharshevsky
@ 2017-09-07 14:26 ` Arkadi Sharshevsky
  2017-09-07 22:12   ` Stephen Hemminger
  2017-09-07 14:26 ` [PATCH iproute2 4/4] devlink: Add support for protocol IPv4/IPv6/Ethernet special formats Arkadi Sharshevsky
  2017-09-07 22:13 ` [PATCH iproute2 0/4] Add support for dpipe's global header formatting Stephen Hemminger
  4 siblings, 1 reply; 7+ messages in thread
From: Arkadi Sharshevsky @ 2017-09-07 14:26 UTC (permalink / raw)
  To: netdev
  Cc: davem, stephen, jiri, mlxsw, andrew, Arkadi Sharshevsky, Jiri Pirko

Update devlink UAPI file.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
 include/linux/devlink.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/linux/devlink.h b/include/linux/devlink.h
index 7644005..a62695e 100644
--- a/include/linux/devlink.h
+++ b/include/linux/devlink.h
@@ -226,4 +226,22 @@ enum devlink_dpipe_action_type {
 	DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY,
 };
 
+enum devlink_dpipe_field_ethernet_id {
+	DEVLINK_DPIPE_FIELD_ETHERNET_DST_MAC,
+};
+
+enum devlink_dpipe_field_ipv4_id {
+	DEVLINK_DPIPE_FIELD_IPV4_DST_IP,
+};
+
+enum devlink_dpipe_field_ipv6_id {
+	DEVLINK_DPIPE_FIELD_IPV6_DST_IP,
+};
+
+enum devlink_dpipe_header_id {
+	DEVLINK_DPIPE_HEADER_ETHERNET,
+	DEVLINK_DPIPE_HEADER_IPV4,
+	DEVLINK_DPIPE_HEADER_IPV6,
+};
+
 #endif /* _LINUX_DEVLINK_H_ */
-- 
2.4.11

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

* [PATCH iproute2 4/4] devlink: Add support for protocol IPv4/IPv6/Ethernet special formats
  2017-09-07 14:26 [PATCH iproute2 0/4] Add support for dpipe's global header formatting Arkadi Sharshevsky
                   ` (2 preceding siblings ...)
  2017-09-07 14:26 ` [PATCH iproute2 3/4] devlink: Update devlink UAPI file Arkadi Sharshevsky
@ 2017-09-07 14:26 ` Arkadi Sharshevsky
  2017-09-07 22:13 ` [PATCH iproute2 0/4] Add support for dpipe's global header formatting Stephen Hemminger
  4 siblings, 0 replies; 7+ messages in thread
From: Arkadi Sharshevsky @ 2017-09-07 14:26 UTC (permalink / raw)
  To: netdev
  Cc: davem, stephen, jiri, mlxsw, andrew, Arkadi Sharshevsky, Jiri Pirko

Add support for protocol IPv4/IPv6/Ethernet special formats.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/devlink.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index b87de38..39cda06 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -20,6 +20,7 @@
 #include <linux/genetlink.h>
 #include <linux/devlink.h>
 #include <libmnl/libmnl.h>
+#include <netinet/ether.h>
 
 #include "SNAPSHOT.h"
 #include "list.h"
@@ -3401,7 +3402,79 @@ struct dpipe_header_printer {
 	unsigned int header_id;
 };
 
-static struct dpipe_header_printer *dpipe_header_printers[] = {};
+static void dpipe_field_printer_ipv4_addr(struct dpipe_ctx *ctx,
+					  enum dpipe_value_type type,
+					  void *value)
+{
+	struct in_addr ip_addr;
+
+	ip_addr.s_addr = htonl(*(uint32_t *)value);
+	pr_out_str(ctx->dl, dpipe_value_type_e2s(type), inet_ntoa(ip_addr));
+}
+
+static void
+dpipe_field_printer_ethernet_addr(struct dpipe_ctx *ctx,
+				  enum dpipe_value_type type,
+				  void *value)
+{
+	pr_out_str(ctx->dl, dpipe_value_type_e2s(type),
+		   ether_ntoa((struct ether_addr *)value));
+}
+
+static void dpipe_field_printer_ipv6_addr(struct dpipe_ctx *ctx,
+					  enum dpipe_value_type type,
+					  void *value)
+{
+	char str[INET6_ADDRSTRLEN];
+
+	inet_ntop(AF_INET6, value, str, INET6_ADDRSTRLEN);
+	pr_out_str(ctx->dl, dpipe_value_type_e2s(type), str);
+}
+
+static struct dpipe_field_printer dpipe_field_printers_ipv4[] = {
+	{
+		.printer = dpipe_field_printer_ipv4_addr,
+		.field_id = DEVLINK_DPIPE_FIELD_IPV4_DST_IP,
+	}
+};
+
+static struct dpipe_header_printer dpipe_header_printer_ipv4  = {
+	.printers = dpipe_field_printers_ipv4,
+	.printers_count = ARRAY_SIZE(dpipe_field_printers_ipv4),
+	.header_id = DEVLINK_DPIPE_HEADER_IPV4,
+};
+
+static struct dpipe_field_printer dpipe_field_printers_ethernet[] = {
+	{
+		.printer = dpipe_field_printer_ethernet_addr,
+		.field_id = DEVLINK_DPIPE_FIELD_ETHERNET_DST_MAC,
+	},
+};
+
+static struct dpipe_header_printer dpipe_header_printer_ethernet = {
+	.printers = dpipe_field_printers_ethernet,
+	.printers_count = ARRAY_SIZE(dpipe_field_printers_ethernet),
+	.header_id = DEVLINK_DPIPE_HEADER_ETHERNET,
+};
+
+static struct dpipe_field_printer dpipe_field_printers_ipv6[] = {
+	{
+		.printer = dpipe_field_printer_ipv6_addr,
+		.field_id = DEVLINK_DPIPE_FIELD_IPV6_DST_IP,
+	}
+};
+
+static struct dpipe_header_printer dpipe_header_printer_ipv6 = {
+	.printers = dpipe_field_printers_ipv6,
+	.printers_count = ARRAY_SIZE(dpipe_field_printers_ipv6),
+	.header_id = DEVLINK_DPIPE_HEADER_IPV6,
+};
+
+static struct dpipe_header_printer *dpipe_header_printers[] = {
+	&dpipe_header_printer_ipv4,
+	&dpipe_header_printer_ethernet,
+	&dpipe_header_printer_ipv6,
+};
 
 static int dpipe_print_prot_header(struct dpipe_ctx *ctx,
 				   struct dpipe_op_info *info,
-- 
2.4.11

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

* Re: [PATCH iproute2 3/4] devlink: Update devlink UAPI file
  2017-09-07 14:26 ` [PATCH iproute2 3/4] devlink: Update devlink UAPI file Arkadi Sharshevsky
@ 2017-09-07 22:12   ` Stephen Hemminger
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2017-09-07 22:12 UTC (permalink / raw)
  To: Arkadi Sharshevsky; +Cc: netdev, davem, jiri, mlxsw, andrew, Jiri Pirko

On Thu,  7 Sep 2017 17:26:42 +0300
Arkadi Sharshevsky <arkadis@mellanox.com> wrote:

> Update devlink UAPI file.
> 
> Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
> ---
>  include/linux/devlink.h | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/include/linux/devlink.h b/include/linux/devlink.h
> index 7644005..a62695e 100644
> --- a/include/linux/devlink.h
> +++ b/include/linux/devlink.h
> @@ -226,4 +226,22 @@ enum devlink_dpipe_action_type {
>  	DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY,
>  };
>  
> +enum devlink_dpipe_field_ethernet_id {
> +	DEVLINK_DPIPE_FIELD_ETHERNET_DST_MAC,
> +};
> +
> +enum devlink_dpipe_field_ipv4_id {
> +	DEVLINK_DPIPE_FIELD_IPV4_DST_IP,
> +};
> +
> +enum devlink_dpipe_field_ipv6_id {
> +	DEVLINK_DPIPE_FIELD_IPV6_DST_IP,
> +};
> +
> +enum devlink_dpipe_header_id {
> +	DEVLINK_DPIPE_HEADER_ETHERNET,
> +	DEVLINK_DPIPE_HEADER_IPV4,
> +	DEVLINK_DPIPE_HEADER_IPV6,
> +};
> +
>  #endif /* _LINUX_DEVLINK_H_ */

This patch was unnecessary. Already had updated file present.

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

* Re: [PATCH iproute2 0/4] Add support for dpipe's global header formatting
  2017-09-07 14:26 [PATCH iproute2 0/4] Add support for dpipe's global header formatting Arkadi Sharshevsky
                   ` (3 preceding siblings ...)
  2017-09-07 14:26 ` [PATCH iproute2 4/4] devlink: Add support for protocol IPv4/IPv6/Ethernet special formats Arkadi Sharshevsky
@ 2017-09-07 22:13 ` Stephen Hemminger
  4 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2017-09-07 22:13 UTC (permalink / raw)
  To: Arkadi Sharshevsky; +Cc: netdev, davem, jiri, mlxsw, andrew

On Thu,  7 Sep 2017 17:26:39 +0300
Arkadi Sharshevsky <arkadis@mellanox.com> wrote:

> Some dpipe's global header values need special formatting, for example
> Ethernet and IP addresses. This patchset adds support for IPv4/6 and
> Ethernet's special format.
> 
> Arkadi Sharshevsky (4):
>   devlink: Make match/action parsing more flexible
>   devlink: Add support for special format protocol headers
>   devlink: Update devlink UAPI file
>   devlink: Add support for protocol IPv4/IPv6/Ethernet special formats
> 
>  devlink/devlink.c       | 319 +++++++++++++++++++++++++++++++++++++-----------
>  include/linux/devlink.h |  18 +++
>  2 files changed, 265 insertions(+), 72 deletions(-)
> 

Applied 1,2 and 4.  #3 was not needed.

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

end of thread, other threads:[~2017-09-07 22:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-07 14:26 [PATCH iproute2 0/4] Add support for dpipe's global header formatting Arkadi Sharshevsky
2017-09-07 14:26 ` [PATCH iproute2 1/4] devlink: Make match/action parsing more flexible Arkadi Sharshevsky
2017-09-07 14:26 ` [PATCH iproute2 2/4] devlink: Add support for special format protocol headers Arkadi Sharshevsky
2017-09-07 14:26 ` [PATCH iproute2 3/4] devlink: Update devlink UAPI file Arkadi Sharshevsky
2017-09-07 22:12   ` Stephen Hemminger
2017-09-07 14:26 ` [PATCH iproute2 4/4] devlink: Add support for protocol IPv4/IPv6/Ethernet special formats Arkadi Sharshevsky
2017-09-07 22:13 ` [PATCH iproute2 0/4] Add support for dpipe's global header formatting Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).