Skip to content

Commit

Permalink
Added caps term for peer config - to specify starting advertised capa…
Browse files Browse the repository at this point in the history
…bility set

Docs updates
  • Loading branch information
wladwm committed Dec 18, 2023
1 parent 3c8d1dd commit 94214ef
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 0.3.4 (2023-12-18)

#### Features
* zettabgp 0.3.4 with support EVPN5 routes
* protocol session state expose via API

### 0.3.3 (2022-01-17)

#### Features
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bgpexplorer"
version = "0.3.3"
version = "0.3.4"
authors = ["Vladimir Melnikov <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ Main section parameters:

Service section parameters:
* mode - protocol mode, can be bgpactive,bgppassive,bmpactive or bmppassive. bgp or bmp means protocol, active or passive determines which side will initiate session.
* bgppeer - bgp peer address for bgp active mode. Can be just IP address or IP:port. bgpexplorer will attempt to connect to specified BGP speaker.
* bmppeer - bmp peer address for bgp active mode. Can be IP:port or just IP address - then default port 632 will be used. bgpexplorer will attempt to connect to specified BMP-capable router.
* peer - bgp/bmp peer address for active mode. Can be just IP address or IP:port. bgpexplorer will attempt to connect to specified BGP speaker. Default port is 179 for BGP and 632 for BMP.
* protolisten - TCP endpoint for bgp/bmp passived mode. Should be IP:port form. Please note that you will not be able to run process listening port number below 1024 in *nix OS if you are not root without special tricks.
* routerid - BGP router ID, if not specified, default value 1.1.1.1 will be used.
* peeras - BGP AS number for bgpactive.
* caps - comma-separated list capabilities to advertise. May be "min" for minimal set, "all" for maximum set, and set of specific values: ipv4u,ipv4lu,vpnv4u,vpnv4m,ipv4mdt,mvpn,vpls,evpn,asn32,ipv6u,ipv6lu,vpnv6u,vpnv6m,ipv6mdt,addpath
* filter_rd - With BMP session this parametr will filter watching BGP session matching this RD. Default is 0:0 (global vrf).

BTW, builtin whois proxy allows you to see some info about AS and hosts:
Expand Down
2 changes: 1 addition & 1 deletion src/bgpsvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl BgpSvr {
BgpTransportMode::IPv6
},
fpeer.routerid,
ProtoPeer::def_caps(fpeer.bgppeeras),
ProtoPeer::all_caps(fpeer.bgppeeras),
),
client.0,
&*self,
Expand Down
80 changes: 78 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct ProtoPeer {
pub bgppeeras: u32,
pub flt_rd: Option<zettabgp::afi::BgpRD>,
pub bgpsessionparams: Arc<std::sync::Mutex<Option<BgpSessionParams>>>,
pub caps: Vec<BgpCapability>,
}
impl PartialEq for ProtoPeer {
fn eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -185,6 +186,70 @@ impl ProtoPeer {
} else {
Some(zettabgp::afi::BgpRD::new(0, 0))
};
let caps: Vec<BgpCapability> = if svcsection.contains_key("caps") {
match svcsection["caps"]
.as_ref()
.map(|s| s.as_str())
.unwrap_or("")
{
"all" => Self::all_caps(0),
"" | "min" | "minimal" => {
vec![
if peer.is_some() && peer.as_ref().unwrap().is_ipv6() {
BgpCapability::SafiIPv6u
} else {
BgpCapability::SafiIPv4u
},
BgpCapability::CapASN32(0),
]
}
capsstr => {
let mut caps = Vec::new();
let cps = capsstr.split(",");
let mut addpath = false;
for cs in cps {
match cs {
"ipv4u" => caps.push(BgpCapability::SafiIPv4u),
"ipv4lu" => caps.push(BgpCapability::SafiIPv4lu),
"vpnv4u" => caps.push(BgpCapability::SafiVPNv4u),
"vpnv4m" => caps.push(BgpCapability::SafiVPNv4m),
"ipv4mdt" => caps.push(BgpCapability::SafiIPv4mdt),
"mvpn" => caps.push(BgpCapability::SafiIPv4mvpn),
"vpls" => caps.push(BgpCapability::SafiVPLS),
"evpn" => caps.push(BgpCapability::SafiEVPN),
"asn32" => caps.push(BgpCapability::CapASN32(0)),
"ipv6u" => caps.push(BgpCapability::SafiIPv6u),
"ipv6lu" => caps.push(BgpCapability::SafiIPv6lu),
"vpnv6u" => caps.push(BgpCapability::SafiVPNv6u),
"vpnv6m" => caps.push(BgpCapability::SafiVPNv6m),
"ipv6mdt" => caps.push(BgpCapability::SafiIPv6mdt),
"addpath" => addpath = true,
x => warn!("Unknown capability code: {}", x),
}
}
if addpath {
let mut vap = Vec::new();
for cp in caps.iter() {
match cp {
BgpCapability::SafiIPv4u => vap.push(
BgpCapAddPath::new_from_cap(
BgpCapability::SafiIPv4u,
true,
true,
)
.unwrap(),
),
_ => {}
}
}
caps.push(BgpCapability::CapAddPath(vap));
}
caps
}
}
} else {
Self::all_caps(0)
};
Ok(ProtoPeer {
routerid,
mode: peermode,
Expand All @@ -193,12 +258,13 @@ impl ProtoPeer {
bgppeeras,
flt_rd,
bgpsessionparams: Arc::new(std::sync::Mutex::new(None)),
caps,
})
}
pub fn set_session_params(&self, params: BgpSessionParams) {
*(self.bgpsessionparams.lock().unwrap()) = Some(params);
}
pub fn def_caps(asn: u32) -> Vec<BgpCapability> {
pub fn all_caps(asn: u32) -> Vec<BgpCapability> {
vec![
BgpCapability::SafiIPv4u,
BgpCapability::SafiIPv4fu,
Expand Down Expand Up @@ -227,6 +293,16 @@ impl ProtoPeer {
]),
]
}
pub fn def_caps(&self, asn: u32) -> Vec<BgpCapability> {
let mut ret = Vec::new();
for c in self.caps.iter() {
match c {
BgpCapability::CapASN32(_) => ret.push(BgpCapability::CapASN32(asn)),
x => ret.push(x.clone()),
}
}
ret
}
pub fn get_session_params(&self) -> BgpSessionParams {
let mut lck = self.bgpsessionparams.lock().unwrap();
if let Some(p) = lck.as_ref() {
Expand All @@ -244,7 +320,7 @@ impl ProtoPeer {
180,
peeraddrmode,
self.routerid,
Self::def_caps(self.bgppeeras),
self.def_caps(self.bgppeeras),
);
*lck = Some(pbsp.clone());
pbsp
Expand Down

0 comments on commit 94214ef

Please sign in to comment.