Skip to content

Commit

Permalink
feat(netlink): debug rule logs contain the ip family
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Nov 3, 2024
1 parent ddd3876 commit 96a8015
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 12 additions & 1 deletion internal/netlink/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ func netlinkRuleToRule(netlinkRule netlink.Rule) (rule Rule) {
}

func ruleDbgMsg(add bool, rule Rule) (debugMessage string) {
debugMessage = "ip rule"
debugMessage = "ip"

switch rule.Family {
case FamilyV4:
debugMessage += " -f inet"
case FamilyV6:
debugMessage += " -f inet6"
default:
debugMessage += " -f " + fmt.Sprint(rule.Family)
}

debugMessage += " rule"

if add {
debugMessage += " add"
Expand Down
8 changes: 5 additions & 3 deletions internal/netlink/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,28 @@ func Test_ruleDbgMsg(t *testing.T) {
dbgMsg string
}{
"default values": {
dbgMsg: "ip rule del pref 0",
dbgMsg: "ip -f 0 rule del pref 0",
},
"add rule": {
add: true,
rule: Rule{
Family: FamilyV4,
Src: makeNetipPrefix(1),
Dst: makeNetipPrefix(2),
Table: 100,
Priority: 101,
},
dbgMsg: "ip rule add from 1.1.1.0/24 to 2.2.2.0/24 lookup 100 pref 101",
dbgMsg: "ip -f inet rule add from 1.1.1.0/24 to 2.2.2.0/24 lookup 100 pref 101",
},
"del rule": {
rule: Rule{
Family: FamilyV4,
Src: makeNetipPrefix(1),
Dst: makeNetipPrefix(2),
Table: 100,
Priority: 101,
},
dbgMsg: "ip rule del from 1.1.1.0/24 to 2.2.2.0/24 lookup 100 pref 101",
dbgMsg: "ip -f inet rule del from 1.1.1.0/24 to 2.2.2.0/24 lookup 100 pref 101",
},
}

Expand Down

0 comments on commit 96a8015

Please sign in to comment.