NAT: prefix support (#251)

This commit is contained in:
Francesco Cheinasso 2023-12-22 08:33:18 +01:00 committed by GitHub
parent 6d4c531bb6
commit ef45dd3322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -287,6 +287,8 @@ const (
NF_NAT_RANGE_PROTO_RANDOM_FULLY = 0x10 NF_NAT_RANGE_PROTO_RANDOM_FULLY = 0x10
// NF_NAT_RANGE_PERSISTENT defines flag for a persistent masquerade // NF_NAT_RANGE_PERSISTENT defines flag for a persistent masquerade
NF_NAT_RANGE_PERSISTENT = 0x8 NF_NAT_RANGE_PERSISTENT = 0x8
// NF_NAT_RANGE_PREFIX defines flag for a prefix masquerade
NF_NAT_RANGE_PREFIX = 0x40
) )
func (e *Masq) marshal(fam byte) ([]byte, error) { func (e *Masq) marshal(fam byte) ([]byte, error) {

View File

@ -40,6 +40,7 @@ type NAT struct {
Random bool Random bool
FullyRandom bool FullyRandom bool
Persistent bool Persistent bool
Prefix bool
} }
// |00048|N-|00001| |len |flags| type| // |00048|N-|00001| |len |flags| type|
@ -82,6 +83,9 @@ func (e *NAT) marshal(fam byte) ([]byte, error) {
if e.Persistent { if e.Persistent {
flags |= NF_NAT_RANGE_PERSISTENT flags |= NF_NAT_RANGE_PERSISTENT
} }
if e.Prefix {
flags |= NF_NAT_RANGE_PREFIX
}
if flags != 0 { if flags != 0 {
attrs = append(attrs, netlink.Attribute{Type: unix.NFTA_NAT_FLAGS, Data: binaryutil.BigEndian.PutUint32(flags)}) attrs = append(attrs, netlink.Attribute{Type: unix.NFTA_NAT_FLAGS, Data: binaryutil.BigEndian.PutUint32(flags)})
} }
@ -121,6 +125,7 @@ func (e *NAT) unmarshal(fam byte, data []byte) error {
e.Persistent = (flags & NF_NAT_RANGE_PERSISTENT) != 0 e.Persistent = (flags & NF_NAT_RANGE_PERSISTENT) != 0
e.Random = (flags & NF_NAT_RANGE_PROTO_RANDOM) != 0 e.Random = (flags & NF_NAT_RANGE_PROTO_RANDOM) != 0
e.FullyRandom = (flags & NF_NAT_RANGE_PROTO_RANDOM_FULLY) != 0 e.FullyRandom = (flags & NF_NAT_RANGE_PROTO_RANDOM_FULLY) != 0
e.Prefix = (flags & NF_NAT_RANGE_PREFIX) != 0
} }
} }
return ad.Err() return ad.Err()