All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Subject: [PATCH 02/12] ethdev: add flow API rule copy function
Date: Fri,  3 Mar 2017 16:40:24 +0100	[thread overview]
Message-ID: <8cc5c40c704f2d2600196cf8d65655fb90a5436b.1488550982.git.gaetan.rivet@6wind.com> (raw)
In-Reply-To: <cover.1488550982.git.gaetan.rivet@6wind.com>

Take this helper from the testpmd app to offer it alongside the flow
API.

This allows PMDs and applications to save flow rules in their generic
format for later processing. This is useful when rules cannot be applied
immediately, such as when the device is not properly initialized.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 app/test-pmd/config.c       | 263 +++++++---------------------------------
 app/test-pmd/testpmd.h      |   5 +-
 lib/librte_ether/rte_flow.c | 283 ++++++++++++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_flow.h |  59 +++++++++
 4 files changed, 387 insertions(+), 223 deletions(-)

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 54e38c4..f20e258 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -932,208 +932,6 @@ port_mtu_set(portid_t port_id, uint16_t mtu)
 	printf("Set MTU failed. diag=%d\n", diag);
 }
 
-/* Generic flow management functions. */
-
-/** Generate flow_item[] entry. */
-#define MK_FLOW_ITEM(t, s) \
-	[RTE_FLOW_ITEM_TYPE_ ## t] = { \
-		.name = # t, \
-		.size = s, \
-	}
-
-/** Information about known flow pattern items. */
-static const struct {
-	const char *name;
-	size_t size;
-} flow_item[] = {
-	MK_FLOW_ITEM(END, 0),
-	MK_FLOW_ITEM(VOID, 0),
-	MK_FLOW_ITEM(INVERT, 0),
-	MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
-	MK_FLOW_ITEM(PF, 0),
-	MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
-	MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)),
-	MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */
-	MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
-	MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
-	MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
-	MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
-	MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
-	MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
-	MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
-	MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
-	MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
-};
-
-/** Compute storage space needed by item specification. */
-static void
-flow_item_spec_size(const struct rte_flow_item *item,
-		    size_t *size, size_t *pad)
-{
-	if (!item->spec)
-		goto empty;
-	switch (item->type) {
-		union {
-			const struct rte_flow_item_raw *raw;
-		} spec;
-
-	case RTE_FLOW_ITEM_TYPE_RAW:
-		spec.raw = item->spec;
-		*size = offsetof(struct rte_flow_item_raw, pattern) +
-			spec.raw->length * sizeof(*spec.raw->pattern);
-		break;
-	default:
-empty:
-		*size = 0;
-		break;
-	}
-	*pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
-}
-
-/** Generate flow_action[] entry. */
-#define MK_FLOW_ACTION(t, s) \
-	[RTE_FLOW_ACTION_TYPE_ ## t] = { \
-		.name = # t, \
-		.size = s, \
-	}
-
-/** Information about known flow actions. */
-static const struct {
-	const char *name;
-	size_t size;
-} flow_action[] = {
-	MK_FLOW_ACTION(END, 0),
-	MK_FLOW_ACTION(VOID, 0),
-	MK_FLOW_ACTION(PASSTHRU, 0),
-	MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
-	MK_FLOW_ACTION(FLAG, 0),
-	MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
-	MK_FLOW_ACTION(DROP, 0),
-	MK_FLOW_ACTION(COUNT, 0),
-	MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
-	MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */
-	MK_FLOW_ACTION(PF, 0),
-	MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
-};
-
-/** Compute storage space needed by action configuration. */
-static void
-flow_action_conf_size(const struct rte_flow_action *action,
-		      size_t *size, size_t *pad)
-{
-	if (!action->conf)
-		goto empty;
-	switch (action->type) {
-		union {
-			const struct rte_flow_action_rss *rss;
-		} conf;
-
-	case RTE_FLOW_ACTION_TYPE_RSS:
-		conf.rss = action->conf;
-		*size = offsetof(struct rte_flow_action_rss, queue) +
-			conf.rss->num * sizeof(*conf.rss->queue);
-		break;
-	default:
-empty:
-		*size = 0;
-		break;
-	}
-	*pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
-}
-
-/** Generate a port_flow entry from attributes/pattern/actions. */
-static struct port_flow *
-port_flow_new(const struct rte_flow_attr *attr,
-	      const struct rte_flow_item *pattern,
-	      const struct rte_flow_action *actions)
-{
-	const struct rte_flow_item *item;
-	const struct rte_flow_action *action;
-	struct port_flow *pf = NULL;
-	size_t tmp;
-	size_t pad;
-	size_t off1 = 0;
-	size_t off2 = 0;
-	int err = ENOTSUP;
-
-store:
-	item = pattern;
-	if (pf)
-		pf->pattern = (void *)&pf->data[off1];
-	do {
-		struct rte_flow_item *dst = NULL;
-
-		if ((unsigned int)item->type >= RTE_DIM(flow_item) ||
-		    !flow_item[item->type].name)
-			goto notsup;
-		if (pf)
-			dst = memcpy(pf->data + off1, item, sizeof(*item));
-		off1 += sizeof(*item);
-		flow_item_spec_size(item, &tmp, &pad);
-		if (item->spec) {
-			if (pf)
-				dst->spec = memcpy(pf->data + off2,
-						   item->spec, tmp);
-			off2 += tmp + pad;
-		}
-		if (item->last) {
-			if (pf)
-				dst->last = memcpy(pf->data + off2,
-						   item->last, tmp);
-			off2 += tmp + pad;
-		}
-		if (item->mask) {
-			if (pf)
-				dst->mask = memcpy(pf->data + off2,
-						   item->mask, tmp);
-			off2 += tmp + pad;
-		}
-		off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
-	} while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
-	off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
-	action = actions;
-	if (pf)
-		pf->actions = (void *)&pf->data[off1];
-	do {
-		struct rte_flow_action *dst = NULL;
-
-		if ((unsigned int)action->type >= RTE_DIM(flow_action) ||
-		    !flow_action[action->type].name)
-			goto notsup;
-		if (pf)
-			dst = memcpy(pf->data + off1, action, sizeof(*action));
-		off1 += sizeof(*action);
-		flow_action_conf_size(action, &tmp, &pad);
-		if (action->conf) {
-			if (pf)
-				dst->conf = memcpy(pf->data + off2,
-						   action->conf, tmp);
-			off2 += tmp + pad;
-		}
-		off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
-	} while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
-	if (pf != NULL)
-		return pf;
-	off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
-	tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double));
-	pf = calloc(1, tmp + off1 + off2);
-	if (pf == NULL)
-		err = errno;
-	else {
-		*pf = (const struct port_flow){
-			.size = tmp + off1 + off2,
-			.attr = *attr,
-		};
-		tmp -= offsetof(struct port_flow, data);
-		off2 = tmp + off1;
-		off1 = tmp;
-		goto store;
-	}
-notsup:
-	rte_errno = err;
-	return NULL;
-}
-
 /** Print a message out of a flow error. */
 static int
 port_flow_complain(struct rte_flow_error *error)
