datapath: Convert ODP_VPORT_* to use AF_NETLINK socket layer.
[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_FLOW_NEW            _IOWR('O', 13, struct odp_flow)
74 #define ODP_FLOW_DEL            _IOWR('O', 14, struct odp_flow)
75 #define ODP_FLOW_GET            _IOWR('O', 15, struct odp_flow)
76 #define ODP_FLOW_SET            _IOWR('O', 16, struct odp_flow)
77 #define ODP_FLOW_DUMP           _IOWR('O', 17, struct odp_flow)
78 #define ODP_FLOW_FLUSH          _IO('O', 19)
79 \f
80 /* Datapaths. */
81
82 #define ODP_DATAPATH_FAMILY  "odp_datapath"
83 #define ODP_DATAPATH_MCGROUP "odp_datapath"
84
85 enum odp_datapath_cmd {
86         ODP_DP_CMD_UNSPEC,
87         ODP_DP_CMD_NEW,
88         ODP_DP_CMD_DEL,
89         ODP_DP_CMD_GET,
90         ODP_DP_CMD_SET
91 };
92
93 /**
94  * struct odp_header - header for ODP Generic Netlink messages.
95  * @dp_idx: Number of datapath to which the packet belongs.
96  *
97  * Attributes following the header are specific to a particular ODP Generic
98  * Netlink family, but all of the ODP families use this header.
99  */
100 struct odp_header {
101         uint32_t dp_idx;
102 };
103 \f
104 /**
105  * enum odp_datapath_attr - attributes for %ODP_DP_* commands.
106  * @ODP_DP_ATTR_NAME: Name of the network device that serves as the "local
107  * port".  This is the name of the network device whose dp_idx is given in the
108  * &struct odp_header.  Always present in notifications.  Required in
109  * %ODP_DP_NEW requests.  May be used as an alternative to specifying dp_idx on
110  * other requests (with a dp_idx of %UINT32_MAX).
111  * @ODP_DP_ATTR_STATS: Statistics about packets that have passed through the
112  * datapath.  Always present in notifications.
113  * @ODP_DP_ATTR_IPV4_FRAGS: One of %ODP_DP_FRAG_*.  Always present in
114  * notifications.  May be included in %ODP_DP_NEW or %ODP_DP_SET requests to
115  * change the fragment handling policy.
116  * @ODP_DP_ATTR_SAMPLING: 32-bit fraction of packets to sample with
117  * @ODP_PACKET_CMD_SAMPLE.  A value of 0 samples no packets, a value of
118  * %UINT32_MAX samples all packets, and intermediate values sample intermediate
119  * fractions of packets.
120  * @ODP_DP_ATTR_MCGROUPS: Nested attributes with multicast groups.  Each nested
121  * attribute has a %ODP_PACKET_CMD_* type with a 32-bit value giving the
122  * Generic Netlink multicast group number used for sending this datapath's
123  * messages with that command type up to userspace.
124  *
125  * These attributes follow the &struct odp_header within the Generic Netlink
126  * payload for %ODP_DP_* commands.
127  */
128 enum odp_datapath_attr {
129         ODP_DP_ATTR_UNSPEC,
130         ODP_DP_ATTR_NAME,       /* name of dp_ifidx netdev */
131         ODP_DP_ATTR_STATS,      /* struct odp_stats */
132         ODP_DP_ATTR_IPV4_FRAGS, /* 32-bit enum odp_frag_handling */
133         ODP_DP_ATTR_SAMPLING,   /* 32-bit fraction of packets to sample. */
134         ODP_DP_ATTR_MCGROUPS,   /* Nested attributes with multicast groups. */
135         __ODP_DP_ATTR_MAX
136 };
137
138 #define ODP_DP_ATTR_MAX (__ODP_DP_ATTR_MAX - 1)
139
140 /**
141  * enum odp_frag_handling - policy for handling received IPv4 fragments.
142  * @ODP_DP_FRAG_ZERO: Treat IP fragments as IP protocol 0 and transport ports
143  * zero.
144  * @ODP_DP_FRAG_DROP: Drop IP fragments.  Do not pass them through the flow
145  * table or up to userspace.
146  */
147 enum odp_frag_handling {
148         ODP_DP_FRAG_UNSPEC,
149         ODP_DP_FRAG_ZERO,       /* Treat IP fragments as transport port 0. */
150         ODP_DP_FRAG_DROP        /* Drop IP fragments. */
151 };
152
153 struct odp_stats {
154     uint64_t n_frags;           /* Number of dropped IP fragments. */
155     uint64_t n_hit;             /* Number of flow table matches. */
156     uint64_t n_missed;          /* Number of flow table misses. */
157     uint64_t n_lost;            /* Number of misses not sent to userspace. */
158 };
159
160 /* Logical ports. */
161 #define ODPP_LOCAL      ((uint16_t)0)
162 \f
163 #define ODP_PACKET_FAMILY "odp_packet"
164
165 enum odp_packet_cmd {
166         ODP_PACKET_CMD_UNSPEC,
167
168         /* Kernel-to-user notifications. */
169         ODP_PACKET_CMD_MISS,    /* Flow table miss. */
170         ODP_PACKET_CMD_ACTION,  /* ODPAT_CONTROLLER action. */
171         ODP_PACKET_CMD_SAMPLE,  /* Sampled packet. */
172
173         /* User commands. */
174         ODP_PACKET_CMD_EXECUTE  /* Apply actions to a packet. */
175 };
176
177 /**
178  * enum odp_packet_attr - attributes for %ODP_PACKET_* commands.
179  * @ODP_PACKET_ATTR_PACKET: Present for all notifications.  Contains the entire
180  * packet as received, from the start of the Ethernet header onward.  For
181  * %ODP_PACKET_CMD_ACTION, %ODP_PACKET_ATTR_PACKET reflects changes made by
182  * actions preceding %ODPAT_CONTROLLER, but %ODP_PACKET_ATTR_KEY is the flow
183  * key extracted from the packet as originally received.
184  * @ODP_PACKET_ATTR_KEY: Present for all notifications.  Contains the flow key
185  * extracted from the packet as nested %ODP_KEY_ATTR_* attributes.  This allows
186  * userspace to adapt its flow setup strategy by comparing its notion of the
187  * flow key against the kernel's.
188  * @ODP_PACKET_ATTR_USERDATA: Present for an %ODP_PACKET_CMD_ACTION
189  * notification if the %ODPAT_CONTROLLER action's argument was nonzero.
190  * @ODP_PACKET_ATTR_SAMPLE_POOL: Present for %ODP_PACKET_CMD_SAMPLE.  Contains
191  * the number of packets processed so far that were candidates for sampling.
192  * @ODP_PACKET_ATTR_ACTIONS: Present for %ODP_PACKET_CMD_SAMPLE.  Contains a
193  * copy of the actions applied to the packet, as nested %ODPAT_* attributes.
194  *
195  * These attributes follow the &struct odp_header within the Generic Netlink
196  * payload for %ODP_PACKET_* commands.
197  */
198 enum odp_packet_attr {
199         ODP_PACKET_ATTR_UNSPEC,
200         ODP_PACKET_ATTR_PACKET,      /* Packet data. */
201         ODP_PACKET_ATTR_KEY,         /* Nested ODP_KEY_ATTR_* attributes. */
202         ODP_PACKET_ATTR_USERDATA,    /* 64-bit data from ODPAT_CONTROLLER. */
203         ODP_PACKET_ATTR_SAMPLE_POOL, /* # sampling candidate packets so far. */
204         ODP_PACKET_ATTR_ACTIONS,     /* Nested ODPAT_* attributes. */
205         __ODP_PACKET_ATTR_MAX
206 };
207
208 #define ODP_PACKET_ATTR_MAX (__ODP_PACKET_ATTR_MAX - 1)
209 \f
210 enum odp_vport_type {
211         ODP_VPORT_TYPE_UNSPEC,
212         ODP_VPORT_TYPE_NETDEV,   /* network device */
213         ODP_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
214         ODP_VPORT_TYPE_PATCH,    /* virtual tunnel connecting two vports */
215         ODP_VPORT_TYPE_GRE,      /* GRE tunnel */
216         ODP_VPORT_TYPE_CAPWAP,   /* CAPWAP tunnel */
217         __ODP_VPORT_TYPE_MAX
218 };
219
220 #define ODP_VPORT_TYPE_MAX (__ODP_VPORT_TYPE_MAX - 1)
221 \f
222 #define ODP_VPORT_FAMILY  "odp_vport"
223 #define ODP_VPORT_MCGROUP "odp_vport"
224
225 enum odp_vport_cmd {
226         ODP_VPORT_CMD_UNSPEC,
227         ODP_VPORT_CMD_NEW,
228         ODP_VPORT_CMD_DEL,
229         ODP_VPORT_CMD_GET,
230         ODP_VPORT_CMD_SET
231 };
232
233 /**
234  * enum odp_vport_attr - attributes for %ODP_VPORT_* commands.
235  * @ODP_VPORT_ATTR_PORT_NO: 32-bit port number within datapath.
236  * @ODP_VPORT_ATTR_TYPE: 32-bit %ODP_VPORT_TYPE_* constant describing the type
237  * of vport.
238  * @ODP_VPORT_ATTR_NAME: Name of vport.  For a vport based on a network device
239  * this is the name of the network device.  Maximum length %IFNAMSIZ-1 bytes
240  * plus a null terminator.
241  * @ODP_VPORT_ATTR_STATS: A &struct rtnl_link_stats64 giving statistics for
242  * packets sent or received through the vport.
243  * @ODP_VPORT_ATTR_ADDRESS: A 6-byte Ethernet address for the vport.
244  * @ODP_VPORT_ATTR_MTU: MTU for the vport.
245  * @ODP_VPORT_ATTR_IFINDEX: ifindex of the underlying network device, if any.
246  * @ODP_VPORT_ATTR_IFLINK: ifindex of the device on which packets are sent (for
247  * tunnels), if any.
248  *
249  * These attributes follow the &struct odp_header within the Generic Netlink
250  * payload for %ODP_VPORT_* commands.
251  *
252  * All attributes applicable to a given port are present in notifications.
253  * This means that, for example, a vport that has no corresponding network
254  * device would omit %ODP_VPORT_ATTR_IFINDEX.
255  *
256  * For %ODP_VPORT_CMD_NEW requests, the %ODP_VPORT_ATTR_TYPE and
257  * %ODP_VPORT_ATTR_NAME attributes are required.  %ODP_VPORT_ATTR_PORT_NO is
258  * optional; if not specified a free port number is automatically selected.
259  * Whether %ODP_VPORT_ATTR_OPTIONS is required or optional depends on the type
260  * of vport.  %ODP_VPORT_ATTR_STATS, %ODP_VPORT_ATTR_ADDRESS, and
261  * %ODP_VPORT_ATTR_MTU are optional, and other attributes are ignored.
262  *
263  * For other requests, if %ODP_VPORT_ATTR_NAME is specified then it is used to
264  * look up the vport to operate on; otherwise dp_idx from the &struct
265  * odp_header plus %ODP_VPORT_ATTR_PORT_NO determine the vport.
266  */
267 enum odp_vport_attr {
268         ODP_VPORT_ATTR_UNSPEC,
269         ODP_VPORT_ATTR_PORT_NO, /* port number within datapath */
270         ODP_VPORT_ATTR_TYPE,    /* 32-bit ODP_VPORT_TYPE_* constant. */
271         ODP_VPORT_ATTR_NAME,    /* string name, up to IFNAMSIZ bytes long */
272         ODP_VPORT_ATTR_STATS,   /* struct rtnl_link_stats64 */
273         ODP_VPORT_ATTR_ADDRESS, /* hardware address */
274         ODP_VPORT_ATTR_MTU,     /* 32-bit maximum transmission unit */
275         ODP_VPORT_ATTR_OPTIONS, /* nested attributes, varies by vport type */
276         ODP_VPORT_ATTR_IFINDEX, /* 32-bit ifindex of backing netdev */
277         ODP_VPORT_ATTR_IFLINK,  /* 32-bit ifindex on which packets are sent */
278         __ODP_VPORT_ATTR_MAX
279 };
280
281 #define ODP_VPORT_ATTR_MAX (__ODP_VPORT_ATTR_MAX - 1)
282
283 /* ODP_VPORT_ATTR_OPTIONS attributes for patch vports. */
284 enum {
285         ODP_PATCH_ATTR_UNSPEC,
286         ODP_PATCH_ATTR_PEER,    /* name of peer vport, as a string */
287         __ODP_PATCH_ATTR_MAX
288 };
289
290 #define ODP_PATCH_ATTR_MAX (__ODP_PATCH_ATTR_MAX - 1)
291
292 struct odp_flow_stats {
293     uint64_t n_packets;         /* Number of matched packets. */
294     uint64_t n_bytes;           /* Number of matched bytes. */
295 };
296
297 enum odp_key_type {
298         ODP_KEY_ATTR_UNSPEC,
299         ODP_KEY_ATTR_TUN_ID,    /* 64-bit tunnel ID */
300         ODP_KEY_ATTR_IN_PORT,   /* 32-bit ODP port number */
301         ODP_KEY_ATTR_ETHERNET,  /* struct odp_key_ethernet */
302         ODP_KEY_ATTR_8021Q,     /* struct odp_key_8021q */
303         ODP_KEY_ATTR_ETHERTYPE, /* 16-bit Ethernet type */
304         ODP_KEY_ATTR_IPV4,      /* struct odp_key_ipv4 */
305         ODP_KEY_ATTR_TCP,       /* struct odp_key_tcp */
306         ODP_KEY_ATTR_UDP,       /* struct odp_key_udp */
307         ODP_KEY_ATTR_ICMP,      /* struct odp_key_icmp */
308         ODP_KEY_ATTR_ARP,       /* struct odp_key_arp */
309         __ODP_KEY_ATTR_MAX
310 };
311
312 #define ODP_KEY_ATTR_MAX (__ODP_KEY_ATTR_MAX - 1)
313
314 struct odp_key_ethernet {
315         uint8_t  eth_src[6];
316         uint8_t  eth_dst[6];
317 };
318
319 struct odp_key_8021q {
320         ovs_be16 q_tpid;
321         ovs_be16 q_tci;
322 };
323
324 struct odp_key_ipv4 {
325         ovs_be32 ipv4_src;
326         ovs_be32 ipv4_dst;
327         uint8_t  ipv4_proto;
328         uint8_t  ipv4_tos;
329 };
330
331 struct odp_key_tcp {
332         ovs_be16 tcp_src;
333         ovs_be16 tcp_dst;
334 };
335
336 struct odp_key_udp {
337         ovs_be16 udp_src;
338         ovs_be16 udp_dst;
339 };
340
341 struct odp_key_icmp {
342         uint8_t icmp_type;
343         uint8_t icmp_code;
344 };
345
346 struct odp_key_arp {
347         ovs_be32 arp_sip;
348         ovs_be32 arp_tip;
349         ovs_be16 arp_op;
350 };
351
352 /**
353  * struct odp_flow - header with basic information about a flow.
354  * @dp_idx: Datapath index.
355  * @len: Length of this structure plus the Netlink attributes following it.
356  * @total_len: Total space available for kernel reply to request.
357  *
358  * Followed by &struct nlattr attributes, whose types are drawn from
359  * %ODP_FLOW_ATTR_*, up to a length of @len bytes including the &struct
360  * odp_flow header.
361  */
362 struct odp_flow {
363         uint32_t nlmsg_flags;
364         uint32_t dp_idx;
365         uint32_t len;
366         uint32_t total_len;
367 };
368
369 enum odp_flow_type {
370         ODP_FLOW_ATTR_UNSPEC,
371         ODP_FLOW_ATTR_KEY,       /* Sequence of ODP_KEY_ATTR_* attributes. */
372         ODP_FLOW_ATTR_ACTIONS,   /* Sequence of nested ODPAT_* attributes. */
373         ODP_FLOW_ATTR_STATS,     /* struct odp_flow_stats. */
374         ODP_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
375         ODP_FLOW_ATTR_USED,      /* u64 msecs last used in monotonic time. */
376         ODP_FLOW_ATTR_CLEAR,     /* Flag to clear stats, tcp_flags, used. */
377         ODP_FLOW_ATTR_STATE,     /* u64 state for ODP_FLOW_DUMP. */
378         __ODP_FLOW_ATTR_MAX
379 };
380
381 #define ODP_FLOW_ATTR_MAX (__ODP_FLOW_ATTR_MAX - 1)
382
383 /* Action types. */
384 enum odp_action_type {
385     ODPAT_UNSPEC,
386     ODPAT_OUTPUT,               /* Output to switch port. */
387     ODPAT_CONTROLLER,           /* Send copy to controller. */
388     ODPAT_SET_DL_TCI,           /* Set the 802.1q TCI value. */
389     ODPAT_STRIP_VLAN,           /* Strip the 802.1q header. */
390     ODPAT_SET_DL_SRC,           /* Ethernet source address. */
391     ODPAT_SET_DL_DST,           /* Ethernet destination address. */
392     ODPAT_SET_NW_SRC,           /* IPv4 source address. */
393     ODPAT_SET_NW_DST,           /* IPv4 destination address. */
394     ODPAT_SET_NW_TOS,           /* IP ToS/DSCP field (6 bits). */
395     ODPAT_SET_TP_SRC,           /* TCP/UDP source port. */
396     ODPAT_SET_TP_DST,           /* TCP/UDP destination port. */
397     ODPAT_SET_TUNNEL,           /* Set the encapsulating tunnel ID. */
398     ODPAT_SET_PRIORITY,         /* Set skb->priority. */
399     ODPAT_POP_PRIORITY,         /* Restore original skb->priority. */
400     ODPAT_DROP_SPOOFED_ARP,     /* Drop ARPs with spoofed source MAC. */
401     __ODPAT_MAX
402 };
403
404 #define ODPAT_MAX (__ODPAT_MAX - 1)
405
406 #endif  /* openvswitch/datapath-protocol.h */