-
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(netlink): debug log ip rule commands in netlink instead of rout…
…ing package
- Loading branch information
Showing
8 changed files
with
100 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package netlink | ||
|
||
import "net/netip" | ||
|
||
func makeNetipPrefix(n byte) netip.Prefix { | ||
const bits = 24 | ||
return netip.PrefixFrom(netip.AddrFrom4([4]byte{n, n, n, 0}), bits) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package netlink | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_ruleDbgMsg(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
add bool | ||
rule Rule | ||
dbgMsg string | ||
}{ | ||
"default values": { | ||
dbgMsg: "ip rule del pref 0", | ||
}, | ||
"add rule": { | ||
add: true, | ||
rule: Rule{ | ||
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", | ||
}, | ||
"del rule": { | ||
rule: Rule{ | ||
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", | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
dbgMsg := ruleDbgMsg(testCase.add, testCase.rule) | ||
|
||
assert.Equal(t, testCase.dbgMsg, dbgMsg) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.