datapath: Add 32-bit compatibility ioctls.
[sliver-openvswitch.git] / include / openvswitch / datapath-protocol.h
1 /*
2  * Copyright (c) 2009, 2010 Nicira Networks.
3  *
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.
10  *
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  * ----------------------------------------------------------------------
38  */
39
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. */
44
45 #ifndef OPENVSWITCH_DATAPATH_PROTOCOL_H
46 #define OPENVSWITCH_DATAPATH_PROTOCOL_H 1
47
48 #ifdef __KERNEL__
49 #include <linux/types.h>
50 #else
51 #include <sys/types.h>
52 #endif
53 #include <linux/if_ether.h>
54
55 #define ODP_MAX 256             /* Maximum number of datapaths. */
56
57 #define ODP_DP_CREATE           _IO('O', 0)
58 #define ODP_DP_DESTROY          _IO('O', 1)
59 #define ODP_DP_STATS            _IOW('O', 2, struct odp_stats)
60
61 #define ODP_GET_DROP_FRAGS      _IOW('O', 3, int)
62 #define ODP_SET_DROP_FRAGS      _IOR('O', 4, int)
63
64 #define ODP_GET_LISTEN_MASK     _IOW('O', 5, int)
65 #define ODP_SET_LISTEN_MASK     _IOR('O', 6, int)
66
67 #define ODP_PORT_ATTACH         _IOR('O', 7, struct odp_port)
68 #define ODP_PORT_DETACH         _IOR('O', 8, int)
69 #define ODP_PORT_QUERY          _IOWR('O', 9, struct odp_port)
70 #define ODP_PORT_LIST           _IOWR('O', 10, struct odp_portvec)
71
72 #define ODP_PORT_GROUP_SET      _IOR('O', 11, struct odp_port_group)
73 #define ODP_PORT_GROUP_GET      _IOWR('O', 12, struct odp_port_group)
74
75 #define ODP_FLOW_GET            _IOWR('O', 13, struct odp_flow)
76 #define ODP_FLOW_PUT            _IOWR('O', 14, struct odp_flow)
77 #define ODP_FLOW_LIST           _IOWR('O', 15, struct odp_flowvec)
78 #define ODP_FLOW_FLUSH          _IO('O', 16)
79 #define ODP_FLOW_DEL            _IOWR('O', 17, struct odp_flow)
80
81 #define ODP_EXECUTE             _IOR('O', 18, struct odp_execute)
82
83 #define ODP_SET_SFLOW_PROBABILITY _IOR('O', 19, int)
84 #define ODP_GET_SFLOW_PROBABILITY _IOW('O', 20, int)
85
86 #define ODP_VPORT_ADD           _IOR('O', 21, struct odp_vport_add)
87 #define ODP_VPORT_MOD           _IOR('O', 22, struct odp_vport_mod)
88 #define ODP_VPORT_DEL           _IO('O', 23)
89 #define ODP_VPORT_STATS_GET     _IOWR('O', 24, struct odp_vport_stats_req)
90 #define ODP_VPORT_ETHER_GET     _IOWR('O', 25, struct odp_vport_ether)
91 #define ODP_VPORT_ETHER_SET     _IOW('O', 26, struct odp_vport_ether)
92 #define ODP_VPORT_MTU_GET       _IOWR('O', 27, struct odp_vport_mtu)
93 #define ODP_VPORT_MTU_SET       _IOW('O', 28, struct odp_vport_mtu)
94
95 struct odp_stats {
96     /* Flows. */
97     __u32 n_flows;              /* Number of flows in flow table. */
98     __u32 cur_capacity;         /* Current flow table capacity. */
99     __u32 max_capacity;         /* Maximum expansion of flow table capacity. */
100
101     /* Ports. */
102     __u32 n_ports;              /* Current number of ports. */
103     __u32 max_ports;            /* Maximum supported number of ports. */
104     __u16 max_groups;           /* Maximum number of port groups. */
105     __u16 reserved;
106
107     /* Lookups. */
108     __u64 n_frags;               /* Number of dropped IP fragments. */
109     __u64 n_hit;                 /* Number of flow table matches. */
110     __u64 n_missed;              /* Number of flow table misses. */
111     __u64 n_lost;                /* Number of misses not sent to userspace. */
112
113     /* Queues. */
114     __u16 max_miss_queue;       /* Max length of ODPL_MISS queue. */
115     __u16 max_action_queue;     /* Max length of ODPL_ACTION queue. */
116     __u16 max_sflow_queue;      /* Max length of ODPL_SFLOW queue. */
117 };
118
119 /* Logical ports. */
120 #define ODPP_LOCAL      ((__u16)0)
121 #define ODPP_NONE       ((__u16)-1)
122 #define ODPP_NORMAL     ((__u16)-2)
123
124 /* Listening channels. */
125 #define _ODPL_MISS_NR   0       /* Packet missed in flow table. */
126 #define ODPL_MISS       (1 << _ODPL_MISS_NR)
127 #define _ODPL_ACTION_NR 1       /* Packet output to ODPP_CONTROLLER. */
128 #define ODPL_ACTION     (1 << _ODPL_ACTION_NR)
129 #define _ODPL_SFLOW_NR  2       /* sFlow samples. */
130 #define ODPL_SFLOW      (1 << _ODPL_SFLOW_NR)
131 #define ODPL_ALL        (ODPL_MISS | ODPL_ACTION | ODPL_SFLOW)
132
133 /**
134  * struct odp_msg - format of messages read from datapath fd.
135  * @type: One of the %_ODPL_* constants.
136  * @length: Total length of message, including this header.
137  * @port: Port that received the packet embedded in this message.
138  * @reserved: Not currently used.  Should be set to 0.
139  * @arg: Argument value whose meaning depends on @type.
140  *
141  * For @type == %_ODPL_MISS_NR, the header is followed by packet data.  The
142  * @arg member is the ID (in network byte order) of the tunnel that
143  * encapsulated this packet. It is 0 if the packet was not received on a tunnel.
144  *
145  * For @type == %_ODPL_ACTION_NR, the header is followed by packet data.  The
146  * @arg member is copied from the &struct odp_action_controller that caused
147  * the &struct odp_msg to be composed.
148  *
149  * For @type == %_ODPL_SFLOW_NR, the header is followed by &struct
150  * odp_sflow_sample_header, then by an array of &union odp_action (the number
151  * of which is specified in &struct odp_sflow_sample_header), then by packet
152  * data.
153  */
154 struct odp_msg {
155     __u32 type;
156     __u32 length;
157     __u16 port;
158     __u16 reserved;
159     __u32 arg;
160 };
161
162 /**
163  * struct odp_sflow_sample_header - header added to sFlow sampled packet.
164  * @sample_pool: Number of packets that were candidates for sFlow sampling,
165  * regardless of whether they were actually chosen and sent down to userspace.
166  * @n_actions: Number of "union odp_action"s immediately following this header.
167  *
168  * This header follows &struct odp_msg when that structure's @type is
169  * %_ODPL_SFLOW_NR, and it is itself followed by an array of &union odp_action
170  * (the number of which is specified in @n_actions) and then by packet data.
171  */
172 struct odp_sflow_sample_header {
173     __u32 sample_pool;
174     __u32 n_actions;
175 };
176
177 #define ODP_PORT_INTERNAL (1 << 0) /* This port is simulated. */
178 struct odp_port {
179     char devname[16];           /* IFNAMSIZ */
180     __u16 port;
181     __u16 flags;
182     __u32 reserved2;
183 };
184
185 struct odp_portvec {
186     struct odp_port *ports;
187     __u32 n_ports;
188 };
189
190 struct odp_port_group {
191     __u16 *ports;
192     __u16 n_ports;                /* Number of ports. */
193     __u16 group;                  /* Group number. */
194 };
195
196 struct odp_flow_stats {
197     __u64 n_packets;            /* Number of matched packets. */
198     __u64 n_bytes;              /* Number of matched bytes. */
199     __u64 used_sec;             /* Time last used. */
200     __u32 used_nsec;
201     __u8 tcp_flags;
202     __u8 ip_tos;
203     __u16 error;                /* Used by ODP_FLOW_GET. */
204 };
205
206 struct odp_flow_key {
207     __be32 tun_id;               /* Encapsulating tunnel ID. */
208     __be32 nw_src;               /* IP source address. */
209     __be32 nw_dst;               /* IP destination address. */
210     __u16  in_port;              /* Input switch port. */
211     __be16 dl_vlan;              /* Input VLAN. */
212     __be16 dl_type;              /* Ethernet frame type. */
213     __be16 tp_src;               /* TCP/UDP source port. */
214     __be16 tp_dst;               /* TCP/UDP destination port. */
215     __u8   dl_src[ETH_ALEN];     /* Ethernet source address. */
216     __u8   dl_dst[ETH_ALEN];     /* Ethernet destination address. */
217     __u8   nw_proto;             /* IP protocol or lower 8 bits of 
218                                     ARP opcode. */
219     __u8   dl_vlan_pcp;          /* Input VLAN priority. */
220     __u8   nw_tos;               /* IP ToS (DSCP field, 6 bits). */
221     __u8   reserved[3];          /* Align to 32-bits...must be zeroed. */
222 };
223
224 /* Flags for ODP_FLOW. */
225 #define ODPFF_ZERO_TCP_FLAGS (1 << 0) /* Zero the TCP flags. */
226
227 struct odp_flow {
228     struct odp_flow_stats stats;
229     struct odp_flow_key key;
230     union odp_action *actions;
231     __u32 n_actions;
232     __u32 flags;
233 };
234
235 /* Flags for ODP_FLOW_PUT. */
236 #define ODPPF_CREATE        (1 << 0) /* Allow creating a new flow. */
237 #define ODPPF_MODIFY        (1 << 1) /* Allow modifying an existing flow. */
238 #define ODPPF_ZERO_STATS    (1 << 2) /* Zero the stats of an existing flow. */
239
240 /* ODP_FLOW_PUT argument. */
241 struct odp_flow_put {
242     struct odp_flow flow;
243     __u32 flags;
244 };
245
246 struct odp_flowvec {
247     struct odp_flow *flows;
248     __u32 n_flows;
249 };
250
251 /* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
252  * special conditions.  All ones is used to match that no VLAN id was
253  * set. */
254 #define ODP_VLAN_NONE      0xffff
255
256 /* Action types. */
257 #define ODPAT_OUTPUT            0    /* Output to switch port. */
258 #define ODPAT_OUTPUT_GROUP      1    /* Output to all ports in group. */
259 #define ODPAT_CONTROLLER        2    /* Send copy to controller. */
260 #define ODPAT_SET_VLAN_VID      3    /* Set the 802.1q VLAN id. */
261 #define ODPAT_SET_VLAN_PCP      4    /* Set the 802.1q priority. */
262 #define ODPAT_STRIP_VLAN        5    /* Strip the 802.1q header. */
263 #define ODPAT_SET_DL_SRC        6    /* Ethernet source address. */
264 #define ODPAT_SET_DL_DST        7    /* Ethernet destination address. */
265 #define ODPAT_SET_NW_SRC        8    /* IP source address. */
266 #define ODPAT_SET_NW_DST        9    /* IP destination address. */
267 #define ODPAT_SET_NW_TOS        10   /* IP ToS/DSCP field (6 bits). */
268 #define ODPAT_SET_TP_SRC        11   /* TCP/UDP source port. */
269 #define ODPAT_SET_TP_DST        12   /* TCP/UDP destination port. */
270 #define ODPAT_SET_TUNNEL        13   /* Set the encapsulating tunnel ID. */
271 #define ODPAT_N_ACTIONS         14
272
273 struct odp_action_output {
274     __u16 type;                  /* ODPAT_OUTPUT. */
275     __u16 port;                  /* Output port. */
276     __u16 reserved1;
277     __u16 reserved2;
278 };
279
280 struct odp_action_output_group {
281     __u16 type;                 /* ODPAT_OUTPUT_GROUP. */
282     __u16 group;                /* Group number. */
283     __u16 reserved1;
284     __u16 reserved2;
285 };
286
287 struct odp_action_controller {
288     __u16 type;                 /* ODPAT_OUTPUT_CONTROLLER. */
289     __u16 reserved;
290     __u32 arg;                  /* Copied to struct odp_msg 'arg' member. */
291 };
292
293 struct odp_action_tunnel {
294     __u16 type;                 /* ODPAT_SET_TUNNEL. */
295     __u16 reserved;
296     __be32 tun_id;              /* Tunnel ID. */
297 };
298
299 /* Action structure for ODPAT_SET_VLAN_VID. */
300 struct odp_action_vlan_vid {
301     __u16 type;                  /* ODPAT_SET_VLAN_VID. */
302     __be16 vlan_vid;             /* VLAN id. */
303     __u16 reserved1;
304     __u16 reserved2;
305 };
306
307 /* Action structure for ODPAT_SET_VLAN_PCP. */
308 struct odp_action_vlan_pcp {
309     __u16 type;                  /* ODPAT_SET_VLAN_PCP. */
310     __u8 vlan_pcp;               /* VLAN priority. */
311     __u8 reserved1;
312     __u16 reserved2;
313     __u16 reserved3;
314 };
315
316 /* Action structure for ODPAT_SET_DL_SRC/DST. */
317 struct odp_action_dl_addr {
318     __u16 type;                  /* ODPAT_SET_DL_SRC/DST. */
319     __u8 dl_addr[ETH_ALEN];      /* Ethernet address. */
320 };
321
322 /* Action structure for ODPAT_SET_NW_SRC/DST. */
323 struct odp_action_nw_addr {
324     __u16 type;                 /* ODPAT_SET_TW_SRC/DST. */
325     __u16 reserved;
326     __be32 nw_addr;             /* IP address. */
327 };
328
329 struct odp_action_nw_tos {
330     __u16 type;                  /* ODPAT_SET_NW_TOS. */
331     __u8 nw_tos;                 /* IP ToS/DSCP field (6 bits). */
332     __u8 reserved1;
333     __u16 reserved2;
334     __u16 reserved3;
335 };
336
337 /* Action structure for ODPAT_SET_TP_SRC/DST. */
338 struct odp_action_tp_port {
339     __u16 type;                  /* ODPAT_SET_TP_SRC/DST. */
340     __be16 tp_port;              /* TCP/UDP port. */
341     __u16 reserved1;
342     __u16 reserved2;
343 };
344
345 union odp_action {
346     __u16 type;
347     struct odp_action_output output;
348     struct odp_action_output_group output_group;
349     struct odp_action_controller controller;
350     struct odp_action_tunnel tunnel;
351     struct odp_action_vlan_vid vlan_vid;
352     struct odp_action_vlan_pcp vlan_pcp;
353     struct odp_action_dl_addr dl_addr;
354     struct odp_action_nw_addr nw_addr;
355     struct odp_action_nw_tos nw_tos;
356     struct odp_action_tp_port tp_port;
357 };
358
359 struct odp_execute {
360     __u16 in_port;
361     __u16 reserved1;
362     __u32 reserved2;
363
364     union odp_action *actions;
365     __u32 n_actions;
366
367     const void *data;
368     __u32 length;
369 };
370
371 #define VPORT_TYPE_SIZE     16
372 struct odp_vport_add {
373     char port_type[VPORT_TYPE_SIZE];
374     char devname[16];            /* IFNAMSIZ */
375     void *config;
376 };
377
378 struct odp_vport_mod {
379     char devname[16];            /* IFNAMSIZ */
380     void *config;
381 };
382
383 struct odp_vport_stats {
384     __u64 rx_packets;
385     __u64 tx_packets;
386     __u64 rx_bytes;
387     __u64 tx_bytes;
388     __u64 rx_dropped;
389     __u64 tx_dropped;
390     __u64 rx_errors;
391     __u64 tx_errors;
392     __u64 rx_frame_err;
393     __u64 rx_over_err;
394     __u64 rx_crc_err;
395     __u64 collisions;
396 };
397
398 struct odp_vport_stats_req {
399     char devname[16];            /* IFNAMSIZ */
400     struct odp_vport_stats stats;
401 };
402
403 struct odp_vport_ether {
404     char devname[16];            /* IFNAMSIZ */
405     unsigned char ether_addr[ETH_ALEN];
406 };
407
408 struct odp_vport_mtu {
409     char devname[16];            /* IFNAMSIZ */
410     __u16 mtu;
411 };
412
413 /* Values below this cutoff are 802.3 packets and the two bytes
414  * following MAC addresses are used as a frame length.  Otherwise, the
415  * two bytes are used as the Ethernet type.
416  */
417 #define ODP_DL_TYPE_ETH2_CUTOFF   0x0600
418
419 /* Value of dl_type to indicate that the frame does not include an
420  * Ethernet type.
421  */
422 #define ODP_DL_TYPE_NOT_ETH_TYPE  0x05ff
423
424 /* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
425  * special conditions.  All ones indicates that no VLAN id was set.
426  */
427 #define ODP_VLAN_NONE      0xffff
428
429 #endif /* openvswitch/datapath-protocol.h */