-
Notifications
You must be signed in to change notification settings - Fork 2
/
fix_routes.go
59 lines (44 loc) · 1.38 KB
/
fix_routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//go:build windows
package main
import (
"fmt"
"github.com/wheatevo/wslroutesvc/network"
"github.com/wheatevo/wslroutesvc/runner"
)
func fixRoutes(wslIfaceNames []string, runner runner.Runner) {
var wslIface network.Iface
var wslIfaceName string
foundIface := false
// Iterate through possible WSL interface names to find a valid interface
for _, ifaceName := range wslIfaceNames {
wslIface = network.NewIface(ifaceName, runner)
if wslIface.ID == "" || wslIface.IP.String() == "<nil>" {
continue
}
wslIfaceName = ifaceName
foundIface = true
break
}
if !foundIface {
elog.Error(1, fmt.Sprintf("Could not find interface ID or IP for WSL interfaces ", wslIfaceNames))
return
}
elog.Info(1, fmt.Sprintf("%s interface ID: %s, IP: %s", wslIfaceName, wslIface.ID, wslIface.IP))
routeList := network.NewRouteList(runner)
for _, r := range routeList.Routes {
if r.Network.Contains(wslIface.IP) && r.InterfaceID != wslIface.ID {
maskSize, _ := r.Network.Mask.Size()
// Prevent broad routes from qualifying
if maskSize < 16 {
continue
}
// Remove the route
out, err := r.Remove(runner)
if err != nil {
elog.Error(1, fmt.Sprintf("Failed to remove route %s with interface ID %s!\n%s\n%v", r.Network, r.InterfaceID, out, err))
continue
}
elog.Info(1, fmt.Sprintf("Route %s with interface ID %s removed!", r.Network, r.InterfaceID))
}
}
}