add Ipv4Network to Config

This commit is contained in:
Masato Imai
2025-02-25 15:00:47 +00:00
parent 7208d33b6e
commit e3b56ae1a0
2 changed files with 12 additions and 2 deletions

View File

@ -2,7 +2,7 @@ use std::{net::Ipv4Addr, str::FromStr};
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)]
pub struct Config {
@ -11,6 +11,7 @@ pub struct Config {
pub remote_as: AutonomousSystemNumber,
pub remote_ip: Ipv4Addr,
pub mode: Mode,
pub networks: Vec<Ipv4Network>,
}
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, PartialOrd, Ord)]
@ -62,12 +63,21 @@ impl FromStr for Config {
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 {
local_as,
local_ip,
remote_as,
remote_ip,
mode,
networks,
})
}
}

View File

@ -8,4 +8,4 @@ COPY . .
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"]