mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-05 13:11:44 +00:00
kvm tools: Allow the user to pass a FD to use as a TAP device
This allows users to pass a pre-configured fd to use for the network
interface.
For example:
kvm run -n mode=tap,fd=3 3<>/dev/net/tap3
Acked-by: Daniel P. Berrange <berrange@redhat.com>
Cc: Osier Yang <jyang@redhat.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user