Skip to content

Commit a7d6a6b

Browse files
authored
enable ipv6 in boshSysctl (#347)
1 parent dae5611 commit a7d6a6b

File tree

2 files changed

+82
-8
lines changed

2 files changed

+82
-8
lines changed

platform/net/kernel_ipv6.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,30 @@ func NewKernelIPv6Impl(fs boshsys.FileSystem, cmdRunner boshsys.CmdRunner, logge
2424

2525
func (net KernelIPv6Impl) Enable(stopCh <-chan struct{}) error {
2626
const (
27-
grubConfPathBIOS = "/boot/grub/grub.cfg"
28-
grubConfPathEFI = "/boot/efi/EFI/grub/grub.cfg"
29-
grubIPv6DisableOpt = "ipv6.disable=1"
27+
grubConfPathBIOS = "/boot/grub/grub.cfg"
28+
grubConfPathEFI = "/boot/efi/EFI/grub/grub.cfg"
29+
grubIPv6DisableOpt = "ipv6.disable=1"
30+
boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"
31+
sysctlIpv6AllDisableOpt = "net.ipv6.conf.all.disable_ipv6=1"
32+
sysctlIpv6DefaultDisableOpt = "net.ipv6.conf.default.disable_ipv6=1"
33+
sysctlIpv6AllEnableOpt = "net.ipv6.conf.all.disable_ipv6=0"
34+
sysctlIpv6DefaultEnableOpt = "net.ipv6.conf.default.disable_ipv6=0"
3035
)
3136

37+
boshSysctl, err := net.fs.ReadFileString(boshSysctlPath)
38+
if err != nil {
39+
return bosherr.WrapError(err, "Reading boshSysctl")
40+
}
41+
42+
if strings.Contains(boshSysctl, sysctlIpv6AllDisableOpt) {
43+
boshSysctl = strings.ReplaceAll(boshSysctl, sysctlIpv6AllDisableOpt, sysctlIpv6AllEnableOpt)
44+
boshSysctl = strings.ReplaceAll(boshSysctl, sysctlIpv6DefaultDisableOpt, sysctlIpv6DefaultEnableOpt)
45+
err = net.fs.WriteFileString(boshSysctlPath, boshSysctl)
46+
if err != nil {
47+
return bosherr.WrapError(err, "Writing boshSysctl")
48+
}
49+
}
50+
3251
grubConfPath := grubConfPathBIOS
3352

3453
grubConf, err := net.fs.ReadFileString(grubConfPath)

platform/net/kernel_ipv6_test.go

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ var _ = Describe("KernelIPv6", func() {
3838

3939
When("grub.cfg disables IPv6", func() {
4040
When("grub path is /boot/grub/grub.cfg", func() {
41+
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"
4142
const grubPath = "/boot/grub/grub.cfg"
43+
4244
BeforeEach(func() {
43-
err := fs.WriteFileString(grubPath, "before ipv6.disable=1 after")
45+
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
46+
Expect(err).ToNot(HaveOccurred())
47+
48+
err = fs.WriteFileString(grubPath, "before ipv6.disable=1 after")
4449
Expect(err).ToNot(HaveOccurred())
4550
})
4651

@@ -55,6 +60,7 @@ var _ = Describe("KernelIPv6", func() {
5560
Expect(act()).ToNot(HaveOccurred())
5661
Expect(cmdRunner.RunCommands).To(Equal([][]string{{"shutdown", "-r", "now"}}))
5762
})
63+
5864
It("returns an error if update to "+grubPath+" fails", func() {
5965
fs.WriteFileError = errors.New("fake-err")
6066

@@ -72,11 +78,45 @@ var _ = Describe("KernelIPv6", func() {
7278
Expect(err).To(HaveOccurred())
7379
Expect(err.Error()).To(ContainSubstring("fake-err"))
7480
})
81+
82+
When("60-bosh-sysctl.conf disables IPv6", func() {
83+
It("changes net.ipv6.conf.all.disable_ipv6=1 to net.ipv6.conf.all.disable_ipv6=0 from "+boshSysctlPath, func() {
84+
stopCh <- struct{}{}
85+
Expect(act()).ToNot(HaveOccurred())
86+
Expect(fs.ReadFileString(boshSysctlPath)).To(Equal("net.ipv6.conf.all.disable_ipv6=0\nnet.ipv6.conf.default.disable_ipv6=0"))
87+
})
88+
})
89+
90+
When("60-bosh-sysctl.conf enables IPv6", func() {
91+
BeforeEach(func() {
92+
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=0\nnet.ipv6.conf.default.disable_ipv6=0")
93+
Expect(err).ToNot(HaveOccurred())
94+
})
95+
96+
It("does not change "+boshSysctlPath, func() {
97+
stopCh <- struct{}{}
98+
Expect(act()).ToNot(HaveOccurred())
99+
Expect(fs.ReadFileString(boshSysctlPath)).To(Equal("net.ipv6.conf.all.disable_ipv6=0\nnet.ipv6.conf.default.disable_ipv6=0"))
100+
})
101+
})
75102
})
103+
104+
When("60-bosh-sysctl.conf does not exist", func() {
105+
It("returns an error", func() {
106+
err := act()
107+
Expect(err).To(HaveOccurred())
108+
})
109+
})
110+
76111
When("grub path is /boot/efi/EFI/grub/grub.cfg", func() {
112+
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"
77113
const grubPath = "/boot/efi/EFI/grub/grub.cfg"
114+
78115
BeforeEach(func() {
79-
err := fs.WriteFileString(grubPath, "before ipv6.disable=1 after")
116+
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
117+
Expect(err).ToNot(HaveOccurred())
118+
119+
err = fs.WriteFileString(grubPath, "before ipv6.disable=1 after")
80120
Expect(err).ToNot(HaveOccurred())
81121
})
82122

@@ -112,8 +152,13 @@ var _ = Describe("KernelIPv6", func() {
112152
})
113153

114154
When("/boot/grub/grub.cfg doesn't exist but /boot/efi/EFI/grub/grub.cfg does", func() {
155+
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"
156+
115157
BeforeEach(func() {
116-
err := fs.WriteFileString("/boot/efi/EFI/grub/grub.cfg", "before ipv6.disable=1 after")
158+
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
159+
Expect(err).ToNot(HaveOccurred())
160+
161+
err = fs.WriteFileString("/boot/efi/EFI/grub/grub.cfg", "before ipv6.disable=1 after")
117162
Expect(err).ToNot(HaveOccurred())
118163
})
119164
It("does not return an error if it fails to read /boot/grub/grub.cfg", func() {
@@ -129,8 +174,13 @@ var _ = Describe("KernelIPv6", func() {
129174
})
130175

131176
When("neither /boot/grub/grub.cfg nor /boot/efi/EFI/grub/grub.cfg exists", func() {
177+
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"
178+
132179
It("returns an error", func() {
133-
err := act()
180+
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
181+
Expect(err).ToNot(HaveOccurred())
182+
183+
err = act()
134184
Expect(err).To(HaveOccurred())
135185
})
136186
})
@@ -140,8 +190,13 @@ var _ = Describe("KernelIPv6", func() {
140190
"/boot/efi/EFI/grub/grub.cfg",
141191
} {
142192
When(grubPath+" allows IPv6", func() {
193+
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"
194+
143195
BeforeEach(func() {
144-
err := fs.WriteFileString(grubPath, "before after")
196+
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
197+
Expect(err).ToNot(HaveOccurred())
198+
199+
err = fs.WriteFileString(grubPath, "before after")
145200
Expect(err).ToNot(HaveOccurred())
146201
})
147202

0 commit comments

Comments
 (0)