11package main
22
33import (
4+ "code.cloudfoundry.org/lib/common"
5+ "code.cloudfoundry.org/lib/rules"
46 "flag"
57 "log"
68 "sync"
7- "time"
8-
9- "code.cloudfoundry.org/lib/rules"
109
1110 "code.cloudfoundry.org/filelock"
1211 "github.com/coreos/go-iptables/iptables"
1312)
1413
1514const (
16- ClientTimeout = 5 * time .Second
17- IngressChainName = "istio-ingress"
18- jobPrefix = "silk-daemon-bootstrap"
19- logPrefix = "cfnetworking"
20- MAX_RETRIES = 15
15+ MaxRetries = 15
2116)
2217
2318func main () {
2419 lockFilePath := flag .String ("lock-file" , "" , "path to iptables file" )
2520 flag .Parse ()
2621
27- ipTablesAdapter , err := createIpTablesAdapter (* lockFilePath )
22+ ipTablesAdapter , err := createIpTablesAdapter (* lockFilePath , false )
2823 if err != nil {
29- log .Fatalf ("Could not initialize iptables adapter: %s" , err )
24+ log .Fatalf ("Could not initialize ip4tables adapter: %s" , err )
3025 }
3126
3227 err = PreStart (ipTablesAdapter )
3328 if err != nil {
34- log .Fatalf ("pre-start failed after %d attempts - giving up" , MAX_RETRIES )
29+ log .Fatalf ("pre-start failed after %d attempts - giving up" , MaxRetries )
30+ }
31+
32+ if common .IsIPv6Enabled () {
33+ ipTablesAdapter , err = createIpTablesAdapter (* lockFilePath , false )
34+ if err != nil {
35+ log .Fatalf ("Could not initialize ip6tables adapter: %s" , err )
36+ }
37+
38+ err = PreStart (ipTablesAdapter )
39+ if err != nil {
40+ log .Fatalf ("pre-start failed after %d attempts - giving up" , MaxRetries )
41+ }
3542 }
3643}
3744
3845func PreStart (ipTablesAdapter rules.IPTablesAdapter ) error {
3946 var err error
40- for i := 0 ; i < MAX_RETRIES ; i ++ {
47+ for i := 0 ; i < MaxRetries ; i ++ {
4148 err = ipTablesAdapter .FlushAndRestore (`*filter
4249:INPUT ACCEPT [0:0]
4350:FORWARD ACCEPT [0:0]
@@ -59,8 +66,16 @@ COMMIT
5966 return err
6067}
6168
62- func createIpTablesAdapter (iptablesLockFile string ) (rules.IPTablesAdapter , error ) {
63- ipt , err := iptables .New ()
69+ func createIpTablesAdapter (iptablesLockFile string , ipv6 bool ) (rules.IPTablesAdapter , error ) {
70+ var ipt * iptables.IPTables
71+ var err error
72+
73+ if ipv6 {
74+ ipt , err = iptables .NewWithProtocol (iptables .ProtocolIPv6 )
75+ } else {
76+ ipt , err = iptables .New ()
77+ }
78+
6479 if err != nil {
6580 return nil , err
6681 }
@@ -70,10 +85,14 @@ func createIpTablesAdapter(iptablesLockFile string) (rules.IPTablesAdapter, erro
7085 Mutex : & sync.Mutex {},
7186 }
7287
88+ restorer := & rules.Restorer {
89+ IPv6 : ipv6 ,
90+ }
91+
7392 tables := & rules.LockedIPTables {
7493 IPTables : ipt ,
7594 Locker : iptLocker ,
76- Restorer : & rules. Restorer {} ,
95+ Restorer : restorer ,
7796 }
7897
7998 return tables , nil
0 commit comments