diff --git a/internal/splitrt/config.go b/internal/splitrt/config.go index 20e090a..7302b2a 100644 --- a/internal/splitrt/config.go +++ b/internal/splitrt/config.go @@ -39,6 +39,12 @@ func (c *Config) Valid() bool { return false } + // check routing table value: must be > 0, < 0xFFFFFFFF + rtTable, err := strconv.ParseUint(c.RoutingTable, 10, 32) + if err != nil || rtTable == 0 || rtTable >= 0xFFFFFFFF { + return false + } + // check rule priority values: must be > 0, < 32766, prio1 < prio2 prio1, err := strconv.ParseUint(c.RulePriority1, 10, 16) if err != nil { @@ -55,6 +61,11 @@ func (c *Config) Valid() bool { return false } + // check fwmark value: must be 32 bit unsigned int + if _, err := strconv.ParseUint(c.FirewallMark, 10, 32); err != nil { + return false + } + return true } diff --git a/internal/splitrt/config_test.go b/internal/splitrt/config_test.go index bbd87c3..e82c93f 100644 --- a/internal/splitrt/config_test.go +++ b/internal/splitrt/config_test.go @@ -44,6 +44,24 @@ func TestConfigValid(t *testing.T) { RulePriority1: "2111", RulePriority2: "65537", }, + { + RoutingTable: "0", + FirewallMark: "42112", + RulePriority1: "2222", + RulePriority2: "2223", + }, + { + RoutingTable: "4294967295", + FirewallMark: "42112", + RulePriority1: "2222", + RulePriority2: "2223", + }, + { + RoutingTable: "42112", + FirewallMark: "4294967296", + RulePriority1: "2222", + RulePriority2: "2223", + }, } { want := false got := invalid.Valid()