@@ -1186,6 +984,28 @@ port_flow_validate(portid_t port_id,
 	return 0;
 }
 
+/** Generate a port_flow entry from attributes/pattern/actions. */
+static struct port_flow *
+port_flow_new(const struct rte_flow_attr *attr,
+	      const struct rte_flow_item *pattern,
+	      const struct rte_flow_action *actions)
+{
+	struct port_flow *pf;
+
+	pf = calloc(1, sizeof(struct port_flow));
+	if (!pf)
+		return NULL;
+
+	pf->fd = rte_flow_copy(attr, pattern, actions, NULL);
+	if (pf->fd == NULL) {
+		free(pf);
+		return NULL;
+	}
+	pf->size += pf->fd->size;
+
+	return pf;
+}
+
 /** Create flow rule. */
 int
 port_flow_create(portid_t port_id,
@@ -1265,6 +1085,7 @@ port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
 			}
 			printf("Flow rule #%u destroyed\n", pf->id);
 			*tmp = pf->next;
+			free(pf->fd);
 			free(pf);
 			break;
 		}
@@ -1325,11 +1146,11 @@ port_flow_query(portid_t port_id, uint32_t rule,
 		printf("Flow rule #%u not found\n", rule);
 		return -ENOENT;
 	}
-	if ((unsigned int)action >= RTE_DIM(flow_action) ||
-	    !flow_action[action].name)
+	if ((unsigned int)action >= RTE_FLOW_ACTION_TYPE_MAX ||
+	    !rte_flow_desc_data_action[action].name)
 		name = "unknown";
 	else
