Skip to content

Commit

Permalink
fix: unmarshaling verdicts with chain information (#106)
Browse files Browse the repository at this point in the history
Before this commit: the unmarshaling of a verdict pointing
to a chain fails.

After this commit: the unmarshaling of a rule with a verdict
pointing to a chain succeeds and the information about the
chain gets put in `Verdict.Chain`.

Resolves: #105

Signed-off-by: Paul Greenberg <[email protected]>
  • Loading branch information
greenpau authored Aug 2, 2020
1 parent 7127d9d commit c25e4f6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion expr/verdict.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package expr

import (
"bytes"
"encoding/binary"
"fmt"

Expand Down Expand Up @@ -100,6 +101,7 @@ func (e *Verdict) unmarshal(data []byte) error {
if err != nil {
return err
}

ad.ByteOrder = binary.BigEndian
for ad.Next() {
switch ad.Type() {
Expand All @@ -111,7 +113,10 @@ func (e *Verdict) unmarshal(data []byte) error {
for nestedAD.Next() {
switch nestedAD.Type() {
case unix.NFTA_DATA_VERDICT:
e.Kind = VerdictKind(binaryutil.BigEndian.Uint32(nestedAD.Bytes()[4:]))
e.Kind = VerdictKind(int32(binaryutil.BigEndian.Uint32(nestedAD.Bytes()[4:8])))
if len(nestedAD.Bytes()) > 12 {
e.Chain = string(bytes.Trim(nestedAD.Bytes()[12:], "\x00"))
}
}
}
if nestedAD.Err() != nil {
Expand Down

0 comments on commit c25e4f6

Please sign in to comment.