diff --git a/src/vmm/src/core/devices/virtio/net/device.rs b/src/vmm/src/core/devices/virtio/net/device.rs index 3698d84..96acde6 100644 --- a/src/vmm/src/core/devices/virtio/net/device.rs +++ b/src/vmm/src/core/devices/virtio/net/device.rs @@ -85,13 +85,14 @@ impl Net { tap.set_vnet_hdr_size(VIRTIO_NET_HDR_SIZE as i32) .map_err(Error::Tap)?; - let bridge = Bridge::new("br0".to_string()); + let bridge_name = "br0".to_string(); + let bridge = Bridge::new(bridge_name.clone()); bridge.set_addr(iface_host_addr, netmask); bridge.attach_link(tap.get_name().map_err(Error::Tap)?); bridge.set_up(); // Get internet access - iptables_ip_masq(network, netmask); + iptables_ip_masq(network, netmask, bridge_name); let net = Arc::new(Mutex::new(Net { mem, diff --git a/src/vmm/src/core/devices/virtio/net/iptables.rs b/src/vmm/src/core/devices/virtio/net/iptables.rs index d7d66de..2c61579 100644 --- a/src/vmm/src/core/devices/virtio/net/iptables.rs +++ b/src/vmm/src/core/devices/virtio/net/iptables.rs @@ -2,12 +2,12 @@ use std::net::Ipv4Addr; use super::xx_netmask_width; -pub fn iptables_ip_masq(network: Ipv4Addr, netmask: Ipv4Addr) { +pub fn iptables_ip_masq(network: Ipv4Addr, netmask: Ipv4Addr, link_name: String) { let prefix_len = xx_netmask_width(netmask.octets()); let source = format!("{}/{}", network, prefix_len); let ipt = iptables::new(false).unwrap(); - let rule = format!("-s {} ! -o br0 -j MASQUERADE", source); + let rule = format!("-s {} ! -o {} -j MASQUERADE", source, link_name); let exists = ipt.exists("nat", "POSTROUTING", rule.as_str()).unwrap(); if !exists {