packets: Define RSO flags.
[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 #include <stdint.h>
33 #include <sys/socket.h>
34 #include "util.h"
35
36 #ifdef HAVE_NETLINK
37 #include <linux/netlink.h>
38 #include <linux/genetlink.h>
39
40 #else
41 #define NETLINK_NETFILTER       12
42 #define NETLINK_GENERIC         16
43
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
50 #define NLM_F_ROOT              0x100
51 #define NLM_F_MATCH             0x200
52 #define NLM_F_EXCL              0x200
53 #define NLM_F_ATOMIC            0x400
54 #define NLM_F_CREATE            0x400
55 #define NLM_F_DUMP              (NLM_F_ROOT | NLM_F_MATCH)
56
57 /* nlmsg_type values. */
58 #define NLMSG_NOOP              1
59 #define NLMSG_ERROR             2
60 #define NLMSG_DONE              3
61 #define NLMSG_OVERRUN           4
62
63 #define NLMSG_MIN_TYPE          0x10
64
65 #define MAX_LINKS               32
66
67 struct nlmsghdr {
68     uint32_t nlmsg_len;
69     uint16_t nlmsg_type;
70     uint16_t nlmsg_flags;
71     uint32_t nlmsg_seq;
72     uint32_t nlmsg_pid;
73 };
74 BUILD_ASSERT_DECL(sizeof(struct nlmsghdr) == 16);
75
76 #define NLMSG_ALIGNTO 4
77 #define NLMSG_ALIGN(SIZE) ROUND_UP(SIZE, NLMSG_ALIGNTO)
78 #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
79
80 struct nlmsgerr
81 {
82         int error;
83         struct nlmsghdr msg;
84 };
85 BUILD_ASSERT_DECL(sizeof(struct nlmsgerr) == 20);
86
87 struct genlmsghdr {
88     uint8_t cmd;
89     uint8_t version;
90     uint16_t reserved;
91 };
92 BUILD_ASSERT_DECL(sizeof(struct genlmsghdr) == 4);
93
94 #define GENL_HDRLEN NLMSG_ALIGN(sizeof(struct genlmsghdr))
95
96 struct nlattr {
97     uint16_t nla_len;
98     uint16_t nla_type;
99 };
100 BUILD_ASSERT_DECL(sizeof(struct nlattr) == 4);
101
102 #define NLA_ALIGNTO 4
103 #define NLA_ALIGN(SIZE) ROUND_UP(SIZE, NLA_ALIGNTO)
104 #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
105
106 #define GENL_MIN_ID     NLMSG_MIN_TYPE
107 #define GENL_MAX_ID     1023
108
109 #define GENL_ID_CTRL            NLMSG_MIN_TYPE
110
111 enum {
112         CTRL_CMD_UNSPEC,
113         CTRL_CMD_NEWFAMILY,
114         CTRL_CMD_DELFAMILY,
115         CTRL_CMD_GETFAMILY,
116         CTRL_CMD_NEWOPS,
117         CTRL_CMD_DELOPS,
118         CTRL_CMD_GETOPS,
119         __CTRL_CMD_MAX,
120 };
121
122 #define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)
123
124 enum {
125         CTRL_ATTR_UNSPEC,
126         CTRL_ATTR_FAMILY_ID,
127         CTRL_ATTR_FAMILY_NAME,
128         CTRL_ATTR_VERSION,
129         CTRL_ATTR_HDRSIZE,
130         CTRL_ATTR_MAXATTR,
131         CTRL_ATTR_OPS,
132         __CTRL_ATTR_MAX,
133 };
134
135 #define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)
136
137 enum {
138         CTRL_ATTR_OP_UNSPEC,
139         CTRL_ATTR_OP_ID,
140         CTRL_ATTR_OP_FLAGS,
141         __CTRL_ATTR_OP_MAX,
142 };
143
144 #define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
145 #endif  /* !HAVE_NETLINK */
146
147 /* These were introduced all together in 2.6.24. */
148 #ifndef NLA_TYPE_MASK
149 #define NLA_F_NESTED        (1 << 15)
150 #define NLA_F_NET_BYTEORDER (1 << 14)
151 #define NLA_TYPE_MASK       ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
152 #endif
153
154 /* These were introduced all together in 2.6.14.  (We want our programs to
155  * support the newer kernel features even if compiled with older headers.) */
156 #ifndef NETLINK_ADD_MEMBERSHIP
157 #define NETLINK_ADD_MEMBERSHIP 1
158 #define NETLINK_DROP_MEMBERSHIP 2
159 #endif
160
161 /* These were introduced all together in 2.6.23.  (We want our programs to
162  * support the newer kernel features even if compiled with older headers.) */
163 #ifndef CTRL_ATTR_MCAST_GRP_MAX
164
165 #undef CTRL_ATTR_MAX
166 #define CTRL_ATTR_MAX 7
167 #define CTRL_ATTR_MCAST_GROUPS 7
168
169 enum {
170     CTRL_ATTR_MCAST_GRP_UNSPEC,
171     CTRL_ATTR_MCAST_GRP_NAME,
172     CTRL_ATTR_MCAST_GRP_ID,
173     __CTRL_ATTR_MCAST_GRP_MAX,
174 };
175
176 #define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
177 #endif /* CTRL_ATTR_MCAST_GRP_MAX */
178
179 #endif /* netlink-protocol.h */