Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable ipv6 in boshSysctl #347

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions platform/net/kernel_ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,30 @@ func NewKernelIPv6Impl(fs boshsys.FileSystem, cmdRunner boshsys.CmdRunner, logge

func (net KernelIPv6Impl) Enable(stopCh <-chan struct{}) error {
const (
grubConfPathBIOS = "/boot/grub/grub.cfg"
grubConfPathEFI = "/boot/efi/EFI/grub/grub.cfg"
grubIPv6DisableOpt = "ipv6.disable=1"
grubConfPathBIOS = "/boot/grub/grub.cfg"
grubConfPathEFI = "/boot/efi/EFI/grub/grub.cfg"
grubIPv6DisableOpt = "ipv6.disable=1"
boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"
sysctlIpv6AllDisableOpt = "net.ipv6.conf.all.disable_ipv6=1"
sysctlIpv6DefaultDisableOpt = "net.ipv6.conf.default.disable_ipv6=1"
sysctlIpv6AllEnableOpt = "net.ipv6.conf.all.disable_ipv6=0"
sysctlIpv6DefaultEnableOpt = "net.ipv6.conf.default.disable_ipv6=0"
Comment on lines +27 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Point: #348

)

boshSysctl, err := net.fs.ReadFileString(boshSysctlPath)
if err != nil {
return bosherr.WrapError(err, "Reading boshSysctl")
}

if strings.Contains(boshSysctl, sysctlIpv6AllDisableOpt) {
boshSysctl = strings.ReplaceAll(boshSysctl, sysctlIpv6AllDisableOpt, sysctlIpv6AllEnableOpt)
boshSysctl = strings.ReplaceAll(boshSysctl, sysctlIpv6DefaultDisableOpt, sysctlIpv6DefaultEnableOpt)
err = net.fs.WriteFileString(boshSysctlPath, boshSysctl)
if err != nil {
return bosherr.WrapError(err, "Writing boshSysctl")
}
}

grubConfPath := grubConfPathBIOS

grubConf, err := net.fs.ReadFileString(grubConfPath)
Expand Down
65 changes: 60 additions & 5 deletions platform/net/kernel_ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ var _ = Describe("KernelIPv6", func() {

When("grub.cfg disables IPv6", func() {
When("grub path is /boot/grub/grub.cfg", func() {
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"
const grubPath = "/boot/grub/grub.cfg"

BeforeEach(func() {
err := fs.WriteFileString(grubPath, "before ipv6.disable=1 after")
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
Expect(err).ToNot(HaveOccurred())

err = fs.WriteFileString(grubPath, "before ipv6.disable=1 after")
Expect(err).ToNot(HaveOccurred())
})

Expand All @@ -55,6 +60,7 @@ var _ = Describe("KernelIPv6", func() {
Expect(act()).ToNot(HaveOccurred())
Expect(cmdRunner.RunCommands).To(Equal([][]string{{"shutdown", "-r", "now"}}))
})

It("returns an error if update to "+grubPath+" fails", func() {
fs.WriteFileError = errors.New("fake-err")

Expand All @@ -72,11 +78,45 @@ var _ = Describe("KernelIPv6", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-err"))
})

When("60-bosh-sysctl.conf disables IPv6", func() {
It("changes net.ipv6.conf.all.disable_ipv6=1 to net.ipv6.conf.all.disable_ipv6=0 from "+boshSysctlPath, func() {
stopCh <- struct{}{}
Expect(act()).ToNot(HaveOccurred())
Expect(fs.ReadFileString(boshSysctlPath)).To(Equal("net.ipv6.conf.all.disable_ipv6=0\nnet.ipv6.conf.default.disable_ipv6=0"))
})
})

When("60-bosh-sysctl.conf enables IPv6", func() {
BeforeEach(func() {
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=0\nnet.ipv6.conf.default.disable_ipv6=0")
Expect(err).ToNot(HaveOccurred())
})

It("does not change "+boshSysctlPath, func() {
stopCh <- struct{}{}
Expect(act()).ToNot(HaveOccurred())
Expect(fs.ReadFileString(boshSysctlPath)).To(Equal("net.ipv6.conf.all.disable_ipv6=0\nnet.ipv6.conf.default.disable_ipv6=0"))
})
})
})

When("60-bosh-sysctl.conf does not exist", func() {
It("returns an error", func() {
err := act()
Expect(err).To(HaveOccurred())
})
})

When("grub path is /boot/efi/EFI/grub/grub.cfg", func() {
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"
const grubPath = "/boot/efi/EFI/grub/grub.cfg"

BeforeEach(func() {
err := fs.WriteFileString(grubPath, "before ipv6.disable=1 after")
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
Expect(err).ToNot(HaveOccurred())

err = fs.WriteFileString(grubPath, "before ipv6.disable=1 after")
Expect(err).ToNot(HaveOccurred())
})

Expand Down Expand Up @@ -112,8 +152,13 @@ var _ = Describe("KernelIPv6", func() {
})

When("/boot/grub/grub.cfg doesn't exist but /boot/efi/EFI/grub/grub.cfg does", func() {
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"

BeforeEach(func() {
err := fs.WriteFileString("/boot/efi/EFI/grub/grub.cfg", "before ipv6.disable=1 after")
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
Expect(err).ToNot(HaveOccurred())

err = fs.WriteFileString("/boot/efi/EFI/grub/grub.cfg", "before ipv6.disable=1 after")
Expect(err).ToNot(HaveOccurred())
})
It("does not return an error if it fails to read /boot/grub/grub.cfg", func() {
Expand All @@ -129,8 +174,13 @@ var _ = Describe("KernelIPv6", func() {
})

When("neither /boot/grub/grub.cfg nor /boot/efi/EFI/grub/grub.cfg exists", func() {
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"

It("returns an error", func() {
err := act()
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
Expect(err).ToNot(HaveOccurred())

err = act()
Expect(err).To(HaveOccurred())
})
})
Expand All @@ -140,8 +190,13 @@ var _ = Describe("KernelIPv6", func() {
"/boot/efi/EFI/grub/grub.cfg",
} {
When(grubPath+" allows IPv6", func() {
const boshSysctlPath = "/etc/sysctl.d/60-bosh-sysctl.conf"

BeforeEach(func() {
err := fs.WriteFileString(grubPath, "before after")
err := fs.WriteFileString(boshSysctlPath, "net.ipv6.conf.all.disable_ipv6=1\nnet.ipv6.conf.default.disable_ipv6=1")
Expect(err).ToNot(HaveOccurred())

err = fs.WriteFileString(grubPath, "before after")
Expect(err).ToNot(HaveOccurred())
})

Expand Down
Loading