Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use primary interface to add iptables for connmark entry #305

Merged
merged 2 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 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"
mogren marked this conversation as resolved.
Show resolved Hide resolved
if n.nodePortSupportEnabled {

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

if err != nil {
return errors.Wrapf(err, "failed to SetupHostNetwork")
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