]> git.proxmox.com Git - mirror_ovs.git/blame - lib/netlink-protocol.h
ofp-ed-props: Fix using uninitialized padding for NSH encap actions.
[mirror_ovs.git] / lib / netlink-protocol.h
CommitLineData
064af421 1/*
aa359b5f 2 * Copyright (c) 2008, 2010, 2011, 2014 Nicira, Inc.
064af421 3 *
a14bc59f
BP
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:
064af421 7 *
a14bc59f
BP
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
064af421
BP
15 */
16
17#ifndef NETLINK_PROTOCOL_H
18#define NETLINK_PROTOCOL_H 1
19
20/* Netlink protocol definitions.
21 *
365a2517
BP
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.
26 *
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.
30 */
064af421
BP
31
32#include <stdint.h>
33#include <sys/socket.h>
34#include "util.h"
35
365a2517
BP
36#ifdef HAVE_NETLINK
37#include <linux/netlink.h>
38#include <linux/genetlink.h>
b0025c83 39
365a2517 40#else
218e42da 41#define NETLINK_NETFILTER 12
064af421
BP
42#define NETLINK_GENERIC 16
43
064af421
BP
44/* nlmsg_flags bits. */
45#define NLM_F_REQUEST 0x001
46#define NLM_F_MULTI 0x002
47#define NLM_F_ACK 0x004
48#define NLM_F_ECHO 0x008
49
1f161318 50/* GET request flag.*/
064af421
BP
51#define NLM_F_ROOT 0x100
52#define NLM_F_MATCH 0x200
53#define NLM_F_ATOMIC 0x400
54#define NLM_F_DUMP (NLM_F_ROOT | NLM_F_MATCH)
55
1f161318
YHW
56/* NEW request flags. */
57#define NLM_F_REPLACE 0x100
58#define NLM_F_EXCL 0x200
59#define NLM_F_CREATE 0x400
60
064af421
BP
61/* nlmsg_type values. */
62#define NLMSG_NOOP 1
63#define NLMSG_ERROR 2
64#define NLMSG_DONE 3
65#define NLMSG_OVERRUN 4
66
67#define NLMSG_MIN_TYPE 0x10
68
1675f19e
AS
69#define MAX_LINKS 32
70
064af421
BP
71struct nlmsghdr {
72 uint32_t nlmsg_len;
73 uint16_t nlmsg_type;
74 uint16_t nlmsg_flags;
75 uint32_t nlmsg_seq;
76 uint32_t nlmsg_pid;
77};
78BUILD_ASSERT_DECL(sizeof(struct nlmsghdr) == 16);
79
80#define NLMSG_ALIGNTO 4
81#define NLMSG_ALIGN(SIZE) ROUND_UP(SIZE, NLMSG_ALIGNTO)
82#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
83
84struct nlmsgerr
85{
86 int error;
87 struct nlmsghdr msg;
88};
89BUILD_ASSERT_DECL(sizeof(struct nlmsgerr) == 20);
90
064af421
BP
91struct genlmsghdr {
92 uint8_t cmd;
93 uint8_t version;
94 uint16_t reserved;
95};
96BUILD_ASSERT_DECL(sizeof(struct genlmsghdr) == 4);
97
98#define GENL_HDRLEN NLMSG_ALIGN(sizeof(struct genlmsghdr))
99
100struct nlattr {
101 uint16_t nla_len;
102 uint16_t nla_type;
103};
104BUILD_ASSERT_DECL(sizeof(struct nlattr) == 4);
105
106#define NLA_ALIGNTO 4
107#define NLA_ALIGN(SIZE) ROUND_UP(SIZE, NLA_ALIGNTO)
108#define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
109
110#define GENL_MIN_ID NLMSG_MIN_TYPE
111#define GENL_MAX_ID 1023
112
113#define GENL_ID_CTRL NLMSG_MIN_TYPE
114
115enum {
116 CTRL_CMD_UNSPEC,
117 CTRL_CMD_NEWFAMILY,
118 CTRL_CMD_DELFAMILY,
119 CTRL_CMD_GETFAMILY,
120 CTRL_CMD_NEWOPS,
121 CTRL_CMD_DELOPS,
122 CTRL_CMD_GETOPS,
123 __CTRL_CMD_MAX,
124};
125
126#define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)
127
128enum {
129 CTRL_ATTR_UNSPEC,
130 CTRL_ATTR_FAMILY_ID,
131 CTRL_ATTR_FAMILY_NAME,
132 CTRL_ATTR_VERSION,
133 CTRL_ATTR_HDRSIZE,
134 CTRL_ATTR_MAXATTR,
135 CTRL_ATTR_OPS,
136 __CTRL_ATTR_MAX,
137};
138
139#define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)
140
141enum {
142 CTRL_ATTR_OP_UNSPEC,
143 CTRL_ATTR_OP_ID,
144 CTRL_ATTR_OP_FLAGS,
145 __CTRL_ATTR_OP_MAX,
146};
147
148#define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
365a2517 149#endif /* !HAVE_NETLINK */
064af421 150
7c624478
BP
151/* These were introduced all together in 2.6.24. */
152#ifndef NLA_TYPE_MASK
05fe1764
BP
153#define NLA_F_NESTED (1 << 15)
154#define NLA_F_NET_BYTEORDER (1 << 14)
155#define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
7c624478
BP
156#endif
157
cceb11f5
BP
158/* These were introduced all together in 2.6.14. (We want our programs to
159 * support the newer kernel features even if compiled with older headers.) */
160#ifndef NETLINK_ADD_MEMBERSHIP
161#define NETLINK_ADD_MEMBERSHIP 1
162#define NETLINK_DROP_MEMBERSHIP 2
163#endif
164
cf114a7f
FL
165/* This was introduced in v4.2. (We want our programs to support the newer
166 * kernel features even if compiled with older headers.) */
167#ifndef NETLINK_LISTEN_ALL_NSID
168#define NETLINK_LISTEN_ALL_NSID 8
169#endif
170
0a397a2f
BP
171/* These were introduced all together in 2.6.23. (We want our programs to
172 * support the newer kernel features even if compiled with older headers.) */
173#ifndef CTRL_ATTR_MCAST_GRP_MAX
174
175#undef CTRL_ATTR_MAX
176#define CTRL_ATTR_MAX 7
177#define CTRL_ATTR_MCAST_GROUPS 7
178
179enum {
05fe1764
BP
180 CTRL_ATTR_MCAST_GRP_UNSPEC,
181 CTRL_ATTR_MCAST_GRP_NAME,
182 CTRL_ATTR_MCAST_GRP_ID,
183 __CTRL_ATTR_MCAST_GRP_MAX,
0a397a2f
BP
184};
185
186#define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
187#endif /* CTRL_ATTR_MCAST_GRP_MAX */
188
064af421 189#endif /* netlink-protocol.h */