int net_init_tap(const NetClientOptions *opts, const char *name,
                 NetClientState *peer)
{
    const NetdevTapOptions *tap;
    int fd, vnet_hdr = 0, i = 0, queues;
    /* for the no-fd, no-helper case */
    const char *script = NULL; /* suppress wrong "uninit'd use" gcc warning */
    const char *downscript = NULL;
    const char *vhostfdname;
    char ifname[128];
    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
    tap = opts->tap;
    queues = tap->has_queues ? tap->queues : 1;
    vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
    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) {
            error_report("ifname=, script=, downscript=, vnet_hdr=, "
                         "helper=, queues=, and fds= are invalid with fd=");
        fd = monitor_handle_fd_param(cur_mon, tap->fd);
        if (fd == -1) {
        fcntl(fd, F_SETFL, O_NONBLOCK);
        vnet_hdr = tap_probe_vnet_hdr(fd);
        if (net_init_tap_one(tap, peer, "tap", name, NULL,
                             script, downscript,
                             vhostfdname, vnet_hdr, fd)) {
    } else if (tap->has_fds) {
        char *fds[MAX_TAP_QUEUES];
        char *vhost_fds[MAX_TAP_QUEUES];
        int nfds, nvhosts;
        if (tap->has_ifname || tap->has_script || tap->has_downscript ||
            tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
            tap->has_fd) {
            error_report("ifname=, script=, downscript=, vnet_hdr=, "
                         "helper=, queues=, and fd= are invalid with fds=");
        nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
        if (tap->has_vhostfds) {
            nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
            if (nfds != nvhosts) {
                error_report("The number of fds passed does not match the "
                             "number of vhostfds passed");
        for (i = 0; i < nfds; i++) {
            fd = monitor_handle_fd_param(cur_mon, fds[i]);
            if (fd == -1) {
            fcntl(fd, F_SETFL, O_NONBLOCK);
            if (i == 0) {
                vnet_hdr = tap_probe_vnet_hdr(fd);
            } else if (vnet_hdr != tap_probe_vnet_hdr(fd)) {
                error_report("vnet_hdr not consistent across given tap fds");
            if (net_init_tap_one(tap, peer, "tap", name, ifname,
                                 script, downscript,
                                 tap->has_vhostfds ? vhost_fds[i] : NULL,
                                 vnet_hdr, fd)) {
    } else if (tap->has_helper) {
        if (tap->has_ifname || tap->has_script || tap->has_downscript ||
            tap->has_vnet_hdr || tap->has_queues || tap->has_fds) {
            error_report("ifname=, script=, downscript=, and vnet_hdr= "
                         "queues=, and fds= are invalid with helper=");
        fd = net_bridge_run_helper(tap->helper, DEFAULT_BRIDGE_INTERFACE);
        if (fd == -1) {
        fcntl(fd, F_SETFL, O_NONBLOCK);
        vnet_hdr = tap_probe_vnet_hdr(fd);
        if (net_init_tap_one(tap, peer, "bridge", name, ifname,
                             script, downscript, vhostfdname,
                             vnet_hdr, fd)) {
    } else {
        script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT;
        downscript = tap->has_downscript ? tap->downscript :
            DEFAULT_NETWORK_DOWN_SCRIPT;
        if (tap->has_ifname) {
            pstrcpy(ifname, sizeof ifname, tap->ifname);
        } else {
            ifname[0] = '\0';
        for (i = 0; i < queues; i++) {
            fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? "no" : script,
                              ifname, sizeof ifname, queues > 1);
            if (fd == -1) {
            if (queues > 1 && i == 0 && !tap->has_ifname) {
                if (tap_fd_get_ifname(fd, ifname)) {
                    error_report("Fail to get ifname");
            if (net_init_tap_one(tap, peer, "tap", name, ifname,
                                 i >= 1 ? "no" : script,
                                 i >= 1 ? "no" : downscript,
                                 vhostfdname, vnet_hdr, fd)) {
    return 0;
int net_init_tap(const NetClientOptions *opts, const char *name,
                 NetClientState *peer)
{
    const NetdevTapOptions *tap;
    int fd, vnet_hdr = 0, i = 0, queues;
    
    const char *script = NULL; 
    const char *downscript = NULL;
    const char *vhostfdname;
    char ifname[128];
    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
    tap = opts->tap;
    queues = tap->has_queues ? tap->queues : 1;
    vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
    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) {
            error_report("ifname=, script=, downscript=, vnet_hdr=, "
                         "helper=, queues=, and fds= are invalid with fd=");
        fd = monitor_handle_fd_param(cur_mon, tap->fd);
        if (fd == -1) {
        fcntl(fd, F_SETFL, O_NONBLOCK);
        vnet_hdr = tap_probe_vnet_hdr(fd);
        if (net_init_tap_one(tap, peer, "tap", name, NULL,
                             script, downscript,
                             vhostfdname, vnet_hdr, fd)) {
    } else if (tap->has_fds) {
        char *fds[MAX_TAP_QUEUES];
        char *vhost_fds[MAX_TAP_QUEUES];
        int nfds, nvhosts;
        if (tap->has_ifname || tap->has_script || tap->has_downscript ||
            tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
            tap->has_fd) {
            error_report("ifname=, script=, downscript=, vnet_hdr=, "
                         "helper=, queues=, and fd= are invalid with fds=");
        nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
        if (tap->has_vhostfds) {
            nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
            if (nfds != nvhosts) {
                error_report("The number of fds passed does not match the "
                             "number of vhostfds passed");
        for (i = 0; i < nfds; i++) {
            fd = monitor_handle_fd_param(cur_mon, fds[i]);
            if (fd == -1) {
            fcntl(fd, F_SETFL, O_NONBLOCK);
            if (i == 0) {
                vnet_hdr = tap_probe_vnet_hdr(fd);
            } else if (vnet_hdr != tap_probe_vnet_hdr(fd)) {
                error_report("vnet_hdr not consistent across given tap fds");
            if (net_init_tap_one(tap, peer, "tap", name, ifname,
                                 script, downscript,
                                 tap->has_vhostfds ? vhost_fds[i] : NULL,
                                 vnet_hdr, fd)) {
    } else if (tap->has_helper) {
        if (tap->has_ifname || tap->has_script || tap->has_downscript ||
            tap->has_vnet_hdr || tap->has_queues || tap->has_fds) {
            error_report("ifname=, script=, downscript=, and vnet_hdr= "
                         "queues=, and fds= are invalid with helper=");
        fd = net_bridge_run_helper(tap->helper, DEFAULT_BRIDGE_INTERFACE);
        if (fd == -1) {
        fcntl(fd, F_SETFL, O_NONBLOCK);
        vnet_hdr = tap_probe_vnet_hdr(fd);
        if (net_init_tap_one(tap, peer, "bridge", name, ifname,
                             script, downscript, vhostfdname,
                             vnet_hdr, fd)) {
    } else {
        script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT;
        downscript = tap->has_downscript ? tap->downscript :
            DEFAULT_NETWORK_DOWN_SCRIPT;
        if (tap->has_ifname) {
            pstrcpy(ifname, sizeof ifname, tap->ifname);
        } else {
            ifname[0] = '\0';
        for (i = 0; i < queues; i++) {
            fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? "no" : script,
                              ifname, sizeof ifname, queues > 1);
            if (fd == -1) {
            if (queues > 1 && i == 0 && !tap->has_ifname) {
                if (tap_fd_get_ifname(fd, ifname)) {
                    error_report("Fail to get ifname");
            if (net_init_tap_one(tap, peer, "tap", name, ifname,
                                 i >= 1 ? "no" : script,
                                 i >= 1 ? "no" : downscript,
                                 vhostfdname, vnet_hdr, fd)) {
    return 0;
int FUNC_0(const NetClientOptions *VAR_0, const char *VAR_1,
                 NetClientState *VAR_2)
{
    const NetdevTapOptions *VAR_3;
    int VAR_4, VAR_5 = 0, VAR_6 = 0, VAR_7;
    
    const char *VAR_8 = NULL; 
    const char *VAR_9 = NULL;
    const char *VAR_10;
    char VAR_11[128];
    assert(VAR_0->kind == NET_CLIENT_OPTIONS_KIND_TAP);
    VAR_3 = VAR_0->VAR_3;
    VAR_7 = VAR_3->has_queues ? VAR_3->VAR_7 : 1;
    VAR_10 = VAR_3->has_vhostfd ? VAR_3->vhostfd : NULL;
    if (VAR_3->has_fd) {
        if (VAR_3->has_ifname || VAR_3->has_script || VAR_3->has_downscript ||
            VAR_3->has_vnet_hdr || VAR_3->has_helper || VAR_3->has_queues ||
            VAR_3->has_fds) {
            error_report("VAR_11=, VAR_8=, VAR_9=, VAR_5=, "
                         "helper=, VAR_7=, and VAR_12= are invalid with VAR_4=");
        VAR_4 = monitor_handle_fd_param(cur_mon, VAR_3->VAR_4);
        if (VAR_4 == -1) {
        fcntl(VAR_4, F_SETFL, O_NONBLOCK);
        VAR_5 = tap_probe_vnet_hdr(VAR_4);
        if (net_init_tap_one(VAR_3, VAR_2, "VAR_3", VAR_1, NULL,
                             VAR_8, VAR_9,
                             VAR_10, VAR_5, VAR_4)) {
    } else if (VAR_3->has_fds) {
        char *VAR_12[MAX_TAP_QUEUES];
        char *VAR_13[MAX_TAP_QUEUES];
        int VAR_14, VAR_15;
        if (VAR_3->has_ifname || VAR_3->has_script || VAR_3->has_downscript ||
            VAR_3->has_vnet_hdr || VAR_3->has_helper || VAR_3->has_queues ||
            VAR_3->has_fd) {
            error_report("VAR_11=, VAR_8=, VAR_9=, VAR_5=, "
                         "helper=, VAR_7=, and VAR_4= are invalid with VAR_12=");
        VAR_14 = get_fds(VAR_3->VAR_12, VAR_12, MAX_TAP_QUEUES);
        if (VAR_3->has_vhostfds) {
            VAR_15 = get_fds(VAR_3->vhostfds, VAR_13, MAX_TAP_QUEUES);
            if (VAR_14 != VAR_15) {
                error_report("The number of VAR_12 passed does not match the "
                             "number of vhostfds passed");
        for (VAR_6 = 0; VAR_6 < VAR_14; VAR_6++) {
            VAR_4 = monitor_handle_fd_param(cur_mon, VAR_12[VAR_6]);
            if (VAR_4 == -1) {
            fcntl(VAR_4, F_SETFL, O_NONBLOCK);
            if (VAR_6 == 0) {
                VAR_5 = tap_probe_vnet_hdr(VAR_4);
            } else if (VAR_5 != tap_probe_vnet_hdr(VAR_4)) {
                error_report("VAR_5 not consistent across given VAR_3 VAR_12");
            if (net_init_tap_one(VAR_3, VAR_2, "VAR_3", VAR_1, VAR_11,
                                 VAR_8, VAR_9,
                                 VAR_3->has_vhostfds ? VAR_13[VAR_6] : NULL,
                                 VAR_5, VAR_4)) {
    } else if (VAR_3->has_helper) {
        if (VAR_3->has_ifname || VAR_3->has_script || VAR_3->has_downscript ||
            VAR_3->has_vnet_hdr || VAR_3->has_queues || VAR_3->has_fds) {
            error_report("VAR_11=, VAR_8=, VAR_9=, and VAR_5= "
                         "VAR_7=, and VAR_12= are invalid with helper=");
        VAR_4 = net_bridge_run_helper(VAR_3->helper, DEFAULT_BRIDGE_INTERFACE);
        if (VAR_4 == -1) {
        fcntl(VAR_4, F_SETFL, O_NONBLOCK);
        VAR_5 = tap_probe_vnet_hdr(VAR_4);
        if (net_init_tap_one(VAR_3, VAR_2, "bridge", VAR_1, VAR_11,
                             VAR_8, VAR_9, VAR_10,
                             VAR_5, VAR_4)) {
    } else {
        VAR_8 = VAR_3->has_script ? VAR_3->VAR_8 : DEFAULT_NETWORK_SCRIPT;
        VAR_9 = VAR_3->has_downscript ? VAR_3->VAR_9 :
            DEFAULT_NETWORK_DOWN_SCRIPT;
        if (VAR_3->has_ifname) {
            pstrcpy(VAR_11, sizeof VAR_11, VAR_3->VAR_11);
        } else {
            VAR_11[0] = '\0';
        for (VAR_6 = 0; VAR_6 < VAR_7; VAR_6++) {
            VAR_4 = net_tap_init(VAR_3, &VAR_5, VAR_6 >= 1 ? "no" : VAR_8,
                              VAR_11, sizeof VAR_11, VAR_7 > 1);
            if (VAR_4 == -1) {
            if (VAR_7 > 1 && VAR_6 == 0 && !VAR_3->has_ifname) {
                if (tap_fd_get_ifname(VAR_4, VAR_11)) {
                    error_report("Fail to get VAR_11");
            if (net_init_tap_one(VAR_3, VAR_2, "VAR_3", VAR_1, VAR_11,
                                 VAR_6 >= 1 ? "no" : VAR_8,
                                 VAR_6 >= 1 ? "no" : VAR_9,
                                 VAR_10, VAR_5, VAR_4)) {
    return 0;
int FUNC_0(const NetClientOptions *VAR_0, const char *VAR_1,
NetClientState *VAR_2)
{ const NetdevTapOptions *VAR_3; int VAR_4, VAR_5 = 0, VAR_6 = 0, VAR_7; const char *VAR_8 = NULL; const char *VAR_9 = NULL; const char *VAR_10; char VAR_11[128]; assert(VAR_0->kind == NET_CLIENT_OPTIONS_KIND_TAP); VAR_3 = VAR_0->VAR_3; VAR_7 = VAR_3->has_queues ? VAR_3->VAR_7 : 1; VAR_10 = VAR_3->has_vhostfd ? VAR_3->vhostfd : NULL; if (VAR_3->has_fd) { if (VAR_3->has_ifname || VAR_3->has_script || VAR_3->has_downscript ||
VAR_3->has_vnet_hdr || VAR_3->has_helper || VAR_3->has_queues ||
VAR_3->has_fds) { error_report("VAR_11=, VAR_8=, VAR_9=, VAR_5=, "
"helper=, VAR_7=, and VAR_12= are invalid with VAR_4="); VAR_4 = monitor_handle_fd_param(cur_mon, VAR_3->VAR_4); if (VAR_4 == -1) { fcntl(VAR_4, F_SETFL, O_NONBLOCK); VAR_5 = tap_probe_vnet_hdr(VAR_4); if (net_init_tap_one(VAR_3, VAR_2, "VAR_3", VAR_1, NULL,
VAR_8, VAR_9,
VAR_10, VAR_5, VAR_4)) { } else if (VAR_3->has_fds) { char *VAR_12[MAX_TAP_QUEUES]; char *VAR_13[MAX_TAP_QUEUES]; int VAR_14, VAR_15; if (VAR_3->has_ifname || VAR_3->has_script || VAR_3->has_downscript ||
VAR_3->has_vnet_hdr || VAR_3->has_helper || VAR_3->has_queues ||
VAR_3->has_fd) { error_report("VAR_11=, VAR_8=, VAR_9=, VAR_5=, "
"helper=, VAR_7=, and VAR_4= are invalid with VAR_12="); VAR_14 = get_fds(VAR_3->VAR_12, VAR_12, MAX_TAP_QUEUES); if (VAR_3->has_vhostfds) { VAR_15 = get_fds(VAR_3->vhostfds, VAR_13, MAX_TAP_QUEUES); if (VAR_14 != VAR_15) { error_report("The number of VAR_12 passed does not match the "
"number of vhostfds passed"); for (VAR_6 = 0; VAR_6 < VAR_14; VAR_6++) { VAR_4 = monitor_handle_fd_param(cur_mon, VAR_12[VAR_6]); if (VAR_4 == -1) { fcntl(VAR_4, F_SETFL, O_NONBLOCK); if (VAR_6 == 0) { VAR_5 = tap_probe_vnet_hdr(VAR_4); } else if (VAR_5 != tap_probe_vnet_hdr(VAR_4)) { error_report("VAR_5 not consistent across given VAR_3 VAR_12"); if (net_init_tap_one(VAR_3, VAR_2, "VAR_3", VAR_1, VAR_11,
VAR_8, VAR_9,
VAR_3->has_vhostfds ? VAR_13[VAR_6] : NULL,
VAR_5, VAR_4)) { } else if (VAR_3->has_helper) { if (VAR_3->has_ifname || VAR_3->has_script || VAR_3->has_downscript ||
VAR_3->has_vnet_hdr || VAR_3->has_queues || VAR_3->has_fds) { error_report("VAR_11=, VAR_8=, VAR_9=, and VAR_5= "
"VAR_7=, and VAR_12= are invalid with helper="); VAR_4 = net_bridge_run_helper(VAR_3->helper, DEFAULT_BRIDGE_INTERFACE); if (VAR_4 == -1) { fcntl(VAR_4, F_SETFL, O_NONBLOCK); VAR_5 = tap_probe_vnet_hdr(VAR_4); if (net_init_tap_one(VAR_3, VAR_2, "bridge", VAR_1, VAR_11,
VAR_8, VAR_9, VAR_10,
VAR_5, VAR_4)) { } else { VAR_8 = VAR_3->has_script ? VAR_3->VAR_8 : DEFAULT_NETWORK_SCRIPT; VAR_9 = VAR_3->has_downscript ? VAR_3->VAR_9 :
DEFAULT_NETWORK_DOWN_SCRIPT; if (VAR_3->has_ifname) { pstrcpy(VAR_11, sizeof VAR_11, VAR_3->VAR_11); } else { VAR_11[0] = '\0'; for (VAR_6 = 0; VAR_6 < VAR_7; VAR_6++) { VAR_4 = net_tap_init(VAR_3, &VAR_5, VAR_6 >= 1 ? "no" : VAR_8,
VAR_11, sizeof VAR_11, VAR_7 > 1); if (VAR_4 == -1) { if (VAR_7 > 1 && VAR_6 == 0 && !VAR_3->has_ifname) { if (tap_fd_get_ifname(VAR_4, VAR_11)) { error_report("Fail to get VAR_11"); if (net_init_tap_one(VAR_3, VAR_2, "VAR_3", VAR_1, VAR_11,
VAR_6 >= 1 ? "no" : VAR_8,
VAR_6 >= 1 ? "no" : VAR_9,
VAR_10, VAR_5, VAR_4)) { return 0;