int net_client_init(Monitor *mon, const char *device, const char *p)

{

    char buf[1024];

    int vlan_id, ret;

    VLANState *vlan;

    char *name = NULL;



    vlan_id = 0;

    if (get_param_value(buf, sizeof(buf), "vlan", p)) {

        vlan_id = strtol(buf, NULL, 0);

    }

    vlan = qemu_find_vlan(vlan_id, 1);



    if (get_param_value(buf, sizeof(buf), "name", p)) {

        name = qemu_strdup(buf);

    }

    if (!strcmp(device, "nic")) {

        static const char * const nic_params[] = {

            "vlan", "name", "macaddr", "model", "addr", "id", "vectors", NULL

        };

        NICInfo *nd;

        uint8_t *macaddr;

        int idx = nic_get_free_idx();



        if (check_params(buf, sizeof(buf), nic_params, p) < 0) {

            config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);

            ret = -1;

            goto out;

        }

        if (idx == -1 || nb_nics >= MAX_NICS) {

            config_error(mon, "Too Many NICs\n");

            ret = -1;

            goto out;

        }

        nd = &nd_table[idx];

        memset(nd, 0, sizeof(*nd));

        macaddr = nd->macaddr;

        macaddr[0] = 0x52;

        macaddr[1] = 0x54;

        macaddr[2] = 0x00;

        macaddr[3] = 0x12;

        macaddr[4] = 0x34;

        macaddr[5] = 0x56 + idx;



        if (get_param_value(buf, sizeof(buf), "macaddr", p)) {

            if (parse_macaddr(macaddr, buf) < 0) {

                config_error(mon, "invalid syntax for ethernet address\n");

                ret = -1;

                goto out;

            }

        }

        if (get_param_value(buf, sizeof(buf), "model", p)) {

            nd->model = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "addr", p)) {

            nd->devaddr = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "id", p)) {

            nd->id = qemu_strdup(buf);

        }

        nd->nvectors = NIC_NVECTORS_UNSPECIFIED;

        if (get_param_value(buf, sizeof(buf), "vectors", p)) {

            char *endptr;

            long vectors = strtol(buf, &endptr, 0);

            if (*endptr) {

                config_error(mon, "invalid syntax for # of vectors\n");

                ret = -1;

                goto out;

            }

            if (vectors < 0 || vectors > 0x7ffffff) {

                config_error(mon, "invalid # of vectors\n");

                ret = -1;

                goto out;

            }

            nd->nvectors = vectors;

        }

        nd->vlan = vlan;

        nd->name = name;

        nd->used = 1;

        name = NULL;

        nb_nics++;

        vlan->nb_guest_devs++;

        ret = idx;

    } else

    if (!strcmp(device, "none")) {

        if (*p != '\0') {

            config_error(mon, "'none' takes no parameters\n");

            ret = -1;

            goto out;

        }

        /* does nothing. It is needed to signal that no network cards

           are wanted */

        ret = 0;

    } else

#ifdef CONFIG_SLIRP

    if (!strcmp(device, "user")) {

        static const char * const slirp_params[] = {

            "vlan", "name", "hostname", "restrict", "ip", "net", "host",

            "tftp", "bootfile", "dhcpstart", "dns", "smb", "smbserver",

            "hostfwd", "guestfwd", NULL

        };

        struct slirp_config_str *config;

        int restricted = 0;

        char *vnet = NULL;

        char *vhost = NULL;

        char *vhostname = NULL;

        char *tftp_export = NULL;

        char *bootfile = NULL;

        char *vdhcp_start = NULL;

        char *vnamesrv = NULL;

        char *smb_export = NULL;

        char *vsmbsrv = NULL;

        const char *q;



        if (check_params(buf, sizeof(buf), slirp_params, p) < 0) {

            config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);

            ret = -1;

            goto out;

        }

        if (get_param_value(buf, sizeof(buf), "ip", p)) {

            int vnet_buflen = strlen(buf) + strlen("/24") + 1;

            /* emulate legacy parameter */

            vnet = qemu_malloc(vnet_buflen);

            pstrcpy(vnet, vnet_buflen, buf);

            pstrcat(vnet, vnet_buflen, "/24");

        }

        if (get_param_value(buf, sizeof(buf), "net", p)) {

            vnet = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "host", p)) {

            vhost = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "hostname", p)) {

            vhostname = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "restrict", p)) {

            restricted = (buf[0] == 'y') ? 1 : 0;

        }

        if (get_param_value(buf, sizeof(buf), "dhcpstart", p)) {

            vdhcp_start = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "dns", p)) {

            vnamesrv = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "tftp", p)) {

            tftp_export = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "bootfile", p)) {

            bootfile = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "smb", p)) {

            smb_export = qemu_strdup(buf);

            if (get_param_value(buf, sizeof(buf), "smbserver", p)) {

                vsmbsrv = qemu_strdup(buf);

            }

        }

        q = p;

        while (1) {

            config = qemu_malloc(sizeof(*config));

            if (!get_next_param_value(config->str, sizeof(config->str),

                                      "hostfwd", &q)) {

                break;

            }

            config->flags = SLIRP_CFG_HOSTFWD;

            config->next = slirp_configs;

            slirp_configs = config;

            config = NULL;

        }

        q = p;

        while (1) {

            config = qemu_malloc(sizeof(*config));

            if (!get_next_param_value(config->str, sizeof(config->str),

                                      "guestfwd", &q)) {

                break;

            }

            config->flags = 0;

            config->next = slirp_configs;

            slirp_configs = config;

            config = NULL;

        }

        qemu_free(config);

        vlan->nb_host_devs++;

        ret = net_slirp_init(mon, vlan, device, name, restricted, vnet, vhost,

                             vhostname, tftp_export, bootfile, vdhcp_start,

                             vnamesrv, smb_export, vsmbsrv);

        while (slirp_configs) {

            config = slirp_configs;

            slirp_configs = config->next;

            qemu_free(config);

        }

        qemu_free(vnet);

        qemu_free(vhost);

        qemu_free(vhostname);

        qemu_free(tftp_export);

        qemu_free(bootfile);

        qemu_free(vdhcp_start);

        qemu_free(vnamesrv);

        qemu_free(smb_export);

        qemu_free(vsmbsrv);

    } else if (!strcmp(device, "channel")) {

        if (QTAILQ_EMPTY(&slirp_stacks)) {

            struct slirp_config_str *config;



            config = qemu_malloc(sizeof(*config));

            pstrcpy(config->str, sizeof(config->str), p);

            config->flags = SLIRP_CFG_LEGACY;

            config->next = slirp_configs;

            slirp_configs = config;

        } else {

            slirp_guestfwd(QTAILQ_FIRST(&slirp_stacks), mon, p, 1);

        }

        ret = 0;

    } else

#endif

