Fix review comment

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
This commit is contained in:
Artem Glazychev 2022-01-18 20:20:09 +07:00 committed by Vish (Ishaya) Abrams
parent 5a3e901175
commit d6b03fdeb8
2 changed files with 10 additions and 7 deletions

View File

@ -152,6 +152,12 @@ func ruleHandle(rule *Rule, req *nl.NetlinkRequest) error {
req.AddData(nl.NewRtAttr(nl.FRA_GOTO, b))
}
if rule.IPProto > 0 {
b := make([]byte, 4)
native.PutUint32(b, uint32(rule.IPProto))
req.AddData(nl.NewRtAttr(nl.FRA_IP_PROTO, b))
}
if rule.Dport != nil {
b := rule.Dport.toRtAttrData()
req.AddData(nl.NewRtAttr(nl.FRA_DPORT_RANGE, b))
@ -162,12 +168,6 @@ func ruleHandle(rule *Rule, req *nl.NetlinkRequest) error {
req.AddData(nl.NewRtAttr(nl.FRA_SPORT_RANGE, b))
}
if rule.IPProto > 0 {
b := make([]byte, 4)
native.PutUint32(b, uint32(rule.IPProto))
req.AddData(nl.NewRtAttr(nl.FRA_IP_PROTO, b))
}
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
return err
}
@ -256,6 +256,8 @@ func (h *Handle) RuleListFiltered(family int, filter *Rule, filterMask uint64) (
rule.Goto = int(native.Uint32(attrs[j].Value[0:4]))
case nl.FRA_PRIORITY:
rule.Priority = int(native.Uint32(attrs[j].Value[0:4]))
case nl.FRA_IP_PROTO:
rule.IPProto = int(native.Uint32(attrs[j].Value[0:4]))
case nl.FRA_DPORT_RANGE:
rule.Dport = NewRulePortRange(native.Uint16(attrs[j].Value[0:2]), native.Uint16(attrs[j].Value[2:4]))
case nl.FRA_SPORT_RANGE:

View File

@ -418,5 +418,6 @@ func ruleEquals(a, b Rule) bool {
a.Priority == b.Priority &&
a.IifName == b.IifName &&
a.Invert == b.Invert &&
a.Tos == b.Tos
a.Tos == b.Tos &&
a.IPProto == b.IPProto
}