Skip to content

Commit

Permalink
Linux rule list results have Family populated
Browse files Browse the repository at this point in the history
Fixes #708
  • Loading branch information
Derek Dagit authored and vishvananda committed Jul 28, 2023
1 parent 1b56373 commit dbf1bd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions rule_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func (h *Handle) RuleListFiltered(family int, filter *Rule, filterMask uint64) (
rule := NewRule()

rule.Invert = msg.Flags&FibRuleInvert > 0
rule.Family = int(msg.Family)
rule.Tos = uint(msg.Tos)

for j := range attrs {
Expand Down
11 changes: 11 additions & 0 deletions rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestRuleAddDel(t *testing.T) {
}

rule := NewRule()
rule.Family = FAMILY_V4
rule.Table = unix.RT_TABLE_MAIN
rule.Src = srcNet
rule.Dst = dstNet
Expand Down Expand Up @@ -121,6 +122,7 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
r := NewRule()
r.Src = srcNet
r.Priority = 1 // Must add priority and table otherwise it's auto-assigned
r.Family = family
r.Table = 1
RuleAdd(r)
return r
Expand All @@ -138,6 +140,7 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
r := NewRule()
r.Dst = dstNet
r.Priority = 1 // Must add priority and table otherwise it's auto-assigned
r.Family = family
r.Table = 1
RuleAdd(r)
return r
Expand All @@ -155,6 +158,7 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
r := NewRule()
r.Dst = dstNet
r.Priority = 1 // Must add priority and table otherwise it's auto-assigned
r.Family = family
r.Table = 1
RuleAdd(r)

Expand Down Expand Up @@ -190,6 +194,7 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
r := NewRule()
r.Dst = dstNet
r.Priority = 1 // Must add priority and table otherwise it's auto-assigned
r.Family = family
r.Table = 1
RuleAdd(r)

Expand Down Expand Up @@ -225,6 +230,7 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
r := NewRule()
r.Src = srcNet
r.Priority = 5
r.Family = family
r.Table = 1
RuleAdd(r)

Expand Down Expand Up @@ -266,6 +272,7 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
r := NewRule()
r.Src = srcNet
r.Priority = 1 // Must add priority otherwise it's auto-assigned
r.Family = family
r.Table = 199
RuleAdd(r)
return r
Expand All @@ -283,6 +290,7 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
r := NewRule()
r.Src = srcNet
r.Priority = 1 // Must add priority and table otherwise it's auto-assigned
r.Family = family
r.Table = 1
r.Mask = 0x5
RuleAdd(r)
Expand All @@ -301,6 +309,7 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
r := NewRule()
r.Src = srcNet
r.Priority = 1 // Must add priority, table, mask otherwise it's auto-assigned
r.Family = family
r.Table = 1
r.Mask = 0xff
r.Mark = 0xbb
Expand All @@ -320,6 +329,7 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) {
r := NewRule()
r.Src = srcNet
r.Priority = 1 // Must add priority, table, mask otherwise it's auto-assigned
r.Family = family
r.Table = 12
r.Tos = 12 // Tos must equal table
RuleAdd(r)
Expand Down Expand Up @@ -418,6 +428,7 @@ func ruleEquals(a, b Rule) bool {
(a.Dst != nil && b.Dst != nil && a.Dst.String() == b.Dst.String())) &&
a.OifName == b.OifName &&
a.Priority == b.Priority &&
a.Family == b.Family &&
a.IifName == b.IifName &&
a.Invert == b.Invert &&
a.Tos == b.Tos &&
Expand Down

0 comments on commit dbf1bd0

Please sign in to comment.