Skip to content

Commit 7f756b4

Browse files
champtarsqueed
authored andcommitted
portmap: fix iptables conditions detection
As show in the docs, iptables conditions can also start with '!' Fixes 01a94e1 Signed-off-by: Etienne Champetier <[email protected]>
1 parent 3ffc42c commit 7f756b4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

plugins/meta/portmap/main.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,11 @@ func detectBackendOfConditions(conditions *[]string) string {
349349
return ""
350350
}
351351

352-
// The first token of any iptables condition would start with a hyphen (e.g. "-d",
353-
// "--sport", "-m"). No nftables condition would start that way. (An nftables
354-
// condition might include a negative number, but not as the first token.)
355-
if (*conditions)[0][0] == '-' {
352+
// The first character of any iptables condition would either be an hyphen
353+
// (e.g. "-d", "--sport", "-m") or an exclamation mark.
354+
// No nftables condition would start that way. (An nftables condition might
355+
// include a negative number, but not as the first token.)
356+
if (*conditions)[0][0] == '-' || (*conditions)[0][0] == '!' {
356357
return iptablesBackend
357358
}
358359
return nftablesBackend

plugins/meta/portmap/portmap_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var _ = Describe("portmapping configuration", func() {
4444
},
4545
"snat": false,
4646
"conditionsV4": ["-s", "1.2.3.4"],
47-
"conditionsV6": ["-s", "12::34"],
47+
"conditionsV6": ["!", "-s", "12::34"],
4848
"prevResult": {
4949
"interfaces": [
5050
{"name": "host"},
@@ -76,7 +76,7 @@ var _ = Describe("portmapping configuration", func() {
7676
Expect(err).NotTo(HaveOccurred())
7777
Expect(c.CNIVersion).To(Equal(ver))
7878
Expect(c.ConditionsV4).To(Equal(&[]string{"-s", "1.2.3.4"}))
79-
Expect(c.ConditionsV6).To(Equal(&[]string{"-s", "12::34"}))
79+
Expect(c.ConditionsV6).To(Equal(&[]string{"!", "-s", "12::34"}))
8080
fvar := false
8181
Expect(c.SNAT).To(Equal(&fvar))
8282
Expect(c.Name).To(Equal("test"))

0 commit comments

Comments
 (0)