From f69625c9b006200ff35cad0334773f2ffadfa629 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Thu, 3 Aug 2023 13:12:58 -0400 Subject: [PATCH] Implement nat64 cli args --- src/protomask-clat.rs | 2 +- src/protomask.rs | 68 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/protomask-clat.rs b/src/protomask-clat.rs index b024273..cab3299 100644 --- a/src/protomask-clat.rs +++ b/src/protomask-clat.rs @@ -19,7 +19,7 @@ mod common; #[derive(Debug, Parser)] #[clap(author, version, about="IPv4 to IPv6 Customer-side transLATor (CLAT)", long_about = None)] struct Args { - /// IPv6 prefix to embed IPv4 addresses in + /// RFC6052 IPv6 prefix to encapsulate IPv4 packets within #[clap(long="via", default_value_t = ("64:ff9b::/96").parse().unwrap(), value_parser = parse_network_specific_prefix)] embed_prefix: Ipv6Net, diff --git a/src/protomask.rs b/src/protomask.rs index b8c879c..cb42757 100644 --- a/src/protomask.rs +++ b/src/protomask.rs @@ -1,2 +1,68 @@ +use std::path::PathBuf; + +use clap::Parser; +use common::{logging::enable_logger, rfc6052::parse_network_specific_prefix}; +use ipnet::{Ipv4Net, Ipv6Net}; +use nix::unistd::Uid; + +mod common; + +#[derive(Parser)] +#[clap(author, version, about="Fast and simple NAT64", long_about = None)] +struct Args { + /// RFC6052 IPv6 translation prefix + #[clap(long, default_value_t = ("64:ff9b::/96").parse().unwrap(), value_parser = parse_network_specific_prefix)] + translation_prefix: Ipv6Net, + + #[command(flatten)] + pool: PoolArgs, + + /// A CSV file containing static address mappings from IPv6 to IPv4 + #[clap(long = "static-file")] + static_file: Option, + + /// NAT reservation timeout in seconds + #[clap(long, default_value = "7200")] + reservation_timeout: u64, + + /// Explicitly set the interface name to use + #[clap(short, long, default_value_t = ("nat%d").to_string())] + interface: String, + + /// Enable verbose logging + #[clap(short, long)] + verbose: bool, +} + +#[derive(clap::Args)] +#[group(required = true, multiple = false)] +struct PoolArgs { + /// IPv4 prefixes to use as NAT pool address space + #[clap(long = "pool-add")] + pool_prefixes: Vec, + + /// A file containing newline-delimited IPv4 prefixes to use as NAT pool address space + #[clap(long = "pool-file", conflicts_with = "pool_prefixes")] + pool_file: Option, +} + +impl PoolArgs { + pub fn prefixes(&self) -> Result, std::io::Error> { + todo!() + } +} + #[tokio::main] -pub async fn main() {} +pub async fn main() { + // Parse CLI args + let args = Args::parse(); + + // Initialize logging + enable_logger(args.verbose); + + // We must be root to continue program execution + if !Uid::effective().is_root() { + log::error!("This program must be run as root"); + std::process::exit(1); + } +}