#ifdef _WIN32

    if (!strcmp(device, "tap")) {

        static const char * const tap_params[] = {

            "vlan", "name", "ifname", NULL

        };

        char ifname[64];



        if (check_params(buf, sizeof(buf), tap_params, p) < 0) {

            config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);

            ret = -1;

            goto out;

        }

        if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {

            config_error(mon, "tap: no interface name\n");

            ret = -1;

            goto out;

        }

        vlan->nb_host_devs++;

        ret = tap_win32_init(vlan, device, name, ifname);

    } else

#elif defined (_AIX)

#else

    if (!strcmp(device, "tap")) {

        char ifname[64], chkbuf[64];

        char setup_script[1024], down_script[1024];

        TAPState *s;

        int fd;

        vlan->nb_host_devs++;

        if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {

            static const char * const fd_params[] = {

                "vlan", "name", "fd", "sndbuf", NULL

            };

            ret = -1;

            if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                goto out;

            }

            fd = net_handle_fd_param(mon, buf);

            if (fd == -1) {

                goto out;

            }

            fcntl(fd, F_SETFL, O_NONBLOCK);

            s = net_tap_fd_init(vlan, device, name, fd);

            if (!s) {

                close(fd);

            }

        } else {

            static const char * const tap_params[] = {

                "vlan", "name", "ifname", "script", "downscript", "sndbuf", NULL

            };

            if (check_params(chkbuf, sizeof(chkbuf), tap_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                ret = -1;

                goto out;

            }

            if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {

                ifname[0] = '\0';

            }

            if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) {

                pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT);

            }

            if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {

                pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);

            }

            s = net_tap_init(vlan, device, name, ifname, setup_script, down_script);

        }

        if (s != NULL) {

            const char *sndbuf_str = NULL;

            if (get_param_value(buf, sizeof(buf), "sndbuf", p)) {

                sndbuf_str = buf;

            }

            tap_set_sndbuf(s, sndbuf_str, mon);

            ret = 0;

        } else {

            ret = -1;

        }

    } else

#endif

    if (!strcmp(device, "socket")) {

        char chkbuf[64];

        if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {

            static const char * const fd_params[] = {

                "vlan", "name", "fd", NULL

            };

            int fd;

            ret = -1;

            if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                goto out;

            }

            fd = net_handle_fd_param(mon, buf);

            if (fd == -1) {

                goto out;

            }

            if (!net_socket_fd_init(vlan, device, name, fd, 1)) {

                close(fd);

                goto out;

            }

            ret = 0;

        } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {

            static const char * const listen_params[] = {

                "vlan", "name", "listen", NULL

            };

            if (check_params(chkbuf, sizeof(chkbuf), listen_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                ret = -1;

                goto out;

            }

            ret = net_socket_listen_init(vlan, device, name, buf);

        } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {

            static const char * const connect_params[] = {

                "vlan", "name", "connect", NULL

            };

            if (check_params(chkbuf, sizeof(chkbuf), connect_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                ret = -1;

                goto out;

            }

            ret = net_socket_connect_init(vlan, device, name, buf);

        } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {

            static const char * const mcast_params[] = {

                "vlan", "name", "mcast", NULL

            };

            if (check_params(chkbuf, sizeof(chkbuf), mcast_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                ret = -1;

                goto out;

            }

            ret = net_socket_mcast_init(vlan, device, name, buf);

        } else {

            config_error(mon, "Unknown socket options: %s\n", p);

            ret = -1;

            goto out;

        }

        vlan->nb_host_devs++;

    } else

#ifdef CONFIG_VDE

    if (!strcmp(device, "vde")) {

        static const char * const vde_params[] = {

            "vlan", "name", "sock", "port", "group", "mode", NULL

        };

        char vde_sock[1024], vde_group[512];

	int vde_port, vde_mode;



        if (check_params(buf, sizeof(buf), vde_params, p) < 0) {

            config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);

            ret = -1;

            goto out;

        }

        vlan->nb_host_devs++;

        if (get_param_value(vde_sock, sizeof(vde_sock), "sock", p) <= 0) {

	    vde_sock[0] = '\0';

	}

	if (get_param_value(buf, sizeof(buf), "port", p) > 0) {

	    vde_port = strtol(buf, NULL, 10);

	} else {

	    vde_port = 0;

	}

	if (get_param_value(vde_group, sizeof(vde_group), "group", p) <= 0) {

	    vde_group[0] = '\0';

	}

	if (get_param_value(buf, sizeof(buf), "mode", p) > 0) {

	    vde_mode = strtol(buf, NULL, 8);

	} else {

	    vde_mode = 0700;

	}

	ret = net_vde_init(vlan, device, name, vde_sock, vde_port, vde_group, vde_mode);

    } else

#endif

    if (!strcmp(device, "dump")) {

        int len = 65536;



        if (get_param_value(buf, sizeof(buf), "len", p) > 0) {

            len = strtol(buf, NULL, 0);

        }

        if (!get_param_value(buf, sizeof(buf), "file", p)) {

            snprintf(buf, sizeof(buf), "qemu-vlan%d.pcap", vlan_id);

        }

        ret = net_dump_init(mon, vlan, device, name, buf, len);

    } else {

        config_error(mon, "Unknown network device: %s\n", device);

        ret = -1;

        goto out;

    }

    if (ret < 0) {

        config_error(mon, "Could not initialize device '%s'\n", device);

    }

out:

    qemu_free(name);

    return ret;

}

int net_client_init(Monitor *mon, const char *device, const char *p)

{

    char buf[1024];

    int vlan_id, ret;

    VLANState *vlan;

    char *name = NULL;



    vlan_id = 0;

    if (get_param_value(buf, sizeof(buf), "vlan", p)) {

        vlan_id = strtol(buf, NULL, 0);

    }

    vlan = qemu_find_vlan(vlan_id, 1);



    if (get_param_value(buf, sizeof(buf), "name", p)) {

        name = qemu_strdup(buf);

    }

    if (!strcmp(device, "nic")) {

        static const char * const nic_params[] = {

            "vlan", "name", "macaddr", "model", "addr", "id", "vectors", NULL

        };

        NICInfo *nd;

        uint8_t *macaddr;

        int idx = nic_get_free_idx();



        if (check_params(buf, sizeof(buf), nic_params, p) < 0) {

            config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);

            ret = -1;

            goto out;

        }

        if (idx == -1 || nb_nics >= MAX_NICS) {

            config_error(mon, "Too Many NICs\n");

            ret = -1;

            goto out;

        }

        nd = &nd_table[idx];

        memset(nd, 0, sizeof(*nd));

        macaddr = nd->macaddr;

        macaddr[0] = 0x52;

        macaddr[1] = 0x54;

        macaddr[2] = 0x00;

        macaddr[3] = 0x12;

        macaddr[4] = 0x34;

        macaddr[5] = 0x56 + idx;



        if (get_param_value(buf, sizeof(buf), "macaddr", p)) {

            if (parse_macaddr(macaddr, buf) < 0) {

                config_error(mon, "invalid syntax for ethernet address\n");

                ret = -1;

                goto out;

            }

        }

        if (get_param_value(buf, sizeof(buf), "model", p)) {

            nd->model = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "addr", p)) {

            nd->devaddr = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "id", p)) {

            nd->id = qemu_strdup(buf);

        }

        nd->nvectors = NIC_NVECTORS_UNSPECIFIED;

        if (get_param_value(buf, sizeof(buf), "vectors", p)) {

            char *endptr;

            long vectors = strtol(buf, &endptr, 0);

            if (*endptr) {

                config_error(mon, "invalid syntax for # of vectors\n");

                ret = -1;

                goto out;

            }

            if (vectors < 0 || vectors > 0x7ffffff) {

                config_error(mon, "invalid # of vectors\n");

                ret = -1;

                goto out;

            }

            nd->nvectors = vectors;

        }

        nd->vlan = vlan;

        nd->name = name;

        nd->used = 1;

        name = NULL;

        nb_nics++;

        vlan->nb_guest_devs++;

        ret = idx;

    } else

    if (!strcmp(device, "none")) {

        if (*p != '\0') {

            config_error(mon, "'none' takes no parameters\n");

            ret = -1;

            goto out;

        }

        



        ret = 0;

    } else

