Check for cloned routes only on MacOS

BSD doesn't have support for cloned flags
This commit is contained in:
Maycon Santos
2024-06-11 12:21:57 +02:00
parent 4f3aa8d420
commit cf58c185ce
3 changed files with 15 additions and 1 deletions
+7
View File
@@ -0,0 +1,7 @@
//go:build dragonfly || freebsd || netbsd || openbsd
package netroute
func skipCloned(_ int, _ *rtInfo) bool {
return false
}
+7
View File
@@ -0,0 +1,7 @@
package netroute
import "syscall"
func skipCloned(flags int, routeInfo *rtInfo) bool {
return flags&syscall.RTF_CLONING != 0 && routeInfo.Dst.String() == "0.0.0.0/0" && routeInfo.Gateway == nil
}
+1 -1
View File
@@ -115,7 +115,7 @@ func New() (routing.Router, error) {
routeInfo.OutputIface = uint32(m.Index)
// skipping cloned default routes without gateway to avoid choosing a invalid default route
if m.Flags&syscall.RTF_CLONING != 0 && routeInfo.Dst.String() == "0.0.0.0/0" && routeInfo.Gateway == nil {
if skipCloned(m.Flags, routeInfo) {
log.Tracef("skipping cloned default route without gateway: src: %s, dst: %s, interface idx: %d", routeInfo.Src, routeInfo.Dst, routeInfo.OutputIface)
continue
}