Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 #ifndef _UAPI__LINUX_NETLINK_H
0003 #define _UAPI__LINUX_NETLINK_H
0004 
0005 #include <linux/const.h>
0006 #include <linux/socket.h> /* for __kernel_sa_family_t */
0007 #include <linux/types.h>
0008 
0009 #define NETLINK_ROUTE       0   /* Routing/device hook              */
0010 #define NETLINK_UNUSED      1   /* Unused number                */
0011 #define NETLINK_USERSOCK    2   /* Reserved for user mode socket protocols  */
0012 #define NETLINK_FIREWALL    3   /* Unused number, formerly ip_queue     */
0013 #define NETLINK_SOCK_DIAG   4   /* socket monitoring                */
0014 #define NETLINK_NFLOG       5   /* netfilter/iptables ULOG */
0015 #define NETLINK_XFRM        6   /* ipsec */
0016 #define NETLINK_SELINUX     7   /* SELinux event notifications */
0017 #define NETLINK_ISCSI       8   /* Open-iSCSI */
0018 #define NETLINK_AUDIT       9   /* auditing */
0019 #define NETLINK_FIB_LOOKUP  10  
0020 #define NETLINK_CONNECTOR   11
0021 #define NETLINK_NETFILTER   12  /* netfilter subsystem */
0022 #define NETLINK_IP6_FW      13
0023 #define NETLINK_DNRTMSG     14  /* DECnet routing messages */
0024 #define NETLINK_KOBJECT_UEVENT  15  /* Kernel messages to userspace */
0025 #define NETLINK_GENERIC     16
0026 /* leave room for NETLINK_DM (DM Events) */
0027 #define NETLINK_SCSITRANSPORT   18  /* SCSI Transports */
0028 #define NETLINK_ECRYPTFS    19
0029 #define NETLINK_RDMA        20
0030 #define NETLINK_CRYPTO      21  /* Crypto layer */
0031 #define NETLINK_SMC     22  /* SMC monitoring */
0032 
0033 #define NETLINK_INET_DIAG   NETLINK_SOCK_DIAG
0034 
0035 #define MAX_LINKS 32        
0036 
0037 struct sockaddr_nl {
0038     __kernel_sa_family_t    nl_family;  /* AF_NETLINK   */
0039     unsigned short  nl_pad;     /* zero     */
0040     __u32       nl_pid;     /* port ID  */
0041         __u32       nl_groups;  /* multicast groups mask */
0042 };
0043 
0044 struct nlmsghdr {
0045     __u32       nlmsg_len;  /* Length of message including header */
0046     __u16       nlmsg_type; /* Message content */
0047     __u16       nlmsg_flags;    /* Additional flags */
0048     __u32       nlmsg_seq;  /* Sequence number */
0049     __u32       nlmsg_pid;  /* Sending process port ID */
0050 };
0051 
0052 /* Flags values */
0053 
0054 #define NLM_F_REQUEST       0x01    /* It is request message.   */
0055 #define NLM_F_MULTI     0x02    /* Multipart message, terminated by NLMSG_DONE */
0056 #define NLM_F_ACK       0x04    /* Reply with ack, with zero or error code */
0057 #define NLM_F_ECHO      0x08    /* Echo this request        */
0058 #define NLM_F_DUMP_INTR     0x10    /* Dump was inconsistent due to sequence change */
0059 #define NLM_F_DUMP_FILTERED 0x20    /* Dump was filtered as requested */
0060 
0061 /* Modifiers to GET request */
0062 #define NLM_F_ROOT  0x100   /* specify tree root    */
0063 #define NLM_F_MATCH 0x200   /* return all matching  */
0064 #define NLM_F_ATOMIC    0x400   /* atomic GET       */
0065 #define NLM_F_DUMP  (NLM_F_ROOT|NLM_F_MATCH)
0066 
0067 /* Modifiers to NEW request */
0068 #define NLM_F_REPLACE   0x100   /* Override existing        */
0069 #define NLM_F_EXCL  0x200   /* Do not touch, if it exists   */
0070 #define NLM_F_CREATE    0x400   /* Create, if it does not exist */
0071 #define NLM_F_APPEND    0x800   /* Add to end of list       */
0072 
0073 /* Modifiers to DELETE request */
0074 #define NLM_F_NONREC    0x100   /* Do not delete recursively    */
0075 #define NLM_F_BULK  0x200   /* Delete multiple objects  */
0076 
0077 /* Flags for ACK message */
0078 #define NLM_F_CAPPED    0x100   /* request was capped */
0079 #define NLM_F_ACK_TLVS  0x200   /* extended ACK TVLs were included */
0080 
0081 /*
0082    4.4BSD ADD       NLM_F_CREATE|NLM_F_EXCL
0083    4.4BSD CHANGE    NLM_F_REPLACE
0084 
0085    True CHANGE      NLM_F_CREATE|NLM_F_REPLACE
0086    Append       NLM_F_CREATE
0087    Check        NLM_F_EXCL
0088  */
0089 
0090 #define NLMSG_ALIGNTO   4U
0091 #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
0092 #define NLMSG_HDRLEN     ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
0093 #define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
0094 #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
0095 #define NLMSG_DATA(nlh)  ((void *)(((char *)nlh) + NLMSG_HDRLEN))
0096 #define NLMSG_NEXT(nlh,len)  ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
0097                   (struct nlmsghdr *)(((char *)(nlh)) + \
0098                   NLMSG_ALIGN((nlh)->nlmsg_len)))
0099 #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
0100                (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
0101                (nlh)->nlmsg_len <= (len))
0102 #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
0103 
0104 #define NLMSG_NOOP      0x1 /* Nothing.     */
0105 #define NLMSG_ERROR     0x2 /* Error        */
0106 #define NLMSG_DONE      0x3 /* End of a dump    */
0107 #define NLMSG_OVERRUN       0x4 /* Data lost        */
0108 
0109 #define NLMSG_MIN_TYPE      0x10    /* < 0x10: reserved control messages */
0110 
0111 struct nlmsgerr {
0112     int     error;
0113     struct nlmsghdr msg;
0114     /*
0115      * followed by the message contents unless NETLINK_CAP_ACK was set
0116      * or the ACK indicates success (error == 0)
0117      * message length is aligned with NLMSG_ALIGN()
0118      */
0119     /*
0120      * followed by TLVs defined in enum nlmsgerr_attrs
0121      * if NETLINK_EXT_ACK was set
0122      */
0123 };
0124 
0125 /**
0126  * enum nlmsgerr_attrs - nlmsgerr attributes
0127  * @NLMSGERR_ATTR_UNUSED: unused
0128  * @NLMSGERR_ATTR_MSG: error message string (string)
0129  * @NLMSGERR_ATTR_OFFS: offset of the invalid attribute in the original
0130  *   message, counting from the beginning of the header (u32)
0131  * @NLMSGERR_ATTR_COOKIE: arbitrary subsystem specific cookie to
0132  *  be used - in the success case - to identify a created
0133  *  object or operation or similar (binary)
0134  * @NLMSGERR_ATTR_POLICY: policy for a rejected attribute
0135  * @__NLMSGERR_ATTR_MAX: number of attributes
0136  * @NLMSGERR_ATTR_MAX: highest attribute number
0137  */
0138 enum nlmsgerr_attrs {
0139     NLMSGERR_ATTR_UNUSED,
0140     NLMSGERR_ATTR_MSG,
0141     NLMSGERR_ATTR_OFFS,
0142     NLMSGERR_ATTR_COOKIE,
0143     NLMSGERR_ATTR_POLICY,
0144 
0145     __NLMSGERR_ATTR_MAX,
0146     NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
0147 };
0148 
0149 #define NETLINK_ADD_MEMBERSHIP      1
0150 #define NETLINK_DROP_MEMBERSHIP     2
0151 #define NETLINK_PKTINFO         3
0152 #define NETLINK_BROADCAST_ERROR     4
0153 #define NETLINK_NO_ENOBUFS      5
0154 #ifndef __KERNEL__
0155 #define NETLINK_RX_RING         6
0156 #define NETLINK_TX_RING         7
0157 #endif
0158 #define NETLINK_LISTEN_ALL_NSID     8
0159 #define NETLINK_LIST_MEMBERSHIPS    9
0160 #define NETLINK_CAP_ACK         10
0161 #define NETLINK_EXT_ACK         11
0162 #define NETLINK_GET_STRICT_CHK      12
0163 
0164 struct nl_pktinfo {
0165     __u32   group;
0166 };
0167 
0168 struct nl_mmap_req {
0169     unsigned int    nm_block_size;
0170     unsigned int    nm_block_nr;
0171     unsigned int    nm_frame_size;
0172     unsigned int    nm_frame_nr;
0173 };
0174 
0175 struct nl_mmap_hdr {
0176     unsigned int    nm_status;
0177     unsigned int    nm_len;
0178     __u32       nm_group;
0179     /* credentials */
0180     __u32       nm_pid;
0181     __u32       nm_uid;
0182     __u32       nm_gid;
0183 };
0184 
0185 #ifndef __KERNEL__
0186 enum nl_mmap_status {
0187     NL_MMAP_STATUS_UNUSED,
0188     NL_MMAP_STATUS_RESERVED,
0189     NL_MMAP_STATUS_VALID,
0190     NL_MMAP_STATUS_COPY,
0191     NL_MMAP_STATUS_SKIP,
0192 };
0193 
0194 #define NL_MMAP_MSG_ALIGNMENT       NLMSG_ALIGNTO
0195 #define NL_MMAP_MSG_ALIGN(sz)       __ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT)
0196 #define NL_MMAP_HDRLEN          NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr))
0197 #endif
0198 
0199 #define NET_MAJOR 36        /* Major 36 is reserved for networking                      */
0200 
0201 enum {
0202     NETLINK_UNCONNECTED = 0,
0203     NETLINK_CONNECTED,
0204 };
0205 
0206 /*
0207  *  <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
0208  * +---------------------+- - -+- - - - - - - - - -+- - -+
0209  * |        Header       | Pad |     Payload       | Pad |
0210  * |   (struct nlattr)   | ing |                   | ing |
0211  * +---------------------+- - -+- - - - - - - - - -+- - -+
0212  *  <-------------- nlattr->nla_len -------------->
0213  */
0214 
0215 struct nlattr {
0216     __u16           nla_len;
0217     __u16           nla_type;
0218 };
0219 
0220 /*
0221  * nla_type (16 bits)
0222  * +---+---+-------------------------------+
0223  * | N | O | Attribute Type                |
0224  * +---+---+-------------------------------+
0225  * N := Carries nested attributes
0226  * O := Payload stored in network byte order
0227  *
0228  * Note: The N and O flag are mutually exclusive.
0229  */
0230 #define NLA_F_NESTED        (1 << 15)
0231 #define NLA_F_NET_BYTEORDER (1 << 14)
0232 #define NLA_TYPE_MASK       ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
0233 
0234 #define NLA_ALIGNTO     4
0235 #define NLA_ALIGN(len)      (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
0236 #define NLA_HDRLEN      ((int) NLA_ALIGN(sizeof(struct nlattr)))
0237 
0238 /* Generic 32 bitflags attribute content sent to the kernel.
0239  *
0240  * The value is a bitmap that defines the values being set
0241  * The selector is a bitmask that defines which value is legit
0242  *
0243  * Examples:
0244  *  value = 0x0, and selector = 0x1
0245  *  implies we are selecting bit 1 and we want to set its value to 0.
0246  *
0247  *  value = 0x2, and selector = 0x2
0248  *  implies we are selecting bit 2 and we want to set its value to 1.
0249  *
0250  */
0251 struct nla_bitfield32 {
0252     __u32 value;
0253     __u32 selector;
0254 };
0255 
0256 /*
0257  * policy descriptions - it's specific to each family how this is used
0258  * Normally, it should be retrieved via a dump inside another attribute
0259  * specifying where it applies.
0260  */
0261 
0262 /**
0263  * enum netlink_attribute_type - type of an attribute
0264  * @NL_ATTR_TYPE_INVALID: unused
0265  * @NL_ATTR_TYPE_FLAG: flag attribute (present/not present)
0266  * @NL_ATTR_TYPE_U8: 8-bit unsigned attribute
0267  * @NL_ATTR_TYPE_U16: 16-bit unsigned attribute
0268  * @NL_ATTR_TYPE_U32: 32-bit unsigned attribute
0269  * @NL_ATTR_TYPE_U64: 64-bit unsigned attribute
0270  * @NL_ATTR_TYPE_S8: 8-bit signed attribute
0271  * @NL_ATTR_TYPE_S16: 16-bit signed attribute
0272  * @NL_ATTR_TYPE_S32: 32-bit signed attribute
0273  * @NL_ATTR_TYPE_S64: 64-bit signed attribute
0274  * @NL_ATTR_TYPE_BINARY: binary data, min/max length may be specified
0275  * @NL_ATTR_TYPE_STRING: string, min/max length may be specified
0276  * @NL_ATTR_TYPE_NUL_STRING: NUL-terminated string,
0277  *  min/max length may be specified
0278  * @NL_ATTR_TYPE_NESTED: nested, i.e. the content of this attribute
0279  *  consists of sub-attributes. The nested policy and maxtype
0280  *  inside may be specified.
0281  * @NL_ATTR_TYPE_NESTED_ARRAY: nested array, i.e. the content of this
0282  *  attribute contains sub-attributes whose type is irrelevant
0283  *  (just used to separate the array entries) and each such array
0284  *  entry has attributes again, the policy for those inner ones
0285  *  and the corresponding maxtype may be specified.
0286  * @NL_ATTR_TYPE_BITFIELD32: &struct nla_bitfield32 attribute
0287  */
0288 enum netlink_attribute_type {
0289     NL_ATTR_TYPE_INVALID,
0290 
0291     NL_ATTR_TYPE_FLAG,
0292 
0293     NL_ATTR_TYPE_U8,
0294     NL_ATTR_TYPE_U16,
0295     NL_ATTR_TYPE_U32,
0296     NL_ATTR_TYPE_U64,
0297 
0298     NL_ATTR_TYPE_S8,
0299     NL_ATTR_TYPE_S16,
0300     NL_ATTR_TYPE_S32,
0301     NL_ATTR_TYPE_S64,
0302 
0303     NL_ATTR_TYPE_BINARY,
0304     NL_ATTR_TYPE_STRING,
0305     NL_ATTR_TYPE_NUL_STRING,
0306 
0307     NL_ATTR_TYPE_NESTED,
0308     NL_ATTR_TYPE_NESTED_ARRAY,
0309 
0310     NL_ATTR_TYPE_BITFIELD32,
0311 };
0312 
0313 /**
0314  * enum netlink_policy_type_attr - policy type attributes
0315  * @NL_POLICY_TYPE_ATTR_UNSPEC: unused
0316  * @NL_POLICY_TYPE_ATTR_TYPE: type of the attribute,
0317  *  &enum netlink_attribute_type (U32)
0318  * @NL_POLICY_TYPE_ATTR_MIN_VALUE_S: minimum value for signed
0319  *  integers (S64)
0320  * @NL_POLICY_TYPE_ATTR_MAX_VALUE_S: maximum value for signed
0321  *  integers (S64)
0322  * @NL_POLICY_TYPE_ATTR_MIN_VALUE_U: minimum value for unsigned
0323  *  integers (U64)
0324  * @NL_POLICY_TYPE_ATTR_MAX_VALUE_U: maximum value for unsigned
0325  *  integers (U64)
0326  * @NL_POLICY_TYPE_ATTR_MIN_LENGTH: minimum length for binary
0327  *  attributes, no minimum if not given (U32)
0328  * @NL_POLICY_TYPE_ATTR_MAX_LENGTH: maximum length for binary
0329  *  attributes, no maximum if not given (U32)
0330  * @NL_POLICY_TYPE_ATTR_POLICY_IDX: sub policy for nested and
0331  *  nested array types (U32)
0332  * @NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE: maximum sub policy
0333  *  attribute for nested and nested array types, this can
0334  *  in theory be < the size of the policy pointed to by
0335  *  the index, if limited inside the nesting (U32)
0336  * @NL_POLICY_TYPE_ATTR_BITFIELD32_MASK: valid mask for the
0337  *  bitfield32 type (U32)
0338  * @NL_POLICY_TYPE_ATTR_MASK: mask of valid bits for unsigned integers (U64)
0339  * @NL_POLICY_TYPE_ATTR_PAD: pad attribute for 64-bit alignment
0340  */
0341 enum netlink_policy_type_attr {
0342     NL_POLICY_TYPE_ATTR_UNSPEC,
0343     NL_POLICY_TYPE_ATTR_TYPE,
0344     NL_POLICY_TYPE_ATTR_MIN_VALUE_S,
0345     NL_POLICY_TYPE_ATTR_MAX_VALUE_S,
0346     NL_POLICY_TYPE_ATTR_MIN_VALUE_U,
0347     NL_POLICY_TYPE_ATTR_MAX_VALUE_U,
0348     NL_POLICY_TYPE_ATTR_MIN_LENGTH,
0349     NL_POLICY_TYPE_ATTR_MAX_LENGTH,
0350     NL_POLICY_TYPE_ATTR_POLICY_IDX,
0351     NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE,
0352     NL_POLICY_TYPE_ATTR_BITFIELD32_MASK,
0353     NL_POLICY_TYPE_ATTR_PAD,
0354     NL_POLICY_TYPE_ATTR_MASK,
0355 
0356     /* keep last */
0357     __NL_POLICY_TYPE_ATTR_MAX,
0358     NL_POLICY_TYPE_ATTR_MAX = __NL_POLICY_TYPE_ATTR_MAX - 1
0359 };
0360 
0361 #endif /* _UAPI__LINUX_NETLINK_H */