#ifdef CONFIG_SLIRP

    if (!strcmp(device, "user")) {

        static const char * const slirp_params[] = {

            "vlan", "name", "hostname", "restrict", "ip", "net", "host",

            "tftp", "bootfile", "dhcpstart", "dns", "smb", "smbserver",

            "hostfwd", "guestfwd", NULL

        };

        struct slirp_config_str *config;

        int restricted = 0;

        char *vnet = NULL;

        char *vhost = NULL;

        char *vhostname = NULL;

        char *tftp_export = NULL;

        char *bootfile = NULL;

        char *vdhcp_start = NULL;

        char *vnamesrv = NULL;

        char *smb_export = NULL;

        char *vsmbsrv = NULL;

        const char *q;



        if (check_params(buf, sizeof(buf), slirp_params, p) < 0) {

            config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);

            ret = -1;

            goto out;

        }

        if (get_param_value(buf, sizeof(buf), "ip", p)) {

            int vnet_buflen = strlen(buf) + strlen("/24") + 1;

            

            vnet = qemu_malloc(vnet_buflen);

            pstrcpy(vnet, vnet_buflen, buf);

            pstrcat(vnet, vnet_buflen, "/24");

        }

        if (get_param_value(buf, sizeof(buf), "net", p)) {

            vnet = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "host", p)) {

            vhost = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "hostname", p)) {

            vhostname = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "restrict", p)) {

            restricted = (buf[0] == 'y') ? 1 : 0;

        }

        if (get_param_value(buf, sizeof(buf), "dhcpstart", p)) {

            vdhcp_start = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "dns", p)) {

            vnamesrv = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "tftp", p)) {

            tftp_export = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "bootfile", p)) {

            bootfile = qemu_strdup(buf);

        }

        if (get_param_value(buf, sizeof(buf), "smb", p)) {

            smb_export = qemu_strdup(buf);

            if (get_param_value(buf, sizeof(buf), "smbserver", p)) {

                vsmbsrv = qemu_strdup(buf);

            }

        }

        q = p;

        while (1) {

            config = qemu_malloc(sizeof(*config));

            if (!get_next_param_value(config->str, sizeof(config->str),

                                      "hostfwd", &q)) {

                break;

            }

            config->flags = SLIRP_CFG_HOSTFWD;

            config->next = slirp_configs;

            slirp_configs = config;

            config = NULL;

        }

        q = p;

        while (1) {

            config = qemu_malloc(sizeof(*config));

            if (!get_next_param_value(config->str, sizeof(config->str),

                                      "guestfwd", &q)) {

                break;

            }

            config->flags = 0;

            config->next = slirp_configs;

            slirp_configs = config;

            config = NULL;

        }

        qemu_free(config);

        vlan->nb_host_devs++;

        ret = net_slirp_init(mon, vlan, device, name, restricted, vnet, vhost,

                             vhostname, tftp_export, bootfile, vdhcp_start,

                             vnamesrv, smb_export, vsmbsrv);

        while (slirp_configs) {

            config = slirp_configs;

            slirp_configs = config->next;

            qemu_free(config);

        }

        qemu_free(vnet);

        qemu_free(vhost);

        qemu_free(vhostname);

        qemu_free(tftp_export);

        qemu_free(bootfile);

        qemu_free(vdhcp_start);

        qemu_free(vnamesrv);

        qemu_free(smb_export);

        qemu_free(vsmbsrv);

    } else if (!strcmp(device, "channel")) {

        if (QTAILQ_EMPTY(&slirp_stacks)) {

            struct slirp_config_str *config;



            config = qemu_malloc(sizeof(*config));

            pstrcpy(config->str, sizeof(config->str), p);

            config->flags = SLIRP_CFG_LEGACY;

            config->next = slirp_configs;

            slirp_configs = config;

        } else {

            slirp_guestfwd(QTAILQ_FIRST(&slirp_stacks), mon, p, 1);

        }

        ret = 0;

    } else

#endif

#ifdef _WIN32

    if (!strcmp(device, "tap")) {

        static const char * const tap_params[] = {

            "vlan", "name", "ifname", NULL

        };

        char ifname[64];



        if (check_params(buf, sizeof(buf), tap_params, p) < 0) {

            config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);

            ret = -1;

            goto out;

        }

        if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {

            config_error(mon, "tap: no interface name\n");

            ret = -1;

            goto out;

        }

        vlan->nb_host_devs++;

        ret = tap_win32_init(vlan, device, name, ifname);

    } else

#elif defined (_AIX)

#else

    if (!strcmp(device, "tap")) {

        char ifname[64], chkbuf[64];

        char setup_script[1024], down_script[1024];

        TAPState *s;

        int fd;

        vlan->nb_host_devs++;

        if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {

            static const char * const fd_params[] = {

                "vlan", "name", "fd", "sndbuf", NULL

            };

            ret = -1;

            if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                goto out;

            }

            fd = net_handle_fd_param(mon, buf);

            if (fd == -1) {

                goto out;

            }

            fcntl(fd, F_SETFL, O_NONBLOCK);

            s = net_tap_fd_init(vlan, device, name, fd);

            if (!s) {

                close(fd);

            }

        } else {

            static const char * const tap_params[] = {

                "vlan", "name", "ifname", "script", "downscript", "sndbuf", NULL

            };

            if (check_params(chkbuf, sizeof(chkbuf), tap_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                ret = -1;

                goto out;

            }

            if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {

                ifname[0] = '\0';

            }

            if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) {

                pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT);

            }

            if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {

                pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);

            }

            s = net_tap_init(vlan, device, name, ifname, setup_script, down_script);

        }

        if (s != NULL) {

            const char *sndbuf_str = NULL;

            if (get_param_value(buf, sizeof(buf), "sndbuf", p)) {

                sndbuf_str = buf;

            }

            tap_set_sndbuf(s, sndbuf_str, mon);

            ret = 0;

        } else {

            ret = -1;

        }

    } else

