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 /* Protocol between userspace and kernel datapath.
42 * Be sure to update datapath/odp-compat.h if you change any of the structures
45 #ifndef OPENVSWITCH_DATAPATH_PROTOCOL_H
46 #define OPENVSWITCH_DATAPATH_PROTOCOL_H 1
48 /* The ovs_be<N> types indicate that an object is in big-endian, not
49 * native-endian, byte order. They are otherwise equivalent to uint<N>_t.
50 * The Linux kernel already has __be<N> types for this, which take on
51 * additional semantics when the "sparse" static checker is used, so we use
52 * those types when compiling the kernel. */
54 #include <linux/types.h>
55 #include <linux/socket.h>
56 #define ovs_be16 __be16
57 #define ovs_be32 __be32
58 #define ovs_be64 __be64
60 #include "openvswitch/types.h"
61 #include <sys/socket.h>
65 #define __aligned_u64 __u64 __attribute__((aligned(8)))
66 #define __aligned_be64 __be64 __attribute__((aligned(8)))
67 #define __aligned_le64 __le64 __attribute__((aligned(8)))
70 #include <linux/if_link.h>
71 #include <linux/netlink.h>
73 #define ODP_VPORT_NEW _IOR('O', 7, struct odp_vport)
74 #define ODP_VPORT_DEL _IOR('O', 8, struct odp_vport)
75 #define ODP_VPORT_GET _IOWR('O', 9, struct odp_vport)
76 #define ODP_VPORT_SET _IOR('O', 22, struct odp_vport)
77 #define ODP_VPORT_DUMP _IOWR('O', 10, struct odp_vport)
79 #define ODP_FLOW_NEW _IOWR('O', 13, struct odp_flow)
80 #define ODP_FLOW_DEL _IOWR('O', 14, struct odp_flow)
81 #define ODP_FLOW_GET _IOWR('O', 15, struct odp_flow)
82 #define ODP_FLOW_SET _IOWR('O', 16, struct odp_flow)
83 #define ODP_FLOW_DUMP _IOWR('O', 17, struct odp_flow)
84 #define ODP_FLOW_FLUSH _IO('O', 19)
88 #define ODP_DATAPATH_FAMILY "odp_datapath"
89 #define ODP_DATAPATH_MCGROUP "odp_datapath"
91 enum odp_datapath_cmd {
100 * struct odp_header - header for ODP Generic Netlink messages.
101 * @dp_idx: Number of datapath to which the packet belongs.
103 * Attributes following the header are specific to a particular ODP Generic
104 * Netlink family, but all of the ODP families use this header.
111 * enum odp_datapath_attr - attributes for %ODP_DP_* commands.
112 * @ODP_DP_ATTR_NAME: Name of the network device that serves as the "local
113 * port". This is the name of the network device whose dp_idx is given in the
114 * &struct odp_header. Always present in notifications. Required in
115 * %ODP_DP_NEW requests. May be used as an alternative to specifying dp_idx on
116 * other requests (with a dp_idx of %UINT32_MAX).
117 * @ODP_DP_ATTR_STATS: Statistics about packets that have passed through the
118 * datapath. Always present in notifications.
119 * @ODP_DP_ATTR_IPV4_FRAGS: One of %ODP_DP_FRAG_*. Always present in
120 * notifications. May be included in %ODP_DP_NEW or %ODP_DP_SET requests to
121 * change the fragment handling policy.
122 * @ODP_DP_ATTR_SAMPLING: 32-bit fraction of packets to sample with
123 * @ODP_PACKET_CMD_SAMPLE. A value of 0 samples no packets, a value of
124 * %UINT32_MAX samples all packets, and intermediate values sample intermediate
125 * fractions of packets.
126 * @ODP_DP_ATTR_MCGROUPS: Nested attributes with multicast groups. Each nested
127 * attribute has a %ODP_PACKET_CMD_* type with a 32-bit value giving the
128 * Generic Netlink multicast group number used for sending this datapath's
129 * messages with that command type up to userspace.
131 * These attributes follow the &struct odp_header within the Generic Netlink
132 * payload for %ODP_DP_* commands.
134 enum odp_datapath_attr {
136 ODP_DP_ATTR_NAME, /* name of dp_ifidx netdev */
137 ODP_DP_ATTR_STATS, /* struct odp_stats */
138 ODP_DP_ATTR_IPV4_FRAGS, /* 32-bit enum odp_frag_handling */
139 ODP_DP_ATTR_SAMPLING, /* 32-bit fraction of packets to sample. */
140 ODP_DP_ATTR_MCGROUPS, /* Nested attributes with multicast groups. */
144 #define ODP_DP_ATTR_MAX (__ODP_DP_ATTR_MAX - 1)
147 * enum odp_frag_handling - policy for handling received IPv4 fragments.
148 * @ODP_DP_FRAG_ZERO: Treat IP fragments as IP protocol 0 and transport ports
150 * @ODP_DP_FRAG_DROP: Drop IP fragments. Do not pass them through the flow
151 * table or up to userspace.
153 enum odp_frag_handling {
155 ODP_DP_FRAG_ZERO, /* Treat IP fragments as transport port 0. */
156 ODP_DP_FRAG_DROP /* Drop IP fragments. */
160 uint64_t n_frags; /* Number of dropped IP fragments. */
161 uint64_t n_hit; /* Number of flow table matches. */
162 uint64_t n_missed; /* Number of flow table misses. */
163 uint64_t n_lost; /* Number of misses not sent to userspace. */
167 #define ODPP_LOCAL ((uint16_t)0)
169 #define ODP_PACKET_FAMILY "odp_packet"
171 enum odp_packet_cmd {
172 ODP_PACKET_CMD_UNSPEC,
174 /* Kernel-to-user notifications. */
175 ODP_PACKET_CMD_MISS, /* Flow table miss. */
176 ODP_PACKET_CMD_ACTION, /* ODPAT_CONTROLLER action. */
177 ODP_PACKET_CMD_SAMPLE, /* Sampled packet. */
180 ODP_PACKET_CMD_EXECUTE /* Apply actions to a packet. */
184 * enum odp_packet_attr - attributes for %ODP_PACKET_* commands.
185 * @ODP_PACKET_ATTR_PACKET: Present for all notifications. Contains the entire
186 * packet as received, from the start of the Ethernet header onward. For
187 * %ODP_PACKET_CMD_ACTION, %ODP_PACKET_ATTR_PACKET reflects changes made by
188 * actions preceding %ODPAT_CONTROLLER, but %ODP_PACKET_ATTR_KEY is the flow
189 * key extracted from the packet as originally received.
190 * @ODP_PACKET_ATTR_KEY: Present for all notifications. Contains the flow key
191 * extracted from the packet as nested %ODP_KEY_ATTR_* attributes. This allows
192 * userspace to adapt its flow setup strategy by comparing its notion of the
193 * flow key against the kernel's.
194 * @ODP_PACKET_ATTR_USERDATA: Present for an %ODP_PACKET_CMD_ACTION
195 * notification if the %ODPAT_CONTROLLER action's argument was nonzero.
196 * @ODP_PACKET_ATTR_SAMPLE_POOL: Present for %ODP_PACKET_CMD_SAMPLE. Contains
197 * the number of packets processed so far that were candidates for sampling.
198 * @ODP_PACKET_ATTR_ACTIONS: Present for %ODP_PACKET_CMD_SAMPLE. Contains a
199 * copy of the actions applied to the packet, as nested %ODPAT_* attributes.
201 * These attributes follow the &struct odp_header within the Generic Netlink
202 * payload for %ODP_PACKET_* commands.
204 enum odp_packet_attr {
205 ODP_PACKET_ATTR_UNSPEC,
206 ODP_PACKET_ATTR_PACKET, /* Packet data. */
207 ODP_PACKET_ATTR_KEY, /* Nested ODP_KEY_ATTR_* attributes. */
208 ODP_PACKET_ATTR_USERDATA, /* 64-bit data from ODPAT_CONTROLLER. */
209 ODP_PACKET_ATTR_SAMPLE_POOL, /* # sampling candidate packets so far. */
210 ODP_PACKET_ATTR_ACTIONS, /* Nested ODPAT_* attributes. */
211 __ODP_PACKET_ATTR_MAX
214 #define ODP_PACKET_ATTR_MAX (__ODP_PACKET_ATTR_MAX - 1)
216 enum odp_vport_type {
217 ODP_VPORT_TYPE_UNSPEC,
218 ODP_VPORT_TYPE_NETDEV, /* network device */
219 ODP_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
220 ODP_VPORT_TYPE_PATCH, /* virtual tunnel connecting two vports */
221 ODP_VPORT_TYPE_GRE, /* GRE tunnel */
222 ODP_VPORT_TYPE_CAPWAP, /* CAPWAP tunnel */
226 #define ODP_VPORT_TYPE_MAX (__ODP_VPORT_TYPE_MAX - 1)
229 * struct odp_vport - header with basic information about a virtual port.
230 * @dp_idx: Number of datapath to which the vport belongs.
231 * @len: Length of this structure plus the Netlink attributes following it.
232 * @total_len: Total space available for kernel reply to request.
234 * Followed by &struct nlattr attributes, whose types are drawn from
235 * %ODP_VPORT_ATTR_*, up to a length of @len bytes including the &struct
245 ODP_VPORT_ATTR_UNSPEC,
246 ODP_VPORT_ATTR_PORT_NO, /* port number within datapath */
247 ODP_VPORT_ATTR_TYPE, /* 32-bit ODP_VPORT_TYPE_* constant. */
248 ODP_VPORT_ATTR_NAME, /* string name, up to IFNAMSIZ bytes long */
249 ODP_VPORT_ATTR_STATS, /* struct rtnl_link_stats64 */
250 ODP_VPORT_ATTR_ADDRESS, /* hardware address */
251 ODP_VPORT_ATTR_MTU, /* 32-bit maximum transmission unit */
252 ODP_VPORT_ATTR_OPTIONS, /* nested attributes, varies by vport type */
253 ODP_VPORT_ATTR_IFINDEX, /* 32-bit ifindex of backing netdev */
254 ODP_VPORT_ATTR_IFLINK, /* 32-bit ifindex on which packets are sent */
258 #define ODP_VPORT_ATTR_MAX (__ODP_VPORT_ATTR_MAX - 1)
260 /* ODP_VPORT_ATTR_OPTIONS attributes for patch vports. */
262 ODP_PATCH_ATTR_UNSPEC,
263 ODP_PATCH_ATTR_PEER, /* name of peer vport, as a string */
267 #define ODP_PATCH_ATTR_MAX (__ODP_PATCH_ATTR_MAX - 1)
269 struct odp_flow_stats {
270 uint64_t n_packets; /* Number of matched packets. */
271 uint64_t n_bytes; /* Number of matched bytes. */
276 ODP_KEY_ATTR_TUN_ID, /* 64-bit tunnel ID */
277 ODP_KEY_ATTR_IN_PORT, /* 32-bit ODP port number */
278 ODP_KEY_ATTR_ETHERNET, /* struct odp_key_ethernet */
279 ODP_KEY_ATTR_8021Q, /* struct odp_key_8021q */
280 ODP_KEY_ATTR_ETHERTYPE, /* 16-bit Ethernet type */
281 ODP_KEY_ATTR_IPV4, /* struct odp_key_ipv4 */
282 ODP_KEY_ATTR_TCP, /* struct odp_key_tcp */
283 ODP_KEY_ATTR_UDP, /* struct odp_key_udp */
284 ODP_KEY_ATTR_ICMP, /* struct odp_key_icmp */
285 ODP_KEY_ATTR_ARP, /* struct odp_key_arp */
289 #define ODP_KEY_ATTR_MAX (__ODP_KEY_ATTR_MAX - 1)
291 struct odp_key_ethernet {
296 struct odp_key_8021q {
301 struct odp_key_ipv4 {
318 struct odp_key_icmp {
330 * struct odp_flow - header with basic information about a flow.
331 * @dp_idx: Datapath index.
332 * @len: Length of this structure plus the Netlink attributes following it.
333 * @total_len: Total space available for kernel reply to request.
335 * Followed by &struct nlattr attributes, whose types are drawn from
336 * %ODP_FLOW_ATTR_*, up to a length of @len bytes including the &struct
340 uint32_t nlmsg_flags;
347 ODP_FLOW_ATTR_UNSPEC,
348 ODP_FLOW_ATTR_KEY, /* Sequence of ODP_KEY_ATTR_* attributes. */
349 ODP_FLOW_ATTR_ACTIONS, /* Sequence of nested ODPAT_* attributes. */
350 ODP_FLOW_ATTR_STATS, /* struct odp_flow_stats. */
351 ODP_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
352 ODP_FLOW_ATTR_USED, /* u64 msecs last used in monotonic time. */
353 ODP_FLOW_ATTR_CLEAR, /* Flag to clear stats, tcp_flags, used. */
354 ODP_FLOW_ATTR_STATE, /* u64 state for ODP_FLOW_DUMP. */
358 #define ODP_FLOW_ATTR_MAX (__ODP_FLOW_ATTR_MAX - 1)
361 enum odp_action_type {
363 ODPAT_OUTPUT, /* Output to switch port. */
364 ODPAT_CONTROLLER, /* Send copy to controller. */
365 ODPAT_SET_DL_TCI, /* Set the 802.1q TCI value. */
366 ODPAT_STRIP_VLAN, /* Strip the 802.1q header. */
367 ODPAT_SET_DL_SRC, /* Ethernet source address. */
368 ODPAT_SET_DL_DST, /* Ethernet destination address. */
369 ODPAT_SET_NW_SRC, /* IPv4 source address. */
370 ODPAT_SET_NW_DST, /* IPv4 destination address. */
371 ODPAT_SET_NW_TOS, /* IP ToS/DSCP field (6 bits). */
372 ODPAT_SET_TP_SRC, /* TCP/UDP source port. */
373 ODPAT_SET_TP_DST, /* TCP/UDP destination port. */
374 ODPAT_SET_TUNNEL, /* Set the encapsulating tunnel ID. */
375 ODPAT_SET_PRIORITY, /* Set skb->priority. */
376 ODPAT_POP_PRIORITY, /* Restore original skb->priority. */
377 ODPAT_DROP_SPOOFED_ARP, /* Drop ARPs with spoofed source MAC. */
381 #define ODPAT_MAX (__ODPAT_MAX - 1)
383 #endif /* openvswitch/datapath-protocol.h */