Skip to content

Commit 0bce3d4

Browse files
committed
test(nat): Add tests for static NAT + {masquerade, port forwarding}
Add unit tests to validate the use in a pipeline of static NAT + masquerade, or static NAT + port forwarding, on opposite sides of a peering. We set up a pipeline, create a packet, process it, and check for its output; then we create a fake reply, process it, check as well; at last, we re-process the original packet, to make sure that the connection still works after the flow table entry has been created. Signed-off-by: Quentin Monnet <qmo@qmon.net>
1 parent 2267593 commit 0bce3d4

3 files changed

Lines changed: 638 additions & 0 deletions

File tree

nat/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub mod portfw;
3030
mod ranges;
3131
pub mod stateful;
3232
pub mod stateless;
33+
mod test;
3334

3435
pub use icmp_handler::nf::IcmpErrorHandler;
3536
pub use port::NatPort;

nat/src/portfw/portfwtable/access.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
//! Port forwarding table objects for concurrent accesses
55
//! from datapath and configuration / management
66
7+
use super::super::build_port_forwarding_configuration;
78
use super::PortFwTableError;
89
use super::objects::{PortFwEntry, PortFwTable};
10+
use config::external::overlay::vpc::ValidatedVpcTable;
911
use left_right::{Absorb, ReadGuard, ReadHandle, ReadHandleFactory, WriteHandle};
1012

1113
#[allow(unused)]
@@ -57,6 +59,14 @@ impl PortFwTableWriter {
5759
self.0.publish(); // intended
5860
Ok(())
5961
}
62+
pub fn update_from_vpc_table(
63+
&mut self,
64+
vpc_table: &ValidatedVpcTable,
65+
) -> Result<(), PortFwTableError> {
66+
let ruleset = build_port_forwarding_configuration(vpc_table)
67+
.map_err(|e| PortFwTableError::Unsupported(e.to_string()))?;
68+
self.update_table(&ruleset)
69+
}
6070
}
6171

6272
#[derive(Debug)]

0 commit comments

Comments
 (0)