diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..ba077a403 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 000000000..99c884ebd --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,254 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "clap" +version = "3.0.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcd70aa5597dbc42f7217a543f9ef2768b2ef823ba29036072d30e1d88e98406" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim", + "termcolor", + "textwrap", + "vec_map", +] + +[[package]] +name = "clap_derive" +version = "3.0.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5bb0d655624a0b8770d1c178fb8ffcb1f91cc722cb08f451e3dc72465421ac" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" + +[[package]] +name = "netavark" +version = "0.0.1" +dependencies = [ + "clap", +] + +[[package]] +name = "os_str_bytes" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "unicode-segmentation" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..e7cd6673d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "netavark" +version = "0.0.1" +edition = "2018" +authors = ["github.com/containers"] +description = "A container network stack" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = "3.0.0-beta.4" diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..0615048cd --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +# TODO: Make this more configurable +#prog :=xnixperms + +debug ?= + +$(info debug is $(debug)) + +ifdef debug + release := + target :=debug + extension :=debug +else + release :=--release + target :=release + extension := +endif + +build: + cargo build $(release) --target-dir bin + cp bin/$(target)/netavark bin/netavark + +clean: + rm -rf bin + +all: build + +help: + @echo "usage: make $(prog) [debug=1]" diff --git a/README.md b/README.md index ba71cc06e..a765a2560 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,18 @@ Netavark is capable of the following given the proper JSON input: As this project is in very early development, we will add more capabilities in the near future. +## Requires + +- [Rust](https://www.rust-lang.org/tools/install) + +## Build + +```console +$ make +``` +## Latest release +Not applicable yet (TBD) + ## Latest release Not applicable yet (TBD) @@ -24,4 +36,4 @@ IRC `#podman` channel on `irc.libera.chat`. For discussions around issues/bugs and features, you can use the GitHub [issues](https://github.com/containers/netavark/issues) -and [PRs](https://github.com/containers/netavark/pulls) tracking system. \ No newline at end of file +and [PRs](https://github.com/containers/netavark/pulls) tracking system. diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 000000000..3d41beb35 --- /dev/null +++ b/src/commands/mod.rs @@ -0,0 +1,2 @@ +pub mod setup; +pub mod teardown; diff --git a/src/commands/setup.rs b/src/commands/setup.rs new file mode 100644 index 000000000..c45c829dc --- /dev/null +++ b/src/commands/setup.rs @@ -0,0 +1,23 @@ +//! Configures the given network namespace with provided specs +use std::path::PathBuf; +use clap::{self, Clap}; + +#[derive(Clap, Debug)] +pub struct Setup { + /// Network namespace path + #[clap(forbid_empty_values = true, required = true)] + network_namespace_path: String, +} + +impl Setup { + /// The setup command configures the given network namespace with the given configuration, creating any interfaces and firewall rules necessary. + pub fn new(network_namespace_path: String) -> Self { + Self { + network_namespace_path, + } + } + + pub fn exec(&self, input_file: PathBuf) { + () + } +} diff --git a/src/commands/teardown.rs b/src/commands/teardown.rs new file mode 100644 index 000000000..d01ea3fec --- /dev/null +++ b/src/commands/teardown.rs @@ -0,0 +1,22 @@ +use std::path::PathBuf; +use clap::{self, Clap}; + +#[derive(Clap, Debug)] +pub struct Teardown { + /// Network namespace path + #[clap(forbid_empty_values = true, required = true)] + network_namespace_path: String, +} + +impl Teardown { + /// The teardown command is the inverse of the setup command, undoing any configuration applied. Some interfaces may not be deleted (bridge interfaces, for example, will not be removed). + pub fn new(network_namespace_path: String) -> Self { + Self { + network_namespace_path, + } + } + + pub fn exec(&self, input_file: PathBuf) { + () + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 000000000..82b6da3c0 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod commands; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 000000000..a774b7207 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,36 @@ + +use std::path::PathBuf; +use clap::{crate_version, Clap}; + +use netavark::commands::setup; +use netavark::commands::teardown; + +#[derive(Clap, Debug)] +#[clap(version = crate_version!())] +struct Opts { + /// Instead of reading from STDIN, read the configuration to be applied from the given file. + #[clap(short, long)] + file: Option, + /// Netavark trig command + #[clap(subcommand)] + subcmd: SubCommand, +} + +#[derive(Clap, Debug)] +enum SubCommand { + #[clap(version = crate_version!())] + /// Configures the given network namespace with the given configuration. + Setup(setup::Setup), + #[clap(version = crate_version!())] + /// Undo any configuration applied via setup command. + Teardown(teardown::Teardown), +} + +fn main() { + let opts = Opts::parse(); + + match opts.subcmd { + SubCommand::Setup(setup) => setup.exec(opts.file.unwrap()), + SubCommand::Teardown(teardown) => teardown.exec(opts.file.unwrap()), + } +}