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
b1470b66
Commit
b1470b66
authored
Dec 02, 2014
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
strip quotes in back-compat iptables
parent
7d9a7218
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
8 deletions
+30
-8
iptables.go
pkg/util/iptables/iptables.go
+30
-8
No files found.
pkg/util/iptables/iptables.go
View file @
b1470b66
...
@@ -187,7 +187,8 @@ func (runner *runner) checkRule(table Table, chain Chain, args ...string) (bool,
...
@@ -187,7 +187,8 @@ func (runner *runner) checkRule(table Table, chain Chain, args ...string) (bool,
}
}
// 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.
// Present for compatibility with <1.4.11 versions of iptables. This is full
// of hack and half-measures. We should nix this ASAP.
func
(
runner
*
runner
)
checkRuleWithoutCheck
(
table
Table
,
chain
Chain
,
args
...
string
)
(
bool
,
error
)
{
func
(
runner
*
runner
)
checkRuleWithoutCheck
(
table
Table
,
chain
Chain
,
args
...
string
)
(
bool
,
error
)
{
glog
.
V
(
1
)
.
Infof
(
"running iptables-save -t %s"
,
string
(
table
))
glog
.
V
(
1
)
.
Infof
(
"running iptables-save -t %s"
,
string
(
table
))
out
,
err
:=
runner
.
exec
.
Command
(
"iptables-save"
,
"-t"
,
string
(
table
))
.
CombinedOutput
()
out
,
err
:=
runner
.
exec
.
Command
(
"iptables-save"
,
"-t"
,
string
(
table
))
.
CombinedOutput
()
...
@@ -195,25 +196,46 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
...
@@ -195,25 +196,46 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
return
false
,
fmt
.
Errorf
(
"error checking rule: %v"
,
err
)
return
false
,
fmt
.
Errorf
(
"error checking rule: %v"
,
err
)
}
}
argset
:=
util
.
NewStringSet
(
args
...
)
// 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
])
}
argset
:=
util
.
NewStringSet
(
argsCopy
...
)
for
_
,
line
:=
range
strings
.
Split
(
string
(
out
),
"
\n
"
)
{
for
_
,
line
:=
range
strings
.
Split
(
string
(
out
),
"
\n
"
)
{
var
fields
=
strings
.
Fields
(
line
)
var
fields
=
strings
.
Fields
(
line
)
// Check that this is a rule for the correct chain, and that it has
// Check that this is a rule for the correct chain, and that it has
// the correct number of argument (+2 for "-A <chain name>")
// 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
)
+
2
{
// TODO: This misses reorderings e.g. "-x foo ! -y bar" will match "! -x foo -y bar"
continue
if
util
.
NewStringSet
(
fields
...
)
.
IsSuperset
(
argset
)
{
}
return
true
,
nil
}
// Sadly, iptables has inconsistent quoting rules for comments.
glog
.
V
(
5
)
.
Infof
(
"DBG: fields is not a superset of args: fields=%v args=%v"
,
fields
,
args
)
// Just unquote any arg that is wrapped in quotes.
for
i
:=
range
fields
{
unquote
(
&
fields
[
i
])
}
}
// TODO: This misses reorderings e.g. "-x foo ! -y bar" will match "! -x foo -y bar"
if
util
.
NewStringSet
(
fields
...
)
.
IsSuperset
(
argset
)
{
return
true
,
nil
}
glog
.
V
(
5
)
.
Infof
(
"DBG: fields is not a superset of args: fields=%v args=%v"
,
fields
,
args
)
}
}
return
false
,
nil
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
// Executes the rule check using the "-C" flag
func
(
runner
*
runner
)
checkRuleUsingCheck
(
args
[]
string
)
(
bool
,
error
)
{
func
(
runner
*
runner
)
checkRuleUsingCheck
(
args
[]
string
)
(
bool
,
error
)
{
out
,
err
:=
runner
.
run
(
opCheckRule
,
args
)
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