working on args
This commit is contained in:
parent
1e7b616701
commit
167394ff91
42
src/cli.rs
42
src/cli.rs
@ -1,8 +1,20 @@
|
||||
//! Command line argument definitions
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{net::Ipv6Addr, path::PathBuf, str::FromStr};
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use ipnet::{Ipv4Net, Ipv6Net};
|
||||
|
||||
/// Shorthand for generating the well-known NAT64 prefix
|
||||
macro_rules! wkp {
|
||||
() => {
|
||||
Ipv6Net::new(
|
||||
Ipv6Addr::new(0x0064, 0xff9b, 0x000, 0x0000, 0x000, 0x0000, 0x000, 0x0000),
|
||||
96,
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
@ -17,9 +29,31 @@ pub struct Args {
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum Commands {
|
||||
/// Run protomask in NAT64 mode
|
||||
Nat64 {
|
||||
/// Path to the config file
|
||||
config_file: PathBuf,
|
||||
/// IPv6 prefix to listen for packets on
|
||||
#[clap(short='l', long = "listen", default_value_t = wkp!(), value_parser = nat64_prefix_parser)]
|
||||
listen_prefix: Ipv6Net,
|
||||
|
||||
/// Add an IPv4 prefix to the NAT pool
|
||||
#[clap(long = "nat", required = true)]
|
||||
nat_pool: Vec<Ipv4Net>,
|
||||
},
|
||||
/// Run protomask in Customer-side transLATor (CLAT) mode
|
||||
///
|
||||
/// CLAT mode will translate all native IPv4 traffic to IPv6 traffic.
|
||||
Clat {
|
||||
/// IPv6 prefix to use for source addressing
|
||||
#[clap(long = "via", default_value_t = wkp!(), value_parser = nat64_prefix_parser)]
|
||||
origin_prefix: Ipv6Net,
|
||||
},
|
||||
Clat {},
|
||||
}
|
||||
|
||||
fn nat64_prefix_parser(s: &str) -> Result<Ipv6Net, String> {
|
||||
let net = Ipv6Net::from_str(s).map_err(|err| err.to_string())?;
|
||||
if net.prefix_len() > 96 {
|
||||
return Err("Prefix length must be 96 or less".to_owned());
|
||||
}
|
||||
Ok(net)
|
||||
}
|
||||
|
||||
|
62
src/main.rs
62
src/main.rs
@ -15,36 +15,34 @@ mod cli;
|
||||
mod config;
|
||||
mod logging;
|
||||
|
||||
async fn run_nat(config_file: PathBuf) {
|
||||
// Parse the config file
|
||||
let config = Config::load(args.config_file).unwrap();
|
||||
// async fn run_nat(config_file: PathBuf) {
|
||||
// // Parse the config file
|
||||
// let config = Config::load(args.config_file).unwrap();
|
||||
|
||||
// Currently, only a /96 is supported
|
||||
if config.nat64_prefix.prefix_len() != 96 {
|
||||
log::error!("Only a /96 prefix is supported for the NAT64 prefix");
|
||||
std::process::exit(1);
|
||||
}
|
||||
// // Currently, only a /96 is supported
|
||||
// if config.nat64_prefix.prefix_len() != 96 {
|
||||
// log::error!("Only a /96 prefix is supported for the NAT64 prefix");
|
||||
// std::process::exit(1);
|
||||
// }
|
||||
|
||||
// Create the NAT64 instance
|
||||
let mut nat64 = Nat64::new(
|
||||
config.nat64_prefix,
|
||||
config.pool.prefixes.clone(),
|
||||
config
|
||||
.pool
|
||||
.static_map
|
||||
.iter()
|
||||
.map(|rule| (rule.v6, rule.v4))
|
||||
.collect(),
|
||||
config.pool.reservation_duration(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
// // Create the NAT64 instance
|
||||
// let mut nat64 = Nat64::new(
|
||||
// config.nat64_prefix,
|
||||
// config.pool.prefixes.clone(),
|
||||
// config
|
||||
// .pool
|
||||
// .static_map
|
||||
// .iter()
|
||||
// .map(|rule| (rule.v6, rule.v4))
|
||||
// .collect(),
|
||||
// config.pool.reservation_duration(),
|
||||
// )
|
||||
// .await
|
||||
// .unwrap();
|
||||
|
||||
|
||||
|
||||
// Handle packets
|
||||
nat64.run().await.unwrap();
|
||||
}
|
||||
// // Handle packets
|
||||
// nat64.run().await.unwrap();
|
||||
// }
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() {
|
||||
@ -54,11 +52,11 @@ pub async fn main() {
|
||||
// Set up logging
|
||||
enable_logger(args.verbose);
|
||||
|
||||
// Handle metrics requests
|
||||
if let Some(bind_addr) = config.prom_bind_addr {
|
||||
log::info!("Enabling metrics server on {}", bind_addr);
|
||||
tokio::spawn(protomask::metrics::serve_metrics(bind_addr));
|
||||
}
|
||||
// // Handle metrics requests
|
||||
// if let Some(bind_addr) = config.prom_bind_addr {
|
||||
// log::info!("Enabling metrics server on {}", bind_addr);
|
||||
// tokio::spawn(protomask::metrics::serve_metrics(bind_addr));
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user