Skip to content
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

SNAT routing #1083

Merged
merged 7 commits into from
Feb 3, 2025
Merged

SNAT routing #1083

merged 7 commits into from
Feb 3, 2025

Conversation

ch-iara
Copy link
Contributor

@ch-iara ch-iara commented Jan 15, 2025

Integration test is still cooking, iptables rules must be translated into nftables as should parsing for the teardown code when nftables in use

@ch-iara ch-iara force-pushed the chiara/iptables-routing-snat-cgnat branch 4 times, most recently from e25610a to ab2b2e8 Compare January 27, 2025 20:40
Routes work with pingability for snat exit integration test. In this
mode clients are assigned an external ip that their traffic exits on.
Wherein we finish testing the teardown logic in the integration test.
Routers offline for more than 5 days have their SNAT rules torn down
so that the ip is freed up.
@ch-iara ch-iara force-pushed the chiara/iptables-routing-snat-cgnat branch from ab2b2e8 to fbfd486 Compare January 30, 2025 11:10
@ch-iara ch-iara force-pushed the chiara/iptables-routing-snat-cgnat branch from fbfd486 to 7c6628a Compare January 30, 2025 11:14
@ch-iara ch-iara changed the title SNAT routing wip SNAT routing Jan 30, 2025
Copy link
Member

@jkilpatr jkilpatr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work getting this working. It's an in depth change with a lot of moving parts.

I've left some comments on logic cleanup in a few places, and one edgecase that needs to be handled. Overall I like the structure you've used and the implementation is very clean.

My only flag is the significant use of functional chains to get a given value out of an array for example, these can be hard to read and confusing sometimes. You can usually just ask copilot to generate a utility function or an iterative version of the same check and get a great result.

info!("Setting up iptables SNAT rules on exit for client: {client_external_ip} to {client_internal_ip}");
add_iptables_rule(
"iptables",
&[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where these actually ever tested since the test environment is nftables only?

I suppose we'd have to delete nftables in the container to try.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it turns out they don't work I'd rather drop iptables support for this entierly. We still want it form the routers becuase we have hundreds of devices out there without nftables installed, but for exit appliances since none currently exist we will never make an image without nftables in the first place. Not that this isn't still useful if someone tries to install an exit on an older machine for some reason in the future, but it won't be us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed iptables rules since if we won't be using them I don't think we need to include them untested

The previous implementation of setup would have readded the same SNAT
rules to nftables any time a new client registered to the exit, which
would clog the tables and mess with teardown logic. In this fix we
only add rules when a client is not in the external ip assignments
list AND also online as defined by WG_INACTIVE_THRESHOLD. When a client
is deemed offline they are now removed from external ip assignments
list as they should have been on top of just having their snat rules
torn down.
@ch-iara
Copy link
Contributor Author

ch-iara commented Feb 3, 2025

Multi Exit test currently spitting about a bunch of "Too many open files" error from all namespaces and panics when trying to spawn the thread registering to exit?

Better handling for the 0 timestamp wg handshake, now clients have 1 min
to handshake after connecting and receiving an ip before they can be
auto torn down.
+ Extra cleanup
@jkilpatr jkilpatr merged commit b72ae14 into master Feb 3, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants