Skip to content

Commit e864e20

Browse files
committed
avoid triggering loopback alias creation for freebsd bootstrap when nfsd is already running
1 parent fdd70c5 commit e864e20

5 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎anylinuxfs/src/main.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ pub(crate) fn default_linux_image_source(prefs: &impl Preferences) -> ImageSourc
175175
.unwrap_or(ImageSource::default())
176176
}
177177

178+
/// 2049=NFS, 32765=statd, 32767=mountd.
179+
const GVPROXY_FORWARDED_PORTS: &[u16] = &[2049, 32765, 32767];
180+
178181
fn load_config(common_args: &CommonArgs, debug_args: &DebugArgs) -> anyhow::Result<Config> {
179182
let identity =
180183
privilege::resolve_invoker_identity().context("Could not determine invoking user")?;
@@ -230,6 +233,8 @@ fn load_config(common_args: &CommonArgs, debug_args: &DebugArgs) -> anyhow::Resu
230233
let vsock_path = format!("/tmp/anylinuxfs-{}-vsock", rand_string(8));
231234
let unixgram_sock_path = format!("/tmp/vfkit-{}.sock", rand_string(8));
232235

236+
let gvproxy_forwards = GVPROXY_FORWARDED_PORTS.into();
237+
233238
let global_prefix_dir = if prefix_dir.starts_with("/opt/homebrew") {
234239
PathBuf::from("/opt/homebrew")
235240
} else {
@@ -293,6 +298,7 @@ fn load_config(common_args: &CommonArgs, debug_args: &DebugArgs) -> anyhow::Resu
293298
},
294299
network: NetworkConfig {
295300
gvproxy_net_sock_path,
301+
gvproxy_forwards,
296302
vsock_path,
297303
unixgram_sock_path,
298304
preferred_net_helper,

‎anylinuxfs/src/netutil.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ mod darwin {
230230
let Some(addr) = itf.address.ip_addr() else {
231231
continue;
232232
};
233-
let mut ip_candidate = None;
233+
let mut ip_candidate = Some(addr);
234234
let ipv6_scope = if addr.is_ipv6() { itf.index } else { None };
235235
for port in required_ports.iter().cloned() {
236236
if let Some(mut sock) = (addr, port).to_socket_addrs()?.next() {

‎anylinuxfs/src/settings.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub struct LogPaths {
5858
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
5959
pub struct NetworkConfig {
6060
pub gvproxy_net_sock_path: String,
61+
pub gvproxy_forwards: Vec<u16>,
6162
pub vsock_path: String,
6263
pub unixgram_sock_path: String,
6364
pub preferred_net_helper: NetHelper,
@@ -138,6 +139,13 @@ impl Config {
138139

139140
new_config
140141
}
142+
143+
// returns copy of Config with modified NetworkConfig
144+
pub fn with_network_config(&self, net_conf_fn: impl FnOnce(&mut NetworkConfig)) -> Self {
145+
let mut new_config = self.clone();
146+
net_conf_fn(&mut new_config.network);
147+
new_config
148+
}
141149
}
142150

143151
pub trait Preferences {

‎anylinuxfs/src/vm_image.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ mod freebsd {
219219
anyhow::bail!("FreeBSD base directory not specified");
220220
}
221221

222+
// We don't forward any ports during VM bootstrap.
223+
// This affects which loopback interface will be selected for gvproxy.
224+
// Normally, when there's a NFS port conflict, we ask the OS to create
225+
// a loopback alias which is a privileged operation. Without any ports,
226+
// no additional alias is needed and a non-root user can always proceed.
227+
let config = config.with_network_config(|net_conf| {
228+
net_conf.gvproxy_forwards = vec![];
229+
});
230+
222231
let base_path = config.paths.profile_path.join(&src.base_dir);
223232
let mtimes_path = base_path.join("mtimes");
224233
let tmp_path = base_path.join("tmp");

‎anylinuxfs/src/vm_network/mod.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ pub fn vsock_cleanup(vsock_path: &str) -> anyhow::Result<()> {
7373
Ok(())
7474
}
7575

76-
/// Ports gvproxy needs to forward through the loopback IP we select.
77-
/// 2049=NFS, 32765=statd, 32767=mountd.
78-
const GVPROXY_FORWARDED_PORTS: &[u16] = &[2049, 32765, 32767];
79-
8076
pub fn start_gvproxy(config: &Config) -> anyhow::Result<NetHelperService> {
8177
vfkit_sock_cleanup(&config.network.unixgram_sock_path)?;
8278

@@ -126,7 +122,7 @@ pub fn start_gvproxy(config: &Config) -> anyhow::Result<NetHelperService> {
126122
.spawn()
127123
.context("Failed to start gvproxy process")?;
128124

129-
let loopback_ip = netutil::pick_usable_loopback_ip(GVPROXY_FORWARDED_PORTS)?;
125+
let loopback_ip = netutil::pick_usable_loopback_ip(&config.network.gvproxy_forwards)?;
130126

131127
Ok(NetHelperService {
132128
proc: gvproxy_process,

0 commit comments

Comments
 (0)