From 7d36922a3cb9d77e9c4ba4db3f70b34bc65b27dd Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 2 Mar 2019 05:18:40 +0100 Subject: ifaceconfig: monitor for changes to default interface --- service/service_tunnel.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'service/service_tunnel.go') diff --git a/service/service_tunnel.go b/service/service_tunnel.go index 750a4302..12a0d709 100644 --- a/service/service_tunnel.go +++ b/service/service_tunnel.go @@ -8,6 +8,7 @@ package service import ( "bufio" "fmt" + "golang.zx2c4.com/winipcfg" "log" "strings" @@ -131,8 +132,9 @@ func (service *tunnelService) Execute(args []string, r <-chan svc.ChangeRequest, return } ipcSetOperation(device, bufio.NewReader(strings.NewReader(uapiConf))) + guid := wintun.(*tun.NativeTun).GUID() - err = monitorDefaultRoutes(device.net.bind.(*NativeBind)) + routeMonitorCallback, err := monitorDefaultRoutes(device.net.bind.(*NativeBind), &guid) if err != nil { logger.Error.Println("Unable to bind sockets to default route:", err) changes <- svc.Status{State: svc.StopPending} @@ -141,7 +143,6 @@ func (service *tunnelService) Execute(args []string, r <-chan svc.ChangeRequest, return } - guid := wintun.(*tun.NativeTun).GUID() err = configureInterface(conf, &guid) if err != nil { logger.Error.Println("Unable to set interface addresses, routes, DNS, or IP settings:", err) @@ -174,6 +175,7 @@ loop: changes <- svc.Status{State: svc.StopPending} logger.Info.Println("Shutting down") + winipcfg.UnregisterRouteChangeCallback(routeMonitorCallback) uapi.Close() device.Close() return -- cgit v1.2.3-59-g8ed1b