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(connlib): remove Option<RawFd> return value from Callbacks #4471

Closed
wants to merge 6 commits into from

Conversation

thomaseizinger
Copy link
Member

@thomaseizinger thomaseizinger commented Apr 3, 2024

This represents a more minimal version of #4159 where we for now only change the Android-related code, making this a much smaller change.

The idea is that, instead of setting the new file descriptor based on the return value from the callback, it is the responsibility of the connlib-client-android glue code to construct a new Tun device and set it on the Tunnel using a new command.

Related: #4473.

Copy link

vercel bot commented Apr 3, 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 Apr 12, 2024 1:45am

Copy link

github-actions bot commented Apr 3, 2024

Terraform Cloud Plan Output

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

Terraform Cloud Plan

Copy link

github-actions bot commented Apr 3, 2024

Performance Test Results

TCP

Test Name Received/s Sent/s Retransmits
direct-tcp-client2server 245.8 MiB (+0%) 248.3 MiB (+1%) 243 (+1%)
direct-tcp-server2client 241.9 MiB (-2%) 243.4 MiB (-2%) 234 (-57%)
relayed-tcp-client2server 223.1 MiB (+2%) 224.0 MiB (+2%) 254 (-9%)
relayed-tcp-server2client 240.9 MiB (+2%) 241.5 MiB (+2%) 455 (+8%)

UDP

Test Name Total/s Jitter Lost
direct-udp-client2server 50.0 MiB (+0%) 0.04ms (+2%) 0.00% (NaN%)
direct-udp-server2client 50.0 MiB (+0%) 0.01ms (+3%) 0.00% (NaN%)
relayed-udp-client2server 50.0 MiB (-0%) 0.04ms (-13%) 0.00% (NaN%)
relayed-udp-server2client 50.0 MiB (+0%) 0.01ms (-26%) 0.00% (NaN%)

.expect("session must be set once callbacks get called")
.set_tun(tun),
Err(e) => {
tracing::error!("Failed to make new `Tun`: {e}");
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, any error when creating a new Tun device is also only bubbled up

) -> Result<(), ConnlibError> {
and eventually logged
tracing::warn!("Tunnel error: {e}");

so this isn't a change in behaviour.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we fail to create the Tun for some reason, will the app silently go on without tunneling any traffic?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is the behaviour today.

@thomaseizinger
Copy link
Member Author

I still need to test this on an actual device.

rust/connlib/tunnel/src/device_channel.rs Show resolved Hide resolved
rust/connlib/tunnel/src/device_channel.rs Show resolved Hide resolved
let fd = callbacks
.on_set_interface_config(config.ipv4, config.ipv6, dns_config)
.ok_or(Error::NoFd)?;
pub fn with_fd(fd: RawFd) -> Result<Self> {
// Safety: File descriptor is open.
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this function safe if its safety depends on the caller passing an open fd?

Copy link
Member Author

Choose a reason for hiding this comment

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

It isn't but this is already what is on main, I just moved things around a bit.

.expect("session must be set once callbacks get called")
.set_tun(tun),
Err(e) => {
tracing::error!("Failed to make new `Tun`: {e}");
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we fail to create the Tun for some reason, will the app silently go on without tunneling any traffic?

@thomaseizinger thomaseizinger marked this pull request as draft April 8, 2024 10:25
Some(MAX_PARTITION_TIME),
runtime.handle().clone(),
);

callback_handler.session = Some(session.clone());
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't gonna work because the instance of CallbackHandler that got passed into Session doesn't have the Session set 🤦‍♂️

Need to think of something else here.


// SAFETY: we expect the callback to return a valid file descriptor
unsafe { self.replace_fd(fd)? };
let fd = callbacks.on_update_routes(
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
let fd = callbacks.on_update_routes(
callbacks.on_update_routes(

Assignment of a unit-value.

@thomaseizinger thomaseizinger force-pushed the refactor/connlib/android-set-tun branch from f7ccba4 to c91ea2e Compare April 12, 2024 00:18
@thomaseizinger
Copy link
Member Author

Outdated.

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.

None yet

2 participants