Changeset View
Changeset View
Standalone View
Standalone View
sys/netlink/netlink.h
Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | |||||
enum nlmsginfo_attrs { | enum nlmsginfo_attrs { | ||||
NLMSGINFO_ATTR_UNUSED, | NLMSGINFO_ATTR_UNUSED, | ||||
NLMSGINFO_ATTR_PROCESS_ID = 1, /* u32, source process PID */ | NLMSGINFO_ATTR_PROCESS_ID = 1, /* u32, source process PID */ | ||||
NLMSGINFO_ATTR_PORT_ID = 2, /* u32, source socket nl_pid */ | NLMSGINFO_ATTR_PORT_ID = 2, /* u32, source socket nl_pid */ | ||||
NLMSGINFO_ATTR_SEQ_ID = 3, /* u32, source message seq_id */ | NLMSGINFO_ATTR_SEQ_ID = 3, /* u32, source message seq_id */ | ||||
}; | }; | ||||
#ifndef roundup2 | |||||
#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ | |||||
#endif | |||||
#define NL_ITEM_ALIGN_SIZE sizeof(uint32_t) | #define NL_ITEM_ALIGN_SIZE sizeof(uint32_t) | ||||
#define NL_ITEM_ALIGN(_len) roundup2(_len, NL_ITEM_ALIGN_SIZE) | #define NL_ITEM_ALIGN(_len) __align_up(_len, NL_ITEM_ALIGN_SIZE) | ||||
#define NL_ITEM_DATA(_ptr, _off) ((void *)((char *)(_ptr) + _off)) | #define NL_ITEM_DATA(_ptr, _off) ((void *)((char *)(_ptr) + _off)) | ||||
#define NL_ITEM_DATA_CONST(_ptr, _off) ((const void *)((const char *)(_ptr) + _off)) | #define NL_ITEM_DATA_CONST(_ptr, _off) ((const void *)((const char *)(_ptr) + _off)) | ||||
#define NL_ITEM_OK(_ptr, _len, _hlen, _LEN_M) \ | #define NL_ITEM_OK(_ptr, _len, _hlen, _LEN_M) \ | ||||
((_len) >= _hlen && _LEN_M(_ptr) >= _hlen && _LEN_M(_ptr) <= (_len)) | ((_len) >= _hlen && _LEN_M(_ptr) >= _hlen && _LEN_M(_ptr) <= (_len)) | ||||
#define NL_ITEM_NEXT(_ptr, _LEN_M) ((__typeof(_ptr))((char *)(_ptr) + _LEN_M(_ptr))) | #define NL_ITEM_NEXT(_ptr, _LEN_M) ((__typeof(_ptr))((char *)(_ptr) + _LEN_M(_ptr))) | ||||
#define NL_ITEM_ITER(_ptr, _len, _LEN_MACRO) \ | #define NL_ITEM_ITER(_ptr, _len, _LEN_MACRO) \ | ||||
((_len) -= _LEN_MACRO(_ptr), NL_ITEM_NEXT(_ptr, _LEN_MACRO)) | ((_len) -= _LEN_MACRO(_ptr), NL_ITEM_NEXT(_ptr, _LEN_MACRO)) | ||||
#ifndef _KERNEL | |||||
/* part of netlink(3) API */ | /* part of netlink(3) API */ | ||||
#define NLMSG_ALIGNTO NL_ITEM_ALIGN_SIZE | #define NLMSG_ALIGNTO NL_ITEM_ALIGN_SIZE | ||||
#define NLMSG_ALIGN(_len) NL_ITEM_ALIGN(_len) | #define NLMSG_ALIGN(_len) NL_ITEM_ALIGN(_len) | ||||
#define NLMSG_HDRLEN ((int)sizeof(struct nlmsghdr)) | |||||
#ifndef _KERNEL | |||||
/* part of netlink(3) API */ | |||||
#define NLMSG_HDRLEN (sizeof(struct nlmsghdr)) | |||||
jhb: sizeof() already returns a size_t, so you can just remove this cast instead | |||||
#define NLMSG_LENGTH(_len) ((_len) + NLMSG_HDRLEN) | #define NLMSG_LENGTH(_len) ((_len) + NLMSG_HDRLEN) | ||||
#define NLMSG_SPACE(_len) NLMSG_ALIGN(NLMSG_LENGTH(_len)) | #define NLMSG_SPACE(_len) NLMSG_ALIGN(NLMSG_LENGTH(_len)) | ||||
#define NLMSG_DATA(_hdr) NL_ITEM_DATA(_hdr, NLMSG_HDRLEN) | #define NLMSG_DATA(_hdr) NL_ITEM_DATA(_hdr, NLMSG_HDRLEN) | ||||
#define _NLMSG_LEN(_hdr) ((int)(_hdr)->nlmsg_len) | #define _NLMSG_LEN(_hdr) ((_hdr)->nlmsg_len) | ||||
#define _NLMSG_ALIGNED_LEN(_hdr) NLMSG_ALIGN(_NLMSG_LEN(_hdr)) | #define _NLMSG_ALIGNED_LEN(_hdr) NLMSG_ALIGN(_NLMSG_LEN(_hdr)) | ||||
#define NLMSG_OK(_hdr, _len) NL_ITEM_OK(_hdr, _len, NLMSG_HDRLEN, _NLMSG_LEN) | #define NLMSG_OK(_hdr, _len) NL_ITEM_OK(_hdr, _len, NLMSG_HDRLEN, _NLMSG_LEN) | ||||
#define NLMSG_PAYLOAD(_hdr,_len) (_NLMSG_LEN(_hdr) - NLMSG_SPACE((_len))) | #define NLMSG_PAYLOAD(_hdr,_len) (_NLMSG_LEN(_hdr) - NLMSG_SPACE((_len))) | ||||
#define NLMSG_NEXT(_hdr, _len) NL_ITEM_ITER(_hdr, _len, _NLMSG_ALIGNED_LEN) | #define NLMSG_NEXT(_hdr, _len) NL_ITEM_ITER(_hdr, _len, _NLMSG_ALIGNED_LEN) | ||||
#else | #else | ||||
#define NLMSG_ALIGNTO 4U | #define NLMSG_HDRLEN (NLMSG_ALIGN(sizeof(struct nlmsghdr))) | ||||
Done Inline ActionsI'm not sure you need this cast either jhb: I'm not sure you need this cast either | |||||
Done Inline ActionsYou can use tabs to align the macro value now while you are here. jhb: You can use tabs to align the macro value now while you are here. | |||||
#define NLMSG_ALIGN(len) (((len) + NLMSG_ALIGNTO - 1) & ~(NLMSG_ALIGNTO - 1)) | |||||
#define NLMSG_HDRLEN ((int)NLMSG_ALIGN(sizeof(struct nlmsghdr))) | |||||
#endif | #endif | ||||
/* | /* | ||||
* Base netlink attribute TLV header. | * Base netlink attribute TLV header. | ||||
*/ | */ | ||||
struct nlattr { | struct nlattr { | ||||
uint16_t nla_len; /* Total attribute length */ | uint16_t nla_len; /* Total attribute length */ | ||||
uint16_t nla_type; /* Attribute type */ | uint16_t nla_type; /* Attribute type */ | ||||
Show All 30 Lines |
sizeof() already returns a size_t, so you can just remove this cast instead