Remove NXAST_DROP_SPOOFED_ARP action.
[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
54 #include <linux/if_link.h>
55 #include <linux/netlink.h>
56 \f
57 /* datapaths. */
58
59 #define ODP_DATAPATH_FAMILY  "odp_datapath"
60 #define ODP_DATAPATH_MCGROUP "odp_datapath"
61
62 enum odp_datapath_cmd {
63         ODP_DP_CMD_UNSPEC,
64         ODP_DP_CMD_NEW,
65         ODP_DP_CMD_DEL,
66         ODP_DP_CMD_GET,
67         ODP_DP_CMD_SET
68 };
69
70 /**
71  * struct odp_header - header for ODP Generic Netlink messages.
72  * @dp_ifindex: ifindex of local port for datapath (0 to make a request not
73  * specific to a datapath).
74  *
75  * Attributes following the header are specific to a particular ODP Generic
76  * Netlink family, but all of the ODP families use this header.
77  */
78 struct odp_header {
79         int dp_ifindex;
80 };
81 \f
82 /**
83  * enum odp_datapath_attr - attributes for %ODP_DP_* commands.
84  * @ODP_DP_ATTR_NAME: Name of the network device that serves as the "local
85  * port".  This is the name of the network device whose dp_ifindex is given in
86  * the &struct odp_header.  Always present in notifications.  Required in
87  * %ODP_DP_NEW requests.  May be used as an alternative to specifying
88  * dp_ifindex in other requests (with a dp_ifindex of 0).
89  * @ODP_DP_ATTR_STATS: Statistics about packets that have passed through the
90  * datapath.  Always present in notifications.
91  * @ODP_DP_ATTR_IPV4_FRAGS: One of %ODP_DP_FRAG_*.  Always present in
92  * notifications.  May be included in %ODP_DP_NEW or %ODP_DP_SET requests to
93  * change the fragment handling policy.
94  * @ODP_DP_ATTR_SAMPLING: 32-bit fraction of packets to sample with
95  * @ODP_PACKET_CMD_SAMPLE.  A value of 0 samples no packets, a value of
96  * %UINT32_MAX samples all packets, and intermediate values sample intermediate
97  * fractions of packets.
98  * @ODP_DP_ATTR_MCGROUPS: Nested attributes with multicast groups.  Each nested
99  * attribute has a %ODP_PACKET_CMD_* type with a 32-bit value giving the
100  * Generic Netlink multicast group number used for sending this datapath's
101  * messages with that command type up to userspace.
102  *
103  * These attributes follow the &struct odp_header within the Generic Netlink
104  * payload for %ODP_DP_* commands.
105  */
106 enum odp_datapath_attr {
107         ODP_DP_ATTR_UNSPEC,
108         ODP_DP_ATTR_NAME,       /* name of dp_ifindex netdev */
109         ODP_DP_ATTR_STATS,      /* struct odp_stats */
110         ODP_DP_ATTR_IPV4_FRAGS, /* 32-bit enum odp_frag_handling */
111         ODP_DP_ATTR_SAMPLING,   /* 32-bit fraction of packets to sample. */
112         ODP_DP_ATTR_MCGROUPS,   /* Nested attributes with multicast groups. */
113         __ODP_DP_ATTR_MAX
114 };
115
116 #define ODP_DP_ATTR_MAX (__ODP_DP_ATTR_MAX - 1)
117
118 /**
119  * enum odp_frag_handling - policy for handling received IPv4 fragments.
120  * @ODP_DP_FRAG_ZERO: Treat IP fragments as IP protocol 0 and transport ports
121  * zero.
122  * @ODP_DP_FRAG_DROP: Drop IP fragments.  Do not pass them through the flow
123  * table or up to userspace.
124  */
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 \f
141 #define ODP_PACKET_FAMILY "odp_packet"
142
143 enum odp_packet_cmd {
144         ODP_PACKET_CMD_UNSPEC,
145
146         /* Kernel-to-user notifications. */
147         ODP_PACKET_CMD_MISS,    /* Flow table miss. */
148         ODP_PACKET_CMD_ACTION,  /* ODP_ACTION_ATTR_CONTROLLER action. */
149         ODP_PACKET_CMD_SAMPLE,  /* Sampled packet. */
150
151         /* User commands. */
152         ODP_PACKET_CMD_EXECUTE  /* Apply actions to a packet. */
153 };
154
155 /**
156  * enum odp_packet_attr - attributes for %ODP_PACKET_* commands.
157  * @ODP_PACKET_ATTR_PACKET: Present for all notifications.  Contains the entire
158  * packet as received, from the start of the Ethernet header onward.  For
159  * %ODP_PACKET_CMD_ACTION, %ODP_PACKET_ATTR_PACKET reflects changes made by
160  * actions preceding %ODP_ACTION_ATTR_CONTROLLER, but %ODP_PACKET_ATTR_KEY is
161  * the flow key extracted from the packet as originally received.
162  * @ODP_PACKET_ATTR_KEY: Present for all notifications.  Contains the flow key
163  * extracted from the packet as nested %ODP_KEY_ATTR_* attributes.  This allows
164  * userspace to adapt its flow setup strategy by comparing its notion of the
165  * flow key against the kernel's.
166  * @ODP_PACKET_ATTR_USERDATA: Present for an %ODP_PACKET_CMD_ACTION
167  * notification if the %ODP_ACTION_ATTR_CONTROLLER, action's argument was
168  * nonzero.
169  * @ODP_PACKET_ATTR_SAMPLE_POOL: Present for %ODP_PACKET_CMD_SAMPLE.  Contains
170  * the number of packets processed so far that were candidates for sampling.
171  * @ODP_PACKET_ATTR_ACTIONS: Present for %ODP_PACKET_CMD_SAMPLE.  Contains a
172  * copy of the actions applied to the packet, as nested %ODP_ACTION_ATTR_*
173  * attributes.
174  *
175  * These attributes follow the &struct odp_header within the Generic Netlink
176  * payload for %ODP_PACKET_* commands.
177  */
178 enum odp_packet_attr {
179         ODP_PACKET_ATTR_UNSPEC,
180         ODP_PACKET_ATTR_PACKET,      /* Packet data. */
181         ODP_PACKET_ATTR_KEY,         /* Nested ODP_KEY_ATTR_* attributes. */
182         ODP_PACKET_ATTR_USERDATA,    /* u64 ODP_ACTION_ATTR_CONTROLLER arg. */
183         ODP_PACKET_ATTR_SAMPLE_POOL, /* # sampling candidate packets so far. */
184         ODP_PACKET_ATTR_ACTIONS,     /* Nested ODP_ACTION_ATTR_* attributes. */
185         __ODP_PACKET_ATTR_MAX
186 };
187
188 #define ODP_PACKET_ATTR_MAX (__ODP_PACKET_ATTR_MAX - 1)
189 \f
190 enum odp_vport_type {
191         ODP_VPORT_TYPE_UNSPEC,
192         ODP_VPORT_TYPE_NETDEV,   /* network device */
193         ODP_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
194         ODP_VPORT_TYPE_PATCH,    /* virtual tunnel connecting two vports */
195         ODP_VPORT_TYPE_GRE,      /* GRE tunnel */
196         ODP_VPORT_TYPE_CAPWAP,   /* CAPWAP tunnel */
197         __ODP_VPORT_TYPE_MAX
198 };
199
200 #define ODP_VPORT_TYPE_MAX (__ODP_VPORT_TYPE_MAX - 1)
201 \f
202 #define ODP_VPORT_FAMILY  "odp_vport"
203 #define ODP_VPORT_MCGROUP "odp_vport"
204
205 enum odp_vport_cmd {
206         ODP_VPORT_CMD_UNSPEC,
207         ODP_VPORT_CMD_NEW,
208         ODP_VPORT_CMD_DEL,
209         ODP_VPORT_CMD_GET,
210         ODP_VPORT_CMD_SET
211 };
212
213 /**
214  * enum odp_vport_attr - attributes for %ODP_VPORT_* commands.
215  * @ODP_VPORT_ATTR_PORT_NO: 32-bit port number within datapath.
216  * @ODP_VPORT_ATTR_TYPE: 32-bit %ODP_VPORT_TYPE_* constant describing the type
217  * of vport.
218  * @ODP_VPORT_ATTR_NAME: Name of vport.  For a vport based on a network device
219  * this is the name of the network device.  Maximum length %IFNAMSIZ-1 bytes
220  * plus a null terminator.
221  * @ODP_VPORT_ATTR_STATS: A &struct rtnl_link_stats64 giving statistics for
222  * packets sent or received through the vport.
223  * @ODP_VPORT_ATTR_ADDRESS: A 6-byte Ethernet address for the vport.
224  * @ODP_VPORT_ATTR_MTU: MTU for the vport.  Omitted if the vport does not have
225  * an MTU as, e.g., some tunnels do not.
226  * @ODP_VPORT_ATTR_IFINDEX: ifindex of the underlying network device, if any.
227  * @ODP_VPORT_ATTR_IFLINK: ifindex of the device on which packets are sent (for
228  * tunnels), if any.
229  *
230  * These attributes follow the &struct odp_header within the Generic Netlink
231  * payload for %ODP_VPORT_* commands.
232  *
233  * All attributes applicable to a given port are present in notifications.
234  * This means that, for example, a vport that has no corresponding network
235  * device would omit %ODP_VPORT_ATTR_IFINDEX.
236  *
237  * For %ODP_VPORT_CMD_NEW requests, the %ODP_VPORT_ATTR_TYPE and
238  * %ODP_VPORT_ATTR_NAME attributes are required.  %ODP_VPORT_ATTR_PORT_NO is
239  * optional; if not specified a free port number is automatically selected.
240  * Whether %ODP_VPORT_ATTR_OPTIONS is required or optional depends on the type
241  * of vport.  %ODP_VPORT_ATTR_STATS, %ODP_VPORT_ATTR_ADDRESS, and
242  * %ODP_VPORT_ATTR_MTU are optional, and other attributes are ignored.
243  *
244  * For other requests, if %ODP_VPORT_ATTR_NAME is specified then it is used to
245  * look up the vport to operate on; otherwise dp_idx from the &struct
246  * odp_header plus %ODP_VPORT_ATTR_PORT_NO determine the vport.
247  */
248 enum odp_vport_attr {
249         ODP_VPORT_ATTR_UNSPEC,
250         ODP_VPORT_ATTR_PORT_NO, /* port number within datapath */
251         ODP_VPORT_ATTR_TYPE,    /* 32-bit ODP_VPORT_TYPE_* constant. */
252         ODP_VPORT_ATTR_NAME,    /* string name, up to IFNAMSIZ bytes long */
253         ODP_VPORT_ATTR_STATS,   /* struct rtnl_link_stats64 */
254         ODP_VPORT_ATTR_ADDRESS, /* hardware address */
255         ODP_VPORT_ATTR_MTU,     /* 32-bit maximum transmission unit */
256         ODP_VPORT_ATTR_OPTIONS, /* nested attributes, varies by vport type */
257         ODP_VPORT_ATTR_IFINDEX, /* 32-bit ifindex of backing netdev */
258         ODP_VPORT_ATTR_IFLINK,  /* 32-bit ifindex on which packets are sent */
259         __ODP_VPORT_ATTR_MAX
260 };
261
262 #define ODP_VPORT_ATTR_MAX (__ODP_VPORT_ATTR_MAX - 1)
263
264 /* ODP_VPORT_ATTR_OPTIONS attributes for patch vports. */
265 enum {
266         ODP_PATCH_ATTR_UNSPEC,
267         ODP_PATCH_ATTR_PEER,    /* name of peer vport, as a string */
268         __ODP_PATCH_ATTR_MAX
269 };
270
271 #define ODP_PATCH_ATTR_MAX (__ODP_PATCH_ATTR_MAX - 1)
272 \f
273 /* Flows. */
274
275 #define ODP_FLOW_FAMILY  "odp_flow"
276 #define ODP_FLOW_MCGROUP "odp_flow"
277
278 enum odp_flow_cmd {
279         ODP_FLOW_CMD_UNSPEC,
280         ODP_FLOW_CMD_NEW,
281         ODP_FLOW_CMD_DEL,
282         ODP_FLOW_CMD_GET,
283         ODP_FLOW_CMD_SET
284 };
285
286 struct odp_flow_stats {
287     uint64_t n_packets;         /* Number of matched packets. */
288     uint64_t n_bytes;           /* Number of matched bytes. */
289 };
290
291 enum odp_key_type {
292         ODP_KEY_ATTR_UNSPEC,
293         ODP_KEY_ATTR_TUN_ID,    /* 64-bit tunnel ID */
294         ODP_KEY_ATTR_IN_PORT,   /* 32-bit ODP port number */
295         ODP_KEY_ATTR_ETHERNET,  /* struct odp_key_ethernet */
296         ODP_KEY_ATTR_8021Q,     /* struct odp_key_8021q */
297         ODP_KEY_ATTR_ETHERTYPE, /* 16-bit Ethernet type */
298         ODP_KEY_ATTR_IPV4,      /* struct odp_key_ipv4 */
299         ODP_KEY_ATTR_IPV6,      /* struct odp_key_ipv6 */
300         ODP_KEY_ATTR_TCP,       /* struct odp_key_tcp */
301         ODP_KEY_ATTR_UDP,       /* struct odp_key_udp */
302         ODP_KEY_ATTR_ICMP,      /* struct odp_key_icmp */
303         ODP_KEY_ATTR_ICMPV6,    /* struct odp_key_icmpv6 */
304         ODP_KEY_ATTR_ARP,       /* struct odp_key_arp */
305         ODP_KEY_ATTR_ND,        /* struct odp_key_nd */
306         __ODP_KEY_ATTR_MAX
307 };
308
309 #define ODP_KEY_ATTR_MAX (__ODP_KEY_ATTR_MAX - 1)
310
311 struct odp_key_ethernet {
312         uint8_t  eth_src[6];
313         uint8_t  eth_dst[6];
314 };
315
316 struct odp_key_8021q {
317         ovs_be16 q_tpid;
318         ovs_be16 q_tci;
319 };
320
321 struct odp_key_ipv4 {
322         ovs_be32 ipv4_src;
323         ovs_be32 ipv4_dst;
324         uint8_t  ipv4_proto;
325         uint8_t  ipv4_tos;
326 };
327
328 struct odp_key_ipv6 {
329         ovs_be32 ipv6_src[4];
330         ovs_be32 ipv6_dst[4];
331         uint8_t  ipv6_proto;
332         uint8_t  ipv6_tos;
333 };
334
335 struct odp_key_tcp {
336         ovs_be16 tcp_src;
337         ovs_be16 tcp_dst;
338 };
339
340 struct odp_key_udp {
341         ovs_be16 udp_src;
342         ovs_be16 udp_dst;
343 };
344
345 struct odp_key_icmp {
346         uint8_t icmp_type;
347         uint8_t icmp_code;
348 };
349
350 struct odp_key_icmpv6 {
351         uint8_t icmpv6_type;
352         uint8_t icmpv6_code;
353 };
354
355 struct odp_key_arp {
356         ovs_be32 arp_sip;
357         ovs_be32 arp_tip;
358         ovs_be16 arp_op;
359         uint8_t  arp_sha[6];
360         uint8_t  arp_tha[6];
361 };
362
363 struct odp_key_nd {
364         uint32_t nd_target[4];
365         uint8_t  nd_sll[6];
366         uint8_t  nd_tll[6];
367 };
368
369 /**
370  * enum odp_flow_attr - attributes for %ODP_FLOW_* commands.
371  * @ODP_FLOW_ATTR_KEY: Nested %ODP_KEY_ATTR_* attributes specifying the flow
372  * key.  Always present in notifications.  Required for all requests (except
373  * dumps).
374  * @ODP_FLOW_ATTR_ACTIONS: Nested %ODPAT_* attributes specifying the actions to
375  * take for packets that match the key.  Always present in notifications.
376  * Required for %ODP_FLOW_CMD_NEW requests, optional on %ODP_FLOW_CMD_SET
377  * request to change the existing actions, ignored for other requests.
378  * @ODP_FLOW_ATTR_STATS: &struct odp_flow_stats giving statistics for this
379  * flow.  Present in notifications if the stats would be nonzero.  Ignored in
380  * requests.
381  * @ODP_FLOW_ATTR_TCP_FLAGS: An 8-bit value giving the OR'd value of all of the
382  * TCP flags seen on packets in this flow.  Only present in notifications for
383  * TCP flows, and only if it would be nonzero.  Ignored in requests.
384  * @ODP_FLOW_ATTR_USED: A 64-bit integer giving the time, in milliseconds on
385  * the system monotonic clock, at which a packet was last processed for this
386  * flow.  Only present in notifications if a packet has been processed for this
387  * flow.  Ignored in requests.
388  * @ODP_FLOW_ATTR_CLEAR: If present in a %ODP_FLOW_CMD_SET request, clears the
389  * last-used time, accumulated TCP flags, and statistics for this flow.
390  * Otherwise ignored in requests.  Never present in notifications.
391  *
392  * These attributes follow the &struct odp_header within the Generic Netlink
393  * payload for %ODP_FLOW_* commands.
394  */
395 enum odp_flow_attr {
396         ODP_FLOW_ATTR_UNSPEC,
397         ODP_FLOW_ATTR_KEY,       /* Sequence of ODP_KEY_ATTR_* attributes. */
398         ODP_FLOW_ATTR_ACTIONS,   /* Nested ODP_ACTION_ATTR_* attributes. */
399         ODP_FLOW_ATTR_STATS,     /* struct odp_flow_stats. */
400         ODP_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
401         ODP_FLOW_ATTR_USED,      /* u64 msecs last used in monotonic time. */
402         ODP_FLOW_ATTR_CLEAR,     /* Flag to clear stats, tcp_flags, used. */
403         __ODP_FLOW_ATTR_MAX
404 };
405
406 #define ODP_FLOW_ATTR_MAX (__ODP_FLOW_ATTR_MAX - 1)
407
408 /* Action types. */
409 enum odp_action_type {
410         ODP_ACTION_ATTR_UNSPEC,
411         ODP_ACTION_ATTR_OUTPUT,       /* Output to switch port. */
412         ODP_ACTION_ATTR_CONTROLLER,   /* Send copy to controller. */
413         ODP_ACTION_ATTR_SET_DL_TCI,   /* Set the 802.1q TCI value. */
414         ODP_ACTION_ATTR_STRIP_VLAN,   /* Strip the 802.1q header. */
415         ODP_ACTION_ATTR_SET_DL_SRC,   /* Ethernet source address. */
416         ODP_ACTION_ATTR_SET_DL_DST,   /* Ethernet destination address. */
417         ODP_ACTION_ATTR_SET_NW_SRC,   /* IPv4 source address. */
418         ODP_ACTION_ATTR_SET_NW_DST,   /* IPv4 destination address. */
419         ODP_ACTION_ATTR_SET_NW_TOS,   /* IP ToS/DSCP field (6 bits). */
420         ODP_ACTION_ATTR_SET_TP_SRC,   /* TCP/UDP source port. */
421         ODP_ACTION_ATTR_SET_TP_DST,   /* TCP/UDP destination port. */
422         ODP_ACTION_ATTR_SET_TUNNEL,   /* Set the encapsulating tunnel ID. */
423         ODP_ACTION_ATTR_SET_PRIORITY, /* Set skb->priority. */
424         ODP_ACTION_ATTR_POP_PRIORITY, /* Restore original skb->priority. */
425         __ODP_ACTION_ATTR_MAX
426 };
427
428 #define ODP_ACTION_ATTR_MAX (__ODP_ACTION_ATTR_MAX - 1)
429
430 #endif  /* openvswitch/datapath-protocol.h */