Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions bfd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use anyhow::Result;
use mg_api_types::bfd::{BfdPeerState, SessionMode};
use mg_api_types::common::headers::Dscp;
use mg_common::thread::ManagedThread;
use slog::{Logger, warn};
use sm::StateMachine;
Expand Down Expand Up @@ -107,12 +108,14 @@ pub struct AddPeerRequest {
pub endpoint: BfdEndpoint,
pub egress_thread: Option<Arc<ManagedThread>>,
pub db: rdb::Db,
pub dscp: Dscp,
}

/// A session holds a BFD state machine for a particular peer.
pub struct Session {
pub sm: StateMachine,
pub mode: SessionMode,
pub dscp: Dscp,
pub counters: Arc<SessionCounters>,
/// Managed egress thread for UDP packet transmission. Stored here to
/// ensure automatic cleanup on drop — the ManagedThread's Drop impl
Expand All @@ -137,6 +140,7 @@ impl Session {
Ok(Session {
sm,
mode: rq.mode,
dscp: rq.dscp,
counters,
_egress_thread: rq.egress_thread,
})
Expand Down Expand Up @@ -314,6 +318,7 @@ mod test {
endpoint: a,
egress_thread: None,
db: db.db().clone(),
dscp: Dscp::CS6,
},
)?;
assert_eq!(daemon.peer_state(v4_addr), Some(BfdPeerState::Down));
Expand All @@ -330,6 +335,7 @@ mod test {
endpoint: a,
egress_thread: None,
db: db.db().clone(),
dscp: Dscp::CS6,
},
)?;
assert_eq!(daemon.peer_state(v6_addr), Some(BfdPeerState::Down));
Expand Down Expand Up @@ -368,6 +374,7 @@ mod test {
endpoint: a,
egress_thread: None,
db: db.db().clone(),
dscp: Dscp::CS6,
},
)?;
net.register(v4_addr2, b);
Expand All @@ -382,6 +389,7 @@ mod test {
endpoint: a,
egress_thread: None,
db: db.db().clone(),
dscp: Dscp::CS6,
},
)?;
net.register(v6_addr2, b);
Expand All @@ -398,6 +406,7 @@ mod test {
endpoint: a,
egress_thread: None,
db: db.db().clone(),
dscp: Dscp::CS6,
},
)?;
net.register(v4_addr1, b);
Expand All @@ -412,6 +421,7 @@ mod test {
endpoint: a,
egress_thread: None,
db: db.db().clone(),
dscp: Dscp::CS6,
},
)?;
net.register(v6_addr1, b);
Expand Down
2 changes: 2 additions & 0 deletions bgp/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl From<Neighbor> for PeerConfig {
connect_retry_jitter: _,
src_addr: _,
src_port: _,
dscp: _,
} = parameters;
Self {
name,
Expand Down Expand Up @@ -168,6 +169,7 @@ impl PeerConfig {
connect_retry_jitter: _,
src_addr: _,
src_port: _,
dscp: _,
} = parameters;
Self {
name,
Expand Down
24 changes: 16 additions & 8 deletions bgp/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
session::{FsmEvent, SessionInfo},
unnumbered::UnnumberedManager,
};
use mg_api_types::common::headers::Dscp;
use slog::Logger;
use std::{
net::{SocketAddr, ToSocketAddrs},
Expand Down Expand Up @@ -57,14 +58,6 @@ pub trait BgpListener<Cnx: BgpConnection> {
timeout: Duration,
) -> Result<Cnx, Error>;

/// Apply policy to an established connection. This is called by the
/// Dispatcher after accept() returns and session lookup is completed.
fn apply_policy(
conn: &Cnx,
min_ttl: Option<u8>,
md5_key: Option<String>,
) -> Result<(), Error>;

/// `SocketAddr` the listener is receiving connections on
fn bind_addr(&self) -> SocketAddr;
}
Expand Down Expand Up @@ -134,6 +127,21 @@ pub trait BgpConnection: Send + Sync + Sized {
/// Start the receive loop for this connection. This method is idempotent.
/// Returns Ok(()) upon successful start of recv loop, else Err.
fn start_recv_loop(self: &Arc<Self>) -> Result<(), Error>;

/// Update a socket option on a live connection. Used to apply
/// configuration changes (DSCP, TTL) without resetting the session.
fn update_socket_option(&self, option: &SocketOption) -> Result<(), Error>;

/// Apply MD5 authentication key to a live connection.
/// This is a no-op on platforms that don't support MD5 BGP auth.
fn apply_md5(&self, key: &str) -> Result<(), Error>;
}

/// A socket option that can be updated on a live BGP connection.
#[derive(Clone, Debug)]
pub enum SocketOption {
Dscp(Dscp),
MinTtl(Option<std::num::NonZeroU8>),
}

pub use mg_common::thread::{ManagedThread, ThreadState};
24 changes: 14 additions & 10 deletions bgp/src/connection_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
clock::ConnectionClock,
connection::{
BgpConnection, BgpConnector, BgpListener, ConnectionDirection,
ConnectionId, ThreadState,
ConnectionId, SocketOption, ThreadState,
},
error::Error,
log::{connection_log, connection_log_lite},
Expand Down Expand Up @@ -271,15 +271,6 @@ impl BgpListener<BgpConnectionChannel> for BgpListenerChannel {
))
}

fn apply_policy(
_conn: &BgpConnectionChannel,
_min_ttl: Option<u8>,
_md5_key: Option<String>,
) -> Result<(), Error> {
// Policy application is ignored for test connections
Ok(())
}

fn bind_addr(&self) -> SocketAddr {
self.bind_addr
}
Expand Down Expand Up @@ -378,6 +369,19 @@ impl BgpConnection for BgpConnectionChannel {

Ok(())
}

fn update_socket_option(
&self,
_option: &SocketOption,
) -> Result<(), Error> {
// Socket options are ignored for test connections
Ok(())
}

fn apply_md5(&self, _key: &str) -> Result<(), Error> {
// MD5 auth is ignored for test connections
Ok(())
}
}

impl BgpConnectionChannel {
Expand Down
Loading