MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / setup_wireguard

Function setup_wireguard

gateway/src/config.rs:308–332  ·  view source on GitHub ↗
(config: &WgConfig)

Source from the content-addressed store, hash-verified

306}
307
308pub fn setup_wireguard(config: &WgConfig) -> Result<()> {
309 config.validate().context("Invalid wireguard config")?;
310
311 info!("Setting up wireguard interface");
312
313 let ifname = &config.interface;
314
315 // Check if interface exists by trying to run ip link show
316 if cmd!(ip link show $ifname > /dev/null).is_ok() {
317 info!("WireGuard interface {ifname} already exists");
318 return Ok(());
319 }
320
321 let addr = format!("{}", config.ip);
322 // Interface doesn't exist, create and configure it
323 cmd! {
324 ip link add $ifname type wireguard;
325 ip address add $addr dev $ifname;
326 ip link set $ifname up;
327 }?;
328
329 info!("Created and configured WireGuard interface {ifname}");
330
331 Ok(())
332}
333
334#[cfg(test)]
335mod tests {

Callers 1

mainFunction · 0.85

Calls 1

validateMethod · 0.45

Tested by

no test coverage detected