diff --git a/builtin-run.c b/builtin-run.c index 9148d83..924ae80 100644 --- a/builtin-run.c +++ b/builtin-run.c @@ -220,6 +220,8 @@ static int set_net_param(struct virtio_net_params *p, const char *param, p->host_ip = strdup(val); } else if (strcmp(param, "vhost") == 0) { p->vhost = atoi(val); + } else if (strcmp(param, "fd") == 0) { + p->fd = atoi(val); } return 0; diff --git a/include/kvm/virtio-net.h b/include/kvm/virtio-net.h index dade8cb..a3219b6 100644 --- a/include/kvm/virtio-net.h +++ b/include/kvm/virtio-net.h @@ -12,6 +12,7 @@ struct virtio_net_params { struct kvm *kvm; int mode; int vhost; + int fd; }; void virtio_net__init(const struct virtio_net_params *params); diff --git a/virtio/net.c b/virtio/net.c index 3fb5054..9b93c5d 100644 --- a/virtio/net.c +++ b/virtio/net.c @@ -178,6 +178,12 @@ static bool virtio_net__tap_init(const struct virtio_net_params *params, struct sockaddr_in sin = {0}; struct ifreq ifr; + /* Did the user already gave us the FD? */ + if (params->fd) { + ndev->tap_fd = params->fd; + return 1; + } + ndev->tap_fd = open("/dev/net/tun", O_RDWR); if (ndev->tap_fd < 0) { pr_warning("Unable to open /dev/net/tun");