Skip to content

Commit 4518c2c

Browse files
newTrafficManager skeleton
1 parent 1b6bb82 commit 4518c2c

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

main.go

+21-20
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,7 @@ func main() {
337337
}
338338

339339
//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()
344341
// Set up ipMasq if needed
345342
if opts.ipMasq {
346343
if config.EnableIPv4 {
@@ -351,22 +348,22 @@ func main() {
351348
wg.Wait()
352349
os.Exit(1)
353350
}
354-
if err = recycleIPTables(iptm, net, bn.Lease()); err != nil {
351+
if err = recycleIPTables(trafficMngr, net, bn.Lease()); err != nil {
355352
log.Errorf("Failed to recycle IPTables rules, %v", err)
356353
cancel()
357354
wg.Wait()
358355
os.Exit(1)
359356
}
360357
log.Infof("Setting up masking rules")
361-
iptm.CreateIP4Chain("nat", "FLANNEL-POSTRTG")
358+
trafficMngr.CreateIP4Chain("nat", "FLANNEL-POSTRTG")
362359
getRules := func() []trafficmngr.IPTablesRule {
363360
if config.HasNetworks() {
364-
return iptm.MasqRules(config.Networks, bn.Lease())
361+
return trafficMngr.MasqRules(config.Networks, bn.Lease())
365362
} else {
366-
return iptm.MasqRules([]ip.IP4Net{config.Network}, bn.Lease())
363+
return trafficMngr.MasqRules([]ip.IP4Net{config.Network}, bn.Lease())
367364
}
368365
}
369-
go iptm.SetupAndEnsureIP4Tables(getRules, opts.iptablesResyncSeconds)
366+
go trafficMngr.SetupAndEnsureIP4Tables(getRules, opts.iptablesResyncSeconds)
370367

371368
}
372369
if config.EnableIPv6 {
@@ -377,22 +374,22 @@ func main() {
377374
wg.Wait()
378375
os.Exit(1)
379376
}
380-
if err = recycleIP6Tables(iptm, ip6net, bn.Lease()); err != nil {
377+
if err = recycleIP6Tables(trafficMngr, ip6net, bn.Lease()); err != nil {
381378
log.Errorf("Failed to recycle IP6Tables rules, %v", err)
382379
cancel()
383380
wg.Wait()
384381
os.Exit(1)
385382
}
386383
log.Infof("Setting up masking ip6 rules")
387-
iptm.CreateIP6Chain("nat", "FLANNEL-POSTRTG")
384+
trafficMngr.CreateIP6Chain("nat", "FLANNEL-POSTRTG")
388385
getRules := func() []trafficmngr.IPTablesRule {
389386
if config.HasIPv6Networks() {
390-
return iptm.MasqIP6Rules(config.IPv6Networks, bn.Lease())
387+
return trafficMngr.MasqIP6Rules(config.IPv6Networks, bn.Lease())
391388
} else {
392-
return iptm.MasqIP6Rules([]ip.IP6Net{config.IPv6Network}, bn.Lease())
389+
return trafficMngr.MasqIP6Rules([]ip.IP6Net{config.IPv6Network}, bn.Lease())
393390
}
394391
}
395-
go iptm.SetupAndEnsureIP6Tables(getRules, opts.iptablesResyncSeconds)
392+
go trafficMngr.SetupAndEnsureIP6Tables(getRules, opts.iptablesResyncSeconds)
396393
}
397394
}
398395

@@ -409,11 +406,11 @@ func main() {
409406
os.Exit(1)
410407
}
411408
log.Infof("Changing default FORWARD chain policy to ACCEPT")
412-
iptm.CreateIP4Chain("filter", "FLANNEL-FWD")
409+
trafficMngr.CreateIP4Chain("filter", "FLANNEL-FWD")
413410
getRules := func() []trafficmngr.IPTablesRule {
414-
return iptm.ForwardRules(net.String())
411+
return trafficMngr.ForwardRules(net.String())
415412
}
416-
go iptm.SetupAndEnsureIP4Tables(getRules, opts.iptablesResyncSeconds)
413+
go trafficMngr.SetupAndEnsureIP4Tables(getRules, opts.iptablesResyncSeconds)
417414
}
418415
if config.EnableIPv6 {
419416
ip6net, err := config.GetFlannelIPv6Network(&bn.Lease().IPv6Subnet)
@@ -424,11 +421,11 @@ func main() {
424421
os.Exit(1)
425422
}
426423
log.Infof("IPv6: Changing default FORWARD chain policy to ACCEPT")
427-
iptm.CreateIP6Chain("filter", "FLANNEL-FWD")
424+
trafficMngr.CreateIP6Chain("filter", "FLANNEL-FWD")
428425
getRules := func() []trafficmngr.IPTablesRule {
429-
return iptm.ForwardRules(ip6net.String())
426+
return trafficMngr.ForwardRules(ip6net.String())
430427
}
431-
go iptm.SetupAndEnsureIP6Tables(getRules, opts.iptablesResyncSeconds)
428+
go trafficMngr.SetupAndEnsureIP6Tables(getRules, opts.iptablesResyncSeconds)
432429
}
433430
}
434431

@@ -662,3 +659,7 @@ func ReadIP6CIDRsFromSubnetFile(path string, CIDRKey string) []ip.IP6Net {
662659
}
663660
return prevCIDRs
664661
}
662+
663+
func newTrafficManager() trafficmngr.TrafficManager {
664+
return iptables.IPTablesManager{}
665+
}

0 commit comments

Comments
 (0)