mirror of
https://codeberg.org/icewind/netnsd.git
synced 2026-06-05 01:54:06 +02:00
add support for setting up routing inside the netns
This commit is contained in:
parent
35c8f5cc6c
commit
7588b5db00
18 changed files with 272 additions and 53 deletions
|
|
@ -5,10 +5,15 @@ mod target;
|
|||
pub use crate::config::name::{DeviceName, NamespaceName};
|
||||
pub use crate::config::source::ForwardSource;
|
||||
pub use crate::config::target::ForwardTarget;
|
||||
use serde::Deserialize;
|
||||
use cidr::AnyIpCidr;
|
||||
use serde::de::Error;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::fs::read_to_string;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use thiserror::Error;
|
||||
use toml::from_str;
|
||||
|
||||
|
|
@ -84,6 +89,8 @@ pub struct NamespaceConfig {
|
|||
pub forward: Vec<ForwardConfig>,
|
||||
#[serde(default)]
|
||||
pub devices: Vec<DeviceName>,
|
||||
#[serde(default, rename = "route")]
|
||||
pub routes: Vec<RouteConfig>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
|
@ -94,6 +101,27 @@ pub struct ForwardConfig {
|
|||
pub reverse: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct RouteConfig {
|
||||
#[serde(deserialize_with = "parse_cidr")]
|
||||
pub destination: AnyIpCidr,
|
||||
pub device: DeviceName,
|
||||
}
|
||||
|
||||
impl Display for RouteConfig {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} dev {}", self.destination, self.device)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_cidr<'de, D: Deserializer<'de>>(deserializer: D) -> Result<AnyIpCidr, D::Error> {
|
||||
let str = Cow::<'de, str>::deserialize(deserializer)?;
|
||||
match str.as_ref() {
|
||||
"default" => Ok(AnyIpCidr::Any),
|
||||
str => AnyIpCidr::from_str(str).map_err(D::Error::custom),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ConfigError {
|
||||
#[error("Error while reading config from {}: {error:#}", path.display())]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue