Skip to content

Commit

Permalink
net/tap: restore state of remote device when closing
Browse files Browse the repository at this point in the history
When exiting a DPDK application, the TAP remote was left
with the link down even if it was initially up.

The device flags of the remote netdevice are saved when probing,
and restored when calling the close function.
The remote state is not set down when calling the stop function anymore.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Pascal Mazon <pascal.mazon@6wind.com>
  • Loading branch information
tmonjalo authored and Ferruh Yigit committed Jul 6, 2017
1 parent 856ceb3 commit 4810d3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion drivers/net/tap/rte_eth_tap.c
Expand Up @@ -569,7 +569,7 @@ tap_link_set_down(struct rte_eth_dev *dev)
struct ifreq ifr = { .ifr_flags = IFF_UP };

dev->data->dev_link.link_status = ETH_LINK_DOWN;
return tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 0, LOCAL_AND_REMOTE);
return tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 0, LOCAL_ONLY);
}

static int
Expand Down Expand Up @@ -735,6 +735,12 @@ tap_dev_close(struct rte_eth_dev *dev)
internals->rxq[i].fd = -1;
internals->txq[i].fd = -1;
}

if (internals->remote_if_index) {
/* Restore initial remote state */
ioctl(internals->ioctl_sock, SIOCSIFFLAGS,
&internals->remote_initial_flags);
}
}

static void
Expand Down Expand Up @@ -1320,6 +1326,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
}
snprintf(pmd->remote_iface, RTE_ETH_NAME_MAX_LEN,
"%s", remote_iface);

/* Save state of remote device */
tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY);

/* Replicate remote MAC address */
if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, REMOTE_ONLY) < 0) {
RTE_LOG(ERR, PMD, "%s: failed to get %s MAC address.",
pmd->name, pmd->remote_iface);
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/tap/rte_eth_tap.h
Expand Up @@ -37,6 +37,7 @@
#include <sys/queue.h>
#include <sys/uio.h>
#include <inttypes.h>
#include <net/if.h>

#include <linux/if_tun.h>

Expand Down Expand Up @@ -83,6 +84,7 @@ struct pmd_internals {
char name[RTE_ETH_NAME_MAX_LEN]; /* Internal Tap device name */
uint16_t nb_queues; /* Number of queues supported */
struct ether_addr eth_addr; /* Mac address of the device port */
struct ifreq remote_initial_flags; /* Remote netdevice flags on init */
int remote_if_index; /* remote netdevice IF_INDEX */
int if_index; /* IF_INDEX for the port */
int ioctl_sock; /* socket for ioctl calls */
Expand Down

0 comments on commit 4810d3a

Please sign in to comment.