-
Notifications
You must be signed in to change notification settings - Fork 6
Interface-related type changes #1067
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
base: main
Are you sure you want to change the base?
Conversation
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]>
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]>
daniel-noland
left a comment
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three concerns
- why put this in the routing package? Doesn't this belong in net?
- Shouldn't this be an enum with two differently validated types? One for ipv4 and one for ipv6?
- 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> { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There are more changes to come that will be addressed in subsequent PRs.