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

interfaces: create android impl #11784

Merged
merged 1 commit into from
Apr 18, 2024
Merged

interfaces: create android impl #11784

merged 1 commit into from
Apr 18, 2024

Conversation

kari-ts
Copy link
Contributor

@kari-ts kari-ts commented Apr 17, 2024

-Move Android impl into interfaces_android.go
-Instead of using ip route to get the interface name, use the one passed in by Android (ip route is restricted in Android 13+ per termux/termux-app#2993)

Follow-up will be to do the same for router

Fixes tailscale/corp#19215
Fixes tailscale/corp#19124

@kari-ts kari-ts requested a review from awly April 17, 2024 21:23
@kari-ts kari-ts requested a review from bradfitz April 17, 2024 22:06
@kari-ts kari-ts marked this pull request as ready for review April 17, 2024 22:14
@@ -1,5 +1,6 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build !android
Copy link
Member

Choose a reason for hiding this comment

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

blank line before this

@@ -0,0 +1,186 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build android
Copy link
Member

Choose a reason for hiding this comment

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

this line's not needed. Can delete. The filename's sufficient.

(but if you did need it, blank line above)

return
}
if old := lastKnownDefaultRouteIfName.Swap(ifName); old != ifName {
log.Printf("defaultroute_android: update from Android, ifName = %s (was %s)", ifName, old)
Copy link
Member

Choose a reason for hiding this comment

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

no need for _android here

Comment on lines 8 to 10
import (
"errors"
)
Copy link
Member

Choose a reason for hiding this comment

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

unrelated change? but sure?

@bradfitz
Copy link
Member

Please copy the PR text to the commit message.

@bradfitz
Copy link
Member

Also it's not a "class" in Go.

Comment on lines 169 to 175
// UpdateLastKnownDefaultRouteInterface is called by libtailscale in the Android app when
// the connectivity manager detects a network path transition.
func UpdateLastKnownDefaultRouteInterface(ifName string) {
if ifName == "" {
return
}
if old := lastKnownDefaultRouteIfName.Swap(ifName); old != ifName {
log.Printf("defaultroute: update from Android, ifName = %s (was %s)", ifName, old)
}
Copy link
Member

Choose a reason for hiding this comment

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

can we document the meaning of the empty string? Does that mean no network? And shouldn't that transition be logged as well? Why's it not being recorded in the atomic?

Can you also document why this doesn't wake up something? Or why it's not a method on the Monitor?

When Android calls this, what happens later in the lifecycle that makes something back in Go read this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, no network should be recorded, thanks!

this doesn't wake anything up because debounce() is continuously monitoring and calls interfaces.GetState, which uses defaultRoute()

/*
Parse 10.0.0.1 out of:

$ cat /proc/net/route
Copy link
Member

Choose a reason for hiding this comment

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

IIRC only now-ancient Androids permit reading this file.

Is it even worth keeping this proc net parsing code? I think we need to 100% rely on Android APIs at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, this will be removed in a follow up


// UpdateLastKnownDefaultRouteInterface is called by libtailscale in the Android app when
// the connectivity manager detects a network path transition. If ifName is "", network has been lost.
// interfaces.debounce continuously monitors for network changes and will trigger a link change
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't continuously. This makes it sounds like it's busy looping polling this atomic.

I assume Android is calling Monitor.InjectEvent after the changes? Say that instead, if that's true?

Copy link
Member

@bradfitz bradfitz left a comment

Choose a reason for hiding this comment

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

But please fix the comment first.

-Move Android impl into interfaces_android.go
-Instead of using ip route to get the interface name, use the one passed in by Android (ip route is restricted in Android 13+ per termux/termux-app#2993)

Follow-up will be to do the same for router

Fixes tailscale/corp#19215
Fixes tailscale/corp#19124

Signed-off-by: kari-ts <kari@tailscale.com>
@kari-ts kari-ts merged commit 048cb61 into main Apr 18, 2024
43 of 44 checks passed
@kari-ts kari-ts deleted the kari/interface branch April 18, 2024 19:49
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