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