Eliminate ODPL_* from userspace-facing interface.
[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_packet)
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
141 /* Listening channels. */
142 #define _ODPL_MISS_NR   0       /* Packet missed in flow table. */
143 #define ODPL_MISS       (1 << _ODPL_MISS_NR)
144 #define _ODPL_ACTION_NR 1       /* Packet output to ODPP_CONTROLLER. */
145 #define ODPL_ACTION     (1 << _ODPL_ACTION_NR)
146 #define _ODPL_SFLOW_NR  2       /* sFlow samples. */
147 #define ODPL_SFLOW      (1 << _ODPL_SFLOW_NR)
148 #define ODPL_ALL        (ODPL_MISS | ODPL_ACTION | ODPL_SFLOW)
149
150 enum odp_packet_type {
151         ODP_PACKET_ATTR_UNSPEC,
152         ODP_PACKET_ATTR_TYPE,        /* 32-bit enum, one of _ODP_*_NR. */
153         ODP_PACKET_ATTR_PACKET,      /* Packet data. */
154         ODP_PACKET_ATTR_KEY,         /* Nested ODP_KEY_ATTR_* attributes. */
155         ODP_PACKET_ATTR_USERDATA,    /* 64-bit data from ODPAT_CONTROLLER. */
156         ODP_PACKET_ATTR_SAMPLE_POOL, /* # sampling candidate packets so far. */
157         ODP_PACKET_ATTR_ACTIONS,     /* Nested ODPAT_* attributes. */
158         __ODP_PACKET_ATTR_MAX
159 };
160
161 #define ODP_PACKET_ATTR_MAX (__ODP_PACKET_ATTR_MAX - 1)
162
163 /**
164  * struct odp_packet - header for packets passed up between kernel and
165  * userspace.
166  * @dp_idx: Number of datapath to which the packet belongs.
167  * @len: Length of complete message, including this header.
168  *
169  * The header is followed by a sequence of Netlink attributes.  The
170  * %ODP_PACKET_ATTR_TYPE, %ODP_PACKET_ATTR_PACKET, and %ODP_PACKET_ATTR_KEY
171  * attributes are always present.  When @type == %_ODPL_ACTION_NR, the
172  * %ODP_PACKET_ATTR_USERDATA attribute is included if it would be nonzero.
173  * When @type == %_ODPL_SFLOW_NR, the %ODP_PACKET_ATTR_SAMPLE_POOL and
174  * %ODP_PACKET_ATTR_ACTIONS attributes are included.
175  *
176  * For @type of %_ODPL_ACTION_NR, %ODP_PACKET_ATTR_PACKET reflects changes made
177  * by actions preceding %ODPAT_CONTROLLER, but %ODP_PACKET_ATTR_KEY is the flow
178  * key extracted from the packet as originally received.
179  */
180 struct odp_packet {
181         uint32_t dp_idx;
182         uint32_t len;
183 };
184
185 enum odp_vport_type {
186         ODP_VPORT_TYPE_UNSPEC,
187         ODP_VPORT_TYPE_NETDEV,   /* network device */
188         ODP_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
189         ODP_VPORT_TYPE_PATCH,    /* virtual tunnel connecting two vports */
190         ODP_VPORT_TYPE_GRE,      /* GRE tunnel */
191         ODP_VPORT_TYPE_CAPWAP,   /* CAPWAP tunnel */
192         __ODP_VPORT_TYPE_MAX
193 };
194
195 #define ODP_VPORT_TYPE_MAX (__ODP_VPORT_TYPE_MAX - 1)
196
197 /**
198  * struct odp_vport - header with basic information about a virtual port.
199  * @dp_idx: Number of datapath to which the vport belongs.
200  * @len: Length of this structure plus the Netlink attributes following it.
201  * @total_len: Total space available for kernel reply to request.
202  *
203  * Followed by &struct nlattr attributes, whose types are drawn from
204  * %ODP_VPORT_ATTR_*, up to a length of @len bytes including the &struct
205  * odp_vport header.
206  */
207 struct odp_vport {
208         uint32_t dp_idx;
209         uint32_t len;
210         uint32_t total_len;
211 };
212
213 enum {
214         ODP_VPORT_ATTR_UNSPEC,
215         ODP_VPORT_ATTR_PORT_NO, /* port number within datapath */
216         ODP_VPORT_ATTR_TYPE,    /* 32-bit ODP_VPORT_TYPE_* constant. */
217         ODP_VPORT_ATTR_NAME,    /* string name, up to IFNAMSIZ bytes long */
218         ODP_VPORT_ATTR_STATS,   /* struct rtnl_link_stats64 */
219         ODP_VPORT_ATTR_ADDRESS, /* hardware address */
220         ODP_VPORT_ATTR_MTU,     /* 32-bit maximum transmission unit */
221         ODP_VPORT_ATTR_OPTIONS, /* nested attributes, varies by vport type */
222         ODP_VPORT_ATTR_IFINDEX, /* 32-bit ifindex of backing netdev */
223         ODP_VPORT_ATTR_IFLINK,  /* 32-bit ifindex on which packets are sent */
224         __ODP_VPORT_ATTR_MAX
225 };
226
227 #define ODP_VPORT_ATTR_MAX (__ODP_VPORT_ATTR_MAX - 1)
228
229 /* ODP_VPORT_ATTR_OPTIONS attributes for patch vports. */
230 enum {
231         ODP_PATCH_ATTR_UNSPEC,
232         ODP_PATCH_ATTR_PEER,    /* name of peer vport, as a string */
233         __ODP_PATCH_ATTR_MAX
234 };
235
236 #define ODP_PATCH_ATTR_MAX (__ODP_PATCH_ATTR_MAX - 1)
237
238 struct odp_flow_stats {
239     uint64_t n_packets;         /* Number of matched packets. */
240     uint64_t n_bytes;           /* Number of matched bytes. */
241 };
242
243 enum odp_key_type {
244         ODP_KEY_ATTR_UNSPEC,
245         ODP_KEY_ATTR_TUN_ID,    /* 64-bit tunnel ID */
246         ODP_KEY_ATTR_IN_PORT,   /* 32-bit ODP port number */
247         ODP_KEY_ATTR_ETHERNET,  /* struct odp_key_ethernet */
248         ODP_KEY_ATTR_8021Q,     /* struct odp_key_8021q */
249         ODP_KEY_ATTR_ETHERTYPE, /* 16-bit Ethernet type */
250         ODP_KEY_ATTR_IPV4,      /* struct odp_key_ipv4 */
251         ODP_KEY_ATTR_TCP,       /* struct odp_key_tcp */
252         ODP_KEY_ATTR_UDP,       /* struct odp_key_udp */
253         ODP_KEY_ATTR_ICMP,      /* struct odp_key_icmp */
254         ODP_KEY_ATTR_ARP,       /* struct odp_key_arp */
255         __ODP_KEY_ATTR_MAX
256 };
257
258 #define ODP_KEY_ATTR_MAX (__ODP_KEY_ATTR_MAX - 1)
259
260 struct odp_key_ethernet {
261         uint8_t  eth_src[6];
262         uint8_t  eth_dst[6];
263 };
264
265 struct odp_key_8021q {
266         ovs_be16 q_tpid;
267         ovs_be16 q_tci;
268 };
269
270 struct odp_key_ipv4 {
271         ovs_be32 ipv4_src;
272         ovs_be32 ipv4_dst;
273         uint8_t  ipv4_proto;
274         uint8_t  ipv4_tos;
275 };
276
277 struct odp_key_tcp {
278         ovs_be16 tcp_src;
279         ovs_be16 tcp_dst;
280 };
281
282 struct odp_key_udp {
283         ovs_be16 udp_src;
284         ovs_be16 udp_dst;
285 };
286
287 struct odp_key_icmp {
288         uint8_t icmp_type;
289         uint8_t icmp_code;
290 };
291
292 struct odp_key_arp {
293         ovs_be32 arp_sip;
294         ovs_be32 arp_tip;
295         ovs_be16 arp_op;
296 };
297
298 /**
299  * struct odp_flow - header with basic information about a flow.
300  * @dp_idx: Datapath index.
301  * @len: Length of this structure plus the Netlink attributes following it.
302  * @total_len: Total space available for kernel reply to request.
303  *
304  * Followed by &struct nlattr attributes, whose types are drawn from
305  * %ODP_FLOW_ATTR_*, up to a length of @len bytes including the &struct
306  * odp_flow header.
307  */
308 struct odp_flow {
309         uint32_t nlmsg_flags;
310         uint32_t dp_idx;
311         uint32_t len;
312         uint32_t total_len;
313 };
314
315 enum odp_flow_type {
316         ODP_FLOW_ATTR_UNSPEC,
317         ODP_FLOW_ATTR_KEY,       /* Sequence of ODP_KEY_ATTR_* attributes. */
318         ODP_FLOW_ATTR_ACTIONS,   /* Sequence of nested ODPAT_* attributes. */
319         ODP_FLOW_ATTR_STATS,     /* struct odp_flow_stats. */
320         ODP_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
321         ODP_FLOW_ATTR_USED,      /* u64 msecs last used in monotonic time. */
322         ODP_FLOW_ATTR_CLEAR,     /* Flag to clear stats, tcp_flags, used. */
323         ODP_FLOW_ATTR_STATE,     /* u64 state for ODP_FLOW_DUMP. */
324         __ODP_FLOW_ATTR_MAX
325 };
326
327 #define ODP_FLOW_ATTR_MAX (__ODP_FLOW_ATTR_MAX - 1)
328
329 /* Action types. */
330 enum odp_action_type {
331     ODPAT_UNSPEC,
332     ODPAT_OUTPUT,               /* Output to switch port. */
333     ODPAT_CONTROLLER,           /* Send copy to controller. */
334     ODPAT_SET_DL_TCI,           /* Set the 802.1q TCI value. */
335     ODPAT_STRIP_VLAN,           /* Strip the 802.1q header. */
336     ODPAT_SET_DL_SRC,           /* Ethernet source address. */
337     ODPAT_SET_DL_DST,           /* Ethernet destination address. */
338     ODPAT_SET_NW_SRC,           /* IPv4 source address. */
339     ODPAT_SET_NW_DST,           /* IPv4 destination address. */
340     ODPAT_SET_NW_TOS,           /* IP ToS/DSCP field (6 bits). */
341     ODPAT_SET_TP_SRC,           /* TCP/UDP source port. */
342     ODPAT_SET_TP_DST,           /* TCP/UDP destination port. */
343     ODPAT_SET_TUNNEL,           /* Set the encapsulating tunnel ID. */
344     ODPAT_SET_PRIORITY,         /* Set skb->priority. */
345     ODPAT_POP_PRIORITY,         /* Restore original skb->priority. */
346     ODPAT_DROP_SPOOFED_ARP,     /* Drop ARPs with spoofed source MAC. */
347     __ODPAT_MAX
348 };
349
350 #define ODPAT_MAX (__ODPAT_MAX - 1)
351
352 #endif  /* openvswitch/datapath-protocol.h */