#endif

    if (!strcmp(device, "socket")) {

        char chkbuf[64];

        if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {

            static const char * const fd_params[] = {

                "vlan", "name", "fd", NULL

            };

            int fd;

            ret = -1;

            if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                goto out;

            }

            fd = net_handle_fd_param(mon, buf);

            if (fd == -1) {

                goto out;

            }

            if (!net_socket_fd_init(vlan, device, name, fd, 1)) {

                close(fd);

                goto out;

            }

            ret = 0;

        } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {

            static const char * const listen_params[] = {

                "vlan", "name", "listen", NULL

            };

            if (check_params(chkbuf, sizeof(chkbuf), listen_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                ret = -1;

                goto out;

            }

            ret = net_socket_listen_init(vlan, device, name, buf);

        } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {

            static const char * const connect_params[] = {

                "vlan", "name", "connect", NULL

            };

            if (check_params(chkbuf, sizeof(chkbuf), connect_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                ret = -1;

                goto out;

            }

            ret = net_socket_connect_init(vlan, device, name, buf);

        } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {

            static const char * const mcast_params[] = {

                "vlan", "name", "mcast", NULL

            };

            if (check_params(chkbuf, sizeof(chkbuf), mcast_params, p) < 0) {

                config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);

                ret = -1;

                goto out;

            }

            ret = net_socket_mcast_init(vlan, device, name, buf);

        } else {

            config_error(mon, "Unknown socket options: %s\n", p);

            ret = -1;

            goto out;

        }

        vlan->nb_host_devs++;

    } else

#ifdef CONFIG_VDE

    if (!strcmp(device, "vde")) {

        static const char * const vde_params[] = {

            "vlan", "name", "sock", "port", "group", "mode", NULL

        };

        char vde_sock[1024], vde_group[512];

	int vde_port, vde_mode;



        if (check_params(buf, sizeof(buf), vde_params, p) < 0) {

            config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);

            ret = -1;

            goto out;

        }

        vlan->nb_host_devs++;

        if (get_param_value(vde_sock, sizeof(vde_sock), "sock", p) <= 0) {

	    vde_sock[0] = '\0';

	}

	if (get_param_value(buf, sizeof(buf), "port", p) > 0) {

	    vde_port = strtol(buf, NULL, 10);

	} else {

	    vde_port = 0;

	}

	if (get_param_value(vde_group, sizeof(vde_group), "group", p) <= 0) {

	    vde_group[0] = '\0';

	}

	if (get_param_value(buf, sizeof(buf), "mode", p) > 0) {

	    vde_mode = strtol(buf, NULL, 8);

	} else {

	    vde_mode = 0700;

	}

	ret = net_vde_init(vlan, device, name, vde_sock, vde_port, vde_group, vde_mode);

    } else

#endif

    if (!strcmp(device, "dump")) {

        int len = 65536;



        if (get_param_value(buf, sizeof(buf), "len", p) > 0) {

            len = strtol(buf, NULL, 0);

        }

        if (!get_param_value(buf, sizeof(buf), "file", p)) {

            snprintf(buf, sizeof(buf), "qemu-vlan%d.pcap", vlan_id);

        }

        ret = net_dump_init(mon, vlan, device, name, buf, len);

    } else {

        config_error(mon, "Unknown network device: %s\n", device);

        ret = -1;

        goto out;

    }

    if (ret < 0) {

        config_error(mon, "Could not initialize device '%s'\n", device);

    }

out:

    qemu_free(name);

    return ret;

}

            slirp_guestfwd(QTAILQ_FIRST(&slirp_stacks), mon, p, 1);         ret = 0;             tap_set_sndbuf(s, sndbuf_str, mon);             ret = 0;
int FUNC_0(Monitor *VAR_0, const char *VAR_1, const char *VAR_2)

{

    char VAR_3[1024];

    int VAR_4, VAR_5;

    VLANState *vlan;

    char *VAR_6 = NULL;



    VAR_4 = 0;

    if (get_param_value(VAR_3, sizeof(VAR_3), "vlan", VAR_2)) {

        VAR_4 = strtol(VAR_3, NULL, 0);

    }

    vlan = qemu_find_vlan(VAR_4, 1);



    if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_6", VAR_2)) {

        VAR_6 = qemu_strdup(VAR_3);

    }

    if (!strcmp(VAR_1, "nic")) {

        static const char * const VAR_7[] = {

            "vlan", "VAR_6", "macaddr", "model", "addr", "id", "VAR_10", NULL

        };

        NICInfo *nd;

        uint8_t *macaddr;

        int VAR_8 = nic_get_free_idx();



        if (check_params(VAR_3, sizeof(VAR_3), VAR_7, VAR_2) < 0) {

            config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_3, VAR_2);

            VAR_5 = -1;

            goto out;

        }

        if (VAR_8 == -1 || nb_nics >= MAX_NICS) {

            config_error(VAR_0, "Too Many NICs\n");

            VAR_5 = -1;

            goto out;

        }

        nd = &nd_table[VAR_8];

        memset(nd, 0, sizeof(*nd));

        macaddr = nd->macaddr;

        macaddr[0] = 0x52;

        macaddr[1] = 0x54;

        macaddr[2] = 0x00;

        macaddr[3] = 0x12;

        macaddr[4] = 0x34;

        macaddr[5] = 0x56 + VAR_8;



        if (get_param_value(VAR_3, sizeof(VAR_3), "macaddr", VAR_2)) {

            if (parse_macaddr(macaddr, VAR_3) < 0) {

                config_error(VAR_0, "invalid syntax for ethernet address\n");

                VAR_5 = -1;

                goto out;

            }

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "model", VAR_2)) {

            nd->model = qemu_strdup(VAR_3);

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "addr", VAR_2)) {

            nd->devaddr = qemu_strdup(VAR_3);

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "id", VAR_2)) {

            nd->id = qemu_strdup(VAR_3);

        }

        nd->nvectors = NIC_NVECTORS_UNSPECIFIED;

        if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_10", VAR_2)) {

            char *VAR_9;

            long VAR_10 = strtol(VAR_3, &VAR_9, 0);

            if (*VAR_9) {

                config_error(VAR_0, "invalid syntax for # of VAR_10\n");

                VAR_5 = -1;

                goto out;

            }

            if (VAR_10 < 0 || VAR_10 > 0x7ffffff) {

                config_error(VAR_0, "invalid # of VAR_10\n");

                VAR_5 = -1;

                goto out;

            }

            nd->nvectors = VAR_10;

        }

        nd->vlan = vlan;

        nd->VAR_6 = VAR_6;

        nd->used = 1;

        VAR_6 = NULL;

        nb_nics++;

        vlan->nb_guest_devs++;

        VAR_5 = VAR_8;

    } else

    if (!strcmp(VAR_1, "none")) {

        if (*VAR_2 != '\0') {

            config_error(VAR_0, "'none' takes no parameters\n");

            VAR_5 = -1;

            goto out;

        }

        



        VAR_5 = 0;

    } else

