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

refactor(firezone-tunnel): move routes and DNS control out of connlib and up to the Client #5111

Merged
merged 84 commits into from
Jun 3, 2024

Conversation

ReactorScram
Copy link
Collaborator

@ReactorScram ReactorScram commented May 23, 2024

Refs #3636 (This pays down some of the technical debt from Linux DNS)
Refs #4473 (This partially fulfills it)
Refs #5068 (This is needed to make FIREZONE_DNS_CONTROL mandatory)

As of dd6421:

  • On both Linux and Windows, DNS control and IP setting (i.e. on_set_interface_config) both move to the Client
  • On Windows, route setting stays in tun_windows.rs. Route setting in Windows requires us to know the interface index, which we don't know in the Client code. If we could pass opaque platform-specific data between the tunnel and the Client it would be easy.
  • On Linux, route setting moves to the Client and Gateway, which completely removes the worker task in tun_linux.rs
  • Notifying systemd that we're ready moves up to the headless Client / IPC service

Before merging / notes

Edit tasklist title
Beta Give feedback Tasklist Before merging / notes, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Does DNS roaming work on Linux on main? I don't see where it hooks up. I think I only set up DNS in Tun::new (Yes, the Tun gets recreated every time we reconfigure the device)
    Options
  2. Fix Windows Clients
    Options
  3. Fix Gateway
    Options
  4. Make sure connlib doesn't get the DNS control method from the env var (will be fixed in feat(headless-client/linux)!: make FIREZONE_DNS_CONTROL mandatory #5068)
    Options
  5. De-dupe consts
    Options
  6. Add DNS control test (failed)
    Options
  7. Smoke test Linux
    Options
  8. Smoke test Windows
    Options

@ReactorScram ReactorScram self-assigned this May 23, 2024
Copy link

vercel bot commented May 23, 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 Jun 3, 2024 2:13pm

@github-actions github-actions bot added the kind/refactor Code refactoring label May 23, 2024
Copy link

github-actions bot commented May 23, 2024

Terraform Cloud Plan Output

Plan: 17 to add, 14 to change, 17 to destroy.

Terraform Cloud Plan

@ReactorScram ReactorScram changed the base branch from main to refactor/debug-ipc-service May 23, 2024 18:34
@ReactorScram ReactorScram changed the base branch from refactor/debug-ipc-service to refactor/dedupe-ipc-clients May 23, 2024 18:38
@thomaseizinger
Copy link
Member

  • On Windows, Route settings stays in tun_windows.rs. Route setting in Windows requires us to know the interface index, which we don't know in the Client code. If we could pass opaque platform-specific data between the tunnel and the Client it would be easy.

Or, if you construct Tun in the clients too (as a result of the on-interface-callback) and make a setter on Tunnel then the Windows client can query and remember the interface index itself. For Tunnel, all we need to know about Tun is Stream + Sink of IpPacket.

Copy link
Collaborator

@conectado conectado left a comment

Choose a reason for hiding this comment

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

Nice work! I think there are some minor comments to be addressed before merging

rust/connlib/tunnel/src/device_channel/tun_linux.rs Outdated Show resolved Hide resolved
rust/connlib/shared/src/interface/linux.rs Outdated Show resolved Hide resolved
let mut signals = Signals::new()?;

loop {
match future::select(pin!(signals.recv()), pin!(on_disconnect_rx.recv())).await {
match future::select(pin!(signals.recv()), pin!(cb_rx.recv())).await {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is pin needed here? aren't these Unpin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤷‍♀️ If I try to remove either of those pin!() macros it won't compile.
I don't know how pinning works so I could be overlooking something.

rust/connlib/shared/src/interface/linux.rs Outdated Show resolved Hide resolved
@conectado
Copy link
Collaborator

  • On Windows, Route settings stays in tun_windows.rs. Route setting in Windows requires us to know the interface index, which we don't know in the Client code. If we could pass opaque platform-specific data between the tunnel and the Client it would be easy.

Or, if you construct Tun in the clients too (as a result of the on-interface-callback) and make a setter on Tunnel then the Windows client can query and remember the interface index itself. For Tunnel, all we need to know about Tun is Stream + Sink of IpPacket.

We could just construct the Tun without the on-interface-callback for windows and linux, for macos and android it's needed because we need to set some ip. Though we can just pick a placeholder ip and always have a tun interface created when the program starts. Move everything to the clients and just pass a reference Stream + Sink when calling poll_next_event.

Copy link
Member

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Great work! Slowly things are moving into the places where they belong :)

rust/connlib/shared/src/interface/linux.rs Outdated Show resolved Hide resolved
pub struct InterfaceManager {
// This gets lazy-initialized when the interface is first configured
connection: Option<Connection>,
dns_control_method: Option<DnsControlMethod>,
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to keep DNS in here? How we control DNS doesn't really have anything to do with the TUN device.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was using it for RAII but yeah looks like that can be split out into its own struct, so I will

rust/connlib/shared/src/interface/linux.rs Outdated Show resolved Hide resolved
rust/connlib/shared/src/interface/linux.rs Outdated Show resolved Hide resolved
rust/connlib/shared/src/interface/linux.rs Outdated Show resolved Hide resolved
rust/connlib/shared/src/interface/linux.rs Outdated Show resolved Hide resolved
rust/connlib/tunnel/src/device_channel/tun_windows.rs Outdated Show resolved Hide resolved
Copy link
Member

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Great work, thank you for cleaning this up!

Comment on lines -506 to -508
connlib
.set_dns(client::resolvers::get().unwrap_or_default())
.await?;
Copy link
Member

Choose a reason for hiding this comment

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

We can delete this because we will just do it on the first tick of the timer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe. I don't think I have a test to prove that yet, so I'll leave it. If DNS control is up in the Client now, maybe I can try to enforce in the Client that the "Firezone connected" notification or the systemd ready notification only fires after we definitely control DNS. Maybe in another PR

Copy link
Member

Choose a reason for hiding this comment

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

Nice work!

Move 👏 more 👏 config 👏 to 👏 the 👏 clients 👏

@ReactorScram ReactorScram added this pull request to the merge queue Jun 3, 2024
Merged via the queue into main with commit deefabd Jun 3, 2024
135 checks passed
@ReactorScram ReactorScram deleted the refactor/move-linux-dns-control branch June 3, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/refactor Code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants