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

More sysctls to set for IPv6 #76

Merged
merged 1 commit into from
Apr 16, 2019
Merged
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
56 changes: 43 additions & 13 deletions pkg/danmep/danmep.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@ const (
dockerApiVersion = "1.22"
)

type sysctlData struct {
type sysctlFunction func(danmtypes.DanmEp) bool
type sysctlObject struct {
sysctlName string
sysctlValue string
}
var sysctls = map[string][]sysctlData {
"enable_ipv6_on_iface": {
{"net.ipv6.conf.%s.disable_ipv6", "0"},
type sysctlTask struct {
sysctlFunc sysctlFunction
sysctlData []sysctlObject
}

var sysctls = []sysctlTask {
{
sysctlFunc: isIPv6Needed,
sysctlData: []sysctlObject {
{"net.ipv6.conf.%s.disable_ipv6", "0"},
{"net.ipv6.conf.%s.autoconf", "0"},
{"net.ipv6.conf.%s.accept_ra", "0"},
},
},
"disable_ipv6_on_iface": {
{"net.ipv6.conf.%s.disable_ipv6", "1"},
{
sysctlFunc: isIPv6NotNeeded,
sysctlData: []sysctlObject {
{"net.ipv6.conf.%s.disable_ipv6", "1"},
},
},
}

Expand Down Expand Up @@ -139,15 +153,31 @@ func SetDanmEpSysctls(ep danmtypes.DanmEp) error {
podNs.Close()
origNs.Set()
}()
// set sysctls for IPv6 (since IPv6 is enabled on all interfaces, let's disable on those where it is not needed)
if ep.Spec.Iface.AddressIPv6 == "" {
for _, s := range sysctls["disable_ipv6_on_iface"] {
sstr := fmt.Sprintf(s.sysctlName, ep.Spec.Iface.Name)
_, err = sysctl.Sysctl(sstr, s.sysctlValue)
if err != nil {
return errors.New("failed to set sysctl due to:" + err.Error())
// set sysctls
for _, s := range sysctls {
if s.sysctlFunc(ep) {
for _, ss := range s.sysctlData {
sss := fmt.Sprintf(ss.sysctlName, ep.Spec.Iface.Name)
_, err = sysctl.Sysctl(sss, ss.sysctlValue)
if err != nil {
return errors.New("failed to set sysctl due to:" + err.Error())
}
}
}
}
return nil
}

func isIPv6Needed(ep danmtypes.DanmEp) bool {
if ep.Spec.Iface.AddressIPv6 != "" {
return true
}
return false
}

func isIPv6NotNeeded(ep danmtypes.DanmEp) bool {
if ep.Spec.Iface.AddressIPv6 == "" {
return true
}
return false
}