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

fix(connlib): only update the interface when setting dns if the effective dns changed #4327

Merged
merged 3 commits into from
Mar 27, 2024

Conversation

conectado
Copy link
Collaborator

@conectado conectado commented Mar 26, 2024

Supersedes #4320, closes #4318

Updates the interface if effective dns have changed.

Fixes a bug where we could set upstream_dns to have sentinel dns

Adds corresponding unit tests.

Copy link

vercel bot commented Mar 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
firezone ⬜️ Ignored (Inspect) Visit Preview Mar 27, 2024 4:42pm

Copy link

github-actions bot commented Mar 26, 2024

Terraform Cloud Plan Output

Plan: 9 to add, 8 to change, 26 to destroy.

Terraform Cloud Plan

Copy link

github-actions bot commented Mar 26, 2024

Performance Test Results

TCP

Test Name Received/s Sent/s Retransmits
direct-tcp-client2server 224.0 MiB (+0%) 226.2 MiB (+0%) 122 (-36%)
direct-tcp-server2client 224.3 MiB (-0%) 225.9 MiB (-0%) 310 (-4%)
relayed-tcp-client2server 148.6 MiB (+4%) 149.3 MiB (+4%) 167 (+25%)
relayed-tcp-server2client 153.3 MiB (-2%) 153.7 MiB (-2%) 164 (-32%)

UDP

Test Name Total/s Jitter Lost
direct-udp-client2server 50.0 MiB (+0%) 0.04ms (-87%) 0.00% (NaN%)
direct-udp-server2client 50.0 MiB (-0%) 0.02ms (+160%) 0.00% (NaN%)
relayed-udp-client2server 50.0 MiB (-0%) 0.09ms (-12%) 0.00% (-100%)
relayed-udp-server2client 50.0 MiB (+0%) 0.06ms (+13%) 0.00% (NaN%)

Copy link
Collaborator

@ReactorScram ReactorScram left a comment

Choose a reason for hiding this comment

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

If the unit tests can prove that it does everything we need (Ignores sentinels, doesn't update if the upstream resolvers are set and stay the same, correctly updates when the upstream is enabled and disabled, etc.) then it's fine.

But for some reason I find it really hard to follow this part of the code, so I asked a lot of questions to make sure I'm understanding it.

@@ -167,12 +167,11 @@ where

/// Updates the system's dns
pub fn set_dns(&mut self, new_dns: Vec<IpAddr>) -> connlib_shared::Result<()> {
let dns_changed = self.role_state.update_system_resolvers(new_dns);

self.role_state.update_system_resolvers(new_dns);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know this code well so I'll just write what I think is happening, like I did for the macOS network PR

So this function has changed to always set the DNS, the logic is moving up from RoleState to whatever this struct is. (ClientTunnel?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well, the function called just below this, which is still in role_state checks for changes.

let dns_changed = self.role_state.update_system_resolvers(new_dns);

self.role_state.update_system_resolvers(new_dns);
let dns_changed = self.update_dns_mapping();
Copy link
Collaborator

Choose a reason for hiding this comment

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

The change check moved over to this function, so far so good..

rust/connlib/tunnel/src/client.rs Show resolved Hide resolved
rust/connlib/tunnel/src/client.rs Outdated Show resolved Hide resolved
Comment on lines 281 to 284
let effective_dns_servers = effective_dns_servers(
config.upstream_dns.clone(),
self.role_state.system_resolvers.clone(),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are the current new effective DNS servers

This function is called after the DNS servers are updated in role_state? So the role state is out of sync until its owner calls this?

And this is where the filtering happens, in effective_dns_servers, and that also means we won't spuriously update anything if the system DNS changes while an upstream DNS is set.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well, the system's resolvers are right before this in role_state but we haven't updated the dns mappings considering the newest one.

And this is where the filtering happens, in effective_dns_servers, and that also means we won't spuriously update anything if the system DNS changes while an upstream DNS is set.

yup!

rust/connlib/tunnel/src/client.rs Outdated Show resolved Hide resolved
rust/connlib/tunnel/src/client.rs Show resolved Hide resolved
rust/connlib/tunnel/src/client.rs Outdated Show resolved Hide resolved
@conectado conectado marked this pull request as ready for review March 27, 2024 01:25
@conectado
Copy link
Collaborator Author

@ReactorScram fixed a bug where the effective dns would contain sentinels if they were in the upstream and added the unit tests.

I think those should cover everything

@conectado conectado force-pushed the fix/only-update-interface-if-dns-changed branch from 2101d9a to 5334184 Compare March 27, 2024 02:12
rust/connlib/tunnel/src/client.rs Outdated Show resolved Hide resolved
Co-authored-by: Reactor Scram <ReactorScram@users.noreply.github.com>
Signed-off-by: Gabi <gabrielalejandro7@gmail.com>
@conectado conectado added this pull request to the merge queue Mar 27, 2024
Merged via the queue into main with commit f57f834 Mar 27, 2024
152 checks passed
@conectado conectado deleted the fix/only-update-interface-if-dns-changed branch March 27, 2024 17:27
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.

bug(windows): Infinite on_tunnel_ready notifications
2 participants