From: Pascal Mazon <pascal.mazon@6wind.com>
To: keith.wiles@intel.com
Cc: dev@dpdk.org, Pascal Mazon <pascal.mazon@6wind.com>
Subject: [dpdk-dev] [PATCH v3 2/4] net/tap: add preliminary support for rte_flow
Date: Tue, 7 Mar 2017 17:35:11 +0100 [thread overview]
Message-ID: <175de14bd7a4fdd512e59fd0c02423ed901c3d4e.1488904425.git.pascal.mazon@6wind.com> (raw)
In-Reply-To: <cover.1488904425.git.pascal.mazon@6wind.com>
The flow API provides the ability to classify packets received by a tap
netdevice.
This patch only implements skeleton functions for flow API support, no
patterns are supported yet.
Signed-off-by: Pascal Mazon <pascal.mazon@6wind.com>
Acked-by: Olga Shern <olgas@mellanox.com>
---
doc/guides/nics/features/tap.ini | 1 +
drivers/net/tap/Makefile | 1 +
drivers/net/tap/rte_eth_tap.c | 6 ++
drivers/net/tap/tap.h | 2 +
drivers/net/tap/tap_flow.c | 185 +++++++++++++++++++++++++++++++++++++++
drivers/net/tap/tap_flow.h | 46 ++++++++++
6 files changed, 241 insertions(+)
create mode 100644 drivers/net/tap/tap_flow.c
create mode 100644 drivers/net/tap/tap_flow.h
diff --git a/doc/guides/nics/features/tap.ini b/doc/guides/nics/features/tap.ini
index a51712dce066..9d73f61cca3b 100644
--- a/doc/guides/nics/features/tap.ini
+++ b/doc/guides/nics/features/tap.ini
@@ -9,6 +9,7 @@ Jumbo frame = Y
Promiscuous mode = Y
Allmulticast mode = Y
Basic stats = Y
+Flow API = Y
MTU update = Y
Multicast MAC filter = Y
Speed capabilities = Y
diff --git a/drivers/net/tap/Makefile b/drivers/net/tap/Makefile
index bdbe69e62a4e..386b8b0594d3 100644
--- a/drivers/net/tap/Makefile
+++ b/drivers/net/tap/Makefile
@@ -47,6 +47,7 @@ CFLAGS += $(WERROR_FLAGS)
# all source are stored in SRCS-y
#
SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += rte_eth_tap.c
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_flow.c
# this lib depends upon:
DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += lib/librte_eal
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 308519d265cb..d4f2ff72e8b4 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -52,6 +52,7 @@
#include <fcntl.h>
#include <tap.h>
+#include <tap_flow.h>
/* Linux based path to the TUN device */
#define TUN_TAP_DEV_PATH "/dev/net/tun"
@@ -797,6 +798,7 @@ static const struct eth_dev_ops ops = {
.stats_get = tap_stats_get,
.stats_reset = tap_stats_reset,
.dev_supported_ptypes_get = tap_dev_supported_ptypes_get,
+ .filter_ctrl = tap_dev_filter_ctrl,
};
static int
@@ -860,6 +862,8 @@ eth_dev_tap_create(const char *name, char *tap_name)
pmd->txq[i].fd = -1;
}
+ LIST_INIT(&pmd->flows);
+
return 0;
error_exit:
@@ -972,6 +976,8 @@ rte_pmd_tap_remove(const char *name)
if (!eth_dev)
return 0;
+ tap_flow_flush(eth_dev, NULL);
+
internals = eth_dev->data->dev_private;
for (i = 0; i < internals->nb_queues; i++)
if (internals->rxq[i].fd != -1)
diff --git a/drivers/net/tap/tap.h b/drivers/net/tap/tap.h
index abd1795b2a43..60c0c58c7c1a 100644
--- a/drivers/net/tap/tap.h
+++ b/drivers/net/tap/tap.h
@@ -34,6 +34,7 @@
#ifndef _TAP_H_
#define _TAP_H_
+#include <sys/queue.h>
#include <inttypes.h>
#include <rte_ethdev.h>
@@ -66,6 +67,7 @@ struct pmd_internals {
uint16_t nb_queues; /* Number of queues supported */
struct ether_addr eth_addr; /* Mac address of the device port */
int if_index; /* IF_INDEX for the port */
+ LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules */
struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
};
diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c
new file mode 100644
index 000000000000..de41c127c920
--- /dev/null
+++ b/drivers/net/tap/tap_flow.c
@@ -0,0 +1,185 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright 2017 6WIND S.A.
+ * Copyright 2017 Mellanox.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of 6WIND S.A. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/queue.h>
+
+#include <rte_malloc.h>
+#include <tap_flow.h>
+#include <tap.h>
+
+struct rte_flow {
+ LIST_ENTRY(rte_flow) next; /* Pointer to the next rte_flow structure */
+};
+
+static int
+tap_flow_validate(struct rte_eth_dev *dev,
+ const struct rte_flow_attr *attr,
+ const struct rte_flow_item items[],
+ const struct rte_flow_action actions[],
+ struct rte_flow_error *error);
+
+static struct rte_flow *
+tap_flow_create(struct rte_eth_dev *dev,
+ const struct rte_flow_attr *attr,
+ const struct rte_flow_item items[],
+ const struct rte_flow_action actions[],
+ struct rte_flow_error *error);
+
+static int
+tap_flow_destroy(struct rte_eth_dev *dev,
+ struct rte_flow *flow,
+ struct rte_flow_error *error);
+
+static const struct rte_flow_ops tap_flow_ops = {
+ .validate = tap_flow_validate,
+ .create = tap_flow_create,
+ .destroy = tap_flow_destroy,
+ .flush = tap_flow_flush,
+};
+
+/**
+ * Validate a flow.
+ *
+ * @see rte_flow_validate()
+ * @see rte_flow_ops
+ */
+static int
+tap_flow_validate(struct rte_eth_dev *dev __rte_unused,
+ const struct rte_flow_attr *attr __rte_unused,
+ const struct rte_flow_item items[] __rte_unused,
+ const struct rte_flow_action actions[] __rte_unused,
+ struct rte_flow_error *error)
+{
+ return -rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+ NULL, "not implemented yet");
+}
+
+/**
+ * Create a flow.
+ *
+ * @see rte_flow_create()
+ * @see rte_flow_ops
+ */
+static struct rte_flow *
+tap_flow_create(struct rte_eth_dev *dev,
+ const struct rte_flow_attr *attr,
+ const struct rte_flow_item items[],
+ const struct rte_flow_action actions[],
+ struct rte_flow_error *error)
+{
+ struct pmd_internals *pmd = dev->data->dev_private;
+ struct rte_flow *flow = NULL;
+
+ if (tap_flow_validate(dev, attr, items, actions, error))
+ return NULL;
+ flow = rte_malloc(__func__, sizeof(struct rte_flow), 0);
+ if (!flow) {
+ rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
+ NULL, "cannot allocate memory for rte_flow");
+ return NULL;
+ }
+ LIST_INSERT_HEAD(&pmd->flows, flow, next);
+ return flow;
+}
+
+/**
+ * Destroy a flow.
+ *
+ * @see rte_flow_destroy()
+ * @see rte_flow_ops
+ */
+static int
+tap_flow_destroy(struct rte_eth_dev *dev __rte_unused,
+ struct rte_flow *flow,
+ struct rte_flow_error *error __rte_unused)
+{
+ LIST_REMOVE(flow, next);
+ rte_free(flow);
+ return 0;
+}
+
+/**
+ * Destroy all flows.
+ *
+ * @see rte_flow_flush()
+ * @see rte_flow_ops
+ */
+int
+tap_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
+{
+ struct pmd_internals *pmd = dev->data->dev_private;
+ struct rte_flow *flow;
+
+ while (!LIST_EMPTY(&pmd->flows)) {
+ flow = LIST_FIRST(&pmd->flows);
+ if (tap_flow_destroy(dev, flow, error) < 0)
+ return -1;
+ }
+ return 0;
+}
+
+/**
+ * Manage filter operations.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param filter_type
+ * Filter type.
+ * @param filter_op
+ * Operation to perform.
+ * @param arg
+ * Pointer to operation-specific structure.
+ *
+ * @return
+ * 0 on success, negative errno value on failure.
+ */
+int
+tap_dev_filter_ctrl(struct rte_eth_dev *dev,
+ enum rte_filter_type filter_type,
+ enum rte_filter_op filter_op,
+ void *arg)
+{
+ switch (filter_type) {
+ case RTE_ETH_FILTER_GENERIC:
+ if (filter_op != RTE_ETH_FILTER_GET)
+ return -EINVAL;
+ *(const void **)arg = &tap_flow_ops;
+ return 0;
+ default:
+ RTE_LOG(ERR, PMD, "%p: filter type (%d) not supported",
+ (void *)dev, filter_type);
+ }
+ return -EINVAL;
+}
+
diff --git a/drivers/net/tap/tap_flow.h b/drivers/net/tap/tap_flow.h
new file mode 100644
index 000000000000..377a9f7b758a
--- /dev/null
+++ b/drivers/net/tap/tap_flow.h
@@ -0,0 +1,46 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright 2017 6WIND S.A.
+ * Copyright 2017 Mellanox.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of 6WIND S.A. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _TAP_FLOW_H_
+#define _TAP_FLOW_H_
+
+#include <rte_flow.h>
+#include <rte_flow_driver.h>
+
+int tap_dev_filter_ctrl(struct rte_eth_dev *dev,
+ enum rte_filter_type filter_type,
+ enum rte_filter_op filter_op,
+ void *arg);
+int tap_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
+
+#endif /* _TAP_FLOW_H_ */
--
2.8.0.rc0
next prev parent reply other threads:[~2017-03-07 16:35 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 10:45 [dpdk-dev] [PATCH 0/4] net/tap: support flow API Pascal Mazon
2017-03-03 10:45 ` [dpdk-dev] [PATCH 1/4] net/tap: move private elements to external header Pascal Mazon
2017-03-03 15:38 ` Wiles, Keith
2017-03-06 14:18 ` Pascal Mazon
2017-03-06 14:51 ` Wiles, Keith
2017-03-03 10:45 ` [dpdk-dev] [PATCH 2/4] net/tap: add preliminary support for rte_flow Pascal Mazon
2017-03-03 10:45 ` [dpdk-dev] [PATCH 3/4] net/tap: add netlink back-end for flow API Pascal Mazon
2017-03-03 10:45 ` [dpdk-dev] [PATCH 4/4] net/tap: add basic flow API patterns and actions Pascal Mazon
2017-03-03 15:47 ` Wiles, Keith
2017-03-06 14:22 ` Pascal Mazon
2017-03-03 15:54 ` [dpdk-dev] [PATCH 0/4] net/tap: support flow API Wiles, Keith
2017-03-06 17:05 ` [dpdk-dev] [PATCH v2 " Pascal Mazon
2017-03-06 17:05 ` [dpdk-dev] [PATCH v2 1/4] net/tap: move private elements to external header Pascal Mazon
2017-03-06 17:05 ` [dpdk-dev] [PATCH v2 2/4] net/tap: add preliminary support for rte_flow Pascal Mazon
2017-03-06 17:05 ` [dpdk-dev] [PATCH v2 3/4] net/tap: add netlink back-end for flow API Pascal Mazon
2017-03-06 17:05 ` [dpdk-dev] [PATCH v2 4/4] net/tap: add basic flow API patterns and actions Pascal Mazon
2017-03-07 15:05 ` [dpdk-dev] [PATCH v2 0/4] net/tap: support flow API Pascal Mazon
2017-03-07 15:08 ` Wiles, Keith
2017-03-07 16:35 ` [dpdk-dev] [PATCH v3 " Pascal Mazon
2017-03-07 16:35 ` [dpdk-dev] [PATCH v3 1/4] net/tap: move private elements to external header Pascal Mazon
2017-03-09 15:28 ` Ferruh Yigit
2017-03-10 9:40 ` Pascal Mazon
2017-03-07 16:35 ` Pascal Mazon [this message]
2017-03-07 16:35 ` [dpdk-dev] [PATCH v3 3/4] net/tap: add netlink back-end for flow API Pascal Mazon
2017-03-09 15:29 ` Ferruh Yigit
2017-03-10 9:39 ` Pascal Mazon
2017-03-07 16:35 ` [dpdk-dev] [PATCH v3 4/4] net/tap: add basic flow API patterns and actions Pascal Mazon
2017-03-14 8:29 ` [dpdk-dev] [PATCH v4 0/4] net/tap: support flow API Pascal Mazon
2017-03-14 8:29 ` [dpdk-dev] [PATCH v4 1/4] net/tap: move private elements to external header Pascal Mazon
2017-03-14 14:05 ` Wiles, Keith
2017-03-14 8:29 ` [dpdk-dev] [PATCH v4 2/4] net/tap: add preliminary support for rte_flow Pascal Mazon
2017-03-14 8:29 ` [dpdk-dev] [PATCH v4 3/4] net/tap: add netlink back-end for flow API Pascal Mazon
2017-03-14 14:03 ` Wiles, Keith
2017-03-14 8:29 ` [dpdk-dev] [PATCH v4 4/4] net/tap: add basic flow API patterns and actions Pascal Mazon
2017-03-15 14:54 ` [dpdk-dev] [PATCH v5 0/4] net/tap: support flow API Pascal Mazon
2017-03-15 14:54 ` [dpdk-dev] [PATCH v5 1/4] net/tap: move private elements to external header Pascal Mazon
2017-03-21 15:32 ` Wiles, Keith
2017-03-21 16:57 ` Pascal Mazon
2017-03-15 14:54 ` [dpdk-dev] [PATCH v5 2/4] net/tap: add preliminary support for rte_flow Pascal Mazon
2017-03-21 15:35 ` Wiles, Keith
2017-03-15 14:54 ` [dpdk-dev] [PATCH v5 3/4] net/tap: add netlink back-end for flow API Pascal Mazon
2017-03-15 14:54 ` [dpdk-dev] [PATCH v5 4/4] net/tap: add basic flow API patterns and actions Pascal Mazon
2017-03-21 17:10 ` Ferruh Yigit
2017-03-21 15:48 ` [dpdk-dev] [PATCH v5 0/4] net/tap: support flow API Wiles, Keith
2017-03-22 9:48 ` [dpdk-dev] [PATCH v6 " Pascal Mazon
2017-03-22 9:48 ` [dpdk-dev] [PATCH v6 1/4] net/tap: move private elements to external header Pascal Mazon
2017-03-22 9:48 ` [dpdk-dev] [PATCH v6 2/4] net/tap: add preliminary support for rte_flow Pascal Mazon
2017-03-22 9:48 ` [dpdk-dev] [PATCH v6 3/4] net/tap: add netlink back-end for flow API Pascal Mazon
2017-03-22 9:48 ` [dpdk-dev] [PATCH v6 4/4] net/tap: add basic flow API patterns and actions Pascal Mazon
2017-03-22 13:56 ` Ferruh Yigit
2017-03-22 14:22 ` [dpdk-dev] [PATCH v6 0/4] net/tap: support flow API Wiles, Keith
2017-03-23 8:33 ` [dpdk-dev] [PATCH v7 " Pascal Mazon
2017-03-23 8:33 ` [dpdk-dev] [PATCH v7 1/4] net/tap: move private elements to external header Pascal Mazon
2017-03-23 8:33 ` [dpdk-dev] [PATCH v7 2/4] net/tap: add preliminary support for rte_flow Pascal Mazon
2017-03-23 8:33 ` [dpdk-dev] [PATCH v7 3/4] net/tap: add netlink back-end for flow API Pascal Mazon
2017-03-23 8:33 ` [dpdk-dev] [PATCH v7 4/4] net/tap: add basic flow API patterns and actions Pascal Mazon
2017-03-23 12:50 ` [dpdk-dev] [PATCH v7 0/4] net/tap: support flow API 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=175de14bd7a4fdd512e59fd0c02423ed901c3d4e.1488904425.git.pascal.mazon@6wind.com \
--to=pascal.mazon@6wind.com \
--cc=dev@dpdk.org \
--cc=keith.wiles@intel.com \
/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 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).