blob: eb1efa54fe842186893e1080e63a8db64f63098f [file] [log] [blame]
Jesse Grossccb13522011-10-25 19:26:31 -07001/*
2 * Copyright (c) 2007-2011 Nicira Networks.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301, USA
17 */
18
19#ifndef _LINUX_OPENVSWITCH_H
20#define _LINUX_OPENVSWITCH_H 1
21
22#include <linux/types.h>
23
24/**
25 * struct ovs_header - header for OVS Generic Netlink messages.
26 * @dp_ifindex: ifindex of local port for datapath (0 to make a request not
27 * specific to a datapath).
28 *
29 * Attributes following the header are specific to a particular OVS Generic
30 * Netlink family, but all of the OVS families use this header.
31 */
32
33struct ovs_header {
34 int dp_ifindex;
35};
36
37/* Datapaths. */
38
39#define OVS_DATAPATH_FAMILY "ovs_datapath"
40#define OVS_DATAPATH_MCGROUP "ovs_datapath"
41#define OVS_DATAPATH_VERSION 0x1
42
43enum ovs_datapath_cmd {
44 OVS_DP_CMD_UNSPEC,
45 OVS_DP_CMD_NEW,
46 OVS_DP_CMD_DEL,
47 OVS_DP_CMD_GET,
48 OVS_DP_CMD_SET
49};
50
51/**
52 * enum ovs_datapath_attr - attributes for %OVS_DP_* commands.
53 * @OVS_DP_ATTR_NAME: Name of the network device that serves as the "local
54 * port". This is the name of the network device whose dp_ifindex is given in
55 * the &struct ovs_header. Always present in notifications. Required in
56 * %OVS_DP_NEW requests. May be used as an alternative to specifying
57 * dp_ifindex in other requests (with a dp_ifindex of 0).
58 * @OVS_DP_ATTR_UPCALL_PID: The Netlink socket in userspace that is initially
59 * set on the datapath port (for OVS_ACTION_ATTR_MISS). Only valid on
60 * %OVS_DP_CMD_NEW requests. A value of zero indicates that upcalls should
61 * not be sent.
62 * @OVS_DP_ATTR_STATS: Statistics about packets that have passed through the
63 * datapath. Always present in notifications.
64 *
65 * These attributes follow the &struct ovs_header within the Generic Netlink
66 * payload for %OVS_DP_* commands.
67 */
68enum ovs_datapath_attr {
69 OVS_DP_ATTR_UNSPEC,
70 OVS_DP_ATTR_NAME, /* name of dp_ifindex netdev */
71 OVS_DP_ATTR_UPCALL_PID, /* Netlink PID to receive upcalls */
72 OVS_DP_ATTR_STATS, /* struct ovs_dp_stats */
73 __OVS_DP_ATTR_MAX
74};
75
76#define OVS_DP_ATTR_MAX (__OVS_DP_ATTR_MAX - 1)
77
78struct ovs_dp_stats {
79 __u64 n_hit; /* Number of flow table matches. */
80 __u64 n_missed; /* Number of flow table misses. */
81 __u64 n_lost; /* Number of misses not sent to userspace. */
82 __u64 n_flows; /* Number of flows present */
83};
84
85struct ovs_vport_stats {
86 __u64 rx_packets; /* total packets received */
87 __u64 tx_packets; /* total packets transmitted */
88 __u64 rx_bytes; /* total bytes received */
89 __u64 tx_bytes; /* total bytes transmitted */
90 __u64 rx_errors; /* bad packets received */
91 __u64 tx_errors; /* packet transmit problems */
92 __u64 rx_dropped; /* no space in linux buffers */
93 __u64 tx_dropped; /* no space available in linux */
94};
95
96/* Fixed logical ports. */
97#define OVSP_LOCAL ((__u16)0)
98
99/* Packet transfer. */
100
101#define OVS_PACKET_FAMILY "ovs_packet"
102#define OVS_PACKET_VERSION 0x1
103
104enum ovs_packet_cmd {
105 OVS_PACKET_CMD_UNSPEC,
106
107 /* Kernel-to-user notifications. */
108 OVS_PACKET_CMD_MISS, /* Flow table miss. */
109 OVS_PACKET_CMD_ACTION, /* OVS_ACTION_ATTR_USERSPACE action. */
110
111 /* Userspace commands. */
112 OVS_PACKET_CMD_EXECUTE /* Apply actions to a packet. */
113};
114
115/**
116 * enum ovs_packet_attr - attributes for %OVS_PACKET_* commands.
117 * @OVS_PACKET_ATTR_PACKET: Present for all notifications. Contains the entire
118 * packet as received, from the start of the Ethernet header onward. For
119 * %OVS_PACKET_CMD_ACTION, %OVS_PACKET_ATTR_PACKET reflects changes made by
120 * actions preceding %OVS_ACTION_ATTR_USERSPACE, but %OVS_PACKET_ATTR_KEY is
121 * the flow key extracted from the packet as originally received.
122 * @OVS_PACKET_ATTR_KEY: Present for all notifications. Contains the flow key
123 * extracted from the packet as nested %OVS_KEY_ATTR_* attributes. This allows
124 * userspace to adapt its flow setup strategy by comparing its notion of the
125 * flow key against the kernel's.
126 * @OVS_PACKET_ATTR_ACTIONS: Contains actions for the packet. Used
127 * for %OVS_PACKET_CMD_EXECUTE. It has nested %OVS_ACTION_ATTR_* attributes.
128 * @OVS_PACKET_ATTR_USERDATA: Present for an %OVS_PACKET_CMD_ACTION
129 * notification if the %OVS_ACTION_ATTR_USERSPACE action specified an
130 * %OVS_USERSPACE_ATTR_USERDATA attribute.
131 *
132 * These attributes follow the &struct ovs_header within the Generic Netlink
133 * payload for %OVS_PACKET_* commands.
134 */
135enum ovs_packet_attr {
136 OVS_PACKET_ATTR_UNSPEC,
137 OVS_PACKET_ATTR_PACKET, /* Packet data. */
138 OVS_PACKET_ATTR_KEY, /* Nested OVS_KEY_ATTR_* attributes. */
139 OVS_PACKET_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
140 OVS_PACKET_ATTR_USERDATA, /* u64 OVS_ACTION_ATTR_USERSPACE arg. */
141 __OVS_PACKET_ATTR_MAX
142};
143
144#define OVS_PACKET_ATTR_MAX (__OVS_PACKET_ATTR_MAX - 1)
145
146/* Virtual ports. */
147
148#define OVS_VPORT_FAMILY "ovs_vport"
149#define OVS_VPORT_MCGROUP "ovs_vport"
150#define OVS_VPORT_VERSION 0x1
151
152enum ovs_vport_cmd {
153 OVS_VPORT_CMD_UNSPEC,
154 OVS_VPORT_CMD_NEW,
155 OVS_VPORT_CMD_DEL,
156 OVS_VPORT_CMD_GET,
157 OVS_VPORT_CMD_SET
158};
159
160enum ovs_vport_type {
161 OVS_VPORT_TYPE_UNSPEC,
162 OVS_VPORT_TYPE_NETDEV, /* network device */
163 OVS_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
164 __OVS_VPORT_TYPE_MAX
165};
166
167#define OVS_VPORT_TYPE_MAX (__OVS_VPORT_TYPE_MAX - 1)
168
169/**
170 * enum ovs_vport_attr - attributes for %OVS_VPORT_* commands.
171 * @OVS_VPORT_ATTR_PORT_NO: 32-bit port number within datapath.
172 * @OVS_VPORT_ATTR_TYPE: 32-bit %OVS_VPORT_TYPE_* constant describing the type
173 * of vport.
174 * @OVS_VPORT_ATTR_NAME: Name of vport. For a vport based on a network device
175 * this is the name of the network device. Maximum length %IFNAMSIZ-1 bytes
176 * plus a null terminator.
177 * @OVS_VPORT_ATTR_OPTIONS: Vport-specific configuration information.
178 * @OVS_VPORT_ATTR_UPCALL_PID: The Netlink socket in userspace that
179 * OVS_PACKET_CMD_MISS upcalls will be directed to for packets received on
180 * this port. A value of zero indicates that upcalls should not be sent.
181 * @OVS_VPORT_ATTR_STATS: A &struct ovs_vport_stats giving statistics for
182 * packets sent or received through the vport.
183 *
184 * These attributes follow the &struct ovs_header within the Generic Netlink
185 * payload for %OVS_VPORT_* commands.
186 *
187 * For %OVS_VPORT_CMD_NEW requests, the %OVS_VPORT_ATTR_TYPE and
188 * %OVS_VPORT_ATTR_NAME attributes are required. %OVS_VPORT_ATTR_PORT_NO is
189 * optional; if not specified a free port number is automatically selected.
190 * Whether %OVS_VPORT_ATTR_OPTIONS is required or optional depends on the type
191 * of vport.
192 * and other attributes are ignored.
193 *
194 * For other requests, if %OVS_VPORT_ATTR_NAME is specified then it is used to
195 * look up the vport to operate on; otherwise dp_idx from the &struct
196 * ovs_header plus %OVS_VPORT_ATTR_PORT_NO determine the vport.
197 */
198enum ovs_vport_attr {
199 OVS_VPORT_ATTR_UNSPEC,
200 OVS_VPORT_ATTR_PORT_NO, /* u32 port number within datapath */
201 OVS_VPORT_ATTR_TYPE, /* u32 OVS_VPORT_TYPE_* constant. */
202 OVS_VPORT_ATTR_NAME, /* string name, up to IFNAMSIZ bytes long */
203 OVS_VPORT_ATTR_OPTIONS, /* nested attributes, varies by vport type */
204 OVS_VPORT_ATTR_UPCALL_PID, /* u32 Netlink PID to receive upcalls */
205 OVS_VPORT_ATTR_STATS, /* struct ovs_vport_stats */
206 __OVS_VPORT_ATTR_MAX
207};
208
209#define OVS_VPORT_ATTR_MAX (__OVS_VPORT_ATTR_MAX - 1)
210
211/* Flows. */
212
213#define OVS_FLOW_FAMILY "ovs_flow"
214#define OVS_FLOW_MCGROUP "ovs_flow"
215#define OVS_FLOW_VERSION 0x1
216
217enum ovs_flow_cmd {
218 OVS_FLOW_CMD_UNSPEC,
219 OVS_FLOW_CMD_NEW,
220 OVS_FLOW_CMD_DEL,
221 OVS_FLOW_CMD_GET,
222 OVS_FLOW_CMD_SET
223};
224
225struct ovs_flow_stats {
226 __u64 n_packets; /* Number of matched packets. */
227 __u64 n_bytes; /* Number of matched bytes. */
228};
229
230enum ovs_key_attr {
231 OVS_KEY_ATTR_UNSPEC,
232 OVS_KEY_ATTR_ENCAP, /* Nested set of encapsulated attributes. */
233 OVS_KEY_ATTR_PRIORITY, /* u32 skb->priority */
234 OVS_KEY_ATTR_IN_PORT, /* u32 OVS dp port number */
235 OVS_KEY_ATTR_ETHERNET, /* struct ovs_key_ethernet */
236 OVS_KEY_ATTR_VLAN, /* be16 VLAN TCI */
237 OVS_KEY_ATTR_ETHERTYPE, /* be16 Ethernet type */
238 OVS_KEY_ATTR_IPV4, /* struct ovs_key_ipv4 */
239 OVS_KEY_ATTR_IPV6, /* struct ovs_key_ipv6 */
240 OVS_KEY_ATTR_TCP, /* struct ovs_key_tcp */
241 OVS_KEY_ATTR_UDP, /* struct ovs_key_udp */
242 OVS_KEY_ATTR_ICMP, /* struct ovs_key_icmp */
243 OVS_KEY_ATTR_ICMPV6, /* struct ovs_key_icmpv6 */
244 OVS_KEY_ATTR_ARP, /* struct ovs_key_arp */
245 OVS_KEY_ATTR_ND, /* struct ovs_key_nd */
246 __OVS_KEY_ATTR_MAX
247};
248
249#define OVS_KEY_ATTR_MAX (__OVS_KEY_ATTR_MAX - 1)
250
251/**
252 * enum ovs_frag_type - IPv4 and IPv6 fragment type
253 * @OVS_FRAG_TYPE_NONE: Packet is not a fragment.
254 * @OVS_FRAG_TYPE_FIRST: Packet is a fragment with offset 0.
255 * @OVS_FRAG_TYPE_LATER: Packet is a fragment with nonzero offset.
256 *
257 * Used as the @ipv4_frag in &struct ovs_key_ipv4 and as @ipv6_frag &struct
258 * ovs_key_ipv6.
259 */
260enum ovs_frag_type {
261 OVS_FRAG_TYPE_NONE,
262 OVS_FRAG_TYPE_FIRST,
263 OVS_FRAG_TYPE_LATER,
264 __OVS_FRAG_TYPE_MAX
265};
266
267#define OVS_FRAG_TYPE_MAX (__OVS_FRAG_TYPE_MAX - 1)
268
269struct ovs_key_ethernet {
270 __u8 eth_src[6];
271 __u8 eth_dst[6];
272};
273
274struct ovs_key_ipv4 {
275 __be32 ipv4_src;
276 __be32 ipv4_dst;
277 __u8 ipv4_proto;
278 __u8 ipv4_tos;
279 __u8 ipv4_ttl;
280 __u8 ipv4_frag; /* One of OVS_FRAG_TYPE_*. */
281};
282
283struct ovs_key_ipv6 {
284 __be32 ipv6_src[4];
285 __be32 ipv6_dst[4];
286 __be32 ipv6_label; /* 20-bits in least-significant bits. */
287 __u8 ipv6_proto;
288 __u8 ipv6_tclass;
289 __u8 ipv6_hlimit;
290 __u8 ipv6_frag; /* One of OVS_FRAG_TYPE_*. */
291};
292
293struct ovs_key_tcp {
294 __be16 tcp_src;
295 __be16 tcp_dst;
296};
297
298struct ovs_key_udp {
299 __be16 udp_src;
300 __be16 udp_dst;
301};
302
303struct ovs_key_icmp {
304 __u8 icmp_type;
305 __u8 icmp_code;
306};
307
308struct ovs_key_icmpv6 {
309 __u8 icmpv6_type;
310 __u8 icmpv6_code;
311};
312
313struct ovs_key_arp {
314 __be32 arp_sip;
315 __be32 arp_tip;
316 __be16 arp_op;
317 __u8 arp_sha[6];
318 __u8 arp_tha[6];
319};
320
321struct ovs_key_nd {
322 __u32 nd_target[4];
323 __u8 nd_sll[6];
324 __u8 nd_tll[6];
325};
326
327/**
328 * enum ovs_flow_attr - attributes for %OVS_FLOW_* commands.
329 * @OVS_FLOW_ATTR_KEY: Nested %OVS_KEY_ATTR_* attributes specifying the flow
330 * key. Always present in notifications. Required for all requests (except
331 * dumps).
332 * @OVS_FLOW_ATTR_ACTIONS: Nested %OVS_ACTION_ATTR_* attributes specifying
333 * the actions to take for packets that match the key. Always present in
334 * notifications. Required for %OVS_FLOW_CMD_NEW requests, optional for
335 * %OVS_FLOW_CMD_SET requests.
336 * @OVS_FLOW_ATTR_STATS: &struct ovs_flow_stats giving statistics for this
337 * flow. Present in notifications if the stats would be nonzero. Ignored in
338 * requests.
339 * @OVS_FLOW_ATTR_TCP_FLAGS: An 8-bit value giving the OR'd value of all of the
340 * TCP flags seen on packets in this flow. Only present in notifications for
341 * TCP flows, and only if it would be nonzero. Ignored in requests.
342 * @OVS_FLOW_ATTR_USED: A 64-bit integer giving the time, in milliseconds on
343 * the system monotonic clock, at which a packet was last processed for this
344 * flow. Only present in notifications if a packet has been processed for this
345 * flow. Ignored in requests.
346 * @OVS_FLOW_ATTR_CLEAR: If present in a %OVS_FLOW_CMD_SET request, clears the
347 * last-used time, accumulated TCP flags, and statistics for this flow.
348 * Otherwise ignored in requests. Never present in notifications.
349 *
350 * These attributes follow the &struct ovs_header within the Generic Netlink
351 * payload for %OVS_FLOW_* commands.
352 */
353enum ovs_flow_attr {
354 OVS_FLOW_ATTR_UNSPEC,
355 OVS_FLOW_ATTR_KEY, /* Sequence of OVS_KEY_ATTR_* attributes. */
356 OVS_FLOW_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
357 OVS_FLOW_ATTR_STATS, /* struct ovs_flow_stats. */
358 OVS_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
359 OVS_FLOW_ATTR_USED, /* u64 msecs last used in monotonic time. */
360 OVS_FLOW_ATTR_CLEAR, /* Flag to clear stats, tcp_flags, used. */
361 __OVS_FLOW_ATTR_MAX
362};
363
364#define OVS_FLOW_ATTR_MAX (__OVS_FLOW_ATTR_MAX - 1)
365
366/**
367 * enum ovs_sample_attr - Attributes for %OVS_ACTION_ATTR_SAMPLE action.
368 * @OVS_SAMPLE_ATTR_PROBABILITY: 32-bit fraction of packets to sample with
369 * @OVS_ACTION_ATTR_SAMPLE. A value of 0 samples no packets, a value of
370 * %UINT32_MAX samples all packets and intermediate values sample intermediate
371 * fractions of packets.
372 * @OVS_SAMPLE_ATTR_ACTIONS: Set of actions to execute in sampling event.
373 * Actions are passed as nested attributes.
374 *
375 * Executes the specified actions with the given probability on a per-packet
376 * basis.
377 */
378enum ovs_sample_attr {
379 OVS_SAMPLE_ATTR_UNSPEC,
380 OVS_SAMPLE_ATTR_PROBABILITY, /* u32 number */
381 OVS_SAMPLE_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
382 __OVS_SAMPLE_ATTR_MAX,
383};
384
385#define OVS_SAMPLE_ATTR_MAX (__OVS_SAMPLE_ATTR_MAX - 1)
386
387/**
388 * enum ovs_userspace_attr - Attributes for %OVS_ACTION_ATTR_USERSPACE action.
389 * @OVS_USERSPACE_ATTR_PID: u32 Netlink PID to which the %OVS_PACKET_CMD_ACTION
390 * message should be sent. Required.
391 * @OVS_USERSPACE_ATTR_USERDATA: If present, its u64 argument is copied to the
392 * %OVS_PACKET_CMD_ACTION message as %OVS_PACKET_ATTR_USERDATA,
393 */
394enum ovs_userspace_attr {
395 OVS_USERSPACE_ATTR_UNSPEC,
396 OVS_USERSPACE_ATTR_PID, /* u32 Netlink PID to receive upcalls. */
397 OVS_USERSPACE_ATTR_USERDATA, /* u64 optional user-specified cookie. */
398 __OVS_USERSPACE_ATTR_MAX
399};
400
401#define OVS_USERSPACE_ATTR_MAX (__OVS_USERSPACE_ATTR_MAX - 1)
402
403/**
404 * struct ovs_action_push_vlan - %OVS_ACTION_ATTR_PUSH_VLAN action argument.
405 * @vlan_tpid: Tag protocol identifier (TPID) to push.
406 * @vlan_tci: Tag control identifier (TCI) to push. The CFI bit must be set
407 * (but it will not be set in the 802.1Q header that is pushed).
408 *
409 * The @vlan_tpid value is typically %ETH_P_8021Q. The only acceptable TPID
410 * values are those that the kernel module also parses as 802.1Q headers, to
411 * prevent %OVS_ACTION_ATTR_PUSH_VLAN followed by %OVS_ACTION_ATTR_POP_VLAN
412 * from having surprising results.
413 */
414struct ovs_action_push_vlan {
415 __be16 vlan_tpid; /* 802.1Q TPID. */
416 __be16 vlan_tci; /* 802.1Q TCI (VLAN ID and priority). */
417};
418
419/**
420 * enum ovs_action_attr - Action types.
421 *
422 * @OVS_ACTION_ATTR_OUTPUT: Output packet to port.
423 * @OVS_ACTION_ATTR_USERSPACE: Send packet to userspace according to nested
424 * %OVS_USERSPACE_ATTR_* attributes.
425 * @OVS_ACTION_ATTR_SET: Replaces the contents of an existing header. The
426 * single nested %OVS_KEY_ATTR_* attribute specifies a header to modify and its
427 * value.
428 * @OVS_ACTION_ATTR_PUSH_VLAN: Push a new outermost 802.1Q header onto the
429 * packet.
430 * @OVS_ACTION_ATTR_POP_VLAN: Pop the outermost 802.1Q header off the packet.
431 * @OVS_ACTION_ATTR_SAMPLE: Probabilitically executes actions, as specified in
432 * the nested %OVS_SAMPLE_ATTR_* attributes.
433 *
434 * Only a single header can be set with a single %OVS_ACTION_ATTR_SET. Not all
435 * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
436 * type may not be changed.
437 */
438
439enum ovs_action_attr {
440 OVS_ACTION_ATTR_UNSPEC,
441 OVS_ACTION_ATTR_OUTPUT, /* u32 port number. */
442 OVS_ACTION_ATTR_USERSPACE, /* Nested OVS_USERSPACE_ATTR_*. */
443 OVS_ACTION_ATTR_SET, /* One nested OVS_KEY_ATTR_*. */
444 OVS_ACTION_ATTR_PUSH_VLAN, /* struct ovs_action_push_vlan. */
445 OVS_ACTION_ATTR_POP_VLAN, /* No argument. */
446 OVS_ACTION_ATTR_SAMPLE, /* Nested OVS_SAMPLE_ATTR_*. */
447 __OVS_ACTION_ATTR_MAX
448};
449
450#define OVS_ACTION_ATTR_MAX (__OVS_ACTION_ATTR_MAX - 1)
451
452#endif /* _LINUX_OPENVSWITCH_H */