diff --git a/clients.go b/clients.go index 7b67501..0696a24 100644 --- a/clients.go +++ b/clients.go @@ -30,7 +30,7 @@ func setupClients(client *websocket.Client) { host = strings.TrimSuffix(host, "/") if useNativeInterface { - setupClientsNative(client, host) + // setupClientsNative(client, host) } else { setupClientsNetstack(client, host) } @@ -81,7 +81,7 @@ func closeClients() { wgService = nil } - closeWgServiceNative() + // closeWgServiceNative() if wgTesterServer != nil { wgTesterServer.Stop() @@ -106,7 +106,7 @@ func clientsHandleNewtConnection(publicKey string, endpoint string) { wgService.StartHolepunch(publicKey, endpoint) } - clientsHandleNewtConnectionNative(publicKey, endpoint) + // clientsHandleNewtConnectionNative(publicKey, endpoint) } func clientsOnConnect() { @@ -117,7 +117,7 @@ func clientsOnConnect() { wgService.LoadRemoteConfig() } - clientsOnConnectNative() + // clientsOnConnectNative() } func clientsAddProxyTarget(pm *proxy.ProxyManager, tunnelIp string) { @@ -130,5 +130,5 @@ func clientsAddProxyTarget(pm *proxy.ProxyManager, tunnelIp string) { pm.AddTarget("udp", tunnelIp, int(wgService.Port), fmt.Sprintf("127.0.0.1:%d", wgService.Port)) } - clientsAddProxyTargetNative(pm, tunnelIp) + // clientsAddProxyTargetNative(pm, tunnelIp) } diff --git a/common.go b/common.go index 7118a7c..b32843e 100644 --- a/common.go +++ b/common.go @@ -18,7 +18,6 @@ import ( "github.com/fosrl/newt/websocket" "golang.org/x/net/icmp" "golang.org/x/net/ipv4" - "golang.zx2c4.com/wireguard/device" "golang.zx2c4.com/wireguard/tun/netstack" "gopkg.in/yaml.v3" ) @@ -349,21 +348,6 @@ func startPingCheck(tnet *netstack.Net, serverIP string, client *websocket.Clien return pingStopChan } -func mapToWireGuardLogLevel(level logger.LogLevel) int { - switch level { - case logger.DEBUG: - return device.LogLevelVerbose - // case logger.INFO: - // return device.LogLevel - case logger.WARN: - return device.LogLevelError - case logger.ERROR, logger.FATAL: - return device.LogLevelSilent - default: - return device.LogLevelSilent - } -} - func parseTargetData(data interface{}) (TargetData, error) { var targetData TargetData jsonData, err := json.Marshal(data) diff --git a/linux.go b/linux.go deleted file mode 100644 index 70918d3..0000000 --- a/linux.go +++ /dev/null @@ -1,74 +0,0 @@ -//go:build linux - -package main - -import ( - "fmt" - "os" - "runtime" - - "github.com/fosrl/newt/logger" - "github.com/fosrl/newt/proxy" - "github.com/fosrl/newt/websocket" - "github.com/fosrl/newt/wg" - "github.com/fosrl/newt/wgtester" -) - -var wgServiceNative *wg.WireGuardService - -func setupClientsNative(client *websocket.Client, host string) { - - if runtime.GOOS != "linux" { - logger.Fatal("Tunnel management is only supported on Linux right now!") - os.Exit(1) - } - - // make sure we are sudo - if os.Geteuid() != 0 { - logger.Fatal("You must run this program as root to manage tunnels on Linux.") - os.Exit(1) - } - - // Create WireGuard service - wgServiceNative, err = wg.NewWireGuardService(interfaceName, mtuInt, generateAndSaveKeyTo, host, id, client) - if err != nil { - logger.Fatal("Failed to create WireGuard service: %v", err) - } - - wgTesterServer = wgtester.NewServer("0.0.0.0", wgServiceNative.Port, id) // TODO: maybe make this the same ip of the wg server? - err := wgTesterServer.Start() - if err != nil { - logger.Error("Failed to start WireGuard tester server: %v", err) - } - - client.OnTokenUpdate(func(token string) { - wgServiceNative.SetToken(token) - }) -} - -func closeWgServiceNative() { - if wgServiceNative != nil { - wgServiceNative.Close(!keepInterface) - wgServiceNative = nil - } -} - -func clientsOnConnectNative() { - if wgServiceNative != nil { - wgServiceNative.LoadRemoteConfig() - } -} - -func clientsHandleNewtConnectionNative(publicKey, endpoint string) { - if wgServiceNative != nil { - wgServiceNative.StartHolepunch(publicKey, endpoint) - } -} - -func clientsAddProxyTargetNative(pm *proxy.ProxyManager, tunnelIp string) { - // add a udp proxy for localost and the wgService port - // TODO: make sure this port is not used in a target - if wgServiceNative != nil { - pm.AddTarget("udp", tunnelIp, int(wgServiceNative.Port), fmt.Sprintf("127.0.0.1:%d", wgServiceNative.Port)) - } -} diff --git a/main.go b/main.go index 5bf656f..7ccc0d2 100644 --- a/main.go +++ b/main.go @@ -651,7 +651,7 @@ func main() { // Create WireGuard device dev = device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger( - mapToWireGuardLogLevel(loggerLevel), + util.MapToWireGuardLogLevel(loggerLevel), "wireguard: ", )) diff --git a/util/util.go b/util/util.go index 9cce3df..98f9828 100644 --- a/util/util.go +++ b/util/util.go @@ -10,6 +10,7 @@ import ( mathrand "math/rand/v2" "github.com/fosrl/newt/logger" + "golang.zx2c4.com/wireguard/device" ) func ResolveDomain(domain string) (string, error) { @@ -136,3 +137,18 @@ func FixKey(key string) string { // Convert to hex return hex.EncodeToString(decoded) } + +func MapToWireGuardLogLevel(level logger.LogLevel) int { + switch level { + case logger.DEBUG: + return device.LogLevelVerbose + // case logger.INFO: + // return device.LogLevel + case logger.WARN: + return device.LogLevelError + case logger.ERROR, logger.FATAL: + return device.LogLevelSilent + default: + return device.LogLevelSilent + } +}