/// let mut trie = LpmTrie::try_from(bpf.map_mut("LPM_TRIE").unwrap())?;
/// let mut trie = LpmTrie::try_from(bpf.map_mut("LPM_TRIE").unwrap())?;
/// let ipaddr = Ipv4Addr::new(8, 8, 8, 8);
/// let ipaddr = Ipv4Addr::new(8, 8, 8, 8);
/// // The following represents a key for the "8.8.8.8/16" subnet.
/// // 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());
/// let key = Key::new(16, u32::from(ipaddr).to_be());
/// trie.insert(&key, 1, 0)?;
/// trie.insert(&key, 1, 0)?;
///
///
@ -51,7 +51,7 @@ pub struct LpmTrie<T, K, V> {
_v: PhantomData<V>,
_v: PhantomData<V>,
}
}
/// A Key for and LpmTrie map.
/// A Key for an LpmTrie map.
///
///
/// # Examples
/// # Examples
///
///
@ -64,15 +64,18 @@ pub struct LpmTrie<T, K, V> {
/// ```
/// ```
#[repr(packed)]
#[repr(packed)]
pubstructKey<K: Pod>{
pubstructKey<K: Pod>{
/// Represents the number of bytes matched against.
prefix_len: u32,
pubprefix_len: u32,
data: K,
/// Represents arbitrary data stored in the LpmTrie.
pubdata: K,
}
}
impl<K: Pod>Key<K>{
impl<K: Pod>Key<K>{
/// Creates a new key.
/// 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
/// # Examples
///
///
/// ```no_run
/// ```no_run
@ -85,6 +88,16 @@ impl<K: Pod> Key<K> {
pubfnnew(prefix_len: u32,data: K)-> Self{
pubfnnew(prefix_len: u32,data: K)-> Self{
Self{prefix_len,data}
Self{prefix_len,data}
}
}
/// Returns the number of bits in the data to be matched.