This commit is contained in:
Siyuan 2025-10-10 13:48:54 +00:00
parent b3ce961b79
commit e47442d701
2 changed files with 17 additions and 0 deletions

View File

@ -444,12 +444,22 @@ func (nm *NetlinkManager) ReconcileLink(link *Link, expected []types.IPAddress,
expectedGateways := make(map[string]net.IP) expectedGateways := make(map[string]net.IP)
mtu := link.Attrs().MTU
expectedMTU := mtu
// add all expected addresses to the map // add all expected addresses to the map
for _, addr := range expected { for _, addr := range expected {
expectedAddrs[addr.String()] = &addr expectedAddrs[addr.String()] = &addr
if addr.Gateway != nil { if addr.Gateway != nil {
expectedGateways[addr.String()] = addr.Gateway expectedGateways[addr.String()] = addr.Gateway
} }
if addr.MTU != 0 {
mtu = addr.MTU
}
}
if expectedMTU != mtu {
if err := link.SetMTU(expectedMTU); err != nil {
nm.logger.Warn().Err(err).Int("expected_mtu", expectedMTU).Int("mtu", mtu).Msg("failed to set MTU")
}
} }
addrs, err := nm.AddrList(link, family) addrs, err := nm.AddrList(link, family)

View File

@ -118,6 +118,13 @@ func (l *Link) AddrList(family int) ([]netlink.Addr, error) {
return netlink.AddrList(l.Link, family) return netlink.AddrList(l.Link, family)
} }
func (l *Link) SetMTU(mtu int) error {
l.mu.Lock()
defer l.mu.Unlock()
return netlink.LinkSetMTU(l.Link, mtu)
}
// HasGlobalUnicastAddress returns true if the link has a global unicast address // HasGlobalUnicastAddress returns true if the link has a global unicast address
func (l *Link) HasGlobalUnicastAddress() bool { func (l *Link) HasGlobalUnicastAddress() bool {
addrs, err := l.AddrList(AfUnspec) addrs, err := l.AddrList(AfUnspec)