Skip to content

Commit

Permalink
ospfv3: update interpretation of configured instance ID values
Browse files Browse the repository at this point in the history
In the last draft of the OSPF YANG module, the "instance-id" leaf had a
`"range "0 .. 31"` constraint, implying it was a relative instance ID,
and the actual instance ID had to be calculated based on RFC5838's
address-family instance ID ranges.

In the RFC update, the range was removed, so let's now interpret the
configured instance IDs as absolute values.

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed May 6, 2023
1 parent 974cb20 commit 504e1ed
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 36 deletions.
2 changes: 1 addition & 1 deletion holo-ospf/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ where
}

// OSPFv3: check for Instance ID mismatch.
V::validate_packet_instance_id(instance.state.af, iface, packet.hdr())?;
V::validate_packet_instance_id(iface, packet.hdr())?;

// Log received packet.
Debug::<V>::PacketRx(iface, &src, &dst, &packet).log();
Expand Down
1 change: 0 additions & 1 deletion holo-ospf/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ pub trait InterfaceVersion<V: Version> {

// Validate the Instance ID of the received packet (OSPFv3 only).
fn validate_packet_instance_id(
af: AddressFamily,
iface: &Interface<V>,
packet_hdr: &V::PacketHdr,
) -> Result<(), Error<V>>;
Expand Down
1 change: 0 additions & 1 deletion holo-ospf/src/ospfv2/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ impl InterfaceVersion<Self> for Ospfv2 {
}

fn validate_packet_instance_id(
_af: AddressFamily,
_iface: &Interface<Self>,
_packet_hdr: &ospfv2::packet::PacketHdr,
) -> Result<(), Error<Self>> {
Expand Down
1 change: 0 additions & 1 deletion holo-ospf/src/ospfv2/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ impl PacketHdrVersion<Ospfv2> for PacketHdr {
pkt_type: PacketType,
router_id: Ipv4Addr,
area_id: Ipv4Addr,
_af: AddressFamily,
_instance_id: Option<u8>,
) -> Self {
PacketHdr {
Expand Down
10 changes: 2 additions & 8 deletions holo-ospf/src/ospfv3/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ impl InterfaceVersion<Self> for Ospfv3 {
pkt_type: PacketType::Hello,
router_id: instance.state.router_id,
area_id: area.area_id,
instance_id: PacketHdr::instance_id(
instance.state.af,
iface.config.instance_id,
),
instance_id: iface.config.instance_id.unwrap_or(0),
};

Packet::Hello(Hello {
Expand Down Expand Up @@ -96,13 +93,10 @@ impl InterfaceVersion<Self> for Ospfv3 {
}

fn validate_packet_instance_id(
af: AddressFamily,
iface: &Interface<Self>,
packet_hdr: &ospfv3::packet::PacketHdr,
) -> Result<(), Error<Self>> {
let iface_instance_id =
PacketHdr::instance_id(af, iface.config.instance_id);

let iface_instance_id = iface.config.instance_id.unwrap_or(0);
if packet_hdr.instance_id != iface_instance_id {
return Err(Error::InstanceIdMismatch(
packet_hdr.instance_id,
Expand Down
17 changes: 1 addition & 16 deletions holo-ospf/src/ospfv3/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,6 @@ impl OptionsVersion<Ospfv3> for Options {
impl PacketHdr {
pub const VERSION: u8 = 3;
pub const CHECKSUM_OFFSET: i32 = 12;

// Calculate the effective interface Instance ID based on the configured
// address family and the Instance ID ranges specified by RFC 5838.
pub(crate) fn instance_id(
af: AddressFamily,
instance_id: Option<u8>,
) -> u8 {
let base_instance_id = match af {
AddressFamily::Ipv4 => 64,
AddressFamily::Ipv6 => 0,
};

base_instance_id + instance_id.unwrap_or(0)
}
}

impl PacketHdrVersion<Ospfv3> for PacketHdr {
Expand Down Expand Up @@ -350,14 +336,13 @@ impl PacketHdrVersion<Ospfv3> for PacketHdr {
pkt_type: PacketType,
router_id: Ipv4Addr,
area_id: Ipv4Addr,
af: AddressFamily,
instance_id: Option<u8>,
) -> Self {
PacketHdr {
pkt_type,
router_id,
area_id,
instance_id: Self::instance_id(af, instance_id),
instance_id: instance_id.unwrap_or(0),
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions holo-ospf/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ pub(crate) fn send_dbdesc<V>(
PacketType::DbDesc,
instance.state.router_id,
area.area_id,
instance.state.af,
iface.config.instance_id,
);
let packet = V::PacketDbDesc::generate(
Expand Down Expand Up @@ -137,7 +136,6 @@ pub(crate) fn send_lsreq<V>(
PacketType::LsRequest,
instance.state.router_id,
area.area_id,
instance.state.af,
iface.config.instance_id,
);
let entries = nbr.lists.ls_request_pending.keys().copied().collect();
Expand Down Expand Up @@ -168,7 +166,6 @@ pub(crate) fn rxmt_lsreq<V>(
PacketType::LsRequest,
instance.state.router_id,
area.area_id,
instance.state.af,
iface.config.instance_id,
);
let entries = nbr.lists.ls_request_pending.keys().copied().collect();
Expand Down Expand Up @@ -239,7 +236,6 @@ pub(crate) fn send_lsupd<V>(
PacketType::LsUpdate,
instance.state.router_id,
area.area_id,
instance.state.af,
iface.config.instance_id,
);
let packet = V::PacketLsUpdate::generate(pkt_hdr, lsas);
Expand Down Expand Up @@ -297,7 +293,6 @@ pub(crate) fn rxmt_lsupd<V>(
PacketType::LsUpdate,
instance.state.router_id,
area.area_id,
instance.state.af,
iface.config.instance_id,
);
let packet = V::PacketLsUpdate::generate(pkt_hdr, lsas);
Expand Down Expand Up @@ -327,7 +322,6 @@ pub(crate) fn send_lsack_direct<V>(
PacketType::LsAck,
instance.state.router_id,
area.area_id,
instance.state.af,
iface.config.instance_id,
);
let lsa_hdrs = vec![*lsa_hdr];
Expand Down Expand Up @@ -373,7 +367,6 @@ pub(crate) fn send_lsack_delayed<V>(
PacketType::LsAck,
instance.state.router_id,
area.area_id,
instance.state.af,
iface.config.instance_id,
);
let packet = V::PacketLsAck::generate(pkt_hdr, lsa_hdrs);
Expand Down
1 change: 0 additions & 1 deletion holo-ospf/src/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ where
pkt_type: PacketType,
router_id: Ipv4Addr,
area_id: Ipv4Addr,
af: AddressFamily,
instance_id: Option<u8>,
) -> Self;
}
Expand Down

0 comments on commit 504e1ed

Please sign in to comment.