mirror of
https://github.com/mii443/miibgpd.git
synced 2025-12-03 02:58:23 +00:00
add Ipv4Network to Config
This commit is contained in:
@@ -2,7 +2,7 @@ use std::{net::Ipv4Addr, str::FromStr};
|
|||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
|
||||||
use crate::{bgp_type::AutonomousSystemNumber, error::ConfigParseError};
|
use crate::{bgp_type::AutonomousSystemNumber, error::ConfigParseError, routing::Ipv4Network};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, PartialOrd, Ord)]
|
#[derive(PartialEq, Eq, Debug, Clone, Hash, PartialOrd, Ord)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
@@ -11,6 +11,7 @@ pub struct Config {
|
|||||||
pub remote_as: AutonomousSystemNumber,
|
pub remote_as: AutonomousSystemNumber,
|
||||||
pub remote_ip: Ipv4Addr,
|
pub remote_ip: Ipv4Addr,
|
||||||
pub mode: Mode,
|
pub mode: Mode,
|
||||||
|
pub networks: Vec<Ipv4Network>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, PartialOrd, Ord)]
|
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, PartialOrd, Ord)]
|
||||||
@@ -62,12 +63,21 @@ impl FromStr for Config {
|
|||||||
config[4], s
|
config[4], s
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
|
let mut networks: Vec<Ipv4Network> = vec![];
|
||||||
|
for network in config[5..].iter() {
|
||||||
|
networks.push(network.parse().context(format!(
|
||||||
|
"cannot parse {0} as Ipv4Network and config is {1}",
|
||||||
|
network, s
|
||||||
|
))?);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
local_as,
|
local_as,
|
||||||
local_ip,
|
local_ip,
|
||||||
remote_as,
|
remote_as,
|
||||||
remote_ip,
|
remote_ip,
|
||||||
mode,
|
mode,
|
||||||
|
networks,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ COPY . .
|
|||||||
RUN cargo build
|
RUN cargo build
|
||||||
|
|
||||||
|
|
||||||
CMD ["./target/debug/miibgpd", "64513 10.200.100.3 64512 10.200.100.2 passive"]
|
CMD ["./target/debug/miibgpd", "64513 10.200.100.3 64512 10.200.100.2 passive 10.100.220.0/24"]
|
||||||
|
|||||||
Reference in New Issue
Block a user