int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)

{

    TAPState *s;

    int fd, vnet_hdr = 0;



    if (qemu_opt_get(opts, "fd")) {

        if (qemu_opt_get(opts, "ifname") ||

            qemu_opt_get(opts, "script") ||

            qemu_opt_get(opts, "downscript") ||

            qemu_opt_get(opts, "vnet_hdr")) {

            error_report("ifname=, script=, downscript= and vnet_hdr= is invalid with fd=");

            return -1;

        }



        fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd"));

        if (fd == -1) {

            return -1;

        }



        fcntl(fd, F_SETFL, O_NONBLOCK);



        vnet_hdr = tap_probe_vnet_hdr(fd);

    } else {

        if (!qemu_opt_get(opts, "script")) {

            qemu_opt_set(opts, "script", DEFAULT_NETWORK_SCRIPT);

        }



        if (!qemu_opt_get(opts, "downscript")) {

            qemu_opt_set(opts, "downscript", DEFAULT_NETWORK_DOWN_SCRIPT);

        }



        fd = net_tap_init(opts, &vnet_hdr);

        if (fd == -1) {

            return -1;

        }

    }



    s = net_tap_fd_init(vlan, "tap", name, fd, vnet_hdr);

    if (!s) {

        close(fd);

        return -1;

    }



    if (tap_set_sndbuf(s->fd, opts) < 0) {

        return -1;

    }



    if (qemu_opt_get(opts, "fd")) {

        snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);

    } else {

        const char *ifname, *script, *downscript;



        ifname     = qemu_opt_get(opts, "ifname");

        script     = qemu_opt_get(opts, "script");

        downscript = qemu_opt_get(opts, "downscript");



        snprintf(s->nc.info_str, sizeof(s->nc.info_str),

                 "ifname=%s,script=%s,downscript=%s",

                 ifname, script, downscript);



        if (strcmp(downscript, "no") != 0) {

            snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);

            snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);

        }

    }



    if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd") ||

                          qemu_opt_get_bool(opts, "vhostforce", false))) {

        int vhostfd, r;

        bool force = qemu_opt_get_bool(opts, "vhostforce", false);

        if (qemu_opt_get(opts, "vhostfd")) {

            r = net_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd"));

            if (r == -1) {

                return -1;

            }

            vhostfd = r;

        } else {

            vhostfd = -1;

        }

        s->vhost_net = vhost_net_init(&s->nc, vhostfd, force);

        if (!s->vhost_net) {

            error_report("vhost-net requested but could not be initialized");

            return -1;

        }

    } else if (qemu_opt_get(opts, "vhostfd")) {

        error_report("vhostfd= is not valid without vhost");

        return -1;

    }



    return 0;

}

int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)

