NAT: prefix support (#251)
This commit is contained in:
parent
6d4c531bb6
commit
ef45dd3322
|
@ -287,6 +287,8 @@ const (
|
|||
NF_NAT_RANGE_PROTO_RANDOM_FULLY = 0x10
|
||||
// NF_NAT_RANGE_PERSISTENT defines flag for a persistent masquerade
|
||||
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) {
|
||||
|
|
|
@ -40,6 +40,7 @@ type NAT struct {
|
|||
Random bool
|
||||
FullyRandom bool
|
||||
Persistent bool
|
||||
Prefix bool
|
||||
}
|
||||
|
||||
// |00048|N-|00001| |len |flags| type|
|
||||
|
@ -82,6 +83,9 @@ func (e *NAT) marshal(fam byte) ([]byte, error) {
|
|||
if e.Persistent {
|
||||
flags |= NF_NAT_RANGE_PERSISTENT
|
||||
}
|
||||
if e.Prefix {
|
||||
flags |= NF_NAT_RANGE_PREFIX
|
||||
}
|
||||
if flags != 0 {
|
||||
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.Random = (flags & NF_NAT_RANGE_PROTO_RANDOM) != 0
|
||||
e.FullyRandom = (flags & NF_NAT_RANGE_PROTO_RANDOM_FULLY) != 0
|
||||
e.Prefix = (flags & NF_NAT_RANGE_PREFIX) != 0
|
||||
}
|
||||
}
|
||||
return ad.Err()
|
||||
|
|
Loading…
Reference in New Issue