]>
Commit | Line | Data |
---|---|---|
f25d0cf3 | 1 | /* |
bdcad671 | 2 | * Copyright (c) 2012, 2013, 2014, 2015, 2016 Nicira, Inc. |
f25d0cf3 BP |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | #ifndef OFP_ACTIONS_H | |
18 | #define OFP_ACTIONS_H 1 | |
19 | ||
7fdb60a7 | 20 | #include <stddef.h> |
f25d0cf3 BP |
21 | #include <stdint.h> |
22 | #include "meta-flow.h" | |
f25d0cf3 BP |
23 | #include "ofp-util.h" |
24 | #include "openflow/openflow.h" | |
25 | #include "openflow/nicira-ext.h" | |
e03c096d | 26 | #include "openvswitch/ofp-errors.h" |
f25d0cf3 BP |
27 | #include "openvswitch/types.h" |
28 | ||
29 | /* List of OVS abstracted actions. | |
30 | * | |
31 | * This macro is used directly only internally by this header, but the list is | |
32 | * still of interest to developers. | |
33 | * | |
08d1e234 | 34 | * Each OFPACT invocation has the following parameters: |
f25d0cf3 BP |
35 | * |
36 | * 1. <ENUM>, used below in the enum definition of OFPACT_<ENUM>, and | |
37 | * elsewhere. | |
38 | * | |
39 | * 2. <STRUCT> corresponding to a structure "struct <STRUCT>", that must be | |
40 | * defined below. This structure must be an abstract definition of the | |
41 | * action. Its first member must have type "struct ofpact" and name | |
42 | * "ofpact". It may be fixed length or end with a flexible array member | |
43 | * (e.g. "int member[];"). | |
44 | * | |
45 | * 3. <MEMBER>, which has one of two possible values: | |
46 | * | |
47 | * - If "struct <STRUCT>" is fixed-length, it must be "ofpact". | |
48 | * | |
49 | * - If "struct <STRUCT>" is variable-length, it must be the name of the | |
50 | * flexible array member. | |
08d1e234 BP |
51 | * |
52 | * 4. <NAME>, a quoted string that gives the name of the action, for use in | |
53 | * parsing actions from text. | |
f25d0cf3 | 54 | */ |
08d1e234 BP |
55 | #define OFPACTS \ |
56 | /* Output. */ \ | |
57 | OFPACT(OUTPUT, ofpact_output, ofpact, "output") \ | |
58 | OFPACT(GROUP, ofpact_group, ofpact, "group") \ | |
bdcad671 | 59 | OFPACT(CONTROLLER, ofpact_controller, userdata, "controller") \ |
08d1e234 BP |
60 | OFPACT(ENQUEUE, ofpact_enqueue, ofpact, "enqueue") \ |
61 | OFPACT(OUTPUT_REG, ofpact_output_reg, ofpact, "output_reg") \ | |
62 | OFPACT(BUNDLE, ofpact_bundle, slaves, "bundle") \ | |
63 | \ | |
64 | /* Header changes. */ \ | |
65 | OFPACT(SET_FIELD, ofpact_set_field, ofpact, "set_field") \ | |
66 | OFPACT(SET_VLAN_VID, ofpact_vlan_vid, ofpact, "set_vlan_vid") \ | |
67 | OFPACT(SET_VLAN_PCP, ofpact_vlan_pcp, ofpact, "set_vlan_pcp") \ | |
68 | OFPACT(STRIP_VLAN, ofpact_null, ofpact, "strip_vlan") \ | |
69 | OFPACT(PUSH_VLAN, ofpact_null, ofpact, "push_vlan") \ | |
70 | OFPACT(SET_ETH_SRC, ofpact_mac, ofpact, "mod_dl_src") \ | |
71 | OFPACT(SET_ETH_DST, ofpact_mac, ofpact, "mod_dl_dst") \ | |
72 | OFPACT(SET_IPV4_SRC, ofpact_ipv4, ofpact, "mod_nw_src") \ | |
73 | OFPACT(SET_IPV4_DST, ofpact_ipv4, ofpact, "mod_nw_dst") \ | |
74 | OFPACT(SET_IP_DSCP, ofpact_dscp, ofpact, "mod_nw_tos") \ | |
75 | OFPACT(SET_IP_ECN, ofpact_ecn, ofpact, "mod_nw_ecn") \ | |
76 | OFPACT(SET_IP_TTL, ofpact_ip_ttl, ofpact, "mod_nw_ttl") \ | |
77 | OFPACT(SET_L4_SRC_PORT, ofpact_l4_port, ofpact, "mod_tp_src") \ | |
78 | OFPACT(SET_L4_DST_PORT, ofpact_l4_port, ofpact, "mod_tp_dst") \ | |
79 | OFPACT(REG_MOVE, ofpact_reg_move, ofpact, "move") \ | |
08d1e234 BP |
80 | OFPACT(STACK_PUSH, ofpact_stack, ofpact, "push") \ |
81 | OFPACT(STACK_POP, ofpact_stack, ofpact, "pop") \ | |
82 | OFPACT(DEC_TTL, ofpact_cnt_ids, cnt_ids, "dec_ttl") \ | |
83 | OFPACT(SET_MPLS_LABEL, ofpact_mpls_label, ofpact, "set_mpls_label") \ | |
84 | OFPACT(SET_MPLS_TC, ofpact_mpls_tc, ofpact, "set_mpls_tc") \ | |
85 | OFPACT(SET_MPLS_TTL, ofpact_mpls_ttl, ofpact, "set_mpls_ttl") \ | |
86 | OFPACT(DEC_MPLS_TTL, ofpact_null, ofpact, "dec_mpls_ttl") \ | |
87 | OFPACT(PUSH_MPLS, ofpact_push_mpls, ofpact, "push_mpls") \ | |
88 | OFPACT(POP_MPLS, ofpact_pop_mpls, ofpact, "pop_mpls") \ | |
89 | \ | |
90 | /* Metadata. */ \ | |
91 | OFPACT(SET_TUNNEL, ofpact_tunnel, ofpact, "set_tunnel") \ | |
92 | OFPACT(SET_QUEUE, ofpact_queue, ofpact, "set_queue") \ | |
93 | OFPACT(POP_QUEUE, ofpact_null, ofpact, "pop_queue") \ | |
94 | OFPACT(FIN_TIMEOUT, ofpact_fin_timeout, ofpact, "fin_timeout") \ | |
95 | \ | |
96 | /* Flow table interaction. */ \ | |
97 | OFPACT(RESUBMIT, ofpact_resubmit, ofpact, "resubmit") \ | |
98 | OFPACT(LEARN, ofpact_learn, specs, "learn") \ | |
18080541 | 99 | OFPACT(CONJUNCTION, ofpact_conjunction, ofpact, "conjunction") \ |
08d1e234 BP |
100 | \ |
101 | /* Arithmetic. */ \ | |
102 | OFPACT(MULTIPATH, ofpact_multipath, ofpact, "multipath") \ | |
103 | \ | |
104 | /* Other. */ \ | |
105 | OFPACT(NOTE, ofpact_note, data, "note") \ | |
106 | OFPACT(EXIT, ofpact_null, ofpact, "exit") \ | |
107 | OFPACT(SAMPLE, ofpact_sample, ofpact, "sample") \ | |
e672ff9b | 108 | OFPACT(UNROLL_XLATE, ofpact_unroll_xlate, ofpact, "unroll_xlate") \ |
07659514 | 109 | OFPACT(CT, ofpact_conntrack, ofpact, "ct") \ |
9ac0aada | 110 | OFPACT(NAT, ofpact_nat, ofpact, "nat") \ |
08d1e234 | 111 | \ |
d4abaff5 BP |
112 | /* Debugging actions. \ |
113 | * \ | |
114 | * These are intentionally undocumented, subject to change, and \ | |
115 | * only accepted if ovs-vswitchd is started with --enable-dummy. */ \ | |
116 | OFPACT(DEBUG_RECIRC, ofpact_null, ofpact, "debug_recirc") \ | |
117 | \ | |
08d1e234 BP |
118 | /* Instructions. */ \ |
119 | OFPACT(METER, ofpact_meter, ofpact, "meter") \ | |
120 | OFPACT(CLEAR_ACTIONS, ofpact_null, ofpact, "clear_actions") \ | |
121 | OFPACT(WRITE_ACTIONS, ofpact_nest, ofpact, "write_actions") \ | |
122 | OFPACT(WRITE_METADATA, ofpact_metadata, ofpact, "write_metadata") \ | |
123 | OFPACT(GOTO_TABLE, ofpact_goto_table, ofpact, "goto_table") | |
f25d0cf3 BP |
124 | |
125 | /* enum ofpact_type, with a member OFPACT_<ENUM> for each action. */ | |
126 | enum OVS_PACKED_ENUM ofpact_type { | |
08d1e234 | 127 | #define OFPACT(ENUM, STRUCT, MEMBER, NAME) OFPACT_##ENUM, |
f25d0cf3 | 128 | OFPACTS |
08d1e234 | 129 | #undef OFPACT |
f25d0cf3 BP |
130 | }; |
131 | ||
08d1e234 | 132 | /* Define N_OFPACTS to the number of types of ofpacts. */ |
f25d0cf3 | 133 | enum { |
08d1e234 BP |
134 | #define OFPACT(ENUM, STRUCT, MEMBER, NAME) + 1 |
135 | N_OFPACTS = OFPACTS | |
136 | #undef OFPACT | |
f25d0cf3 BP |
137 | }; |
138 | ||
139 | /* Header for an action. | |
140 | * | |
141 | * Each action is a structure "struct ofpact_*" that begins with "struct | |
142 | * ofpact", usually followed by other data that describes the action. Actions | |
2ac3c572 BP |
143 | * are padded out to a multiple of OFPACT_ALIGNTO bytes in length. |
144 | * | |
c2d936a4 | 145 | * The 'raw' member is special: |
2ac3c572 BP |
146 | * |
147 | * - Most "struct ofpact"s correspond to one particular kind of OpenFlow | |
148 | * action, at least in a given OpenFlow version. For example, | |
149 | * OFPACT_SET_VLAN_VID corresponds to OFPAT10_SET_VLAN_VID in OpenFlow | |
150 | * 1.0. | |
151 | * | |
c2d936a4 | 152 | * For such actions, the 'raw' member is not meaningful and generally |
2ac3c572 BP |
153 | * should be zero. |
154 | * | |
155 | * - A few "struct ofpact"s correspond to multiple OpenFlow actions. For | |
156 | * example, OFPACT_SET_TUNNEL can be NXAST_SET_TUNNEL or | |
157 | * NXAST_SET_TUNNEL64. In these cases, if the "struct ofpact" originated | |
158 | * from OpenFlow, then we want to make sure that, if it gets translated | |
159 | * back to OpenFlow later, it is translated back to the same action type. | |
160 | * (Otherwise, we'd violate the promise made in DESIGN, in the "Action | |
161 | * Reproduction" section.) | |
162 | * | |
c2d936a4 BP |
163 | * For such actions, the 'raw' member should be the "enum ofp_raw_action" |
164 | * originally extracted from the OpenFlow action. (If the action didn't | |
165 | * originate from OpenFlow, then setting 'raw' to zero should be fine: | |
166 | * code to translate the ofpact to OpenFlow must tolerate this case.) | |
2ac3c572 | 167 | */ |
6b2b63d0 | 168 | struct ofpact { |
80a73e71 BP |
169 | /* We want the space advantage of an 8-bit type here on every |
170 | * implementation, without giving up the advantage of having a useful type | |
171 | * on implementations that support packed enums. */ | |
172 | #ifdef HAVE_PACKED_ENUM | |
f25d0cf3 | 173 | enum ofpact_type type; /* OFPACT_*. */ |
80a73e71 BP |
174 | #else |
175 | uint8_t type; /* OFPACT_* */ | |
176 | #endif | |
177 | ||
c2d936a4 | 178 | uint8_t raw; /* Original type when added, if any. */ |
f25d0cf3 BP |
179 | uint16_t len; /* Length of the action, in bytes, including |
180 | * struct ofpact, excluding padding. */ | |
181 | }; | |
6b2b63d0 JR |
182 | BUILD_ASSERT_DECL(sizeof(struct ofpact) == 4); |
183 | ||
184 | /* Alignment. */ | |
185 | #define OFPACT_ALIGNTO 8 | |
186 | #define OFPACT_ALIGN(SIZE) ROUND_UP(SIZE, OFPACT_ALIGNTO) | |
f25d0cf3 | 187 | |
9193d145 BP |
188 | /* Expands to an anonymous union that contains: |
189 | * | |
190 | * - MEMBERS in a nested anonymous struct. | |
191 | * | |
192 | * - An array as large as MEMBERS plus padding to a multiple of 8 bytes. | |
193 | * | |
194 | * The effect is to pad MEMBERS to a multiple of 8 bytes. */ | |
195 | #define OFPACT_PADDED_MEMBERS(MEMBERS) \ | |
196 | union { \ | |
197 | struct { MEMBERS }; \ | |
198 | uint8_t pad[OFPACT_ALIGN(sizeof(struct { MEMBERS }))]; \ | |
199 | } | |
200 | ||
4f20179d | 201 | /* Returns the ofpact following 'ofpact'. */ |
f25d0cf3 BP |
202 | static inline struct ofpact * |
203 | ofpact_next(const struct ofpact *ofpact) | |
204 | { | |
205 | return (void *) ((uint8_t *) ofpact + OFPACT_ALIGN(ofpact->len)); | |
206 | } | |
207 | ||
4f20179d BP |
208 | struct ofpact *ofpact_next_flattened(const struct ofpact *); |
209 | ||
f25d0cf3 BP |
210 | static inline struct ofpact * |
211 | ofpact_end(const struct ofpact *ofpacts, size_t ofpacts_len) | |
212 | { | |
213 | return (void *) ((uint8_t *) ofpacts + ofpacts_len); | |
214 | } | |
215 | ||
216 | /* Assigns POS to each ofpact, in turn, in the OFPACTS_LEN bytes of ofpacts | |
217 | * starting at OFPACTS. */ | |
218 | #define OFPACT_FOR_EACH(POS, OFPACTS, OFPACTS_LEN) \ | |
219 | for ((POS) = (OFPACTS); (POS) < ofpact_end(OFPACTS, OFPACTS_LEN); \ | |
220 | (POS) = ofpact_next(POS)) | |
4f20179d BP |
221 | |
222 | /* Assigns POS to each ofpact, in turn, in the OFPACTS_LEN bytes of ofpacts | |
223 | * starting at OFPACTS. | |
224 | * | |
225 | * For ofpacts that contain nested ofpacts, this visits each of the inner | |
226 | * ofpacts as well. */ | |
227 | #define OFPACT_FOR_EACH_FLATTENED(POS, OFPACTS, OFPACTS_LEN) \ | |
228 | for ((POS) = (OFPACTS); (POS) < ofpact_end(OFPACTS, OFPACTS_LEN); \ | |
229 | (POS) = ofpact_next_flattened(POS)) | |
f25d0cf3 BP |
230 | \f |
231 | /* Action structure for each OFPACT_*. */ | |
232 | ||
b19e8793 | 233 | /* OFPACT_STRIP_VLAN, OFPACT_POP_QUEUE, OFPACT_EXIT, OFPACT_CLEAR_ACTIONS. |
f25d0cf3 | 234 | * |
7bcb1506 | 235 | * Used for OFPAT10_STRIP_VLAN, NXAST_POP_QUEUE, NXAST_EXIT, |
8e61c110 | 236 | * OFPAT11_POP_VLAN, OFPIT11_CLEAR_ACTIONS. |
f25d0cf3 BP |
237 | * |
238 | * Action structure for actions that do not have any extra data beyond the | |
239 | * action type. */ | |
240 | struct ofpact_null { | |
241 | struct ofpact ofpact; | |
242 | }; | |
243 | ||
244 | /* OFPACT_OUTPUT. | |
245 | * | |
246 | * Used for OFPAT10_OUTPUT. */ | |
247 | struct ofpact_output { | |
248 | struct ofpact ofpact; | |
4e022ec0 | 249 | ofp_port_t port; /* Output port. */ |
f25d0cf3 BP |
250 | uint16_t max_len; /* Max send len, for port OFPP_CONTROLLER. */ |
251 | }; | |
252 | ||
253 | /* OFPACT_CONTROLLER. | |
254 | * | |
255 | * Used for NXAST_CONTROLLER. */ | |
256 | struct ofpact_controller { | |
6335d074 BP |
257 | OFPACT_PADDED_MEMBERS( |
258 | struct ofpact ofpact; | |
259 | uint16_t max_len; /* Max length to send to controller. */ | |
260 | uint16_t controller_id; /* Controller ID to send packet-in. */ | |
261 | enum ofp_packet_in_reason reason; /* Reason to put in packet-in. */ | |
bdcad671 | 262 | |
6335d074 BP |
263 | /* If true, this action freezes packet traversal of the OpenFlow |
264 | * tables and adds a continuation to the packet-in message, that | |
265 | * a controller can use to resume that traversal. */ | |
266 | bool pause; | |
77ab5fd2 | 267 | |
6335d074 BP |
268 | /* Arbitrary data to include in the packet-in message (currently, |
269 | * only in NXT_PACKET_IN2). */ | |
270 | uint16_t userdata_len; | |
271 | ); | |
272 | uint8_t userdata[0]; | |
f25d0cf3 BP |
273 | }; |
274 | ||
275 | /* OFPACT_ENQUEUE. | |
276 | * | |
277 | * Used for OFPAT10_ENQUEUE. */ | |
278 | struct ofpact_enqueue { | |
279 | struct ofpact ofpact; | |
4e022ec0 | 280 | ofp_port_t port; |
f25d0cf3 BP |
281 | uint32_t queue; |
282 | }; | |
283 | ||
284 | /* OFPACT_OUTPUT_REG. | |
285 | * | |
286 | * Used for NXAST_OUTPUT_REG. */ | |
287 | struct ofpact_output_reg { | |
288 | struct ofpact ofpact; | |
f25d0cf3 | 289 | uint16_t max_len; |
dc723c44 | 290 | struct mf_subfield src; |
f25d0cf3 BP |
291 | }; |
292 | ||
c2d936a4 BP |
293 | /* Bundle slave choice algorithm to apply. |
294 | * | |
295 | * In the descriptions below, 'slaves' is the list of possible slaves in the | |
296 | * order they appear in the OpenFlow action. */ | |
297 | enum nx_bd_algorithm { | |
298 | /* Chooses the first live slave listed in the bundle. | |
299 | * | |
300 | * O(n_slaves) performance. */ | |
301 | NX_BD_ALG_ACTIVE_BACKUP = 0, | |
302 | ||
303 | /* Highest Random Weight. | |
304 | * | |
305 | * for i in [0,n_slaves): | |
306 | * weights[i] = hash(flow, i) | |
307 | * slave = { slaves[i] such that weights[i] >= weights[j] for all j != i } | |
308 | * | |
309 | * Redistributes 1/n_slaves of traffic when a slave's liveness changes. | |
310 | * O(n_slaves) performance. | |
311 | * | |
312 | * Uses the 'fields' and 'basis' parameters. */ | |
313 | NX_BD_ALG_HRW = 1 | |
314 | }; | |
315 | ||
f25d0cf3 BP |
316 | /* OFPACT_BUNDLE. |
317 | * | |
318 | * Used for NXAST_BUNDLE. */ | |
319 | struct ofpact_bundle { | |
320 | struct ofpact ofpact; | |
321 | ||
322 | /* Slave choice algorithm to apply to hash value. */ | |
323 | enum nx_bd_algorithm algorithm; | |
324 | ||
325 | /* What fields to hash and how. */ | |
326 | enum nx_hash_fields fields; | |
327 | uint16_t basis; /* Universal hash parameter. */ | |
328 | ||
329 | struct mf_subfield dst; | |
330 | ||
331 | /* Slaves for output. */ | |
332 | unsigned int n_slaves; | |
4e022ec0 | 333 | ofp_port_t slaves[]; |
f25d0cf3 BP |
334 | }; |
335 | ||
336 | /* OFPACT_SET_VLAN_VID. | |
337 | * | |
ca287d20 JR |
338 | * We keep track if vlan was present at action validation time to avoid a |
339 | * PUSH_VLAN when translating to OpenFlow 1.1+. | |
340 | * | |
341 | * We also keep the originating OFPUTIL action code in ofpact.compat. | |
342 | * | |
343 | * Used for OFPAT10_SET_VLAN_VID and OFPAT11_SET_VLAN_VID. */ | |
f25d0cf3 BP |
344 | struct ofpact_vlan_vid { |
345 | struct ofpact ofpact; | |
346 | uint16_t vlan_vid; /* VLAN VID in low 12 bits, 0 in other bits. */ | |
ca287d20 JR |
347 | bool push_vlan_if_needed; /* OF 1.0 semantics if true. */ |
348 | bool flow_has_vlan; /* VLAN present at action validation time? */ | |
f25d0cf3 BP |
349 | }; |
350 | ||
351 | /* OFPACT_SET_VLAN_PCP. | |
352 | * | |
ca287d20 JR |
353 | * We keep track if vlan was present at action validation time to avoid a |
354 | * PUSH_VLAN when translating to OpenFlow 1.1+. | |
355 | * | |
356 | * We also keep the originating OFPUTIL action code in ofpact.compat. | |
357 | * | |
358 | * Used for OFPAT10_SET_VLAN_PCP and OFPAT11_SET_VLAN_PCP. */ | |
f25d0cf3 BP |
359 | struct ofpact_vlan_pcp { |
360 | struct ofpact ofpact; | |
361 | uint8_t vlan_pcp; /* VLAN PCP in low 3 bits, 0 in other bits. */ | |
ca287d20 JR |
362 | bool push_vlan_if_needed; /* OF 1.0 semantics if true. */ |
363 | bool flow_has_vlan; /* VLAN present at action validation time? */ | |
f25d0cf3 BP |
364 | }; |
365 | ||
366 | /* OFPACT_SET_ETH_SRC, OFPACT_SET_ETH_DST. | |
367 | * | |
368 | * Used for OFPAT10_SET_DL_SRC, OFPAT10_SET_DL_DST. */ | |
369 | struct ofpact_mac { | |
370 | struct ofpact ofpact; | |
74ff3298 | 371 | struct eth_addr mac; |
f25d0cf3 BP |
372 | }; |
373 | ||
374 | /* OFPACT_SET_IPV4_SRC, OFPACT_SET_IPV4_DST. | |
375 | * | |
376 | * Used for OFPAT10_SET_NW_SRC, OFPAT10_SET_NW_DST. */ | |
377 | struct ofpact_ipv4 { | |
378 | struct ofpact ofpact; | |
379 | ovs_be32 ipv4; | |
380 | }; | |
381 | ||
04f01c24 | 382 | /* OFPACT_SET_IP_DSCP. |
f25d0cf3 BP |
383 | * |
384 | * Used for OFPAT10_SET_NW_TOS. */ | |
385 | struct ofpact_dscp { | |
386 | struct ofpact ofpact; | |
387 | uint8_t dscp; /* DSCP in high 6 bits, rest ignored. */ | |
388 | }; | |
389 | ||
ff14eb7a JR |
390 | /* OFPACT_SET_IP_ECN. |
391 | * | |
392 | * Used for OFPAT11_SET_NW_ECN. */ | |
393 | struct ofpact_ecn { | |
394 | struct ofpact ofpact; | |
395 | uint8_t ecn; /* ECN in low 2 bits, rest ignored. */ | |
396 | }; | |
397 | ||
0c20dbe4 JR |
398 | /* OFPACT_SET_IP_TTL. |
399 | * | |
400 | * Used for OFPAT11_SET_NW_TTL. */ | |
401 | struct ofpact_ip_ttl { | |
402 | struct ofpact ofpact; | |
403 | uint8_t ttl; | |
404 | }; | |
405 | ||
f25d0cf3 BP |
406 | /* OFPACT_SET_L4_SRC_PORT, OFPACT_SET_L4_DST_PORT. |
407 | * | |
408 | * Used for OFPAT10_SET_TP_SRC, OFPAT10_SET_TP_DST. */ | |
409 | struct ofpact_l4_port { | |
410 | struct ofpact ofpact; | |
1e7db674 JR |
411 | uint16_t port; /* TCP, UDP or SCTP port number. */ |
412 | uint8_t flow_ip_proto; /* IP proto from corresponding match, or 0 */ | |
f25d0cf3 BP |
413 | }; |
414 | ||
415 | /* OFPACT_REG_MOVE. | |
416 | * | |
417 | * Used for NXAST_REG_MOVE. */ | |
418 | struct ofpact_reg_move { | |
419 | struct ofpact ofpact; | |
420 | struct mf_subfield src; | |
421 | struct mf_subfield dst; | |
422 | }; | |
423 | ||
bd85dac1 AZ |
424 | /* OFPACT_STACK_PUSH. |
425 | * | |
426 | * Used for NXAST_STACK_PUSH and NXAST_STACK_POP. */ | |
427 | struct ofpact_stack { | |
428 | struct ofpact ofpact; | |
429 | struct mf_subfield subfield; | |
430 | }; | |
431 | ||
b2dd70be JR |
432 | /* OFPACT_SET_FIELD. |
433 | * | |
7eb4b1f1 | 434 | * Used for NXAST_REG_LOAD and OFPAT12_SET_FIELD. */ |
b2dd70be JR |
435 | struct ofpact_set_field { |
436 | struct ofpact ofpact; | |
437 | const struct mf_field *field; | |
a6fd70bb | 438 | bool flow_has_vlan; /* VLAN present at action validation time. */ |
b2dd70be | 439 | union mf_value value; |
7eb4b1f1 | 440 | union mf_value mask; |
b2dd70be JR |
441 | }; |
442 | ||
b02475c5 SH |
443 | /* OFPACT_PUSH_VLAN/MPLS/PBB |
444 | * | |
445 | * Used for NXAST_PUSH_MPLS, OFPAT11_PUSH_MPLS. */ | |
446 | struct ofpact_push_mpls { | |
447 | struct ofpact ofpact; | |
448 | ovs_be16 ethertype; | |
449 | }; | |
450 | ||
451 | /* OFPACT_POP_MPLS | |
452 | * | |
453 | * Used for NXAST_POP_MPLS, OFPAT11_POP_MPLS.. */ | |
454 | struct ofpact_pop_mpls { | |
455 | struct ofpact ofpact; | |
456 | ovs_be16 ethertype; | |
457 | }; | |
458 | ||
f25d0cf3 BP |
459 | /* OFPACT_SET_TUNNEL. |
460 | * | |
461 | * Used for NXAST_SET_TUNNEL, NXAST_SET_TUNNEL64. */ | |
462 | struct ofpact_tunnel { | |
463 | struct ofpact ofpact; | |
464 | uint64_t tun_id; | |
465 | }; | |
466 | ||
467 | /* OFPACT_SET_QUEUE. | |
468 | * | |
469 | * Used for NXAST_SET_QUEUE. */ | |
470 | struct ofpact_queue { | |
471 | struct ofpact ofpact; | |
472 | uint32_t queue_id; | |
473 | }; | |
474 | ||
475 | /* OFPACT_FIN_TIMEOUT. | |
476 | * | |
477 | * Used for NXAST_FIN_TIMEOUT. */ | |
478 | struct ofpact_fin_timeout { | |
479 | struct ofpact ofpact; | |
480 | uint16_t fin_idle_timeout; | |
481 | uint16_t fin_hard_timeout; | |
482 | }; | |
483 | ||
4cceacb9 JS |
484 | /* OFPACT_WRITE_METADATA. |
485 | * | |
486 | * Used for NXAST_WRITE_METADATA. */ | |
487 | struct ofpact_metadata { | |
488 | struct ofpact ofpact; | |
489 | ovs_be64 metadata; | |
490 | ovs_be64 mask; | |
491 | }; | |
492 | ||
638a19b0 JR |
493 | /* OFPACT_METER. |
494 | * | |
495 | * Used for OFPIT13_METER. */ | |
496 | struct ofpact_meter { | |
497 | struct ofpact ofpact; | |
498 | uint32_t meter_id; | |
499 | }; | |
500 | ||
7fdb60a7 SH |
501 | /* OFPACT_WRITE_ACTIONS. |
502 | * | |
503 | * Used for OFPIT11_WRITE_ACTIONS. */ | |
504 | struct ofpact_nest { | |
9193d145 | 505 | OFPACT_PADDED_MEMBERS(struct ofpact ofpact;); |
7fdb60a7 SH |
506 | struct ofpact actions[]; |
507 | }; | |
93904c85 | 508 | BUILD_ASSERT_DECL(offsetof(struct ofpact_nest, actions) % OFPACT_ALIGNTO == 0); |
c2d936a4 BP |
509 | BUILD_ASSERT_DECL(offsetof(struct ofpact_nest, actions) |
510 | == sizeof(struct ofpact_nest)); | |
7fdb60a7 | 511 | |
07659514 JS |
512 | /* Bits for 'flags' in struct nx_action_conntrack. |
513 | * | |
514 | * If NX_CT_F_COMMIT is set, then the connection entry is moved from the | |
515 | * unconfirmed to confirmed list in the tracker. */ | |
516 | enum nx_conntrack_flags { | |
517 | NX_CT_F_COMMIT = 1 << 0, | |
518 | }; | |
519 | ||
520 | /* Magic value for struct nx_action_conntrack 'recirc_table' field, to specify | |
521 | * that the packet should not be recirculated. */ | |
522 | #define NX_CT_RECIRC_NONE OFPTT_ALL | |
523 | ||
58e3dd5a YT |
524 | #if !defined(IPPORT_FTP) |
525 | #define IPPORT_FTP 21 | |
526 | #endif | |
527 | ||
07659514 JS |
528 | /* OFPACT_CT. |
529 | * | |
530 | * Used for NXAST_CT. */ | |
531 | struct ofpact_conntrack { | |
9193d145 BP |
532 | OFPACT_PADDED_MEMBERS( |
533 | struct ofpact ofpact; | |
534 | uint16_t flags; | |
535 | uint16_t zone_imm; | |
536 | struct mf_subfield zone_src; | |
537 | uint16_t alg; | |
538 | uint8_t recirc_table; | |
539 | ); | |
c7e69808 | 540 | struct ofpact actions[0]; |
07659514 | 541 | }; |
8e53fe8c JS |
542 | BUILD_ASSERT_DECL(offsetof(struct ofpact_conntrack, actions) |
543 | % OFPACT_ALIGNTO == 0); | |
544 | BUILD_ASSERT_DECL(offsetof(struct ofpact_conntrack, actions) | |
545 | == sizeof(struct ofpact_conntrack)); | |
546 | ||
547 | static inline size_t | |
548 | ofpact_ct_get_action_len(const struct ofpact_conntrack *oc) | |
549 | { | |
550 | return oc->ofpact.len - offsetof(struct ofpact_conntrack, actions); | |
551 | } | |
07659514 | 552 | |
7fdb60a7 SH |
553 | static inline size_t |
554 | ofpact_nest_get_action_len(const struct ofpact_nest *on) | |
555 | { | |
556 | return on->ofpact.len - offsetof(struct ofpact_nest, actions); | |
557 | } | |
558 | ||
559 | void ofpacts_execute_action_set(struct ofpbuf *action_list, | |
560 | const struct ofpbuf *action_set); | |
561 | ||
9ac0aada JR |
562 | /* Bits for 'flags' in struct nx_action_nat. |
563 | */ | |
564 | enum nx_nat_flags { | |
565 | NX_NAT_F_SRC = 1 << 0, | |
566 | NX_NAT_F_DST = 1 << 1, | |
567 | NX_NAT_F_PERSISTENT = 1 << 2, | |
568 | NX_NAT_F_PROTO_HASH = 1 << 3, | |
569 | NX_NAT_F_PROTO_RANDOM = 1 << 4, | |
570 | }; | |
571 | ||
572 | /* OFPACT_NAT. | |
573 | * | |
574 | * Used for NXAST_NAT. */ | |
575 | struct ofpact_nat { | |
576 | struct ofpact ofpact; | |
577 | uint8_t range_af; /* AF_UNSPEC, AF_INET, or AF_INET6 */ | |
578 | uint16_t flags; /* NX_NAT_F_* */ | |
579 | struct { | |
580 | struct { | |
581 | uint16_t min; | |
582 | uint16_t max; | |
583 | } proto; | |
584 | union { | |
585 | struct { | |
586 | ovs_be32 min; | |
587 | ovs_be32 max; | |
588 | } ipv4; | |
589 | struct { | |
590 | struct in6_addr min; | |
591 | struct in6_addr max; | |
592 | } ipv6; | |
593 | } addr; | |
594 | } range; | |
595 | }; | |
596 | ||
597 | ||
f25d0cf3 BP |
598 | /* OFPACT_RESUBMIT. |
599 | * | |
600 | * Used for NXAST_RESUBMIT, NXAST_RESUBMIT_TABLE. */ | |
601 | struct ofpact_resubmit { | |
602 | struct ofpact ofpact; | |
4e022ec0 | 603 | ofp_port_t in_port; |
f25d0cf3 BP |
604 | uint8_t table_id; |
605 | }; | |
606 | ||
607 | /* Part of struct ofpact_learn, below. */ | |
608 | struct ofpact_learn_spec { | |
e956d63b | 609 | int n_bits; /* Number of bits in source and dest. */ |
f25d0cf3 | 610 | |
e956d63b BP |
611 | int src_type; /* One of NX_LEARN_SRC_*. */ |
612 | struct mf_subfield src; /* NX_LEARN_SRC_FIELD only. */ | |
613 | union mf_subvalue src_imm; /* NX_LEARN_SRC_IMMEDIATE only. */ | |
f25d0cf3 | 614 | |
e956d63b BP |
615 | int dst_type; /* One of NX_LEARN_DST_*. */ |
616 | struct mf_subfield dst; /* NX_LEARN_DST_MATCH, NX_LEARN_DST_LOAD only. */ | |
f25d0cf3 BP |
617 | }; |
618 | ||
c2d936a4 BP |
619 | |
620 | /* Bits for 'flags' in struct nx_action_learn. | |
621 | * | |
622 | * If NX_LEARN_F_SEND_FLOW_REM is set, then the learned flows will have their | |
623 | * OFPFF_SEND_FLOW_REM flag set. | |
624 | * | |
625 | * If NX_LEARN_F_DELETE_LEARNED is set, then removing this action will delete | |
626 | * all the flows from the learn action's 'table_id' that have the learn | |
627 | * action's 'cookie'. Important points: | |
628 | * | |
629 | * - The deleted flows include those created by this action, those created | |
630 | * by other learn actions with the same 'table_id' and 'cookie', those | |
631 | * created by flow_mod requests by a controller in the specified table | |
632 | * with the specified cookie, and those created through any other | |
633 | * means. | |
634 | * | |
635 | * - If multiple flows specify "learn" actions with | |
636 | * NX_LEARN_F_DELETE_LEARNED with the same 'table_id' and 'cookie', then | |
637 | * no deletion occurs until all of those "learn" actions are deleted. | |
638 | * | |
639 | * - Deleting a flow that contains a learn action is the most obvious way | |
640 | * to delete a learn action. Modifying a flow's actions, or replacing it | |
641 | * by a new flow, can also delete a learn action. Finally, replacing a | |
642 | * learn action with NX_LEARN_F_DELETE_LEARNED with a learn action | |
643 | * without that flag also effectively deletes the learn action and can | |
644 | * trigger flow deletion. | |
645 | * | |
646 | * NX_LEARN_F_DELETE_LEARNED was added in Open vSwitch 2.4. */ | |
647 | enum nx_learn_flags { | |
648 | NX_LEARN_F_SEND_FLOW_REM = 1 << 0, | |
649 | NX_LEARN_F_DELETE_LEARNED = 1 << 1, | |
650 | }; | |
651 | ||
652 | #define NX_LEARN_N_BITS_MASK 0x3ff | |
653 | ||
654 | #define NX_LEARN_SRC_FIELD (0 << 13) /* Copy from field. */ | |
655 | #define NX_LEARN_SRC_IMMEDIATE (1 << 13) /* Copy from immediate value. */ | |
656 | #define NX_LEARN_SRC_MASK (1 << 13) | |
657 | ||
658 | #define NX_LEARN_DST_MATCH (0 << 11) /* Add match criterion. */ | |
659 | #define NX_LEARN_DST_LOAD (1 << 11) /* Add NXAST_REG_LOAD action. */ | |
660 | #define NX_LEARN_DST_OUTPUT (2 << 11) /* Add OFPAT_OUTPUT action. */ | |
661 | #define NX_LEARN_DST_RESERVED (3 << 11) /* Not yet defined. */ | |
662 | #define NX_LEARN_DST_MASK (3 << 11) | |
663 | ||
f25d0cf3 BP |
664 | /* OFPACT_LEARN. |
665 | * | |
666 | * Used for NXAST_LEARN. */ | |
667 | struct ofpact_learn { | |
668 | struct ofpact ofpact; | |
669 | ||
670 | uint16_t idle_timeout; /* Idle time before discarding (seconds). */ | |
671 | uint16_t hard_timeout; /* Max time before discarding (seconds). */ | |
672 | uint16_t priority; /* Priority level of flow entry. */ | |
e0822031 | 673 | uint8_t table_id; /* Table to insert flow entry. */ |
80771642 | 674 | ovs_be64 cookie; /* Cookie for new flow. */ |
35f48b8b | 675 | enum nx_learn_flags flags; /* NX_LEARN_F_*. */ |
f25d0cf3 BP |
676 | uint16_t fin_idle_timeout; /* Idle timeout after FIN, if nonzero. */ |
677 | uint16_t fin_hard_timeout; /* Hard timeout after FIN, if nonzero. */ | |
678 | ||
679 | unsigned int n_specs; | |
680 | struct ofpact_learn_spec specs[]; | |
681 | }; | |
682 | ||
c2d936a4 BP |
683 | /* Multipath link choice algorithm to apply. |
684 | * | |
685 | * In the descriptions below, 'n_links' is max_link + 1. */ | |
686 | enum nx_mp_algorithm { | |
687 | /* link = hash(flow) % n_links. | |
688 | * | |
689 | * Redistributes all traffic when n_links changes. O(1) performance. See | |
690 | * RFC 2992. | |
691 | * | |
692 | * Use UINT16_MAX for max_link to get a raw hash value. */ | |
693 | NX_MP_ALG_MODULO_N = 0, | |
694 | ||
695 | /* link = hash(flow) / (MAX_HASH / n_links). | |
696 | * | |
697 | * Redistributes between one-quarter and one-half of traffic when n_links | |
698 | * changes. O(1) performance. See RFC 2992. | |
699 | */ | |
700 | NX_MP_ALG_HASH_THRESHOLD = 1, | |
701 | ||
702 | /* Highest Random Weight. | |
703 | * | |
704 | * for i in [0,n_links): | |
705 | * weights[i] = hash(flow, i) | |
706 | * link = { i such that weights[i] >= weights[j] for all j != i } | |
707 | * | |
708 | * Redistributes 1/n_links of traffic when n_links changes. O(n_links) | |
709 | * performance. If n_links is greater than a threshold (currently 64, but | |
710 | * subject to change), Open vSwitch will substitute another algorithm | |
711 | * automatically. See RFC 2992. */ | |
712 | NX_MP_ALG_HRW = 2, | |
713 | ||
714 | /* Iterative Hash. | |
715 | * | |
716 | * i = 0 | |
717 | * repeat: | |
718 | * i = i + 1 | |
719 | * link = hash(flow, i) % arg | |
720 | * while link > max_link | |
721 | * | |
722 | * Redistributes 1/n_links of traffic when n_links changes. O(1) | |
723 | * performance when arg/max_link is bounded by a constant. | |
724 | * | |
725 | * Redistributes all traffic when arg changes. | |
726 | * | |
727 | * arg must be greater than max_link and for best performance should be no | |
728 | * more than approximately max_link * 2. If arg is outside the acceptable | |
729 | * range, Open vSwitch will automatically substitute the least power of 2 | |
730 | * greater than max_link. | |
731 | * | |
732 | * This algorithm is specific to Open vSwitch. | |
733 | */ | |
734 | NX_MP_ALG_ITER_HASH = 3, | |
735 | }; | |
736 | ||
18080541 BP |
737 | /* OFPACT_CONJUNCTION. |
738 | * | |
739 | * Used for NXAST_CONJUNCTION. */ | |
740 | struct ofpact_conjunction { | |
741 | struct ofpact ofpact; | |
742 | uint8_t clause; | |
743 | uint8_t n_clauses; | |
744 | uint32_t id; | |
745 | }; | |
746 | ||
f25d0cf3 BP |
747 | /* OFPACT_MULTIPATH. |
748 | * | |
749 | * Used for NXAST_MULTIPATH. */ | |
750 | struct ofpact_multipath { | |
751 | struct ofpact ofpact; | |
752 | ||
753 | /* What fields to hash and how. */ | |
754 | enum nx_hash_fields fields; | |
755 | uint16_t basis; /* Universal hash parameter. */ | |
756 | ||
757 | /* Multipath link choice algorithm to apply to hash value. */ | |
758 | enum nx_mp_algorithm algorithm; | |
759 | uint16_t max_link; /* Number of output links, minus 1. */ | |
760 | uint32_t arg; /* Algorithm-specific argument. */ | |
761 | ||
762 | /* Where to store the result. */ | |
763 | struct mf_subfield dst; | |
764 | }; | |
765 | ||
f25d0cf3 BP |
766 | /* OFPACT_NOTE. |
767 | * | |
768 | * Used for NXAST_NOTE. */ | |
769 | struct ofpact_note { | |
770 | struct ofpact ofpact; | |
771 | size_t length; | |
772 | uint8_t data[]; | |
773 | }; | |
774 | ||
29089a54 RL |
775 | /* OFPACT_SAMPLE. |
776 | * | |
777 | * Used for NXAST_SAMPLE. */ | |
778 | struct ofpact_sample { | |
779 | struct ofpact ofpact; | |
780 | uint16_t probability; // Always >0. | |
781 | uint32_t collector_set_id; | |
782 | uint32_t obs_domain_id; | |
783 | uint32_t obs_point_id; | |
784 | }; | |
785 | ||
c2d967a5 MM |
786 | /* OFPACT_DEC_TTL. |
787 | * | |
7bcb1506 | 788 | * Used for OFPAT11_DEC_NW_TTL, NXAST_DEC_TTL and NXAST_DEC_TTL_CNT_IDS. */ |
c2d967a5 MM |
789 | struct ofpact_cnt_ids { |
790 | struct ofpact ofpact; | |
791 | ||
792 | /* Controller ids. */ | |
793 | unsigned int n_controllers; | |
794 | uint16_t cnt_ids[]; | |
8dd54666 | 795 | }; |
c2d967a5 | 796 | |
097d4939 JR |
797 | /* OFPACT_SET_MPLS_LABEL. |
798 | * | |
799 | * Used for OFPAT11_SET_MPLS_LABEL and NXAST_SET_MPLS_LABEL */ | |
800 | struct ofpact_mpls_label { | |
801 | struct ofpact ofpact; | |
802 | ||
803 | ovs_be32 label; | |
804 | }; | |
805 | ||
806 | /* OFPACT_SET_MPLS_TC. | |
807 | * | |
808 | * Used for OFPAT11_SET_MPLS_TC and NXAST_SET_MPLS_TC */ | |
809 | struct ofpact_mpls_tc { | |
810 | struct ofpact ofpact; | |
811 | ||
812 | uint8_t tc; | |
813 | }; | |
814 | ||
0f3f3c3d SH |
815 | /* OFPACT_SET_MPLS_TTL. |
816 | * | |
097d4939 | 817 | * Used for OFPAT11_SET_MPLS_TTL and NXAST_SET_MPLS_TTL */ |
0f3f3c3d SH |
818 | struct ofpact_mpls_ttl { |
819 | struct ofpact ofpact; | |
820 | ||
821 | uint8_t ttl; | |
822 | }; | |
823 | ||
8dd54666 IY |
824 | /* OFPACT_GOTO_TABLE |
825 | * | |
826 | * Used for OFPIT11_GOTO_TABLE */ | |
827 | struct ofpact_goto_table { | |
828 | struct ofpact ofpact; | |
829 | uint8_t table_id; | |
c2d967a5 MM |
830 | }; |
831 | ||
7395c052 NZ |
832 | /* OFPACT_GROUP. |
833 | * | |
834 | * Used for OFPAT11_GROUP. */ | |
835 | struct ofpact_group { | |
836 | struct ofpact ofpact; | |
837 | uint32_t group_id; | |
838 | }; | |
839 | ||
e672ff9b JR |
840 | /* OFPACT_UNROLL_XLATE. |
841 | * | |
842 | * Used only internally. */ | |
843 | struct ofpact_unroll_xlate { | |
844 | struct ofpact ofpact; | |
845 | ||
846 | /* Metadata in xlate context, visible to controller via PACKET_INs. */ | |
847 | uint8_t rule_table_id; /* 0xFF if none. */ | |
848 | ovs_be64 rule_cookie; /* OVS_BE64_MAX if none. */ | |
849 | }; | |
850 | ||
f25d0cf3 | 851 | /* Converting OpenFlow to ofpacts. */ |
e3f8f887 JR |
852 | enum ofperr ofpacts_pull_openflow_actions(struct ofpbuf *openflow, |
853 | unsigned int actions_len, | |
854 | enum ofp_version version, | |
855 | struct ofpbuf *ofpacts); | |
856 | enum ofperr ofpacts_pull_openflow_instructions(struct ofpbuf *openflow, | |
857 | unsigned int instructions_len, | |
858 | enum ofp_version version, | |
859 | struct ofpbuf *ofpacts); | |
ca287d20 | 860 | enum ofperr ofpacts_check(struct ofpact[], size_t ofpacts_len, |
ba2fe8e9 BP |
861 | struct flow *, ofp_port_t max_ports, |
862 | uint8_t table_id, uint8_t n_tables, | |
863 | enum ofputil_protocol *usable_protocols); | |
864 | enum ofperr ofpacts_check_consistency(struct ofpact[], size_t ofpacts_len, | |
865 | struct flow *, ofp_port_t max_ports, | |
866 | uint8_t table_id, uint8_t n_tables, | |
867 | enum ofputil_protocol usable_protocols); | |
57ad4e9e | 868 | enum ofperr ofpact_check_output_port(ofp_port_t port, ofp_port_t max_ports); |
f25d0cf3 BP |
869 | |
870 | /* Converting ofpacts to OpenFlow. */ | |
e3f8f887 JR |
871 | size_t ofpacts_put_openflow_actions(const struct ofpact[], size_t ofpacts_len, |
872 | struct ofpbuf *openflow, enum ofp_version); | |
873 | void ofpacts_put_openflow_instructions(const struct ofpact[], | |
874 | size_t ofpacts_len, | |
875 | struct ofpbuf *openflow, | |
876 | enum ofp_version ofp_version); | |
f25d0cf3 | 877 | |
08d1e234 BP |
878 | /* Sets of supported actions. */ |
879 | ovs_be32 ofpact_bitmap_to_openflow(uint64_t ofpacts_bitmap, enum ofp_version); | |
880 | uint64_t ofpact_bitmap_from_openflow(ovs_be32 ofpat_bitmap, enum ofp_version); | |
881 | void ofpact_bitmap_format(uint64_t ofpacts_bitmap, struct ds *); | |
882 | ||
f25d0cf3 BP |
883 | /* Working with ofpacts. */ |
884 | bool ofpacts_output_to_port(const struct ofpact[], size_t ofpacts_len, | |
4e022ec0 | 885 | ofp_port_t port); |
7395c052 NZ |
886 | bool ofpacts_output_to_group(const struct ofpact[], size_t ofpacts_len, |
887 | uint32_t group_id); | |
f25d0cf3 BP |
888 | bool ofpacts_equal(const struct ofpact a[], size_t a_len, |
889 | const struct ofpact b[], size_t b_len); | |
28f5311f | 890 | const struct mf_field *ofpact_get_mf_dst(const struct ofpact *ofpact); |
d6fb622d | 891 | uint32_t ofpacts_get_meter(const struct ofpact[], size_t ofpacts_len); |
f25d0cf3 | 892 | |
c2d936a4 | 893 | /* Formatting and parsing ofpacts. */ |
f25d0cf3 | 894 | void ofpacts_format(const struct ofpact[], size_t ofpacts_len, struct ds *); |
c2d936a4 BP |
895 | char *ofpacts_parse_actions(const char *, struct ofpbuf *ofpacts, |
896 | enum ofputil_protocol *usable_protocols) | |
cab50449 | 897 | OVS_WARN_UNUSED_RESULT; |
c2d936a4 BP |
898 | char *ofpacts_parse_instructions(const char *, struct ofpbuf *ofpacts, |
899 | enum ofputil_protocol *usable_protocols) | |
cab50449 | 900 | OVS_WARN_UNUSED_RESULT; |
08d1e234 | 901 | const char *ofpact_name(enum ofpact_type); |
f25d0cf3 BP |
902 | |
903 | /* Internal use by the helpers below. */ | |
904 | void ofpact_init(struct ofpact *, enum ofpact_type, size_t len); | |
905 | void *ofpact_put(struct ofpbuf *, enum ofpact_type, size_t len); | |
906 | ||
907 | /* For each OFPACT_<ENUM> with a corresponding struct <STRUCT>, this defines | |
908 | * the following commonly useful functions: | |
909 | * | |
910 | * struct <STRUCT> *ofpact_put_<ENUM>(struct ofpbuf *ofpacts); | |
911 | * | |
2bd318de | 912 | * Appends a new 'ofpact', of length OFPACT_<ENUM>_SIZE, to 'ofpacts', |
f25d0cf3 | 913 | * initializes it with ofpact_init_<ENUM>(), and returns it. Also sets |
9ac0aada | 914 | * 'ofpacts->header' to the returned action. |
f25d0cf3 BP |
915 | * |
916 | * After using this function to add a variable-length action, add the | |
917 | * elements of the flexible array (e.g. with ofpbuf_put()), then use | |
34abaa3d BP |
918 | * ofpact_finish() to pad the action to a multiple of OFPACT_ALIGNTO bytes |
919 | * and update its embedded length field. (Keep in mind the need to refresh | |
920 | * the structure from 'ofpacts->header' after adding data to 'ofpacts'.) | |
f25d0cf3 BP |
921 | * |
922 | * struct <STRUCT> *ofpact_get_<ENUM>(const struct ofpact *ofpact); | |
923 | * | |
924 | * Returns 'ofpact' cast to "struct <STRUCT> *". 'ofpact->type' must be | |
925 | * OFPACT_<ENUM>. | |
926 | * | |
927 | * as well as the following more rarely useful definitions: | |
928 | * | |
929 | * void ofpact_init_<ENUM>(struct <STRUCT> *ofpact); | |
930 | * | |
931 | * Initializes the parts of 'ofpact' that identify it as having type | |
2bd318de | 932 | * OFPACT_<ENUM> and length OFPACT_<ENUM>_SIZE and zeros the rest. |
f25d0cf3 BP |
933 | * |
934 | * <ENUM>_SIZE | |
935 | * | |
2bd318de BP |
936 | * The size of the action structure. For a fixed-length action, this is |
937 | * sizeof(struct <STRUCT>) rounded up to a multiple of OFPACT_ALIGNTO. For | |
938 | * a variable-length action, this is the offset to the variable-length | |
939 | * part. | |
f25d0cf3 | 940 | */ |
08d1e234 | 941 | #define OFPACT(ENUM, STRUCT, MEMBER, NAME) \ |
f25d0cf3 BP |
942 | BUILD_ASSERT_DECL(offsetof(struct STRUCT, ofpact) == 0); \ |
943 | \ | |
2bd318de | 944 | enum { OFPACT_##ENUM##_SIZE \ |
f25d0cf3 BP |
945 | = (offsetof(struct STRUCT, MEMBER) \ |
946 | ? offsetof(struct STRUCT, MEMBER) \ | |
2bd318de | 947 | : OFPACT_ALIGN(sizeof(struct STRUCT))) }; \ |
f25d0cf3 BP |
948 | \ |
949 | static inline struct STRUCT * \ | |
950 | ofpact_get_##ENUM(const struct ofpact *ofpact) \ | |
951 | { \ | |
cb22974d | 952 | ovs_assert(ofpact->type == OFPACT_##ENUM); \ |
db5a1019 | 953 | return ALIGNED_CAST(struct STRUCT *, ofpact); \ |
f25d0cf3 BP |
954 | } \ |
955 | \ | |
956 | static inline struct STRUCT * \ | |
957 | ofpact_put_##ENUM(struct ofpbuf *ofpacts) \ | |
958 | { \ | |
959 | return ofpact_put(ofpacts, OFPACT_##ENUM, \ | |
2bd318de | 960 | OFPACT_##ENUM##_SIZE); \ |
f25d0cf3 BP |
961 | } \ |
962 | \ | |
963 | static inline void \ | |
964 | ofpact_init_##ENUM(struct STRUCT *ofpact) \ | |
965 | { \ | |
966 | ofpact_init(&ofpact->ofpact, OFPACT_##ENUM, \ | |
2bd318de | 967 | OFPACT_##ENUM##_SIZE); \ |
f25d0cf3 BP |
968 | } |
969 | OFPACTS | |
08d1e234 | 970 | #undef OFPACT |
f25d0cf3 | 971 | |
2bd318de | 972 | /* Call after adding the variable-length part to a variable-length action. */ |
ebe12cd3 | 973 | void *ofpact_finish(struct ofpbuf *, struct ofpact *); |
f25d0cf3 | 974 | |
7eb4b1f1 BP |
975 | /* Additional functions for composing ofpacts. */ |
976 | struct ofpact_set_field *ofpact_put_reg_load(struct ofpbuf *ofpacts); | |
977 | ||
99c476dc IY |
978 | /* OpenFlow 1.1 instructions. |
979 | * The order is sorted in execution order. Not in the value of OFPIT11_xxx. | |
980 | * It is enforced on parser from text string. | |
981 | */ | |
a64f0b0f | 982 | #define OVS_INSTRUCTIONS \ |
638a19b0 JR |
983 | DEFINE_INST(OFPIT13_METER, \ |
984 | ofp13_instruction_meter, false, \ | |
985 | "meter") \ | |
986 | \ | |
99c476dc IY |
987 | DEFINE_INST(OFPIT11_APPLY_ACTIONS, \ |
988 | ofp11_instruction_actions, true, \ | |
989 | "apply_actions") \ | |
a64f0b0f | 990 | \ |
99c476dc IY |
991 | DEFINE_INST(OFPIT11_CLEAR_ACTIONS, \ |
992 | ofp11_instruction, false, \ | |
993 | "clear_actions") \ | |
a64f0b0f IY |
994 | \ |
995 | DEFINE_INST(OFPIT11_WRITE_ACTIONS, \ | |
996 | ofp11_instruction_actions, true, \ | |
997 | "write_actions") \ | |
998 | \ | |
99c476dc IY |
999 | DEFINE_INST(OFPIT11_WRITE_METADATA, \ |
1000 | ofp11_instruction_write_metadata, false, \ | |
1001 | "write_metadata") \ | |
a64f0b0f | 1002 | \ |
99c476dc IY |
1003 | DEFINE_INST(OFPIT11_GOTO_TABLE, \ |
1004 | ofp11_instruction_goto_table, false, \ | |
1005 | "goto_table") | |
a64f0b0f IY |
1006 | |
1007 | enum ovs_instruction_type { | |
1008 | #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) OVSINST_##ENUM, | |
1009 | OVS_INSTRUCTIONS | |
1010 | #undef DEFINE_INST | |
1011 | }; | |
1012 | ||
1013 | enum { | |
1014 | #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) + 1 | |
1015 | N_OVS_INSTRUCTIONS = OVS_INSTRUCTIONS | |
1016 | #undef DEFINE_INST | |
1017 | }; | |
1018 | ||
ba0bc9b0 BP |
1019 | const char *ovs_instruction_name_from_type(enum ovs_instruction_type type); |
1020 | int ovs_instruction_type_from_name(const char *name); | |
084c53de BP |
1021 | enum ovs_instruction_type ovs_instruction_type_from_ofpact_type( |
1022 | enum ofpact_type); | |
c0621c39 AW |
1023 | enum ofperr ovs_instruction_type_from_inst_type( |
1024 | enum ovs_instruction_type *instruction_type, const uint16_t inst_type); | |
1025 | ||
8e97815e BP |
1026 | ovs_be32 ovsinst_bitmap_to_openflow(uint32_t ovsinst_bitmap, enum ofp_version); |
1027 | uint32_t ovsinst_bitmap_from_openflow(ovs_be32 ofpit_bitmap, | |
1028 | enum ofp_version); | |
1029 | ||
f25d0cf3 | 1030 | #endif /* ofp-actions.h */ |