@@ -18,6 +18,7 @@ import (
18
18
"github.com/containernetworking/plugins/pkg/ns"
19
19
"github.com/containernetworking/plugins/pkg/utils/sysctl"
20
20
"github.com/vishvananda/netlink"
21
+ "golang.org/x/sys/unix"
21
22
"k8s.io/apimachinery/pkg/types"
22
23
"k8s.io/klog/v2"
23
24
@@ -481,7 +482,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
481
482
482
483
ipDelMap := make (map [string ]netlink.Addr )
483
484
ipAddMap := make (map [string ]netlink.Addr )
484
- ipAddrs , err := netlink .AddrList (nodeLink , 0x0 )
485
+ ipAddrs , err := netlink .AddrList (nodeLink , unix . AF_UNSPEC )
485
486
if err != nil {
486
487
return fmt .Errorf ("can not get addr %s: %v" , nodeLink , err )
487
488
}
@@ -490,7 +491,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
490
491
// skip 169.254.0.0/16 and fe80::/10
491
492
continue
492
493
}
493
- ipDelMap [ipAddr .IP . String () + "/" + ipAddr . Mask .String ()] = ipAddr
494
+ ipDelMap [ipAddr .IPNet .String ()] = ipAddr
494
495
}
495
496
496
497
for _ , ipStr := range strings .Split (ip , "," ) {
@@ -507,12 +508,13 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
507
508
ipAddMap [ipStr ] = * ipAddr
508
509
}
509
510
510
- for _ , addr := range ipDelMap {
511
+ for ip , addr := range ipDelMap {
512
+ klog .Infof ("delete ip address %s on %s" , ip , link )
511
513
if err = netlink .AddrDel (nodeLink , & addr ); err != nil {
512
514
return fmt .Errorf ("delete address %s: %v" , addr , err )
513
515
}
514
516
}
515
- for _ , addr := range ipAddMap {
517
+ for ip , addr := range ipAddMap {
516
518
if detectIPConflict && addr .IP .To4 () != nil {
517
519
ip := addr .IP .String ()
518
520
mac , err := util .ArpDetectIPConflict (link , ip , macAddr )
@@ -526,6 +528,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
526
528
}
527
529
}
528
530
531
+ klog .Infof ("add ip address %s to %s" , ip , link )
529
532
if err = netlink .AddrAdd (nodeLink , & addr ); err != nil {
530
533
return fmt .Errorf ("can not add address %v to nic %s: %v" , addr , link , err )
531
534
}
@@ -926,7 +929,7 @@ func configureAdditionalNic(link, ip string) error {
926
929
// skip 169.254.0.0/16 and fe80::/10
927
930
continue
928
931
}
929
- ipDelMap [ipAddr .IP . String () + "/" + ipAddr . Mask .String ()] = ipAddr
932
+ ipDelMap [ipAddr .IPNet .String ()] = ipAddr
930
933
}
931
934
932
935
for _ , ipStr := range strings .Split (ip , "," ) {
0 commit comments