Skip to content

Commit

Permalink
Merge pull request #305 from nak3/use-primintf
Browse files Browse the repository at this point in the history
Use primary interface to add iptables for connmark entry
  • Loading branch information
mogren authored Jan 31, 2019
2 parents 646c120 + bda446e commit 8f55c72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pkg/networkutils/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ func (n *linuxNetwork) SetupHostNetwork(vpcCIDR *net.IPNet, vpcCIDRs []*string,
return errors.Wrapf(err, "host network setup: failed to delete old host rule")
}

primaryIntf := "eth0"
if n.nodePortSupportEnabled {

primaryIntf, err := findPrimaryInterfaceName(primaryMAC)
primaryIntf, err = findPrimaryInterfaceName(primaryMAC)

if err != nil {
return errors.Wrapf(err, "failed to SetupHostNetwork")
Expand All @@ -229,7 +230,7 @@ func (n *linuxNetwork) SetupHostNetwork(vpcCIDR *net.IPNet, vpcCIDRs []*string,
log.Debugf("Setting RPF for primary interface: %s", primaryIntfRPFilter)
err = n.setProcSys(primaryIntfRPFilter, rpFilterLoose)
if err != nil {
return errors.Wrapf(err, "failed to configure eth0 RPF check")
return errors.Wrapf(err, "failed to configure %s RPF check", primaryIntf)
}
}

Expand Down Expand Up @@ -350,7 +351,7 @@ func (n *linuxNetwork) SetupHostNetwork(vpcCIDR *net.IPNet, vpcCIDRs []*string,
chain: "PREROUTING",
rule: []string{
"-m", "comment", "--comment", "AWS, primary ENI",
"-i", "eth0",
"-i", primaryIntf,
"-m", "addrtype", "--dst-type", "LOCAL", "--limit-iface-in",
"-j", "CONNMARK", "--set-mark", fmt.Sprintf("%#x/%#x", n.mainENIMark, n.mainENIMark),
},
Expand Down
9 changes: 7 additions & 2 deletions pkg/networkutils/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,20 @@ func TestSetupHostNetworkNodePortEnabled(t *testing.T) {
mockNetLink.EXPECT().RuleAdd(&mainENIRule)

var vpcCIDRs []*string
err := ln.SetupHostNetwork(testENINetIPNet, vpcCIDRs, "", &testENINetIP)

// loopback for primary device is a little bit hacky. But the test is stable and it should be
// OK for test purpose.
LoopBackMac := ""

err := ln.SetupHostNetwork(testENINetIPNet, vpcCIDRs, LoopBackMac, &testENINetIP)
assert.NoError(t, err)

assert.Equal(t, map[string]map[string][][]string{
"mangle": {
"PREROUTING": [][]string{
{
"-m", "comment", "--comment", "AWS, primary ENI",
"-i", "eth0",
"-i", "lo",
"-m", "addrtype", "--dst-type", "LOCAL", "--limit-iface-in",
"-j", "CONNMARK", "--set-mark", "0x80/0x80",
},
Expand Down

0 comments on commit 8f55c72

Please sign in to comment.