Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix network break on kube-ovn-cni startup #2272

Merged
merged 1 commit into from
Jan 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions pkg/daemon/ovs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/utils/sysctl"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -488,7 +489,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo

ipDelMap := make(map[string]netlink.Addr)
ipAddMap := make(map[string]netlink.Addr)
ipAddrs, err := netlink.AddrList(nodeLink, 0x0)
ipAddrs, err := netlink.AddrList(nodeLink, unix.AF_UNSPEC)
if err != nil {
return fmt.Errorf("can not get addr %s: %v", nodeLink, err)
}
Expand All @@ -497,7 +498,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
// skip 169.254.0.0/16 and fe80::/10
continue
}
ipDelMap[ipAddr.IP.String()+"/"+ipAddr.Mask.String()] = ipAddr
ipDelMap[ipAddr.IPNet.String()] = ipAddr
}

for _, ipStr := range strings.Split(ip, ",") {
Expand All @@ -514,12 +515,13 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
ipAddMap[ipStr] = *ipAddr
}

for _, addr := range ipDelMap {
for ip, addr := range ipDelMap {
klog.Infof("delete ip address %s on %s", ip, link)

Check failure

Code scanning / CodeQL

Log entries created from user input

This log entry depends on a [user-provided value](1).
if err = netlink.AddrDel(nodeLink, &addr); err != nil {
return fmt.Errorf("delete address %s: %v", addr, err)
}
}
for _, addr := range ipAddMap {
for ip, addr := range ipAddMap {
if detectIPConflict && addr.IP.To4() != nil {
ip := addr.IP.String()
mac, err := util.ArpDetectIPConflict(link, ip, macAddr)
Expand All @@ -533,6 +535,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
}
}

klog.Infof("add ip address %s to %s", ip, link)

Check failure

Code scanning / CodeQL

Log entries created from user input

This log entry depends on a [user-provided value](1).
if err = netlink.AddrAdd(nodeLink, &addr); err != nil {
return fmt.Errorf("can not add address %v to nic %s: %v", addr, link, err)
}
Expand Down Expand Up @@ -932,7 +935,7 @@ func configureAdditionalNic(link, ip string) error {
// skip 169.254.0.0/16 and fe80::/10
continue
}
ipDelMap[ipAddr.IP.String()+"/"+ipAddr.Mask.String()] = ipAddr
ipDelMap[ipAddr.IPNet.String()] = ipAddr
}

for _, ipStr := range strings.Split(ip, ",") {
Expand Down