From d6b03fdeb845d3fc2d1c5f2fee98b334ce156937 Mon Sep 17 00:00:00 2001 From: Artem Glazychev Date: Tue, 18 Jan 2022 20:20:09 +0700 Subject: [PATCH] Fix review comment Signed-off-by: Artem Glazychev --- rule_linux.go | 14 ++++++++------ rule_test.go | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rule_linux.go b/rule_linux.go index 0445b2f..3ae2138 100644 --- a/rule_linux.go +++ b/rule_linux.go @@ -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: diff --git a/rule_test.go b/rule_test.go index cf209d8..2cf1d54 100644 --- a/rule_test.go +++ b/rule_test.go @@ -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 }