@@ -33,14 +33,17 @@ import (
33
33
utiltrace "k8s.io/utils/trace"
34
34
)
35
35
36
+ // RulePosition holds the -I/-A flags for iptable
36
37
type RulePosition string
37
38
38
39
const (
40
+ // Prepend is the insert flag for iptable
39
41
Prepend RulePosition = "-I"
40
- Append RulePosition = "-A"
42
+ // Append is the append flag for iptable
43
+ Append RulePosition = "-A"
41
44
)
42
45
43
- // An injectable interface for running iptables commands. Implementations must be goroutine-safe.
46
+ // Interface is an injectable interface for running iptables commands. Implementations must be goroutine-safe.
44
47
type Interface interface {
45
48
// EnsureChain checks if the specified chain exists and, if not, creates it. If the chain existed, return true.
46
49
EnsureChain (table Table , chain Chain ) (bool , error )
@@ -83,29 +86,42 @@ type Interface interface {
83
86
HasRandomFully () bool
84
87
}
85
88
89
+ // Protocol defines the ip protocol either ipv4 or ipv6
86
90
type Protocol byte
87
91
88
92
const (
93
+ // ProtocolIpv4 represents ipv4 protocol in iptables
89
94
ProtocolIpv4 Protocol = iota + 1
95
+ // ProtocolIpv6 represents ipv6 protocol in iptables
90
96
ProtocolIpv6
91
97
)
92
98
99
+ // Table represents different iptable like filter,nat, mangle and raw
93
100
type Table string
94
101
95
102
const (
96
- TableNAT Table = "nat"
103
+ // TableNAT represents the built-in nat table
104
+ TableNAT Table = "nat"
105
+ // TableFilter represents the built-in filter table
97
106
TableFilter Table = "filter"
107
+ // TableMangle represents the built-in mangle table
98
108
TableMangle Table = "mangle"
99
109
)
100
110
111
+ // Chain represents the different rules
101
112
type Chain string
102
113
103
114
const (
115
+ // ChainPostrouting used for source NAT in nat table
104
116
ChainPostrouting Chain = "POSTROUTING"
105
- ChainPrerouting Chain = "PREROUTING"
106
- ChainOutput Chain = "OUTPUT"
107
- ChainInput Chain = "INPUT"
108
- ChainForward Chain = "FORWARD"
117
+ // ChainPrerouting used for DNAT (destination NAT) in nat table
118
+ ChainPrerouting Chain = "PREROUTING"
119
+ // ChainOutput used for the packets going out from local
120
+ ChainOutput Chain = "OUTPUT"
121
+ // ChainInput used for incoming packets
122
+ ChainInput Chain = "INPUT"
123
+ // ChainForward used for the packets for another NIC
124
+ ChainForward Chain = "FORWARD"
109
125
)
110
126
111
127
const (
@@ -117,32 +133,49 @@ const (
117
133
cmdIP6Tables string = "ip6tables"
118
134
)
119
135
120
- // Option flag for Restore
136
+ // RestoreCountersFlag is an option flag for Restore
121
137
type RestoreCountersFlag bool
122
138
139
+ // RestoreCounters a boolean true constant for the option flag RestoreCountersFlag
123
140
const RestoreCounters RestoreCountersFlag = true
141
+
142
+ // NoRestoreCounters a boolean false constant for the option flag RestoreCountersFlag
124
143
const NoRestoreCounters RestoreCountersFlag = false
125
144
126
- // Option flag for Flush
145
+ // FlushFlag an option flag for Flush
127
146
type FlushFlag bool
128
147
148
+ // FlushTables a boolean true constant for option flag FlushFlag
129
149
const FlushTables FlushFlag = true
150
+
151
+ // NoFlushTables a boolean false constant for option flag FlushFlag
130
152
const NoFlushTables FlushFlag = false
131
153
154
+ // MinCheckVersion minimum version to be checked
132
155
// Versions of iptables less than this do not support the -C / --check flag
133
156
// (test whether a rule exists).
134
157
var MinCheckVersion = utilversion .MustParseGeneric ("1.4.11" )
135
158
159
+ // RandomFullyMinVersion is the minimum version from which the --random-fully flag is supported,
160
+ // used for port mapping to be fully randomized
136
161
var RandomFullyMinVersion = utilversion .MustParseGeneric ("1.6.2" )
137
162
138
- // Minimum iptables versions supporting the -w and -w<seconds> flags
163
+ // WaitMinVersion a minimum iptables versions supporting the -w and -w<seconds> flags
139
164
var WaitMinVersion = utilversion .MustParseGeneric ("1.4.20" )
165
+
166
+ // WaitSecondsMinVersion a minimum iptables versions supporting the wait seconds
140
167
var WaitSecondsMinVersion = utilversion .MustParseGeneric ("1.4.22" )
168
+
169
+ // WaitRestoreMinVersion a minimum iptables versions supporting the wait restore seconds
141
170
var WaitRestoreMinVersion = utilversion .MustParseGeneric ("1.6.2" )
142
171
172
+ // WaitString a constant for specifying the wait flag
143
173
const WaitString = "-w"
174
+
175
+ // WaitSecondsValue a constant for specifying the default wait seconds
144
176
const WaitSecondsValue = "5"
145
177
178
+ // LockfilePath16x is the iptables lock file acquired by any process that's making any change in the iptable rule
146
179
const LockfilePath16x = "/run/xtables.lock"
147
180
148
181
// runner implements Interface in terms of exec("iptables").
@@ -706,7 +739,6 @@ const iptablesStatusResourceProblem = 4
706
739
func isResourceError (err error ) bool {
707
740
if ee , isExitError := err .(utilexec.ExitError ); isExitError {
708
741
return ee .ExitStatus () == iptablesStatusResourceProblem
709
- } else {
710
- return false
711
742
}
743
+ return false
712
744
}
0 commit comments