@@ -337,10 +337,7 @@ func main() {
337
337
}
338
338
339
339
//Create TrafficManager and instanciate it based on whether we use iptables or nftables
340
- var iptm trafficmngr.TrafficManager
341
-
342
- //For now, always use iptables
343
- iptm = iptables.IPTablesManager {}
340
+ trafficMngr := newTrafficManager ()
344
341
// Set up ipMasq if needed
345
342
if opts .ipMasq {
346
343
if config .EnableIPv4 {
@@ -351,22 +348,22 @@ func main() {
351
348
wg .Wait ()
352
349
os .Exit (1 )
353
350
}
354
- if err = recycleIPTables (iptm , net , bn .Lease ()); err != nil {
351
+ if err = recycleIPTables (trafficMngr , net , bn .Lease ()); err != nil {
355
352
log .Errorf ("Failed to recycle IPTables rules, %v" , err )
356
353
cancel ()
357
354
wg .Wait ()
358
355
os .Exit (1 )
359
356
}
360
357
log .Infof ("Setting up masking rules" )
361
- iptm .CreateIP4Chain ("nat" , "FLANNEL-POSTRTG" )
358
+ trafficMngr .CreateIP4Chain ("nat" , "FLANNEL-POSTRTG" )
362
359
getRules := func () []trafficmngr.IPTablesRule {
363
360
if config .HasNetworks () {
364
- return iptm .MasqRules (config .Networks , bn .Lease ())
361
+ return trafficMngr .MasqRules (config .Networks , bn .Lease ())
365
362
} else {
366
- return iptm .MasqRules ([]ip.IP4Net {config .Network }, bn .Lease ())
363
+ return trafficMngr .MasqRules ([]ip.IP4Net {config .Network }, bn .Lease ())
367
364
}
368
365
}
369
- go iptm .SetupAndEnsureIP4Tables (getRules , opts .iptablesResyncSeconds )
366
+ go trafficMngr .SetupAndEnsureIP4Tables (getRules , opts .iptablesResyncSeconds )
370
367
371
368
}
372
369
if config .EnableIPv6 {
@@ -377,22 +374,22 @@ func main() {
377
374
wg .Wait ()
378
375
os .Exit (1 )
379
376
}
380
- if err = recycleIP6Tables (iptm , ip6net , bn .Lease ()); err != nil {
377
+ if err = recycleIP6Tables (trafficMngr , ip6net , bn .Lease ()); err != nil {
381
378
log .Errorf ("Failed to recycle IP6Tables rules, %v" , err )
382
379
cancel ()
383
380
wg .Wait ()
384
381
os .Exit (1 )
385
382
}
386
383
log .Infof ("Setting up masking ip6 rules" )
387
- iptm .CreateIP6Chain ("nat" , "FLANNEL-POSTRTG" )
384
+ trafficMngr .CreateIP6Chain ("nat" , "FLANNEL-POSTRTG" )
388
385
getRules := func () []trafficmngr.IPTablesRule {
389
386
if config .HasIPv6Networks () {
390
- return iptm .MasqIP6Rules (config .IPv6Networks , bn .Lease ())
387
+ return trafficMngr .MasqIP6Rules (config .IPv6Networks , bn .Lease ())
391
388
} else {
392
- return iptm .MasqIP6Rules ([]ip.IP6Net {config .IPv6Network }, bn .Lease ())
389
+ return trafficMngr .MasqIP6Rules ([]ip.IP6Net {config .IPv6Network }, bn .Lease ())
393
390
}
394
391
}
395
- go iptm .SetupAndEnsureIP6Tables (getRules , opts .iptablesResyncSeconds )
392
+ go trafficMngr .SetupAndEnsureIP6Tables (getRules , opts .iptablesResyncSeconds )
396
393
}
397
394
}
398
395
@@ -409,11 +406,11 @@ func main() {
409
406
os .Exit (1 )
410
407
}
411
408
log .Infof ("Changing default FORWARD chain policy to ACCEPT" )
412
- iptm .CreateIP4Chain ("filter" , "FLANNEL-FWD" )
409
+ trafficMngr .CreateIP4Chain ("filter" , "FLANNEL-FWD" )
413
410
getRules := func () []trafficmngr.IPTablesRule {
414
- return iptm .ForwardRules (net .String ())
411
+ return trafficMngr .ForwardRules (net .String ())
415
412
}
416
- go iptm .SetupAndEnsureIP4Tables (getRules , opts .iptablesResyncSeconds )
413
+ go trafficMngr .SetupAndEnsureIP4Tables (getRules , opts .iptablesResyncSeconds )
417
414
}
418
415
if config .EnableIPv6 {
419
416
ip6net , err := config .GetFlannelIPv6Network (& bn .Lease ().IPv6Subnet )
@@ -424,11 +421,11 @@ func main() {
424
421
os .Exit (1 )
425
422
}
426
423
log .Infof ("IPv6: Changing default FORWARD chain policy to ACCEPT" )
427
- iptm .CreateIP6Chain ("filter" , "FLANNEL-FWD" )
424
+ trafficMngr .CreateIP6Chain ("filter" , "FLANNEL-FWD" )
428
425
getRules := func () []trafficmngr.IPTablesRule {
429
- return iptm .ForwardRules (ip6net .String ())
426
+ return trafficMngr .ForwardRules (ip6net .String ())
430
427
}
431
- go iptm .SetupAndEnsureIP6Tables (getRules , opts .iptablesResyncSeconds )
428
+ go trafficMngr .SetupAndEnsureIP6Tables (getRules , opts .iptablesResyncSeconds )
432
429
}
433
430
}
434
431
@@ -662,3 +659,7 @@ func ReadIP6CIDRsFromSubnetFile(path string, CIDRKey string) []ip.IP6Net {
662
659
}
663
660
return prevCIDRs
664
661
}
662
+
663
+ func newTrafficManager () trafficmngr.TrafficManager {
664
+ return iptables.IPTablesManager {}
665
+ }
0 commit comments