rule, add TOS

Signed-off-by: Amit Nishry <amit.nishry@gmail.com>
This commit is contained in:
Amit Nishry 2020-02-08 20:55:55 +00:00 committed by Alessandro Boch
parent 261f000a62
commit 7ed9c95980
3 changed files with 8 additions and 1 deletions

View File

@ -12,6 +12,7 @@ type Rule struct {
Table int
Mark int
Mask int
Tos uint
TunID uint
Goto int
Src *net.IPNet

View File

@ -55,6 +55,9 @@ func ruleHandle(rule *Rule, req *nl.NetlinkRequest) error {
if rule.Table >= 0 && rule.Table < 256 {
msg.Table = uint8(rule.Table)
}
if rule.Tos != 0 {
msg.Tos = uint8(rule.Tos)
}
var dstFamily uint8
var rtAttrs []*nl.RtAttr
@ -184,6 +187,7 @@ func (h *Handle) RuleList(family int) ([]Rule, error) {
rule := NewRule()
rule.Invert = msg.Flags&FibRuleInvert > 0
rule.Tos = uint(msg.Tos)
for j := range attrs {
switch attrs[j].Attr.Type {

View File

@ -29,6 +29,7 @@ func TestRuleAddDel(t *testing.T) {
rule.OifName = "lo"
rule.IifName = "lo"
rule.Invert = true
rule.Tos = 0x10
if err := RuleAdd(rule); err != nil {
t.Fatal(err)
}
@ -51,7 +52,8 @@ func TestRuleAddDel(t *testing.T) {
rules[i].OifName == rule.OifName &&
rules[i].Priority == rule.Priority &&
rules[i].IifName == rule.IifName &&
rules[i].Invert == rule.Invert {
rules[i].Invert == rule.Invert &&
rules[i].Tos == rule.Tos {
found = true
break
}