Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check routing table and firewall mark in Split Routing Config #89

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading