Skip to content

Conversation

@Fredi-raspall
Copy link
Contributor

@Fredi-raspall Fredi-raspall commented Nov 21, 2025

There are more changes to come that will be addressed in subsequent PRs.

The prior code used a type alias IfAddress = (IpAddr,u8).
Instead, define a struct and add minimal validation.
The new struct is called IfAddr instead of IfAddress to avoid
confusion or the need to rename since the dplane-rpc has a type
with that name.

Signed-off-by: Fredi Raspall <[email protected]>
Change interfaces to use the SourceMac type to represent MACs.
This avoids, among others, needing to convert from Mac to SourceMac
for every packet that egresses the gateway.

Signed-off-by: Fredi Raspall <[email protected]>
@Fredi-raspall Fredi-raspall requested a review from a team as a code owner November 21, 2025 18:37
@Fredi-raspall Fredi-raspall requested review from daniel-noland and removed request for a team November 21, 2025 18:37
Copy link
Collaborator

@daniel-noland daniel-noland left a comment

Choose a reason for hiding this comment

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

Love the second two commits. The first commit only needs minor update. Thanks :D

/// An Ipv4 or Ipv6 address and mask configured on an interface
pub type IfAddress = (IpAddr, u8);
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub struct IfAddr {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Three concerns

  1. why put this in the routing package? Doesn't this belong in net?
  2. Shouldn't this be an enum with two differently validated types? One for ipv4 and one for ipv6?
  3. finally, the ip field should be scoped to unicast since you can't assign multicast addresses to interfaces (I suspect this will de-complicate downstream code as well)

impl IfAddr {
/// Associated function that checks if an address or its mask
/// are legal to be configured on a network interface.
fn is_valid_ifaddr(address: IpAddr, mask_len: u8) -> Result<(), RouterError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you have rustdoc on a private function which won't be shown to most users. Better to put this (reworded) on new

//////////////////////////////////////////////////////////////////
pub fn del_ifaddr(&mut self, ifaddr: &IfAddress) {
self.addresses.remove(ifaddr);
pub fn del_ifaddr(&mut self, ifaddr: IfAddr) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this observation is technically out of scope, but I don't see the point of hiding the return value here. Shouldn't we be able to detect that the address was in fact removed?

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.

3 participants