Skip to content

Commit

Permalink
Check routing table and firewall mark in Split Routing Config
Browse files Browse the repository at this point in the history
Signed-off-by: hwipl <[email protected]>
  • Loading branch information
hwipl committed May 15, 2024
1 parent dc16c9c commit 6c3574d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/splitrt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
18 changes: 18 additions & 0 deletions internal/splitrt/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6c3574d

Please sign in to comment.