Skip to content

Commit

Permalink
WIP: finishes parsing config
Browse files Browse the repository at this point in the history
  • Loading branch information
b-m-f committed Oct 27, 2022
1 parent d9e76ab commit a97c0b8
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/commands/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl Setup {
}
}
debug!("{:?}", "Setting up...");
// TODO_WG: load wg-config file here
let network_options = match network::types::NetworkOptions::load(&input_file) {
Ok(opts) => opts,
Err(e) => {
Expand Down Expand Up @@ -82,6 +83,7 @@ impl Setup {
let mut drivers = Vec::with_capacity(network_options.network_info.len());

// Perform per-network setup
// TODO_WG: add necessary network options here
for (net_name, network) in network_options.network_info.iter() {
let per_network_opts = network_options.networks.get(net_name).ok_or_else(|| {
NetavarkError::Message(format!(
Expand Down
5 changes: 5 additions & 0 deletions src/network/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- https://docs.rs/ipnet/2.5.0/ipnet/enum.IpSubnets.html
- can be used to get smallest subset

- properly parse config
- set up interface
1 change: 1 addition & 0 deletions src/network/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub const IPAM_NONE: &str = "none";

pub const DRIVER_BRIDGE: &str = "bridge";
pub const DRIVER_MACVLAN: &str = "macvlan";
pub const DRIVER_WIREGUARD: &str = "wireguard";

pub const OPTION_ISOLATE: &str = "isolate";
pub const OPTION_MTU: &str = "mtu";
Expand Down
2 changes: 2 additions & 0 deletions src/network/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use super::{
macvlan::MacVlan,
netlink,
types::{Network, PerNetworkOptions, PortMapping, StatusBlock},
wireguard::WireGuard,
};
use std::os::unix::io::RawFd;

Expand Down Expand Up @@ -50,6 +51,7 @@ pub fn get_network_driver(info: DriverInfo) -> NetavarkResult<Box<dyn NetworkDri
match info.network.driver.as_str() {
constants::DRIVER_BRIDGE => Ok(Box::new(Bridge::new(info))),
constants::DRIVER_MACVLAN => Ok(Box::new(MacVlan::new(info))),
constants::DRIVER_WIREGUARD => Ok(Box::new(WireGuard::new(info))),

_ => Err(NetavarkError::Message(format!(
"unknown network driver {}",
Expand Down
1 change: 1 addition & 0 deletions src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod driver;
pub mod internal_types;
pub mod macvlan;
pub mod netlink;
pub mod wireguard;

impl types::NetworkOptions {
pub fn load(path: &str) -> Result<types::NetworkOptions> {
Expand Down
4 changes: 4 additions & 0 deletions src/network/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ pub struct PerNetworkOptions {
/// MAC address for the container interface.
#[serde(rename = "static_mac")]
pub static_mac: Option<String>,

/// Additional options for a network
#[serde(rename = "options")]
pub options: Option<HashMap<String, String>>,
}

// PortMapping is one or more ports that will be mapped into the container.
Expand Down
Loading

0 comments on commit a97c0b8

Please sign in to comment.