From f40ccbc04cfe8098fc2a2d42f82bb52d22e71937 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 9 Jan 2018 15:39:53 -0500 Subject: [PATCH] Make sure oc.tunMAC gets set even if AlreadySetUp() --- pkg/network/node/ovscontroller.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pkg/network/node/ovscontroller.go b/pkg/network/node/ovscontroller.go index c98a673cb72f..7356536f429b 100644 --- a/pkg/network/node/ovscontroller.go +++ b/pkg/network/node/ovscontroller.go @@ -18,8 +18,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" kapi "k8s.io/kubernetes/pkg/apis/core" - - "github.com/vishvananda/netlink" ) type ovsController struct { @@ -87,13 +85,6 @@ func (oc *ovsController) SetupOVS(clusterNetworkCIDR []string, serviceNetworkCID if err != nil { return err } - if oc.tunMAC == "" { - link, err := netlink.LinkByName(Tun0) - if err != nil { - return err - } - oc.tunMAC = link.Attrs().HardwareAddr.String() - } otx := oc.ovs.NewTransaction() @@ -675,6 +666,21 @@ func (oc *ovsController) FindUnusedVNIDs() []int { return policyVNIDs.Difference(inUseVNIDs).UnsortedList() } +func (oc *ovsController) ensureTunMAC() error { + if oc.tunMAC != "" { + return nil + } + + val, err := oc.ovs.Get("Interface", Tun0, "mac_in_use") + if err != nil { + return fmt.Errorf("could not get %s MAC address: %v", Tun0, err) + } else if len(val) != 19 || val[0] != '"' || val[18] != '"' { + return fmt.Errorf("bad MAC address for %s: %q", Tun0, val) + } + oc.tunMAC = val[1:18] + return nil +} + func (oc *ovsController) UpdateNamespaceEgressRules(vnid uint32, nodeIP, egressHex string) error { otx := oc.ovs.NewTransaction() otx.DeleteFlows("table=100, reg0=%d", vnid) @@ -686,6 +692,9 @@ func (oc *ovsController) UpdateNamespaceEgressRules(vnid uint32, nodeIP, egressH otx.AddFlow("table=100, priority=100, reg0=%d, actions=drop", vnid) } else if nodeIP == oc.localIP { // Local Egress IP + if err := oc.ensureTunMAC(); err != nil { + return err + } otx.AddFlow("table=100, priority=100, reg0=%d, ip, actions=set_field:%s->eth_dst,set_field:%s->pkt_mark,goto_table:101", vnid, oc.tunMAC, egressHex) } else { // Remote Egress IP; send via VXLAN