The multiqueue support in virtio-user with vhost kernel backend
is broken when tap name isn't specified by users explicitly,
because the tap name returned by ioctl(TUNSETIFF) isn't saved
properly, and multiple tap interfaces will be created in this
case. Fix this by saving the dynamically allocated tap name
first before reusing the ifr structure. Besides, also make it
possible to support the format string in tap name (e.g. foo%d)
specified by users explicitly.
Fixes:
791b43e08842 ("net/virtio-user: specify MAC of the tap")
Cc: stable@dpdk.org
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
const char *mac, uint64_t features)
{
unsigned int tap_features;
+ char *tap_name = NULL;
int sndbuf = INT_MAX;
struct ifreq ifr;
int tapfd;
goto error;
}
+ tap_name = strdup(ifr.ifr_name);
+ if (!tap_name) {
+ PMD_DRV_LOG(ERR, "strdup ifname failed: %s", strerror(errno));
+ goto error;
+ }
+
fcntl(tapfd, F_SETFL, O_NONBLOCK);
if (ioctl(tapfd, TUNSETVNETHDRSZ, &hdr_size) < 0) {
goto error;
}
- if (!(*p_ifname))
- *p_ifname = strdup(ifr.ifr_name);
+ free(*p_ifname);
+ *p_ifname = tap_name;
return tapfd;
error:
+ free(tap_name);
close(tapfd);
return -1;
}