#ifdef CONFIG_SLIRP

    if (!strcmp(VAR_1, "user")) {

        static const char * const slirp_params[] = {

            "vlan", "VAR_6", "hostname", "restrict", "ip", "net", "host",

            "tftp", "bootfile", "dhcpstart", "dns", "smb", "smbserver",

            "hostfwd", "guestfwd", NULL

        };

        struct slirp_config_str *config;

        int restricted = 0;

        char *vnet = NULL;

        char *vhost = NULL;

        char *vhostname = NULL;

        char *tftp_export = NULL;

        char *bootfile = NULL;

        char *vdhcp_start = NULL;

        char *vnamesrv = NULL;

        char *smb_export = NULL;

        char *vsmbsrv = NULL;

        const char *q;



        if (check_params(VAR_3, sizeof(VAR_3), slirp_params, VAR_2) < 0) {

            config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_3, VAR_2);

            VAR_5 = -1;

            goto out;

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "ip", VAR_2)) {

            int vnet_buflen = strlen(VAR_3) + strlen("/24") + 1;

            

            vnet = qemu_malloc(vnet_buflen);

            pstrcpy(vnet, vnet_buflen, VAR_3);

            pstrcat(vnet, vnet_buflen, "/24");

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "net", VAR_2)) {

            vnet = qemu_strdup(VAR_3);

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "host", VAR_2)) {

            vhost = qemu_strdup(VAR_3);

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "hostname", VAR_2)) {

            vhostname = qemu_strdup(VAR_3);

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "restrict", VAR_2)) {

            restricted = (VAR_3[0] == 'y') ? 1 : 0;

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "dhcpstart", VAR_2)) {

            vdhcp_start = qemu_strdup(VAR_3);

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "dns", VAR_2)) {

            vnamesrv = qemu_strdup(VAR_3);

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "tftp", VAR_2)) {

            tftp_export = qemu_strdup(VAR_3);

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "bootfile", VAR_2)) {

            bootfile = qemu_strdup(VAR_3);

        }

        if (get_param_value(VAR_3, sizeof(VAR_3), "smb", VAR_2)) {

            smb_export = qemu_strdup(VAR_3);

            if (get_param_value(VAR_3, sizeof(VAR_3), "smbserver", VAR_2)) {

                vsmbsrv = qemu_strdup(VAR_3);

            }

        }

        q = VAR_2;

        while (1) {

            config = qemu_malloc(sizeof(*config));

            if (!get_next_param_value(config->str, sizeof(config->str),

                                      "hostfwd", &q)) {

                break;

            }

            config->flags = SLIRP_CFG_HOSTFWD;

            config->next = slirp_configs;

            slirp_configs = config;

            config = NULL;

        }

        q = VAR_2;

        while (1) {

            config = qemu_malloc(sizeof(*config));

            if (!get_next_param_value(config->str, sizeof(config->str),

                                      "guestfwd", &q)) {

                break;

            }

            config->flags = 0;

            config->next = slirp_configs;

            slirp_configs = config;

            config = NULL;

        }

        qemu_free(config);

        vlan->nb_host_devs++;

        VAR_5 = net_slirp_init(VAR_0, vlan, VAR_1, VAR_6, restricted, vnet, vhost,

                             vhostname, tftp_export, bootfile, vdhcp_start,

                             vnamesrv, smb_export, vsmbsrv);

        while (slirp_configs) {

            config = slirp_configs;

            slirp_configs = config->next;

            qemu_free(config);

        }

        qemu_free(vnet);

        qemu_free(vhost);

        qemu_free(vhostname);

        qemu_free(tftp_export);

        qemu_free(bootfile);

        qemu_free(vdhcp_start);

        qemu_free(vnamesrv);

        qemu_free(smb_export);

        qemu_free(vsmbsrv);

    } else if (!strcmp(VAR_1, "channel")) {

        if (QTAILQ_EMPTY(&slirp_stacks)) {

            struct slirp_config_str *config;



            config = qemu_malloc(sizeof(*config));

            pstrcpy(config->str, sizeof(config->str), VAR_2);

            config->flags = SLIRP_CFG_LEGACY;

            config->next = slirp_configs;

            slirp_configs = config;

        } else {

            slirp_guestfwd(QTAILQ_FIRST(&slirp_stacks), VAR_0, VAR_2, 1);

        }

        VAR_5 = 0;

    } else

#endif

#ifdef _WIN32

    if (!strcmp(VAR_1, "tap")) {

        static const char * const VAR_17[] = {

            "vlan", "VAR_6", "VAR_11", NULL

        };

        char VAR_11[64];



        if (check_params(VAR_3, sizeof(VAR_3), VAR_17, VAR_2) < 0) {

            config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_3, VAR_2);

            VAR_5 = -1;

            goto out;

        }

        if (get_param_value(VAR_11, sizeof(VAR_11), "VAR_11", VAR_2) <= 0) {

            config_error(VAR_0, "tap: no interface VAR_6\n");

            VAR_5 = -1;

            goto out;

        }

        vlan->nb_host_devs++;

        VAR_5 = tap_win32_init(vlan, VAR_1, VAR_6, VAR_11);

    } else

#elif defined (_AIX)

