Skip to content

Commit 8060719

Browse files
vxlan-policy-agent: pre-start ipv6 support
1 parent 9b1158b commit 8060719

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

src/code.cloudfoundry.org/vxlan-policy-agent/cmd/pre-start/main.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11
package main
22

33
import (
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

1514
const (
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

2318
func 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

3845
func 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

src/code.cloudfoundry.org/vxlan-policy-agent/cmd/pre-start/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var _ = Describe("Pre-Start", func() {
3131
It("retries up to MAX_RETRIES times", func() {
3232
err := main.PreStart(fakeIpTables)
3333
Expect(err).To(HaveOccurred())
34-
Expect(fakeIpTables.FlushAndRestoreCallCount()).To(Equal(main.MAX_RETRIES))
34+
Expect(fakeIpTables.FlushAndRestoreCallCount()).To(Equal(main.MaxRetries))
3535

3636
})
3737

0 commit comments

Comments
 (0)