Skip to content

Commit 3d6bf6e

Browse files
committed
Fix MTU detection to work with netlink v1.3.1
The vendor dependency update in the previous commit pulled in netlink v1.3.1 which changed how default routes are represented. In v1.1.0, default routes had route.Dst == nil, but in v1.3.1+, they have route.Dst set to 0.0.0.0/0 (IPv4) or ::/0 (IPv6). The existing code checked "if route.Dst != nil { continue }" to skip non-default routes, which incorrectly skipped default routes with the new netlink version, causing "unable to determine MTU" errors. This fix updates the default route detection logic to handle both: - Old behavior (v1.1.0): route.Dst == nil - New behavior (v1.3.1+): route.Dst == 0.0.0.0/0 or ::/0 The fix checks if Dst is nil OR if it represents a default route by verifying the IP is all zeros and the prefix length is 0. Signed-off-by: zhaozhanqi <zzhao@redhat.com>
1 parent f7dbde0 commit 3d6bf6e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/network/mtu.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package network
55

66
import (
77
"fmt"
8+
"net"
9+
810
"github.com/pkg/errors"
911
"github.com/vishvananda/netlink"
1012
)
@@ -30,8 +32,19 @@ func GetDefaultMTU() (int, error) {
3032
const maxMTU = 65536
3133
mtu := maxMTU + 1
3234
for _, route := range routes {
33-
// Skip non-default routes
35+
// Check if this is a default route
36+
// In netlink v1.1.0: default routes have Dst == nil
37+
// In netlink v1.3.1+: default routes have Dst == 0.0.0.0/0 or ::/0
38+
isDefault := route.Dst == nil
3439
if route.Dst != nil {
40+
// Check if Dst represents a default route (0.0.0.0/0 or ::/0)
41+
ones, _ := route.Dst.Mask.Size()
42+
ip := route.Dst.IP
43+
isDefault = (ip.Equal(net.IPv4zero) || ip.Equal(net.IPv6zero)) && ones == 0
44+
}
45+
46+
// Skip non-default routes
47+
if !isDefault {
3548
continue
3649
}
3750
if route.LinkIndex == 0 {

0 commit comments

Comments
 (0)