Skip to content

Commit

Permalink
ignore all link local unicast addresses/routes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Apr 7, 2022
1 parent 9be5734 commit 94bc208
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
12 changes: 8 additions & 4 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int) error {
return fmt.Errorf("can not get addr %s: %v", nodeLink, err)
}
for _, ipAddr := range ipAddrs {
if strings.HasPrefix(ipAddr.IP.String(), "fe80::") {
if ipAddr.IP.IsLinkLocalUnicast() {
// skip 169.254.0.0/16 and fe80::/10
continue
}
ipDelMap[ipAddr.IP.String()+"/"+ipAddr.Mask.String()] = ipAddr
Expand Down Expand Up @@ -711,7 +712,8 @@ func configProviderNic(nicName, brName string) (int, error) {
}
for _, scope := range scopeOrders {
for _, route := range routes {
if route.Gw == nil && route.Dst != nil && route.Dst.String() == "fe80::/64" {
if route.Gw == nil && route.Dst != nil && route.Dst.IP.IsLinkLocalUnicast() {
// skip 169.254.0.0/16 and fe80::/10
continue
}
if route.Scope == scope {
Expand Down Expand Up @@ -814,7 +816,8 @@ func removeProviderNic(nicName, brName string) error {
}
for _, scope := range scopeOrders {
for _, route := range routes {
if route.Gw == nil && route.Dst != nil && route.Dst.String() == "fe80::/64" {
if route.Gw == nil && route.Dst != nil && route.Dst.IP.IsLinkLocalUnicast() {
// skip 169.254.0.0/16 and fe80::/10
continue
}
if route.Scope == scope {
Expand Down Expand Up @@ -1010,7 +1013,8 @@ func configureAdditionalNic(link, ip string) error {
return fmt.Errorf("can not get addr %s %v", nodeLink, err)
}
for _, ipAddr := range ipAddrs {
if strings.HasPrefix(ipAddr.IP.String(), "fe80::") {
if ipAddr.IP.IsLinkLocalUnicast() {
// skip 169.254.0.0/16 and fe80::/10
continue
}
ipDelMap[ipAddr.IP.String()+"/"+ipAddr.Mask.String()] = ipAddr
Expand Down
21 changes: 14 additions & 7 deletions test/e2e-underlay-single-nic/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,10 @@ var _ = Describe("[Underlay Node]", func() {
var hasAddr bool
for _, s := range strings.Split(stdout, "\n") {
if s = strings.TrimSpace(s); strings.HasPrefix(s, "inet ") || strings.HasPrefix(s, "inet6 ") {
if strings.HasPrefix(s, "inet6 ") {
_, ipnet, err := net.ParseCIDR(strings.Fields(s)[1])
Expect(err).NotTo(HaveOccurred())
if ipnet.String() == "fe80::/64" {
continue
}
ip, _, err := net.ParseCIDR(strings.Fields(s)[1])
Expect(err).NotTo(HaveOccurred())
if ip.IsLinkLocalUnicast() {
continue
}
hasAddr = true
break
Expand Down Expand Up @@ -209,10 +207,19 @@ var _ = Describe("[Underlay Node]", func() {

var hasRoute bool
for _, s := range strings.Split(stdout, "\n") {
if s == "" || strings.HasPrefix(s, "fe80::/64 ") {
if s = strings.TrimSpace(s); s == "" {
continue
}

if !strings.HasPrefix(s, "default ") {
addr := strings.Split(strings.Fields(s)[0], "/")[0]
ip := net.ParseIP(addr)
Expect(ip).NotTo(BeNil())
if ip.IsLinkLocalUnicast() {
continue
}
}

hasRoute = true
break
}
Expand Down

0 comments on commit 94bc208

Please sign in to comment.