Added a way to enable host-only networking through tart using --net-host (#32)

* Added a way to enable host-only networking through tart using SOFTNET_NET_TYPE=host

* Removed env variable and moved to Enum instead of str

* Fixed defaults & restricted publicity of host

* Fixed usage of NetType
This commit is contained in:
Sergei Parshev
2024-03-01 11:25:19 -05:00
committed by GitHub
parent f5a1b1cdbd
commit 0a92c290be
4 changed files with 28 additions and 6 deletions
+5 -1
View File
@@ -2,6 +2,7 @@ use anyhow::{anyhow, Context};
use clap::Parser;
use nix::sys::signal::{signal, SigHandler, Signal};
use privdrop::PrivDrop;
use softnet::NetType;
use softnet::proxy::Proxy;
use std::borrow::Cow;
use std::env;
@@ -28,6 +29,9 @@ struct Args {
#[clap(long, help = "MAC address to enforce for the VM")]
vm_mac_address: mac_address::MacAddress,
#[clap(long, arg_enum, help = "type of network to use for the VM", default_value_t=NetType::Nat)]
vm_net_type: NetType,
#[clap(
long,
help = "set bootpd(8) lease time to this value (in seconds) before starting the VM",
@@ -140,7 +144,7 @@ fn try_main() -> anyhow::Result<()> {
set_bootpd_lease_time(args.bootpd_lease_time);
// Initialize the proxy while still having the root privileges
let mut proxy = Proxy::new(args.vm_fd as RawFd, args.vm_mac_address)
let mut proxy = Proxy::new(args.vm_fd as RawFd, args.vm_mac_address, args.vm_net_type)
.context("failed to initialize proxy")?;
// Drop effective privileges to the user