Compare commits

..

3 Commits

Author SHA1 Message Date
Rafael Campos Las Heras 950e408d48 Fix range expression unmarshalling
Fix the range expression unmarshalling on the `FromData` and `ToData`
Range expression fields.
2022-04-07 21:54:05 +02:00
Rafael Campos Las Heras d46a80e963 Fix payload unmarshall operation type.
When unmarshalling the Payload expression the operation type is not
updated. Apply the same logic for unmarshalling that we apply for
marshalling.
2022-04-07 21:54:05 +02:00
Rafael Campos Las Heras c4d774fc49 Fix expression parsing for notracking
Fix the expression parsing for non data content like `notracking`
expression.
2022-04-07 21:54:05 +02:00
3 changed files with 33 additions and 2 deletions

View File

@ -112,6 +112,7 @@ func (e *Payload) unmarshal(data []byte) error {
e.DestRegister = ad.Uint32()
case unix.NFTA_PAYLOAD_SREG:
e.SourceRegister = ad.Uint32()
e.OperationType = PayloadWrite
case unix.NFTA_PAYLOAD_BASE:
e.Base = PayloadBase(ad.Uint32())
case unix.NFTA_PAYLOAD_OFFSET:

View File

@ -77,9 +77,35 @@ func (e *Range) unmarshal(data []byte) error {
case unix.NFTA_RANGE_SREG:
e.Register = ad.Uint32()
case unix.NFTA_RANGE_FROM_DATA:
e.FromData = ad.Bytes()
ad.Do(func(b []byte) error {
ad, err := netlink.NewAttributeDecoder(b)
if err != nil {
return err
}
ad.ByteOrder = binary.BigEndian
if ad.Next() && ad.Type() == unix.NFTA_DATA_VALUE {
ad.Do(func(b []byte) error {
e.FromData = b
return nil
})
}
return ad.Err()
})
case unix.NFTA_RANGE_TO_DATA:
e.ToData = ad.Bytes()
ad.Do(func(b []byte) error {
ad, err := netlink.NewAttributeDecoder(b)
if err != nil {
return err
}
ad.ByteOrder = binary.BigEndian
if ad.Next() && ad.Type() == unix.NFTA_DATA_VALUE {
ad.Do(func(b []byte) error {
e.ToData = b
return nil
})
}
return ad.Err()
})
}
}
return ad.Err()

View File

@ -227,6 +227,10 @@ func exprsFromMsg(b []byte) ([]expr.Any, error) {
switch ad.Type() {
case unix.NFTA_EXPR_NAME:
name = ad.String()
if name == "notrack" {
e := &expr.Notrack{}
exprs = append(exprs, e)
}
case unix.NFTA_EXPR_DATA:
var e expr.Any
switch name {