@@ -186,9 +186,12 @@ const WaitIntervalString = "-W"
186
186
// WaitIntervalUsecondsValue a constant for specifying the default wait interval useconds
187
187
const WaitIntervalUsecondsValue = "100000"
188
188
189
- // LockfilePath16x is the iptables lock file acquired by any process that's making any change in the iptable rule
189
+ // LockfilePath16x is the iptables 1.6.x lock file acquired by any process that's making any change in the iptable rule
190
190
const LockfilePath16x = "/run/xtables.lock"
191
191
192
+ // LockfilePath14x is the iptables 1.4.x lock file acquired by any process that's making any change in the iptable rule
193
+ const LockfilePath14x = "@xtables"
194
+
192
195
// runner implements Interface in terms of exec("iptables").
193
196
type runner struct {
194
197
mu sync.Mutex
@@ -198,20 +201,24 @@ type runner struct {
198
201
hasRandomFully bool
199
202
waitFlag []string
200
203
restoreWaitFlag []string
201
- lockfilePath string
204
+ lockfilePath14x string
205
+ lockfilePath16x string
202
206
}
203
207
204
208
// newInternal returns a new Interface which will exec iptables, and allows the
205
209
// caller to change the iptables-restore lockfile path
206
- func newInternal (exec utilexec.Interface , protocol Protocol , lockfilePath string ) Interface {
210
+ func newInternal (exec utilexec.Interface , protocol Protocol , lockfilePath14x , lockfilePath16x string ) Interface {
207
211
version , err := getIPTablesVersion (exec , protocol )
208
212
if err != nil {
209
213
klog .Warningf ("Error checking iptables version, assuming version at least %s: %v" , MinCheckVersion , err )
210
214
version = MinCheckVersion
211
215
}
212
216
213
- if lockfilePath == "" {
214
- lockfilePath = LockfilePath16x
217
+ if lockfilePath16x == "" {
218
+ lockfilePath16x = LockfilePath16x
219
+ }
220
+ if lockfilePath14x == "" {
221
+ lockfilePath14x = LockfilePath14x
215
222
}
216
223
217
224
runner := & runner {
@@ -221,14 +228,15 @@ func newInternal(exec utilexec.Interface, protocol Protocol, lockfilePath string
221
228
hasRandomFully : version .AtLeast (RandomFullyMinVersion ),
222
229
waitFlag : getIPTablesWaitFlag (version ),
223
230
restoreWaitFlag : getIPTablesRestoreWaitFlag (version , exec , protocol ),
224
- lockfilePath : lockfilePath ,
231
+ lockfilePath14x : lockfilePath14x ,
232
+ lockfilePath16x : lockfilePath16x ,
225
233
}
226
234
return runner
227
235
}
228
236
229
237
// New returns a new Interface which will exec iptables.
230
238
func New (exec utilexec.Interface , protocol Protocol ) Interface {
231
- return newInternal (exec , protocol , "" )
239
+ return newInternal (exec , protocol , "" , "" )
232
240
}
233
241
234
242
// EnsureChain is part of Interface.
@@ -390,7 +398,7 @@ func (runner *runner) restoreInternal(args []string, data []byte, flush FlushFla
390
398
// from stepping on each other. iptables-restore 1.6.2 will have
391
399
// a --wait option like iptables itself, but that's not widely deployed.
392
400
if len (runner .restoreWaitFlag ) == 0 {
393
- locker , err := grabIptablesLocks (runner .lockfilePath )
401
+ locker , err := grabIptablesLocks (runner .lockfilePath14x , runner . lockfilePath16x )
394
402
if err != nil {
395
403
return err
396
404
}
0 commit comments