Skip to content

Commit a3122c7

Browse files
committed
rule: populate Type field in RuleList and RuleListFiltered
The Rule.Type field was missing from the Rule struct, causing RuleList and RuleListFiltered to always return Type as 0 regardless of the actual FIB rule action type (e.g. RTN_UNICAST, RTN_BLACKHOLE). Add Type field to Rule struct, populate it from msg.Type during deserialization, support setting it during rule creation, and add RT_FILTER_TYPE filtering support. Fixes #1055
1 parent 95ab669 commit a3122c7

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

rule.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Rule struct {
1313
Mark int
1414
Mask int
1515
Tos uint
16+
Type int
1617
TunID uint
1718
Goto int
1819
Src *net.IPNet

rule_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func ruleHandle(rule *Rule, req *nl.NetlinkRequest) error {
5959
if rule.Tos != 0 {
6060
msg.Tos = uint8(rule.Tos)
6161
}
62+
if rule.Type > 0 {
63+
msg.Type = uint8(rule.Type)
64+
}
6265

6366
var dstFamily uint8
6467
var rtAttrs []*nl.RtAttr
@@ -225,6 +228,7 @@ func (h *Handle) RuleListFiltered(family int, filter *Rule, filterMask uint64) (
225228
rule.Invert = msg.Flags&FibRuleInvert > 0
226229
rule.Family = int(msg.Family)
227230
rule.Tos = uint(msg.Tos)
231+
rule.Type = int(msg.Type)
228232

229233
for j := range attrs {
230234
switch attrs[j].Attr.Type {
@@ -292,6 +296,8 @@ func (h *Handle) RuleListFiltered(family int, filter *Rule, filterMask uint64) (
292296
continue
293297
case filterMask&RT_FILTER_TOS != 0 && rule.Tos != filter.Tos:
294298
continue
299+
case filterMask&RT_FILTER_TYPE != 0 && rule.Type != filter.Type:
300+
continue
295301
case filterMask&RT_FILTER_PRIORITY != 0 && rule.Priority != filter.Priority:
296302
continue
297303
case filterMask&RT_FILTER_MARK != 0 && rule.Mark != filter.Mark:

0 commit comments

Comments
 (0)