diff --git a/Justfile b/Justfile index e8ab18c..8c12c2e 100644 --- a/Justfile +++ b/Justfile @@ -12,7 +12,7 @@ run: sudo -E capsh --keep=1 --user=$USER --inh=cap_net_admin --addamb=cap_net_admin -- -c \ 'RUST_BACKTRACE=1 '$CARGO_PATH' run --bin vmm -- cli --memory 512 --cpus 1 \ --kernel tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin \ - --network-host-ip 172.29.0.1 --network-host-netmask 255.255.0.0 \ + --iface-host-addr 172.29.0.1 --netmask 255.255.0.0 --iface-guest-addr 172.29.0.2 \ --initramfs=tools/rootfs/initramfs.img' build-kernel: diff --git a/src/vmm/src/args.rs b/src/vmm/src/args.rs index d4e9bcc..3feceef 100644 --- a/src/vmm/src/args.rs +++ b/src/vmm/src/args.rs @@ -42,11 +42,15 @@ pub struct CliArguments { /// IPv4 address of the host tap interface. #[clap(long, env, required = true)] - pub network_host_ip: Ipv4Addr, + pub iface_host_addr: Ipv4Addr, - /// Subnet mask of the host tap interface. + /// Subnet mask for network. #[clap(long, env, required = true)] - pub network_host_netmask: Ipv4Addr, + pub netmask: Ipv4Addr, + + /// IPv4 address of the guest eth0 interface. + #[clap(long, env, required = true)] + pub iface_guest_addr: Ipv4Addr, /// Verbosity level. #[command(flatten)] diff --git a/src/vmm/src/core/devices/virtio/net/device.rs b/src/vmm/src/core/devices/virtio/net/device.rs index d388564..bf8acf8 100644 --- a/src/vmm/src/core/devices/virtio/net/device.rs +++ b/src/vmm/src/core/devices/virtio/net/device.rs @@ -42,8 +42,9 @@ impl Net { mem: Arc, device_mgr: Arc>, mmio_cfg: MmioConfig, - ip_addr: Ipv4Addr, - mask: Ipv4Addr, + tap_addr: Ipv4Addr, + netmask: Ipv4Addr, + iface_guest_addr: Ipv4Addr, irq: u32, endpoint: RemoteEndpoint, vm_fd: Arc, @@ -73,7 +74,7 @@ impl Net { // Set offload flags to match the relevant virtio features of the device (for now, // statically set in the constructor. - let tap = open_tap(None, Some(ip_addr), Some(mask), &mut None, None, None) + let tap = open_tap(None, Some(tap_addr), Some(netmask), &mut None, None, None) .map_err(Error::TunTap)?; // The layout of the header is specified in the standard and is 12 bytes in size. We @@ -87,9 +88,15 @@ impl Net { tap: Arc::new(Mutex::new(tap)), })); - let param = register_mmio_device(mmio_cfg, device_mgr, irq, None, net.clone()) + let vmmio_param = register_mmio_device(mmio_cfg, device_mgr, irq, None, net.clone()) .map_err(Error::Virtio)?; - cmdline_extra_parameters.push(param); + let ip_pnp_param: String = format!( + "ip={}::{}:{}::eth0:off", + iface_guest_addr, tap_addr, netmask + ); + + cmdline_extra_parameters.push(vmmio_param); + cmdline_extra_parameters.push(ip_pnp_param); Ok(net) } diff --git a/src/vmm/src/core/vmm.rs b/src/vmm/src/core/vmm.rs index 6b5097a..902b7ad 100644 --- a/src/vmm/src/core/vmm.rs +++ b/src/vmm/src/core/vmm.rs @@ -58,8 +58,9 @@ pub struct VMM { event_mgr: EventMgr, vcpus: Vec, - tap_ip_addr: Ipv4Addr, - tap_netmask: Ipv4Addr, + tap_addr: Ipv4Addr, + netmask: Ipv4Addr, + iface_guest_addr: Ipv4Addr, net_devices: Vec>>, serial: Arc>>, slip_pty: Arc>, @@ -68,7 +69,7 @@ pub struct VMM { impl VMM { /// Create a new VMM. - pub fn new(tap_ip_addr: Ipv4Addr, tap_netmask: Ipv4Addr) -> Result { + pub fn new(tap_addr: Ipv4Addr, netmask: Ipv4Addr, iface_guest_addr: Ipv4Addr) -> Result { // Open /dev/kvm and get a file descriptor to it. let kvm = Kvm::new().map_err(Error::KvmIoctl)?; @@ -110,8 +111,9 @@ impl VMM { )), slip_pty: Arc::new(Mutex::new(slip_pty)), epoll, - tap_ip_addr, - tap_netmask, + tap_addr, + netmask, + iface_guest_addr, net_devices: Vec::new(), }; @@ -380,8 +382,9 @@ impl VMM { mem, self.device_mgr.clone(), mmio_cfg, - self.tap_ip_addr, - self.tap_netmask, + self.tap_addr, + self.netmask, + self.iface_guest_addr, irq, self.event_mgr.lock().unwrap().remote_endpoint(), self.vm_fd.clone(), diff --git a/src/vmm/src/grpc/server.rs b/src/vmm/src/grpc/server.rs index 1a8fb2c..24c01b6 100644 --- a/src/vmm/src/grpc/server.rs +++ b/src/vmm/src/grpc/server.rs @@ -47,8 +47,8 @@ impl VmmServiceTrait for VmmService { let (tx, rx) = tokio::sync::mpsc::channel(4); const HOST_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 0, 1); - const VM_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 0, 2); const HOST_NETMASK: Ipv4Addr = Ipv4Addr::new(255, 255, 0, 0); + const GUEST_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 0, 2); // Check if the kernel is on the system, else build it if !Path::new("./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin") @@ -77,7 +77,7 @@ impl VmmServiceTrait for VmmService { initramfs_path.push("./tools/rootfs/initramfs.img"); // // Create a new VMM - let mut vmm = VMM::new(HOST_IP, HOST_NETMASK).map_err(VmmErrors::VmmNew)?; + let mut vmm = VMM::new(HOST_IP, HOST_NETMASK, GUEST_IP).map_err(VmmErrors::VmmNew)?; // Configure the VMM parameters might need to be calculated rather than hardcoded vmm.configure(1, 512, kernel_path, &Some(initramfs_path)) @@ -96,7 +96,7 @@ impl VmmServiceTrait for VmmService { tokio::time::sleep(Duration::from_secs(2)).await; println!("Connecting to Agent service"); - WorkloadClient::new(VM_IP, 50051).await + WorkloadClient::new(GUEST_IP, 50051).await }) .await .unwrap(); diff --git a/src/vmm/src/main.rs b/src/vmm/src/main.rs index 9947bf0..e12f375 100644 --- a/src/vmm/src/main.rs +++ b/src/vmm/src/main.rs @@ -38,9 +38,13 @@ async fn main() -> Result<(), Box> { .with_max_level(cli_args.convert_log_to_tracing()) .init(); // Create a new VMM - let mut vmm = VMM::new(cli_args.network_host_ip, cli_args.network_host_netmask) - .map_err(VmmErrors::VmmNew) - .unwrap(); + let mut vmm = VMM::new( + cli_args.iface_host_addr, + cli_args.netmask, + cli_args.iface_guest_addr, + ) + .map_err(VmmErrors::VmmNew) + .unwrap(); vmm.configure( cli_args.cpus,