From d216a5ca5829a7543c16c364680250ad12c1a410 Mon Sep 17 00:00:00 2001 From: Casey Davenport Date: Wed, 15 Apr 2020 17:11:50 -0700 Subject: [PATCH 1/2] Fix VXLAN race condition --- calc/vxlan_resolver.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/calc/vxlan_resolver.go b/calc/vxlan_resolver.go index 9e13566e36..ac351e8920 100644 --- a/calc/vxlan_resolver.go +++ b/calc/vxlan_resolver.go @@ -183,6 +183,9 @@ func (c *VXLANResolver) OnResourceUpdate(update api.Update) (_ bool) { logCxt := logrus.WithField("node", nodeName).WithField("update", update) logCxt.Debug("OnResourceUpdate triggered") if update.Value != nil && update.Value.(*apiv3.Node).Spec.BGP != nil { + // Calculate the pending and sent sets before adding 'node' to nodeNameToNode. + pendingSet, sentSet := c.routeSets() + node := update.Value.(*apiv3.Node) bgp := node.Spec.BGP c.nodeNameToNode[nodeName] = node @@ -192,7 +195,7 @@ func (c *VXLANResolver) OnResourceUpdate(update api.Update) (_ bool) { return } - c.onNodeIPUpdate(nodeName, ipv4.String()) + c.onNodeIPUpdate(nodeName, ipv4.String(), pendingSet, sentSet) } else { delete(c.nodeNameToNode, nodeName) c.onRemoveNode(nodeName) @@ -210,20 +213,20 @@ func (c *VXLANResolver) OnHostIPUpdate(update api.Update) (_ bool) { logrus.WithField("node", nodeName).Debug("OnHostIPUpdate triggered") if update.Value != nil { - c.onNodeIPUpdate(nodeName, update.Value.(*cnet.IP).String()) + pendingSet, sentSet := c.routeSets() + c.onNodeIPUpdate(nodeName, update.Value.(*cnet.IP).String(), pendingSet, sentSet) } else { c.onRemoveNode(nodeName) } return } -func (c *VXLANResolver) onNodeIPUpdate(nodeName string, newIP string) { +func (c *VXLANResolver) onNodeIPUpdate(nodeName string, newIP string, pendingSet set.Set, sentSet set.Set) { logCxt := logrus.WithField("node", nodeName) // Host IP updated or added. If it was added, we should check to see if we're ready // to send a VTEP and associated routes. If we already knew about this one, we need to // see if it has changed. If it has, we should remove and reprogram the VTEP and routes. currIP := c.nodeNameToIPAddr[nodeName] - pendingSet, sentSet := c.routeSets() logCxt = logCxt.WithFields(logrus.Fields{"newIP": newIP, "currIP": currIP}) if c.vtepSent(nodeName) { if currIP == newIP { From c55f425984fb38763fef9c21c45fa3b69d88503a Mon Sep 17 00:00:00 2001 From: Casey Davenport Date: Wed, 15 Apr 2020 17:15:17 -0700 Subject: [PATCH 2/2] Remove unused constant in test --- bpf/ut/bpf_prog_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bpf/ut/bpf_prog_test.go b/bpf/ut/bpf_prog_test.go index f2c03ffaae..dfc2ac535c 100644 --- a/bpf/ut/bpf_prog_test.go +++ b/bpf/ut/bpf_prog_test.go @@ -60,9 +60,8 @@ func init() { // Constants that are shared with the UT binaries that we build. const ( - natTunnelMTU = uint16(700) - ethernetHeaderSize = 14 - testVxlanPort = uint16(5665) + natTunnelMTU = uint16(700) + testVxlanPort = uint16(5665) ) var (