NAT: add RegProtoMax if >0

This commit is contained in:
Michael Stapelberg 2018-06-14 22:26:30 +02:00
parent 0ba4d9997a
commit 05c74458a0
1 changed files with 7 additions and 2 deletions

View File

@ -33,6 +33,7 @@ type NAT struct {
Family uint32 // TODO: typed const Family uint32 // TODO: typed const
RegAddrMin uint32 RegAddrMin uint32
RegProtoMin uint32 RegProtoMin uint32
RegProtoMax uint32
} }
// |00048|N-|00001| |len |flags| type| // |00048|N-|00001| |len |flags| type|
@ -49,12 +50,16 @@ type NAT struct {
// | 00 00 00 02 | | data | reg 2 // | 00 00 00 02 | | data | reg 2
func (e *NAT) marshal() ([]byte, error) { func (e *NAT) marshal() ([]byte, error) {
data, err := netlink.MarshalAttributes([]netlink.Attribute{ attrs := []netlink.Attribute{
{Type: unix.NFTA_NAT_TYPE, Data: binaryutil.BigEndian.PutUint32(uint32(e.Type))}, {Type: unix.NFTA_NAT_TYPE, Data: binaryutil.BigEndian.PutUint32(uint32(e.Type))},
{Type: unix.NFTA_NAT_FAMILY, Data: binaryutil.BigEndian.PutUint32(e.Family)}, {Type: unix.NFTA_NAT_FAMILY, Data: binaryutil.BigEndian.PutUint32(e.Family)},
{Type: unix.NFTA_NAT_REG_ADDR_MIN, Data: binaryutil.BigEndian.PutUint32(e.RegAddrMin)}, {Type: unix.NFTA_NAT_REG_ADDR_MIN, Data: binaryutil.BigEndian.PutUint32(e.RegAddrMin)},
{Type: unix.NFTA_NAT_REG_PROTO_MIN, Data: binaryutil.BigEndian.PutUint32(e.RegProtoMin)}, {Type: unix.NFTA_NAT_REG_PROTO_MIN, Data: binaryutil.BigEndian.PutUint32(e.RegProtoMin)},
}) }
if e.RegProtoMax > 0 {
attrs = append(attrs, netlink.Attribute{Type: unix.NFTA_NAT_REG_PROTO_MAX, Data: binaryutil.BigEndian.PutUint32(e.RegProtoMax)})
}
data, err := netlink.MarshalAttributes(attrs)
if err != nil { if err != nil {
return nil, err return nil, err
} }