@@ -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,