#else

    if (!strcmp(VAR_1, "tap")) {

        char VAR_11[64], VAR_19[64];

        char VAR_13[1024], VAR_14[1024];

        TAPState *s;

        int VAR_19;

        vlan->nb_host_devs++;

        if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_19", VAR_2) > 0) {

            static const char * const VAR_19[] = {

                "vlan", "VAR_6", "VAR_19", "sndbuf", NULL

            };

            VAR_5 = -1;

            if (check_params(VAR_19, sizeof(VAR_19), VAR_19, VAR_2) < 0) {

                config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2);

                goto out;

            }

            VAR_19 = net_handle_fd_param(VAR_0, VAR_3);

            if (VAR_19 == -1) {

                goto out;

            }

            fcntl(VAR_19, F_SETFL, O_NONBLOCK);

            s = net_tap_fd_init(vlan, VAR_1, VAR_6, VAR_19);

            if (!s) {

                close(VAR_19);

            }

        } else {

            static const char * const VAR_17[] = {

                "vlan", "VAR_6", "VAR_11", "script", "downscript", "sndbuf", NULL

            };

            if (check_params(VAR_19, sizeof(VAR_19), VAR_17, VAR_2) < 0) {

                config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2);

                VAR_5 = -1;

                goto out;

            }

            if (get_param_value(VAR_11, sizeof(VAR_11), "VAR_11", VAR_2) <= 0) {

                VAR_11[0] = '\0';

            }

            if (get_param_value(VAR_13, sizeof(VAR_13), "script", VAR_2) == 0) {

                pstrcpy(VAR_13, sizeof(VAR_13), DEFAULT_NETWORK_SCRIPT);

            }

            if (get_param_value(VAR_14, sizeof(VAR_14), "downscript", VAR_2) == 0) {

                pstrcpy(VAR_14, sizeof(VAR_14), DEFAULT_NETWORK_DOWN_SCRIPT);

            }

            s = net_tap_init(vlan, VAR_1, VAR_6, VAR_11, VAR_13, VAR_14);

        }

        if (s != NULL) {

            const char *VAR_18 = NULL;

            if (get_param_value(VAR_3, sizeof(VAR_3), "sndbuf", VAR_2)) {

                VAR_18 = VAR_3;

            }

            tap_set_sndbuf(s, VAR_18, VAR_0);

            VAR_5 = 0;

        } else {

            VAR_5 = -1;

        }

    } else

#endif

    if (!strcmp(VAR_1, "socket")) {

        char VAR_19[64];

        if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_19", VAR_2) > 0) {

            static const char * const VAR_19[] = {

                "vlan", "VAR_6", "VAR_19", NULL

            };

            int VAR_19;

            VAR_5 = -1;

            if (check_params(VAR_19, sizeof(VAR_19), VAR_19, VAR_2) < 0) {

                config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2);

                goto out;

            }

            VAR_19 = net_handle_fd_param(VAR_0, VAR_3);

            if (VAR_19 == -1) {

                goto out;

            }

            if (!net_socket_fd_init(vlan, VAR_1, VAR_6, VAR_19, 1)) {

                close(VAR_19);

                goto out;

            }

            VAR_5 = 0;

        } else if (get_param_value(VAR_3, sizeof(VAR_3), "listen", VAR_2) > 0) {

            static const char * const VAR_19[] = {

                "vlan", "VAR_6", "listen", NULL

            };

            if (check_params(VAR_19, sizeof(VAR_19), VAR_19, VAR_2) < 0) {

                config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2);

                VAR_5 = -1;

                goto out;

            }

            VAR_5 = net_socket_listen_init(vlan, VAR_1, VAR_6, VAR_3);

        } else if (get_param_value(VAR_3, sizeof(VAR_3), "connect", VAR_2) > 0) {

            static const char * const VAR_20[] = {

                "vlan", "VAR_6", "connect", NULL

            };

            if (check_params(VAR_19, sizeof(VAR_19), VAR_20, VAR_2) < 0) {

                config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2);

                VAR_5 = -1;

                goto out;

            }

            VAR_5 = net_socket_connect_init(vlan, VAR_1, VAR_6, VAR_3);

        } else if (get_param_value(VAR_3, sizeof(VAR_3), "mcast", VAR_2) > 0) {

            static const char * const VAR_21[] = {

                "vlan", "VAR_6", "mcast", NULL

            };

            if (check_params(VAR_19, sizeof(VAR_19), VAR_21, VAR_2) < 0) {

                config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2);

                VAR_5 = -1;

                goto out;

            }

            VAR_5 = net_socket_mcast_init(vlan, VAR_1, VAR_6, VAR_3);

        } else {

            config_error(VAR_0, "Unknown socket options: %s\n", VAR_2);

            VAR_5 = -1;

            goto out;

        }

        vlan->nb_host_devs++;

    } else

#ifdef CONFIG_VDE

    if (!strcmp(VAR_1, "vde")) {

        static const char * const vde_params[] = {

            "vlan", "VAR_6", "sock", "port", "group", "mode", NULL

        };

        char vde_sock[1024], vde_group[512];

	int vde_port, vde_mode;



        if (check_params(VAR_3, sizeof(VAR_3), vde_params, VAR_2) < 0) {

            config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_3, VAR_2);

            VAR_5 = -1;

            goto out;

        }

        vlan->nb_host_devs++;

        if (get_param_value(vde_sock, sizeof(vde_sock), "sock", VAR_2) <= 0) {

	    vde_sock[0] = '\0';

	}

	if (get_param_value(VAR_3, sizeof(VAR_3), "port", VAR_2) > 0) {

	    vde_port = strtol(VAR_3, NULL, 10);

	} else {

	    vde_port = 0;

	}

	if (get_param_value(vde_group, sizeof(vde_group), "group", VAR_2) <= 0) {

	    vde_group[0] = '\0';

	}

	if (get_param_value(VAR_3, sizeof(VAR_3), "mode", VAR_2) > 0) {

	    vde_mode = strtol(VAR_3, NULL, 8);

	} else {

	    vde_mode = 0700;

	}

	VAR_5 = net_vde_init(vlan, VAR_1, VAR_6, vde_sock, vde_port, vde_group, vde_mode);

    } else

#endif

    if (!strcmp(VAR_1, "dump")) {

        int VAR_22 = 65536;



        if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_22", VAR_2) > 0) {

            VAR_22 = strtol(VAR_3, NULL, 0);

        }

        if (!get_param_value(VAR_3, sizeof(VAR_3), "file", VAR_2)) {

            snprintf(VAR_3, sizeof(VAR_3), "qemu-vlan%d.pcap", VAR_4);

        }

        VAR_5 = net_dump_init(VAR_0, vlan, VAR_1, VAR_6, VAR_3, VAR_22);

    } else {

        config_error(VAR_0, "Unknown network VAR_1: %s\n", VAR_1);

        VAR_5 = -1;

        goto out;

    }

    if (VAR_5 < 0) {

        config_error(VAR_0, "Could not initialize VAR_1 '%s'\n", VAR_1);

    }

out:

    qemu_free(VAR_6);

    return VAR_5;

}

