diff mbox series

[API-NEXT,v2,1/3] linux-gen: pktio: tap: implement start/stop operations

Message ID 1508400012-1278-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v2,1/3] linux-gen: pktio: tap: implement start/stop operations | expand

Commit Message

Github ODP bot Oct. 19, 2017, 8 a.m. UTC
From: Bogdan Pricope <bogdan.pricope@linaro.org>


Implement start/stop tap pktio operations.

Signed-off-by: Bogdan Pricope <bogdan.pricope@linaro.org>

---
/** Email created from pull request 232 (bogdanPricope:tap_set_mac_pr)
 ** https://github.com/Linaro/odp/pull/232
 ** Patch: https://github.com/Linaro/odp/pull/232.patch
 ** Base sha: edca8cd1e55898826f79383b689c2c4bd2c28b3a
 ** Merge commit sha: 89f18d929052add128b4252f5b17907b9a354ccb
 **/
 platform/linux-generic/pktio/tap.c | 72 +++++++++++++++++++++++++++++++-------
 1 file changed, 59 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c
index ed4479445..8ddd757d9 100644
--- a/platform/linux-generic/pktio/tap.c
+++ b/platform/linux-generic/pktio/tap.c
@@ -134,8 +134,30 @@  static int tap_pktio_open(odp_pktio_t id ODP_UNUSED,
 		goto sock_err;
 	}
 
-	/* Up interface by default. */
-	if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) {
+	tap->fd = fd;
+	tap->skfd = skfd;
+	tap->mtu = mtu;
+	tap->pool = pool;
+	return 0;
+sock_err:
+	close(skfd);
+tap_err:
+	close(fd);
+	ODP_ERR("Tap device alloc failed.\n");
+	return -1;
+}
+
+static int tap_pktio_start(pktio_entry_t *pktio_entry)
+{
+	struct ifreq ifr;
+	pkt_tap_t *tap = &pktio_entry->s.pkt_tap;
+
+	odp_memset(&ifr, 0, sizeof(ifr));
+	snprintf(ifr.ifr_name, IF_NAMESIZE, "%s",
+		 (char *)pktio_entry->s.name + 4);
+
+		/* Up interface by default. */
+	if (ioctl(tap->skfd, SIOCGIFFLAGS, &ifr) < 0) {
 		__odp_errno = errno;
 		ODP_ERR("ioctl(SIOCGIFFLAGS) failed: %s\n", strerror(errno));
 		goto sock_err;
@@ -144,22 +166,46 @@  static int tap_pktio_open(odp_pktio_t id ODP_UNUSED,
 	ifr.ifr_flags |= IFF_UP;
 	ifr.ifr_flags |= IFF_RUNNING;
 
-	if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) {
+	if (ioctl(tap->skfd, SIOCSIFFLAGS, &ifr) < 0) {
 		__odp_errno = errno;
 		ODP_ERR("failed to come up: %s\n", strerror(errno));
 		goto sock_err;
 	}
 
-	tap->fd = fd;
-	tap->skfd = skfd;
-	tap->mtu = mtu;
-	tap->pool = pool;
 	return 0;
 sock_err:
-	close(skfd);
-tap_err:
-	close(fd);
-	ODP_ERR("Tap device alloc failed.\n");
+	ODP_ERR("Tap device open failed.\n");
+	return -1;
+}
+
+static int tap_pktio_stop(pktio_entry_t *pktio_entry)
+{
+	struct ifreq ifr;
+	pkt_tap_t *tap = &pktio_entry->s.pkt_tap;
+
+	odp_memset(&ifr, 0, sizeof(ifr));
+	snprintf(ifr.ifr_name, IF_NAMESIZE, "%s",
+		 (char *)pktio_entry->s.name + 4);
+
+		/* Up interface by default. */
+	if (ioctl(tap->skfd, SIOCGIFFLAGS, &ifr) < 0) {
+		__odp_errno = errno;
+		ODP_ERR("ioctl(SIOCGIFFLAGS) failed: %s\n", strerror(errno));
+		goto sock_err;
+	}
+
+	ifr.ifr_flags &= ~IFF_UP;
+	ifr.ifr_flags &= ~IFF_RUNNING;
+
+	if (ioctl(tap->skfd, SIOCSIFFLAGS, &ifr) < 0) {
+		__odp_errno = errno;
+		ODP_ERR("failed to come up: %s\n", strerror(errno));
+		goto sock_err;
+	}
+
+	return 0;
+sock_err:
+	ODP_ERR("Tap device open failed.\n");
 	return -1;
 }
 
@@ -383,8 +429,8 @@  const pktio_if_ops_t tap_pktio_ops = {
 	.term = NULL,
 	.open = tap_pktio_open,
 	.close = tap_pktio_close,
-	.start = NULL,
-	.stop = NULL,
+	.start = tap_pktio_start,
+	.stop = tap_pktio_stop,
 	.recv = tap_pktio_recv,
 	.send = tap_pktio_send,
 	.mtu_get = tap_mtu_get,