mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
Feature/exit node Android (#1916)
Support exit node on Android. With the protect socket function, we mark every connection that should be used out of VPN.
This commit is contained in:
25
util/net/dialer_android.go
Normal file
25
util/net/dialer_android.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (d *Dialer) init() {
|
||||
d.Dialer.Control = func(_, _ string, c syscall.RawConn) error {
|
||||
err := c.Control(func(fd uintptr) {
|
||||
androidProtectSocketLock.Lock()
|
||||
f := androidProtectSocket
|
||||
androidProtectSocketLock.Unlock()
|
||||
if f == nil {
|
||||
return
|
||||
}
|
||||
ok := f(int32(fd))
|
||||
if !ok {
|
||||
log.Errorf("failed to protect socket: %d", fd)
|
||||
}
|
||||
})
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build android || ios
|
||||
|
||||
package net
|
||||
|
||||
import (
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !android && !ios
|
||||
//go:build !ios
|
||||
|
||||
package net
|
||||
|
||||
@@ -36,7 +36,7 @@ func AddDialerCloseHook(hook DialerCloseHookFunc) {
|
||||
dialerCloseHooks = append(dialerCloseHooks, hook)
|
||||
}
|
||||
|
||||
// RemoveDialerHook removes all dialer hooks.
|
||||
// RemoveDialerHooks removes all dialer hooks.
|
||||
func RemoveDialerHooks() {
|
||||
dialerDialHooksMutex.Lock()
|
||||
defer dialerDialHooksMutex.Unlock()
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !linux || android
|
||||
//go:build !linux
|
||||
|
||||
package net
|
||||
|
||||
|
||||
26
util/net/listener_android.go
Normal file
26
util/net/listener_android.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// init configures the net.ListenerConfig Control function to set the fwmark on the socket
|
||||
func (l *ListenerConfig) init() {
|
||||
l.ListenConfig.Control = func(_, _ string, c syscall.RawConn) error {
|
||||
err := c.Control(func(fd uintptr) {
|
||||
androidProtectSocketLock.Lock()
|
||||
f := androidProtectSocket
|
||||
androidProtectSocketLock.Unlock()
|
||||
if f == nil {
|
||||
return
|
||||
}
|
||||
ok := f(int32(fd))
|
||||
if !ok {
|
||||
log.Errorf("failed to protect listener socket: %d", fd)
|
||||
}
|
||||
})
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build android || ios
|
||||
//go:build ios
|
||||
|
||||
package net
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !android && !ios
|
||||
//go:build !ios
|
||||
|
||||
package net
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !linux || android
|
||||
//go:build !linux
|
||||
|
||||
package net
|
||||
|
||||
|
||||
14
util/net/protectsocket_android.go
Normal file
14
util/net/protectsocket_android.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package net
|
||||
|
||||
import "sync"
|
||||
|
||||
var (
|
||||
androidProtectSocketLock sync.Mutex
|
||||
androidProtectSocket func(fd int32) bool
|
||||
)
|
||||
|
||||
func SetAndroidProtectSocketFn(f func(fd int32) bool) {
|
||||
androidProtectSocketLock.Lock()
|
||||
androidProtectSocket = f
|
||||
androidProtectSocketLock.Unlock()
|
||||
}
|
||||
Reference in New Issue
Block a user