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
2f1edf7d
Commit
2f1edf7d
authored
Aug 20, 2015
by
Saad Ali
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12839 from difro/archaic_iptables
Fix dup rule generation with older iptables
parents
3f66648a
837edf85
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
iptables.go
pkg/util/iptables/iptables.go
+12
-15
No files found.
pkg/util/iptables/iptables.go
View file @
2f1edf7d
...
...
@@ -330,12 +330,15 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
return
false
,
fmt
.
Errorf
(
"error checking rule: %v"
,
err
)
}
// Sadly, iptables has inconsistent quoting rules for comments.
// Just unquote any arg that is wrapped in quotes.
argsCopy
:=
make
([]
string
,
len
(
args
))
copy
(
argsCopy
,
args
)
for
i
:=
range
argsCopy
{
unquote
(
&
argsCopy
[
i
])
// Sadly, iptables has inconsistent quoting rules for comments. Just remove all quotes.
// Also, quoted multi-word comments (which are counted as a single arg)
// will be unpacked into multiple args,
// in order to compare against iptables-save output (which will be split at whitespace boundary)
// e.g. a single arg('"this must be before the NodePort rules"') will be unquoted and unpacked into 7 args.
var
argsCopy
[]
string
for
i
:=
range
args
{
tmpField
:=
strings
.
Trim
(
args
[
i
],
"
\"
"
)
argsCopy
=
append
(
argsCopy
,
strings
.
Fields
(
tmpField
)
...
)
}
argset
:=
util
.
NewStringSet
(
argsCopy
...
)
...
...
@@ -344,14 +347,14 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
// Check that this is a rule for the correct chain, and that it has
// the correct number of argument (+2 for "-A <chain name>")
if
!
strings
.
HasPrefix
(
line
,
fmt
.
Sprintf
(
"-A %s"
,
string
(
chain
)))
||
len
(
fields
)
!=
len
(
args
)
+
2
{
if
!
strings
.
HasPrefix
(
line
,
fmt
.
Sprintf
(
"-A %s"
,
string
(
chain
)))
||
len
(
fields
)
!=
len
(
args
Copy
)
+
2
{
continue
}
// Sadly, iptables has inconsistent quoting rules for comments.
// Just
unquote any arg that is wrapped in
quotes.
// Just
remove all
quotes.
for
i
:=
range
fields
{
unquote
(
&
fields
[
i
]
)
fields
[
i
]
=
strings
.
Trim
(
fields
[
i
],
"
\"
"
)
}
// TODO: This misses reorderings e.g. "-x foo ! -y bar" will match "! -x foo -y bar"
...
...
@@ -364,12 +367,6 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
return
false
,
nil
}
func
unquote
(
strp
*
string
)
{
if
len
(
*
strp
)
>=
2
&&
(
*
strp
)[
0
]
==
'"'
&&
(
*
strp
)[
len
(
*
strp
)
-
1
]
==
'"'
{
*
strp
=
strings
.
TrimPrefix
(
strings
.
TrimSuffix
(
*
strp
,
`"`
),
`"`
)
}
}
// Executes the rule check using the "-C" flag
func
(
runner
*
runner
)
checkRuleUsingCheck
(
args
[]
string
)
(
bool
,
error
)
{
out
,
err
:=
runner
.
run
(
opCheckRule
,
args
)
...
...
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