datapath: Convert ODP_EXECUTE to use Netlink framing.
[sliver-openvswitch.git] / include / openvswitch / datapath-protocol.h
1 /*
2  * Copyright (c) 2009, 2010, 2011 Nicira Networks.
3  *
4  * This file is offered under your choice of two licenses: Apache 2.0 or GNU
5  * GPL 2.0 or later.  The permission statements for each of these licenses is
6  * given below.  You may license your modifications to this file under either
7  * of these licenses or both.  If you wish to license your modifications under
8  * only one of these licenses, delete the permission text for the other
9  * license.
10  *
11  * ----------------------------------------------------------------------
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at:
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  * ----------------------------------------------------------------------
24  * This program is free software; you can redistribute it and/or modify
25  * it under the terms of the GNU General Public License as published by
26  * the Free Software Foundation; either version 2 of the License, or
27  * (at your option) any later version.
28  *
29  * This program is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  * GNU General Public License for more details.
33  *
34  * You should have received a copy of the GNU General Public License along
35  * with this program; if not, write to the Free Software Foundation, Inc.,
36  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
37  * ----------------------------------------------------------------------
38  */
39
40 /* Protocol between userspace and kernel datapath.
41  *
42  * Be sure to update datapath/odp-compat.h if you change any of the structures
43  * in here. */
44
45 #ifndef OPENVSWITCH_DATAPATH_PROTOCOL_H
46 #define OPENVSWITCH_DATAPATH_PROTOCOL_H 1
47
48 /* The ovs_be<N> types indicate that an object is in big-endian, not
49  * native-endian, byte order.  They are otherwise equivalent to uint<N>_t.
50  * The Linux kernel already has __be<N> types for this, which take on
51  * additional semantics when the "sparse" static checker is used, so we use
52  * those types when compiling the kernel. */
53 #ifdef __KERNEL__
54 #include <linux/types.h>
55 #include <linux/socket.h>
56 #define ovs_be16 __be16
57 #define ovs_be32 __be32
58 #define ovs_be64 __be64
59 #else
60 #include "openvswitch/types.h"
61 #include <sys/socket.h>
62 #endif
63
64 #ifndef __aligned_u64
65 #define __aligned_u64 __u64 __attribute__((aligned(8)))
66 #define __aligned_be64 __be64 __attribute__((aligned(8)))
67 #define __aligned_le64 __le64 __attribute__((aligned(8)))
68 #endif
69
70 #include <linux/if_link.h>
71 #include <linux/netlink.h>
72
73 #define ODP_DP_NEW              _IOWR('O', 0, struct odp_datapath)
74 #define ODP_DP_DEL              _IOR('O', 1, struct odp_datapath)
75 #define ODP_DP_GET              _IOWR('O', 2, struct odp_datapath)
76 #define ODP_DP_SET              _IOWR('O', 3, struct odp_datapath)
77 #define ODP_DP_DUMP             _IOWR('O', 4, struct odp_datapath)
78
79 #define ODP_GET_LISTEN_MASK     _IOW('O', 5, int)
80 #define ODP_SET_LISTEN_MASK     _IOR('O', 6, int)
81
82 #define ODP_VPORT_NEW           _IOR('O', 7, struct odp_vport)
83 #define ODP_VPORT_DEL           _IOR('O', 8, struct odp_vport)
84 #define ODP_VPORT_GET           _IOWR('O', 9, struct odp_vport)
85 #define ODP_VPORT_SET           _IOR('O', 22, struct odp_vport)
86 #define ODP_VPORT_DUMP          _IOWR('O', 10, struct odp_vport)
87
88 #define ODP_FLOW_NEW            _IOWR('O', 13, struct odp_flow)
89 #define ODP_FLOW_DEL            _IOWR('O', 14, struct odp_flow)
90 #define ODP_FLOW_GET            _IOWR('O', 15, struct odp_flow)
91 #define ODP_FLOW_SET            _IOWR('O', 16, struct odp_flow)
92 #define ODP_FLOW_DUMP           _IOWR('O', 17, struct odp_flow)
93 #define ODP_FLOW_FLUSH          _IO('O', 19)
94
95 #define ODP_EXECUTE             _IOR('O', 18, struct odp_upcall)
96
97 /**
98  * struct odp_datapath - header with basic information about a datapath.
99  * @dp_idx: Datapath index (-1 to make a request not specific to a datapath).
100  * @len: Length of this structure plus the Netlink attributes following it.
101  * @total_len: Total space available for kernel reply to request.
102  *
103  * Followed by &struct nlattr attributes, whose types are drawn from
104  * %ODP_DP_ATTR_*, up to a length of @len bytes including the &struct
105  * odp_datapath header.
106  */
107 struct odp_datapath {
108         int32_t dp_idx;
109         uint32_t len;
110         uint32_t total_len;
111 };
112
113 enum odp_datapath_type {
114         ODP_DP_ATTR_UNSPEC,
115         ODP_DP_ATTR_NAME,       /* name of dp_ifidx netdev */
116         ODP_DP_ATTR_STATS,      /* struct odp_stats */
117         ODP_DP_ATTR_IPV4_FRAGS, /* 32-bit enum odp_frag_handling */
118         ODP_DP_ATTR_SAMPLING,   /* 32-bit fraction of packets to sample. */
119         __ODP_DP_ATTR_MAX
120 };
121
122 #define ODP_DP_ATTR_MAX (__ODP_DP_ATTR_MAX - 1)
123
124 /* Values for ODP_DP_ATTR_IPV4_FRAGS. */
125 enum odp_frag_handling {
126         ODP_DP_FRAG_UNSPEC,
127         ODP_DP_FRAG_ZERO,       /* Treat IP fragments as transport port 0. */
128         ODP_DP_FRAG_DROP        /* Drop IP fragments. */
129 };
130
131 struct odp_stats {
132     uint64_t n_frags;           /* Number of dropped IP fragments. */
133     uint64_t n_hit;             /* Number of flow table matches. */
134     uint64_t n_missed;          /* Number of flow table misses. */
135     uint64_t n_lost;            /* Number of misses not sent to userspace. */
136 };
137
138 /* Logical ports. */
139 #define ODPP_LOCAL      ((uint16_t)0)
140 #define ODPP_NONE       ((uint16_t)-1)
141
142 /* Listening channels. */
143 #define _ODPL_MISS_NR   0       /* Packet missed in flow table. */
144 #define ODPL_MISS       (1 << _ODPL_MISS_NR)
145 #define _ODPL_ACTION_NR 1       /* Packet output to ODPP_CONTROLLER. */
146 #define ODPL_ACTION     (1 << _ODPL_ACTION_NR)
147 #define _ODPL_SFLOW_NR  2       /* sFlow samples. */
148 #define ODPL_SFLOW      (1 << _ODPL_SFLOW_NR)
149 #define ODPL_ALL        (ODPL_MISS | ODPL_ACTION | ODPL_SFLOW)
150
151 enum odp_packet_type {
152         ODP_PACKET_ATTR_UNSPEC,
153         ODP_PACKET_ATTR_TYPE,        /* 32-bit enum, one of _ODP_*_NR. */
154         ODP_PACKET_ATTR_PACKET,      /* Packet data. */
155         ODP_PACKET_ATTR_KEY,         /* Nested ODP_KEY_ATTR_* attributes. */
156         ODP_PACKET_ATTR_USERDATA,    /* 64-bit data from ODPAT_CONTROLLER. */
157         ODP_PACKET_ATTR_SAMPLE_POOL, /* # sampling candidate packets so far. */
158         ODP_PACKET_ATTR_ACTIONS,     /* Nested ODPAT_* attributes. */
159         __ODP_PACKET_ATTR_MAX
160 };
161
162 #define ODP_PACKET_ATTR_MAX (__ODP_PACKET_ATTR_MAX - 1)
163
164 /**
165  * struct odp_packet - header for packets passed up between kernel and
166  * userspace.
167  * @dp_idx: Number of datapath to which the packet belongs.
168  * @len: Length of complete message, including this header.
169  *
170  * The header is followed by a sequence of Netlink attributes.  The
171  * %ODP_PACKET_ATTR_TYPE, %ODP_PACKET_ATTR_PACKET, and %ODP_PACKET_ATTR_KEY
172  * attributes are always present.  When @type == %_ODPL_ACTION_NR, the
173  * %ODP_PACKET_ATTR_USERDATA attribute is included if it would be nonzero.
174  * When @type == %_ODPL_SFLOW_NR, the %ODP_PACKET_ATTR_SAMPLE_POOL and
175  * %ODP_PACKET_ATTR_ACTIONS attributes are included.
176  *
177  * For @type of %_ODPL_ACTION_NR, %ODP_PACKET_ATTR_PACKET reflects changes made
178  * by actions preceding %ODPAT_CONTROLLER, but %ODP_PACKET_ATTR_KEY is the flow
179  * key extracted from the packet as originally received.
180  */
181 struct odp_packet {
182         uint32_t dp_idx;
183         uint32_t len;
184 };
185
186 enum odp_vport_type {
187         ODP_VPORT_TYPE_UNSPEC,
188         ODP_VPORT_TYPE_NETDEV,   /* network device */
189         ODP_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
190         ODP_VPORT_TYPE_PATCH,    /* virtual tunnel connecting two vports */
191         ODP_VPORT_TYPE_GRE,      /* GRE tunnel */
192         ODP_VPORT_TYPE_CAPWAP,   /* CAPWAP tunnel */
193         __ODP_VPORT_TYPE_MAX
194 };
195
196 #define ODP_VPORT_TYPE_MAX (__ODP_VPORT_TYPE_MAX - 1)
197
198 /**
199  * struct odp_vport - header with basic information about a virtual port.
200  * @dp_idx: Number of datapath to which the vport belongs.
201  * @len: Length of this structure plus the Netlink attributes following it.
202  * @total_len: Total space available for kernel reply to request.
203  *
204  * Followed by &struct nlattr attributes, whose types are drawn from
205  * %ODP_VPORT_ATTR_*, up to a length of @len bytes including the &struct
206  * odp_vport header.
207  */
208 struct odp_vport {
209         uint32_t dp_idx;
210         uint32_t len;
211         uint32_t total_len;
212 };
213
214 enum {
215         ODP_VPORT_ATTR_UNSPEC,
216         ODP_VPORT_ATTR_PORT_NO, /* port number within datapath */
217         ODP_VPORT_ATTR_TYPE,    /* 32-bit ODP_VPORT_TYPE_* constant. */
218         ODP_VPORT_ATTR_NAME,    /* string name, up to IFNAMSIZ bytes long */
219         ODP_VPORT_ATTR_STATS,   /* struct rtnl_link_stats64 */
220         ODP_VPORT_ATTR_ADDRESS, /* hardware address */
221         ODP_VPORT_ATTR_MTU,     /* 32-bit maximum transmission unit */
222         ODP_VPORT_ATTR_OPTIONS, /* nested attributes, varies by vport type */
223         ODP_VPORT_ATTR_IFINDEX, /* 32-bit ifindex of backing netdev */
224         ODP_VPORT_ATTR_IFLINK,  /* 32-bit ifindex on which packets are sent */
225         __ODP_VPORT_ATTR_MAX
226 };
227
228 #define ODP_VPORT_ATTR_MAX (__ODP_VPORT_ATTR_MAX - 1)
229
230 /* ODP_VPORT_ATTR_OPTIONS attributes for patch vports. */
231 enum {
232         ODP_PATCH_ATTR_UNSPEC,
233         ODP_PATCH_ATTR_PEER,    /* name of peer vport, as a string */
234         __ODP_PATCH_ATTR_MAX
235 };
236
237 #define ODP_PATCH_ATTR_MAX (__ODP_PATCH_ATTR_MAX - 1)
238
239 struct odp_flow_stats {
240     uint64_t n_packets;         /* Number of matched packets. */
241     uint64_t n_bytes;           /* Number of matched bytes. */
242 };
243
244 enum odp_key_type {
245         ODP_KEY_ATTR_UNSPEC,
246         ODP_KEY_ATTR_TUN_ID,    /* 64-bit tunnel ID */
247         ODP_KEY_ATTR_IN_PORT,   /* 32-bit ODP port number */
248         ODP_KEY_ATTR_ETHERNET,  /* struct odp_key_ethernet */
249         ODP_KEY_ATTR_8021Q,     /* struct odp_key_8021q */
250         ODP_KEY_ATTR_ETHERTYPE, /* 16-bit Ethernet type */
251         ODP_KEY_ATTR_IPV4,      /* struct odp_key_ipv4 */
252         ODP_KEY_ATTR_TCP,       /* struct odp_key_tcp */
253         ODP_KEY_ATTR_UDP,       /* struct odp_key_udp */
254         ODP_KEY_ATTR_ICMP,      /* struct odp_key_icmp */
255         ODP_KEY_ATTR_ARP,       /* struct odp_key_arp */
256         __ODP_KEY_ATTR_MAX
257 };
258
259 #define ODP_KEY_ATTR_MAX (__ODP_KEY_ATTR_MAX - 1)
260
261 struct odp_key_ethernet {
262         uint8_t  eth_src[6];
263         uint8_t  eth_dst[6];
264 };
265
266 struct odp_key_8021q {
267         ovs_be16 q_tpid;
268         ovs_be16 q_tci;
269 };
270
271 struct odp_key_ipv4 {
272         ovs_be32 ipv4_src;
273         ovs_be32 ipv4_dst;
274         uint8_t  ipv4_proto;
275         uint8_t  ipv4_tos;
276 };
277
278 struct odp_key_tcp {
279         ovs_be16 tcp_src;
280         ovs_be16 tcp_dst;
281 };
282
283 struct odp_key_udp {
284         ovs_be16 udp_src;
285         ovs_be16 udp_dst;
286 };
287
288 struct odp_key_icmp {
289         uint8_t icmp_type;
290         uint8_t icmp_code;
291 };
292
293 struct odp_key_arp {
294         ovs_be32 arp_sip;
295         ovs_be32 arp_tip;
296         ovs_be16 arp_op;
297 };
298
299 /**
300  * struct odp_flow - header with basic information about a flow.
301  * @dp_idx: Datapath index.
302  * @len: Length of this structure plus the Netlink attributes following it.
303  * @total_len: Total space available for kernel reply to request.
304  *
305  * Followed by &struct nlattr attributes, whose types are drawn from
306  * %ODP_FLOW_ATTR_*, up to a length of @len bytes including the &struct
307  * odp_flow header.
308  */
309 struct odp_flow {
310         uint32_t nlmsg_flags;
311         uint32_t dp_idx;
312         uint32_t len;
313         uint32_t total_len;
314 };
315
316 enum odp_flow_type {
317         ODP_FLOW_ATTR_UNSPEC,
318         ODP_FLOW_ATTR_KEY,       /* Sequence of ODP_KEY_ATTR_* attributes. */
319         ODP_FLOW_ATTR_ACTIONS,   /* Sequence of nested ODPAT_* attributes. */
320         ODP_FLOW_ATTR_STATS,     /* struct odp_flow_stats. */
321         ODP_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
322         ODP_FLOW_ATTR_USED,      /* u64 msecs last used in monotonic time. */
323         ODP_FLOW_ATTR_CLEAR,     /* Flag to clear stats, tcp_flags, used. */
324         ODP_FLOW_ATTR_STATE,     /* u64 state for ODP_FLOW_DUMP. */
325         __ODP_FLOW_ATTR_MAX
326 };
327
328 #define ODP_FLOW_ATTR_MAX (__ODP_FLOW_ATTR_MAX - 1)
329
330 /* Action types. */
331 enum odp_action_type {
332     ODPAT_UNSPEC,
333     ODPAT_OUTPUT,               /* Output to switch port. */
334     ODPAT_CONTROLLER,           /* Send copy to controller. */
335     ODPAT_SET_DL_TCI,           /* Set the 802.1q TCI value. */
336     ODPAT_STRIP_VLAN,           /* Strip the 802.1q header. */
337     ODPAT_SET_DL_SRC,           /* Ethernet source address. */
338     ODPAT_SET_DL_DST,           /* Ethernet destination address. */
339     ODPAT_SET_NW_SRC,           /* IPv4 source address. */
340     ODPAT_SET_NW_DST,           /* IPv4 destination address. */
341     ODPAT_SET_NW_TOS,           /* IP ToS/DSCP field (6 bits). */
342     ODPAT_SET_TP_SRC,           /* TCP/UDP source port. */
343     ODPAT_SET_TP_DST,           /* TCP/UDP destination port. */
344     ODPAT_SET_TUNNEL,           /* Set the encapsulating tunnel ID. */
345     ODPAT_SET_PRIORITY,         /* Set skb->priority. */
346     ODPAT_POP_PRIORITY,         /* Restore original skb->priority. */
347     ODPAT_DROP_SPOOFED_ARP,     /* Drop ARPs with spoofed source MAC. */
348     __ODPAT_MAX
349 };
350
351 #define ODPAT_MAX (__ODPAT_MAX - 1)
352
353 #endif  /* openvswitch/datapath-protocol.h */