Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
[fix] (Linux) Pause functionality for OpenVPN v4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
stenya committed Dec 8, 2020
1 parent b447159 commit bc000e1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions service/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ var (
obfsproxyStartScript string
obfsproxyHostPort int

routeCommand string // exmaple: "/sbin/route" - for macOS, "/sbin/ip route" - for Linux

wgBinaryPath string
wgToolBinaryPath string
wgConfigFilePath string
Expand Down Expand Up @@ -137,6 +139,14 @@ func Init() (warnings []string, errors []error) {
warnings = append(warnings, fmt.Errorf("WireGuard functionality not accessible: %w", err).Error())
}

if len(routeCommand) > 0 {
routeBinary := strings.Split(routeCommand, " ")[0]
if err := checkFileAccessRightsExecutable("routeCommand", routeBinary); err != nil {
routeCommand = ""
warnings = append(warnings, fmt.Errorf("Route binary error: %w", err).Error())
}
}

w, e := doInitOperations()
if len(w) > 0 {
warnings = append(warnings, w)
Expand Down Expand Up @@ -288,6 +298,12 @@ func ObfsproxyHostPort() int {
return obfsproxyHostPort
}

// RouteCommand shell command to update routing table
// exmaple: "/sbin/route" - for macOS, "/sbin/ip route" - for Linux
func RouteCommand() string {
return routeCommand
}

// WgBinaryPath path to WireGuard binary
func WgBinaryPath() string {
return wgBinaryPath
Expand Down
1 change: 1 addition & 0 deletions service/platform/platform_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func doOsInit() (warnings []string, errors []error) {
obfsproxyStartScript = "/usr/bin/obfsproxy"
wgBinaryPath = path.Join("/usr/bin", "wg-quick")
wgToolBinaryPath = path.Join("/usr/bin", "wg")
routeCommand = "/sbin/ip route"

warnings, errors = doOsInitForBuild()

Expand Down
12 changes: 12 additions & 0 deletions vpn/openvpn/mi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"time"

"github.com/ivpn/desktop-app-daemon/logger"
"github.com/ivpn/desktop-app-daemon/service/platform"
"github.com/ivpn/desktop-app-daemon/vpn"
)

Expand Down Expand Up @@ -200,6 +201,9 @@ func (i *ManagementInterface) miCommunication() {
mesLogRouteAddCmdRegexp := regexp.MustCompile(".*route(.exe)?[ \t]+add[ \t]+.*([0-9]{1,3}[.]){3,3}[0-9]{1,3}.*([0-9]{1,3}[.]){3,3}[0-9]{1,3}.*")
mesLogPushReplyCmdRegexp := regexp.MustCompile(".*PUSH.*'PUSH_REPLY[ ,]*(.*)'")

mesLogRouteAddCmdRegexpOvpn45 := regexp.MustCompile(".*net_route_v4_add:[ \t]+(([0-9]{1,3}[.]){3,3}[0-9]{1,3}(\\/[0-9]+)?[ \t]+.*[ \t]+([0-9]{1,3}[.]){3,3}[0-9]{1,3}).*")
routeCommandOvpn45 := platform.RouteCommand()

if i.miConn == nil {
i.log.Panic("INTERNAL ERROR: OpenVPN MI connection is null!")
}
Expand Down Expand Up @@ -250,6 +254,14 @@ func (i *ManagementInterface) miCommunication() {
// /sbin/route add -net 128.0.0.0 10.57.40.1 128.0.0.0
if mesLogRouteAddCmdRegexp.MatchString(cmdStr) {
i.addRouteAddCommand(cmdStr)
} else if len(routeCommandOvpn45) > 0 {
// OpenVPN >= 4.5:
// Routing log format was changed since OpenVPN 4.5
// LOG:1607410951,,net_route_v4_add: 193.203.48.54/32 via 192.168.1.1 dev [NULL] table 0 metric -1
submaches := mesLogRouteAddCmdRegexpOvpn45.FindStringSubmatch(cmdStr)
if len(submaches) >= 2 {
i.addRouteAddCommand(fmt.Sprint(routeCommandOvpn45, " ", submaches[1]))
}
}
} else {
// LOG:1586341059,,PUSH: Received control message: 'PUSH_REPLY,redirect-gateway def1,explicit-exit-notify 3,comp-lzo no,route-gateway 10.34.44.1,topology subnet,ping 10,ping-restart 60,dhcp-option DNS 10.34.44.1,ifconfig 10.34.44.19 255.255.252.0,peer-id 17,cipher AES-256-GCM'
Expand Down

0 comments on commit bc000e1

Please sign in to comment.