summaryrefslogtreecommitdiffhomepage
path: root/tunnel/tools/libwg-go/service.go
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-02-11 20:18:54 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2023-02-11 20:18:54 +0100
commit89c6fdac75494e608608c57db75476f69bf88a63 (patch)
treed54c75ce15dd6469f4f1bb7bfb2fd9af851b83c9 /tunnel/tools/libwg-go/service.go
parent8cd49f9a8d3e14568d7c0fda696fe62efb14d0e9 (diff)
WIP: grpc-turnongrpc-turnon
Diffstat (limited to 'tunnel/tools/libwg-go/service.go')
-rw-r--r--tunnel/tools/libwg-go/service.go28
1 files changed, 28 insertions, 0 deletions
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
+}