Skip to content

Commit

Permalink
node: Fix CIDR comparison when updating routes
Browse files Browse the repository at this point in the history
Previously, the CIDR comparison didn't take into account the CIDR mask.
So, if IP didn't change, but the mask did, the comparison would have not
detected the change. The result of it was that old routes could not be
removed.

Fixes: c7a83bf ("datapath/linux: New scalable routing layer via Linux datapath implementation")
Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Martynas Pumputis <m@lambda.lt>
  • Loading branch information
brb authored and aanm committed Mar 11, 2021
1 parent 912792b commit 508b2de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/datapath/linux/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func updateTunnelMapping(oldCIDR, newCIDR *cidr.CIDR, oldIP, newIP net.IP, first
case newCIDR == nil && oldCIDR != nil:
fallthrough
// Node allocation CIDR has changed
case oldCIDR != nil && newCIDR != nil && !oldCIDR.IP.Equal(newCIDR.IP):
case oldCIDR != nil && newCIDR != nil && !oldCIDR.Equal(newCIDR):
deleteTunnelMapping(oldCIDR, false)
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func cidrNodeMappingUpdateRequired(oldCIDR, newCIDR *cidr.CIDR, oldIP, newIP net
}

// CIDR changed
return !oldCIDR.IP.Equal(newCIDR.IP)
return !oldCIDR.Equal(newCIDR)
}

func deleteTunnelMapping(oldCIDR *cidr.CIDR, quietMode bool) {
Expand Down Expand Up @@ -264,7 +264,7 @@ func (n *linuxNodeHandler) updateDirectRoute(oldCIDR, newCIDR *cidr.CIDR, oldIP,
case !oldIP.Equal(newIP):
fallthrough
// Node allocation CIDR has changed
case oldCIDR != nil && newCIDR != nil && !oldCIDR.IP.Equal(newCIDR.IP):
case oldCIDR != nil && newCIDR != nil && !oldCIDR.Equal(newCIDR):
n.deleteDirectRoute(oldCIDR, oldIP)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/datapath/linux/node_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func lookupDirectRoute(CIDR *cidr.CIDR, nodeIP net.IP) ([]netlink.Route, error)

func (s *linuxPrivilegedBaseTestSuite) TestNodeUpdateDirectRouting(c *check.C) {
ip4Alloc1 := cidr.MustParseCIDR("5.5.5.0/24")
ip4Alloc2 := cidr.MustParseCIDR("6.6.6.0/24")
ip4Alloc2 := cidr.MustParseCIDR("5.5.5.0/26")

externalNode1IP4v1 := net.ParseIP("4.4.4.4")
externalNode1IP4v2 := net.ParseIP("4.4.4.5")
Expand Down Expand Up @@ -700,6 +700,7 @@ func (s *linuxPrivilegedBaseTestSuite) TestNodeUpdateDirectRouting(c *check.C) {
},
IPv4AllocCIDR: ip4Alloc1,
}

err = linuxNodeHandler.NodeUpdate(nodev1, nodev2)
c.Assert(err, check.IsNil)

Expand Down

0 comments on commit 508b2de

Please sign in to comment.