2 * Copyright (c) 2009, 2010, 2011 Nicira Networks.
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
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:
16 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
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 * ----------------------------------------------------------------------
40 #ifndef _LINUX_OPENVSWITCH_H
41 #define _LINUX_OPENVSWITCH_H 1
43 #include <linux/types.h>
47 #define OVS_DATAPATH_FAMILY "ovs_datapath"
48 #define OVS_DATAPATH_MCGROUP "ovs_datapath"
50 enum ovs_datapath_cmd {
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).
63 * Attributes following the header are specific to a particular OVS Generic
64 * Netlink family, but all of the OVS families use this header.
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
81 * @OVS_DP_ATTR_STATS: Statistics about packets that have passed through the
82 * datapath. Always present in notifications.
84 * These attributes follow the &struct ovs_header within the Generic Netlink
85 * payload for %OVS_DP_* commands.
87 enum ovs_datapath_attr {
89 OVS_DP_ATTR_NAME, /* name of dp_ifindex netdev */
90 OVS_DP_ATTR_UPCALL_PID, /* Netlink PID to receive upcalls */
91 OVS_DP_ATTR_STATS, /* struct ovs_dp_stats */
95 #define OVS_DP_ATTR_MAX (__OVS_DP_ATTR_MAX - 1)
98 __u64 n_hit; /* Number of flow table matches. */
99 __u64 n_missed; /* Number of flow table misses. */
100 __u64 n_lost; /* Number of misses not sent to userspace. */
101 __u64 n_flows; /* Number of flows present */
104 struct ovs_vport_stats {
105 __u64 rx_packets; /* total packets received */
106 __u64 tx_packets; /* total packets transmitted */
107 __u64 rx_bytes; /* total bytes received */
108 __u64 tx_bytes; /* total bytes transmitted */
109 __u64 rx_errors; /* bad packets received */
110 __u64 tx_errors; /* packet transmit problems */
111 __u64 rx_dropped; /* no space in linux buffers */
112 __u64 tx_dropped; /* no space available in linux */
116 #define OVSP_LOCAL ((__u16)0)
118 #define OVS_PACKET_FAMILY "ovs_packet"
120 enum ovs_packet_cmd {
121 OVS_PACKET_CMD_UNSPEC,
123 /* Kernel-to-user notifications. */
124 OVS_PACKET_CMD_MISS, /* Flow table miss. */
125 OVS_PACKET_CMD_ACTION, /* OVS_ACTION_ATTR_USERSPACE action. */
128 OVS_PACKET_CMD_EXECUTE /* Apply actions to a packet. */
132 * enum ovs_packet_attr - attributes for %OVS_PACKET_* commands.
133 * @OVS_PACKET_ATTR_PACKET: Present for all notifications. Contains the entire
134 * packet as received, from the start of the Ethernet header onward. For
135 * %OVS_PACKET_CMD_ACTION, %OVS_PACKET_ATTR_PACKET reflects changes made by
136 * actions preceding %OVS_ACTION_ATTR_USERSPACE, but %OVS_PACKET_ATTR_KEY is
137 * the flow key extracted from the packet as originally received.
138 * @OVS_PACKET_ATTR_KEY: Present for all notifications. Contains the flow key
139 * extracted from the packet as nested %OVS_KEY_ATTR_* attributes. This allows
140 * userspace to adapt its flow setup strategy by comparing its notion of the
141 * flow key against the kernel's.
142 * @OVS_PACKET_ATTR_ACTIONS: Contains actions for the packet. Used
143 * for %OVS_PACKET_CMD_EXECUTE. It has nested %OVS_ACTION_ATTR_* attributes.
144 * @OVS_PACKET_ATTR_USERDATA: Present for an %OVS_PACKET_CMD_ACTION
145 * notification if the %OVS_ACTION_ATTR_USERSPACE action specified an
146 * %OVS_USERSPACE_ATTR_USERDATA attribute.
148 * These attributes follow the &struct ovs_header within the Generic Netlink
149 * payload for %OVS_PACKET_* commands.
151 enum ovs_packet_attr {
152 OVS_PACKET_ATTR_UNSPEC,
153 OVS_PACKET_ATTR_PACKET, /* Packet data. */
154 OVS_PACKET_ATTR_KEY, /* Nested OVS_KEY_ATTR_* attributes. */
155 OVS_PACKET_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
156 OVS_PACKET_ATTR_USERDATA, /* u64 OVS_ACTION_ATTR_USERSPACE arg. */
157 __OVS_PACKET_ATTR_MAX
160 #define OVS_PACKET_ATTR_MAX (__OVS_PACKET_ATTR_MAX - 1)
162 enum ovs_vport_type {
163 OVS_VPORT_TYPE_UNSPEC,
164 OVS_VPORT_TYPE_NETDEV, /* network device */
165 OVS_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
166 OVS_VPORT_TYPE_PATCH, /* virtual tunnel connecting two vports */
167 OVS_VPORT_TYPE_GRE, /* GRE tunnel */
168 OVS_VPORT_TYPE_CAPWAP, /* CAPWAP tunnel */
172 #define OVS_VPORT_TYPE_MAX (__OVS_VPORT_TYPE_MAX - 1)
174 #define OVS_VPORT_FAMILY "ovs_vport"
175 #define OVS_VPORT_MCGROUP "ovs_vport"
178 OVS_VPORT_CMD_UNSPEC,
186 * enum ovs_vport_attr - attributes for %OVS_VPORT_* commands.
187 * @OVS_VPORT_ATTR_PORT_NO: 32-bit port number within datapath.
188 * @OVS_VPORT_ATTR_TYPE: 32-bit %OVS_VPORT_TYPE_* constant describing the type
190 * @OVS_VPORT_ATTR_NAME: Name of vport. For a vport based on a network device
191 * this is the name of the network device. Maximum length %IFNAMSIZ-1 bytes
192 * plus a null terminator.
193 * @OVS_VPORT_ATTR_UPCALL_PID: The Netlink socket in userspace that
194 * OVS_PACKET_CMD_MISS upcalls will be directed to for packets received on
195 * this port. A value of zero indicates that upcalls should not be sent.
196 * @OVS_VPORT_ATTR_STATS: A &struct ovs_vport_stats giving statistics for
197 * packets sent or received through the vport.
198 * @OVS_VPORT_ATTR_ADDRESS: A 6-byte Ethernet address for the vport.
200 * These attributes follow the &struct ovs_header within the Generic Netlink
201 * payload for %OVS_VPORT_* commands.
203 * For %OVS_VPORT_CMD_NEW requests, the %OVS_VPORT_ATTR_TYPE and
204 * %OVS_VPORT_ATTR_NAME attributes are required. %OVS_VPORT_ATTR_PORT_NO is
205 * optional; if not specified a free port number is automatically selected.
206 * Whether %OVS_VPORT_ATTR_OPTIONS is required or optional depends on the type
207 * of vport. %OVS_VPORT_ATTR_STATS and %OVS_VPORT_ATTR_ADDRESS are optional,
208 * and other attributes are ignored.
210 * For other requests, if %OVS_VPORT_ATTR_NAME is specified then it is used to
211 * look up the vport to operate on; otherwise dp_idx from the &struct
212 * ovs_header plus %OVS_VPORT_ATTR_PORT_NO determine the vport.
214 enum ovs_vport_attr {
215 OVS_VPORT_ATTR_UNSPEC,
216 OVS_VPORT_ATTR_PORT_NO, /* port number within datapath */
217 OVS_VPORT_ATTR_TYPE, /* 32-bit OVS_VPORT_TYPE_* constant. */
218 OVS_VPORT_ATTR_NAME, /* string name, up to IFNAMSIZ bytes long */
219 OVS_VPORT_ATTR_UPCALL_PID, /* Netlink PID to receive upcalls */
220 OVS_VPORT_ATTR_STATS, /* struct ovs_vport_stats */
221 OVS_VPORT_ATTR_ADDRESS, /* hardware address */
222 OVS_VPORT_ATTR_OPTIONS, /* nested attributes, varies by vport type */
226 #define OVS_VPORT_ATTR_MAX (__OVS_VPORT_ATTR_MAX - 1)
228 /* OVS_VPORT_ATTR_OPTIONS attributes for patch vports. */
230 OVS_PATCH_ATTR_UNSPEC,
231 OVS_PATCH_ATTR_PEER, /* name of peer vport, as a string */
235 #define OVS_PATCH_ATTR_MAX (__OVS_PATCH_ATTR_MAX - 1)
239 #define OVS_FLOW_FAMILY "ovs_flow"
240 #define OVS_FLOW_MCGROUP "ovs_flow"
250 struct ovs_flow_stats {
251 __u64 n_packets; /* Number of matched packets. */
252 __u64 n_bytes; /* Number of matched bytes. */
257 OVS_KEY_ATTR_TUN_ID, /* 64-bit tunnel ID */
258 OVS_KEY_ATTR_IN_PORT, /* 32-bit OVS dp port number */
259 OVS_KEY_ATTR_ETHERNET, /* struct ovs_key_ethernet */
260 OVS_KEY_ATTR_8021Q, /* struct ovs_key_8021q */
261 OVS_KEY_ATTR_ETHERTYPE, /* 16-bit Ethernet type */
262 OVS_KEY_ATTR_IPV4, /* struct ovs_key_ipv4 */
263 OVS_KEY_ATTR_IPV6, /* struct ovs_key_ipv6 */
264 OVS_KEY_ATTR_TCP, /* struct ovs_key_tcp */
265 OVS_KEY_ATTR_UDP, /* struct ovs_key_udp */
266 OVS_KEY_ATTR_ICMP, /* struct ovs_key_icmp */
267 OVS_KEY_ATTR_ICMPV6, /* struct ovs_key_icmpv6 */
268 OVS_KEY_ATTR_ARP, /* struct ovs_key_arp */
269 OVS_KEY_ATTR_ND, /* struct ovs_key_nd */
273 #define OVS_KEY_ATTR_MAX (__OVS_KEY_ATTR_MAX - 1)
276 * enum ovs_frag_type - IPv4 and IPv6 fragment type
277 * @OVS_FRAG_TYPE_NONE: Packet is not a fragment.
278 * @OVS_FRAG_TYPE_FIRST: Packet is a fragment with offset 0.
279 * @OVS_FRAG_TYPE_LATER: Packet is a fragment with nonzero offset.
281 * Used as the @ipv4_frag in &struct ovs_key_ipv4 and as @ipv6_frag &struct
291 #define OVS_FRAG_TYPE_MAX (__OVS_FRAG_TYPE_MAX - 1)
293 struct ovs_key_ethernet {
298 struct ovs_key_8021q {
303 struct ovs_key_ipv4 {
308 __u8 ipv4_frag; /* One of OVS_FRAG_TYPE_*. */
311 struct ovs_key_ipv6 {
316 __u8 ipv6_frag; /* One of OVS_FRAG_TYPE_*. */
329 struct ovs_key_icmp {
334 struct ovs_key_icmpv6 {
354 * enum ovs_flow_attr - attributes for %OVS_FLOW_* commands.
355 * @OVS_FLOW_ATTR_KEY: Nested %OVS_KEY_ATTR_* attributes specifying the flow
356 * key. Always present in notifications. Required for all requests (except
358 * @OVS_FLOW_ATTR_ACTIONS: Nested %OVS_ACTION_ATTR_* attributes specifying
359 * the actions to take for packets that match the key. Always present in
360 * notifications. Required for %OVS_FLOW_CMD_NEW requests, optional
361 * @OVS_FLOW_ATTR_STATS: &struct ovs_flow_stats giving statistics for this
362 * flow. Present in notifications if the stats would be nonzero. Ignored in
364 * @OVS_FLOW_ATTR_TCP_FLAGS: An 8-bit value giving the OR'd value of all of the
365 * TCP flags seen on packets in this flow. Only present in notifications for
366 * TCP flows, and only if it would be nonzero. Ignored in requests.
367 * @OVS_FLOW_ATTR_USED: A 64-bit integer giving the time, in milliseconds on
368 * the system monotonic clock, at which a packet was last processed for this
369 * flow. Only present in notifications if a packet has been processed for this
370 * flow. Ignored in requests.
371 * @OVS_FLOW_ATTR_CLEAR: If present in a %OVS_FLOW_CMD_SET request, clears the
372 * last-used time, accumulated TCP flags, and statistics for this flow.
373 * Otherwise ignored in requests. Never present in notifications.
375 * These attributes follow the &struct ovs_header within the Generic Netlink
376 * payload for %OVS_FLOW_* commands.
379 OVS_FLOW_ATTR_UNSPEC,
380 OVS_FLOW_ATTR_KEY, /* Sequence of OVS_KEY_ATTR_* attributes. */
381 OVS_FLOW_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
382 OVS_FLOW_ATTR_STATS, /* struct ovs_flow_stats. */
383 OVS_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
384 OVS_FLOW_ATTR_USED, /* u64 msecs last used in monotonic time. */
385 OVS_FLOW_ATTR_CLEAR, /* Flag to clear stats, tcp_flags, used. */
389 #define OVS_FLOW_ATTR_MAX (__OVS_FLOW_ATTR_MAX - 1)
392 * enum ovs_sample_attr - Attributes for %OVS_ACTION_ATTR_SAMPLE action.
393 * @OVS_SAMPLE_ATTR_PROBABILITY: 32-bit fraction of packets to sample with
394 * @OVS_ACTION_ATTR_SAMPLE. A value of 0 samples no packets, a value of
395 * %UINT32_MAX samples all packets and intermediate values sample intermediate
396 * fractions of packets.
397 * @OVS_SAMPLE_ATTR_ACTIONS: Set of actions to execute in sampling event.
398 * Actions are passed as nested attributes.
400 * Executes the specified actions with the given probability on a per-packet
403 enum ovs_sample_attr {
404 OVS_SAMPLE_ATTR_UNSPEC,
405 OVS_SAMPLE_ATTR_PROBABILITY, /* u32 number */
406 OVS_SAMPLE_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
407 __OVS_SAMPLE_ATTR_MAX,
410 #define OVS_SAMPLE_ATTR_MAX (__OVS_SAMPLE_ATTR_MAX - 1)
413 * enum ovs_userspace_attr - Attributes for %OVS_ACTION_ATTR_USERSPACE action.
414 * @OVS_USERSPACE_ATTR_PID: u32 Netlink PID to which the %OVS_PACKET_CMD_ACTION
415 * message should be sent. Required.
416 * @OVS_USERSPACE_ATTR_USERDATA: If present, its u64 argument is copied to the
417 * %OVS_PACKET_CMD_ACTION message as %OVS_PACKET_ATTR_USERDATA,
419 enum ovs_userspace_attr {
420 OVS_USERSPACE_ATTR_UNSPEC,
421 OVS_USERSPACE_ATTR_PID, /* u32 Netlink PID to receive upcalls. */
422 OVS_USERSPACE_ATTR_USERDATA, /* u64 optional user-specified cookie. */
423 __OVS_USERSPACE_ATTR_MAX
426 #define OVS_USERSPACE_ATTR_MAX (__OVS_USERSPACE_ATTR_MAX - 1)
429 * enum ovs_action_attr - Action types.
431 * @OVS_ACTION_ATTR_OUTPUT: Output packet to port passed as NLA data.
432 * @OVS_ACTION_ATTR_USERSPACE: Nested %OVS_USERSPACE_ATTR_ attributes specifying
434 * @OVS_ACTION_ATTR_PUSH: Nested %OVS_KEY_ATTR_* attribute specifying header to
435 * push to given packet.
436 * E.g. Push vlan tag action would be NLA of %OVS_ACTION_ATTR_PUSH type with
437 * nested attribute of type %OVS_KEY_ATTR_8021Q with struct ovs_key_8021q
439 * @OVS_ACTION_ATTR_POP: Pop header according to %OVS_KEY_ATTR_ sent as
441 * @OVS_ACTION_ATTR_SET: Nested %OVS_KEY_ATTR_* attribute specifying the
442 * field to set to given packet.
443 * @OVS_ACTION_ATTR_SET_PRIORITY: A set skb->priority to 32-bit number passed
445 * @OVS_ACTION_ATTR_POP_PRIORITY: Restore skb->priority to original value.
446 * @OVS_ACTION_ATTR_SAMPLE: Execute set of actions according to probability
447 * %OVS_SAMPLE_ATTR_PROBABILITY.
449 * Only a single field can be set with a single %OVS_ACTION_ATTR_{SET,PUSH}.
452 enum ovs_action_attr {
453 OVS_ACTION_ATTR_UNSPEC,
454 OVS_ACTION_ATTR_OUTPUT, /* Output to switch port. */
455 OVS_ACTION_ATTR_USERSPACE, /* Nested OVS_USERSPACE_ATTR_*. */
456 OVS_ACTION_ATTR_PUSH, /* Push packet header. */
457 OVS_ACTION_ATTR_POP, /* Pop packet header. */
458 OVS_ACTION_ATTR_SET, /* Set packet field(s). */
459 OVS_ACTION_ATTR_SET_PRIORITY, /* Set skb->priority. */
460 OVS_ACTION_ATTR_POP_PRIORITY, /* Restore original skb->priority. */
461 OVS_ACTION_ATTR_SAMPLE, /* Nested OVS_SAMPLE_ATTR_*. */
462 __OVS_ACTION_ATTR_MAX
465 #define OVS_ACTION_ATTR_MAX (__OVS_ACTION_ATTR_MAX - 1)
467 #endif /* _LINUX_OPENVSWITCH_H */