Skip to content

Commit c25e4f6

Browse files
authored
fix: unmarshaling verdicts with chain information (#106)
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]>
1 parent 7127d9d commit c25e4f6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

expr/verdict.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package expr
1616

1717
import (
18+
"bytes"
1819
"encoding/binary"
1920
"fmt"
2021

@@ -100,6 +101,7 @@ func (e *Verdict) unmarshal(data []byte) error {
100101
if err != nil {
101102
return err
102103
}
104+
103105
ad.ByteOrder = binary.BigEndian
104106
for ad.Next() {
105107
switch ad.Type() {
@@ -111,7 +113,10 @@ func (e *Verdict) unmarshal(data []byte) error {
111113
for nestedAD.Next() {
112114
switch nestedAD.Type() {
113115
case unix.NFTA_DATA_VERDICT:
114-
e.Kind = VerdictKind(binaryutil.BigEndian.Uint32(nestedAD.Bytes()[4:]))
116+
e.Kind = VerdictKind(int32(binaryutil.BigEndian.Uint32(nestedAD.Bytes()[4:8])))
117+
if len(nestedAD.Bytes()) > 12 {
118+
e.Chain = string(bytes.Trim(nestedAD.Bytes()[12:], "\x00"))
119+
}
115120
}
116121
}
117122
if nestedAD.Err() != nil {

0 commit comments

Comments
 (0)