From cf58c185ce49000dbb1434839f05b42e13236f54 Mon Sep 17 00:00:00 2001 From: Maycon Santos Date: Tue, 11 Jun 2024 12:21:57 +0200 Subject: [PATCH] Check for cloned routes only on MacOS BSD doesn't have support for cloned flags --- clonedcheck_bsd.go | 7 +++++++ clonedcheck_darwin.go | 7 +++++++ netroute_bsd.go | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 clonedcheck_bsd.go create mode 100644 clonedcheck_darwin.go diff --git a/clonedcheck_bsd.go b/clonedcheck_bsd.go new file mode 100644 index 0000000..b362a8b --- /dev/null +++ b/clonedcheck_bsd.go @@ -0,0 +1,7 @@ +//go:build dragonfly || freebsd || netbsd || openbsd + +package netroute + +func skipCloned(_ int, _ *rtInfo) bool { + return false +} diff --git a/clonedcheck_darwin.go b/clonedcheck_darwin.go new file mode 100644 index 0000000..1f54ea2 --- /dev/null +++ b/clonedcheck_darwin.go @@ -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 +} diff --git a/netroute_bsd.go b/netroute_bsd.go index cabf3dd..707601b 100644 --- a/netroute_bsd.go +++ b/netroute_bsd.go @@ -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 }