assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE);
bridge = &netdev->u.bridge;
- helper = bridge->has_helper ? bridge->helper : NULL;
- br = bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTERFACE;
+ helper = bridge->helper;
+ br = bridge->br ?: DEFAULT_BRIDGE_INTERFACE;
fd = net_bridge_run_helper(helper, br, errp);
if (fd == -1) {
}
s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr);
- snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper,
- br);
+ qemu_set_info_str(&s->nc, "helper=%s,br=%s", helper, br);
return 0;
}
tap_set_sndbuf(s->fd, tap, &err);
if (err) {
error_propagate(errp, err);
- return;
+ goto failed;
}
- if (tap->has_fd || tap->has_fds) {
- snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);
- } else if (tap->has_helper) {
- snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s",
- tap->helper);
+ if (tap->fd || tap->fds) {
+ qemu_set_info_str(&s->nc, "fd=%d", fd);
+ } else if (tap->helper) {
+ qemu_set_info_str(&s->nc, "helper=%s", tap->helper);
} else {
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "ifname=%s,script=%s,downscript=%s", ifname, script,
- downscript);
+ qemu_set_info_str(&s->nc, "ifname=%s,script=%s,downscript=%s", ifname,
+ script, downscript);
if (strcmp(downscript, "no") != 0) {
snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
} else {
warn_report_err(err);
}
- return;
+ goto failed;
}
if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) {
error_setg_errno(errp, errno, "%s: Can't use file descriptor %d",
name, fd);
- return;
+ goto failed;
}
} else {
vhostfd = open("/dev/vhost-net", O_RDWR);
warn_report("tap: open vhost char device failed: %s",
strerror(errno));
}
- return;
+ goto failed;
}
if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) {
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
- return;
+ goto failed;
}
}
options.opaque = (void *)(uintptr_t)vhostfd;
} else {
warn_report(VHOST_NET_INIT_FAILED);
}
- return;
+ goto failed;
}
} else if (vhostfdname) {
error_setg(errp, "vhostfd(s)= is not valid without vhost");
+ goto failed;
}
+
+ return;
+
+failed:
+ qemu_del_net_client(&s->nc);
}
static int get_fds(char *str, char *fds[], int max)
assert(netdev->type == NET_CLIENT_DRIVER_TAP);
tap = &netdev->u.tap;
queues = tap->has_queues ? tap->queues : 1;
- vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
- script = tap->has_script ? tap->script : NULL;
- downscript = tap->has_downscript ? tap->downscript : NULL;
+ vhostfdname = tap->vhostfd;
+ script = tap->script;
+ downscript = tap->downscript;
/* QEMU hubs do not support multiqueue tap, in this case peer is set.
* For -netdev, peer is always NULL. */
- if (peer && (tap->has_queues || tap->has_fds || tap->has_vhostfds)) {
+ if (peer && (tap->has_queues || tap->fds || tap->vhostfds)) {
error_setg(errp, "Multiqueue tap cannot be used with hubs");
return -1;
}
- if (tap->has_fd) {
- if (tap->has_ifname || tap->has_script || tap->has_downscript ||
- tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
- tap->has_fds || tap->has_vhostfds) {
+ if (tap->fd) {
+ if (tap->ifname || tap->script || tap->downscript ||
+ tap->has_vnet_hdr || tap->helper || tap->has_queues ||
+ tap->fds || tap->vhostfds) {
error_setg(errp, "ifname=, script=, downscript=, vnet_hdr=, "
"helper=, queues=, fds=, and vhostfds= "
"are invalid with fd=");
close(fd);
return -1;
}
- } else if (tap->has_fds) {
+ } else if (tap->fds) {
char **fds;
char **vhost_fds;
int nfds = 0, nvhosts = 0;
- if (tap->has_ifname || tap->has_script || tap->has_downscript ||
- tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
- tap->has_vhostfd) {
+ if (tap->ifname || tap->script || tap->downscript ||
+ tap->has_vnet_hdr || tap->helper || tap->has_queues ||
+ tap->vhostfd) {
error_setg(errp, "ifname=, script=, downscript=, vnet_hdr=, "
"helper=, queues=, and vhostfd= "
"are invalid with fds=");
vhost_fds = g_new0(char *, MAX_TAP_QUEUES);
nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
- if (tap->has_vhostfds) {
+ if (tap->vhostfds) {
nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
if (nfds != nvhosts) {
error_setg(errp, "The number of fds passed does not match "
net_init_tap_one(tap, peer, "tap", name, ifname,
script, downscript,
- tap->has_vhostfds ? vhost_fds[i] : NULL,
+ tap->vhostfds ? vhost_fds[i] : NULL,
vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
g_free(fds);
g_free(vhost_fds);
return ret;
- } else if (tap->has_helper) {
- if (tap->has_ifname || tap->has_script || tap->has_downscript ||
- tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) {
+ } else if (tap->helper) {
+ if (tap->ifname || tap->script || tap->downscript ||
+ tap->has_vnet_hdr || tap->has_queues || tap->vhostfds) {
error_setg(errp, "ifname=, script=, downscript=, vnet_hdr=, "
"queues=, and vhostfds= are invalid with helper=");
return -1;
}
fd = net_bridge_run_helper(tap->helper,
- tap->has_br ?
- tap->br : DEFAULT_BRIDGE_INTERFACE,
+ tap->br ?: DEFAULT_BRIDGE_INTERFACE,
errp);
if (fd == -1) {
return -1;
} else {
g_autofree char *default_script = NULL;
g_autofree char *default_downscript = NULL;
- if (tap->has_vhostfds) {
+ if (tap->vhostfds) {
error_setg(errp, "vhostfds= is invalid if fds= wasn't specified");
return -1;
}
get_relocated_path(DEFAULT_NETWORK_DOWN_SCRIPT);
}
- if (tap->has_ifname) {
+ if (tap->ifname) {
pstrcpy(ifname, sizeof ifname, tap->ifname);
} else {
ifname[0] = '\0';
return -1;
}
- if (queues > 1 && i == 0 && !tap->has_ifname) {
+ if (queues > 1 && i == 0 && !tap->ifname) {
if (tap_fd_get_ifname(fd, ifname)) {
error_setg(errp, "Fail to get ifname");
close(fd);