Meta SREG and DREG (#51)
* meta requires to use source and destination registers Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
This commit is contained in:
parent
5cb71bfba1
commit
6925991d82
21
expr/expr.go
21
expr/expr.go
|
@ -77,19 +77,38 @@ const (
|
||||||
// https://wiki.nftables.org/wiki-nftables/index.php/Matching_packet_metainformation
|
// https://wiki.nftables.org/wiki-nftables/index.php/Matching_packet_metainformation
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
Key MetaKey
|
Key MetaKey
|
||||||
|
SourceRegister bool
|
||||||
Register uint32
|
Register uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Meta) marshal() ([]byte, error) {
|
func (e *Meta) marshal() ([]byte, error) {
|
||||||
|
regData := []byte{}
|
||||||
exprData, err := netlink.MarshalAttributes(
|
exprData, err := netlink.MarshalAttributes(
|
||||||
[]netlink.Attribute{
|
[]netlink.Attribute{
|
||||||
{Type: unix.NFTA_META_KEY, Data: binaryutil.BigEndian.PutUint32(uint32(e.Key))},
|
{Type: unix.NFTA_META_KEY, Data: binaryutil.BigEndian.PutUint32(uint32(e.Key))},
|
||||||
{Type: unix.NFTA_META_DREG, Data: binaryutil.BigEndian.PutUint32(e.Register)},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if e.SourceRegister {
|
||||||
|
regData, err = netlink.MarshalAttributes(
|
||||||
|
[]netlink.Attribute{
|
||||||
|
{Type: unix.NFTA_META_SREG, Data: binaryutil.BigEndian.PutUint32(e.Register)},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
regData, err = netlink.MarshalAttributes(
|
||||||
|
[]netlink.Attribute{
|
||||||
|
{Type: unix.NFTA_META_DREG, Data: binaryutil.BigEndian.PutUint32(e.Register)},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
exprData = append(exprData, regData...)
|
||||||
|
|
||||||
return netlink.MarshalAttributes([]netlink.Attribute{
|
return netlink.MarshalAttributes([]netlink.Attribute{
|
||||||
{Type: unix.NFTA_EXPR_NAME, Data: []byte("meta\x00")},
|
{Type: unix.NFTA_EXPR_NAME, Data: []byte("meta\x00")},
|
||||||
{Type: unix.NLA_F_NESTED | unix.NFTA_EXPR_DATA, Data: exprData},
|
{Type: unix.NLA_F_NESTED | unix.NFTA_EXPR_DATA, Data: exprData},
|
||||||
|
|
Loading…
Reference in New Issue