mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-26 18:13:40 +01:00
fdd23d4644
Most operating systems add a /32 route for the default gateway address to its routing table This will allow routes to be configured into the system even when the incoming range contains the default gateway. In case a range is a sub-range of an existing route and this range happens to contain the default gateway it attempts to create a default gateway route to prevent loop issues
42 lines
797 B
Go
42 lines
797 B
Go
//go:build !linux
|
|
// +build !linux
|
|
|
|
package routemanager
|
|
|
|
import (
|
|
"net/netip"
|
|
"os/exec"
|
|
"runtime"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func addToRouteTable(prefix netip.Prefix, addr string) error {
|
|
cmd := exec.Command("route", "add", prefix.String(), addr)
|
|
out, err := cmd.Output()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Debugf(string(out))
|
|
return nil
|
|
}
|
|
|
|
func removeFromRouteTable(prefix netip.Prefix, addr string) error {
|
|
args := []string{"delete", prefix.String()}
|
|
if runtime.GOOS == "darwin" {
|
|
args = append(args, addr)
|
|
}
|
|
cmd := exec.Command("route", args...)
|
|
out, err := cmd.Output()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Debugf(string(out))
|
|
return nil
|
|
}
|
|
|
|
func enableIPForwarding() error {
|
|
log.Infof("enable IP forwarding is not implemented on %s", runtime.GOOS)
|
|
return nil
|
|
}
|