diff --git a/src/main.c b/src/main.c index d26d9a3..a7ccb5d 100644 --- a/src/main.c +++ b/src/main.c @@ -93,6 +93,8 @@ int main(int argc, char *argv[]) return throw_err("Failed to load initrd"); if (diskimg_file && vm_load_diskimg(&vm, diskimg_file) < 0) return throw_err("Failed to load disk image"); + if (vm_enable_net(&vm) < 0) + return throw_err("Failed to Enable Virtio-Net Device"); if (vm_late_init(&vm) < 0) return -1; diff --git a/src/vm.c b/src/vm.c index a88b386..92a0fca 100644 --- a/src/vm.c +++ b/src/vm.c @@ -97,6 +97,14 @@ int vm_load_diskimg(vm_t *v, const char *diskimg_file) return 0; } +int vm_enable_net(vm_t *v) +{ + if (!virtio_net_init(&v->virtio_net_dev)) + return -1; + virtio_net_init_pci(&v->virtio_net_dev, &v->pci, &v->io_bus, &v->mmio_bus); + return 0; +} + void vm_handle_io(vm_t *v, struct kvm_run *run) { uint64_t addr = run->io.port; diff --git a/src/vm.h b/src/vm.h index 0e66d53..5ebd9d3 100644 --- a/src/vm.h +++ b/src/vm.h @@ -31,6 +31,7 @@ int vm_load_image(vm_t *v, const char *image_path); int vm_load_initrd(vm_t *v, const char *initrd_path); int vm_load_diskimg(vm_t *v, const char *diskimg_file); int vm_late_init(vm_t *v); +int vm_enable_net(vm_t *v); int vm_run(vm_t *v); int vm_irq_line(vm_t *v, int irq, int level); void *vm_guest_to_host(vm_t *v, uint64_t guest);