mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-07 04:20:12 +02:00
chore(all): make code compilable for other platforms than Linux
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/netlink"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var ErrRouteDefaultNotFound = errors.New("default route not found")
|
||||
@@ -30,7 +29,7 @@ func (r *Routing) DefaultRoutes() (defaultRoutes []DefaultRoute, err error) {
|
||||
}
|
||||
|
||||
for _, route := range routes {
|
||||
if route.Table != unix.RT_TABLE_MAIN {
|
||||
if route.Table != tableMain {
|
||||
// ignore non-main table
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/netlink"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -48,7 +47,7 @@ func (r *Routing) LocalNetworks() (localNetworks []LocalNetwork, err error) {
|
||||
}
|
||||
|
||||
for _, route := range routes {
|
||||
if route.Table != unix.RT_TABLE_MAIN ||
|
||||
if route.Table != tableMain ||
|
||||
(route.Gw.IsValid() && !route.Gw.IsUnspecified()) ||
|
||||
(route.Dst.IsValid() && route.Dst.Addr().IsUnspecified()) {
|
||||
continue
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package routing
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
const (
|
||||
tableMain = unix.RT_TABLE_MAIN
|
||||
tableLocal = unix.RT_TABLE_LOCAL
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
//go:build !linux
|
||||
|
||||
package routing
|
||||
|
||||
const (
|
||||
tableMain = 0
|
||||
tableLocal = 0
|
||||
)
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/netlink"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -35,7 +34,7 @@ func (r *Routing) VPNLocalGatewayIP(vpnIntf string) (ip netip.Addr, err error) {
|
||||
return route.Gw, nil
|
||||
case route.Dst.IsSingleIP() &&
|
||||
route.Dst.Addr().Compare(route.Src) == 0 &&
|
||||
route.Table == unix.RT_TABLE_LOCAL: // Wireguard
|
||||
route.Table == tableLocal: // Wireguard
|
||||
route.Src = route.Src.Unmap()
|
||||
if route.Src.Is6() {
|
||||
return netip.Addr{}, fmt.Errorf("%w: %s", ErrVPNLocalGatewayIPv6NotSupported, route.Src)
|
||||
|
||||
Reference in New Issue
Block a user