f-41: frr, sysctl, netif: primitives du L3VNI #41
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
0f31b2faf4
commit
94c2f82867
11 changed files with 910 additions and 0 deletions
23
internal/sysctl/sysctl.go
Normal file
23
internal/sysctl/sysctl.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package sysctl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var root = "/proc/sys"
|
||||
|
||||
func Set(key, value string) error {
|
||||
path := filepath.Join(root, strings.ReplaceAll(key, ".", "/"))
|
||||
f, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("sysctl %s: %w", key, err)
|
||||
}
|
||||
if _, err := f.WriteString(value); err != nil {
|
||||
f.Close()
|
||||
return fmt.Errorf("sysctl %s=%s: %w", key, value, err)
|
||||
}
|
||||
return f.Close()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue