xref: /openbmc/linux/include/linux/openvswitch.h (revision d0b73b48)
1 /*
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 
33 struct 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 
43 enum 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  */
68 enum 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 
78 struct 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 
85 struct 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 
104 enum 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  */
135 enum 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 
152 enum 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 
160 enum 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  */
198 enum 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 
217 enum 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 
225 struct ovs_flow_stats {
226 	__u64 n_packets;         /* Number of matched packets. */
227 	__u64 n_bytes;           /* Number of matched bytes. */
228 };
229 
230 enum 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_SKB_MARK,  /* u32 skb mark */
247 	__OVS_KEY_ATTR_MAX
248 };
249 
250 #define OVS_KEY_ATTR_MAX (__OVS_KEY_ATTR_MAX - 1)
251 
252 /**
253  * enum ovs_frag_type - IPv4 and IPv6 fragment type
254  * @OVS_FRAG_TYPE_NONE: Packet is not a fragment.
255  * @OVS_FRAG_TYPE_FIRST: Packet is a fragment with offset 0.
256  * @OVS_FRAG_TYPE_LATER: Packet is a fragment with nonzero offset.
257  *
258  * Used as the @ipv4_frag in &struct ovs_key_ipv4 and as @ipv6_frag &struct
259  * ovs_key_ipv6.
260  */
261 enum ovs_frag_type {
262 	OVS_FRAG_TYPE_NONE,
263 	OVS_FRAG_TYPE_FIRST,
264 	OVS_FRAG_TYPE_LATER,
265 	__OVS_FRAG_TYPE_MAX
266 };
267 
268 #define OVS_FRAG_TYPE_MAX (__OVS_FRAG_TYPE_MAX - 1)
269 
270 struct ovs_key_ethernet {
271 	__u8	 eth_src[6];
272 	__u8	 eth_dst[6];
273 };
274 
275 struct ovs_key_ipv4 {
276 	__be32 ipv4_src;
277 	__be32 ipv4_dst;
278 	__u8   ipv4_proto;
279 	__u8   ipv4_tos;
280 	__u8   ipv4_ttl;
281 	__u8   ipv4_frag;	/* One of OVS_FRAG_TYPE_*. */
282 };
283 
284 struct ovs_key_ipv6 {
285 	__be32 ipv6_src[4];
286 	__be32 ipv6_dst[4];
287 	__be32 ipv6_label;	/* 20-bits in least-significant bits. */
288 	__u8   ipv6_proto;
289 	__u8   ipv6_tclass;
290 	__u8   ipv6_hlimit;
291 	__u8   ipv6_frag;	/* One of OVS_FRAG_TYPE_*. */
292 };
293 
294 struct ovs_key_tcp {
295 	__be16 tcp_src;
296 	__be16 tcp_dst;
297 };
298 
299 struct ovs_key_udp {
300 	__be16 udp_src;
301 	__be16 udp_dst;
302 };
303 
304 struct ovs_key_icmp {
305 	__u8 icmp_type;
306 	__u8 icmp_code;
307 };
308 
309 struct ovs_key_icmpv6 {
310 	__u8 icmpv6_type;
311 	__u8 icmpv6_code;
312 };
313 
314 struct ovs_key_arp {
315 	__be32 arp_sip;
316 	__be32 arp_tip;
317 	__be16 arp_op;
318 	__u8   arp_sha[6];
319 	__u8   arp_tha[6];
320 };
321 
322 struct ovs_key_nd {
323 	__u32 nd_target[4];
324 	__u8  nd_sll[6];
325 	__u8  nd_tll[6];
326 };
327 
328 /**
329  * enum ovs_flow_attr - attributes for %OVS_FLOW_* commands.
330  * @OVS_FLOW_ATTR_KEY: Nested %OVS_KEY_ATTR_* attributes specifying the flow
331  * key.  Always present in notifications.  Required for all requests (except
332  * dumps).
333  * @OVS_FLOW_ATTR_ACTIONS: Nested %OVS_ACTION_ATTR_* attributes specifying
334  * the actions to take for packets that match the key.  Always present in
335  * notifications.  Required for %OVS_FLOW_CMD_NEW requests, optional for
336  * %OVS_FLOW_CMD_SET requests.
337  * @OVS_FLOW_ATTR_STATS: &struct ovs_flow_stats giving statistics for this
338  * flow.  Present in notifications if the stats would be nonzero.  Ignored in
339  * requests.
340  * @OVS_FLOW_ATTR_TCP_FLAGS: An 8-bit value giving the OR'd value of all of the
341  * TCP flags seen on packets in this flow.  Only present in notifications for
342  * TCP flows, and only if it would be nonzero.  Ignored in requests.
343  * @OVS_FLOW_ATTR_USED: A 64-bit integer giving the time, in milliseconds on
344  * the system monotonic clock, at which a packet was last processed for this
345  * flow.  Only present in notifications if a packet has been processed for this
346  * flow.  Ignored in requests.
347  * @OVS_FLOW_ATTR_CLEAR: If present in a %OVS_FLOW_CMD_SET request, clears the
348  * last-used time, accumulated TCP flags, and statistics for this flow.
349  * Otherwise ignored in requests.  Never present in notifications.
350  *
351  * These attributes follow the &struct ovs_header within the Generic Netlink
352  * payload for %OVS_FLOW_* commands.
353  */
354 enum ovs_flow_attr {
355 	OVS_FLOW_ATTR_UNSPEC,
356 	OVS_FLOW_ATTR_KEY,       /* Sequence of OVS_KEY_ATTR_* attributes. */
357 	OVS_FLOW_ATTR_ACTIONS,   /* Nested OVS_ACTION_ATTR_* attributes. */
358 	OVS_FLOW_ATTR_STATS,     /* struct ovs_flow_stats. */
359 	OVS_FLOW_ATTR_TCP_FLAGS, /* 8-bit OR'd TCP flags. */
360 	OVS_FLOW_ATTR_USED,      /* u64 msecs last used in monotonic time. */
361 	OVS_FLOW_ATTR_CLEAR,     /* Flag to clear stats, tcp_flags, used. */
362 	__OVS_FLOW_ATTR_MAX
363 };
364 
365 #define OVS_FLOW_ATTR_MAX (__OVS_FLOW_ATTR_MAX - 1)
366 
367 /**
368  * enum ovs_sample_attr - Attributes for %OVS_ACTION_ATTR_SAMPLE action.
369  * @OVS_SAMPLE_ATTR_PROBABILITY: 32-bit fraction of packets to sample with
370  * @OVS_ACTION_ATTR_SAMPLE.  A value of 0 samples no packets, a value of
371  * %UINT32_MAX samples all packets and intermediate values sample intermediate
372  * fractions of packets.
373  * @OVS_SAMPLE_ATTR_ACTIONS: Set of actions to execute in sampling event.
374  * Actions are passed as nested attributes.
375  *
376  * Executes the specified actions with the given probability on a per-packet
377  * basis.
378  */
379 enum ovs_sample_attr {
380 	OVS_SAMPLE_ATTR_UNSPEC,
381 	OVS_SAMPLE_ATTR_PROBABILITY, /* u32 number */
382 	OVS_SAMPLE_ATTR_ACTIONS,     /* Nested OVS_ACTION_ATTR_* attributes. */
383 	__OVS_SAMPLE_ATTR_MAX,
384 };
385 
386 #define OVS_SAMPLE_ATTR_MAX (__OVS_SAMPLE_ATTR_MAX - 1)
387 
388 /**
389  * enum ovs_userspace_attr - Attributes for %OVS_ACTION_ATTR_USERSPACE action.
390  * @OVS_USERSPACE_ATTR_PID: u32 Netlink PID to which the %OVS_PACKET_CMD_ACTION
391  * message should be sent.  Required.
392  * @OVS_USERSPACE_ATTR_USERDATA: If present, its u64 argument is copied to the
393  * %OVS_PACKET_CMD_ACTION message as %OVS_PACKET_ATTR_USERDATA,
394  */
395 enum ovs_userspace_attr {
396 	OVS_USERSPACE_ATTR_UNSPEC,
397 	OVS_USERSPACE_ATTR_PID,	      /* u32 Netlink PID to receive upcalls. */
398 	OVS_USERSPACE_ATTR_USERDATA,  /* u64 optional user-specified cookie. */
399 	__OVS_USERSPACE_ATTR_MAX
400 };
401 
402 #define OVS_USERSPACE_ATTR_MAX (__OVS_USERSPACE_ATTR_MAX - 1)
403 
404 /**
405  * struct ovs_action_push_vlan - %OVS_ACTION_ATTR_PUSH_VLAN action argument.
406  * @vlan_tpid: Tag protocol identifier (TPID) to push.
407  * @vlan_tci: Tag control identifier (TCI) to push.  The CFI bit must be set
408  * (but it will not be set in the 802.1Q header that is pushed).
409  *
410  * The @vlan_tpid value is typically %ETH_P_8021Q.  The only acceptable TPID
411  * values are those that the kernel module also parses as 802.1Q headers, to
412  * prevent %OVS_ACTION_ATTR_PUSH_VLAN followed by %OVS_ACTION_ATTR_POP_VLAN
413  * from having surprising results.
414  */
415 struct ovs_action_push_vlan {
416 	__be16 vlan_tpid;	/* 802.1Q TPID. */
417 	__be16 vlan_tci;	/* 802.1Q TCI (VLAN ID and priority). */
418 };
419 
420 /**
421  * enum ovs_action_attr - Action types.
422  *
423  * @OVS_ACTION_ATTR_OUTPUT: Output packet to port.
424  * @OVS_ACTION_ATTR_USERSPACE: Send packet to userspace according to nested
425  * %OVS_USERSPACE_ATTR_* attributes.
426  * @OVS_ACTION_ATTR_SET: Replaces the contents of an existing header.  The
427  * single nested %OVS_KEY_ATTR_* attribute specifies a header to modify and its
428  * value.
429  * @OVS_ACTION_ATTR_PUSH_VLAN: Push a new outermost 802.1Q header onto the
430  * packet.
431  * @OVS_ACTION_ATTR_POP_VLAN: Pop the outermost 802.1Q header off the packet.
432  * @OVS_ACTION_ATTR_SAMPLE: Probabilitically executes actions, as specified in
433  * the nested %OVS_SAMPLE_ATTR_* attributes.
434  *
435  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
436  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
437  * type may not be changed.
438  */
439 
440 enum ovs_action_attr {
441 	OVS_ACTION_ATTR_UNSPEC,
442 	OVS_ACTION_ATTR_OUTPUT,	      /* u32 port number. */
443 	OVS_ACTION_ATTR_USERSPACE,    /* Nested OVS_USERSPACE_ATTR_*. */
444 	OVS_ACTION_ATTR_SET,          /* One nested OVS_KEY_ATTR_*. */
445 	OVS_ACTION_ATTR_PUSH_VLAN,    /* struct ovs_action_push_vlan. */
446 	OVS_ACTION_ATTR_POP_VLAN,     /* No argument. */
447 	OVS_ACTION_ATTR_SAMPLE,       /* Nested OVS_SAMPLE_ATTR_*. */
448 	__OVS_ACTION_ATTR_MAX
449 };
450 
451 #define OVS_ACTION_ATTR_MAX (__OVS_ACTION_ATTR_MAX - 1)
452 
453 #endif /* _LINUX_OPENVSWITCH_H */
454