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 v2 6/7] net/tap: implement link up and down callbacks
Date: Thu, 2 Feb 2017 17:18:03 +0100 [thread overview]
Message-ID: <bbbe6488cd51155c5a54a8d1c82d82b9ec030d1b.1486026370.git.pascal.mazon@6wind.com> (raw)
In-Reply-To: <1485855778-15496-1-git-send-email-pascal.mazon@6wind.com>
In-Reply-To: <050aa06c03aa4b56f703d74a8d8a792de5e075f4.1486026370.git.pascal.mazon@6wind.com>
Signed-off-by: Pascal Mazon <pascal.mazon@6wind.com>
---
drivers/net/tap/rte_eth_tap.c | 67 +++++++++++++++++++++++++++++++++++++++----
1 file changed, 62 insertions(+), 5 deletions(-)
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 734e3a579219..275af9df2252 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -275,13 +275,69 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
return num_tx;
}
+static int tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
+{
+ 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));
+ strncpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
+ err = ioctl(s, SIOCGIFFLAGS, &ifr);
+ if (err < 0) {
+ RTE_LOG(ERR, PMD, "Unable to get tap netdevice flags: %s\n",
+ 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(ERR, PMD, "Unable to %s flags 0x%x: %s\n",
+ add ? "set" : "unset", flags, strerror(errno));
+ close(s);
+ return -1;
+ }
+ close(s);
+
+ return 0;
+}
+
static int
-tap_dev_start(struct rte_eth_dev *dev)
+tap_link_set_down(struct rte_eth_dev *dev)
{
- /* Force the Link up */
+ struct pmd_internals *pmd = dev->data->dev_private;
+
+ dev->data->dev_link.link_status = ETH_LINK_DOWN;
+ return tap_link_set_flags(pmd, IFF_UP | IFF_NOARP, 0);
+}
+
+static int
+tap_link_set_up(struct rte_eth_dev *dev)
+{
+ struct pmd_internals *pmd = dev->data->dev_private;
+
dev->data->dev_link.link_status = ETH_LINK_UP;
+ return tap_link_set_flags(pmd, IFF_UP | IFF_NOARP, 1);
+}
- return 0;
+static int
+tap_dev_start(struct rte_eth_dev *dev)
+{
+ return tap_link_set_up(dev);
}
/* This function gets called when the current port gets stopped.
@@ -295,8 +351,7 @@ tap_dev_stop(struct rte_eth_dev *dev)
for (i = 0; i < internals->nb_queues; i++)
if (internals->fds[i] != -1)
close(internals->fds[i]);
-
- dev->data->dev_link.link_status = ETH_LINK_DOWN;
+ tap_link_set_down(dev);
}
static int
@@ -532,6 +587,8 @@ static const struct eth_dev_ops ops = {
.rx_queue_release = tap_rx_queue_release,
.tx_queue_release = tap_tx_queue_release,
.link_update = tap_link_update,
+ .dev_set_link_up = tap_link_set_up,
+ .dev_set_link_down = tap_link_set_down,
.stats_get = tap_stats_get,
.stats_reset = tap_stats_reset,
};
--
2.8.0.rc0
next prev parent reply other threads:[~2017-02-02 16:18 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-31 9:42 [dpdk-dev] [PATCH 1/6] net/tap: use correct tap name Pascal Mazon
2017-01-31 9:42 ` [dpdk-dev] [PATCH 2/6] net/tap: use correct channel for error logs Pascal Mazon
2017-01-31 13:07 ` Ferruh Yigit
2017-01-31 16:58 ` Stephen Hemminger
2017-01-31 17:04 ` Wiles, Keith
2017-01-31 9:42 ` [dpdk-dev] [PATCH 3/6] net/tap: don't set fd value overwritten just below Pascal Mazon
2017-01-31 9:42 ` [dpdk-dev] [PATCH 4/6] net/tap: keep kernel-assigned MAC address Pascal Mazon
2017-01-31 13:13 ` Ferruh Yigit
2017-01-31 9:42 ` [dpdk-dev] [PATCH 5/6] net/tap: display tap name after parsing Pascal Mazon
2017-01-31 13:16 ` Ferruh Yigit
2017-01-31 9:42 ` [dpdk-dev] [PATCH 6/6] net/tap: implement link up and down callbacks Pascal Mazon
2017-01-31 13:21 ` Ferruh Yigit
2017-01-31 14:31 ` Pascal Mazon
2017-01-31 13:06 ` [dpdk-dev] [PATCH 1/6] net/tap: use correct tap name Ferruh Yigit
2017-01-31 14:23 ` Pascal Mazon
2017-01-31 15:28 ` Ferruh Yigit
2017-01-31 15:30 ` Pascal Mazon
2017-01-31 15:38 ` Ferruh Yigit
2017-01-31 15:44 ` Wiles, Keith
2017-01-31 15:44 ` Pascal Mazon
2017-01-31 16:06 ` Wiles, Keith
2017-01-31 16:39 ` Pascal Mazon
2017-01-31 23:29 ` Wiles, Keith
2017-02-01 8:11 ` Pascal Mazon
2017-02-01 15:25 ` Wiles, Keith
2017-02-01 15:40 ` Pascal Mazon
2017-02-01 15:55 ` Wiles, Keith
2017-02-01 17:50 ` Ferruh Yigit
2017-02-02 8:05 ` Pascal Mazon
2017-02-02 8:25 ` Pascal Mazon
2017-02-02 10:23 ` Ferruh Yigit
2017-01-31 14:52 ` Wiles, Keith
2017-01-31 15:14 ` Ferruh Yigit
2017-01-31 15:19 ` Wiles, Keith
2017-02-02 13:46 ` Wiles, Keith
2017-02-02 16:17 ` [dpdk-dev] [PATCH v2 1/7] " Pascal Mazon
2017-02-02 16:17 ` [dpdk-dev] [PATCH v2 2/7] net/tap: use correct channel for error logs Pascal Mazon
2017-02-02 16:18 ` [dpdk-dev] [PATCH v2 3/7] net/tap: don't set fd value overwritten just below Pascal Mazon
2017-02-02 16:18 ` [dpdk-dev] [PATCH v2 4/7] net/tap: keep kernel-assigned MAC address Pascal Mazon
2017-02-02 16:18 ` [dpdk-dev] [PATCH v2 5/7] net/tap: display tap name after parsing Pascal Mazon
2017-02-02 16:18 ` Pascal Mazon [this message]
2017-02-02 16:18 ` [dpdk-dev] [PATCH v2 7/7] net/tap: support promiscuous and allmulti setting Pascal Mazon
2017-02-02 16:23 ` [dpdk-dev] [PATCH v2 1/7] net/tap: use correct tap name Wiles, Keith
2017-02-02 16:24 ` Wiles, Keith
2017-02-02 21:55 ` 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=bbbe6488cd51155c5a54a8d1c82d82b9ec030d1b.1486026370.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).