{

    TAPState *s;

    int fd, vnet_hdr = 0;



    if (qemu_opt_get(opts, "fd")) {

        if (qemu_opt_get(opts, "ifname") ||

            qemu_opt_get(opts, "script") ||

            qemu_opt_get(opts, "downscript") ||

            qemu_opt_get(opts, "vnet_hdr")) {

            error_report("ifname=, script=, downscript= and vnet_hdr= is invalid with fd=");

            return -1;

        }



        fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd"));

        if (fd == -1) {

            return -1;

        }



        fcntl(fd, F_SETFL, O_NONBLOCK);



        vnet_hdr = tap_probe_vnet_hdr(fd);

    } else {

        if (!qemu_opt_get(opts, "script")) {

            qemu_opt_set(opts, "script", DEFAULT_NETWORK_SCRIPT);

        }



        if (!qemu_opt_get(opts, "downscript")) {

            qemu_opt_set(opts, "downscript", DEFAULT_NETWORK_DOWN_SCRIPT);

        }



        fd = net_tap_init(opts, &vnet_hdr);

        if (fd == -1) {

            return -1;

        }

    }



    s = net_tap_fd_init(vlan, "tap", name, fd, vnet_hdr);

    if (!s) {

        close(fd);

        return -1;

    }



    if (tap_set_sndbuf(s->fd, opts) < 0) {

        return -1;

    }



    if (qemu_opt_get(opts, "fd")) {

        snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);

    } else {

        const char *ifname, *script, *downscript;



        ifname     = qemu_opt_get(opts, "ifname");

        script     = qemu_opt_get(opts, "script");

        downscript = qemu_opt_get(opts, "downscript");



        snprintf(s->nc.info_str, sizeof(s->nc.info_str),

                 "ifname=%s,script=%s,downscript=%s",

                 ifname, script, downscript);



        if (strcmp(downscript, "no") != 0) {

            snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);

            snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);

        }

    }



    if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd") ||

                          qemu_opt_get_bool(opts, "vhostforce", false))) {

        int vhostfd, r;

        bool force = qemu_opt_get_bool(opts, "vhostforce", false);

        if (qemu_opt_get(opts, "vhostfd")) {

            r = net_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd"));

            if (r == -1) {

                return -1;

            }

            vhostfd = r;

        } else {

            vhostfd = -1;

        }

        s->vhost_net = vhost_net_init(&s->nc, vhostfd, force);

        if (!s->vhost_net) {

            error_report("vhost-net requested but could not be initialized");

            return -1;

        }

    } else if (qemu_opt_get(opts, "vhostfd")) {

        error_report("vhostfd= is not valid without vhost");

        return -1;

    }



    return 0;

}

            qemu_opt_get(opts, "vnet_hdr")) {             error_report("ifname=, script=, downscript= and vnet_hdr= is invalid with fd=");     s = net_tap_fd_init(vlan, "tap", name, fd, vnet_hdr);
int FUNC_0(QemuOpts *VAR_0, Monitor *VAR_1, const char *VAR_2, VLANState *VAR_3)

{

    TAPState *s;

    int VAR_4, VAR_5 = 0;



    if (qemu_opt_get(VAR_0, "VAR_4")) {

        if (qemu_opt_get(VAR_0, "VAR_6") ||

            qemu_opt_get(VAR_0, "VAR_7") ||

            qemu_opt_get(VAR_0, "VAR_8") ||

            qemu_opt_get(VAR_0, "VAR_5")) {

            error_report("VAR_6=, VAR_7=, VAR_8= and VAR_5= is invalid with VAR_4=");

            return -1;

        }



        VAR_4 = net_handle_fd_param(VAR_1, qemu_opt_get(VAR_0, "VAR_4"));

        if (VAR_4 == -1) {

            return -1;

        }



        fcntl(VAR_4, F_SETFL, O_NONBLOCK);



        VAR_5 = tap_probe_vnet_hdr(VAR_4);

    } else {

        if (!qemu_opt_get(VAR_0, "VAR_7")) {

            qemu_opt_set(VAR_0, "VAR_7", DEFAULT_NETWORK_SCRIPT);

        }



        if (!qemu_opt_get(VAR_0, "VAR_8")) {

            qemu_opt_set(VAR_0, "VAR_8", DEFAULT_NETWORK_DOWN_SCRIPT);

        }



        VAR_4 = net_tap_init(VAR_0, &VAR_5);

        if (VAR_4 == -1) {

            return -1;

        }

    }



    s = net_tap_fd_init(VAR_3, "tap", VAR_2, VAR_4, VAR_5);

    if (!s) {

        close(VAR_4);

        return -1;

    }



    if (tap_set_sndbuf(s->VAR_4, VAR_0) < 0) {

        return -1;

    }



    if (qemu_opt_get(VAR_0, "VAR_4")) {

        snprintf(s->nc.info_str, sizeof(s->nc.info_str), "VAR_4=%d", VAR_4);

    } else {

        const char *VAR_6, *VAR_7, *VAR_8;



        VAR_6     = qemu_opt_get(VAR_0, "VAR_6");

        VAR_7     = qemu_opt_get(VAR_0, "VAR_7");

        VAR_8 = qemu_opt_get(VAR_0, "VAR_8");



        snprintf(s->nc.info_str, sizeof(s->nc.info_str),

                 "VAR_6=%s,VAR_7=%s,VAR_8=%s",

                 VAR_6, VAR_7, VAR_8);



        if (strcmp(VAR_8, "no") != 0) {

            snprintf(s->down_script, sizeof(s->down_script), "%s", VAR_8);

            snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", VAR_6);

        }

    }



    if (qemu_opt_get_bool(VAR_0, "vhost", !!qemu_opt_get(VAR_0, "VAR_9") ||

                          qemu_opt_get_bool(VAR_0, "vhostforce", false))) {

        int VAR_9, VAR_10;

        bool force = qemu_opt_get_bool(VAR_0, "vhostforce", false);

        if (qemu_opt_get(VAR_0, "VAR_9")) {

            VAR_10 = net_handle_fd_param(VAR_1, qemu_opt_get(VAR_0, "VAR_9"));

            if (VAR_10 == -1) {

                return -1;

            }

            VAR_9 = VAR_10;

        } else {

            VAR_9 = -1;

        }

        s->vhost_net = vhost_net_init(&s->nc, VAR_9, force);

        if (!s->vhost_net) {

            error_report("vhost-net requested but could not be initialized");

            return -1;

        }

    } else if (qemu_opt_get(VAR_0, "VAR_9")) {

        error_report("VAR_9= is not valid without vhost");

        return -1;

    }



    return 0;

}

int FUNC_0(QemuOpts *VAR_0, Monitor *VAR_1, const char *VAR_2, VLANState *VAR_3)
{ TAPState *s; int VAR_4, VAR_5 = 0; if (qemu_opt_get(VAR_0, "VAR_4")) { if (qemu_opt_get(VAR_0, "VAR_6") ||
qemu_opt_get(VAR_0, "VAR_7") ||
qemu_opt_get(VAR_0, "VAR_8") ||
qemu_opt_get(VAR_0, "VAR_5")) { error_report("VAR_6=, VAR_7=, VAR_8= and VAR_5= is invalid with VAR_4="); return -1; } VAR_4 = net_handle_fd_param(VAR_1, qemu_opt_get(VAR_0, "VAR_4")); if (VAR_4 == -1) { return -1; } fcntl(VAR_4, F_SETFL, O_NONBLOCK); VAR_5 = tap_probe_vnet_hdr(VAR_4); } else { if (!qemu_opt_get(VAR_0, "VAR_7")) { qemu_opt_set(VAR_0, "VAR_7", DEFAULT_NETWORK_SCRIPT); } if (!qemu_opt_get(VAR_0, "VAR_8")) { qemu_opt_set(VAR_0, "VAR_8", DEFAULT_NETWORK_DOWN_SCRIPT); } VAR_4 = net_tap_init(VAR_0, &VAR_5); if (VAR_4 == -1) { return -1; } } s = net_tap_fd_init(VAR_3, "tap", VAR_2, VAR_4, VAR_5); if (!s) { close(VAR_4); return -1; } if (tap_set_sndbuf(s->VAR_4, VAR_0) < 0) { return -1; } if (qemu_opt_get(VAR_0, "VAR_4")) { snprintf(s->nc.info_str, sizeof(s->nc.info_str), "VAR_4=%d", VAR_4); } else { const char *VAR_6, *VAR_7, *VAR_8; VAR_6     = qemu_opt_get(VAR_0, "VAR_6"); VAR_7     = qemu_opt_get(VAR_0, "VAR_7"); VAR_8 = qemu_opt_get(VAR_0, "VAR_8"); snprintf(s->nc.info_str, sizeof(s->nc.info_str),
"VAR_6=%s,VAR_7=%s,VAR_8=%s",
VAR_6, VAR_7, VAR_8); if (strcmp(VAR_8, "no") != 0) { snprintf(s->down_script, sizeof(s->down_script), "%s", VAR_8); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", VAR_6); } } if (qemu_opt_get_bool(VAR_0, "vhost", !!qemu_opt_get(VAR_0, "VAR_9") ||
qemu_opt_get_bool(VAR_0, "vhostforce", false))) { int VAR_9, VAR_10; bool force = qemu_opt_get_bool(VAR_0, "vhostforce", false); if (qemu_opt_get(VAR_0, "VAR_9")) { VAR_10 = net_handle_fd_param(VAR_1, qemu_opt_get(VAR_0, "VAR_9")); if (VAR_10 == -1) { return -1; } VAR_9 = VAR_10; } else { VAR_9 = -1; } s->vhost_net = vhost_net_init(&s->nc, VAR_9, force); if (!s->vhost_net) { error_report("vhost-net requested but could not be initialized"); return -1; } } else if (qemu_opt_get(VAR_0, "VAR_9")) { error_report("VAR_9= is not valid without vhost"); return -1; } return 0; }