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 <greenpau@outlook.com>
This commit is contained in:
parent
7127d9d224
commit
c25e4f69b4
|
@ -15,6 +15,7 @@
|
||||||
package expr
|
package expr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
@ -100,6 +101,7 @@ func (e *Verdict) unmarshal(data []byte) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ad.ByteOrder = binary.BigEndian
|
ad.ByteOrder = binary.BigEndian
|
||||||
for ad.Next() {
|
for ad.Next() {
|
||||||
switch ad.Type() {
|
switch ad.Type() {
|
||||||
|
@ -111,7 +113,10 @@ func (e *Verdict) unmarshal(data []byte) error {
|
||||||
for nestedAD.Next() {
|
for nestedAD.Next() {
|
||||||
switch nestedAD.Type() {
|
switch nestedAD.Type() {
|
||||||
case unix.NFTA_DATA_VERDICT:
|
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 {
|
if nestedAD.Err() != nil {
|
||||||
|
|
Loading…
Reference in New Issue