Replace TODO const by golang.org/x/sys/unix (#256)

Replace some hardcoded consts by the ones provided in
golang.org/x/sys/unix
This commit is contained in:
Lionel Jouin 2024-03-18 08:32:45 +01:00 committed by GitHub
parent 5494b7c55f
commit 0b98a7af91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 13 deletions

View File

@ -57,11 +57,10 @@ func (c *CounterObj) marshal(data bool) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
const NFT_OBJECT_COUNTER = 1 // TODO: get into x/sys/unix
attrs := []netlink.Attribute{ attrs := []netlink.Attribute{
{Type: unix.NFTA_OBJ_TABLE, Data: []byte(c.Table.Name + "\x00")}, {Type: unix.NFTA_OBJ_TABLE, Data: []byte(c.Table.Name + "\x00")},
{Type: unix.NFTA_OBJ_NAME, Data: []byte(c.Name + "\x00")}, {Type: unix.NFTA_OBJ_NAME, Data: []byte(c.Name + "\x00")},
{Type: unix.NFTA_OBJ_TYPE, Data: binaryutil.BigEndian.PutUint32(NFT_OBJECT_COUNTER)}, {Type: unix.NFTA_OBJ_TYPE, Data: binaryutil.BigEndian.PutUint32(unix.NFT_OBJECT_COUNTER)},
} }
if data { if data {
attrs = append(attrs, netlink.Attribute{Type: unix.NLA_F_NESTED | unix.NFTA_OBJ_DATA, Data: obj}) attrs = append(attrs, netlink.Attribute{Type: unix.NLA_F_NESTED | unix.NFTA_OBJ_DATA, Data: obj})

View File

@ -279,16 +279,15 @@ type Masq struct {
RegProtoMax uint32 RegProtoMax uint32
} }
// TODO, Once the constants below are available in golang.org/x/sys/unix, switch to use those.
const ( const (
// NF_NAT_RANGE_PROTO_RANDOM defines flag for a random masquerade // NF_NAT_RANGE_PROTO_RANDOM defines flag for a random masquerade
NF_NAT_RANGE_PROTO_RANDOM = 0x4 NF_NAT_RANGE_PROTO_RANDOM = unix.NF_NAT_RANGE_PROTO_RANDOM
// NF_NAT_RANGE_PROTO_RANDOM_FULLY defines flag for a fully random masquerade // NF_NAT_RANGE_PROTO_RANDOM_FULLY defines flag for a fully random masquerade
NF_NAT_RANGE_PROTO_RANDOM_FULLY = 0x10 NF_NAT_RANGE_PROTO_RANDOM_FULLY = unix.NF_NAT_RANGE_PROTO_RANDOM_FULLY
// 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 = unix.NF_NAT_RANGE_PERSISTENT
// NF_NAT_RANGE_PREFIX defines flag for a prefix masquerade // NF_NAT_RANGE_PREFIX defines flag for a prefix masquerade
NF_NAT_RANGE_PREFIX = 0x40 NF_NAT_RANGE_PREFIX = unix.NF_NAT_RANGE_NETMAP
) )
func (e *Masq) marshal(fam byte) ([]byte, error) { func (e *Masq) marshal(fam byte) ([]byte, error) {

View File

@ -32,10 +32,9 @@ const (
QueueTotal QueueAttribute = unix.NFTA_QUEUE_TOTAL QueueTotal QueueAttribute = unix.NFTA_QUEUE_TOTAL
QueueFlags QueueAttribute = unix.NFTA_QUEUE_FLAGS QueueFlags QueueAttribute = unix.NFTA_QUEUE_FLAGS
// TODO: get into x/sys/unix QueueFlagBypass QueueFlag = unix.NFT_QUEUE_FLAG_BYPASS
QueueFlagBypass QueueFlag = 0x01 QueueFlagFanout QueueFlag = unix.NFT_QUEUE_FLAG_CPU_FANOUT
QueueFlagFanout QueueFlag = 0x02 QueueFlagMask QueueFlag = unix.NFT_QUEUE_FLAG_MASK
QueueFlagMask QueueFlag = 0x03
) )
type Queue struct { type Queue struct {

3
obj.go
View File

@ -141,7 +141,6 @@ func objFromMsg(msg netlink.Message) (Obj, error) {
name string name string
objectType uint32 objectType uint32
) )
const NFT_OBJECT_COUNTER = 1 // TODO: get into x/sys/unix
for ad.Next() { for ad.Next() {
switch ad.Type() { switch ad.Type() {
case unix.NFTA_OBJ_TABLE: case unix.NFTA_OBJ_TABLE:
@ -152,7 +151,7 @@ func objFromMsg(msg netlink.Message) (Obj, error) {
objectType = ad.Uint32() objectType = ad.Uint32()
case unix.NFTA_OBJ_DATA: case unix.NFTA_OBJ_DATA:
switch objectType { switch objectType {
case NFT_OBJECT_COUNTER: case unix.NFT_OBJECT_COUNTER:
o := CounterObj{ o := CounterObj{
Table: table, Table: table,
Name: name, Name: name,