From e3b56ae1a00c3438e002e56dc1ffd64604ed2943 Mon Sep 17 00:00:00 2001 From: Masato Imai Date: Tue, 25 Feb 2025 15:00:47 +0000 Subject: [PATCH] add Ipv4Network to Config --- src/config.rs | 12 +++++++++++- tests/host2/Dockerfile | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index e5c921b..26b9c6b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, } #[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, PartialOrd, Ord)] @@ -62,12 +63,21 @@ impl FromStr for Config { config[4], s ))?; + let mut networks: Vec = 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, }) } } diff --git a/tests/host2/Dockerfile b/tests/host2/Dockerfile index 22a851a..457e1ad 100644 --- a/tests/host2/Dockerfile +++ b/tests/host2/Dockerfile @@ -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"]