From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by dpdk.org (Postfix) with ESMTP id E00D9F963 for ; Fri, 3 Mar 2017 16:40:47 +0100 (CET) Received: by mail-wr0-f175.google.com with SMTP id g10so76178048wrg.2 for ; Fri, 03 Mar 2017 07:40:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=8By7GMtB+dgyM5hVVpo1oEryHmNgcRmBKNtb2K116vg=; b=ejTqXDR07RJuCtax/UJ7Yz2ELc1xpHVhnq2mZjL7YZognANFZGtR3zF0mUGoD9w48K ycC4fwODDD6MnsSJU2gIEKj0bdb9xfy9f8OSl+GUCoH6opKU218FBBSUQ2tPh1zGuc0P DK9Kg7ES3PyZzdbo9sbshJwlsWv2+h+56B8r3uOqZdsb4WKMpdi3FlpZVmdf66Kogpc+ FrsccdKWMEuXgf5q4a2Q76gHg+z1CGcLBOpCrBIVBdJ9lcvxHDaptiXgGnKV2aJ7yyah zkYBxW79maJcRV/lTQhKTFb3T3eLpmQLbh61goeDOauDD83+fuL1ljaP06aIFNJrTcVx jcVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8By7GMtB+dgyM5hVVpo1oEryHmNgcRmBKNtb2K116vg=; b=NT4pxcUpOwdsTilpZ6NbXqAes5kNA2XhrXHKeLExmayRL4BbZ97XlXIWdB1vu2b/Sm 6xi4c744VdBwgLL/oRnCwVVgMYsY0pG53ohoEReqi75KrPolGWCioYVvL4S493kmCvWu tnpsHYltj4S2dMKMecY2SyvjdPq7+q+Igcsz/lXwm8MqjrKWE5Xp+zQPLDbFgpJheDhi fGLcZ4BvCJpHKLp9ZtpcnQOawKvUSLEifTguAdji8PIP+ru65qw6oal2vcXi64iausV6 H9+x6ps86DfioZTpg8ZjK4sfKjqa+aplX1C6npkyAEHC17y3si3XbuoivfEyfarx+kjg kCLA== X-Gm-Message-State: AMke39kaSvHMZ6zmn417aeANE62ppC4MVSbHN6n1qnZ2zywnvkWLVJijqoy2sUMnLHFSduRc X-Received: by 10.223.136.82 with SMTP id e18mr3233224wre.28.1488555646873; Fri, 03 Mar 2017 07:40:46 -0800 (PST) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id 63sm3486280wmp.9.2017.03.03.07.40.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Mar 2017 07:40:46 -0800 (PST) From: Gaetan Rivet To: dev@dpdk.org Date: Fri, 3 Mar 2017 16:40:24 +0100 Message-Id: <8cc5c40c704f2d2600196cf8d65655fb90a5436b.1488550982.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 02/12] ethdev: add flow API rule copy function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Mar 2017 15:40:48 -0000 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 --- 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 +#include #include #include #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