7577ec9cb2
* Initial work on reverse nat * wip * Refine key gen * Rename to wg_tunnel * Forward packet to peer * Remove source_addr * Check if allowed to write to tunnel * Extract out network_table * Move map struc definitions to udp_listener * Delegate ip network table calls * Fix mac compilation * Add TunTaskTx type
26 lines
566 B
Rust
26 lines
566 B
Rust
use std::net::IpAddr;
|
|
|
|
use ip_network::IpNetwork;
|
|
use ip_network_table::IpNetworkTable;
|
|
|
|
#[derive(Default)]
|
|
pub(crate) struct NetworkTable<T> {
|
|
ips: IpNetworkTable<T>,
|
|
}
|
|
|
|
impl<T> NetworkTable<T> {
|
|
pub(crate) fn new() -> Self {
|
|
Self {
|
|
ips: IpNetworkTable::new(),
|
|
}
|
|
}
|
|
|
|
pub fn insert<N: Into<IpNetwork>>(&mut self, network: N, data: T) -> Option<T> {
|
|
self.ips.insert(network, data)
|
|
}
|
|
|
|
pub fn longest_match<I: Into<IpAddr>>(&self, ip: I) -> Option<(IpNetwork, &T)> {
|
|
self.ips.longest_match(ip)
|
|
}
|
|
}
|