implement expr.Payload unmarshaling
This commit is contained in:
parent
2338808f3c
commit
beb488f6fa
|
@ -15,8 +15,6 @@
|
||||||
package expr
|
package expr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/google/nftables/binaryutil"
|
"github.com/google/nftables/binaryutil"
|
||||||
"github.com/mdlayher/netlink"
|
"github.com/mdlayher/netlink"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
@ -55,5 +53,22 @@ func (e *Payload) marshal() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Payload) unmarshal(data []byte) error {
|
func (e *Payload) unmarshal(data []byte) error {
|
||||||
return fmt.Errorf("not yet implemented")
|
attrs, err := netlink.UnmarshalAttributes(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, attr := range attrs {
|
||||||
|
switch attr.Type {
|
||||||
|
case unix.NFTA_PAYLOAD_DREG:
|
||||||
|
e.DestRegister = binaryutil.BigEndian.Uint32(attr.Data)
|
||||||
|
case unix.NFTA_PAYLOAD_BASE:
|
||||||
|
e.Base = PayloadBase(binaryutil.BigEndian.Uint32(attr.Data))
|
||||||
|
case unix.NFTA_PAYLOAD_OFFSET:
|
||||||
|
e.Offset = binaryutil.BigEndian.Uint32(attr.Data)
|
||||||
|
case unix.NFTA_PAYLOAD_LEN:
|
||||||
|
e.Len = binaryutil.BigEndian.Uint32(attr.Data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,8 @@ func exprsFromMsg(b []byte) ([]expr.Any, error) {
|
||||||
e = &expr.Cmp{}
|
e = &expr.Cmp{}
|
||||||
case "counter":
|
case "counter":
|
||||||
e = &expr.Counter{}
|
e = &expr.Counter{}
|
||||||
|
case "payload":
|
||||||
|
e = &expr.Payload{}
|
||||||
}
|
}
|
||||||
if e == nil {
|
if e == nil {
|
||||||
// TODO: introduce an opaque expression type so that users know
|
// TODO: introduce an opaque expression type so that users know
|
||||||
|
|
Loading…
Reference in New Issue