Skip to content

Commit c423402

Browse files
committed
add pending neighbor status command
1 parent d133492 commit c423402

8 files changed

Lines changed: 130 additions & 10 deletions

File tree

bgp/src/params.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rdb::{ImportExportPolicy, PolicyAction, Prefix4, Prefix6};
88
use schemars::JsonSchema;
99
use serde::{Deserialize, Serialize};
1010
use std::collections::HashMap;
11-
use std::net::SocketAddrV6;
11+
use std::net::{Ipv6Addr, SocketAddrV6};
1212
use std::time::Duration;
1313
use std::{
1414
collections::BTreeMap,
@@ -57,6 +57,12 @@ pub struct UnnumberedNeighbor {
5757
pub parameters: BgpPeerParameters,
5858
}
5959

60+
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone, PartialEq)]
61+
pub struct PendingUnnumberedNeighbor {
62+
pub interface: String,
63+
pub local_addr: Ipv6Addr,
64+
}
65+
6066
impl From<Neighbor> for PeerConfig {
6167
fn from(rq: Neighbor) -> Self {
6268
Self {

mg-api/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use bfd::BfdPeerState;
1212
use bgp::{
1313
params::{
1414
ApplyRequest, CheckerSource, Neighbor, NeighborResetOp, Origin4,
15-
Origin6, PeerInfo, PeerInfoV1, Router, ShaperSource,
16-
UnnumberedNeighbor,
15+
Origin6, PeerInfo, PeerInfoV1, PendingUnnumberedNeighbor, Router,
16+
ShaperSource, UnnumberedNeighbor,
1717
},
1818
session::{FsmEventRecord, MessageHistory, MessageHistoryV1},
1919
};
@@ -154,6 +154,16 @@ pub trait MgAdminApi {
154154

155155
// Unnumbered neighbors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156156

157+
#[endpoint {
158+
method = GET,
159+
path = "/bgp/config/unnumbered-pending",
160+
versions = VERSION_UNNUMBERED..,
161+
}]
162+
async fn read_pending_unnumbered_neighbors(
163+
rqctx: RequestContext<Self::Context>,
164+
request: Query<AsnSelector>,
165+
) -> Result<HttpResponseOk<Vec<PendingUnnumberedNeighbor>>, HttpError>;
166+
157167
#[endpoint {
158168
method = GET,
159169
path = "/bgp/config/unnumbered-neighbors",

mgadm/src/bgp.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ pub enum StatusCmd {
7575
asn: u32,
7676
},
7777

78+
PendingNeighbors {
79+
#[clap(env)]
80+
asn: u32,
81+
},
82+
7883
/// Get the prefixes exported by a BGP router.
7984
Exported {
8085
#[clap(env)]
@@ -806,6 +811,9 @@ pub async fn commands(command: Commands, c: Client) -> Result<()> {
806811

807812
Commands::Status(cmd) => match cmd.command {
808813
StatusCmd::Neighbors { asn } => get_neighbors(c, asn).await?,
814+
StatusCmd::PendingNeighbors { asn } => {
815+
list_unnumbered_pending(asn, c).await?
816+
}
809817
StatusCmd::Exported { asn } => get_exported(c, asn).await?,
810818
},
811819

@@ -975,6 +983,12 @@ async fn delete_nbr(asn: u32, addr: IpAddr, c: Client) -> Result<()> {
975983
Ok(())
976984
}
977985

986+
async fn list_unnumbered_pending(asn: u32, c: Client) -> Result<()> {
987+
let pending = c.read_pending_unnumbered_neighbors(asn).await?;
988+
println!("{pending:#?}");
989+
Ok(())
990+
}
991+
978992
async fn list_unnumbered_nbr(asn: u32, c: Client) -> Result<()> {
979993
let nbrs = c.read_unnumbered_neighbors(asn).await?;
980994
println!("{nbrs:#?}");

mgd/src/admin.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ impl MgAdminApi for MgAdminApiImpl {
188188

189189
// Unnumbered neighbors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190190

191+
async fn read_pending_unnumbered_neighbors(
192+
rqctx: RequestContext<Self::Context>,
193+
request: Query<AsnSelector>,
194+
) -> Result<HttpResponseOk<Vec<PendingUnnumberedNeighbor>>, HttpError> {
195+
bgp_admin::read_pending_unnumbered_neighbors(rqctx, request).await
196+
}
197+
191198
async fn read_unnumbered_neighbors(
192199
rqctx: RequestContext<Self::Context>,
193200
request: Query<AsnSelector>,

mgd/src/bgp_admin.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,29 @@ pub async fn clear_neighbor(
257257

258258
// Unnumbered neighbors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259259

260+
pub async fn read_pending_unnumbered_neighbors(
261+
rqctx: RequestContext<Arc<HandlerContext>>,
262+
request: Query<AsnSelector>,
263+
) -> Result<HttpResponseOk<Vec<PendingUnnumberedNeighbor>>, HttpError> {
264+
let rq = request.into_inner();
265+
let ctx = rqctx.context();
266+
267+
let pending = ctx.bgp.unnumbered_manager.get_pending();
268+
let mut result = Vec::default();
269+
270+
for k in pending.keys() {
271+
if k.asn != rq.asn {
272+
continue;
273+
}
274+
result.push(PendingUnnumberedNeighbor {
275+
interface: k.interface.name.clone(),
276+
local_addr: k.interface.ip,
277+
});
278+
}
279+
280+
Ok(HttpResponseOk(result))
281+
}
282+
260283
pub async fn read_unnumbered_neighbors(
261284
rqctx: RequestContext<Arc<HandlerContext>>,
262285
request: Query<AsnSelector>,

mgd/src/unnumbered_manager.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ pub struct UnnumberedNeighborManager {
2828
}
2929

3030
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
31-
struct NbrKey {
32-
asn: u32,
33-
interface: Ipv6NetworkInterface,
31+
pub struct NbrKey {
32+
pub asn: u32,
33+
pub interface: Ipv6NetworkInterface,
3434
}
3535

3636
#[derive(Clone)]
37-
struct NbrInfo {
38-
nbr: UnnumberedNeighbor,
39-
session: SessionInfo,
37+
pub struct NbrInfo {
38+
pub nbr: UnnumberedNeighbor,
39+
pub session: SessionInfo,
4040
}
4141

4242
#[derive(Debug, thiserror::Error)]
@@ -195,6 +195,10 @@ impl UnnumberedNeighborManager {
195195
})
196196
}
197197

198+
pub fn get_pending(self: &Arc<Self>) -> HashMap<NbrKey, NbrInfo> {
199+
self.pending_sessions.lock().unwrap().clone()
200+
}
201+
198202
fn run(self: Arc<Self>, log: Logger) {
199203
const RUN_LOOP_INTERVAL: Duration = Duration::from_secs(1);
200204
loop {

openapi/mg-admin/mg-admin-3.0.0-8b08af.json renamed to openapi/mg-admin/mg-admin-3.0.0-c7526d.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,46 @@
10601060
}
10611061
}
10621062
},
1063+
"/bgp/config/unnumbered-pending": {
1064+
"get": {
1065+
"operationId": "read_pending_unnumbered_neighbors",
1066+
"parameters": [
1067+
{
1068+
"in": "query",
1069+
"name": "asn",
1070+
"description": "ASN of the router to get imported prefixes from.",
1071+
"required": true,
1072+
"schema": {
1073+
"type": "integer",
1074+
"format": "uint32",
1075+
"minimum": 0
1076+
}
1077+
}
1078+
],
1079+
"responses": {
1080+
"200": {
1081+
"description": "successful operation",
1082+
"content": {
1083+
"application/json": {
1084+
"schema": {
1085+
"title": "Array_of_PendingUnnumberedNeighbor",
1086+
"type": "array",
1087+
"items": {
1088+
"$ref": "#/components/schemas/PendingUnnumberedNeighbor"
1089+
}
1090+
}
1091+
}
1092+
}
1093+
},
1094+
"4XX": {
1095+
"$ref": "#/components/responses/Error"
1096+
},
1097+
"5XX": {
1098+
"$ref": "#/components/responses/Error"
1099+
}
1100+
}
1101+
}
1102+
},
10631103
"/bgp/history/fsm": {
10641104
"get": {
10651105
"operationId": "fsm_history",
@@ -3777,6 +3817,22 @@
37773817
"keepalive"
37783818
]
37793819
},
3820+
"PendingUnnumberedNeighbor": {
3821+
"type": "object",
3822+
"properties": {
3823+
"interface": {
3824+
"type": "string"
3825+
},
3826+
"local_addr": {
3827+
"type": "string",
3828+
"format": "ipv6"
3829+
}
3830+
},
3831+
"required": [
3832+
"interface",
3833+
"local_addr"
3834+
]
3835+
},
37803836
"Prefix": {
37813837
"oneOf": [
37823838
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mg-admin-3.0.0-8b08af.json
1+
mg-admin-3.0.0-c7526d.json

0 commit comments

Comments
 (0)