From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id A59201C122 for ; Wed, 27 Jun 2018 18:31:32 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jun 2018 09:31:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,279,1526367600"; d="scan'208";a="240789590" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by fmsmga005.fm.intel.com with ESMTP; 27 Jun 2018 09:31:31 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com, bernard.iremonger@intel.com Date: Wed, 27 Jun 2018 17:31:05 +0100 Message-Id: <20180627163123.135686-6-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180627163123.135686-1-jasvinder.singh@intel.com> References: <20180615165224.25004-2-jasvinder.singh@intel.com> <20180627163123.135686-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 05/23] net/softnic: add tap object 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: Wed, 27 Jun 2018 16:31:33 -0000 Add tap object implementation to the softnic. Signed-off-by: Cristian Dumitrescu Signed-off-by: Jasvinder Singh --- drivers/net/softnic/Makefile | 1 + drivers/net/softnic/rte_eth_softnic.c | 2 + drivers/net/softnic/rte_eth_softnic_internals.h | 29 ++++++ drivers/net/softnic/rte_eth_softnic_tap.c | 118 ++++++++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 drivers/net/softnic/rte_eth_softnic_tap.c diff --git a/drivers/net/softnic/Makefile b/drivers/net/softnic/Makefile index b211559..677a5b1 100644 --- a/drivers/net/softnic/Makefile +++ b/drivers/net/softnic/Makefile @@ -26,6 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_mempool.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_swq.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_link.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_tm.c +SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_tap.c # # Export include files diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c index 5d5dd8e..6dd8463 100644 --- a/drivers/net/softnic/rte_eth_softnic.c +++ b/drivers/net/softnic/rte_eth_softnic.c @@ -225,6 +225,7 @@ pmd_init(struct pmd_params *params) mempool_init(p); swq_init(p); link_init(p); + tap_init(p); return p; } @@ -235,6 +236,7 @@ pmd_free(struct pmd_internals *p) if (p == NULL) return; + tap_free(p); link_free(p); swq_free(p); mempool_free(p); diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index 35fb140..6b7004c 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -201,6 +201,17 @@ struct tm_internals { }; /** + * TAP + */ +struct tap { + TAILQ_ENTRY(tap) node; + char name[NAME_SIZE]; + int fd; +}; + +TAILQ_HEAD(tap_list, tap); + +/** * PMD Internals */ struct pmd_internals { @@ -215,6 +226,7 @@ struct pmd_internals { struct mempool_list mempool_list; struct swq_list swq_list; struct link_list link_list; + struct tap_list tap_list; }; /** @@ -294,4 +306,21 @@ tm_used(struct rte_eth_dev *dev __rte_unused) return 0; } +/** + * TAP + */ +int +tap_init(struct pmd_internals *p); + +void +tap_free(struct pmd_internals *p); + +struct tap * +tap_find(struct pmd_internals *p, + const char *name); + +struct tap * +tap_create(struct pmd_internals *p, + const char *name); + #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */ diff --git a/drivers/net/softnic/rte_eth_softnic_tap.c b/drivers/net/softnic/rte_eth_softnic_tap.c new file mode 100644 index 0000000..96771e8 --- /dev/null +++ b/drivers/net/softnic/rte_eth_softnic_tap.c @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#include +#ifdef RTE_EXEC_ENV_LINUXAPP +#include +#include +#endif +#include + +#include +#include +#include +#include +#include + +#include + +#include "rte_eth_softnic_internals.h" + +#define TAP_DEV "/dev/net/tun" + +int +tap_init(struct pmd_internals *p) +{ + TAILQ_INIT(&p->tap_list); + + return 0; +} + +void +tap_free(struct pmd_internals *p) +{ + for ( ; ; ) { + struct tap *tap; + + tap = TAILQ_FIRST(&p->tap_list); + if (tap == NULL) + break; + + TAILQ_REMOVE(&p->tap_list, tap, node); + free(tap); + } +} + +struct tap * +tap_find(struct pmd_internals *p, + const char *name) +{ + struct tap *tap; + + if (name == NULL) + return NULL; + + TAILQ_FOREACH(tap, &p->tap_list, node) + if (strcmp(tap->name, name) == 0) + return tap; + + return NULL; +} + +#ifndef RTE_EXEC_ENV_LINUXAPP + +struct tap * +tap_create(struct pmd_internals *p __rte_unused, + const char *name __rte_unused) +{ + return NULL; +} + +#else + +struct tap * +tap_create(struct pmd_internals *p, + const char *name) +{ + struct tap *tap; + struct ifreq ifr; + int fd, status; + + /* Check input params */ + if (name == NULL || + tap_find(p, name)) + return NULL; + + /* Resource create */ + fd = open(TAP_DEV, O_RDWR | O_NONBLOCK); + if (fd < 0) + return NULL; + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */ + snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name); + + status = ioctl(fd, TUNSETIFF, (void *)&ifr); + if (status < 0) { + close(fd); + return NULL; + } + + /* Node allocation */ + tap = calloc(1, sizeof(struct tap)); + if (tap == NULL) { + close(fd); + return NULL; + } + /* Node fill in */ + strlcpy(tap->name, name, sizeof(tap->name)); + tap->fd = fd; + + /* Node add to list */ + TAILQ_INSERT_TAIL(&p->tap_list, tap, node); + + return tap; +} + +#endif -- 2.9.3