2 * Copyright (c) 2008, 2010, 2011, 2014 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef NETLINK_PROTOCOL_H
18 #define NETLINK_PROTOCOL_H 1
20 /* Netlink protocol definitions.
22 * Netlink is a message framing format described in RFC 3549 and used heavily
23 * in Linux to access the network stack. Open vSwitch uses AF_NETLINK sockets
24 * for this purpose on Linux. But on all platforms, Open vSwitch uses Netlink
25 * message framing internally for certain purposes.
27 * This header provides access to the Netlink message framing definitions
28 * regardless of platform. On Linux, it includes the proper headers directly;
29 * on other platforms it directly defines the structures and macros itself.
33 #include <sys/socket.h>
37 #include <linux/netlink.h>
38 #include <linux/genetlink.h>
41 #define NETLINK_GENERIC 16
43 /* nlmsg_flags bits. */
44 #define NLM_F_REQUEST 0x001
45 #define NLM_F_MULTI 0x002
46 #define NLM_F_ACK 0x004
47 #define NLM_F_ECHO 0x008
49 #define NLM_F_ROOT 0x100
50 #define NLM_F_MATCH 0x200
51 #define NLM_F_EXCL 0x200
52 #define NLM_F_ATOMIC 0x400
53 #define NLM_F_CREATE 0x400
54 #define NLM_F_DUMP (NLM_F_ROOT | NLM_F_MATCH)
56 /* nlmsg_type values. */
60 #define NLMSG_OVERRUN 4
62 #define NLMSG_MIN_TYPE 0x10
73 BUILD_ASSERT_DECL(sizeof(struct nlmsghdr
) == 16);
75 #define NLMSG_ALIGNTO 4
76 #define NLMSG_ALIGN(SIZE) ROUND_UP(SIZE, NLMSG_ALIGNTO)
77 #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
84 BUILD_ASSERT_DECL(sizeof(struct nlmsgerr
) == 20);
91 BUILD_ASSERT_DECL(sizeof(struct genlmsghdr
) == 4);
93 #define GENL_HDRLEN NLMSG_ALIGN(sizeof(struct genlmsghdr))
99 BUILD_ASSERT_DECL(sizeof(struct nlattr
) == 4);
101 #define NLA_ALIGNTO 4
102 #define NLA_ALIGN(SIZE) ROUND_UP(SIZE, NLA_ALIGNTO)
103 #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
105 #define GENL_MIN_ID NLMSG_MIN_TYPE
106 #define GENL_MAX_ID 1023
108 #define GENL_ID_CTRL NLMSG_MIN_TYPE
121 #define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)
126 CTRL_ATTR_FAMILY_NAME
,
134 #define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)
143 #define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
144 #endif /* !HAVE_NETLINK */
146 /* These were introduced all together in 2.6.24. */
147 #ifndef NLA_TYPE_MASK
148 #define NLA_F_NESTED (1 << 15)
149 #define NLA_F_NET_BYTEORDER (1 << 14)
150 #define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
153 /* These were introduced all together in 2.6.14. (We want our programs to
154 * support the newer kernel features even if compiled with older headers.) */
155 #ifndef NETLINK_ADD_MEMBERSHIP
156 #define NETLINK_ADD_MEMBERSHIP 1
157 #define NETLINK_DROP_MEMBERSHIP 2
160 /* These were introduced all together in 2.6.23. (We want our programs to
161 * support the newer kernel features even if compiled with older headers.) */
162 #ifndef CTRL_ATTR_MCAST_GRP_MAX
165 #define CTRL_ATTR_MAX 7
166 #define CTRL_ATTR_MCAST_GROUPS 7
169 CTRL_ATTR_MCAST_GRP_UNSPEC
,
170 CTRL_ATTR_MCAST_GRP_NAME
,
171 CTRL_ATTR_MCAST_GRP_ID
,
172 __CTRL_ATTR_MCAST_GRP_MAX
,
175 #define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
176 #endif /* CTRL_ATTR_MCAST_GRP_MAX */
178 #endif /* netlink-protocol.h */