Skip to content

Commit

Permalink
bgp: enhance attribute handling prior to route advertisement
Browse files Browse the repository at this point in the history
* For internal peers, attach LOCAL_PREF with default value when it's
  missing.
* For external peers:
  - Do not propagate the MULTI_EXIT_DISC attribute.
  - Remove the LOCAL_PREF attribute.

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed Feb 21, 2024
1 parent d1f6c76 commit 6932977
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions holo-bgp/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,9 @@ where
}

if update {
// Prepend local AS number when advertising to eBGP
// neighbors.
// Update route's attributes before transmission.
let mut attrs = rpinfo.attrs;
if nbr.peer_type == PeerType::External {
attrs.base.as_path.prepend(instance.config.asn);
}

// Update the next-hop attribute if necessary.
A::nexthop_tx_change(nbr, &mut attrs.base);
attrs_tx_update::<A>(nbr, instance.config.asn, &mut attrs);

// Update neighbor's Tx queue.
let update_queue = A::update_queue(&mut nbr.update_queues);
Expand All @@ -554,6 +548,33 @@ where
Ok(())
}

fn attrs_tx_update<A>(nbr: &Neighbor, local_asn: u32, attrs: &mut Attrs)
where
A: AddressFamily,
{
match nbr.peer_type {
PeerType::Internal => {
// Attach LOCAL_PREF with default value if it's missing.
if attrs.base.local_pref.is_none() {
attrs.base.local_pref = Some(rib::DFLT_LOCAL_PREF);
}
}
PeerType::External => {
// Prepend local AS number.
attrs.base.as_path.prepend(local_asn);

// Do not propagate the MULTI_EXIT_DISC attribute.
attrs.base.med = None;

// Remove the LOCAL_PREF attribute.
attrs.base.local_pref = None;
}
}

// Update the next-hop attribute based on the address family if necessary.
A::nexthop_tx_change(nbr, &mut attrs.base);
}

// ===== BGP decision process =====

pub(crate) fn decision_process<A>(
Expand Down

0 comments on commit 6932977

Please sign in to comment.