Skip to content

Commit d6556b2

Browse files
committed
fix(k8s-intf): Protocol IP is a IP/mask not plain IP
spec.gateway.protocol_ip is a UnicastIPv4Addr/mask not a plain IPv4 addr. Fix generator and parser to reflect this.
1 parent 36fa63e commit d6556b2

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ k8s-intf = { workspace = true }
1616

1717
# external
1818
derive_builder = { workspace = true, default-features = false, features = ["default"] }
19+
ipnet = { workspace = true }
1920
linkme = { workspace = true }
2021
multi_index_map = { workspace = true, features = ["serde"] }
2122
ordermap = { workspace = true, features = ["std"] }

config/src/converters/k8s/underlay.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright Open Network Fabric Authors
33

4-
use std::net::{IpAddr, Ipv4Addr};
4+
use std::net::IpAddr;
55

6+
use ipnet::Ipv4Net;
67
use k8s_intf::gateway_agent_crd::GatewayAgentGateway;
78
use lpm::prefix::{Prefix, PrefixString};
89
use net::eth::mac::SourceMac;
@@ -97,9 +98,14 @@ fn add_bgp_config(
9798
"Gateway protocol IP not specified".to_string(),
9899
))?;
99100

100-
let router_id = protocol_ip.parse::<Ipv4Addr>().map_err(|e| {
101-
FromK8sConversionError::ParseError(format!("Invalid protocol IP {protocol_ip}: {e}"))
102-
})?;
101+
let router_id = protocol_ip
102+
.parse::<Ipv4Net>()
103+
.map_err(|e| {
104+
FromK8sConversionError::ParseError(format!(
105+
"Invalid IPv4 protocol IP {protocol_ip}: {e}"
106+
))
107+
})?
108+
.addr();
103109

104110
let vtep_ip_raw = gateway
105111
.vtep_ip
@@ -190,7 +196,10 @@ mod test {
190196
// Check BGP configuration
191197
assert_eq!(gateway.asn, Some(bgp_config.asn));
192198
assert_eq!(
193-
gateway.protocol_ip,
199+
gateway
200+
.protocol_ip
201+
.as_ref()
202+
.map(|v| v.split('/').next().unwrap().to_string()),
194203
bgp_config.router_id.map(|v| v.to_string())
195204
);
196205
let Some(af_ipv4unicast) = bgp_config.af_ipv4unicast else {

k8s-intf/src/bolero/gateway.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ impl TypeGenerator for LegalValue<GatewayAgentGateway> {
4040
interfaces: Some(interfaces).filter(|i| !i.is_empty()),
4141
neighbors: Some(neighbors).filter(|n| !n.is_empty()),
4242
profiling: None, // FIXME(manishv) Add a proper implementation
43-
protocol_ip: Some(d.produce::<UnicastIpv4Addr>()?.to_string()),
43+
protocol_ip: Some(format!(
44+
"{}/{}",
45+
d.produce::<UnicastIpv4Addr>()?,
46+
d.gen_u8(Bound::Included(&0), Bound::Included(&32))?
47+
)),
4448
vtep_ip: Some(format!(
4549
"{}/{}",
4650
d.produce::<UnicastIpv4Addr>()?,

0 commit comments

Comments
 (0)