pub struct NatEngine {
pub port_pool: PortPool,
pub mappings: BTreeMap<ConntrackKey, NatMapping>,
pub masquerade_addr: Ipv4Address,
pub total_translations: u64,
}Expand description
The NAT engine managing translations and port allocation
Fields§
§port_pool: PortPoolEphemeral port pool
mappings: BTreeMap<ConntrackKey, NatMapping>Active NAT mappings indexed by original connection key
masquerade_addr: Ipv4AddressMasquerade address (outgoing interface IP)
total_translations: u64Total translations performed
Implementations§
Source§impl NatEngine
impl NatEngine
Sourcepub fn set_masquerade_addr(&mut self, addr: Ipv4Address)
pub fn set_masquerade_addr(&mut self, addr: Ipv4Address)
Set the masquerade (outgoing interface) address
Sourcepub fn translate_outbound_snat(
&mut self,
key: &ConntrackKey,
new_src_ip: Ipv4Address,
) -> Option<NatMapping>
pub fn translate_outbound_snat( &mut self, key: &ConntrackKey, new_src_ip: Ipv4Address, ) -> Option<NatMapping>
Translate an outbound packet with SNAT
Rewrites the source address and allocates a new source port. Returns the NAT mapping on success.
Sourcepub fn translate_outbound_masquerade(
&mut self,
key: &ConntrackKey,
) -> Option<NatMapping>
pub fn translate_outbound_masquerade( &mut self, key: &ConntrackKey, ) -> Option<NatMapping>
Translate an outbound packet with masquerading
Uses the configured masquerade address as the source.
Sourcepub fn translate_inbound_dnat(
&mut self,
key: &ConntrackKey,
new_dst_ip: Ipv4Address,
new_dst_port: Port,
) -> Option<NatMapping>
pub fn translate_inbound_dnat( &mut self, key: &ConntrackKey, new_dst_ip: Ipv4Address, new_dst_port: Port, ) -> Option<NatMapping>
Translate an inbound packet with DNAT
Rewrites the destination address and port.
Sourcepub fn lookup_reverse(&self, reply_key: &ConntrackKey) -> Option<&NatMapping>
pub fn lookup_reverse(&self, reply_key: &ConntrackKey) -> Option<&NatMapping>
Look up a reverse NAT mapping for inbound reply traffic
Given a reply packet’s key, find the corresponding SNAT/masquerade mapping to reverse the translation.
Sourcepub fn remove_mapping(&mut self, key: &ConntrackKey) -> Option<NatMapping>
pub fn remove_mapping(&mut self, key: &ConntrackKey) -> Option<NatMapping>
Remove a NAT mapping and release its allocated port
Sourcepub fn mapping_count(&self) -> usize
pub fn mapping_count(&self) -> usize
Number of active mappings