From: Pascal Mazon <pascal.mazon@6wind.com>
To: keith.wiles@intel.com, ferruh.yigit@intel.com
Cc: dev@dpdk.org, Pascal Mazon <pascal.mazon@6wind.com>
Subject: [dpdk-dev] [PATCH v5 2/8] net/tap: refactor ioctl calls
Date: Wed, 15 Mar 2017 15:48:13 +0100 [thread overview]
Message-ID: <49365496189560c2d7f8e6afc236689b7e327fbb.1489589167.git.pascal.mazon@6wind.com> (raw)
In-Reply-To: <cover.1489589167.git.pascal.mazon@6wind.com>
Create a socket for ioctl at tap device creation instead of opening it
and closing it every call to tap_link_set_flags().
Use a common tap_ioctl() function that can be extended for various uses
(such as MTU change, MAC address change, ...).
Signed-off-by: Pascal Mazon <pascal.mazon@6wind.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
drivers/net/tap/rte_eth_tap.c | 90 +++++++++++++++++++++++--------------------
1 file changed, 48 insertions(+), 42 deletions(-)
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index fcf4a1dc3da1..50a07249dff2 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -114,6 +114,7 @@ struct pmd_internals {
struct ether_addr eth_addr; /* Mac address of the device port */
int if_index; /* IF_INDEX for the port */
+ int ioctl_sock; /* socket for ioctl calls */
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 */
@@ -328,63 +329,55 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
}
static int
-tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
+tap_ioctl(struct pmd_internals *pmd, unsigned long request,
+ struct ifreq *ifr, int set)
{
- struct ifreq ifr;
- int err, s;
-
- /*
- * An AF_INET/DGRAM socket is needed for
- * SIOCGIFFLAGS/SIOCSIFFLAGS, using fd won't work.
- */
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s < 0) {
- RTE_LOG(ERR, PMD,
- "Unable to get a socket to set flags: %s\n",
- strerror(errno));
- return -1;
- }
- memset(&ifr, 0, sizeof(ifr));
- snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
- err = ioctl(s, SIOCGIFFLAGS, &ifr);
- if (err < 0) {
- RTE_LOG(WARNING, PMD, "Unable to get %s device flags: %s\n",
- pmd->name, strerror(errno));
- close(s);
- return -1;
- }
- if (add)
- ifr.ifr_flags |= flags;
- else
- ifr.ifr_flags &= ~flags;
- err = ioctl(s, SIOCSIFFLAGS, &ifr);
- if (err < 0) {
- RTE_LOG(WARNING, PMD, "Unable to %s flags 0x%x: %s\n",
- add ? "set" : "unset", flags, strerror(errno));
- close(s);
- return -1;
- }
- close(s);
+ short req_flags = ifr->ifr_flags;
+ snprintf(ifr->ifr_name, IFNAMSIZ, "%s", pmd->name);
+ switch (request) {
+ case SIOCSIFFLAGS:
+ /* fetch current flags to leave other flags untouched */
+ if (ioctl(pmd->ioctl_sock, SIOCGIFFLAGS, ifr) < 0)
+ goto error;
+ if (set)
+ ifr->ifr_flags |= req_flags;
+ else
+ ifr->ifr_flags &= ~req_flags;
+ break;
+ default:
+ RTE_LOG(WARNING, PMD, "%s: ioctl() called with wrong arg\n",
+ pmd->name);
+ return -EINVAL;
+ }
+ if (ioctl(pmd->ioctl_sock, request, ifr) < 0)
+ goto error;
return 0;
+
+error:
+ RTE_LOG(ERR, PMD, "%s: ioctl(%lu) failed with error: %s\n",
+ ifr->ifr_name, request, strerror(errno));
+ return -errno;
}
static int
tap_link_set_down(struct rte_eth_dev *dev)
{
struct pmd_internals *pmd = dev->data->dev_private;
+ struct ifreq ifr = { .ifr_flags = IFF_UP };
dev->data->dev_link.link_status = ETH_LINK_DOWN;
- return tap_link_set_flags(pmd, IFF_UP, 0);
+ return tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 0);
}
static int
tap_link_set_up(struct rte_eth_dev *dev)
{
struct pmd_internals *pmd = dev->data->dev_private;
+ struct ifreq ifr = { .ifr_flags = IFF_UP };
dev->data->dev_link.link_status = ETH_LINK_UP;
- return tap_link_set_flags(pmd, IFF_UP, 1);
+ return tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 1);
}
static int
@@ -518,36 +511,40 @@ static void
tap_promisc_enable(struct rte_eth_dev *dev)
{
struct pmd_internals *pmd = dev->data->dev_private;
+ struct ifreq ifr = { .ifr_flags = IFF_PROMISC };
dev->data->promiscuous = 1;
- tap_link_set_flags(pmd, IFF_PROMISC, 1);
+ tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 1);
}
static void
tap_promisc_disable(struct rte_eth_dev *dev)
{
struct pmd_internals *pmd = dev->data->dev_private;
+ struct ifreq ifr = { .ifr_flags = IFF_PROMISC };
dev->data->promiscuous = 0;
- tap_link_set_flags(pmd, IFF_PROMISC, 0);
+ tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 0);
}
static void
tap_allmulti_enable(struct rte_eth_dev *dev)
{
struct pmd_internals *pmd = dev->data->dev_private;
+ struct ifreq ifr = { .ifr_flags = IFF_ALLMULTI };
dev->data->all_multicast = 1;
- tap_link_set_flags(pmd, IFF_ALLMULTI, 1);
+ tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 1);
}
static void
tap_allmulti_disable(struct rte_eth_dev *dev)
{
struct pmd_internals *pmd = dev->data->dev_private;
+ struct ifreq ifr = { .ifr_flags = IFF_ALLMULTI };
dev->data->all_multicast = 0;
- tap_link_set_flags(pmd, IFF_ALLMULTI, 0);
+ tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 0);
}
static int
@@ -724,6 +721,14 @@ eth_dev_tap_create(const char *name, char *tap_name)
pmd->nb_queues = RTE_PMD_TAP_MAX_QUEUES;
+ pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (pmd->ioctl_sock == -1) {
+ RTE_LOG(ERR, PMD,
+ "TAP Unable to get a socket for management: %s\n",
+ strerror(errno));
+ goto error_exit;
+ }
+
/* Setup some default values */
data->dev_private = pmd;
data->port_id = dev->data->port_id;
@@ -866,6 +871,7 @@ rte_pmd_tap_remove(const char *name)
if (internals->rxq[i].fd != -1)
close(internals->rxq[i].fd);
+ close(internals->ioctl_sock);
rte_free(eth_dev->data->dev_private);
rte_free(eth_dev->data);
--
2.8.0.rc0
next prev parent reply other threads:[~2017-03-15 14:51 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 9:46 [dpdk-dev] [PATCH 0/6] net/tap: add additional management ops Pascal Mazon
2017-03-03 9:46 ` [dpdk-dev] [PATCH 1/6] net/tap: add MAC address " Pascal Mazon
2017-03-03 9:46 ` [dpdk-dev] [PATCH 2/6] net/tap: add speed capabilities Pascal Mazon
2017-03-03 15:27 ` Wiles, Keith
2017-03-06 13:58 ` Pascal Mazon
2017-03-06 14:38 ` Wiles, Keith
2017-03-03 9:46 ` [dpdk-dev] [PATCH 3/6] net/tap: add multicast addresses management Pascal Mazon
2017-03-03 9:46 ` [dpdk-dev] [PATCH 4/6] net/tap: add MTU management Pascal Mazon
2017-03-03 15:23 ` Wiles, Keith
2017-03-06 13:59 ` Pascal Mazon
2017-03-03 9:46 ` [dpdk-dev] [PATCH 5/6] net/tap: add packet type management Pascal Mazon
2017-03-03 15:31 ` Wiles, Keith
2017-03-06 14:10 ` Pascal Mazon
2017-03-06 14:46 ` Wiles, Keith
2017-03-03 9:46 ` [dpdk-dev] [PATCH 6/6] net/tap: add flow control management Pascal Mazon
2017-03-06 16:31 ` [dpdk-dev] [PATCH v2 0/6] net/tap: add additional management ops Pascal Mazon
2017-03-06 16:31 ` [dpdk-dev] [PATCH v2 1/6] net/tap: add MAC address " Pascal Mazon
2017-03-06 16:31 ` [dpdk-dev] [PATCH v2 2/6] net/tap: add speed capabilities Pascal Mazon
2017-03-06 16:31 ` [dpdk-dev] [PATCH v2 3/6] net/tap: add multicast addresses management Pascal Mazon
2017-03-06 16:31 ` [dpdk-dev] [PATCH v2 4/6] net/tap: add MTU management Pascal Mazon
2017-03-06 16:31 ` [dpdk-dev] [PATCH v2 5/6] net/tap: add packet type management Pascal Mazon
2017-03-06 16:31 ` [dpdk-dev] [PATCH v2 6/6] net/tap: add flow control management Pascal Mazon
2017-03-07 16:31 ` [dpdk-dev] [PATCH v3 0/6] net/tap: add additional management ops Pascal Mazon
2017-03-14 8:22 ` [dpdk-dev] [PATCH v4 0/8] " Pascal Mazon
2017-03-14 8:22 ` [dpdk-dev] [PATCH v4 1/8] net/tap: remove wrong IFF_NOARP flags Pascal Mazon
2017-03-14 8:22 ` [dpdk-dev] [PATCH v4 2/8] net/tap: refactor ioctl calls Pascal Mazon
2017-03-14 8:22 ` [dpdk-dev] [PATCH v4 3/8] net/tap: add MAC address management Pascal Mazon
2017-03-14 8:22 ` [dpdk-dev] [PATCH v4 4/8] net/tap: add MTU management Pascal Mazon
2017-03-14 8:22 ` [dpdk-dev] [PATCH v4 5/8] net/tap: add speed capabilities Pascal Mazon
2017-03-14 8:22 ` [dpdk-dev] [PATCH v4 6/8] net/tap: add multicast addresses management Pascal Mazon
2017-03-14 8:22 ` [dpdk-dev] [PATCH v4 7/8] net/tap: add packet type management Pascal Mazon
2017-03-15 13:35 ` Ferruh Yigit
2017-03-15 13:44 ` Pascal Mazon
2017-03-15 14:31 ` Ferruh Yigit
2017-03-15 13:42 ` Ferruh Yigit
2017-03-14 8:22 ` [dpdk-dev] [PATCH v4 8/8] net/tap: add flow control management Pascal Mazon
2017-03-15 13:43 ` [dpdk-dev] [PATCH v4 0/8] net/tap: add additional management ops Ferruh Yigit
2017-03-15 14:48 ` [dpdk-dev] [PATCH v5 " Pascal Mazon
2017-03-15 14:48 ` [dpdk-dev] [PATCH v5 1/8] net/tap: remove wrong IFF_NOARP flags Pascal Mazon
2017-03-15 21:37 ` Wiles, Keith
2017-03-15 14:48 ` Pascal Mazon [this message]
2017-03-15 14:48 ` [dpdk-dev] [PATCH v5 3/8] net/tap: add MAC address management Pascal Mazon
2017-03-15 14:48 ` [dpdk-dev] [PATCH v5 4/8] net/tap: add MTU management Pascal Mazon
2017-03-15 14:48 ` [dpdk-dev] [PATCH v5 5/8] net/tap: add speed capabilities Pascal Mazon
2017-03-15 14:48 ` [dpdk-dev] [PATCH v5 6/8] net/tap: add multicast addresses management Pascal Mazon
2017-03-15 14:48 ` [dpdk-dev] [PATCH v5 7/8] net/tap: add packet type management Pascal Mazon
2017-03-15 14:48 ` [dpdk-dev] [PATCH v5 8/8] net/tap: add flow control management Pascal Mazon
2017-03-15 16:46 ` [dpdk-dev] [PATCH v5 0/8] net/tap: add additional management ops Ferruh Yigit
2017-03-15 21:44 ` Wiles, Keith
2017-03-07 16:31 ` [dpdk-dev] [PATCH v3 1/6] net/tap: add MAC address " Pascal Mazon
2017-03-09 14:05 ` Ferruh Yigit
2017-03-10 9:01 ` Pascal Mazon
2017-03-07 16:31 ` [dpdk-dev] [PATCH v3 2/6] net/tap: add speed capabilities Pascal Mazon
2017-03-09 14:18 ` Ferruh Yigit
2017-03-09 14:36 ` Wiles, Keith
2017-03-09 16:05 ` Ferruh Yigit
2017-03-10 9:03 ` Pascal Mazon
2017-03-10 9:11 ` Pascal Mazon
2017-03-07 16:31 ` [dpdk-dev] [PATCH v3 3/6] net/tap: add multicast addresses management Pascal Mazon
2017-03-07 16:31 ` [dpdk-dev] [PATCH v3 4/6] net/tap: add MTU management Pascal Mazon
2017-03-07 16:31 ` [dpdk-dev] [PATCH v3 5/6] net/tap: add packet type management Pascal Mazon
2017-03-09 14:26 ` Ferruh Yigit
2017-03-10 12:34 ` Pascal Mazon
2017-03-07 16:31 ` [dpdk-dev] [PATCH v3 6/6] net/tap: add flow control management Pascal Mazon
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=49365496189560c2d7f8e6afc236689b7e327fbb.1489589167.git.pascal.mazon@6wind.com \
--to=pascal.mazon@6wind.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--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).