-
Notifications
You must be signed in to change notification settings - Fork 5
Remove the use of the iptrie crate #693
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
Conversation
16c3b32
to
38382ae
Compare
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.
Pull Request Overview
This PR removes the use of the iptrie
crate and replaces it with a new lpm
package providing Prefix
and a TrieMap
trait. Key changes include:
- Introducing the
lpm
crate with prefix and trie implementations. - Swapping all
iptrie::map::RTrieMap
usages forPrefixMapTrieWithDefault
and updating lookup and length calls. - Updating imports across routing, NAT, and management modules to use
lpm::prefix
instead of the oldprefix
oriptrie
paths.
Reviewed Changes
Copilot reviewed 38 out of 39 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
routing/src/rpc_adapt.rs | Swapped crate::prefix::Prefix import for lpm::prefix::Prefix |
routing/src/rib/vrf.rs | Replaced RTrieMap with PrefixMapTrieWithDefault and updated initialization and LPM calls |
routing/src/lib.rs | Removed the now-obsolete prefix module export |
routing/src/fib/fibtype.rs | Updated FIB trie fields and lookups to use the new lpm trie API |
nat/src/stateless/... | Updated NAT prefix trie to use lpm::prefix and lpm::trie types |
mgmt/src/... | Updated management and GRPC converter modules to import from lpm |
lpm/src/... | Added full implementation of prefix and trie logic in the lpm crate |
Cargo.toml files | Added lpm as a workspace dependency and removed iptrie |
Comments suppressed due to low confidence (2)
routing/src/rib/vrf.rs:184
- Consider adding a unit test that verifies the default routes are properly initialized for both IPv4 and IPv6, and that lookups on an empty VRF do not panic.
unsafe { PrefixMapTrieWithDefault::with_capacity(Vrf::DEFAULT_IPV6_CAPACITY) };
mgmt/src/models/internal/natconfig/collapse.rs:64
- The original
break
in this exclusion case was correct: once an exclusion prefix removes a matching allowed prefix, you should stop processing further allowed prefixes for this exclusion and move to the next exclusion. Changing it tocontinue
alters that logic and may lead to incorrect results.
continue;
38382ae
to
25abe59
Compare
25abe59
to
323447b
Compare
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.
Looks good, thanks a lot for this work! Nice abstraction work for the trie map.
I've got some comments (see inline), but it's only minor things, the changes look good overall.
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.
Overall LGTM @mvachhar .
I would, for simplicity and clarity:
- have a single trait by removing
TrieMapNew
and adding anew()
method to Triemap, removing all thewith_capacity
andwith_root
, etc.. - let the users of the crate decide and handle if there has to be a root or not, including the handling of the removal of objects for 0.0.0.0/0 or ::0/0. IMO, this is not something that this crate should decide and this avoids "dangerous" situations, which are better handled by the users of the crate.
- rename
TrieMapWithDefault
and the module as justTrie
.
4c16b70
to
42aad6a
Compare
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.
I made comments but I think they are all outdated at this point.
Regardless, I did a careful review and I'm baiscally happy with where this is at
|
||
/// This function gets the prefix, with lognest prefix match | ||
fn lookup<Q>(&self, addr: &Q) -> Option<(&Self::Prefix, &Self::Value)> | ||
where |
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.
Ideally, lookup
, get
, and get_mut
, and remove
would accept a Q: Borrow<Self::Prefix>
in the same way that std
's HashMap
et al do.
b332e40
to
9efcc66
Compare
9efcc66
to
7b6fd62
Compare
Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Manish Vachharajani <[email protected]>
Adding a ROOT const will allow us to reduce our use of unsafe code in a future commit. This is a logical requirement of a trie in any case. Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
If we use the combo of * a const ROOT * and scope the new method to only apply in the case of a defaulted value type then this method becomes safe. Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
These methods can all be evaluated at compile time and should be scoped as such. Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
This is a contract we can and should hold up. Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
The comment no longer obtains as the described trait is implemented. Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
When explicitly requested, the conversion of Ip{4,6}Net to Ip{4,6}Prefix should be done by zeroing any set host bits. This logic does not apply to constructing Ip{4,6}Prefixes explicitly using new et al. Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
The signature of TrieMapNew didn't allow it to function as a factory before. Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
This name makes it clearer that the trait is intended to be implemented on factory structures. Also, as a general rule, new is reserved as a constructor for the type itself, so rename to `create`. Signed-off-by: Daniel Noland <[email protected]> Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Manish Vachharajani <[email protected]>
Signed-off-by: Manish Vachharajani <[email protected]>
1bae6c0
to
a08ef5f
Compare
Addressed the comments, but dismissing due to timezone so we can merge today.
iptrie
is poorly tested and very buggy. This series of commits replaces it withPrefixMap
. It does so by adding an lpm package that contains thePrefix
implementation and aTrieMap
trait that the implementation can hide behind so we can swap to different implementations later.In the interest of time, there aren't many additional tests for the new stuff, but instead we rely on
PrefixMap
's tests which appear far superior to iptrie (with 90+% coverage) and the routing and nat tests. It is a better use of time to add fuzzing torouting
which will uncover any trie issues and cover the routing crate.Fixes #546