Skip to content

Conversation

daniel-noland
Copy link
Collaborator

@daniel-noland daniel-noland commented Sep 29, 2025

Long overdue tech debt payment

@daniel-noland daniel-noland force-pushed the pr/daniel-noland/interface-index branch 3 times, most recently from cc0715a to ff003df Compare September 29, 2025 22:46
@daniel-noland daniel-noland changed the title scratch Refactor InterfaceIndex type Sep 29, 2025
@daniel-noland daniel-noland self-assigned this Sep 29, 2025
@daniel-noland daniel-noland added the clean-up Code base clean-up, no functional change label Sep 29, 2025
@daniel-noland daniel-noland marked this pull request as ready for review September 29, 2025 22:48
@daniel-noland daniel-noland requested a review from a team as a code owner September 29, 2025 22:48
@daniel-noland daniel-noland requested review from sergeymatov and removed request for a team September 29, 2025 22:48
@daniel-noland daniel-noland mentioned this pull request Sep 30, 2025
Ok(ifindex) => ifindex,
Err(err) => {
let msg = format!("{err}");
error!("{err}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want some more context here about where this error is coming from rather than just emiiting the err message?

if interface.name == name {
InterfaceIndex::try_new(interface.index)
.map_err(|e| error!("{e}"))
.ok()
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this now need to really return a Result<Option<InterfaceIndex>>? It should really never be the case that something is in the list of interfaces but its index is invalid right? And so shouldn't we single out that case? If that is too cumbersome, I suppose the error! will have to suffice. However, do we want some context in the text as to where this error happened instead of blindly logging e?

@qmonnet qmonnet requested a review from Copilot September 30, 2025 11:32
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the InterfaceIndex type from a basic u32 alias (IfIndex) to a proper type wrapper (net::interface::InterfaceIndex). This change improves type safety by ensuring interface indices cannot be zero and provides better validation through the try_new() constructor.

  • Replaces IfIndex alias with proper InterfaceIndex type throughout the codebase
  • Adds validation to prevent zero interface indices via InterfaceIndex::try_new()
  • Updates all interface-related APIs to use the new type

Reviewed Changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
routing/src/rpc_adapt.rs Updates RouteNhop conversion to validate interface indices and remove zero-index handling
routing/src/rib/vrftable.rs Updates tests and VRF operations to use InterfaceIndex type
routing/src/rib/vrf.rs Updates next-hop building functions to use InterfaceIndex
routing/src/rib/rib2fib.rs Updates packet instruction building to use InterfaceIndex
routing/src/rib/nexthop.rs Changes NhopKey to use InterfaceIndex instead of u32
routing/src/interfaces/ Updates interface table and management APIs to use InterfaceIndex
routing/src/fib/fibobjects.rs Updates egress objects to use InterfaceIndex
routing/src/errors.rs Updates error types to use InterfaceIndex
routing/src/cpi.rs Adds validation for interface indices in RPC operations
routing/src/config/ Updates configuration handling to use InterfaceIndex
routing/src/atable/ Updates adjacency table to use InterfaceIndex
net/src/packet/ Updates packet metadata to use InterfaceIndex
mgmt/src/processor/confbuild/router.rs Adds validation when building router interface configs
dataplane/src/packet_processor/ Updates packet processing to use InterfaceIndex
dataplane/src/drivers/kernel.rs Updates kernel driver to use InterfaceIndex
config/src/errors.rs Adds Invalid configuration error variant

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@mvachhar mvachhar requested a review from Copilot September 30, 2025 14:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

instructions.push(PktInstruction::Local(
self.key
.ifindex
.unwrap_or(InterfaceIndex::try_new(1).unwrap_or_else(|_| unreachable!())),
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

The nested unwrap_or_else with unreachable! is confusing. If InterfaceIndex::try_new(1) can never fail, use unwrap() directly. If it can fail, handle the error properly.

Suggested change
.unwrap_or(InterfaceIndex::try_new(1).unwrap_or_else(|_| unreachable!())),
.unwrap_or(InterfaceIndex::try_new(1).unwrap()),

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the intent here is to signal that the error branch is genuinely unreachable.

I think this is ok (if verbose)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that said, I do have a better option here: drop if there is no target interface for the packet. It makes no sense to locally deliver a packet when you don't know where it should be delivered to.

@daniel-noland daniel-noland force-pushed the pr/daniel-noland/interface-index branch 2 times, most recently from 327fe7d to a4b5313 Compare September 30, 2025 20:04
@daniel-noland daniel-noland force-pushed the pr/daniel-noland/interface-index branch from a4b5313 to 11b6a0b Compare September 30, 2025 20:53
Copy link
Contributor

@mvachhar mvachhar left a comment

Choose a reason for hiding this comment

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

Looks good but you have a commit lint error.

Early on in the project we ended up with multiple interface index types.

This can be extremely confusing in the context of DPDK.
Worse, the longer we wait, the more instances of each of these types we end up with.

Time to fix this.

Signed-off-by: Daniel Noland <[email protected]>
Signed-off-by: Daniel Noland <[email protected]>
Hopefully this makes trace logs a little easier to reason about.

Signed-off-by: Daniel Noland <[email protected]>
We just don't need to clone here.

Signed-off-by: Daniel Noland <[email protected]>
@daniel-noland daniel-noland force-pushed the pr/daniel-noland/interface-index branch from 11b6a0b to f6d1797 Compare October 2, 2025 01:34
@daniel-noland daniel-noland added this pull request to the merge queue Oct 2, 2025
Merged via the queue into main with commit ebdcf92 Oct 2, 2025
19 checks passed
@daniel-noland daniel-noland deleted the pr/daniel-noland/interface-index branch October 2, 2025 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clean-up Code base clean-up, no functional change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants