netcfg: suppress RTNETLINK errors from policy route cleanup

Use runQuiet for ip rule/route del commands that may fail harmlessly
when no existing rule exists (e.g. first run after deploy).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Git Sagar 2026-06-07 00:42:56 +05:30
parent 47e06b525c
commit 857733863c

View file

@ -99,7 +99,7 @@ func ConfigurePolicyRoute(ifname string, lease *dhcp.Lease, table int) func() {
clientIP := lease.ClientIP.String()
gw := lease.Gateway.String()
run("ip", "rule", "del", "table", t)
runQuiet("ip", "rule", "del", "table", t)
run("ip", "route", "replace", "default", "via", gw, "dev", ifname, "table", t)
if err := run("ip", "rule", "add", "from", clientIP, "table", t); err != nil {
log.Printf("warning: policy rule: %v", err)
@ -108,8 +108,8 @@ func ConfigurePolicyRoute(ifname string, lease *dhcp.Lease, table int) func() {
}
return func() {
run("ip", "rule", "del", "table", t)
run("ip", "route", "del", "default", "table", t)
runQuiet("ip", "rule", "del", "table", t)
runQuiet("ip", "route", "del", "default", "table", t)
log.Printf("policy route: cleaned up table %s", t)
}
}
@ -233,3 +233,7 @@ func run(name string, args ...string) error {
cmd.Stderr = os.Stderr
return cmd.Run()
}
func runQuiet(name string, args ...string) error {
return exec.Command(name, args...).Run()
}