Skip to content

Commit

Permalink
fix gateway detection
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Dec 10, 2024
1 parent 9894bee commit a51cc80
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hostinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ func gatherHostInfo() (hi HostInfo, e error) {
logEntry.Error("netlink.LinkByIndex error", zap.Error(e))
return hi, nil
}

routes, e := nl.RouteList(link, unix.AF_INET6)
if e != nil {
logEntry.Error("netlink.RouteList error", zap.Error(e))
return hi, nil
}

for _, route := range routes {
if route.Dst == nil {
maskLen := 0
if route.Dst != nil {
maskLen, _ = route.Dst.Mask.Size()
}
if maskLen == 0 {
hi.GatewayIP, _ = netip.AddrFromSlice(route.Gw)
}
}
Expand Down

0 comments on commit a51cc80

Please sign in to comment.