Skip to content

Commit

Permalink
NAT: prefix support (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Dec 22, 2023
1 parent 6d4c531 commit ef45dd3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions expr/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions expr/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type NAT struct {
Random bool
FullyRandom bool
Persistent bool
Prefix bool
}

// |00048|N-|00001| |len |flags| type|
Expand Down Expand Up @@ -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)})
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ef45dd3

Please sign in to comment.