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