Based on the discussion in Discord we've decided to drop the
iter_key() API for LPM Trie. According to the kernel self-tests and
experimentation done in Aya, providing a key into bpf_map_get_next_id
will either:
- If key is an EXACT match, proceed iterating through all keys in the
trie from this point
- If key is NOT an EXACT match, proceed iterating through all keys in
the trie starting at the leftmost entry.
An API in Aya could be crafted that gets the LPM match + less specific
matches for a prefix using these semantics BUT it would only apply to
userspace. Therefore we've opted out of fixing this.
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
/// let mut trie = LpmTrie::try_from(bpf.map_mut("LPM_TRIE").unwrap())?;
/// let ipaddr = Ipv4Addr::new(8, 8, 8, 8);
/// // The following represents a key for the "8.8.8.8/16" subnet.
/// // The first argument - the prefix length - represents how many bytes should be matched against. The second argument is the actual data to be matched.
/// // The first argument - the prefix length - represents how many bits should be matched against. The second argument is the actual data to be matched.
/// let key = Key::new(16, u32::from(ipaddr).to_be());
/// trie.insert(&key, 1, 0)?;
///
@ -51,7 +51,7 @@ pub struct LpmTrie<T, K, V> {
_v: PhantomData<V>,
}
/// A Key for and LpmTrie map.
/// A Key for an LpmTrie map.
///
/// # Examples
///
@ -64,15 +64,18 @@ pub struct LpmTrie<T, K, V> {
/// ```
#[repr(packed)]
pubstructKey<K: Pod>{
/// Represents the number of bytes matched against.
pubprefix_len: u32,
/// Represents arbitrary data stored in the LpmTrie.
pubdata: K,
prefix_len: u32,
data: K,
}
impl<K: Pod>Key<K>{
/// Creates a new key.
///
/// `prefix_len` is the number of bits in the data to match against.
/// `data` is the data in the key which is typically an IPv4 or IPv6 address.
/// If using a key to perform a longest prefix match on you would use a `prefix_len`
/// of 32 for IPv4 and 128 for IPv6.
///
/// # Examples
///
/// ```no_run
@ -85,6 +88,16 @@ impl<K: Pod> Key<K> {
pubfnnew(prefix_len: u32,data: K)-> Self{
Self{prefix_len,data}
}
/// Returns the number of bits in the data to be matched.