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 OPENVSWITCH_DATAPATH_PROTOCOL_H
41 #define OPENVSWITCH_DATAPATH_PROTOCOL_H 1
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
50 #include "openvswitch/types.h"
51 #include <sys/socket.h>
54 #include <linux/netlink.h>
58 #define OVS_DATAPATH_FAMILY "ovs_datapath"
59 #define OVS_DATAPATH_MCGROUP "ovs_datapath"
61 enum ovs_datapath_cmd {
70 * struct ovs_header - header for OVS Generic Netlink messages.
71 * @dp_ifindex: ifindex of local port for datapath (0 to make a request not
72 * specific to a datapath).
74 * Attributes following the header are specific to a particular OVS Generic
75 * Netlink family, but all of the OVS families use this header.
82 * enum ovs_datapath_attr - attributes for %OVS_DP_* commands.
83 * @OVS_DP_ATTR_NAME: Name of the network device that serves as the "local
84 * port". This is the name of the network device whose dp_ifindex is given in
85 * the &struct ovs_header. Always present in notifications. Required in
86 * %OVS_DP_NEW requests. May be used as an alternative to specifying
87 * dp_ifindex in other requests (with a dp_ifindex of 0).
88 * @OVS_DP_ATTR_UPCALL_PID: The Netlink socket in userspace that is initially
89 * set on the datapath port (for OVS_ACTION_ATTR_MISS). Only valid on
90 * %OVS_DP_CMD_NEW requests. A value of zero indicates that upcalls should
92 * @OVS_DP_ATTR_STATS: Statistics about packets that have passed through the
93 * datapath. Always present in notifications.
94 * @OVS_DP_ATTR_IPV4_FRAGS: One of %OVS_DP_FRAG_*. Always present in
95 * notifications. May be included in %OVS_DP_NEW or %OVS_DP_SET requests to
96 * change the fragment handling policy.
98 * These attributes follow the &struct ovs_header within the Generic Netlink
99 * payload for %OVS_DP_* commands.
101 enum ovs_datapath_attr {
103 OVS_DP_ATTR_NAME, /* name of dp_ifindex netdev */
104 OVS_DP_ATTR_UPCALL_PID, /* Netlink PID to receive upcalls */
105 OVS_DP_ATTR_STATS, /* struct ovs_dp_stats */
106 OVS_DP_ATTR_IPV4_FRAGS, /* 32-bit enum ovs_frag_handling */
110 #define OVS_DP_ATTR_MAX (__OVS_DP_ATTR_MAX - 1)
113 * enum ovs_frag_handling - policy for handling received IPv4 fragments.
114 * @OVS_DP_FRAG_ZERO: Treat IP fragments as IP protocol 0 and transport ports
116 * @OVS_DP_FRAG_DROP: Drop IP fragments. Do not pass them through the flow
117 * table or up to userspace.
119 enum ovs_frag_handling {
121 OVS_DP_FRAG_ZERO, /* Treat IP fragments as transport port 0. */
122 OVS_DP_FRAG_DROP /* Drop IP fragments. */
125 struct ovs_dp_stats {
126 uint64_t n_frags; /* Number of dropped IP fragments. */
127 uint64_t n_hit; /* Number of flow table matches. */
128 uint64_t n_missed; /* Number of flow table misses. */
129 uint64_t n_lost; /* Number of misses not sent to userspace. */
130 uint64_t n_flows; /* Number of flows present */
133 struct ovs_vport_stats {
134 uint64_t rx_packets; /* total packets received */
135 uint64_t tx_packets; /* total packets transmitted */
136 uint64_t rx_bytes; /* total bytes received */
137 uint64_t tx_bytes; /* total bytes transmitted */
138 uint64_t rx_errors; /* bad packets received */
139 uint64_t tx_errors; /* packet transmit problems */
140 uint64_t rx_dropped; /* no space in linux buffers */
141 uint64_t tx_dropped; /* no space available in linux */
145 #define OVSP_LOCAL ((uint16_t)0)
147 #define OVS_PACKET_FAMILY "ovs_packet"
149 enum ovs_packet_cmd {
150 OVS_PACKET_CMD_UNSPEC,
152 /* Kernel-to-user notifications. */
153 OVS_PACKET_CMD_MISS, /* Flow table miss. */
154 OVS_PACKET_CMD_ACTION, /* OVS_ACTION_ATTR_USERSPACE action. */
157 OVS_PACKET_CMD_EXECUTE /* Apply actions to a packet. */
161 * enum ovs_packet_attr - attributes for %OVS_PACKET_* commands.
162 * @OVS_PACKET_ATTR_PACKET: Present for all notifications. Contains the entire
163 * packet as received, from the start of the Ethernet header onward. For
164 * %OVS_PACKET_CMD_ACTION, %OVS_PACKET_ATTR_PACKET reflects changes made by
165 * actions preceding %OVS_ACTION_ATTR_USERSPACE, but %OVS_PACKET_ATTR_KEY is
166 * the flow key extracted from the packet as originally received.
167 * @OVS_PACKET_ATTR_KEY: Present for all notifications. Contains the flow key
168 * extracted from the packet as nested %OVS_KEY_ATTR_* attributes. This allows
169 * userspace to adapt its flow setup strategy by comparing its notion of the
170 * flow key against the kernel's.
171 * @OVS_PACKET_ATTR_ACTIONS: Contains actions for the packet. Used
172 * for %OVS_PACKET_CMD_EXECUTE. It has nested %OVS_ACTION_ATTR_* attributes.
173 * @OVS_PACKET_ATTR_UPCALL_PID: Optionally present for OVS_PACKET_CMD_EXECUTE.
174 * The Netlink socket in userspace that OVS_PACKET_CMD_USERSPACE and
175 * OVS_PACKET_CMD_SAMPLE upcalls will be directed to for actions triggered by
176 * this packet. A value of zero indicates that upcalls should not be sent.
177 * @OVS_PACKET_ATTR_USERDATA: Present for an %OVS_PACKET_CMD_ACTION
178 * notification if the %OVS_ACTION_ATTR_USERSPACE, action's argument was
181 * These attributes follow the &struct ovs_header within the Generic Netlink
182 * payload for %OVS_PACKET_* commands.
184 enum ovs_packet_attr {
185 OVS_PACKET_ATTR_UNSPEC,
186 OVS_PACKET_ATTR_PACKET, /* Packet data. */
187 OVS_PACKET_ATTR_KEY, /* Nested OVS_KEY_ATTR_* attributes. */
188 OVS_PACKET_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
189 OVS_PACKET_ATTR_UPCALL_PID, /* Netlink PID to receive upcalls. */
190 OVS_PACKET_ATTR_USERDATA, /* u64 OVS_ACTION_ATTR_USERSPACE arg. */
191 __OVS_PACKET_ATTR_MAX
194 #define OVS_PACKET_ATTR_MAX (__OVS_PACKET_ATTR_MAX - 1)
196 enum ovs_vport_type {
197 OVS_VPORT_TYPE_UNSPEC,
198 OVS_VPORT_TYPE_NETDEV, /* network device */
199 OVS_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
200 OVS_VPORT_TYPE_PATCH, /* virtual tunnel connecting two vports */
201 OVS_VPORT_TYPE_GRE, /* GRE tunnel */
202 OVS_VPORT_TYPE_CAPWAP, /* CAPWAP tunnel */
206 #define OVS_VPORT_TYPE_MAX (__OVS_VPORT_TYPE_MAX - 1)
208 #define OVS_VPORT_FAMILY "ovs_vport"
209 #define OVS_VPORT_MCGROUP "ovs_vport"
212 OVS_VPORT_CMD_UNSPEC,
220 * enum ovs_vport_attr - attributes for %OVS_VPORT_* commands.
221 * @OVS_VPORT_ATTR_PORT_NO: 32-bit port number within datapath.
222 * @OVS_VPORT_ATTR_TYPE: 32-bit %OVS_VPORT_TYPE_* constant describing the type
224 * @OVS_VPORT_ATTR_NAME: Name of vport. For a vport based on a network device
225 * this is the name of the network device. Maximum length %IFNAMSIZ-1 bytes
226 * plus a null terminator.
227 * @OVS_VPORT_ATTR_UPCALL_PID: The Netlink socket in userspace that
228 * OVS_PACKET_CMD_MISS upcalls will be directed to for packets received on
229 * this port. A value of zero indicates that upcalls should not be sent.
230 * @OVS_VPORT_ATTR_STATS: A &struct ovs_vport_stats giving statistics for
231 * packets sent or received through the vport.
232 * @OVS_VPORT_ATTR_ADDRESS: A 6-byte Ethernet address for the vport.
233 * @OVS_VPORT_ATTR_IFINDEX: ifindex of the underlying network device, if any.
235 * These attributes follow the &struct ovs_header within the Generic Netlink
236 * payload for %OVS_VPORT_* commands.
238 * All attributes applicable to a given port are present in notifications.
239 * This means that, for example, a vport that has no corresponding network
240 * device would omit %OVS_VPORT_ATTR_IFINDEX.
242 * For %OVS_VPORT_CMD_NEW requests, the %OVS_VPORT_ATTR_TYPE and
243 * %OVS_VPORT_ATTR_NAME attributes are required. %OVS_VPORT_ATTR_PORT_NO is
244 * optional; if not specified a free port number is automatically selected.
245 * Whether %OVS_VPORT_ATTR_OPTIONS is required or optional depends on the type
246 * of vport. %OVS_VPORT_ATTR_STATS and %OVS_VPORT_ATTR_ADDRESS are optional,
247 * and other attributes are ignored.
249 * For other requests, if %OVS_VPORT_ATTR_NAME is specified then it is used to
250 * look up the vport to operate on; otherwise dp_idx from the &struct
251 * ovs_header plus %OVS_VPORT_ATTR_PORT_NO determine the vport.
253 enum ovs_vport_attr {
254 OVS_VPORT_ATTR_UNSPEC,
255 OVS_VPORT_ATTR_PORT_NO, /* port number within datapath */
256 OVS_VPORT_ATTR_TYPE, /* 32-bit OVS_VPORT_TYPE_* constant. */
257 OVS_VPORT_ATTR_NAME, /* string name, up to IFNAMSIZ bytes long */
258 OVS_VPORT_ATTR_UPCALL_PID, /* Netlink PID to receive upcalls */
259 OVS_VPORT_ATTR_STATS, /* struct ovs_vport_stats */
260 OVS_VPORT_ATTR_ADDRESS, /* hardware address */
261 OVS_VPORT_ATTR_OPTIONS, /* nested attributes, varies by vport type */
262 OVS_VPORT_ATTR_IFINDEX, /* 32-bit ifindex of backing netdev */
266 #define OVS_VPORT_ATTR_MAX (__OVS_VPORT_ATTR_MAX - 1)
268 /* OVS_VPORT_ATTR_OPTIONS attributes for patch vports. */
270 OVS_PATCH_ATTR_UNSPEC,
271 OVS_PATCH_ATTR_PEER, /* name of peer vport, as a string */
275 #define OVS_PATCH_ATTR_MAX (__OVS_PATCH_ATTR_MAX - 1)
279 #define OVS_FLOW_FAMILY "ovs_flow"
280 #define OVS_FLOW_MCGROUP "ovs_flow"
290 struct ovs_flow_stats {
291 uint64_t n_packets; /* Number of matched packets. */
292 uint64_t n_bytes; /* Number of matched bytes. */
297 OVS_KEY_ATTR_TUN_ID, /* 64-bit tunnel ID */
298 OVS_KEY_ATTR_IN_PORT, /* 32-bit OVS dp port number */
299 OVS_KEY_ATTR_ETHERNET, /* struct ovs_key_ethernet */
300 OVS_KEY_ATTR_8021Q, /* struct ovs_key_8021q */
301 OVS_KEY_ATTR_ETHERTYPE, /* 16-bit Ethernet type */
302 OVS_KEY_ATTR_IPV4, /* struct ovs_key_ipv4 */
303 OVS_KEY_ATTR_IPV6, /* struct ovs_key_ipv6 */
304 OVS_KEY_ATTR_TCP, /* struct ovs_key_tcp */
305 OVS_KEY_ATTR_UDP, /* struct ovs_key_udp */
306 OVS_KEY_ATTR_ICMP, /* struct ovs_key_icmp */
307 OVS_KEY_ATTR_ICMPV6, /* struct ovs_key_icmpv6 */
308 OVS_KEY_ATTR_ARP, /* struct ovs_key_arp */
309 OVS_KEY_ATTR_ND, /* struct ovs_key_nd */
313 #define OVS_KEY_ATTR_MAX (__OVS_KEY_ATTR_MAX - 1)
315 struct ovs_key_ethernet {
320 struct ovs_key_8021q {
325 struct ovs_key_ipv4 {
332 struct ovs_key_ipv6 {
333 ovs_be32 ipv6_src[4];
334 ovs_be32 ipv6_dst[4];
349 struct ovs_key_icmp {
354 struct ovs_key_icmpv6 {
368 uint32_t nd_target[4];
374 * enum ovs_flow_attr - attributes for %OVS_FLOW_* commands.
375 * @OVS_FLOW_ATTR_KEY: Nested %OVS_KEY_ATTR_* attributes specifying the flow
376 * key. Always present in notifications. Required for all requests (except
378 * @OVS_FLOW_ATTR_ACTIONS: Nested %OVS_ACTION_ATTR_* attributes specifying
379 * the actions to take for packets that match the key. Always present in
380 * notifications. Required for %OVS_FLOW_CMD_NEW requests, optional
381 * @OVS_FLOW_ATTR_UPCALL_PID: The Netlink socket in userspace that
382 * OVS_PACKET_CMD_USERSPACE and OVS_PACKET_CMD_SAMPLE upcalls will be
383 * directed to for packets received on this port. A value of zero indicates
384 * that upcalls should not be sent.
385 * on %OVS_FLOW_CMD_SET request to change the existing actions, ignored for
387 * @OVS_FLOW_ATTR_STATS: &struct ovs_flow_stats giving statistics for this
388 * flow. Present in notifications if the stats would be nonzero. Ignored in
390 * @OVS_FLOW_ATTR_TCP_FLAGS: An 8-bit value giving the OR'd value of all of the
391 * TCP flags seen on packets in this flow. Only present in notifications for
392 * TCP flows, and only if it would be nonzero. Ignored in requests.
393 * @OVS_FLOW_ATTR_USED: A 64-bit integer giving the time, in milliseconds on
394 * the system monotonic clock, at which a packet was last processed for this
395 * flow. Only present in notifications if a packet has been processed for this
396 * flow. Ignored in requests.
397 * @OVS_FLOW_ATTR_CLEAR: If present in a %OVS_FLOW_CMD_SET request, clears the
398 * last-used time, accumulated TCP flags, and statistics for this flow.
399 * Otherwise ignored in requests. Never present in notifications.
401 * These attributes follow the &struct ovs_header within the Generic Netlink
402 * payload for %OVS_FLOW_* commands.
405 OVS_FLOW_ATTR_UNSPEC,
406 OVS_FLOW_ATTR_KEY, /* Sequence of OVS_KEY_ATTR_* attributes. */
407 OVS_FLOW_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
408 OVS_FLOW_ATTR_UPCALL_PID, /* Netlink PID to receive upcalls. */
409 OVS_FLOW_ATTR_STATS, /* struct ovs_flow_stats. */
410 OVS_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
411 OVS_FLOW_ATTR_USED, /* u64 msecs last used in monotonic time. */
412 OVS_FLOW_ATTR_CLEAR, /* Flag to clear stats, tcp_flags, used. */
416 #define OVS_FLOW_ATTR_MAX (__OVS_FLOW_ATTR_MAX - 1)
419 * enum ovs_sample_attr - Attributes for OVS_ACTION_ATTR_SAMPLE
420 * @OVS_SAMPLE_ATTR_PROBABILITY: 32-bit fraction of packets to sample with
421 * @OVS_ACTION_ATTR_SAMPLE. A value of 0 samples no packets, a value of
422 * %UINT32_MAX samples all packets and intermediate values sample intermediate
423 * fractions of packets.
424 * @OVS_SAMPLE_ATTR_ACTIONS: Set of actions to execute in sampling event.
425 * Actions are passed as nested attributes.
427 enum ovs_sample_attr {
428 OVS_SAMPLE_ATTR_UNSPEC,
429 OVS_SAMPLE_ATTR_PROBABILITY, /* u32 number */
430 OVS_SAMPLE_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
431 __OVS_SAMPLE_ATTR_MAX,
434 #define OVS_SAMPLE_ATTR_MAX (__OVS_SAMPLE_ATTR_MAX - 1)
437 enum ovs_action_type {
438 OVS_ACTION_ATTR_UNSPEC,
439 OVS_ACTION_ATTR_OUTPUT, /* Output to switch port. */
440 OVS_ACTION_ATTR_USERSPACE, /* Send copy to userspace. */
441 OVS_ACTION_ATTR_PUSH_VLAN, /* Set the 802.1q TCI value. */
442 OVS_ACTION_ATTR_POP_VLAN, /* Strip the 802.1q header. */
443 OVS_ACTION_ATTR_SET_DL_SRC, /* Ethernet source address. */
444 OVS_ACTION_ATTR_SET_DL_DST, /* Ethernet destination address. */
445 OVS_ACTION_ATTR_SET_NW_SRC, /* IPv4 source address. */
446 OVS_ACTION_ATTR_SET_NW_DST, /* IPv4 destination address. */
447 OVS_ACTION_ATTR_SET_NW_TOS, /* IP ToS/DSCP field (6 bits). */
448 OVS_ACTION_ATTR_SET_TP_SRC, /* TCP/UDP source port. */
449 OVS_ACTION_ATTR_SET_TP_DST, /* TCP/UDP destination port. */
450 OVS_ACTION_ATTR_SET_TUNNEL, /* Set the encapsulating tunnel ID. */
451 OVS_ACTION_ATTR_SET_PRIORITY, /* Set skb->priority. */
452 OVS_ACTION_ATTR_POP_PRIORITY, /* Restore original skb->priority. */
453 OVS_ACTION_ATTR_SAMPLE, /* Execute list of actions at given
455 __OVS_ACTION_ATTR_MAX
458 #define OVS_ACTION_ATTR_MAX (__OVS_ACTION_ATTR_MAX - 1)
460 #endif /* openvswitch/datapath-protocol.h */