Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ospf dynamic hostname #41

Merged
merged 8 commits into from
Jan 10, 2025
Merged

Conversation

fliqqs
Copy link
Member

@fliqqs fliqqs commented Jan 9, 2025

No description provided.

fliqqs added 7 commits January 9, 2025 11:30
reoriginate on ibus hostname change

rename to DynamicHostnameTlv

dont originate tlv unless host name present

Signed-off-by: fliqqs <[email protected]>
@fliqqs fliqqs requested a review from rwestphal January 9, 2025 03:01
Copy link
Member

@rwestphal rwestphal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Overall, this looks really good, it only needs a few touches here and there. Please see the inline review comments.

@@ -281,6 +282,12 @@ impl LsdbVersion<Self> for Ospfv3 {
}
}
}
LsaOriginateEvent::HostnameChange => {
// (Re)originate Router-LSA(s) in all areas.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should reoriginate Router Information LSAs here instead

@@ -81,6 +82,8 @@ bitflags! {
#[derive(Deserialize, Serialize)]
pub struct RouterInfoCapsTlv(RouterInfoCaps);

const MAX_HOSTNAME_LEN: usize = 255;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please make this an associated const within the TLV struct

pub(crate) fn encode(&self, buf: &mut BytesMut) {
let start_pos =
tlv_encode_start(buf, RouterInfoTlvType::DynamicHostname);
let mut hostname = self.hostname.clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could try something like this to avoid cloning the string:

        let hostname = self.hostname.as_bytes();
        let hostname_len = usize::min(hostname.len(), MAX_HOSTNAME_LEN);
        buf.put_slice(&hostname[..hostname_len]);

impl DynamicHostnameTlv {
pub(crate) fn decode(tlv_len: u16, buf: &mut Bytes) -> DecodeResult<Self> {
let mut hostname = String::new();
for _ in 0..tlv_len {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should validate the TLV length is within the 1..255 range

&lsa.body
{
if let Some(hostname_tlv) = router_info.info_hostname.as_ref() {
debug!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this and the other debug! call

@@ -346,6 +353,44 @@ impl LsdbVersion<Self> for Ospfv2 {
}
}
}

// examine for DynamicHostnameTlv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could try this to avoid the code duplication (area/AS scope):

        // Update hostname database.
        if let LsaBody::OpaqueArea(LsaOpaque::RouterInfo(router_info))
        | LsaBody::OpaqueAs(LsaOpaque::RouterInfo(router_info)) = &lsa.body
        {
            if let Some(hostname_tlv) = router_info.info_hostname.as_ref() {
                // Install or update hostname.
                instance
                    .state
                    .hostnames
                    .insert(lsa.hdr.adv_rtr, hostname_tlv.hostname.clone());
            } else {
                // Remove hostname if it exists.
                instance.state.hostnames.remove(&lsa.hdr.adv_rtr);
            }
        }

@@ -103,6 +103,8 @@ pub struct InstanceState<V: Version> {
pub gr_helper_count: usize,
// Authentication non-decreasing sequence number.
pub auth_seqno: Arc<AtomicU64>,
// Hostname cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing trailing dot for consistency with the other comments

@@ -597,6 +597,7 @@ static LSA2: Lazy<(Vec<u8>, Lsa<Ospfv2>)> = Lazy::new(|| {
)],
msds: None,
srms_pref: None,
info_hostname: Some(DynamicHostnameTlv::new("holo".to_owned())),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to update reference data (vector of bytes) for this test to pass

@@ -122,6 +122,8 @@ pub struct LsaRouterInfo {
pub srlb: Vec<SrLocalBlockTlv>,
pub msds: Option<MsdTlv>,
pub srms_pref: Option<SrmsPrefTlv>,
// #[serde(skip)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need #[serde(skip)] here otherwise some conformance tests will fail. This is a workaround for something that should be fixed in the test framework soonish.

Copy link
Member

@rwestphal rwestphal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fliqqs Thank you for the updates! Merging...

@rwestphal rwestphal merged commit 05b3b3f into holo-routing:master Jan 10, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants