github.com/sagernet/netlink@v0.0.0-20240612041022-b9a21c07ac6a/nl/genetlink_linux.go (about)

     1  package nl
     2  
     3  import (
     4  	"unsafe"
     5  )
     6  
     7  const SizeofGenlmsg = 4
     8  
     9  const (
    10  	GENL_ID_CTRL      = 0x10
    11  	GENL_CTRL_VERSION = 2
    12  	GENL_CTRL_NAME    = "nlctrl"
    13  )
    14  
    15  const (
    16  	GENL_CTRL_CMD_GETFAMILY = 3
    17  )
    18  
    19  const (
    20  	GENL_CTRL_ATTR_UNSPEC = iota
    21  	GENL_CTRL_ATTR_FAMILY_ID
    22  	GENL_CTRL_ATTR_FAMILY_NAME
    23  	GENL_CTRL_ATTR_VERSION
    24  	GENL_CTRL_ATTR_HDRSIZE
    25  	GENL_CTRL_ATTR_MAXATTR
    26  	GENL_CTRL_ATTR_OPS
    27  	GENL_CTRL_ATTR_MCAST_GROUPS
    28  )
    29  
    30  const (
    31  	GENL_CTRL_ATTR_OP_UNSPEC = iota
    32  	GENL_CTRL_ATTR_OP_ID
    33  	GENL_CTRL_ATTR_OP_FLAGS
    34  )
    35  
    36  const (
    37  	GENL_ADMIN_PERM = 1 << iota
    38  	GENL_CMD_CAP_DO
    39  	GENL_CMD_CAP_DUMP
    40  	GENL_CMD_CAP_HASPOL
    41  )
    42  
    43  const (
    44  	GENL_CTRL_ATTR_MCAST_GRP_UNSPEC = iota
    45  	GENL_CTRL_ATTR_MCAST_GRP_NAME
    46  	GENL_CTRL_ATTR_MCAST_GRP_ID
    47  )
    48  
    49  const (
    50  	GENL_GTP_VERSION = 0
    51  	GENL_GTP_NAME    = "gtp"
    52  )
    53  
    54  const (
    55  	GENL_GTP_CMD_NEWPDP = iota
    56  	GENL_GTP_CMD_DELPDP
    57  	GENL_GTP_CMD_GETPDP
    58  )
    59  
    60  const (
    61  	GENL_GTP_ATTR_UNSPEC = iota
    62  	GENL_GTP_ATTR_LINK
    63  	GENL_GTP_ATTR_VERSION
    64  	GENL_GTP_ATTR_TID
    65  	GENL_GTP_ATTR_PEER_ADDRESS
    66  	GENL_GTP_ATTR_MS_ADDRESS
    67  	GENL_GTP_ATTR_FLOW
    68  	GENL_GTP_ATTR_NET_NS_FD
    69  	GENL_GTP_ATTR_I_TEI
    70  	GENL_GTP_ATTR_O_TEI
    71  	GENL_GTP_ATTR_PAD
    72  )
    73  
    74  type Genlmsg struct {
    75  	Command uint8
    76  	Version uint8
    77  }
    78  
    79  func (msg *Genlmsg) Len() int {
    80  	return SizeofGenlmsg
    81  }
    82  
    83  func DeserializeGenlmsg(b []byte) *Genlmsg {
    84  	return (*Genlmsg)(unsafe.Pointer(&b[0:SizeofGenlmsg][0]))
    85  }
    86  
    87  func (msg *Genlmsg) Serialize() []byte {
    88  	return (*(*[SizeofGenlmsg]byte)(unsafe.Pointer(msg)))[:]
    89  }