Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions native/hyperrs-linux/src/sysctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ impl Ipv6 {
self.conf_dir(link.as_component())
}

/// `net/ipv6/neigh/<link>/`.
pub fn neigh(self, link: &IfName) -> Ipv6Neigh {
Ipv6Neigh(
self.0
.child(StrictComponent::from_static("neigh"))
.child(link.as_component()),
)
}

fn conf_dir(self, dir: &StrictComponent) -> Ipv6Conf {
Ipv6Conf(
self.0
Expand Down Expand Up @@ -152,6 +161,20 @@ impl Ipv6Conf {
}
}

/// `net/ipv6/neigh/<link>/`.
pub struct Ipv6Neigh(SysctlKey);

impl Ipv6Neigh {
/// `net/ipv6/neigh/<link>/proxy_delay` at 0: a neighbour advertisement the link answers by
/// proxy goes out at once, not after a random delay of up to the default 0.8 s.
pub fn no_proxy_delay(self) -> Setting {
Setting {
key: self.0.child(StrictComponent::from_static("proxy_delay")),
value: "0",
}
}
}

/// A sysctl and the value to give it.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Setting {
Expand Down Expand Up @@ -287,6 +310,30 @@ mod tests {
assert_eq!(read(path), host);
}

#[rstest]
fn no_proxy_delay_zeroes_only_the_namespace_it_is_written_in_as_root() {
let Some(ns) = ScratchNs::new("sysctl-proxy-delay") else {
return;
};
let path = "net/ipv6/neigh/lo/proxy_delay";
let host = read(path);

let written = ns
.get()
.scoped(|| {
Sysctl::net()
.ipv6()
.neigh(&"lo".parse().unwrap())
.no_proxy_delay()
.write()
.unwrap();
read(path)
})
.unwrap();

assert_eq!((written.as_str(), read(path)), ("0", host));
}

#[rstest]
fn accept_ra_reads_back_every_mode_it_is_set_to_as_root() {
let Some(ns) = ScratchNs::new("sysctl-accept-ra") else {
Expand Down
12 changes: 10 additions & 2 deletions native/suidhelper/src/net/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub struct HostNet<'a> {
}

impl HostNet<'_> {
/// Forward and proxy NDP for VMs, masquerade their IPv4 out of `uplink`, and
/// firewall them off from the host, its network, and inbound connections.
/// Forward and proxy NDP for VMs, answering at once, masquerade their IPv4 out of
/// `uplink`, and firewall them off from the host, its network, and inbound connections.
pub fn init(&self, root: &Root<'_>, nft: &Nft) -> Result<(), HostNetError> {
if Rtnl::open()?.link(self.uplink)?.is_none() {
return Err(HostNetError::NoUplink(self.uplink.clone()));
Expand All @@ -65,6 +65,14 @@ impl HostNet<'_> {
.conf(self.uplink)
.proxy_ndp(true)
.write()?;
// The uplink's router asks for each new VM's address and drops what it holds for it
// meanwhile. Answered after the default random delay of up to 0.8 s, a VM's first inbound
// connection loses its SYN and waits a second for TCP to send it again.
Sysctl::net()
.ipv6()
.neigh(self.uplink)
.no_proxy_delay()
.write()?;

nft.replace_table(root, &self.table())?;
Ok(())
Expand Down
Loading