Skip to content

Commit

Permalink
Fix up destination MAC of auto-egress-ip packets
Browse files Browse the repository at this point in the history
Also, one final OVS flow fix for egress IPs
  • Loading branch information
danwinship committed Oct 31, 2017
1 parent c4d53a2 commit 286af89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/network/node/ovscontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import (

"k8s.io/apimachinery/pkg/util/sets"
kapi "k8s.io/kubernetes/pkg/api"

"github.com/vishvananda/netlink"
)

type ovsController struct {
ovs ovs.Interface
pluginId int
useConnTrack bool
localIP string
tunMAC string
}

const (
Expand Down Expand Up @@ -83,6 +86,13 @@ 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()

Expand All @@ -94,6 +104,7 @@ func (oc *ovsController) SetupOVS(clusterNetworkCIDR []string, serviceNetworkCID
for _, clusterCIDR := range clusterNetworkCIDR {
otx.AddFlow("table=0, priority=200, in_port=1, arp, nw_src=%s, nw_dst=%s, actions=move:NXM_NX_TUN_ID[0..31]->NXM_NX_REG0[],goto_table:10", clusterCIDR, localSubnetCIDR)
otx.AddFlow("table=0, priority=200, in_port=1, ip, nw_src=%s, actions=move:NXM_NX_TUN_ID[0..31]->NXM_NX_REG0[],goto_table:10", clusterCIDR)
otx.AddFlow("table=0, priority=200, in_port=1, ip, nw_dst=%s, actions=move:NXM_NX_TUN_ID[0..31]->NXM_NX_REG0[],goto_table:10", clusterCIDR)
}
otx.AddFlow("table=0, priority=150, in_port=1, actions=drop")
// tun0
Expand Down Expand Up @@ -693,7 +704,7 @@ 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
otx.AddFlow("table=100, priority=100, reg0=%d, ip, actions=set_field:%s->pkt_mark,output:2", vnid, egressHex)
otx.AddFlow("table=100, priority=100, reg0=%d, ip, actions=set_field:%s->eth_dst,set_field:%s->pkt_mark,output:2", vnid, oc.tunMAC, egressHex)
} else {
// Remote Egress IP; send via VXLAN
otx.AddFlow("table=100, priority=100, reg0=%d, ip, actions=move:NXM_NX_REG0[]->NXM_NX_TUN_ID[0..31],set_field:%s->tun_dst,output:1", vnid, nodeIP)
Expand Down
1 change: 1 addition & 0 deletions pkg/network/node/ovscontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
func setupOVSController(t *testing.T) (ovs.Interface, *ovsController, []string) {
ovsif := ovs.NewFake(Br0)
oc := NewOVSController(ovsif, 0, true, "172.17.0.4")
oc.tunMAC = "c6:ac:2c:13:48:4b"
err := oc.SetupOVS([]string{"10.128.0.0/14"}, "172.30.0.0/16", "10.128.0.0/23", "10.128.0.1")
if err != nil {
t.Fatalf("Unexpected error setting up OVS: %v", err)
Expand Down

0 comments on commit 286af89

Please sign in to comment.