int FUNC_0(Monitor *VAR_0, const char *VAR_1, const char *VAR_2)
{ char VAR_3[1024]; int VAR_4, VAR_5; VLANState *vlan; char *VAR_6 = NULL; VAR_4 = 0; if (get_param_value(VAR_3, sizeof(VAR_3), "vlan", VAR_2)) { VAR_4 = strtol(VAR_3, NULL, 0); } vlan = qemu_find_vlan(VAR_4, 1); if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_6", VAR_2)) { VAR_6 = qemu_strdup(VAR_3); } if (!strcmp(VAR_1, "nic")) { static const char * const VAR_7[] = { "vlan", "VAR_6", "macaddr", "model", "addr", "id", "VAR_10", NULL
}; NICInfo *nd; uint8_t *macaddr; int VAR_8 = nic_get_free_idx(); if (check_params(VAR_3, sizeof(VAR_3), VAR_7, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_3, VAR_2); VAR_5 = -1; goto out; } if (VAR_8 == -1 || nb_nics >= MAX_NICS) { config_error(VAR_0, "Too Many NICs\n"); VAR_5 = -1; goto out; } nd = &nd_table[VAR_8]; memset(nd, 0, sizeof(*nd)); macaddr = nd->macaddr; macaddr[0] = 0x52; macaddr[1] = 0x54; macaddr[2] = 0x00; macaddr[3] = 0x12; macaddr[4] = 0x34; macaddr[5] = 0x56 + VAR_8; if (get_param_value(VAR_3, sizeof(VAR_3), "macaddr", VAR_2)) { if (parse_macaddr(macaddr, VAR_3) < 0) { config_error(VAR_0, "invalid syntax for ethernet address\n"); VAR_5 = -1; goto out; } } if (get_param_value(VAR_3, sizeof(VAR_3), "model", VAR_2)) { nd->model = qemu_strdup(VAR_3); } if (get_param_value(VAR_3, sizeof(VAR_3), "addr", VAR_2)) { nd->devaddr = qemu_strdup(VAR_3); } if (get_param_value(VAR_3, sizeof(VAR_3), "id", VAR_2)) { nd->id = qemu_strdup(VAR_3); } nd->nvectors = NIC_NVECTORS_UNSPECIFIED; if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_10", VAR_2)) { char *VAR_9; long VAR_10 = strtol(VAR_3, &VAR_9, 0); if (*VAR_9) { config_error(VAR_0, "invalid syntax for # of VAR_10\n"); VAR_5 = -1; goto out; } if (VAR_10 < 0 || VAR_10 > 0x7ffffff) { config_error(VAR_0, "invalid # of VAR_10\n"); VAR_5 = -1; goto out; } nd->nvectors = VAR_10; } nd->vlan = vlan; nd->VAR_6 = VAR_6; nd->used = 1; VAR_6 = NULL; nb_nics++; vlan->nb_guest_devs++; VAR_5 = VAR_8; } else if (!strcmp(VAR_1, "none")) { if (*VAR_2 != '\0') { config_error(VAR_0, "'none' takes no parameters\n"); VAR_5 = -1; goto out; } VAR_5 = 0; } else #ifdef CONFIG_SLIRP
if (!strcmp(VAR_1, "user")) { static const char * const slirp_params[] = { "vlan", "VAR_6", "hostname", "restrict", "ip", "net", "host",
"tftp", "bootfile", "dhcpstart", "dns", "smb", "smbserver",
"hostfwd", "guestfwd", NULL
}; struct slirp_config_str *config; int restricted = 0; char *vnet = NULL; char *vhost = NULL; char *vhostname = NULL; char *tftp_export = NULL; char *bootfile = NULL; char *vdhcp_start = NULL; char *vnamesrv = NULL; char *smb_export = NULL; char *vsmbsrv = NULL; const char *q; if (check_params(VAR_3, sizeof(VAR_3), slirp_params, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_3, VAR_2); VAR_5 = -1; goto out; } if (get_param_value(VAR_3, sizeof(VAR_3), "ip", VAR_2)) { int vnet_buflen = strlen(VAR_3) + strlen("/24") + 1; vnet = qemu_malloc(vnet_buflen); pstrcpy(vnet, vnet_buflen, VAR_3); pstrcat(vnet, vnet_buflen, "/24"); } if (get_param_value(VAR_3, sizeof(VAR_3), "net", VAR_2)) { vnet = qemu_strdup(VAR_3); } if (get_param_value(VAR_3, sizeof(VAR_3), "host", VAR_2)) { vhost = qemu_strdup(VAR_3); } if (get_param_value(VAR_3, sizeof(VAR_3), "hostname", VAR_2)) { vhostname = qemu_strdup(VAR_3); } if (get_param_value(VAR_3, sizeof(VAR_3), "restrict", VAR_2)) { restricted = (VAR_3[0] == 'y') ? 1 : 0; } if (get_param_value(VAR_3, sizeof(VAR_3), "dhcpstart", VAR_2)) { vdhcp_start = qemu_strdup(VAR_3); } if (get_param_value(VAR_3, sizeof(VAR_3), "dns", VAR_2)) { vnamesrv = qemu_strdup(VAR_3); } if (get_param_value(VAR_3, sizeof(VAR_3), "tftp", VAR_2)) { tftp_export = qemu_strdup(VAR_3); } if (get_param_value(VAR_3, sizeof(VAR_3), "bootfile", VAR_2)) { bootfile = qemu_strdup(VAR_3); } if (get_param_value(VAR_3, sizeof(VAR_3), "smb", VAR_2)) { smb_export = qemu_strdup(VAR_3); if (get_param_value(VAR_3, sizeof(VAR_3), "smbserver", VAR_2)) { vsmbsrv = qemu_strdup(VAR_3); } } q = VAR_2; while (1) { config = qemu_malloc(sizeof(*config)); if (!get_next_param_value(config->str, sizeof(config->str),
"hostfwd", &q)) { break; } config->flags = SLIRP_CFG_HOSTFWD; config->next = slirp_configs; slirp_configs = config; config = NULL; } q = VAR_2; while (1) { config = qemu_malloc(sizeof(*config)); if (!get_next_param_value(config->str, sizeof(config->str),
"guestfwd", &q)) { break; } config->flags = 0; config->next = slirp_configs; slirp_configs = config; config = NULL; } qemu_free(config); vlan->nb_host_devs++; VAR_5 = net_slirp_init(VAR_0, vlan, VAR_1, VAR_6, restricted, vnet, vhost,
vhostname, tftp_export, bootfile, vdhcp_start,
vnamesrv, smb_export, vsmbsrv); while (slirp_configs) { config = slirp_configs; slirp_configs = config->next; qemu_free(config); } qemu_free(vnet); qemu_free(vhost); qemu_free(vhostname); qemu_free(tftp_export); qemu_free(bootfile); qemu_free(vdhcp_start); qemu_free(vnamesrv); qemu_free(smb_export); qemu_free(vsmbsrv); } else if (!strcmp(VAR_1, "channel")) { if (QTAILQ_EMPTY(&slirp_stacks)) { struct slirp_config_str *config; config = qemu_malloc(sizeof(*config)); pstrcpy(config->str, sizeof(config->str), VAR_2); config->flags = SLIRP_CFG_LEGACY; config->next = slirp_configs; slirp_configs = config; } else { slirp_guestfwd(QTAILQ_FIRST(&slirp_stacks), VAR_0, VAR_2, 1); } VAR_5 = 0; } else #endif
#ifdef _WIN32
if (!strcmp(VAR_1, "tap")) { static const char * const VAR_17[] = { "vlan", "VAR_6", "VAR_11", NULL
}; char VAR_11[64]; if (check_params(VAR_3, sizeof(VAR_3), VAR_17, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_3, VAR_2); VAR_5 = -1; goto out; } if (get_param_value(VAR_11, sizeof(VAR_11), "VAR_11", VAR_2) <= 0) { config_error(VAR_0, "tap: no interface VAR_6\n"); VAR_5 = -1; goto out; } vlan->nb_host_devs++; VAR_5 = tap_win32_init(vlan, VAR_1, VAR_6, VAR_11); } else #elif defined (_AIX)
#else
if (!strcmp(VAR_1, "tap")) { char VAR_11[64], VAR_19[64]; char VAR_13[1024], VAR_14[1024]; TAPState *s; int VAR_19; vlan->nb_host_devs++; if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_19", VAR_2) > 0) { static const char * const VAR_19[] = { "vlan", "VAR_6", "VAR_19", "sndbuf", NULL
}; VAR_5 = -1; if (check_params(VAR_19, sizeof(VAR_19), VAR_19, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2); goto out; } VAR_19 = net_handle_fd_param(VAR_0, VAR_3); if (VAR_19 == -1) { goto out; } fcntl(VAR_19, F_SETFL, O_NONBLOCK); s = net_tap_fd_init(vlan, VAR_1, VAR_6, VAR_19); if (!s) { close(VAR_19); } } else { static const char * const VAR_17[] = { "vlan", "VAR_6", "VAR_11", "script", "downscript", "sndbuf", NULL
}; if (check_params(VAR_19, sizeof(VAR_19), VAR_17, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2); VAR_5 = -1; goto out; } if (get_param_value(VAR_11, sizeof(VAR_11), "VAR_11", VAR_2) <= 0) { VAR_11[0] = '\0'; } if (get_param_value(VAR_13, sizeof(VAR_13), "script", VAR_2) == 0) { pstrcpy(VAR_13, sizeof(VAR_13), DEFAULT_NETWORK_SCRIPT); } if (get_param_value(VAR_14, sizeof(VAR_14), "downscript", VAR_2) == 0) { pstrcpy(VAR_14, sizeof(VAR_14), DEFAULT_NETWORK_DOWN_SCRIPT); } s = net_tap_init(vlan, VAR_1, VAR_6, VAR_11, VAR_13, VAR_14); } if (s != NULL) { const char *VAR_18 = NULL; if (get_param_value(VAR_3, sizeof(VAR_3), "sndbuf", VAR_2)) { VAR_18 = VAR_3; } tap_set_sndbuf(s, VAR_18, VAR_0); VAR_5 = 0; } else { VAR_5 = -1; } } else #endif
if (!strcmp(VAR_1, "socket")) { char VAR_19[64]; if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_19", VAR_2) > 0) { static const char * const VAR_19[] = { "vlan", "VAR_6", "VAR_19", NULL
}; int VAR_19; VAR_5 = -1; if (check_params(VAR_19, sizeof(VAR_19), VAR_19, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2); goto out; } VAR_19 = net_handle_fd_param(VAR_0, VAR_3); if (VAR_19 == -1) { goto out; } if (!net_socket_fd_init(vlan, VAR_1, VAR_6, VAR_19, 1)) { close(VAR_19); goto out; } VAR_5 = 0; } else if (get_param_value(VAR_3, sizeof(VAR_3), "listen", VAR_2) > 0) { static const char * const VAR_19[] = { "vlan", "VAR_6", "listen", NULL
}; if (check_params(VAR_19, sizeof(VAR_19), VAR_19, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2); VAR_5 = -1; goto out; } VAR_5 = net_socket_listen_init(vlan, VAR_1, VAR_6, VAR_3); } else if (get_param_value(VAR_3, sizeof(VAR_3), "connect", VAR_2) > 0) { static const char * const VAR_20[] = { "vlan", "VAR_6", "connect", NULL
}; if (check_params(VAR_19, sizeof(VAR_19), VAR_20, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2); VAR_5 = -1; goto out; } VAR_5 = net_socket_connect_init(vlan, VAR_1, VAR_6, VAR_3); } else if (get_param_value(VAR_3, sizeof(VAR_3), "mcast", VAR_2) > 0) { static const char * const VAR_21[] = { "vlan", "VAR_6", "mcast", NULL
}; if (check_params(VAR_19, sizeof(VAR_19), VAR_21, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_19, VAR_2); VAR_5 = -1; goto out; } VAR_5 = net_socket_mcast_init(vlan, VAR_1, VAR_6, VAR_3); } else { config_error(VAR_0, "Unknown socket options: %s\n", VAR_2); VAR_5 = -1; goto out; } vlan->nb_host_devs++; } else #ifdef CONFIG_VDE
if (!strcmp(VAR_1, "vde")) { static const char * const vde_params[] = { "vlan", "VAR_6", "sock", "port", "group", "mode", NULL
}; char vde_sock[1024], vde_group[512]; int vde_port, vde_mode; if (check_params(VAR_3, sizeof(VAR_3), vde_params, VAR_2) < 0) { config_error(VAR_0, "invalid parameter '%s' in '%s'\n", VAR_3, VAR_2); VAR_5 = -1; goto out; } vlan->nb_host_devs++; if (get_param_value(vde_sock, sizeof(vde_sock), "sock", VAR_2) <= 0) { vde_sock[0] = '\0'; } if (get_param_value(VAR_3, sizeof(VAR_3), "port", VAR_2) > 0) { vde_port = strtol(VAR_3, NULL, 10); } else { vde_port = 0; } if (get_param_value(vde_group, sizeof(vde_group), "group", VAR_2) <= 0) { vde_group[0] = '\0'; } if (get_param_value(VAR_3, sizeof(VAR_3), "mode", VAR_2) > 0) { vde_mode = strtol(VAR_3, NULL, 8); } else { vde_mode = 0700; } VAR_5 = net_vde_init(vlan, VAR_1, VAR_6, vde_sock, vde_port, vde_group, vde_mode); } else #endif
if (!strcmp(VAR_1, "dump")) { int VAR_22 = 65536; if (get_param_value(VAR_3, sizeof(VAR_3), "VAR_22", VAR_2) > 0) { VAR_22 = strtol(VAR_3, NULL, 0); } if (!get_param_value(VAR_3, sizeof(VAR_3), "file", VAR_2)) { snprintf(VAR_3, sizeof(VAR_3), "qemu-vlan%d.pcap", VAR_4); } VAR_5 = net_dump_init(VAR_0, vlan, VAR_1, VAR_6, VAR_3, VAR_22); } else { config_error(VAR_0, "Unknown network VAR_1: %s\n", VAR_1); VAR_5 = -1; goto out; } if (VAR_5 < 0) { config_error(VAR_0, "Could not initialize VAR_1 '%s'\n", VAR_1); } out:
qemu_free(VAR_6); return VAR_5; }