@@ -52,12 +52,6 @@ func createPodInterface(netconf *NetworkConfig) error {
5252 nameData := nl .NewRtAttr (unix .IFLA_IFNAME , nl .ZeroTerminated (iifName ))
5353 req .AddData (nameData )
5454
55- // set MTU if defined
56- if netconf .MTU > 0 {
57- mtuData := nl .NewRtAttr (unix .IFLA_MTU , nl .Uint32Attr (uint32 (netconf .MTU )))
58- req .AddData (mtuData )
59- }
60-
6155 // base namespace is the container namespace
6256 val := nl .Uint32Attr (uint32 (containerNs ))
6357 attr := nl .NewRtAttr (unix .IFLA_NET_NS_FD , val )
@@ -152,7 +146,18 @@ func createPodInterface(netconf *NetworkConfig) error {
152146
153147 // set metadata on the alias field with the pod name and namespace
154148 if netconf .Name != "" {
155- _ = nhRoot .LinkSetAlias (hostLink , fmt .Sprintf ("%s/%s" , netconf .Namespace , netconf .Name ))
149+ err = nhRoot .LinkSetAlias (hostLink , fmt .Sprintf ("link-pod %s/%s" , netconf .Namespace , netconf .Name ))
150+ if err != nil {
151+ logger .Printf ("could not set interface %s alias : %v" , oofName , err )
152+ }
153+ }
154+
155+ // set MTU if defined
156+ if netconf .MTU > 0 {
157+ err = nhRoot .LinkSetMTU (hostLink , netconf .MTU )
158+ if err != nil {
159+ return fmt .Errorf ("could not set interface %s mtu : %w" , oofName , err )
160+ }
156161 }
157162
158163 if err = nhRoot .LinkSetUp (hostLink ); err != nil {
@@ -296,25 +301,7 @@ func getDefaultGwInterfaceMTU() int {
296301 }
297302
298303 for _ , r := range routes {
299- // no multipath
300- if len (r .MultiPath ) == 0 {
301- if r .Gw == nil {
302- continue
303- }
304- intfLink , err := netlink .LinkByIndex (r .LinkIndex )
305- if err != nil {
306- logger .Printf ("Failed to get interface link for route %v : %v" , r , err )
307- continue
308- }
309- return intfLink .Attrs ().MTU
310- }
311-
312- // multipath, use the first valid entry
313- // xref: https://github.com/vishvananda/netlink/blob/6ffafa9fc19b848776f4fd608c4ad09509aaacb4/route.go#L137-L145
314- for _ , nh := range r .MultiPath {
315- if nh .Gw == nil {
316- continue
317- }
304+ if r .Dst .IP .Equal (net .IPv4zero ) || r .Dst .IP .Equal (net .IPv6zero ) {
318305 intfLink , err := netlink .LinkByIndex (r .LinkIndex )
319306 if err != nil {
320307 logger .Printf ("Failed to get interface link for route %v : %v" , r , err )
0 commit comments