Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions crates/analytics/src/aggregation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2025-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -143,8 +144,9 @@ impl<Key: Eq + Hash + Clone, AggInit: Clone, AggregatorImpl>
*current_time = (*current_time).max(ts);
let window_start = get_window_start(ts);
let active_windows = self.active_windows.entry(key).or_default();
// Aggregates the value in the current window (or create new one if needed)

// Aggregates the value in the current window
// (or create a new one if needed)
active_windows
.entry(window_start)
.or_insert_with(|| AggregatorImpl::init(self.agg_init.clone()))
Expand Down Expand Up @@ -583,8 +585,9 @@ mod tests {
(),
);
let (items, expected_results) = get_test_input();
// Note this doesn't include the final event since the window doesn't close
// without a new event with a timestamp greater than the current time + lateness
// Note this doesn't include the final event since the window
// doesn't close without a new event with a timestamp greater
// than the current time + lateness
let expected_on_time: Vec<_> = expected_results[0..expected_results.len() - 1]
.iter()
.cloned()
Expand Down
4 changes: 3 additions & 1 deletion crates/bgp-pkt/src/codec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2023-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -98,7 +99,8 @@ impl Decoder for BgpCodec {
if enabled!(Level::TRACE) {
trace!(buffer=?buf, length=buf.len(), "decoding buffered message")
}
// ASN4 capability is used only when both peers agree on enabling ASN4
// ASN4 capability is used only when both peers
// agree on enabling ASN4
let asn4 = self.asn4_received.unwrap_or(false) && self.asn4_sent.unwrap_or(false);
self.ctx.set_asn4(asn4);
let ret = BgpMessage::from_wire(Span::new(buf), &mut self.ctx);
Expand Down
9 changes: 5 additions & 4 deletions crates/bgp-pkt/src/nlri/nlri.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2022-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -1252,8 +1253,8 @@ impl Ipv4NlriMplsLabelsAddress {
labels: Vec<MplsLabel>,
prefix: Ipv4Net,
) -> Result<Self, InvalidIpv4NlriMplsLabelsAddress> {
// Total length should not exceed 255, each MPLS Label is 24 bit and account for
// 32 bit IP prefix length
// Total length should not exceed 255, each MPLS Label is 24 bit
// and account for 32 bit IP prefix length
if labels.len() * 24 + prefix.prefix_len() as usize > u8::MAX as usize {
Err(InvalidIpv4NlriMplsLabelsAddress::InvalidLabelsLength(
labels.len(),
Expand Down Expand Up @@ -1349,8 +1350,8 @@ impl Ipv6NlriMplsLabelsAddress {
labels: Vec<MplsLabel>,
prefix: Ipv6Net,
) -> Result<Self, InvalidIpv6NlriMplsLabelsAddress> {
// Total length should not exceed 255, each MPLS Label is 24 bit and account for
// 32 bit IP prefix length
// Total length should not exceed 255, each MPLS Label is 24 bit
// and account for 32 bit IP prefix length
if labels.len() * 24 + prefix.prefix_len() as usize > u8::MAX as usize {
Err(InvalidIpv6NlriMplsLabelsAddress::InvalidLabelsLength(
labels.len(),
Expand Down
9 changes: 5 additions & 4 deletions crates/bgp-pkt/src/update.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2022-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -100,8 +101,8 @@ impl BgpUpdateMessage {
if let PathAttributeValue::MpUnreach(unreach) = attr.value() {
mp_unreach_count += 1;
if mp_unreach_count > 1 {
// Only one MpUnreach is used to indicate End-of-RIB (EoR), more than one
// MpUnreach attribute doesn't define EoR.
// Only one MpUnreach is used to indicate End-of-RIB (EoR),
// more than one MpUnreach attribute doesn't define EoR.
return None;
}
match unreach {
Expand Down Expand Up @@ -166,8 +167,8 @@ impl BgpUpdateMessage {
}
}
MpUnreach::Unknown { .. } => {
// For unknown address families we assume it's not EoR, as they might have
// different semantics defined.
// For unknown address families we assume it's not EoR,
// as they might have different semantics defined.
current = None;
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/bgp-pkt/src/wire/deserializer/capabilities.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2022-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -245,7 +246,8 @@ impl<'a> ReadablePdu<'a, LocatedBgpCapabilityParsingError<'a>> for BgpCapability
error:
BgpCapabilityParsingError::UndefinedCapabilityCode(UndefinedBgpCapabilityCode(_)),
})) => {
// Parse code again, since nom won't advance the buffer on map_res error
// Parse code again, since nom won't advance the buffer
// on map_res error
let (buf, code) = be_u8(buf)?;
parse_unrecognized_capability(code, buf)
}
Expand Down
17 changes: 9 additions & 8 deletions crates/bgp-pkt/src/wire/deserializer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2022-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -241,8 +242,8 @@ impl<'a> ReadablePduWithTwoInputs<'a, u8, Span<'a>, LocatedIpv4PrefixParsingErro
prefix_len: u8,
prefix_location: Span<'a>,
) -> IResult<Span<'a>, Self, LocatedIpv4PrefixParsingError<'a>> {
// The prefix value must fall into the octet boundary, even if the prefix_len
// doesn't. For example,
// The prefix value must fall into the octet boundary,
// even if the prefix_len doesn't. For example,
// prefix_len=24 => prefix_size=24 while prefix_len=19 => prefix_size=24
let prefix_size = if prefix_len >= u8::MAX - 7 {
u8::MAX
Expand Down Expand Up @@ -290,8 +291,8 @@ impl<'a> ReadablePduWithTwoInputs<'a, u8, Span<'a>, LocatedIpv6PrefixParsingErro
prefix_len: u8,
prefix_location: Span<'a>,
) -> IResult<Span<'a>, Self, LocatedIpv6PrefixParsingError<'a>> {
// The prefix value must fall into the octet boundary, even if the prefix_len
// doesn't. For example,
// The prefix value must fall into the octet boundary,
// even if the prefix_len doesn't. For example,
// prefix_len=24 => prefix_size=24 while prefix_len=19 => prefix_size=24
let prefix_size = if prefix_len >= u8::MAX - 7 {
u8::MAX
Expand Down Expand Up @@ -510,8 +511,8 @@ impl<'a> ReadablePduWithOneInput<'a, &mut BgpParsingContext, LocatedBgpMessagePa
}
})(buf)?;

// Parse both length and type together, since we need to do input validation on
// the length based on the type of the message
// Parse both length and type together, since we need to do input
// validation on the length based on the type of the message
let (buf, (_, message_type, remainder_buf)) = match parse_bgp_message_length_and_type(buf) {
Ok(value) => value,
Err(err) => return Err(into_located_bgp_message_parsing_error(err)),
Expand Down Expand Up @@ -580,8 +581,8 @@ impl From<BgpMessageParsingError> for BgpNotificationMessage {
BgpNotificationMessage::UpdateMessageError(update_err.into())
}
BgpMessageParsingError::BgpNotificationMessageParsingError(_notification) => {
// Notification messages parsing should be ignored and consider a session
// closed.
// Notification messages parsing should be ignored
// and consider a session closed.
BgpNotificationMessage::FiniteStateMachineError(
FiniteStateMachineError::Unspecific { value: vec![] },
)
Expand Down
9 changes: 5 additions & 4 deletions crates/bgp-pkt/src/wire/deserializer/nlri/nlri.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2022-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -210,8 +211,8 @@ impl<'a>
} else {
prefix_len.div_ceil(8)
};
// consuming only the bytes specified by the prefix length field, since MPLS
// stack is read until the last bit is set.
// consuming only the bytes specified by the prefix length field,
// since MPLS stack is read until the last bit is set.
let (buf, prefix_buf) = nom::bytes::complete::take(prefix_bytes)(buf)?;
let (prefix_buf, label_stack) =
parse_mpls_label_stack(prefix_buf, is_unreach, multiple_labels_limit).map_err(
Expand Down Expand Up @@ -286,8 +287,8 @@ impl<'a>
} else {
prefix_len.div_ceil(8)
};
// consuming only the bytes specified by the prefix length field, since MPLS
// stack is read until the last bit is set.
// consuming only the bytes specified by the prefix length field,
// since MPLS stack is read until the last bit is set.
let (buf, prefix_buf) = nom::bytes::complete::take(prefix_bytes)(buf)?;
let (prefix_buf, label_stack) =
parse_mpls_label_stack(prefix_buf, is_unreach, multiple_labels_limit).map_err(
Expand Down
41 changes: 22 additions & 19 deletions crates/bgp-pkt/src/wire/deserializer/open.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2022-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -76,10 +77,10 @@ impl<'a> ReadablePduWithOneInput<'a, &mut BgpParsingContext, LocatedBgpOpenMessa
let (buf, my_as) = be_u16(buf)?;
let begin_buf = buf;
let (buf, hold_time) = be_u16(buf)?;
// RFC 4271: If the Hold Time field of the OPEN message is unacceptable, then
// the Error Subcode MUST be set to Unacceptable Hold Time. An implementation
// MUST reject Hold Time values of one or two seconds. An implementation MAY
// reject any proposed Hold Time.
// RFC 4271: If the Hold Time field of the OPEN message is unacceptable,
// then the Error Subcode MUST be set to Unacceptable Hold Time.
// An implementation MUST reject Hold Time values of one or two seconds.
// An implementation MAY reject any proposed Hold Time.
if hold_time == 1 || hold_time == 2 {
return Err(nom::Err::Error(LocatedBgpOpenMessageParsingError::new(
begin_buf,
Expand All @@ -89,11 +90,11 @@ impl<'a> ReadablePduWithOneInput<'a, &mut BgpParsingContext, LocatedBgpOpenMessa
let (buf, bgp_id) = be_u32(buf)?;
let begin_buf = buf;
let bgp_id = Ipv4Addr::from(bgp_id);
// RFC 4271: If the BGP Identifier field of the OPEN message is syntactically
// incorrect, then the Error Subcode MUST be set to Bad BGP Identifier.
// Syntactic correctness means that the BGP Identifier field represents
// a valid unicast IP host address. NOTE: not all BGP implementation
// check for syntactic correctness
// RFC 4271: If the BGP Identifier field of the OPEN message is
// syntactically incorrect, then the Error Subcode MUST be set to
// Bad BGP Identifier. Syntactic correctness means that the BGP
// Identifier field represents a valid unicast IP host address.
// NOTE: not all BGP implementation check for syntactic correctness
if bgp_id.is_broadcast() || bgp_id.is_multicast() || bgp_id.is_unspecified() {
return Err(nom::Err::Error(LocatedBgpOpenMessageParsingError::new(
begin_buf,
Expand Down Expand Up @@ -155,11 +156,12 @@ fn parse_capability_param<'a>(
nom::Err::Incomplete(needed) => Err(nom::Err::Incomplete(needed))?,
nom::Err::Error(err) => {
if !ctx.fail_on_capability_error {
// Advance the parser and ignore malformed capability
// RFC 5492 defines that a BGP speaker should ignore capabilities it
// does not understand and not report any error.
// It will only report a notification if the capability is
// understood but not supported by the speaker
// Advance the parser and ignore malformed
// capability. RFC 5492 defines that a BGP speaker
// should ignore capabilities it does not understand
// and not report any error. It will only report
// a notification if the capability is understood
// but not supported by the speaker.
let (tmp, _code) = be_u8(capabilities_buf)?;
let (tmp, _value) = nom::multi::length_count(be_u8, be_u8)(tmp)?;
capabilities_buf = tmp;
Expand All @@ -172,11 +174,12 @@ fn parse_capability_param<'a>(
}
nom::Err::Failure(failure) => {
if !ctx.fail_on_capability_error {
// Advance the parser and ignore malformed capability
// RFC 5492 defines that a BGP speaker should ignore capabilities it
// does not understand and not report any error.
// It will only report a notification if the capability is
// understood but not supported by the speaker
// Advance the parser and ignore malformed
// capability. RFC 5492 defines that a BGP speaker
// should ignore capabilities it does not understand
// and not report any error. It will only report
// a notification if the capability is understood
// but not supported by the speaker.
let (tmp, _code) = be_u8(capabilities_buf)?;
let (tmp, _value) = nom::multi::length_count(be_u8, be_u8)(tmp)?;
capabilities_buf = tmp;
Expand Down
14 changes: 8 additions & 6 deletions crates/bgp-pkt/src/wire/deserializer/route_refresh.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2022-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -69,12 +70,13 @@ impl<'a> ReadablePdu<'a, LocatedBgpRouteRefreshMessageParsingError<'a>> for BgpR
impl From<BgpRouteRefreshMessageParsingError> for RouteRefreshError {
fn from(_value: BgpRouteRefreshMessageParsingError) -> Self {
// Mapping all RouteRefresh errors to invalid length
// TODO implement RFC 7313 error handling: If the length, excluding the
// fixed-size message header, of the received ROUTE-REFRESH message with Message
// Subtype 1 and 2 is not 4, then the BGP speaker MUST send a NOTIFICATION
// message with the Error Code of "ROUTE-REFRESH Message Error" and the subcode
// of "Invalid Message Length". The Data field of the NOTIFICATION message MUST
// ontain the complete ROUTE-REFRESH message.
// TODO implement RFC 7313 error handling: If the length, excluding
// the fixed-size message header, of the received ROUTE-REFRESH message
// with Message Subtype 1 and 2 is not 4, then the BGP speaker MUST
// send a NOTIFICATION message with the Error Code of "ROUTE-REFRESH
// Message Error" and the subcode of "Invalid Message Length".
// The Data field of the NOTIFICATION message MUST contain the complete
// ROUTE-REFRESH message.
RouteRefreshError::InvalidMessageLength { value: vec![] }
}
}
29 changes: 16 additions & 13 deletions crates/bgp-pkt/src/wire/deserializer/update.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2022-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -77,9 +78,10 @@ fn parse_nlri<'a>(
nlri_vec.push(address);
}
Err(err) => {
// RFC 4271: If a prefix in the NLRI field is semantically incorrect (e.g., an
// unexpected multicast IP address), an error SHOULD be logged locally, and the
// prefix SHOULD be ignored.
// RFC 4271: If a prefix in the NLRI field is semantically
// incorrect (e.g., an unexpected multicast IP address),
// an error SHOULD be logged locally, and the prefix SHOULD
// be ignored.
if is_update && ctx.fail_on_non_unicast_update_nlri {
ctx.parsing_errors.non_unicast_update_nlri.push(ipv4_net);
}
Expand Down Expand Up @@ -296,11 +298,12 @@ fn handle_path_error<'a>(

impl From<BgpUpdateMessageParsingError> for UpdateMessageError {
fn from(value: BgpUpdateMessageParsingError) -> Self {
// For EoF errors we follow: RFC 4271 Error checking of an UPDATE message begins
// by examining the path attributes. If the Withdrawn Routes Length or
// Total Attribute Length is too large (i.e., if Withdrawn Routes Length
// + Total Attribute Length + 23 exceeds the message Length), then the
// Error Subcode MUST be set to Malformed Attribute List.
// For EoF errors we follow: RFC 4271 Error checking of an UPDATE
// message begins by examining the path attributes. If the
// Withdrawn Routes Length or Total Attribute Length is too large
// (i.e., if Withdrawn Routes Length + Total Attribute Length + 23
// exceeds the message Length), then the Error Subcode MUST be set
// to Malformed Attribute List.
match value {
BgpUpdateMessageParsingError::NomError(err) => {
if err == nom::error::ErrorKind::Eof {
Expand Down Expand Up @@ -396,11 +399,11 @@ impl From<BgpUpdateMessageParsingError> for UpdateMessageError {
UpdateMessageError::InvalidNetworkField { value: vec![] }
}
BgpUpdateMessageParsingError::InvalidIpv4UnicastNetwork(_) => {
// RFC 4271: If a prefix in the NLRI field is semantically incorrect (e.g., an
// unexpected multicast IP address), an error SHOULD be logged locally, and the
// prefix SHOULD be ignored.
// If parser is configured to be strict and this error triggered, then report
// Unspecific error
// RFC 4271: If a prefix in the NLRI field is semantically
// incorrect (e.g., an unexpected multicast IP address),
// an error SHOULD be logged locally, and the prefix SHOULD
// be ignored. If parser is configured to be strict and this
// error triggered, then report Unspecific error.
UpdateMessageError::Unspecific { value: vec![] }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2026-present The NetCalyx Authors.
// Copyright (C) 2022-present The NetGauze Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -177,7 +178,8 @@ pub enum OriginWritingError {
}

impl WritablePduWithOneInput<bool, OriginWritingError> for Origin {
// One octet length (if extended is not enabled) and second for the origin value
// One octet length (if extended is not enabled)
// and second for the origin value
const BASE_LENGTH: usize = 2;

fn len(&self, extended_length: bool) -> usize {
Expand Down
Loading
Loading