Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
35cc60e4
Commit
35cc60e4
authored
Nov 28, 2016
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better compat with very old iptables
Older iptables expanded things like 0x4000 into 0x00004000, which defeats the fallback "check" logic.
parent
305528d7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
iptables.go
pkg/util/iptables/iptables.go
+8
-0
iptables_test.go
pkg/util/iptables/iptables_test.go
+7
-2
No files found.
pkg/util/iptables/iptables.go
View file @
35cc60e4
...
@@ -374,6 +374,12 @@ func (runner *runner) checkRule(table Table, chain Chain, args ...string) (bool,
...
@@ -374,6 +374,12 @@ func (runner *runner) checkRule(table Table, chain Chain, args ...string) (bool,
}
}
}
}
var
hexnumRE
=
regexp
.
MustCompile
(
"0x0+([0-9])"
)
func
trimhex
(
s
string
)
string
{
return
hexnumRE
.
ReplaceAllString
(
s
,
"0x$1"
)
}
// Executes the rule check without using the "-C" flag, instead parsing iptables-save.
// Executes the rule check without using the "-C" flag, instead parsing iptables-save.
// Present for compatibility with <1.4.11 versions of iptables. This is full
// Present for compatibility with <1.4.11 versions of iptables. This is full
// of hack and half-measures. We should nix this ASAP.
// of hack and half-measures. We should nix this ASAP.
...
@@ -392,6 +398,7 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
...
@@ -392,6 +398,7 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
var
argsCopy
[]
string
var
argsCopy
[]
string
for
i
:=
range
args
{
for
i
:=
range
args
{
tmpField
:=
strings
.
Trim
(
args
[
i
],
"
\"
"
)
tmpField
:=
strings
.
Trim
(
args
[
i
],
"
\"
"
)
tmpField
=
trimhex
(
tmpField
)
argsCopy
=
append
(
argsCopy
,
strings
.
Fields
(
tmpField
)
...
)
argsCopy
=
append
(
argsCopy
,
strings
.
Fields
(
tmpField
)
...
)
}
}
argset
:=
sets
.
NewString
(
argsCopy
...
)
argset
:=
sets
.
NewString
(
argsCopy
...
)
...
@@ -409,6 +416,7 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
...
@@ -409,6 +416,7 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
// Just remove all quotes.
// Just remove all quotes.
for
i
:=
range
fields
{
for
i
:=
range
fields
{
fields
[
i
]
=
strings
.
Trim
(
fields
[
i
],
"
\"
"
)
fields
[
i
]
=
strings
.
Trim
(
fields
[
i
],
"
\"
"
)
fields
[
i
]
=
trimhex
(
fields
[
i
])
}
}
// TODO: This misses reorderings e.g. "-x foo ! -y bar" will match "! -x foo -y bar"
// TODO: This misses reorderings e.g. "-x foo ! -y bar" will match "! -x foo -y bar"
...
...
pkg/util/iptables/iptables_test.go
View file @
35cc60e4
...
@@ -470,7 +470,7 @@ func TestCheckRuleWithoutCheckPresent(t *testing.T) {
...
@@ -470,7 +470,7 @@ func TestCheckRuleWithoutCheckPresent(t *testing.T) {
:PREROUTING ACCEPT [2136997:197881818]
:PREROUTING ACCEPT [2136997:197881818]
:POSTROUTING ACCEPT [4284525:258542680]
:POSTROUTING ACCEPT [4284525:258542680]
:OUTPUT ACCEPT [5901660:357267963]
:OUTPUT ACCEPT [5901660:357267963]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A PREROUTING -m addrtype --dst-type LOCAL -
m mark --mark 0x00004000/0x00004000 -
j DOCKER
COMMIT
COMMIT
# Completed on Wed Oct 29 14:56:01 2014`
# Completed on Wed Oct 29 14:56:01 2014`
...
@@ -487,7 +487,12 @@ COMMIT
...
@@ -487,7 +487,12 @@ COMMIT
},
},
}
}
runner
:=
&
runner
{
exec
:
&
fexec
}
runner
:=
&
runner
{
exec
:
&
fexec
}
exists
,
err
:=
runner
.
checkRuleWithoutCheck
(
TableNAT
,
ChainPrerouting
,
"-m"
,
"addrtype"
,
"-j"
,
"DOCKER"
,
"--dst-type"
,
"LOCAL"
)
exists
,
err
:=
runner
.
checkRuleWithoutCheck
(
TableNAT
,
ChainPrerouting
,
"-m"
,
"addrtype"
,
"-m"
,
"mark"
,
"--mark"
,
"0x4000/0x4000"
,
"-j"
,
"DOCKER"
,
"--dst-type"
,
"LOCAL"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"expected success, got %v"
,
err
)
t
.
Errorf
(
"expected success, got %v"
,
err
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment