static void tap_send(void *opaque);
static void tap_writable(void *opaque);
+static char *tap_parse_script(const char *script_arg, const char *default_path)
+{
+ g_autofree char *res = g_strdup(script_arg);
+
+ if (!res) {
+ res = get_relocated_path(default_path);
+ }
+
+ if (res[0] == '\0' || strcmp(res, "no") == 0) {
+ return NULL;
+ }
+
+ return g_steal_pointer(&res);
+}
+
static void tap_update_fd_handler(TAPState *s)
{
qemu_set_fd_handler(s->fd,
return -1;
}
- if (setup_script &&
- setup_script[0] != '\0' &&
- strcmp(setup_script, "no") != 0) {
+ if (setup_script) {
launch_script(setup_script, ifname, fd, &err);
if (err) {
error_propagate(errp, err);
qemu_set_info_str(&s->nc, "helper=%s", tap->helper);
} else {
qemu_set_info_str(&s->nc, "ifname=%s,script=%s,downscript=%s", ifname,
- script, downscript);
+ script ?: "no", downscript ?: "no");
- if (strcmp(downscript, "no") != 0) {
+ if (downscript) {
snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
snprintf(s->down_script_arg, sizeof(s->down_script_arg),
"%s", ifname);
return -1;
}
} else {
- const char *script = tap->script;
- const char *downscript = tap->downscript;
- g_autofree char *default_script = NULL;
- g_autofree char *default_downscript = NULL;
+ g_autofree char *script =
+ tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT);
+ g_autofree char *downscript =
+ tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT);
+
if (tap->vhostfds) {
error_setg(errp, "vhostfds= is invalid if fds= wasn't specified");
return -1;
}
- if (!script) {
- script = default_script = get_relocated_path(DEFAULT_NETWORK_SCRIPT);
- }
- if (!downscript) {
- downscript = default_downscript =
- get_relocated_path(DEFAULT_NETWORK_DOWN_SCRIPT);
- }
-
if (tap->ifname) {
pstrcpy(ifname, sizeof ifname, tap->ifname);
} else {
}
for (i = 0; i < queues; i++) {
- fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? "no" : script,
+ fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? NULL : script,
ifname, sizeof ifname, queues > 1, errp);
if (fd == -1) {
return -1;
}
net_init_tap_one(tap, peer, "tap", name, ifname,
- i >= 1 ? "no" : script,
- i >= 1 ? "no" : downscript,
+ i >= 1 ? NULL : script,
+ i >= 1 ? NULL : downscript,
vhostfdname, vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);