Change logic of searching for rule's ID (#34)

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
This commit is contained in:
Serguei Bezverkhi 2019-07-08 16:46:23 -04:00 committed by Michael Stapelberg
parent 7c0b8e78d4
commit b62e86457d
1 changed files with 9 additions and 7 deletions

12
rule.go
View File

@ -114,16 +114,18 @@ func (cc *Conn) GetRuleHandle(t *Table, c *Chain, ruleID uint32) (uint64, error)
if err != nil {
return 0, fmt.Errorf("Receive: %v", err)
}
if len(reply) != 1 {
return 0, fmt.Errorf("Receive: Expected 1 message but got %d", len(reply))
}
rr, err := ruleFromMsg(reply[0])
for _, msg := range reply {
rr, err := ruleFromMsg(msg)
if err != nil {
return 0, err
}
if rr.RuleID == ruleID {
return rr.Handle, nil
}
}
return 0, fmt.Errorf("rule with id %d is not found", ruleID)
}
// AddRule adds the specified Rule
func (cc *Conn) AddRule(r *Rule) *Rule {