Merge citrix branch into master.
[sliver-openvswitch.git] / include / openvswitch / datapath-protocol.h
1 /*
2  * Copyright (c) 2009 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 #ifndef OPENVSWITCH_DATAPATH_PROTOCOL_H
43 #define OPENVSWITCH_DATAPATH_PROTOCOL_H 1
44
45 #ifdef __KERNEL__
46 #include <linux/types.h>
47 #else
48 #include <sys/types.h>
49 #endif
50 #include <linux/if_ether.h>
51
52 #define ODP_MAX 256             /* Maximum number of datapaths. */
53
54 #define ODP_DP_CREATE           _IO('O', 0)
55 #define ODP_DP_DESTROY          _IO('O', 1)
56 #define ODP_DP_STATS            _IOW('O', 2, struct odp_stats)
57
58 #define ODP_GET_DROP_FRAGS      _IOW('O', 3, int)
59 #define ODP_SET_DROP_FRAGS      _IOR('O', 4, int)
60
61 #define ODP_GET_LISTEN_MASK     _IOW('O', 5, int)
62 #define ODP_SET_LISTEN_MASK     _IOR('O', 6, int)
63
64 #define ODP_PORT_ADD            _IOR('O', 7, struct odp_port)
65 #define ODP_PORT_DEL            _IOR('O', 8, int)
66 #define ODP_PORT_QUERY          _IOWR('O', 9, struct odp_port)
67 #define ODP_PORT_LIST           _IOWR('O', 10, struct odp_portvec)
68
69 #define ODP_PORT_GROUP_SET      _IOR('O', 11, struct odp_port_group)
70 #define ODP_PORT_GROUP_GET      _IOWR('O', 12, struct odp_port_group)
71
72 #define ODP_FLOW_GET            _IOWR('O', 13, struct odp_flow)
73 #define ODP_FLOW_PUT            _IOWR('O', 14, struct odp_flow)
74 #define ODP_FLOW_LIST           _IOWR('O', 15, struct odp_flowvec)
75 #define ODP_FLOW_FLUSH          _IO('O', 16)
76 #define ODP_FLOW_DEL            _IOWR('O', 17, struct odp_flow)
77
78 #define ODP_EXECUTE             _IOR('O', 18, struct odp_execute)
79
80 struct odp_stats {
81     /* Flows. */
82     __u32 n_flows;              /* Number of flows in flow table. */
83     __u32 cur_capacity;         /* Current flow table capacity. */
84     __u32 max_capacity;         /* Maximum expansion of flow table capacity. */
85
86     /* Ports. */
87     __u32 n_ports;              /* Current number of ports. */
88     __u32 max_ports;            /* Maximum supported number of ports. */
89     __u16 max_groups;           /* Maximum number of port groups. */
90     __u16 reserved;
91
92     /* Lookups. */
93     __u64 n_frags;               /* Number of dropped IP fragments. */
94     __u64 n_hit;                 /* Number of flow table matches. */
95     __u64 n_missed;              /* Number of flow table misses. */
96     __u64 n_lost;                /* Number of misses not sent to userspace. */
97
98     /* Queues. */
99     __u16 max_miss_queue;       /* Max length of ODPL_MISS queue. */
100     __u16 max_action_queue;     /* Max length of ODPL_ACTION queue. */
101 };
102
103 /* Logical ports. */
104 #define ODPP_LOCAL      ((__u16)0)
105 #define ODPP_NONE       ((__u16)-1)
106
107 /* Listening channels. */
108 #define _ODPL_MISS_NR   0       /* Packet missed in flow table. */
109 #define ODPL_MISS       (1 << _ODPL_MISS_NR)
110 #define _ODPL_ACTION_NR 1       /* Packet output to ODPP_CONTROLLER. */
111 #define ODPL_ACTION     (1 << _ODPL_ACTION_NR)
112 #define ODPL_ALL        (ODPL_MISS | ODPL_ACTION)
113
114 /* Format of messages read from datapath fd. */
115 struct odp_msg {
116     __u32 type;                 /* _ODPL_MISS_NR or _ODPL_ACTION_NR. */
117     __u32 length;               /* Message length, including header. */
118     __u16 port;                 /* Port on which frame was received. */
119     __u16 reserved;
120     __u32 arg;                  /* Argument value specified in action. */
121     /* Followed by packet data. */
122 };
123
124 #define ODP_PORT_INTERNAL (1 << 0) /* This port is simulated. */
125 struct odp_port {
126     char devname[16];           /* IFNAMSIZ */
127     __u16 port;
128     __u16 flags;
129     __u32 reserved2;
130 };
131
132 struct odp_portvec {
133     struct odp_port *ports;
134     int n_ports;
135 };
136
137 struct odp_port_group {
138     __u16 *ports;
139     __u16 n_ports;                /* Number of ports. */
140     __u16 group;                  /* Group number. */
141 };
142
143 struct odp_flow_stats {
144     __u64 n_packets;            /* Number of matched packets. */
145     __u64 n_bytes;              /* Number of matched bytes. */
146     __u64 used_sec;             /* Time last used. */
147     __u32 used_nsec;
148     __u8 tcp_flags;
149     __u8 ip_tos;
150     __u16 error;                /* Used by ODP_FLOW_GET. */
151 };
152
153 struct odp_flow_key {
154     __be32 nw_src;               /* IP source address. */
155     __be32 nw_dst;               /* IP destination address. */
156     __u16  in_port;              /* Input switch port. */
157     __be16 dl_vlan;              /* Input VLAN. */
158     __be16 dl_type;              /* Ethernet frame type. */
159     __be16 tp_src;               /* TCP/UDP source port. */
160     __be16 tp_dst;               /* TCP/UDP destination port. */
161     __u8   dl_src[ETH_ALEN];     /* Ethernet source address. */
162     __u8   dl_dst[ETH_ALEN];     /* Ethernet destination address. */
163     __u8   nw_proto;             /* IP protocol or lower 8 bits of 
164                                     ARP opcode. */
165     __u8   reserved;             /* Pad to 64 bits. */
166 };
167
168 struct odp_flow {
169     struct odp_flow_stats stats;
170     struct odp_flow_key key;
171     union odp_action *actions;
172     __u32 n_actions;
173 };
174
175 /* Flags for ODP_FLOW_PUT. */
176 #define ODPPF_CREATE        (1 << 0) /* Allow creating a new flow. */
177 #define ODPPF_MODIFY        (1 << 1) /* Allow modifying an existing flow. */
178 #define ODPPF_ZERO_STATS    (1 << 2) /* Zero the stats of an existing flow. */
179
180 /* ODP_FLOW_PUT argument. */
181 struct odp_flow_put {
182     struct odp_flow flow;
183     __u32 flags;
184 };
185
186 struct odp_flowvec {
187     struct odp_flow *flows;
188     int n_flows;
189 };
190
191 /* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
192  * special conditions.  All ones is used to match that no VLAN id was
193  * set. */
194 #define ODP_VLAN_NONE      0xffff
195
196 /* Action types. */
197 #define ODPAT_OUTPUT            0    /* Output to switch port. */
198 #define ODPAT_OUTPUT_GROUP      1    /* Output to all ports in group. */
199 #define ODPAT_CONTROLLER        2    /* Send copy to controller. */
200 #define ODPAT_SET_VLAN_VID      3    /* Set the 802.1q VLAN id. */
201 #define ODPAT_SET_VLAN_PCP      4    /* Set the 802.1q priority. */
202 #define ODPAT_STRIP_VLAN        5    /* Strip the 802.1q header. */
203 #define ODPAT_SET_DL_SRC        6    /* Ethernet source address. */
204 #define ODPAT_SET_DL_DST        7    /* Ethernet destination address. */
205 #define ODPAT_SET_NW_SRC        8    /* IP source address. */
206 #define ODPAT_SET_NW_DST        9    /* IP destination address. */
207 #define ODPAT_SET_TP_SRC        10   /* TCP/UDP source port. */
208 #define ODPAT_SET_TP_DST        11   /* TCP/UDP destination port. */
209 #define ODPAT_N_ACTIONS         12
210
211 struct odp_action_output {
212     __u16 type;                  /* ODPAT_OUTPUT. */
213     __u16 port;                  /* Output port. */
214     __u16 reserved1;
215     __u16 reserved2;
216 };
217
218 struct odp_action_output_group {
219     __u16 type;                 /* ODPAT_OUTPUT_GROUP. */
220     __u16 group;                /* Group number. */
221     __u16 reserved1;
222     __u16 reserved2;
223 };
224
225 struct odp_action_controller {
226     __u16 type;                 /* ODPAT_OUTPUT_CONTROLLER. */
227     __u16 reserved;
228     __u32 arg;                  /* Copied to struct odp_msg 'arg' member. */
229 };
230
231 /* Action structure for ODPAT_SET_VLAN_VID. */
232 struct odp_action_vlan_vid {
233     __u16 type;                  /* ODPAT_SET_VLAN_VID. */
234     __be16 vlan_vid;             /* VLAN id. */
235     __u16 reserved1;
236     __u16 reserved2;
237 };
238
239 /* Action structure for ODPAT_SET_VLAN_PCP. */
240 struct odp_action_vlan_pcp {
241     __u16 type;                  /* ODPAT_SET_VLAN_PCP. */
242     __u8 vlan_pcp;               /* VLAN priority. */
243     __u8 reserved1;
244     __u16 reserved2;
245     __u16 reserved3;
246 };
247
248 /* Action structure for ODPAT_SET_DL_SRC/DST. */
249 struct odp_action_dl_addr {
250     __u16 type;                  /* ODPAT_SET_DL_SRC/DST. */
251     __u8 dl_addr[ETH_ALEN];      /* Ethernet address. */
252 };
253
254 /* Action structure for ODPAT_SET_NW_SRC/DST. */
255 struct odp_action_nw_addr {
256     __u16 type;                 /* ODPAT_SET_TW_SRC/DST. */
257     __u16 reserved;
258     __be32 nw_addr;             /* IP address. */
259 };
260
261 /* Action structure for ODPAT_SET_TP_SRC/DST. */
262 struct odp_action_tp_port {
263     __u16 type;                  /* ODPAT_SET_TP_SRC/DST. */
264     __be16 tp_port;              /* TCP/UDP port. */
265     __u16 reserved1;
266     __u16 reserved2;
267 };
268
269 union odp_action {
270     __u16 type;
271     struct odp_action_output output;
272     struct odp_action_output_group output_group;
273     struct odp_action_controller controller;
274     struct odp_action_vlan_vid vlan_vid;
275     struct odp_action_vlan_pcp vlan_pcp;
276     struct odp_action_dl_addr dl_addr;
277     struct odp_action_nw_addr nw_addr;
278     struct odp_action_tp_port tp_port;
279 };
280
281 struct odp_execute {
282     __u16 in_port;
283     __u16 reserved1;
284     __u32 reserved2;
285
286     union odp_action *actions;
287     __u32 n_actions;
288
289     const void *data;
290     __u32 length;
291 };
292
293 /* Values below this cutoff are 802.3 packets and the two bytes
294  * following MAC addresses are used as a frame length.  Otherwise, the
295  * two bytes are used as the Ethernet type.
296  */
297 #define ODP_DL_TYPE_ETH2_CUTOFF   0x0600
298
299 /* Value of dl_type to indicate that the frame does not include an
300  * Ethernet type.
301  */
302 #define ODP_DL_TYPE_NOT_ETH_TYPE  0x05ff
303
304 /* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
305  * special conditions.  All ones indicates that no VLAN id was set.
306  */
307 #define ODP_VLAN_NONE      0xffff
308
309 #endif /* openvswitch/datapath-protocol.h */