Skip to content

Commit abc2b83

Browse files
authored
Merge pull request #5312 from hedgieinsocks/fix/use_sysctl_slash_separator
Use forward slash as path separator for some sysctl commands
2 parents a89b20e + 19be786 commit abc2b83

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

go-controller/pkg/node/gateway_init.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import (
2727
func bridgedGatewayNodeSetup(nodeName, bridgeName, physicalNetworkName string) (string, error) {
2828
// IPv6 forwarding is enabled globally
2929
if config.IPv4Mode {
30-
stdout, stderr, err := util.RunSysctl("-w", fmt.Sprintf("net.ipv4.conf.%s.forwarding=1", bridgeName))
31-
if err != nil || stdout != fmt.Sprintf("net.ipv4.conf.%s.forwarding = 1", bridgeName) {
30+
// we use forward slash as path separator to allow dotted bridgeName e.g. foo.200
31+
stdout, stderr, err := util.RunSysctl("-w", fmt.Sprintf("net/ipv4/conf/%s/forwarding=1", bridgeName))
32+
// systctl output enforces dot as path separator
33+
if err != nil || stdout != fmt.Sprintf("net.ipv4.conf.%s.forwarding = 1", strings.ReplaceAll(bridgeName, ".", "/")) {
3234
return "", fmt.Errorf("could not set the correct forwarding value for interface %s: stdout: %v, stderr: %v, err: %v",
3335
bridgeName, stdout, stderr, err)
3436
}

go-controller/pkg/node/gateway_init_linux_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func shareGatewayInterfaceTest(app *cli.App, testNS ns.NetNS,
166166
})
167167
if config.IPv4Mode {
168168
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
169-
Cmd: "sysctl -w net.ipv4.conf.breth0.forwarding=1",
169+
Cmd: "sysctl -w net/ipv4/conf/breth0/forwarding=1",
170170
Output: "net.ipv4.conf.breth0.forwarding = 1",
171171
})
172172
}
@@ -595,7 +595,7 @@ func shareGatewayInterfaceDPUTest(app *cli.App, testNS ns.NetNS,
595595
})
596596
if config.IPv4Mode {
597597
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
598-
Cmd: "sysctl -w net.ipv4.conf.brp0.forwarding=1",
598+
Cmd: "sysctl -w net/ipv4/conf/brp0/forwarding=1",
599599
Output: "net.ipv4.conf.brp0.forwarding = 1",
600600
})
601601
}
@@ -1057,7 +1057,7 @@ OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0`
10571057
})
10581058
if config.IPv4Mode {
10591059
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
1060-
Cmd: "sysctl -w net.ipv4.conf.breth0.forwarding=1",
1060+
Cmd: "sysctl -w net/ipv4/conf/breth0/forwarding=1",
10611061
Output: "net.ipv4.conf.breth0.forwarding = 1",
10621062
})
10631063
}

go-controller/pkg/node/gateway_udn.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net"
77
"slices"
8+
"strings"
89
"sync/atomic"
910
"time"
1011

@@ -522,8 +523,10 @@ func (udng *UserDefinedNetworkGateway) addUDNManagementPort() (netlink.Link, err
522523
// STEP3
523524
// IPv6 forwarding is enabled globally
524525
if ipv4, _ := udng.IPMode(); ipv4 {
525-
stdout, stderr, err := util.RunSysctl("-w", fmt.Sprintf("net.ipv4.conf.%s.forwarding=1", interfaceName))
526-
if err != nil || stdout != fmt.Sprintf("net.ipv4.conf.%s.forwarding = 1", interfaceName) {
526+
// we use forward slash as path separator to allow dotted interfaceName e.g. foo.200
527+
stdout, stderr, err := util.RunSysctl("-w", fmt.Sprintf("net/ipv4/conf/%s/forwarding=1", interfaceName))
528+
// systctl output enforces dot as path separator
529+
if err != nil || stdout != fmt.Sprintf("net.ipv4.conf.%s.forwarding = 1", strings.ReplaceAll(interfaceName, ".", "/")) {
527530
return nil, fmt.Errorf("could not set the correct forwarding value for interface %s: stdout: %v, stderr: %v, err: %v",
528531
interfaceName, stdout, stderr, err)
529532
}
@@ -891,8 +894,10 @@ func addRPFilterLooseModeForManagementPort(mgmtPortName string) error {
891894
rpFilterLooseMode := "2"
892895
// TODO: Convert testing framework to mock golang module utilities. Example:
893896
// result, err := sysctl.Sysctl(fmt.Sprintf("net/ipv4/conf/%s/rp_filter", types.K8sMgmtIntfName), rpFilterLooseMode)
894-
stdout, stderr, err := util.RunSysctl("-w", fmt.Sprintf("net.ipv4.conf.%s.rp_filter=%s", mgmtPortName, rpFilterLooseMode))
895-
if err != nil || stdout != fmt.Sprintf("net.ipv4.conf.%s.rp_filter = %s", mgmtPortName, rpFilterLooseMode) {
897+
// we use forward slash as path separator to allow dotted mgmtPortName e.g. foo.200
898+
stdout, stderr, err := util.RunSysctl("-w", fmt.Sprintf("net/ipv4/conf/%s/rp_filter=%s", mgmtPortName, rpFilterLooseMode))
899+
// systctl output enforces dot as path separator
900+
if err != nil || stdout != fmt.Sprintf("net.ipv4.conf.%s.rp_filter = %s", strings.ReplaceAll(mgmtPortName, ".", "/"), rpFilterLooseMode) {
896901
return fmt.Errorf("could not set the correct rp_filter value for interface %s: stdout: %v, stderr: %v, err: %v",
897902
mgmtPortName, stdout, stderr, err)
898903
}

go-controller/pkg/node/gateway_udn_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ func getCreationFakeCommands(fexec *ovntest.FakeExec, mgtPort, mgtPortMAC, netNa
5959
})
6060

6161
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
62-
Cmd: "sysctl -w net.ipv4.conf." + mgtPort + ".forwarding=1",
62+
Cmd: "sysctl -w net/ipv4/conf/" + mgtPort + "/forwarding=1",
6363
Output: "net.ipv4.conf." + mgtPort + ".forwarding = 1",
6464
})
6565
}
6666

6767
func getRPFilterLooseModeFakeCommands(fexec *ovntest.FakeExec) {
6868
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
69-
Cmd: "sysctl -w net.ipv4.conf.ovn-k8s-mp3.rp_filter=2",
69+
Cmd: "sysctl -w net/ipv4/conf/ovn-k8s-mp3/rp_filter=2",
7070
Output: "net.ipv4.conf.ovn-k8s-mp3.rp_filter = 2",
7171
})
7272
}
@@ -148,7 +148,7 @@ func setUpGatewayFakeOVSCommands(fexec *ovntest.FakeExec) {
148148
})
149149
if config.IPv4Mode {
150150
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
151-
Cmd: "sysctl -w net.ipv4.conf.breth0.forwarding=1",
151+
Cmd: "sysctl -w net/ipv4/conf/breth0/forwarding=1",
152152
Output: "net.ipv4.conf.breth0.forwarding = 1",
153153
})
154154
}

0 commit comments

Comments
 (0)