-
Notifications
You must be signed in to change notification settings - Fork 9
Static NAT + Masquerading / Static NAT + Port Forwarding #1548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3ffcc35
c8e1076
925c390
f3fb6d4
fe450af
659c96b
92719fa
4df3964
6af7039
bb61bf2
5a42178
65dc8f1
59c6a31
3530547
a7c7bdf
ebf7a27
e1cd599
1523214
2267593
a36a1c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,21 +20,30 @@ use strum::EnumMessage; | |
| use tracectl::trace_target; | ||
| use tracing::{debug, warn}; | ||
|
|
||
| use crate::StatelessNat; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude spotted this on this commit:
Looking over this, that seems to be true, but I'm not done reviewing yet |
||
| use crate::common::NatFlowStatus; | ||
| use crate::portfw::icmp_handling::handle_icmp_error_port_forwarding; | ||
| use crate::stateful::icmp_handling::handle_icmp_error_masquerading; | ||
| use crate::stateless::natrw::NatTablesReaderFactory; | ||
|
|
||
| trace_target!("icmp-errors", LevelFilter::INFO, &["nat", "pipeline"]); | ||
|
|
||
| pub struct IcmpErrorHandler { | ||
| flow_table: Arc<FlowTable>, | ||
| tables_factory: Option<NatTablesReaderFactory>, | ||
| } | ||
|
|
||
| impl IcmpErrorHandler { | ||
| /// Creates a new `IcmpErrorHandler` | ||
| #[must_use] | ||
| pub fn new(flow_table: Arc<FlowTable>) -> Self { | ||
| Self { flow_table } | ||
| pub fn new( | ||
| flow_table: Arc<FlowTable>, | ||
| static_nat_tables_factory: Option<NatTablesReaderFactory>, | ||
| ) -> Self { | ||
| Self { | ||
| flow_table, | ||
| tables_factory: static_nat_tables_factory, | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -205,6 +214,20 @@ impl IcmpErrorHandler { | |
| } else { | ||
| debug!("Will not invalidate flows (reason={reason} flow-status={status})"); | ||
| } | ||
|
|
||
| // We may also need to apply static NAT to the packet, if static NAT is used on the other | ||
| // end of the peering. | ||
| // We first need to update the checksums after the previous NAT changes, or the static NAT | ||
| // processor will fail to validate checksums and won't proceed. | ||
| let Some(tables_factory) = &self.tables_factory else { | ||
| return; | ||
| }; | ||
| packet.update_checksums(); | ||
| packet.meta_mut().set_static_nat_src(true); | ||
| packet.meta_mut().set_static_nat_dst(true); | ||
| let nat_processor = | ||
| StatelessNat::with_reader("icmp_error_static_nat", tables_factory.handle()); | ||
| nat_processor.process_packet(packet); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super tiny nit: this should work with
assert_matches!as of rust 1.96.0 (very new). That will give you better error messages than the true / false this returns.