Fix range expression unmarshalling

Fix the range expression unmarshalling on the `FromData` and `ToData`
Range expression fields.
This commit is contained in:
Rafael Campos Las Heras 2022-04-05 09:52:55 -03:00 committed by Michael Stapelberg
parent d46a80e963
commit 950e408d48
1 changed files with 28 additions and 2 deletions

View File

@ -77,9 +77,35 @@ func (e *Range) unmarshal(data []byte) error {
case unix.NFTA_RANGE_SREG: case unix.NFTA_RANGE_SREG:
e.Register = ad.Uint32() e.Register = ad.Uint32()
case unix.NFTA_RANGE_FROM_DATA: 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: 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() return ad.Err()