Skip to content

Commit bfa83a9

Browse files
tgrafThomas Graf
authored andcommitted
[NETLINK]: Type-safe netlink messages/attributes interface
Introduces a new type-safe interface for netlink message and attributes handling. The interface is fully binary compatible with the old interface towards userspace. Besides type safety, this interface features attribute validation capabilities, simplified message contstruction, and documentation. The resulting netlink code should be smaller, less error prone and easier to understand. Signed-off-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9fb9cbb commit bfa83a9

File tree

4 files changed

+1229
-2
lines changed

4 files changed

+1229
-2
lines changed

include/linux/netlink.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ struct nlmsghdr
7171

7272
#define NLMSG_ALIGNTO 4
7373
#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
74-
#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(sizeof(struct nlmsghdr)))
74+
#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
75+
#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN))
7576
#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
7677
#define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
7778
#define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
@@ -86,6 +87,8 @@ struct nlmsghdr
8687
#define NLMSG_DONE 0x3 /* End of a dump */
8788
#define NLMSG_OVERRUN 0x4 /* Data lost */
8889

90+
#define NLMSG_MIN_TYPE 0x10 /* < 0x10: reserved control messages */
91+
8992
struct nlmsgerr
9093
{
9194
int error;
@@ -108,6 +111,25 @@ enum {
108111
NETLINK_CONNECTED,
109112
};
110113

114+
/*
115+
* <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
116+
* +---------------------+- - -+- - - - - - - - - -+- - -+
117+
* | Header | Pad | Payload | Pad |
118+
* | (struct nlattr) | ing | | ing |
119+
* +---------------------+- - -+- - - - - - - - - -+- - -+
120+
* <-------------- nlattr->nla_len -------------->
121+
*/
122+
123+
struct nlattr
124+
{
125+
__u16 nla_len;
126+
__u16 nla_type;
127+
};
128+
129+
#define NLA_ALIGNTO 4
130+
#define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
131+
#define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
132+
111133
#ifdef __KERNEL__
112134

113135
#include <linux/capability.h>

0 commit comments

Comments
 (0)