Merge pull request #779 from mmirecki/sysctl_on_vlan

Fix path substitution to enable setting sysctls on vlan interfaces
This commit is contained in:
Dan Williams 2022-11-14 10:51:25 -06:00 committed by GitHub
commit 7e9ada51e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -316,6 +316,10 @@ func cmdAdd(args *skel.CmdArgs) error {
return err return err
} }
if err = validateArgs(args); err != nil {
return err
}
// Parse previous result. // Parse previous result.
if tuningConf.RawPrevResult == nil { if tuningConf.RawPrevResult == nil {
return fmt.Errorf("Required prevResult missing") return fmt.Errorf("Required prevResult missing")
@ -330,12 +334,14 @@ func cmdAdd(args *skel.CmdArgs) error {
err = ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error { err = ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error {
for key, value := range tuningConf.SysCtl { for key, value := range tuningConf.SysCtl {
key = strings.Replace(key, ".", string(os.PathSeparator), -1)
// If the key contains `IFNAME` - substitute it with args.IfName // If the key contains `IFNAME` - substitute it with args.IfName
// to allow setting sysctls on a particular interface, on which // to allow setting sysctls on a particular interface, on which
// other operations (like mac/mtu setting) are performed // other operations (like mac/mtu setting) are performed
key = strings.Replace(key, "IFNAME", args.IfName, 1) key = strings.Replace(key, "IFNAME", args.IfName, 1)
fileName := filepath.Join("/proc/sys", strings.Replace(key, ".", "/", -1)) fileName := filepath.Join("/proc/sys", key)
// Refuse to modify sysctl parameters that don't belong // Refuse to modify sysctl parameters that don't belong
// to the network subsystem. // to the network subsystem.
@ -570,3 +576,10 @@ func validateSysctlConflictingKeys(data []byte) error {
sysctlCheck := sysctlCheck{} sysctlCheck := sysctlCheck{}
return json.Unmarshal(data, &sysctlCheck) return json.Unmarshal(data, &sysctlCheck)
} }
func validateArgs(args *skel.CmdArgs) error {
if strings.Contains(args.Args, string(os.PathSeparator)) {
return errors.New(fmt.Sprintf("Interface name contains an invalid character %s", string(os.PathSeparator)))
}
return nil
}