diff options
Diffstat (limited to 'tunnel')
-rw-r--r-- | tunnel/src/main/proto/libwg.proto | 28 | ||||
-rw-r--r-- | tunnel/tools/libwg-go/api-android.go | 5 | ||||
-rw-r--r-- | tunnel/tools/libwg-go/service.go | 28 |
3 files changed, 61 insertions, 0 deletions
diff --git a/tunnel/src/main/proto/libwg.proto b/tunnel/src/main/proto/libwg.proto index e633ea46..24758940 100644 --- a/tunnel/src/main/proto/libwg.proto +++ b/tunnel/src/main/proto/libwg.proto @@ -15,6 +15,7 @@ service Libwg { rpc StopHttpProxy(StopHttpProxyRequest) returns (StopHttpProxyResponse); rpc Reverse(stream ReverseRequest) returns (stream ReverseResponse); rpc IpcSet(IpcSetRequest) returns (IpcSetResponse); + rpc TurnOn(TurnOnRequest) returns (TurnOnResponse); } message TunnelHandle { int32 handle = 1; } @@ -39,6 +40,17 @@ message InetSocketAddress { uint32 port = 2; } +message InetPrefix { + InetAddress address = 1; + uint32 prefixLenght = 2; +} + +enum TurnOnFlags { + NONE = 0x00; + ENABLE_DHCP = 0x01; + ENABLE_FOOBAR = 0x04; +} + message StopGrpcRequest { } @@ -101,3 +113,19 @@ message IpcSetRequest { message IpcSetResponse { Error error = 1; } + +message TurnOnRequest { + string interfaceName = 1; + int32 tunFd = 2; + string settings = 3; + // Bitwise-OR of TurnOnFlags. + optional uint32 flags = 4; + optional InetAddress linkLocalAddr = 5; +} + +message TurnOnResponse { + Error error = 1; + TunnelHandle tunnel = 2; + repeated InetPrefix addresses = 3; + // TODO add dns servers etc. +} diff --git a/tunnel/tools/libwg-go/api-android.go b/tunnel/tools/libwg-go/api-android.go index 0ab80be9..df2486db 100644 --- a/tunnel/tools/libwg-go/api-android.go +++ b/tunnel/tools/libwg-go/api-android.go @@ -13,6 +13,7 @@ import ( "fmt" "math" "net" + netip "net/netip" "os" "os/signal" "runtime" @@ -80,6 +81,10 @@ func init() { //export wgTurnOn func wgTurnOn(interfaceName string, tunFd int32, settings string) int32 { + return WgTurnOn(interfaceName, tunFd, settings, 0, netip.IPv6Unspecified()) +} + +func WgTurnOn(interfaceName string, tunFd int32, settings string, flags uint32, llAddr netip.Addr) int32 { tag := cstring("WireGuard/GoBackend/" + interfaceName) logger := &device.Logger{ Verbosef: AndroidLogger{level: C.ANDROID_LOG_DEBUG, tag: tag}.Printf, diff --git a/tunnel/tools/libwg-go/service.go b/tunnel/tools/libwg-go/service.go index 1f2e629c..cf4b56eb 100644 --- a/tunnel/tools/libwg-go/service.go +++ b/tunnel/tools/libwg-go/service.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net" + "net/netip" "net/url" "os" @@ -244,3 +245,30 @@ func (e *LibwgServiceImpl) IpcSet(ctx context.Context, req *gen.IpcSetRequest) ( return r, nil } + +func (e *LibwgServiceImpl) TurnOn(ctx context.Context, req *gen.TurnOnRequest) (*gen.TurnOnResponse, error) { + llAddr, _ := netip.AddrFromSlice(req.GetLinkLocalAddr().GetAddress()) + + flags := req.GetFlags() + + // if !ok { + // flags = flags & ^gen.TurnOnFlags_value[gen.TurnOnFlags_ENABLE_DHCP.String()] + // } + + handle := WgTurnOn(req.GetInterfaceName(), req.GetTunFd(), req.GetSettings(), flags, llAddr) + + if handle < 0 { + r := &gen.TurnOnResponse{ + Error: &gen.Error{ + Message: fmt.Sprintf("WgTurnOn failed"), + }, + } + return r, nil + } + + r := &gen.TurnOnResponse{ + Tunnel: &gen.TunnelHandle{Handle: handle}, + } + + return r, nil +} |