struct vhost_net *vhost_net_init(VhostNetOptions *options)

{

    int r;

    bool backend_kernel = options->backend_type == VHOST_BACKEND_TYPE_KERNEL;

    struct vhost_net *net = g_malloc(sizeof *net);



    if (!options->net_backend) {

        fprintf(stderr, "vhost-net requires net backend to be setup\n");

        goto fail;

    }



    if (backend_kernel) {

        r = vhost_net_get_fd(options->net_backend);

        if (r < 0) {

            goto fail;

        }

        net->dev.backend_features = qemu_has_vnet_hdr(options->net_backend)

            ? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_HDR);

        net->backend = r;

    } else {

        net->dev.backend_features = 0;

        net->backend = -1;

    }

    net->nc = options->net_backend;



    net->dev.nvqs = 2;

    net->dev.vqs = net->vqs;

    net->dev.vq_index = net->nc->queue_index;



    r = vhost_dev_init(&net->dev, options->opaque,

                       options->backend_type, options->force);

    if (r < 0) {

        goto fail;

    }

    if (backend_kernel) {

        if (!qemu_has_vnet_hdr_len(options->net_backend,

                               sizeof(struct virtio_net_hdr_mrg_rxbuf))) {

            net->dev.features &= ~(1ULL << VIRTIO_NET_F_MRG_RXBUF);

        }

        if (~net->dev.features & net->dev.backend_features) {

            fprintf(stderr, "vhost lacks feature mask %" PRIu64

                   " for backend\n",

                   (uint64_t)(~net->dev.features & net->dev.backend_features));

            vhost_dev_cleanup(&net->dev);

            goto fail;

        }

    }

    /* Set sane init value. Override when guest acks. */

    vhost_net_ack_features(net, 0);

    return net;

fail:

    g_free(net);

    return NULL;

}

struct vhost_net *vhost_net_init(VhostNetOptions *options)

{

    int r;

    bool backend_kernel = options->backend_type == VHOST_BACKEND_TYPE_KERNEL;

    struct vhost_net *net = g_malloc(sizeof *net);



    if (!options->net_backend) {

        fprintf(stderr, "vhost-net requires net backend to be setup\n");

        goto fail;

    }



    if (backend_kernel) {

        r = vhost_net_get_fd(options->net_backend);

        if (r < 0) {

            goto fail;

        }

        net->dev.backend_features = qemu_has_vnet_hdr(options->net_backend)

            ? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_HDR);

        net->backend = r;

    } else {

        net->dev.backend_features = 0;

        net->backend = -1;

    }

    net->nc = options->net_backend;



    net->dev.nvqs = 2;

    net->dev.vqs = net->vqs;

    net->dev.vq_index = net->nc->queue_index;



    r = vhost_dev_init(&net->dev, options->opaque,

                       options->backend_type, options->force);

    if (r < 0) {

        goto fail;

    }

    if (backend_kernel) {

        if (!qemu_has_vnet_hdr_len(options->net_backend,

                               sizeof(struct virtio_net_hdr_mrg_rxbuf))) {

            net->dev.features &= ~(1ULL << VIRTIO_NET_F_MRG_RXBUF);

        }

        if (~net->dev.features & net->dev.backend_features) {

            fprintf(stderr, "vhost lacks feature mask %" PRIu64

                   " for backend\n",

                   (uint64_t)(~net->dev.features & net->dev.backend_features));

            vhost_dev_cleanup(&net->dev);

            goto fail;

        }

    }

    

    vhost_net_ack_features(net, 0);

    return net;

fail:

    g_free(net);

    return NULL;

}

                       options->backend_type, options->force);
struct vhost_net *FUNC_0(VhostNetOptions *VAR_0)

{

    int VAR_1;

    bool backend_kernel = VAR_0->backend_type == VHOST_BACKEND_TYPE_KERNEL;

    struct vhost_net *VAR_2 = g_malloc(sizeof *VAR_2);



    if (!VAR_0->net_backend) {

        fprintf(stderr, "vhost-VAR_2 requires VAR_2 backend to be setup\n");

        goto fail;

    }



    if (backend_kernel) {

        VAR_1 = vhost_net_get_fd(VAR_0->net_backend);

        if (VAR_1 < 0) {

            goto fail;

        }

        VAR_2->dev.backend_features = qemu_has_vnet_hdr(VAR_0->net_backend)

            ? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_HDR);

        VAR_2->backend = VAR_1;

    } else {

        VAR_2->dev.backend_features = 0;

        VAR_2->backend = -1;

    }

    VAR_2->nc = VAR_0->net_backend;



    VAR_2->dev.nvqs = 2;

    VAR_2->dev.vqs = VAR_2->vqs;

    VAR_2->dev.vq_index = VAR_2->nc->queue_index;



    VAR_1 = vhost_dev_init(&VAR_2->dev, VAR_0->opaque,

                       VAR_0->backend_type, VAR_0->force);

    if (VAR_1 < 0) {

        goto fail;

    }

    if (backend_kernel) {

        if (!qemu_has_vnet_hdr_len(VAR_0->net_backend,

                               sizeof(struct virtio_net_hdr_mrg_rxbuf))) {

            VAR_2->dev.features &= ~(1ULL << VIRTIO_NET_F_MRG_RXBUF);

        }

        if (~VAR_2->dev.features & VAR_2->dev.backend_features) {

            fprintf(stderr, "vhost lacks feature mask %" PRIu64

                   " for backend\n",

                   (uint64_t)(~VAR_2->dev.features & VAR_2->dev.backend_features));

            vhost_dev_cleanup(&VAR_2->dev);

            goto fail;

        }

    }

    

    vhost_net_ack_features(VAR_2, 0);

    return VAR_2;

fail:

    g_free(VAR_2);

    return NULL;

}

struct vhost_net *FUNC_0(VhostNetOptions *VAR_0)
{ int VAR_1; bool backend_kernel = VAR_0->backend_type == VHOST_BACKEND_TYPE_KERNEL; struct vhost_net *VAR_2 = g_malloc(sizeof *VAR_2); if (!VAR_0->net_backend) { fprintf(stderr, "vhost-VAR_2 requires VAR_2 backend to be setup\n"); goto fail; } if (backend_kernel) { VAR_1 = vhost_net_get_fd(VAR_0->net_backend); if (VAR_1 < 0) { goto fail; } VAR_2->dev.backend_features = qemu_has_vnet_hdr(VAR_0->net_backend)
? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_HDR); VAR_2->backend = VAR_1; } else { VAR_2->dev.backend_features = 0; VAR_2->backend = -1; } VAR_2->nc = VAR_0->net_backend; VAR_2->dev.nvqs = 2; VAR_2->dev.vqs = VAR_2->vqs; VAR_2->dev.vq_index = VAR_2->nc->queue_index; VAR_1 = vhost_dev_init(&VAR_2->dev, VAR_0->opaque,
VAR_0->backend_type, VAR_0->force); if (VAR_1 < 0) { goto fail; } if (backend_kernel) { if (!qemu_has_vnet_hdr_len(VAR_0->net_backend,
sizeof(struct virtio_net_hdr_mrg_rxbuf))) { VAR_2->dev.features &= ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); } if (~VAR_2->dev.features & VAR_2->dev.backend_features) { fprintf(stderr, "vhost lacks feature mask %" PRIu64
" for backend\n",
(uint64_t)(~VAR_2->dev.features & VAR_2->dev.backend_features)); vhost_dev_cleanup(&VAR_2->dev); goto fail; } } vhost_net_ack_features(VAR_2, 0); return VAR_2; fail:
g_free(VAR_2); return NULL; }