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 28, 2022
1 parent 279be6e commit 57f5727
Show file tree
Hide file tree
Showing 8 changed files with 490 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 = network::types::NetworkOptions::load(input_file)?;

let firewall_driver = match firewall::get_supported_firewall_driver() {
Expand Down Expand Up @@ -73,6 +74,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
16 changes: 16 additions & 0 deletions src/network/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- https://docs.rs/ipnet/2.5.0/ipnet/enum.IpSubnets.html
- can be used to get smallest subset

- properly parse config
- set up interface

## To test
- interface config without
- address
- private key
- peer configs without
- allowedIPs
- publickey
- config must be readable
- Interface is up
- routes match the allowedIPs settings
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 @@ -16,6 +16,7 @@ pub mod driver;
pub mod internal_types;
pub mod macvlan;
pub mod netlink;
pub mod wireguard;

impl types::NetworkOptions {
pub fn load(path: Option<String>) -> NetavarkResult<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 57f5727

Please sign in to comment.