-		name = flow_action[action].name;
+		name = rte_flow_desc_data_action[action].name;
 	switch (action) {
 	case RTE_FLOW_ACTION_TYPE_COUNT:
 		break;
@@ -1385,18 +1206,18 @@ port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
 		if (n) {
 			/* Filter out unwanted groups. */
 			for (i = 0; i != n; ++i)
-				if (pf->attr.group == group[i])
+				if (pf->fd->attr.group == group[i])
 					break;
 			if (i == n)
 				continue;
 		}
 		tmp = &list;
 		while (*tmp &&
-		       (pf->attr.group > (*tmp)->attr.group ||
-			(pf->attr.group == (*tmp)->attr.group &&
-			 pf->attr.priority > (*tmp)->attr.priority) ||
-			(pf->attr.group == (*tmp)->attr.group &&
-			 pf->attr.priority == (*tmp)->attr.priority &&
+		       (pf->fd->attr.group > (*tmp)->fd->attr.group ||
+			(pf->fd->attr.group == (*tmp)->fd->attr.group &&
+			 pf->fd->attr.priority > (*tmp)->fd->attr.priority) ||
+			(pf->fd->attr.group == (*tmp)->fd->attr.group &&
+			 pf->fd->attr.priority == (*tmp)->fd->attr.priority &&
 			 pf->id > (*tmp)->id)))
 			tmp = &(*tmp)->tmp;
 		pf->tmp = *tmp;
@@ -1404,24 +1225,28 @@ port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
 	}
 	printf("ID\tGroup\tPrio\tAttr\tRule\n");
 	for (pf = list; pf != NULL; pf = pf->tmp) {
-		const struct rte_flow_item *item = pf->pattern;
-		const struct rte_flow_action *action = pf->actions;
+		const struct rte_flow_item *item = pf->fd->items;
+		const struct rte_flow_action *action = pf->fd->actions;
 
 		printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t",
 		       pf->id,
-		       pf->attr.group,
-		       pf->attr.priority,
-		       pf->attr.ingress ? 'i' : '-',
-		       pf->attr.egress ? 'e' : '-');
+		       pf->fd->attr.group,
+		       pf->fd->attr.priority,
+		       pf->fd->attr.ingress ? 'i' : '-',
+		       pf->fd->attr.egress ? 'e' : '-');
 		while (item->type != RTE_FLOW_ITEM_TYPE_END) {
 			if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
-				printf("%s ", flow_item[item->type].name);
+				printf("%s ",
+				       rte_flow_desc_data_item[item->type].
+									name);
 			++item;
 		}
 		printf("=>");
 		while (action->type != RTE_FLOW_ACTION_TYPE_END) {
 			if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
-				printf(" %s", flow_action[action->type].name);
+				printf(" %s",
+				       rte_flow_desc_data_action[action->type].
+									name);
 			++action;
 		}
 		printf("\n");
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 85d3e82..6002388 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -153,10 +153,7 @@ struct port_flow {
 	struct port_flow *tmp; /**< Temporary linking. */
 	uint32_t id; /**< Flow rule ID. */
 	struct rte_flow *flow; /**< Opaque flow object returned by PMD. */
-	struct rte_flow_attr attr; /**< Attributes. */
-	struct rte_flow_item *pattern; /**< Pattern. */
-	struct rte_flow_action *actions; /**< Actions. */
-	uint8_t data[]; /**< Storage for pattern/actions. */
+	struct rte_flow_desc *fd; /**< Generic flow description */
 };
 
 /**
diff --git a/lib/librte_ether/rte_flow.c b/lib/librte_ether/rte_flow.c
index aaa70d6..c8e2e93 100644
--- a/lib/librte_ether/rte_flow.c
+++ b/lib/librte_ether/rte_flow.c
@@ -33,6 +33,7 @@
 
 #include <stdint.h>
 
+#include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_branch_prediction.h>
 #include "rte_ethdev.h"
@@ -157,3 +158,285 @@ rte_flow_query(uint8_t port_id,
 				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				   NULL, rte_strerror(ENOSYS));
 }
+
+/** Information about known flow pattern items. */
+const struct rte_flow_desc_data rte_flow_desc_data_item[] = {
+	[RTE_FLOW_ITEM_TYPE_END] = {
+		.name = "END",
+		.size = 0,
+	},
+	[RTE_FLOW_ITEM_TYPE_VOID] = {
+		.name = "VOID",
+		.size = 0,
+	},
+	[RTE_FLOW_ITEM_TYPE_INVERT] = {
+		.name = "INVERT",
+		.size = 0,
+	},
+	[RTE_FLOW_ITEM_TYPE_ANY] = {
+		.name = "ANY",
+		.size = sizeof(struct rte_flow_item_any),
+	},
+	[RTE_FLOW_ITEM_TYPE_PF] = {
+		.name = "PF",
+		.size = 0,
+	},
+	[RTE_FLOW_ITEM_TYPE_VF] = {
+		.name = "VF",
+		.size = sizeof(struct rte_flow_item_vf),
+	},
+	[RTE_FLOW_ITEM_TYPE_PORT] = {
+		.name = "PORT",
+		.size = sizeof(struct rte_flow_item_port),
+	},
+	[RTE_FLOW_ITEM_TYPE_RAW] = {
+		.name = "RAW",
+		.size = sizeof(struct rte_flow_item_raw), /* +pattern[] */
+	},
+	[RTE_FLOW_ITEM_TYPE_ETH] = {
+		.name = "ETH",
+		.size = sizeof(struct rte_flow_item_eth),
+	},
+	[RTE_FLOW_ITEM_TYPE_VLAN] = {
+		.name = "VLAN",
+		.size = sizeof(struct rte_flow_item_vlan),
+	},
+	[RTE_FLOW_ITEM_TYPE_IPV4] = {
+		.name = "IPV4",
+		.size = sizeof(struct rte_flow_item_ipv4),
+	},
+	[RTE_FLOW_ITEM_TYPE_IPV6] = {
+		.name = "IPV6",
+		.size = sizeof(struct rte_flow_item_ipv6),
+	},
+	[RTE_FLOW_ITEM_TYPE_ICMP] = {
+		.name = "ICMP",
+		.size = sizeof(struct rte_flow_item_icmp),
+	},
+	[RTE_FLOW_ITEM_TYPE_UDP] = {
+		.name = "UDP",
+		.size = sizeof(struct rte_flow_item_udp),
+	},
+	[RTE_FLOW_ITEM_TYPE_TCP] = {
+		.name = "TCP",
+		.size = sizeof(struct rte_flow_item_tcp),
+	},
+	[RTE_FLOW_ITEM_TYPE_SCTP] = {
+		.name = "SCTP",
+		.size = sizeof(struct rte_flow_item_sctp),
+	},
+	[RTE_FLOW_ITEM_TYPE_VXLAN] = {
+		.name = "VXLAN",
+		.size = sizeof(struct rte_flow_item_vxlan),
+	},
+	[RTE_FLOW_ITEM_TYPE_MAX] = {
+		.name = "MAX",
+		.size = 0,
+	},
+};
+
+/** Compute storage space needed by item specification. */
+static void
+flow_item_spec_size(const struct rte_flow_item *item,
+		    size_t *size, size_t *pad)
+{
+	union {
+		const struct rte_flow_item_raw *raw;
+	} spec;
+
+	if (!item->spec)
+		goto empty;
+	switch (item->type) {
+	case RTE_FLOW_ITEM_TYPE_RAW:
+		spec.raw = item->spec;
+		*size = offsetof(struct rte_flow_item_raw, pattern) +
+			spec.raw->length * sizeof(*spec.raw->pattern);
+		break;
+	default:
+empty:
+		*size = 0;
+		break;
+	}
+	*pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
+}
+
+/** Information about known flow actions. */
+const struct rte_flow_desc_data rte_flow_desc_data_action[] = {
+	[RTE_FLOW_ACTION_TYPE_END] = {
+		.name = "END",
+		.size = 0,
+	},
+	[RTE_FLOW_ACTION_TYPE_VOID] = {
+		.name = "VOID",
+		.size = 0,
+	},
+	[RTE_FLOW_ACTION_TYPE_PASSTHRU] = {
+		.name = "PASSTHRU",
+		.size = 0,
+	},
+	[RTE_FLOW_ACTION_TYPE_MARK] = {
+		.name = "MARK",
+		.size = sizeof(struct rte_flow_action_mark),
+	},
+	[RTE_FLOW_ACTION_TYPE_FLAG] = {
+		.name = "FLAG",
+		.size = 0,
+	},
+	[RTE_FLOW_ACTION_TYPE_QUEUE] = {
+		.name = "QUEUE",
+		.size = sizeof(struct rte_flow_action_queue),
+	},
+	[RTE_FLOW_ACTION_TYPE_DROP] = {
+		.name = "DROP",
+		.size = 0,
+	},
+	[RTE_FLOW_ACTION_TYPE_COUNT] = {
+		.name = "COUNT",
+		.size = 0,
+	},
+	[RTE_FLOW_ACTION_TYPE_DUP] = {
+		.name = "DUP",
+		.size = sizeof(struct rte_flow_action_dup),
+	},
+	[RTE_FLOW_ACTION_TYPE_RSS] = {
+		.name = "RSS",
+		.size = sizeof(struct rte_flow_action_rss), /* +queue[] */
+	},
+	[RTE_FLOW_ACTION_TYPE_PF] = {
+		.name = "PF",
+		.size = 0,
+	},
+	[RTE_FLOW_ACTION_TYPE_VF] = {
+		.name = "VF",
+		.size = sizeof(struct rte_flow_action_vf),
+	},
+	[RTE_FLOW_ACTION_TYPE_MAX] = {
+		.name = "MAX",
+		.size = 0,
+	},
+};
+
+/** Compute storage space needed by action configuration. */
+static void
+flow_action_conf_size(const struct rte_flow_action *action,
+		      size_t *size, size_t *pad)
+{
+	union {
+		const struct rte_flow_action_rss *rss;
+	} conf;
+
+	if (!action->conf)
+		goto empty;
+	switch (action->type) {
+	case RTE_FLOW_ACTION_TYPE_RSS:
+		conf.rss = action->conf;
+		*size = offsetof(struct rte_flow_action_rss, queue) +
+			conf.rss->num * sizeof(*conf.rss->queue);
+		break;
+	default:
+empty:
+		*size = 0;
+		break;
+	}
+	*pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
+}
+
+/** Copy a comprehensive description of an rte_flow. */
+struct rte_flow_desc *
+rte_flow_copy(const struct rte_flow_attr *attr,
+	      const struct rte_flow_item *items,
+	      const struct rte_flow_action *actions,
+	      void *(zalloc)(size_t, size_t))
+{
+	const struct rte_flow_item *item;
+	const struct rte_flow_action *action;
+	struct rte_flow_desc *fd = NULL;
+	size_t tmp;
+	size_t pad;
+	size_t off1 = 0;
+	size_t off2 = 0;
+	int err = ENOTSUP;
+
+	if (zalloc == NULL)
+		zalloc = &calloc;
+
+store:
+	item = items;
+	if (fd)
+		fd->items = (void *)&fd->data[off1];
+	do {
+		struct rte_flow_item *dst = NULL;
+
+		if ((unsigned int)item->type >=
+			RTE_DIM(rte_flow_desc_data_item) ||
+		    !rte_flow_desc_data_item[item->type].name)
+			goto notsup;
+		if (fd)
+			dst = memcpy(fd->data + off1, item, sizeof(*item));
+		off1 += sizeof(*item);
+		flow_item_spec_size(item, &tmp, &pad);
+		if (item->spec) {
+			if (fd)
+				dst->spec = memcpy(fd->data + off2,
+						   item->spec, tmp);
+			off2 += tmp + pad;
+		}
+		if (item->last) {
+			if (fd)
+				dst->last = memcpy(fd->data + off2,
+						   item->last, tmp);
+			off2 += tmp + pad;
+		}
+		if (item->mask) {
+			if (fd)
+				dst->mask = memcpy(fd->data + off2,
+						   item->mask, tmp);
+			off2 += tmp + pad;
+		}
+		off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
+	} while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
+	off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
+	action = actions;
+	if (fd)
+		fd->actions = (void *)&fd->data[off1];
+	do {
+		struct rte_flow_action *dst = NULL;
+
+		if ((unsigned int)action->type >=
+			RTE_DIM(rte_flow_desc_data_action) ||
+		    !rte_flow_desc_data_action[action->type].name)
+			goto notsup;
+		if (fd)
+			dst = memcpy(fd->data + off1, action, sizeof(*action));
+		off1 += sizeof(*action);
+		flow_action_conf_size(action, &tmp, &pad);
+		if (action->conf) {
+			if (fd)
+				dst->conf = memcpy(fd->data + off2,
+						   action->conf, tmp);
+			off2 += tmp + pad;
+		}
+		off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
+	} while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
+	if (fd != NULL)
+		return fd;
+	off1 = RTE_ALIGN_CEIL(off1, sizeof(double));
+	tmp = RTE_ALIGN_CEIL(offsetof(struct rte_flow_desc, data),
+			     sizeof(double));
+	fd = zalloc(1, tmp + off1 + off2);
+	if (fd == NULL)
+		err = errno;
+	else {
+		*fd = (const struct rte_flow_desc){
+			.size = tmp + off1 + off2,
+			.attr = *attr,
+		};
+		tmp -= offsetof(struct rte_flow_desc, data);
+		off2 = tmp + off1;
+		off1 = tmp;
+		goto store;
+	}
+notsup:
+	rte_errno = err;
+	return NULL;
+}
diff --git a/lib/librte_ether/rte_flow.h b/lib/librte_ether/rte_flow.h
index 171a569..f0b33d2 100644
--- a/lib/librte_ether/rte_flow.h
+++ b/lib/librte_ether/rte_flow.h
@@ -282,6 +282,11 @@ enum rte_flow_item_type {
 	 * See struct rte_flow_item_nvgre.
 	 */
 	RTE_FLOW_ITEM_TYPE_NVGRE,
+
+	/**
+	 * Sentinel
+	 */
+	RTE_FLOW_ITEM_TYPE_MAX,
 };
 
 /**
@@ -779,6 +784,11 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_vf.
 	 */
 	RTE_FLOW_ACTION_TYPE_VF,
+
+	/**
+	 * Sentinel
+	 */
+	RTE_FLOW_ACTION_TYPE_MAX,
 };
 
 /**
@@ -1083,6 +1093,55 @@ rte_flow_query(uint8_t port_id,
 	       void *data,
 	       struct rte_flow_error *error);
 
+/**
+ * Generic flow generator description.
+ *
+ * This description must be sufficient to describe an rte_flow independently
+ * from any PMD implementation and allow for replayability and identification.
+ */
+struct rte_flow_desc {
+	size_t size; /**< Allocated space including data[]. */
+	struct rte_flow_attr attr; /**< Attributes. */
+	struct rte_flow_item *items; /**< Items. */
+	struct rte_flow_action *actions; /**< Actions. */
+	uint8_t data[]; /**< Storage for items/actions. */
+};
+
+/**
+ * Copy an rte_flow rule description
+ *
+ * @param[in] attr
+ *   Flow rule attributes.
+ * @param[in] pattern
+ *   Pattern specification (list terminated by the END pattern item).
+ * @param[in] actions
+ *   Associated actions (list terminated by the END action).
+ * @param zalloc
+ *   A zeroing allocator function. If NULL, the standard calloc() function is
+ *   used.
+ *
+ * @return
+ *   The flow description structure sufficient to re-create or identify a
+ *   specific flow if successful ; NULL otherwise, in which case rte_error
+ *   is set.
+ */
+struct rte_flow_desc *
+rte_flow_copy(const struct rte_flow_attr *attr,
+	      const struct rte_flow_item *items,
+	      const struct rte_flow_action *actions,
+	      void *(zalloc)(size_t, size_t));
+
+/**
+ * Flow elements description tables.
+ */
+struct rte_flow_desc_data {
+	const char *name;
+	size_t size;
+};
+
+extern const struct rte_flow_desc_data rte_flow_desc_data_item[];
+extern const struct rte_flow_desc_data rte_flow_desc_data_action[];
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.1.4

  parent reply	other threads:[~2017-03-03 15:40 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-03 15:40 [PATCH 00/12] introduce fail-safe PMD Gaetan Rivet
2017-03-03 15:40 ` [PATCH 01/12] ethdev: save VLAN filter setting Gaetan Rivet
2017-03-03 17:33   ` Stephen Hemminger
2017-03-03 15:40 ` Gaetan Rivet [this message]
2017-03-03 15:40 ` [PATCH 03/12] ethdev: add deferred intermediate device state Gaetan Rivet
2017-03-03 17:34   ` Stephen Hemminger
2017-03-03 15:40 ` [PATCH 04/12] pci: expose device detach routine Gaetan Rivet
2017-03-03 15:40 ` [PATCH 05/12] pci: expose parse and probe routines Gaetan Rivet
2017-03-03 15:40 ` [PATCH 06/12] net/failsafe: add fail-safe PMD Gaetan Rivet
2017-03-03 17:38   ` Stephen Hemminger
2017-03-06 14:19     ` Gaëtan Rivet
2017-03-03 15:40 ` [PATCH 07/12] net/failsafe: add plug-in support Gaetan Rivet
2017-03-03 15:40 ` [PATCH 08/12] net/failsafe: add flexible device definition Gaetan Rivet
2017-03-03 15:40 ` [PATCH 09/12] net/failsafe: support flow API Gaetan Rivet
2017-03-03 15:40 ` [PATCH 10/12] net/failsafe: support offload capabilities Gaetan Rivet
2017-03-03 15:40 ` [PATCH 11/12] net/failsafe: add fast burst functions Gaetan Rivet
2017-03-03 15:40 ` [PATCH 12/12] net/failsafe: support device removal Gaetan Rivet
2017-03-03 16:14 ` [PATCH 00/12] introduce fail-safe PMD Bruce Richardson
2017-03-06 13:53   ` Gaëtan Rivet
2017-03-03 17:27 ` Stephen Hemminger
2017-03-08 15:15 ` [PATCH v2 00/13] " Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 01/13] ethdev: save VLAN filter setting Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 02/13] ethdev: add flow API rule copy function Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 03/13] ethdev: add deferred intermediate device state Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 04/13] pci: expose device detach routine Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 05/13] pci: expose parse and probe routines Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 06/13] net/failsafe: add fail-safe PMD Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 07/13] net/failsafe: add plug-in support Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 08/13] net/failsafe: add flexible device definition Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 09/13] net/failsafe: support flow API Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 10/13] net/failsafe: support offload capabilities Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 11/13] net/failsafe: add fast burst functions Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 12/13] net/failsafe: support device removal Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 13/13] net/failsafe: support link status change event Gaetan Rivet
2017-03-08 16:54   ` [PATCH v2 00/13] introduce fail-safe PMD Neil Horman
2017-03-09  9:15     ` Bruce Richardson
2017-03-10  9:13       ` Gaëtan Rivet
2017-03-10 22:43         ` Neil Horman
2017-03-14 14:49           ` Gaëtan Rivet
2017-03-15  3:28             ` Bruce Richardson
2017-03-15 11:15               ` Thomas Monjalon
2017-03-15 14:25                 ` Gaëtan Rivet
2017-03-16 20:50                   ` Neil Horman
2017-03-17 10:56                     ` Gaëtan Rivet
2017-03-18 19:51                       ` Neil Horman
2017-03-20 15:00   ` Thomas Monjalon
2017-05-17 12:50     ` Ferruh Yigit
2017-05-17 16:59       ` Gaëtan Rivet
2017-03-23 13:01   ` Ferruh Yigit

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=8cc5c40c704f2d2600196cf8d65655fb90a5436b.1488550982.git.gaetan.rivet@6wind.com \
    --to=gaetan.rivet@6wind.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.