datapath: Simplify flow mask cache delete.
[cascardo/ovs.git] / lib / netlink-protocol.h
1 /*
2  * Copyright (c) 2008, 2010, 2011, 2014 Nicira, Inc.
3  *
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:
7  *
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.
15  */
16
17 #ifndef NETLINK_PROTOCOL_H
18 #define NETLINK_PROTOCOL_H 1
19
20 /* Netlink protocol definitions.
21  *
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  */
31
32 /* This file is included by windows driver as well (as of now).
33  * It does not have access to following header files,
34  * hence do not include them for windows driver.
35  */
36 #ifndef OVS_WIN_DP
37 #include <stdint.h>
38 #include <sys/socket.h>
39 #include "util.h"
40 #endif
41
42 #ifdef HAVE_NETLINK
43 #include <linux/netlink.h>
44 #include <linux/genetlink.h>
45
46 #else
47 #define NETLINK_GENERIC         16
48
49 /* nlmsg_flags bits. */
50 #define NLM_F_REQUEST           0x001
51 #define NLM_F_MULTI             0x002
52 #define NLM_F_ACK               0x004
53 #define NLM_F_ECHO              0x008
54
55 #define NLM_F_ROOT              0x100
56 #define NLM_F_MATCH             0x200
57 #define NLM_F_EXCL              0x200
58 #define NLM_F_ATOMIC            0x400
59 #define NLM_F_CREATE            0x400
60 #define NLM_F_DUMP              (NLM_F_ROOT | NLM_F_MATCH)
61
62 /* nlmsg_type values. */
63 #define NLMSG_NOOP              1
64 #define NLMSG_ERROR             2
65 #define NLMSG_DONE              3
66 #define NLMSG_OVERRUN           4
67
68 #define NLMSG_MIN_TYPE          0x10
69
70 #define MAX_LINKS               32
71
72 struct nlmsghdr {
73     uint32_t nlmsg_len;
74     uint16_t nlmsg_type;
75     uint16_t nlmsg_flags;
76     uint32_t nlmsg_seq;
77     uint32_t nlmsg_pid;
78 };
79 BUILD_ASSERT_DECL(sizeof(struct nlmsghdr) == 16);
80
81 #define NLMSG_ALIGNTO 4
82 #define NLMSG_ALIGN(SIZE) ROUND_UP(SIZE, NLMSG_ALIGNTO)
83 #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
84
85 struct nlmsgerr
86 {
87         int error;
88         struct nlmsghdr msg;
89 };
90 BUILD_ASSERT_DECL(sizeof(struct nlmsgerr) == 20);
91
92 struct genlmsghdr {
93     uint8_t cmd;
94     uint8_t version;
95     uint16_t reserved;
96 };
97 BUILD_ASSERT_DECL(sizeof(struct genlmsghdr) == 4);
98
99 #define GENL_HDRLEN NLMSG_ALIGN(sizeof(struct genlmsghdr))
100
101 struct nlattr {
102     uint16_t nla_len;
103     uint16_t nla_type;
104 };
105 BUILD_ASSERT_DECL(sizeof(struct nlattr) == 4);
106
107 #define NLA_ALIGNTO 4
108 #define NLA_ALIGN(SIZE) ROUND_UP(SIZE, NLA_ALIGNTO)
109 #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
110
111 #define GENL_MIN_ID     NLMSG_MIN_TYPE
112 #define GENL_MAX_ID     1023
113
114 #define GENL_ID_CTRL            NLMSG_MIN_TYPE
115
116 enum {
117         CTRL_CMD_UNSPEC,
118         CTRL_CMD_NEWFAMILY,
119         CTRL_CMD_DELFAMILY,
120         CTRL_CMD_GETFAMILY,
121         CTRL_CMD_NEWOPS,
122         CTRL_CMD_DELOPS,
123         CTRL_CMD_GETOPS,
124         __CTRL_CMD_MAX,
125 };
126
127 #define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)
128
129 enum {
130         CTRL_ATTR_UNSPEC,
131         CTRL_ATTR_FAMILY_ID,
132         CTRL_ATTR_FAMILY_NAME,
133         CTRL_ATTR_VERSION,
134         CTRL_ATTR_HDRSIZE,
135         CTRL_ATTR_MAXATTR,
136         CTRL_ATTR_OPS,
137         __CTRL_ATTR_MAX,
138 };
139
140 #define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)
141
142 enum {
143         CTRL_ATTR_OP_UNSPEC,
144         CTRL_ATTR_OP_ID,
145         CTRL_ATTR_OP_FLAGS,
146         __CTRL_ATTR_OP_MAX,
147 };
148
149 #define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
150 #endif  /* !HAVE_NETLINK */
151
152 /* These were introduced all together in 2.6.24. */
153 #ifndef NLA_TYPE_MASK
154 #define NLA_F_NESTED        (1 << 15)
155 #define NLA_F_NET_BYTEORDER (1 << 14)
156 #define NLA_TYPE_MASK       ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
157 #endif
158
159 /* These were introduced all together in 2.6.14.  (We want our programs to
160  * support the newer kernel features even if compiled with older headers.) */
161 #ifndef NETLINK_ADD_MEMBERSHIP
162 #define NETLINK_ADD_MEMBERSHIP 1
163 #define NETLINK_DROP_MEMBERSHIP 2
164 #endif
165
166 /* These were introduced all together in 2.6.23.  (We want our programs to
167  * support the newer kernel features even if compiled with older headers.) */
168 #ifndef CTRL_ATTR_MCAST_GRP_MAX
169
170 #undef CTRL_ATTR_MAX
171 #define CTRL_ATTR_MAX 7
172 #define CTRL_ATTR_MCAST_GROUPS 7
173
174 enum {
175     CTRL_ATTR_MCAST_GRP_UNSPEC,
176     CTRL_ATTR_MCAST_GRP_NAME,
177     CTRL_ATTR_MCAST_GRP_ID,
178     __CTRL_ATTR_MCAST_GRP_MAX,
179 };
180
181 #define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
182 #endif /* CTRL_ATTR_MCAST_GRP_MAX */
183
184 #endif /* netlink-protocol.h */