datapath-protocol: Remove #include <linux/netlink.h>.
[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 #ifndef OPENVSWITCH_DATAPATH_PROTOCOL_H
41 #define OPENVSWITCH_DATAPATH_PROTOCOL_H 1
42
43 #ifdef __KERNEL__
44 #include <linux/types.h>
45 #include <linux/socket.h>
46 #define ovs_be16 __be16
47 #define ovs_be32 __be32
48 #define ovs_be64 __be64
49 #else
50 #include "openvswitch/types.h"
51 #include <sys/socket.h>
52 #endif
53 \f
54 /* datapaths. */
55
56 #define OVS_DATAPATH_FAMILY  "ovs_datapath"
57 #define OVS_DATAPATH_MCGROUP "ovs_datapath"
58
59 enum ovs_datapath_cmd {
60         OVS_DP_CMD_UNSPEC,
61         OVS_DP_CMD_NEW,
62         OVS_DP_CMD_DEL,
63         OVS_DP_CMD_GET,
64         OVS_DP_CMD_SET
65 };
66
67 /**
68  * struct ovs_header - header for OVS Generic Netlink messages.
69  * @dp_ifindex: ifindex of local port for datapath (0 to make a request not
70  * specific to a datapath).
71  *
72  * Attributes following the header are specific to a particular OVS Generic
73  * Netlink family, but all of the OVS families use this header.
74  */
75 struct ovs_header {
76         int dp_ifindex;
77 };
78 \f
79 /**
80  * enum ovs_datapath_attr - attributes for %OVS_DP_* commands.
81  * @OVS_DP_ATTR_NAME: Name of the network device that serves as the "local
82  * port".  This is the name of the network device whose dp_ifindex is given in
83  * the &struct ovs_header.  Always present in notifications.  Required in
84  * %OVS_DP_NEW requests.  May be used as an alternative to specifying
85  * dp_ifindex in other requests (with a dp_ifindex of 0).
86  * @OVS_DP_ATTR_UPCALL_PID: The Netlink socket in userspace that is initially
87  * set on the datapath port (for OVS_ACTION_ATTR_MISS).  Only valid on
88  * %OVS_DP_CMD_NEW requests. A value of zero indicates that upcalls should
89  * not be sent.
90  * @OVS_DP_ATTR_STATS: Statistics about packets that have passed through the
91  * datapath.  Always present in notifications.
92  * @OVS_DP_ATTR_IPV4_FRAGS: One of %OVS_DP_FRAG_*.  Always present in
93  * notifications.  May be included in %OVS_DP_NEW or %OVS_DP_SET requests to
94  * change the fragment handling policy.
95  *
96  * These attributes follow the &struct ovs_header within the Generic Netlink
97  * payload for %OVS_DP_* commands.
98  */
99 enum ovs_datapath_attr {
100         OVS_DP_ATTR_UNSPEC,
101         OVS_DP_ATTR_NAME,       /* name of dp_ifindex netdev */
102         OVS_DP_ATTR_UPCALL_PID, /* Netlink PID to receive upcalls */
103         OVS_DP_ATTR_STATS,      /* struct ovs_dp_stats */
104         OVS_DP_ATTR_IPV4_FRAGS, /* 32-bit enum ovs_frag_handling */
105         __OVS_DP_ATTR_MAX
106 };
107
108 #define OVS_DP_ATTR_MAX (__OVS_DP_ATTR_MAX - 1)
109
110 /**
111  * enum ovs_frag_handling - policy for handling received IPv4 fragments.
112  * @OVS_DP_FRAG_ZERO: Treat IP fragments as IP protocol 0 and transport ports
113  * zero.
114  * @OVS_DP_FRAG_DROP: Drop IP fragments.  Do not pass them through the flow
115  * table or up to userspace.
116  */
117 enum ovs_frag_handling {
118         OVS_DP_FRAG_UNSPEC,
119         OVS_DP_FRAG_ZERO,       /* Treat IP fragments as transport port 0. */
120         OVS_DP_FRAG_DROP        /* Drop IP fragments. */
121 };
122
123 struct ovs_dp_stats {
124     uint64_t n_frags;           /* Number of dropped IP fragments. */
125     uint64_t n_hit;             /* Number of flow table matches. */
126     uint64_t n_missed;          /* Number of flow table misses. */
127     uint64_t n_lost;            /* Number of misses not sent to userspace. */
128     uint64_t n_flows;           /* Number of flows present */
129 };
130
131 struct ovs_vport_stats {
132         uint64_t   rx_packets;          /* total packets received       */
133         uint64_t   tx_packets;          /* total packets transmitted    */
134         uint64_t   rx_bytes;            /* total bytes received         */
135         uint64_t   tx_bytes;            /* total bytes transmitted      */
136         uint64_t   rx_errors;           /* bad packets received         */
137         uint64_t   tx_errors;           /* packet transmit problems     */
138         uint64_t   rx_dropped;          /* no space in linux buffers    */
139         uint64_t   tx_dropped;          /* no space available in linux  */
140 };
141
142 /* Logical ports. */
143 #define OVSP_LOCAL      ((uint16_t)0)
144 \f
145 #define OVS_PACKET_FAMILY "ovs_packet"
146
147 enum ovs_packet_cmd {
148         OVS_PACKET_CMD_UNSPEC,
149
150         /* Kernel-to-user notifications. */
151         OVS_PACKET_CMD_MISS,    /* Flow table miss. */
152         OVS_PACKET_CMD_ACTION,  /* OVS_ACTION_ATTR_USERSPACE action. */
153
154         /* User commands. */
155         OVS_PACKET_CMD_EXECUTE  /* Apply actions to a packet. */
156 };
157
158 /**
159  * enum ovs_packet_attr - attributes for %OVS_PACKET_* commands.
160  * @OVS_PACKET_ATTR_PACKET: Present for all notifications.  Contains the entire
161  * packet as received, from the start of the Ethernet header onward.  For
162  * %OVS_PACKET_CMD_ACTION, %OVS_PACKET_ATTR_PACKET reflects changes made by
163  * actions preceding %OVS_ACTION_ATTR_USERSPACE, but %OVS_PACKET_ATTR_KEY is
164  * the flow key extracted from the packet as originally received.
165  * @OVS_PACKET_ATTR_KEY: Present for all notifications.  Contains the flow key
166  * extracted from the packet as nested %OVS_KEY_ATTR_* attributes.  This allows
167  * userspace to adapt its flow setup strategy by comparing its notion of the
168  * flow key against the kernel's.
169  * @OVS_PACKET_ATTR_ACTIONS: Contains actions for the packet.  Used
170  * for %OVS_PACKET_CMD_EXECUTE.  It has nested %OVS_ACTION_ATTR_* attributes.
171  * @OVS_PACKET_ATTR_USERDATA: Present for an %OVS_PACKET_CMD_ACTION
172  * notification if the %OVS_ACTION_ATTR_USERSPACE action specified an
173  * %OVS_USERSPACE_ATTR_USERDATA attribute.
174  *
175  * These attributes follow the &struct ovs_header within the Generic Netlink
176  * payload for %OVS_PACKET_* commands.
177  */
178 enum ovs_packet_attr {
179         OVS_PACKET_ATTR_UNSPEC,
180         OVS_PACKET_ATTR_PACKET,      /* Packet data. */
181         OVS_PACKET_ATTR_KEY,         /* Nested OVS_KEY_ATTR_* attributes. */
182         OVS_PACKET_ATTR_ACTIONS,     /* Nested OVS_ACTION_ATTR_* attributes. */
183         OVS_PACKET_ATTR_USERDATA,    /* u64 OVS_ACTION_ATTR_USERSPACE arg. */
184         __OVS_PACKET_ATTR_MAX
185 };
186
187 #define OVS_PACKET_ATTR_MAX (__OVS_PACKET_ATTR_MAX - 1)
188 \f
189 enum ovs_vport_type {
190         OVS_VPORT_TYPE_UNSPEC,
191         OVS_VPORT_TYPE_NETDEV,   /* network device */
192         OVS_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
193         OVS_VPORT_TYPE_PATCH,    /* virtual tunnel connecting two vports */
194         OVS_VPORT_TYPE_GRE,      /* GRE tunnel */
195         OVS_VPORT_TYPE_CAPWAP,   /* CAPWAP tunnel */
196         __OVS_VPORT_TYPE_MAX
197 };
198
199 #define OVS_VPORT_TYPE_MAX (__OVS_VPORT_TYPE_MAX - 1)
200 \f
201 #define OVS_VPORT_FAMILY  "ovs_vport"
202 #define OVS_VPORT_MCGROUP "ovs_vport"
203
204 enum ovs_vport_cmd {
205         OVS_VPORT_CMD_UNSPEC,
206         OVS_VPORT_CMD_NEW,
207         OVS_VPORT_CMD_DEL,
208         OVS_VPORT_CMD_GET,
209         OVS_VPORT_CMD_SET
210 };
211
212 /**
213  * enum ovs_vport_attr - attributes for %OVS_VPORT_* commands.
214  * @OVS_VPORT_ATTR_PORT_NO: 32-bit port number within datapath.
215  * @OVS_VPORT_ATTR_TYPE: 32-bit %OVS_VPORT_TYPE_* constant describing the type
216  * of vport.
217  * @OVS_VPORT_ATTR_NAME: Name of vport.  For a vport based on a network device
218  * this is the name of the network device.  Maximum length %IFNAMSIZ-1 bytes
219  * plus a null terminator.
220  * @OVS_VPORT_ATTR_UPCALL_PID: The Netlink socket in userspace that
221  * OVS_PACKET_CMD_MISS upcalls will be directed to for packets received on
222  * this port.  A value of zero indicates that upcalls should not be sent.
223  * @OVS_VPORT_ATTR_STATS: A &struct ovs_vport_stats giving statistics for
224  * packets sent or received through the vport.
225  * @OVS_VPORT_ATTR_ADDRESS: A 6-byte Ethernet address for the vport.
226  *
227  * These attributes follow the &struct ovs_header within the Generic Netlink
228  * payload for %OVS_VPORT_* commands.
229  *
230  * For %OVS_VPORT_CMD_NEW requests, the %OVS_VPORT_ATTR_TYPE and
231  * %OVS_VPORT_ATTR_NAME attributes are required.  %OVS_VPORT_ATTR_PORT_NO is
232  * optional; if not specified a free port number is automatically selected.
233  * Whether %OVS_VPORT_ATTR_OPTIONS is required or optional depends on the type
234  * of vport.  %OVS_VPORT_ATTR_STATS and %OVS_VPORT_ATTR_ADDRESS are optional,
235  * and other attributes are ignored.
236  *
237  * For other requests, if %OVS_VPORT_ATTR_NAME is specified then it is used to
238  * look up the vport to operate on; otherwise dp_idx from the &struct
239  * ovs_header plus %OVS_VPORT_ATTR_PORT_NO determine the vport.
240  */
241 enum ovs_vport_attr {
242         OVS_VPORT_ATTR_UNSPEC,
243         OVS_VPORT_ATTR_PORT_NO, /* port number within datapath */
244         OVS_VPORT_ATTR_TYPE,    /* 32-bit OVS_VPORT_TYPE_* constant. */
245         OVS_VPORT_ATTR_NAME,    /* string name, up to IFNAMSIZ bytes long */
246         OVS_VPORT_ATTR_UPCALL_PID, /* Netlink PID to receive upcalls */
247         OVS_VPORT_ATTR_STATS,   /* struct ovs_vport_stats */
248         OVS_VPORT_ATTR_ADDRESS, /* hardware address */
249         OVS_VPORT_ATTR_OPTIONS, /* nested attributes, varies by vport type */
250         __OVS_VPORT_ATTR_MAX
251 };
252
253 #define OVS_VPORT_ATTR_MAX (__OVS_VPORT_ATTR_MAX - 1)
254
255 /* OVS_VPORT_ATTR_OPTIONS attributes for patch vports. */
256 enum {
257         OVS_PATCH_ATTR_UNSPEC,
258         OVS_PATCH_ATTR_PEER,    /* name of peer vport, as a string */
259         __OVS_PATCH_ATTR_MAX
260 };
261
262 #define OVS_PATCH_ATTR_MAX (__OVS_PATCH_ATTR_MAX - 1)
263 \f
264 /* Flows. */
265
266 #define OVS_FLOW_FAMILY  "ovs_flow"
267 #define OVS_FLOW_MCGROUP "ovs_flow"
268
269 enum ovs_flow_cmd {
270         OVS_FLOW_CMD_UNSPEC,
271         OVS_FLOW_CMD_NEW,
272         OVS_FLOW_CMD_DEL,
273         OVS_FLOW_CMD_GET,
274         OVS_FLOW_CMD_SET
275 };
276
277 struct ovs_flow_stats {
278     uint64_t n_packets;         /* Number of matched packets. */
279     uint64_t n_bytes;           /* Number of matched bytes. */
280 };
281
282 enum ovs_key_type {
283         OVS_KEY_ATTR_UNSPEC,
284         OVS_KEY_ATTR_TUN_ID,    /* 64-bit tunnel ID */
285         OVS_KEY_ATTR_IN_PORT,   /* 32-bit OVS dp port number */
286         OVS_KEY_ATTR_ETHERNET,  /* struct ovs_key_ethernet */
287         OVS_KEY_ATTR_8021Q,     /* struct ovs_key_8021q */
288         OVS_KEY_ATTR_ETHERTYPE, /* 16-bit Ethernet type */
289         OVS_KEY_ATTR_IPV4,      /* struct ovs_key_ipv4 */
290         OVS_KEY_ATTR_IPV6,      /* struct ovs_key_ipv6 */
291         OVS_KEY_ATTR_TCP,       /* struct ovs_key_tcp */
292         OVS_KEY_ATTR_UDP,       /* struct ovs_key_udp */
293         OVS_KEY_ATTR_ICMP,      /* struct ovs_key_icmp */
294         OVS_KEY_ATTR_ICMPV6,    /* struct ovs_key_icmpv6 */
295         OVS_KEY_ATTR_ARP,       /* struct ovs_key_arp */
296         OVS_KEY_ATTR_ND,        /* struct ovs_key_nd */
297         __OVS_KEY_ATTR_MAX
298 };
299
300 #define OVS_KEY_ATTR_MAX (__OVS_KEY_ATTR_MAX - 1)
301
302 struct ovs_key_ethernet {
303         uint8_t  eth_src[6];
304         uint8_t  eth_dst[6];
305 };
306
307 struct ovs_key_8021q {
308         ovs_be16 q_tpid;
309         ovs_be16 q_tci;
310 };
311
312 struct ovs_key_ipv4 {
313         ovs_be32 ipv4_src;
314         ovs_be32 ipv4_dst;
315         uint8_t  ipv4_proto;
316         uint8_t  ipv4_tos;
317 };
318
319 struct ovs_key_ipv6 {
320         ovs_be32 ipv6_src[4];
321         ovs_be32 ipv6_dst[4];
322         uint8_t  ipv6_proto;
323         uint8_t  ipv6_tos;
324 };
325
326 struct ovs_key_tcp {
327         ovs_be16 tcp_src;
328         ovs_be16 tcp_dst;
329 };
330
331 struct ovs_key_udp {
332         ovs_be16 udp_src;
333         ovs_be16 udp_dst;
334 };
335
336 struct ovs_key_icmp {
337         uint8_t icmp_type;
338         uint8_t icmp_code;
339 };
340
341 struct ovs_key_icmpv6 {
342         uint8_t icmpv6_type;
343         uint8_t icmpv6_code;
344 };
345
346 struct ovs_key_arp {
347         ovs_be32 arp_sip;
348         ovs_be32 arp_tip;
349         ovs_be16 arp_op;
350         uint8_t  arp_sha[6];
351         uint8_t  arp_tha[6];
352 };
353
354 struct ovs_key_nd {
355         uint32_t nd_target[4];
356         uint8_t  nd_sll[6];
357         uint8_t  nd_tll[6];
358 };
359
360 /**
361  * enum ovs_flow_attr - attributes for %OVS_FLOW_* commands.
362  * @OVS_FLOW_ATTR_KEY: Nested %OVS_KEY_ATTR_* attributes specifying the flow
363  * key.  Always present in notifications.  Required for all requests (except
364  * dumps).
365  * @OVS_FLOW_ATTR_ACTIONS: Nested %OVS_ACTION_ATTR_* attributes specifying
366  * the actions to take for packets that match the key.  Always present in
367  * notifications.  Required for %OVS_FLOW_CMD_NEW requests, optional
368  * @OVS_FLOW_ATTR_STATS: &struct ovs_flow_stats giving statistics for this
369  * flow.  Present in notifications if the stats would be nonzero.  Ignored in
370  * requests.
371  * @OVS_FLOW_ATTR_TCP_FLAGS: An 8-bit value giving the OR'd value of all of the
372  * TCP flags seen on packets in this flow.  Only present in notifications for
373  * TCP flows, and only if it would be nonzero.  Ignored in requests.
374  * @OVS_FLOW_ATTR_USED: A 64-bit integer giving the time, in milliseconds on
375  * the system monotonic clock, at which a packet was last processed for this
376  * flow.  Only present in notifications if a packet has been processed for this
377  * flow.  Ignored in requests.
378  * @OVS_FLOW_ATTR_CLEAR: If present in a %OVS_FLOW_CMD_SET request, clears the
379  * last-used time, accumulated TCP flags, and statistics for this flow.
380  * Otherwise ignored in requests.  Never present in notifications.
381  *
382  * These attributes follow the &struct ovs_header within the Generic Netlink
383  * payload for %OVS_FLOW_* commands.
384  */
385 enum ovs_flow_attr {
386         OVS_FLOW_ATTR_UNSPEC,
387         OVS_FLOW_ATTR_KEY,       /* Sequence of OVS_KEY_ATTR_* attributes. */
388         OVS_FLOW_ATTR_ACTIONS,   /* Nested OVS_ACTION_ATTR_* attributes. */
389         OVS_FLOW_ATTR_STATS,     /* struct ovs_flow_stats. */
390         OVS_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
391         OVS_FLOW_ATTR_USED,      /* u64 msecs last used in monotonic time. */
392         OVS_FLOW_ATTR_CLEAR,     /* Flag to clear stats, tcp_flags, used. */
393         __OVS_FLOW_ATTR_MAX
394 };
395
396 #define OVS_FLOW_ATTR_MAX (__OVS_FLOW_ATTR_MAX - 1)
397
398 /**
399  * enum ovs_sample_attr - Attributes for %OVS_ACTION_ATTR_SAMPLE action.
400  * @OVS_SAMPLE_ATTR_PROBABILITY: 32-bit fraction of packets to sample with
401  * @OVS_ACTION_ATTR_SAMPLE.  A value of 0 samples no packets, a value of
402  * %UINT32_MAX samples all packets and intermediate values sample intermediate
403  * fractions of packets.
404  * @OVS_SAMPLE_ATTR_ACTIONS: Set of actions to execute in sampling event.
405  * Actions are passed as nested attributes.
406  *
407  * Executes the specified actions with the given probability on a per-packet
408  * basis.
409  */
410 enum ovs_sample_attr {
411         OVS_SAMPLE_ATTR_UNSPEC,
412         OVS_SAMPLE_ATTR_PROBABILITY, /* u32 number */
413         OVS_SAMPLE_ATTR_ACTIONS,     /* Nested OVS_ACTION_ATTR_* attributes. */
414         __OVS_SAMPLE_ATTR_MAX,
415 };
416
417 #define OVS_SAMPLE_ATTR_MAX (__OVS_SAMPLE_ATTR_MAX - 1)
418
419 /**
420  * enum ovs_userspace_attr - Attributes for %OVS_ACTION_ATTR_USERSPACE action.
421  * @OVS_USERSPACE_ATTR_PID: u32 Netlink PID to which the %OVS_PACKET_CMD_ACTION
422  * message should be sent.  Required.
423  * @OVS_USERSPACE_ATTR_USERDATA: If present, its u64 argument is copied to the
424  * %OVS_PACKET_CMD_ACTION message as %OVS_PACKET_ATTR_USERDATA,
425  */
426 enum ovs_userspace_attr {
427         OVS_USERSPACE_ATTR_UNSPEC,
428         OVS_USERSPACE_ATTR_PID,       /* u32 Netlink PID to receive upcalls. */
429         OVS_USERSPACE_ATTR_USERDATA,  /* u64 optional user-specified cookie. */
430         __OVS_USERSPACE_ATTR_MAX
431 };
432
433 #define OVS_USERSPACE_ATTR_MAX (__OVS_USERSPACE_ATTR_MAX - 1)
434
435 /* Action types. */
436 enum ovs_action_type {
437         OVS_ACTION_ATTR_UNSPEC,
438         OVS_ACTION_ATTR_OUTPUT,       /* Output to switch port. */
439         OVS_ACTION_ATTR_USERSPACE,    /* Nested OVS_USERSPACE_ATTR_*. */
440         OVS_ACTION_ATTR_PUSH_VLAN,    /* Set the 802.1q TCI value. */
441         OVS_ACTION_ATTR_POP_VLAN,     /* Strip the 802.1q header. */
442         OVS_ACTION_ATTR_SET_DL_SRC,   /* Ethernet source address. */
443         OVS_ACTION_ATTR_SET_DL_DST,   /* Ethernet destination address. */
444         OVS_ACTION_ATTR_SET_NW_SRC,   /* IPv4 source address. */
445         OVS_ACTION_ATTR_SET_NW_DST,   /* IPv4 destination address. */
446         OVS_ACTION_ATTR_SET_NW_TOS,   /* IP ToS/DSCP field (6 bits). */
447         OVS_ACTION_ATTR_SET_TP_SRC,   /* TCP/UDP source port. */
448         OVS_ACTION_ATTR_SET_TP_DST,   /* TCP/UDP destination port. */
449         OVS_ACTION_ATTR_SET_TUNNEL,   /* Set the encapsulating tunnel ID. */
450         OVS_ACTION_ATTR_SET_PRIORITY, /* Set skb->priority. */
451         OVS_ACTION_ATTR_POP_PRIORITY, /* Restore original skb->priority. */
452         OVS_ACTION_ATTR_SAMPLE,       /* Nested OVS_SAMPLE_ATTR_*. */
453         __OVS_ACTION_ATTR_MAX
454 };
455
456 #define OVS_ACTION_ATTR_MAX (__OVS_ACTION_ATTR_MAX - 1)
457
458 #endif  /* openvswitch/datapath-protocol.h */