Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions plugins/meta/portmap/portmap_iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,15 @@ func genToplevelDnatChain() chain {

// genDnatChain creates the per-container chain.
// Conditions are any static entry conditions for the chain.
// Entry rules are prepended within CNI-HOSTPORT-DNAT so that the most recent
// container using a host port wins without moving CNI-HOSTPORT-DNAT ahead of
// Kubernetes service rules in PREROUTING/OUTPUT.
func genDnatChain(netName, containerID string) chain {
return chain{
table: "nat",
name: utils.MustFormatChainNameWithPrefix(netName, containerID, "DN-"),
entryChains: []string{TopLevelDNATChainName},
table: "nat",
name: utils.MustFormatChainNameWithPrefix(netName, containerID, "DN-"),
entryChains: []string{TopLevelDNATChainName},
prependEntry: true,
}
}

Expand Down
21 changes: 12 additions & 9 deletions plugins/meta/portmap/portmap_iptables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ var _ = Describe("portmapping configuration (iptables)", func() {
ch := genDnatChain(netName, containerID)

Expect(ch).To(Equal(chain{
table: "nat",
name: "CNI-DN-bfd599665540dd91d5d28",
entryChains: []string{TopLevelDNATChainName},
table: "nat",
name: "CNI-DN-bfd599665540dd91d5d28",
entryChains: []string{TopLevelDNATChainName},
prependEntry: true,
}))
configBytes := []byte(fmt.Sprintf(`{
"name": "test",
Expand Down Expand Up @@ -69,9 +70,10 @@ var _ = Describe("portmapping configuration (iptables)", func() {

ch = genDnatChain(conf.Name, containerID)
Expect(ch).To(Equal(chain{
table: "nat",
name: "CNI-DN-67e92b96e692a494b6b85",
entryChains: []string{"CNI-HOSTPORT-DNAT"},
table: "nat",
name: "CNI-DN-67e92b96e692a494b6b85",
entryChains: []string{"CNI-HOSTPORT-DNAT"},
prependEntry: true,
}))

n, err := types.ParseCIDR("10.0.0.2/24")
Expand Down Expand Up @@ -171,9 +173,10 @@ var _ = Describe("portmapping configuration (iptables)", func() {
ch := genDnatChain(netName, containerID)

Expect(ch).To(Equal(chain{
table: "nat",
name: "CNI-DN-bfd599665540dd91d5d28",
entryChains: []string{TopLevelDNATChainName},
table: "nat",
name: "CNI-DN-bfd599665540dd91d5d28",
entryChains: []string{TopLevelDNATChainName},
prependEntry: true,
}))
configBytes := []byte(fmt.Sprintf(`{
"name": "test",
Expand Down
Loading