]>
Commit | Line | Data |
---|---|---|
f25d0cf3 | 1 | /* |
d3cb080e | 2 | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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 | #include <config.h> | |
18 | #include "ofp-actions.h" | |
f25d0cf3 BP |
19 | #include "bundle.h" |
20 | #include "byte-order.h" | |
21 | #include "compiler.h" | |
22 | #include "dynamic-string.h" | |
c2d936a4 | 23 | #include "hmap.h" |
f25d0cf3 BP |
24 | #include "learn.h" |
25 | #include "meta-flow.h" | |
26 | #include "multipath.h" | |
27 | #include "nx-match.h" | |
c2d936a4 | 28 | #include "ofp-parse.h" |
f25d0cf3 BP |
29 | #include "ofp-util.h" |
30 | #include "ofpbuf.h" | |
c2d936a4 | 31 | #include "unaligned.h" |
cb22974d | 32 | #include "util.h" |
e6211adc | 33 | #include "openvswitch/vlog.h" |
f25d0cf3 BP |
34 | |
35 | VLOG_DEFINE_THIS_MODULE(ofp_actions); | |
36 | ||
37 | static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); | |
f25d0cf3 | 38 | |
c2d936a4 BP |
39 | struct ofp_action_header; |
40 | ||
41 | /* Raw identifiers for OpenFlow actions. | |
42 | * | |
43 | * Decoding and encoding OpenFlow actions across multiple versions is difficult | |
44 | * to do in a clean, consistent way. This enumeration lays out all of the | |
45 | * forms of actions that Open vSwitch supports. | |
46 | * | |
47 | * The comments here must follow a stylized form because the | |
48 | * "extract-ofp-actions" program parses them at build time to generate data | |
49 | * tables. | |
50 | * | |
51 | * - The first part of each comment specifies the vendor, OpenFlow versions, | |
52 | * and type for each protocol that supports the action: | |
53 | * | |
54 | * # The vendor is OF for standard OpenFlow actions, NX for Nicira | |
55 | * extension actions. (Support for other vendors can be added, but | |
56 | * it can't be done just based on a vendor ID definition alone | |
57 | * because OpenFlow doesn't define a standard way to specify a | |
58 | * subtype for vendor actions, so other vendors might do it different | |
59 | * from Nicira.) | |
60 | * | |
61 | * # The version can specify a specific OpenFlow version, a version | |
62 | * range delimited by "-", or an open-ended range with "+". | |
63 | * | |
64 | * # The type, in parentheses, is the action type number (for standard | |
65 | * OpenFlow actions) or subtype (for vendor extension actions). | |
66 | * | |
67 | * # Optionally one may add "is deprecated" followed by a | |
68 | * human-readable reason in parentheses (which will be used in log | |
69 | * messages), if a particular action should no longer be used. | |
70 | * | |
71 | * Multiple such specifications may be separated by commas. | |
72 | * | |
73 | * - The second part describes the action's wire format. It may be: | |
74 | * | |
75 | * # "struct <name>": The struct fully specifies the wire format. The | |
76 | * action is exactly the size of the struct. (Thus, the struct must | |
77 | * be an exact multiple of 8 bytes in size.) | |
78 | * | |
79 | * # "struct <name>, ...": The struct specifies the beginning of the | |
80 | * wire format. An instance of the action is either the struct's | |
81 | * exact size, or a multiple of 8 bytes longer. | |
82 | * | |
83 | * # "uint<N>_t" or "ovs_be<N>": The action consists of a (standard or | |
84 | * vendor extension) header, followed by 0 or more pad bytes to align | |
85 | * to a multiple of <N> bits, followed by an argument of the given | |
86 | * type, followed by 0 or more pad bytes to bring the total action up | |
87 | * to a multiple of 8 bytes. | |
88 | * | |
89 | * # "void": The action is just a (standard or vendor extension) | |
90 | * header. | |
91 | * | |
92 | * - Optional additional text enclosed in square brackets is commentary for | |
93 | * the human reader. | |
94 | */ | |
95 | enum ofp_raw_action_type { | |
96 | /* ## ----------------- ## */ | |
97 | /* ## Standard actions. ## */ | |
98 | /* ## ----------------- ## */ | |
99 | ||
100 | /* OF1.0(0): struct ofp10_action_output. */ | |
101 | OFPAT_RAW10_OUTPUT, | |
102 | /* OF1.1+(0): struct ofp11_action_output. */ | |
103 | OFPAT_RAW11_OUTPUT, | |
104 | ||
105 | /* OF1.0(1): uint16_t. */ | |
106 | OFPAT_RAW10_SET_VLAN_VID, | |
107 | /* OF1.0(2): uint8_t. */ | |
108 | OFPAT_RAW10_SET_VLAN_PCP, | |
109 | ||
110 | /* OF1.1(1), OF1.2+(1) is deprecated (use Set-Field): uint16_t. | |
111 | * | |
112 | * [Semantics differ slightly between the 1.0 and 1.1 versions of the VLAN | |
113 | * modification actions: the 1.0 versions push a VLAN header if none is | |
114 | * present, but the 1.1 versions do not. That is the only reason that we | |
115 | * distinguish their raw action types.] */ | |
116 | OFPAT_RAW11_SET_VLAN_VID, | |
117 | /* OF1.1(2), OF1.2+(2) is deprecated (use Set-Field): uint8_t. */ | |
118 | OFPAT_RAW11_SET_VLAN_PCP, | |
119 | ||
120 | /* OF1.1+(17): ovs_be16. | |
121 | * | |
122 | * [The argument is the Ethertype, e.g. ETH_TYPE_VLAN_8021Q, not the VID or | |
123 | * TCI.] */ | |
124 | OFPAT_RAW11_PUSH_VLAN, | |
125 | ||
126 | /* OF1.0(3): void. */ | |
127 | OFPAT_RAW10_STRIP_VLAN, | |
128 | /* OF1.1+(18): void. */ | |
129 | OFPAT_RAW11_POP_VLAN, | |
130 | ||
131 | /* OF1.0(4), OF1.1(3), OF1.2+(3) is deprecated (use Set-Field): struct | |
132 | * ofp_action_dl_addr. */ | |
133 | OFPAT_RAW_SET_DL_SRC, | |
134 | ||
135 | /* OF1.0(5), OF1.1(4), OF1.2+(4) is deprecated (use Set-Field): struct | |
136 | * ofp_action_dl_addr. */ | |
137 | OFPAT_RAW_SET_DL_DST, | |
138 | ||
139 | /* OF1.0(6), OF1.1(5), OF1.2+(5) is deprecated (use Set-Field): | |
140 | * ovs_be32. */ | |
141 | OFPAT_RAW_SET_NW_SRC, | |
142 | ||
143 | /* OF1.0(7), OF1.1(6), OF1.2+(6) is deprecated (use Set-Field): | |
144 | * ovs_be32. */ | |
145 | OFPAT_RAW_SET_NW_DST, | |
146 | ||
147 | /* OF1.0(8), OF1.1(7), OF1.2+(7) is deprecated (use Set-Field): uint8_t. */ | |
148 | OFPAT_RAW_SET_NW_TOS, | |
149 | ||
150 | /* OF1.1(8), OF1.2+(8) is deprecated (use Set-Field): uint8_t. */ | |
151 | OFPAT_RAW11_SET_NW_ECN, | |
152 | ||
153 | /* OF1.0(9), OF1.1(9), OF1.2+(9) is deprecated (use Set-Field): | |
154 | * ovs_be16. */ | |
155 | OFPAT_RAW_SET_TP_SRC, | |
156 | ||
157 | /* OF1.0(10), OF1.1(10), OF1.2+(10) is deprecated (use Set-Field): | |
158 | * ovs_be16. */ | |
159 | OFPAT_RAW_SET_TP_DST, | |
160 | ||
161 | /* OF1.0(11): struct ofp10_action_enqueue. */ | |
162 | OFPAT_RAW10_ENQUEUE, | |
163 | ||
164 | /* NX1.0(30), OF1.1(13), OF1.2+(13) is deprecated (use Set-Field): | |
165 | * ovs_be32. */ | |
166 | OFPAT_RAW_SET_MPLS_LABEL, | |
167 | ||
168 | /* NX1.0(31), OF1.1(14), OF1.2+(14) is deprecated (use Set-Field): | |
169 | * uint8_t. */ | |
170 | OFPAT_RAW_SET_MPLS_TC, | |
171 | ||
172 | /* NX1.0(25), OF1.1(15), OF1.2+(15) is deprecated (use Set-Field): | |
173 | * uint8_t. */ | |
174 | OFPAT_RAW_SET_MPLS_TTL, | |
175 | ||
176 | /* NX1.0(26), OF1.1+(16): void. */ | |
177 | OFPAT_RAW_DEC_MPLS_TTL, | |
178 | ||
179 | /* NX1.0(23), OF1.1+(19): ovs_be16. | |
180 | * | |
181 | * [The argument is the Ethertype, e.g. ETH_TYPE_MPLS, not the label.] */ | |
182 | OFPAT_RAW_PUSH_MPLS, | |
183 | ||
184 | /* NX1.0(24), OF1.1+(20): ovs_be16. | |
185 | * | |
186 | * [The argument is the Ethertype, e.g. ETH_TYPE_IPV4 if at BoS or | |
187 | * ETH_TYPE_MPLS otherwise, not the label.] */ | |
188 | OFPAT_RAW_POP_MPLS, | |
189 | ||
190 | /* NX1.0(4), OF1.1+(21): uint32_t. */ | |
191 | OFPAT_RAW_SET_QUEUE, | |
192 | ||
193 | /* OF1.1+(22): uint32_t. */ | |
194 | OFPAT_RAW11_GROUP, | |
195 | ||
196 | /* OF1.1+(23): uint8_t. */ | |
197 | OFPAT_RAW11_SET_NW_TTL, | |
198 | ||
199 | /* NX1.0(18), OF1.1+(24): void. */ | |
200 | OFPAT_RAW_DEC_NW_TTL, | |
201 | /* NX1.0+(21): struct nx_action_cnt_ids, ... */ | |
202 | NXAST_RAW_DEC_TTL_CNT_IDS, | |
203 | ||
7eb4b1f1 | 204 | /* OF1.2-1.4(25): struct ofp12_action_set_field, ... */ |
c2d936a4 | 205 | OFPAT_RAW12_SET_FIELD, |
7eb4b1f1 BP |
206 | /* OF1.5+(25): struct ofp12_action_set_field, ... */ |
207 | OFPAT_RAW15_SET_FIELD, | |
208 | /* NX1.0-1.4(7): struct nx_action_reg_load. | |
209 | * | |
210 | * [In OpenFlow 1.5, set_field is a superset of reg_load functionality, so | |
211 | * we drop reg_load.] */ | |
c2d936a4 | 212 | NXAST_RAW_REG_LOAD, |
bad8a439 BP |
213 | /* NX1.0-1.4(33): struct nx_action_reg_load2, ... |
214 | * | |
215 | * [In OpenFlow 1.5, set_field is a superset of reg_load2 functionality, so | |
216 | * we drop reg_load2.] */ | |
217 | NXAST_RAW_REG_LOAD2, | |
c2d936a4 | 218 | |
f13cdd73 | 219 | /* OF1.5+(28): struct ofp15_action_copy_field, ... */ |
73178f20 | 220 | OFPAT_RAW15_COPY_FIELD, |
914624f8 BP |
221 | /* ONF1.3-1.4(3200): struct onf_action_copy_field, ... */ |
222 | ONFACT_RAW13_COPY_FIELD, | |
bad8a439 | 223 | /* NX1.0-1.4(6): struct nx_action_reg_move, ... */ |
73178f20 BP |
224 | NXAST_RAW_REG_MOVE, |
225 | ||
c2d936a4 BP |
226 | /* ## ------------------------- ## */ |
227 | /* ## Nicira extension actions. ## */ | |
228 | /* ## ------------------------- ## */ | |
229 | ||
230 | /* Actions similar to standard actions are listed with the standard actions. */ | |
231 | ||
232 | /* NX1.0+(1): uint16_t. */ | |
233 | NXAST_RAW_RESUBMIT, | |
234 | /* NX1.0+(14): struct nx_action_resubmit. */ | |
235 | NXAST_RAW_RESUBMIT_TABLE, | |
236 | ||
237 | /* NX1.0+(2): uint32_t. */ | |
238 | NXAST_RAW_SET_TUNNEL, | |
239 | /* NX1.0+(9): uint64_t. */ | |
240 | NXAST_RAW_SET_TUNNEL64, | |
241 | ||
242 | /* NX1.0+(5): void. */ | |
243 | NXAST_RAW_POP_QUEUE, | |
244 | ||
c2d936a4 BP |
245 | /* NX1.0+(8): struct nx_action_note, ... */ |
246 | NXAST_RAW_NOTE, | |
247 | ||
248 | /* NX1.0+(10): struct nx_action_multipath. */ | |
249 | NXAST_RAW_MULTIPATH, | |
250 | ||
251 | /* NX1.0+(12): struct nx_action_bundle, ... */ | |
252 | NXAST_RAW_BUNDLE, | |
253 | /* NX1.0+(13): struct nx_action_bundle, ... */ | |
254 | NXAST_RAW_BUNDLE_LOAD, | |
255 | ||
256 | /* NX1.0+(15): struct nx_action_output_reg. */ | |
257 | NXAST_RAW_OUTPUT_REG, | |
bad8a439 BP |
258 | /* NX1.0+(32): struct nx_action_output_reg2. */ |
259 | NXAST_RAW_OUTPUT_REG2, | |
c2d936a4 BP |
260 | |
261 | /* NX1.0+(16): struct nx_action_learn, ... */ | |
262 | NXAST_RAW_LEARN, | |
263 | ||
264 | /* NX1.0+(17): void. */ | |
265 | NXAST_RAW_EXIT, | |
266 | ||
267 | /* NX1.0+(19): struct nx_action_fin_timeout. */ | |
268 | NXAST_RAW_FIN_TIMEOUT, | |
269 | ||
270 | /* NX1.0+(20): struct nx_action_controller. */ | |
271 | NXAST_RAW_CONTROLLER, | |
272 | ||
273 | /* NX1.0+(22): struct nx_action_write_metadata. */ | |
274 | NXAST_RAW_WRITE_METADATA, | |
275 | ||
276 | /* NX1.0+(27): struct nx_action_stack. */ | |
277 | NXAST_RAW_STACK_PUSH, | |
278 | ||
279 | /* NX1.0+(28): struct nx_action_stack. */ | |
280 | NXAST_RAW_STACK_POP, | |
281 | ||
282 | /* NX1.0+(29): struct nx_action_sample. */ | |
283 | NXAST_RAW_SAMPLE, | |
18080541 BP |
284 | |
285 | /* NX1.0+(34): struct nx_action_conjunction. */ | |
286 | NXAST_RAW_CONJUNCTION, | |
c2d936a4 BP |
287 | }; |
288 | ||
289 | /* OpenFlow actions are always a multiple of 8 bytes in length. */ | |
290 | #define OFP_ACTION_ALIGN 8 | |
291 | ||
292 | /* Define a few functions for working with instructions. */ | |
293 | #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \ | |
294 | static inline const struct STRUCT * OVS_UNUSED \ | |
295 | instruction_get_##ENUM(const struct ofp11_instruction *inst)\ | |
296 | { \ | |
297 | ovs_assert(inst->type == htons(ENUM)); \ | |
298 | return ALIGNED_CAST(struct STRUCT *, inst); \ | |
299 | } \ | |
300 | \ | |
301 | static inline void OVS_UNUSED \ | |
302 | instruction_init_##ENUM(struct STRUCT *s) \ | |
303 | { \ | |
304 | memset(s, 0, sizeof *s); \ | |
305 | s->type = htons(ENUM); \ | |
306 | s->len = htons(sizeof *s); \ | |
307 | } \ | |
308 | \ | |
309 | static inline struct STRUCT * OVS_UNUSED \ | |
310 | instruction_put_##ENUM(struct ofpbuf *buf) \ | |
311 | { \ | |
312 | struct STRUCT *s = ofpbuf_put_uninit(buf, sizeof *s); \ | |
313 | instruction_init_##ENUM(s); \ | |
314 | return s; \ | |
315 | } | |
316 | OVS_INSTRUCTIONS | |
317 | #undef DEFINE_INST | |
318 | ||
319 | static void ofpacts_update_instruction_actions(struct ofpbuf *openflow, | |
320 | size_t ofs); | |
178742f9 | 321 | static void pad_ofpat(struct ofpbuf *openflow, size_t start_ofs); |
c2d936a4 BP |
322 | |
323 | static enum ofperr ofpacts_verify(const struct ofpact[], size_t ofpacts_len, | |
324 | uint32_t allowed_ovsinsts); | |
325 | ||
326 | static void ofpact_put_set_field(struct ofpbuf *openflow, enum ofp_version, | |
327 | enum mf_field_id, uint64_t value); | |
328 | ||
329 | static enum ofperr ofpact_pull_raw(struct ofpbuf *, enum ofp_version, | |
330 | enum ofp_raw_action_type *, uint64_t *arg); | |
331 | static void *ofpact_put_raw(struct ofpbuf *, enum ofp_version, | |
332 | enum ofp_raw_action_type, uint64_t arg); | |
333 | ||
cab50449 | 334 | static char *OVS_WARN_UNUSED_RESULT ofpacts_parse( |
c2d936a4 BP |
335 | char *str, struct ofpbuf *ofpacts, enum ofputil_protocol *usable_protocols, |
336 | bool allow_instructions); | |
337 | ||
338 | #include "ofp-actions.inc1" | |
339 | \f | |
340 | /* Output actions. */ | |
341 | ||
342 | /* Action structure for OFPAT10_OUTPUT, which sends packets out 'port'. | |
343 | * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max | |
344 | * number of bytes to send. A 'max_len' of zero means no bytes of the | |
345 | * packet should be sent. */ | |
346 | struct ofp10_action_output { | |
347 | ovs_be16 type; /* OFPAT10_OUTPUT. */ | |
348 | ovs_be16 len; /* Length is 8. */ | |
349 | ovs_be16 port; /* Output port. */ | |
350 | ovs_be16 max_len; /* Max length to send to controller. */ | |
e45e72f1 | 351 | }; |
c2d936a4 BP |
352 | OFP_ASSERT(sizeof(struct ofp10_action_output) == 8); |
353 | ||
354 | /* Action structure for OFPAT_OUTPUT, which sends packets out 'port'. | |
355 | * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max | |
356 | * number of bytes to send. A 'max_len' of zero means no bytes of the | |
357 | * packet should be sent.*/ | |
358 | struct ofp11_action_output { | |
359 | ovs_be16 type; /* OFPAT11_OUTPUT. */ | |
360 | ovs_be16 len; /* Length is 16. */ | |
361 | ovs_be32 port; /* Output port. */ | |
362 | ovs_be16 max_len; /* Max length to send to controller. */ | |
363 | uint8_t pad[6]; /* Pad to 64 bits. */ | |
364 | }; | |
365 | OFP_ASSERT(sizeof(struct ofp11_action_output) == 16); | |
e45e72f1 | 366 | |
f25d0cf3 | 367 | static enum ofperr |
c2d936a4 BP |
368 | decode_OFPAT_RAW10_OUTPUT(const struct ofp10_action_output *oao, |
369 | struct ofpbuf *out) | |
f25d0cf3 BP |
370 | { |
371 | struct ofpact_output *output; | |
372 | ||
373 | output = ofpact_put_OUTPUT(out); | |
4e022ec0 | 374 | output->port = u16_to_ofp(ntohs(oao->port)); |
f25d0cf3 BP |
375 | output->max_len = ntohs(oao->max_len); |
376 | ||
57ad4e9e | 377 | return ofpact_check_output_port(output->port, OFPP_MAX); |
f25d0cf3 BP |
378 | } |
379 | ||
380 | static enum ofperr | |
c2d936a4 BP |
381 | decode_OFPAT_RAW11_OUTPUT(const struct ofp11_action_output *oao, |
382 | struct ofpbuf *out) | |
f25d0cf3 | 383 | { |
c2d936a4 BP |
384 | struct ofpact_output *output; |
385 | enum ofperr error; | |
f25d0cf3 | 386 | |
c2d936a4 BP |
387 | output = ofpact_put_OUTPUT(out); |
388 | output->max_len = ntohs(oao->max_len); | |
389 | ||
390 | error = ofputil_port_from_ofp11(oao->port, &output->port); | |
391 | if (error) { | |
392 | return error; | |
f25d0cf3 | 393 | } |
c2d936a4 BP |
394 | |
395 | return ofpact_check_output_port(output->port, OFPP_MAX); | |
f25d0cf3 BP |
396 | } |
397 | ||
398 | static void | |
c2d936a4 BP |
399 | encode_OUTPUT(const struct ofpact_output *output, |
400 | enum ofp_version ofp_version, struct ofpbuf *out) | |
f25d0cf3 | 401 | { |
c2d936a4 BP |
402 | if (ofp_version == OFP10_VERSION) { |
403 | struct ofp10_action_output *oao; | |
f25d0cf3 | 404 | |
c2d936a4 BP |
405 | oao = put_OFPAT10_OUTPUT(out); |
406 | oao->port = htons(ofp_to_u16(output->port)); | |
407 | oao->max_len = htons(output->max_len); | |
408 | } else { | |
409 | struct ofp11_action_output *oao; | |
410 | ||
411 | oao = put_OFPAT11_OUTPUT(out); | |
412 | oao->port = ofputil_port_to_ofp11(output->port); | |
413 | oao->max_len = htons(output->max_len); | |
414 | } | |
f25d0cf3 BP |
415 | } |
416 | ||
cab50449 | 417 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
418 | parse_OUTPUT(const char *arg, struct ofpbuf *ofpacts, |
419 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
f25d0cf3 | 420 | { |
c2d936a4 BP |
421 | if (strchr(arg, '[')) { |
422 | struct ofpact_output_reg *output_reg; | |
f25d0cf3 | 423 | |
c2d936a4 BP |
424 | output_reg = ofpact_put_OUTPUT_REG(ofpacts); |
425 | output_reg->max_len = UINT16_MAX; | |
426 | return mf_parse_subfield(&output_reg->src, arg); | |
427 | } else { | |
428 | struct ofpact_output *output; | |
429 | ||
430 | output = ofpact_put_OUTPUT(ofpacts); | |
431 | if (!ofputil_port_from_string(arg, &output->port)) { | |
432 | return xasprintf("%s: output to unknown port", arg); | |
433 | } | |
434 | output->max_len = output->port == OFPP_CONTROLLER ? UINT16_MAX : 0; | |
435 | return NULL; | |
f25d0cf3 | 436 | } |
c2d936a4 | 437 | } |
f25d0cf3 | 438 | |
c2d936a4 BP |
439 | static void |
440 | format_OUTPUT(const struct ofpact_output *a, struct ds *s) | |
441 | { | |
442 | if (ofp_to_u16(a->port) < ofp_to_u16(OFPP_MAX)) { | |
443 | ds_put_format(s, "output:%"PRIu16, a->port); | |
444 | } else { | |
445 | ofputil_format_port(a->port, s); | |
446 | if (a->port == OFPP_CONTROLLER) { | |
447 | ds_put_format(s, ":%"PRIu16, a->max_len); | |
448 | } | |
449 | } | |
f25d0cf3 | 450 | } |
c2d936a4 BP |
451 | \f |
452 | /* Group actions. */ | |
f25d0cf3 BP |
453 | |
454 | static enum ofperr | |
c2d936a4 | 455 | decode_OFPAT_RAW11_GROUP(uint32_t group_id, struct ofpbuf *out) |
f25d0cf3 | 456 | { |
c2d936a4 BP |
457 | ofpact_put_GROUP(out)->group_id = group_id; |
458 | return 0; | |
459 | } | |
f25d0cf3 | 460 | |
c2d936a4 BP |
461 | static void |
462 | encode_GROUP(const struct ofpact_group *group, | |
463 | enum ofp_version ofp_version, struct ofpbuf *out) | |
464 | { | |
465 | if (ofp_version == OFP10_VERSION) { | |
466 | /* XXX */ | |
467 | } else { | |
468 | put_OFPAT11_GROUP(out, group->group_id); | |
f25d0cf3 | 469 | } |
c2d936a4 | 470 | } |
f25d0cf3 | 471 | |
cab50449 | 472 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
473 | parse_GROUP(char *arg, struct ofpbuf *ofpacts, |
474 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
475 | { | |
476 | return str_to_u32(arg, &ofpact_put_GROUP(ofpacts)->group_id); | |
f25d0cf3 BP |
477 | } |
478 | ||
479 | static void | |
c2d936a4 | 480 | format_GROUP(const struct ofpact_group *a, struct ds *s) |
f25d0cf3 | 481 | { |
c2d936a4 | 482 | ds_put_format(s, "group:%"PRIu32, a->group_id); |
f25d0cf3 | 483 | } |
c2d936a4 BP |
484 | \f |
485 | /* Action structure for NXAST_CONTROLLER. | |
486 | * | |
487 | * This generalizes using OFPAT_OUTPUT to send a packet to OFPP_CONTROLLER. In | |
488 | * addition to the 'max_len' that OFPAT_OUTPUT supports, it also allows | |
489 | * specifying: | |
490 | * | |
491 | * - 'reason': The reason code to use in the ofp_packet_in or nx_packet_in. | |
492 | * | |
493 | * - 'controller_id': The ID of the controller connection to which the | |
494 | * ofp_packet_in should be sent. The ofp_packet_in or nx_packet_in is | |
495 | * sent only to controllers that have the specified controller connection | |
496 | * ID. See "struct nx_controller_id" for more information. */ | |
497 | struct nx_action_controller { | |
498 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
499 | ovs_be16 len; /* Length is 16. */ | |
500 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
501 | ovs_be16 subtype; /* NXAST_CONTROLLER. */ | |
502 | ovs_be16 max_len; /* Maximum length to send to controller. */ | |
503 | ovs_be16 controller_id; /* Controller ID to send packet-in. */ | |
504 | uint8_t reason; /* enum ofp_packet_in_reason (OFPR_*). */ | |
505 | uint8_t zero; /* Must be zero. */ | |
506 | }; | |
507 | OFP_ASSERT(sizeof(struct nx_action_controller) == 16); | |
f25d0cf3 | 508 | |
c2d936a4 BP |
509 | static enum ofperr |
510 | decode_NXAST_RAW_CONTROLLER(const struct nx_action_controller *nac, | |
511 | struct ofpbuf *out) | |
f25d0cf3 BP |
512 | { |
513 | struct ofpact_controller *oc; | |
514 | ||
515 | oc = ofpact_put_CONTROLLER(out); | |
516 | oc->max_len = ntohs(nac->max_len); | |
517 | oc->controller_id = ntohs(nac->controller_id); | |
518 | oc->reason = nac->reason; | |
c2d936a4 | 519 | return 0; |
f25d0cf3 BP |
520 | } |
521 | ||
c2d936a4 BP |
522 | static void |
523 | encode_CONTROLLER(const struct ofpact_controller *controller, | |
524 | enum ofp_version ofp_version OVS_UNUSED, | |
525 | struct ofpbuf *out) | |
4cceacb9 | 526 | { |
c2d936a4 | 527 | struct nx_action_controller *nac; |
4cceacb9 | 528 | |
c2d936a4 BP |
529 | nac = put_NXAST_CONTROLLER(out); |
530 | nac->max_len = htons(controller->max_len); | |
531 | nac->controller_id = htons(controller->controller_id); | |
532 | nac->reason = controller->reason; | |
533 | } | |
534 | ||
cab50449 | 535 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
536 | parse_CONTROLLER(char *arg, struct ofpbuf *ofpacts, |
537 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
538 | { | |
539 | enum ofp_packet_in_reason reason = OFPR_ACTION; | |
540 | uint16_t controller_id = 0; | |
541 | uint16_t max_len = UINT16_MAX; | |
542 | ||
543 | if (!arg[0]) { | |
544 | /* Use defaults. */ | |
545 | } else if (strspn(arg, "0123456789") == strlen(arg)) { | |
546 | char *error = str_to_u16(arg, "max_len", &max_len); | |
547 | if (error) { | |
548 | return error; | |
549 | } | |
550 | } else { | |
551 | char *name, *value; | |
552 | ||
553 | while (ofputil_parse_key_value(&arg, &name, &value)) { | |
554 | if (!strcmp(name, "reason")) { | |
555 | if (!ofputil_packet_in_reason_from_string(value, &reason)) { | |
556 | return xasprintf("unknown reason \"%s\"", value); | |
557 | } | |
558 | } else if (!strcmp(name, "max_len")) { | |
559 | char *error = str_to_u16(value, "max_len", &max_len); | |
560 | if (error) { | |
561 | return error; | |
562 | } | |
563 | } else if (!strcmp(name, "id")) { | |
564 | char *error = str_to_u16(value, "id", &controller_id); | |
565 | if (error) { | |
566 | return error; | |
567 | } | |
568 | } else { | |
569 | return xasprintf("unknown key \"%s\" parsing controller " | |
570 | "action", name); | |
571 | } | |
572 | } | |
4cceacb9 JS |
573 | } |
574 | ||
c2d936a4 BP |
575 | if (reason == OFPR_ACTION && controller_id == 0) { |
576 | struct ofpact_output *output; | |
4cceacb9 | 577 | |
c2d936a4 BP |
578 | output = ofpact_put_OUTPUT(ofpacts); |
579 | output->port = OFPP_CONTROLLER; | |
580 | output->max_len = max_len; | |
581 | } else { | |
582 | struct ofpact_controller *controller; | |
583 | ||
584 | controller = ofpact_put_CONTROLLER(ofpacts); | |
585 | controller->max_len = max_len; | |
586 | controller->reason = reason; | |
587 | controller->controller_id = controller_id; | |
588 | } | |
589 | ||
590 | return NULL; | |
4cceacb9 JS |
591 | } |
592 | ||
f25d0cf3 | 593 | static void |
c2d936a4 | 594 | format_CONTROLLER(const struct ofpact_controller *a, struct ds *s) |
f25d0cf3 | 595 | { |
c2d936a4 BP |
596 | if (a->reason == OFPR_ACTION && a->controller_id == 0) { |
597 | ds_put_format(s, "CONTROLLER:%"PRIu16, a->max_len); | |
598 | } else { | |
599 | enum ofp_packet_in_reason reason = a->reason; | |
f25d0cf3 | 600 | |
c2d936a4 BP |
601 | ds_put_cstr(s, "controller("); |
602 | if (reason != OFPR_ACTION) { | |
603 | char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE]; | |
604 | ||
605 | ds_put_format(s, "reason=%s,", | |
606 | ofputil_packet_in_reason_to_string( | |
607 | reason, reasonbuf, sizeof reasonbuf)); | |
608 | } | |
609 | if (a->max_len != UINT16_MAX) { | |
610 | ds_put_format(s, "max_len=%"PRIu16",", a->max_len); | |
611 | } | |
612 | if (a->controller_id != 0) { | |
613 | ds_put_format(s, "id=%"PRIu16",", a->controller_id); | |
614 | } | |
615 | ds_chomp(s, ','); | |
616 | ds_put_char(s, ')'); | |
617 | } | |
f25d0cf3 | 618 | } |
c2d936a4 BP |
619 | \f |
620 | /* Enqueue action. */ | |
621 | struct ofp10_action_enqueue { | |
622 | ovs_be16 type; /* OFPAT10_ENQUEUE. */ | |
623 | ovs_be16 len; /* Len is 16. */ | |
624 | ovs_be16 port; /* Port that queue belongs. Should | |
625 | refer to a valid physical port | |
626 | (i.e. < OFPP_MAX) or OFPP_IN_PORT. */ | |
627 | uint8_t pad[6]; /* Pad for 64-bit alignment. */ | |
628 | ovs_be32 queue_id; /* Where to enqueue the packets. */ | |
629 | }; | |
630 | OFP_ASSERT(sizeof(struct ofp10_action_enqueue) == 16); | |
f25d0cf3 | 631 | |
c2d967a5 | 632 | static enum ofperr |
c2d936a4 BP |
633 | decode_OFPAT_RAW10_ENQUEUE(const struct ofp10_action_enqueue *oae, |
634 | struct ofpbuf *out) | |
c2d967a5 | 635 | { |
c2d936a4 | 636 | struct ofpact_enqueue *enqueue; |
c2d967a5 | 637 | |
c2d936a4 BP |
638 | enqueue = ofpact_put_ENQUEUE(out); |
639 | enqueue->port = u16_to_ofp(ntohs(oae->port)); | |
640 | enqueue->queue = ntohl(oae->queue_id); | |
641 | if (ofp_to_u16(enqueue->port) >= ofp_to_u16(OFPP_MAX) | |
642 | && enqueue->port != OFPP_IN_PORT | |
643 | && enqueue->port != OFPP_LOCAL) { | |
644 | return OFPERR_OFPBAC_BAD_OUT_PORT; | |
645 | } | |
646 | return 0; | |
c2d967a5 MM |
647 | } |
648 | ||
c2d936a4 BP |
649 | static void |
650 | encode_ENQUEUE(const struct ofpact_enqueue *enqueue, | |
651 | enum ofp_version ofp_version, struct ofpbuf *out) | |
c2d967a5 | 652 | { |
c2d936a4 BP |
653 | if (ofp_version == OFP10_VERSION) { |
654 | struct ofp10_action_enqueue *oae; | |
c2d967a5 | 655 | |
c2d936a4 BP |
656 | oae = put_OFPAT10_ENQUEUE(out); |
657 | oae->port = htons(ofp_to_u16(enqueue->port)); | |
658 | oae->queue_id = htonl(enqueue->queue); | |
659 | } else { | |
660 | /* XXX */ | |
c2d967a5 | 661 | } |
c2d936a4 | 662 | } |
c2d967a5 | 663 | |
cab50449 | 664 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
665 | parse_ENQUEUE(char *arg, struct ofpbuf *ofpacts, |
666 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
667 | { | |
668 | char *sp = NULL; | |
669 | char *port = strtok_r(arg, ":q,", &sp); | |
670 | char *queue = strtok_r(NULL, "", &sp); | |
671 | struct ofpact_enqueue *enqueue; | |
c2d967a5 | 672 | |
c2d936a4 BP |
673 | if (port == NULL || queue == NULL) { |
674 | return xstrdup("\"enqueue\" syntax is \"enqueue:PORT:QUEUE\" or " | |
675 | "\"enqueue(PORT,QUEUE)\""); | |
c2d967a5 MM |
676 | } |
677 | ||
c2d936a4 BP |
678 | enqueue = ofpact_put_ENQUEUE(ofpacts); |
679 | if (!ofputil_port_from_string(port, &enqueue->port)) { | |
680 | return xasprintf("%s: enqueue to unknown port", port); | |
681 | } | |
682 | return str_to_u32(queue, &enqueue->queue); | |
c2d967a5 MM |
683 | } |
684 | ||
c2d936a4 BP |
685 | static void |
686 | format_ENQUEUE(const struct ofpact_enqueue *a, struct ds *s) | |
29089a54 | 687 | { |
c2d936a4 BP |
688 | ds_put_format(s, "enqueue:"); |
689 | ofputil_format_port(a->port, s); | |
690 | ds_put_format(s, ":%"PRIu32, a->queue); | |
691 | } | |
692 | \f | |
693 | /* Action structure for NXAST_OUTPUT_REG. | |
694 | * | |
695 | * Outputs to the OpenFlow port number written to src[ofs:ofs+nbits]. | |
696 | * | |
697 | * The format and semantics of 'src' and 'ofs_nbits' are similar to those for | |
698 | * the NXAST_REG_LOAD action. | |
699 | * | |
700 | * The acceptable nxm_header values for 'src' are the same as the acceptable | |
701 | * nxm_header values for the 'src' field of NXAST_REG_MOVE. | |
702 | * | |
703 | * The 'max_len' field indicates the number of bytes to send when the chosen | |
704 | * port is OFPP_CONTROLLER. Its semantics are equivalent to the 'max_len' | |
705 | * field of OFPAT_OUTPUT. | |
706 | * | |
707 | * The 'zero' field is required to be zeroed for forward compatibility. */ | |
708 | struct nx_action_output_reg { | |
709 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
710 | ovs_be16 len; /* 24. */ | |
711 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
712 | ovs_be16 subtype; /* NXAST_OUTPUT_REG. */ | |
29089a54 | 713 | |
c2d936a4 BP |
714 | ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */ |
715 | ovs_be32 src; /* Source. */ | |
29089a54 | 716 | |
c2d936a4 | 717 | ovs_be16 max_len; /* Max length to send to controller. */ |
29089a54 | 718 | |
c2d936a4 BP |
719 | uint8_t zero[6]; /* Reserved, must be zero. */ |
720 | }; | |
721 | OFP_ASSERT(sizeof(struct nx_action_output_reg) == 24); | |
29089a54 | 722 | |
bad8a439 BP |
723 | /* Action structure for NXAST_OUTPUT_REG2. |
724 | * | |
725 | * Like the NXAST_OUTPUT_REG but organized so that there is room for a 64-bit | |
726 | * experimenter OXM as 'src'. | |
727 | */ | |
728 | struct nx_action_output_reg2 { | |
729 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
730 | ovs_be16 len; /* 24. */ | |
731 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
732 | ovs_be16 subtype; /* NXAST_OUTPUT_REG2. */ | |
733 | ||
734 | ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */ | |
735 | ovs_be16 max_len; /* Max length to send to controller. */ | |
736 | ||
737 | /* Followed by: | |
738 | * - 'src', as an OXM/NXM header (either 4 or 8 bytes). | |
739 | * - Enough 0-bytes to pad the action out to 24 bytes. */ | |
740 | uint8_t pad[10]; | |
741 | }; | |
742 | OFP_ASSERT(sizeof(struct nx_action_output_reg2) == 24); | |
743 | ||
a7a2d006 | 744 | static enum ofperr |
c2d936a4 BP |
745 | decode_NXAST_RAW_OUTPUT_REG(const struct nx_action_output_reg *naor, |
746 | struct ofpbuf *out) | |
a7a2d006 | 747 | { |
c2d936a4 | 748 | struct ofpact_output_reg *output_reg; |
a7a2d006 | 749 | |
c2d936a4 | 750 | if (!is_all_zeros(naor->zero, sizeof naor->zero)) { |
a7a2d006 JS |
751 | return OFPERR_OFPBAC_BAD_ARGUMENT; |
752 | } | |
a7a2d006 | 753 | |
c2d936a4 | 754 | output_reg = ofpact_put_OUTPUT_REG(out); |
bad8a439 | 755 | output_reg->ofpact.raw = NXAST_RAW_OUTPUT_REG; |
c2d936a4 BP |
756 | output_reg->src.field = mf_from_nxm_header(ntohl(naor->src)); |
757 | output_reg->src.ofs = nxm_decode_ofs(naor->ofs_nbits); | |
758 | output_reg->src.n_bits = nxm_decode_n_bits(naor->ofs_nbits); | |
759 | output_reg->max_len = ntohs(naor->max_len); | |
760 | ||
761 | return mf_check_src(&output_reg->src, NULL); | |
a7a2d006 JS |
762 | } |
763 | ||
bad8a439 BP |
764 | static enum ofperr |
765 | decode_NXAST_RAW_OUTPUT_REG2(const struct nx_action_output_reg2 *naor, | |
766 | struct ofpbuf *out) | |
767 | { | |
768 | struct ofpact_output_reg *output_reg; | |
769 | enum ofperr error; | |
770 | struct ofpbuf b; | |
771 | ||
772 | output_reg = ofpact_put_OUTPUT_REG(out); | |
773 | output_reg->ofpact.raw = NXAST_RAW_OUTPUT_REG2; | |
774 | output_reg->src.ofs = nxm_decode_ofs(naor->ofs_nbits); | |
775 | output_reg->src.n_bits = nxm_decode_n_bits(naor->ofs_nbits); | |
776 | output_reg->max_len = ntohs(naor->max_len); | |
777 | ||
778 | ofpbuf_use_const(&b, naor, ntohs(naor->len)); | |
779 | ofpbuf_pull(&b, OBJECT_OFFSETOF(naor, pad)); | |
780 | error = nx_pull_header(&b, &output_reg->src.field, NULL); | |
781 | if (error) { | |
782 | return error; | |
783 | } | |
6fd6ed71 | 784 | if (!is_all_zeros(b.data, b.size)) { |
bad8a439 BP |
785 | return OFPERR_NXBRC_MUST_BE_ZERO; |
786 | } | |
787 | ||
788 | return mf_check_src(&output_reg->src, NULL); | |
789 | } | |
790 | ||
c2d936a4 BP |
791 | static void |
792 | encode_OUTPUT_REG(const struct ofpact_output_reg *output_reg, | |
793 | enum ofp_version ofp_version OVS_UNUSED, | |
794 | struct ofpbuf *out) | |
f25d0cf3 | 795 | { |
bad8a439 BP |
796 | /* If 'output_reg' came in as an NXAST_RAW_OUTPUT_REG2 action, or if it |
797 | * cannot be encoded in the older form, encode it as | |
798 | * NXAST_RAW_OUTPUT_REG2. */ | |
799 | if (output_reg->ofpact.raw == NXAST_RAW_OUTPUT_REG2 | |
800 | || !mf_nxm_header(output_reg->src.field->id)) { | |
801 | struct nx_action_output_reg2 *naor = put_NXAST_OUTPUT_REG2(out); | |
6fd6ed71 | 802 | size_t size = out->size; |
bad8a439 BP |
803 | |
804 | naor->ofs_nbits = nxm_encode_ofs_nbits(output_reg->src.ofs, | |
805 | output_reg->src.n_bits); | |
806 | naor->max_len = htons(output_reg->max_len); | |
807 | ||
6fd6ed71 | 808 | out->size = size - sizeof naor->pad; |
bad8a439 | 809 | nx_put_header(out, output_reg->src.field->id, 0, false); |
6fd6ed71 | 810 | out->size = size; |
bad8a439 BP |
811 | } else { |
812 | struct nx_action_output_reg *naor = put_NXAST_OUTPUT_REG(out); | |
f25d0cf3 | 813 | |
bad8a439 BP |
814 | naor->ofs_nbits = nxm_encode_ofs_nbits(output_reg->src.ofs, |
815 | output_reg->src.n_bits); | |
816 | naor->src = htonl(mf_nxm_header(output_reg->src.field->id)); | |
817 | naor->max_len = htons(output_reg->max_len); | |
818 | } | |
f25d0cf3 BP |
819 | } |
820 | ||
cab50449 | 821 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
822 | parse_OUTPUT_REG(const char *arg, struct ofpbuf *ofpacts, |
823 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
f25d0cf3 | 824 | { |
c2d936a4 | 825 | return parse_OUTPUT(arg, ofpacts, usable_protocols); |
f25d0cf3 BP |
826 | } |
827 | ||
c2d936a4 BP |
828 | static void |
829 | format_OUTPUT_REG(const struct ofpact_output_reg *a, struct ds *s) | |
f25d0cf3 | 830 | { |
c2d936a4 BP |
831 | ds_put_cstr(s, "output:"); |
832 | mf_format_subfield(&a->src, s); | |
833 | } | |
834 | \f | |
835 | /* Action structure for NXAST_BUNDLE and NXAST_BUNDLE_LOAD. | |
836 | * | |
837 | * The bundle actions choose a slave from a supplied list of options. | |
838 | * NXAST_BUNDLE outputs to its selection. NXAST_BUNDLE_LOAD writes its | |
839 | * selection to a register. | |
840 | * | |
841 | * The list of possible slaves follows the nx_action_bundle structure. The size | |
842 | * of each slave is governed by its type as indicated by the 'slave_type' | |
843 | * parameter. The list of slaves should be padded at its end with zeros to make | |
844 | * the total length of the action a multiple of 8. | |
845 | * | |
846 | * Switches infer from the 'slave_type' parameter the size of each slave. All | |
847 | * implementations must support the NXM_OF_IN_PORT 'slave_type' which indicates | |
848 | * that the slaves are OpenFlow port numbers with NXM_LENGTH(NXM_OF_IN_PORT) == | |
849 | * 2 byte width. Switches should reject actions which indicate unknown or | |
850 | * unsupported slave types. | |
851 | * | |
852 | * Switches use a strategy dictated by the 'algorithm' parameter to choose a | |
853 | * slave. If the switch does not support the specified 'algorithm' parameter, | |
854 | * it should reject the action. | |
855 | * | |
856 | * Several algorithms take into account liveness when selecting slaves. The | |
857 | * liveness of a slave is implementation defined (with one exception), but will | |
858 | * generally take into account things like its carrier status and the results | |
859 | * of any link monitoring protocols which happen to be running on it. In order | |
860 | * to give controllers a place-holder value, the OFPP_NONE port is always | |
861 | * considered live. | |
862 | * | |
863 | * Some slave selection strategies require the use of a hash function, in which | |
864 | * case the 'fields' and 'basis' parameters should be populated. The 'fields' | |
865 | * parameter (one of NX_HASH_FIELDS_*) designates which parts of the flow to | |
866 | * hash. Refer to the definition of "enum nx_hash_fields" for details. The | |
867 | * 'basis' parameter is used as a universal hash parameter. Different values | |
868 | * of 'basis' yield different hash results. | |
869 | * | |
870 | * The 'zero' parameter at the end of the action structure is reserved for | |
871 | * future use. Switches are required to reject actions which have nonzero | |
872 | * bytes in the 'zero' field. | |
873 | * | |
874 | * NXAST_BUNDLE actions should have 'ofs_nbits' and 'dst' zeroed. Switches | |
875 | * should reject actions which have nonzero bytes in either of these fields. | |
876 | * | |
877 | * NXAST_BUNDLE_LOAD stores the OpenFlow port number of the selected slave in | |
878 | * dst[ofs:ofs+n_bits]. The format and semantics of 'dst' and 'ofs_nbits' are | |
879 | * similar to those for the NXAST_REG_LOAD action. */ | |
880 | struct nx_action_bundle { | |
881 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
882 | ovs_be16 len; /* Length including slaves. */ | |
883 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
884 | ovs_be16 subtype; /* NXAST_BUNDLE or NXAST_BUNDLE_LOAD. */ | |
f25d0cf3 | 885 | |
c2d936a4 BP |
886 | /* Slave choice algorithm to apply to hash value. */ |
887 | ovs_be16 algorithm; /* One of NX_BD_ALG_*. */ | |
4cceacb9 | 888 | |
c2d936a4 BP |
889 | /* What fields to hash and how. */ |
890 | ovs_be16 fields; /* One of NX_HASH_FIELDS_*. */ | |
891 | ovs_be16 basis; /* Universal hash parameter. */ | |
f25d0cf3 | 892 | |
c2d936a4 BP |
893 | ovs_be32 slave_type; /* NXM_OF_IN_PORT. */ |
894 | ovs_be16 n_slaves; /* Number of slaves. */ | |
f25d0cf3 | 895 | |
c2d936a4 BP |
896 | ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */ |
897 | ovs_be32 dst; /* Destination. */ | |
f25d0cf3 | 898 | |
c2d936a4 BP |
899 | uint8_t zero[4]; /* Reserved. Must be zero. */ |
900 | }; | |
901 | OFP_ASSERT(sizeof(struct nx_action_bundle) == 32); | |
f25d0cf3 | 902 | |
c2d936a4 BP |
903 | static enum ofperr |
904 | decode_bundle(bool load, const struct nx_action_bundle *nab, | |
905 | struct ofpbuf *ofpacts) | |
906 | { | |
907 | static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); | |
908 | struct ofpact_bundle *bundle; | |
909 | uint32_t slave_type; | |
910 | size_t slaves_size, i; | |
911 | enum ofperr error; | |
bd85dac1 | 912 | |
c2d936a4 BP |
913 | bundle = ofpact_put_BUNDLE(ofpacts); |
914 | ||
915 | bundle->n_slaves = ntohs(nab->n_slaves); | |
916 | bundle->basis = ntohs(nab->basis); | |
917 | bundle->fields = ntohs(nab->fields); | |
918 | bundle->algorithm = ntohs(nab->algorithm); | |
919 | slave_type = ntohl(nab->slave_type); | |
920 | slaves_size = ntohs(nab->len) - sizeof *nab; | |
921 | ||
922 | error = OFPERR_OFPBAC_BAD_ARGUMENT; | |
923 | if (!flow_hash_fields_valid(bundle->fields)) { | |
924 | VLOG_WARN_RL(&rl, "unsupported fields %d", (int) bundle->fields); | |
925 | } else if (bundle->n_slaves > BUNDLE_MAX_SLAVES) { | |
926 | VLOG_WARN_RL(&rl, "too many slaves"); | |
927 | } else if (bundle->algorithm != NX_BD_ALG_HRW | |
928 | && bundle->algorithm != NX_BD_ALG_ACTIVE_BACKUP) { | |
929 | VLOG_WARN_RL(&rl, "unsupported algorithm %d", (int) bundle->algorithm); | |
508a9338 | 930 | } else if (slave_type != mf_nxm_header(MFF_IN_PORT)) { |
c2d936a4 BP |
931 | VLOG_WARN_RL(&rl, "unsupported slave type %"PRIu16, slave_type); |
932 | } else { | |
933 | error = 0; | |
934 | } | |
bd85dac1 | 935 | |
c2d936a4 BP |
936 | if (!is_all_zeros(nab->zero, sizeof nab->zero)) { |
937 | VLOG_WARN_RL(&rl, "reserved field is nonzero"); | |
938 | error = OFPERR_OFPBAC_BAD_ARGUMENT; | |
939 | } | |
f25d0cf3 | 940 | |
c2d936a4 BP |
941 | if (load) { |
942 | bundle->dst.field = mf_from_nxm_header(ntohl(nab->dst)); | |
943 | bundle->dst.ofs = nxm_decode_ofs(nab->ofs_nbits); | |
944 | bundle->dst.n_bits = nxm_decode_n_bits(nab->ofs_nbits); | |
f25d0cf3 | 945 | |
c2d936a4 BP |
946 | if (bundle->dst.n_bits < 16) { |
947 | VLOG_WARN_RL(&rl, "bundle_load action requires at least 16 bit " | |
948 | "destination."); | |
949 | error = OFPERR_OFPBAC_BAD_ARGUMENT; | |
950 | } | |
951 | } else { | |
952 | if (nab->ofs_nbits || nab->dst) { | |
953 | VLOG_WARN_RL(&rl, "bundle action has nonzero reserved fields"); | |
954 | error = OFPERR_OFPBAC_BAD_ARGUMENT; | |
955 | } | |
956 | } | |
f25d0cf3 | 957 | |
c2d936a4 BP |
958 | if (slaves_size < bundle->n_slaves * sizeof(ovs_be16)) { |
959 | VLOG_WARN_RL(&rl, "Nicira action %s only has %"PRIuSIZE" bytes " | |
960 | "allocated for slaves. %"PRIuSIZE" bytes are required " | |
961 | "for %"PRIu16" slaves.", | |
962 | load ? "bundle_load" : "bundle", slaves_size, | |
963 | bundle->n_slaves * sizeof(ovs_be16), bundle->n_slaves); | |
964 | error = OFPERR_OFPBAC_BAD_LEN; | |
965 | } | |
f25d0cf3 | 966 | |
c2d936a4 BP |
967 | for (i = 0; i < bundle->n_slaves; i++) { |
968 | uint16_t ofp_port = ntohs(((ovs_be16 *)(nab + 1))[i]); | |
969 | ofpbuf_put(ofpacts, &ofp_port, sizeof ofp_port); | |
970 | } | |
f25d0cf3 | 971 | |
6fd6ed71 | 972 | bundle = ofpacts->header; |
c2d936a4 | 973 | ofpact_update_len(ofpacts, &bundle->ofpact); |
f25d0cf3 | 974 | |
c2d936a4 BP |
975 | if (!error) { |
976 | error = bundle_check(bundle, OFPP_MAX, NULL); | |
977 | } | |
978 | return error; | |
979 | } | |
f25d0cf3 | 980 | |
c2d936a4 BP |
981 | static enum ofperr |
982 | decode_NXAST_RAW_BUNDLE(const struct nx_action_bundle *nab, struct ofpbuf *out) | |
983 | { | |
984 | return decode_bundle(false, nab, out); | |
985 | } | |
f25d0cf3 | 986 | |
c2d936a4 BP |
987 | static enum ofperr |
988 | decode_NXAST_RAW_BUNDLE_LOAD(const struct nx_action_bundle *nab, | |
989 | struct ofpbuf *out) | |
990 | { | |
991 | return decode_bundle(true, nab, out); | |
992 | } | |
c2d967a5 | 993 | |
c2d936a4 BP |
994 | static void |
995 | encode_BUNDLE(const struct ofpact_bundle *bundle, | |
996 | enum ofp_version ofp_version OVS_UNUSED, | |
997 | struct ofpbuf *out) | |
998 | { | |
999 | int slaves_len = ROUND_UP(2 * bundle->n_slaves, OFP_ACTION_ALIGN); | |
1000 | struct nx_action_bundle *nab; | |
1001 | ovs_be16 *slaves; | |
1002 | size_t i; | |
f25d0cf3 | 1003 | |
c2d936a4 BP |
1004 | nab = (bundle->dst.field |
1005 | ? put_NXAST_BUNDLE_LOAD(out) | |
1006 | : put_NXAST_BUNDLE(out)); | |
1007 | nab->len = htons(ntohs(nab->len) + slaves_len); | |
1008 | nab->algorithm = htons(bundle->algorithm); | |
1009 | nab->fields = htons(bundle->fields); | |
1010 | nab->basis = htons(bundle->basis); | |
508a9338 | 1011 | nab->slave_type = htonl(mf_nxm_header(MFF_IN_PORT)); |
c2d936a4 BP |
1012 | nab->n_slaves = htons(bundle->n_slaves); |
1013 | if (bundle->dst.field) { | |
1014 | nab->ofs_nbits = nxm_encode_ofs_nbits(bundle->dst.ofs, | |
1015 | bundle->dst.n_bits); | |
508a9338 | 1016 | nab->dst = htonl(mf_nxm_header(bundle->dst.field->id)); |
c2d936a4 | 1017 | } |
f25d0cf3 | 1018 | |
c2d936a4 BP |
1019 | slaves = ofpbuf_put_zeros(out, slaves_len); |
1020 | for (i = 0; i < bundle->n_slaves; i++) { | |
1021 | slaves[i] = htons(ofp_to_u16(bundle->slaves[i])); | |
1022 | } | |
1023 | } | |
b02475c5 | 1024 | |
cab50449 | 1025 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1026 | parse_BUNDLE(const char *arg, struct ofpbuf *ofpacts, |
1027 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1028 | { | |
1029 | return bundle_parse(arg, ofpacts); | |
1030 | } | |
b02475c5 | 1031 | |
cab50449 | 1032 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1033 | parse_bundle_load(const char *arg, struct ofpbuf *ofpacts) |
1034 | { | |
1035 | return bundle_parse_load(arg, ofpacts); | |
1036 | } | |
097d4939 | 1037 | |
c2d936a4 BP |
1038 | static void |
1039 | format_BUNDLE(const struct ofpact_bundle *a, struct ds *s) | |
1040 | { | |
1041 | bundle_format(a, s); | |
1042 | } | |
1043 | \f | |
1044 | /* Set VLAN actions. */ | |
097d4939 | 1045 | |
c2d936a4 BP |
1046 | static enum ofperr |
1047 | decode_set_vlan_vid(uint16_t vid, bool push_vlan_if_needed, struct ofpbuf *out) | |
1048 | { | |
1049 | if (vid & ~0xfff) { | |
1050 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
1051 | } else { | |
1052 | struct ofpact_vlan_vid *vlan_vid = ofpact_put_SET_VLAN_VID(out); | |
1053 | vlan_vid->vlan_vid = vid; | |
1054 | vlan_vid->push_vlan_if_needed = push_vlan_if_needed; | |
1055 | return 0; | |
1056 | } | |
1057 | } | |
0f3f3c3d | 1058 | |
c2d936a4 BP |
1059 | static enum ofperr |
1060 | decode_OFPAT_RAW10_SET_VLAN_VID(uint16_t vid, struct ofpbuf *out) | |
1061 | { | |
1062 | return decode_set_vlan_vid(vid, true, out); | |
1063 | } | |
b676167a | 1064 | |
c2d936a4 BP |
1065 | static enum ofperr |
1066 | decode_OFPAT_RAW11_SET_VLAN_VID(uint16_t vid, struct ofpbuf *out) | |
1067 | { | |
1068 | return decode_set_vlan_vid(vid, false, out); | |
1069 | } | |
29089a54 | 1070 | |
c2d936a4 BP |
1071 | static void |
1072 | encode_SET_VLAN_VID(const struct ofpact_vlan_vid *vlan_vid, | |
1073 | enum ofp_version ofp_version, struct ofpbuf *out) | |
1074 | { | |
1075 | uint16_t vid = vlan_vid->vlan_vid; | |
1076 | ||
1077 | /* Push a VLAN tag, if none is present and this form of the action calls | |
1078 | * for such a feature. */ | |
1079 | if (ofp_version > OFP10_VERSION | |
1080 | && vlan_vid->push_vlan_if_needed | |
1081 | && !vlan_vid->flow_has_vlan) { | |
1082 | put_OFPAT11_PUSH_VLAN(out, htons(ETH_TYPE_VLAN_8021Q)); | |
f25d0cf3 BP |
1083 | } |
1084 | ||
c2d936a4 BP |
1085 | if (ofp_version == OFP10_VERSION) { |
1086 | put_OFPAT10_SET_VLAN_VID(out, vid); | |
1087 | } else if (ofp_version == OFP11_VERSION) { | |
1088 | put_OFPAT11_SET_VLAN_VID(out, vid); | |
1089 | } else { | |
1090 | ofpact_put_set_field(out, ofp_version, | |
1091 | MFF_VLAN_VID, vid | OFPVID12_PRESENT); | |
1092 | } | |
f25d0cf3 BP |
1093 | } |
1094 | ||
cab50449 | 1095 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 | 1096 | parse_set_vlan_vid(char *arg, struct ofpbuf *ofpacts, bool push_vlan_if_needed) |
d01c980f | 1097 | { |
ca287d20 | 1098 | struct ofpact_vlan_vid *vlan_vid; |
c2d936a4 BP |
1099 | uint16_t vid; |
1100 | char *error; | |
d01c980f | 1101 | |
c2d936a4 | 1102 | error = str_to_u16(arg, "VLAN VID", &vid); |
d01c980f BP |
1103 | if (error) { |
1104 | return error; | |
1105 | } | |
1106 | ||
c2d936a4 BP |
1107 | if (vid & ~VLAN_VID_MASK) { |
1108 | return xasprintf("%s: not a valid VLAN VID", arg); | |
d01c980f | 1109 | } |
c2d936a4 BP |
1110 | vlan_vid = ofpact_put_SET_VLAN_VID(ofpacts); |
1111 | vlan_vid->vlan_vid = vid; | |
1112 | vlan_vid->push_vlan_if_needed = push_vlan_if_needed; | |
1113 | return NULL; | |
1114 | } | |
d01c980f | 1115 | |
cab50449 | 1116 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1117 | parse_SET_VLAN_VID(char *arg, struct ofpbuf *ofpacts, |
1118 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1119 | { | |
1120 | return parse_set_vlan_vid(arg, ofpacts, false); | |
d01c980f BP |
1121 | } |
1122 | ||
c2d936a4 BP |
1123 | static void |
1124 | format_SET_VLAN_VID(const struct ofpact_vlan_vid *a, struct ds *s) | |
1125 | { | |
1126 | ds_put_format(s, "%s:%"PRIu16, | |
1127 | a->push_vlan_if_needed ? "mod_vlan_vid" : "set_vlan_vid", | |
1128 | a->vlan_vid); | |
1129 | } | |
1130 | \f | |
1131 | /* Set PCP actions. */ | |
e3f8f887 | 1132 | |
c2d936a4 BP |
1133 | static enum ofperr |
1134 | decode_set_vlan_pcp(uint8_t pcp, bool push_vlan_if_needed, struct ofpbuf *out) | |
f25d0cf3 | 1135 | { |
c2d936a4 BP |
1136 | if (pcp & ~7) { |
1137 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
1138 | } else { | |
1139 | struct ofpact_vlan_pcp *vlan_pcp = ofpact_put_SET_VLAN_PCP(out); | |
1140 | vlan_pcp->vlan_pcp = pcp; | |
1141 | vlan_pcp->push_vlan_if_needed = push_vlan_if_needed; | |
1142 | return 0; | |
1143 | } | |
f25d0cf3 BP |
1144 | } |
1145 | ||
c2d936a4 BP |
1146 | static enum ofperr |
1147 | decode_OFPAT_RAW10_SET_VLAN_PCP(uint8_t pcp, struct ofpbuf *out) | |
f25d0cf3 | 1148 | { |
c2d936a4 | 1149 | return decode_set_vlan_pcp(pcp, true, out); |
f25d0cf3 BP |
1150 | } |
1151 | ||
c2d936a4 BP |
1152 | static enum ofperr |
1153 | decode_OFPAT_RAW11_SET_VLAN_PCP(uint8_t pcp, struct ofpbuf *out) | |
1154 | { | |
1155 | return decode_set_vlan_pcp(pcp, false, out); | |
1156 | } | |
f25d0cf3 | 1157 | |
699dddf1 | 1158 | static void |
c2d936a4 BP |
1159 | encode_SET_VLAN_PCP(const struct ofpact_vlan_pcp *vlan_pcp, |
1160 | enum ofp_version ofp_version, struct ofpbuf *out) | |
699dddf1 | 1161 | { |
c2d936a4 BP |
1162 | uint8_t pcp = vlan_pcp->vlan_pcp; |
1163 | ||
1164 | /* Push a VLAN tag, if none is present and this form of the action calls | |
1165 | * for such a feature. */ | |
1166 | if (ofp_version > OFP10_VERSION | |
1167 | && vlan_pcp->push_vlan_if_needed | |
1168 | && !vlan_pcp->flow_has_vlan) { | |
1169 | put_OFPAT11_PUSH_VLAN(out, htons(ETH_TYPE_VLAN_8021Q)); | |
1170 | } | |
699dddf1 | 1171 | |
c2d936a4 BP |
1172 | if (ofp_version == OFP10_VERSION) { |
1173 | put_OFPAT10_SET_VLAN_PCP(out, pcp); | |
1174 | } else if (ofp_version == OFP11_VERSION) { | |
1175 | put_OFPAT11_SET_VLAN_PCP(out, pcp); | |
1176 | } else { | |
1177 | ofpact_put_set_field(out, ofp_version, MFF_VLAN_PCP, pcp); | |
699dddf1 BP |
1178 | } |
1179 | } | |
1180 | ||
cab50449 | 1181 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 | 1182 | parse_set_vlan_pcp(char *arg, struct ofpbuf *ofpacts, bool push_vlan_if_needed) |
f25d0cf3 | 1183 | { |
c2d936a4 BP |
1184 | struct ofpact_vlan_pcp *vlan_pcp; |
1185 | uint8_t pcp; | |
1186 | char *error; | |
e3f8f887 | 1187 | |
c2d936a4 BP |
1188 | error = str_to_u8(arg, "VLAN PCP", &pcp); |
1189 | if (error) { | |
699dddf1 | 1190 | return error; |
f25d0cf3 BP |
1191 | } |
1192 | ||
c2d936a4 BP |
1193 | if (pcp & ~7) { |
1194 | return xasprintf("%s: not a valid VLAN PCP", arg); | |
1195 | } | |
1196 | vlan_pcp = ofpact_put_SET_VLAN_PCP(ofpacts); | |
1197 | vlan_pcp->vlan_pcp = pcp; | |
1198 | vlan_pcp->push_vlan_if_needed = push_vlan_if_needed; | |
1199 | return NULL; | |
1200 | } | |
1201 | ||
cab50449 | 1202 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1203 | parse_SET_VLAN_PCP(char *arg, struct ofpbuf *ofpacts, |
1204 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1205 | { | |
1206 | return parse_set_vlan_pcp(arg, ofpacts, false); | |
1207 | } | |
1208 | ||
1209 | static void | |
1210 | format_SET_VLAN_PCP(const struct ofpact_vlan_pcp *a, struct ds *s) | |
1211 | { | |
1212 | ds_put_format(s, "%s:%"PRIu8, | |
1213 | a->push_vlan_if_needed ? "mod_vlan_pcp" : "set_vlan_pcp", | |
1214 | a->vlan_pcp); | |
1215 | } | |
1216 | \f | |
1217 | /* Strip VLAN actions. */ | |
1218 | ||
1219 | static enum ofperr | |
1220 | decode_OFPAT_RAW10_STRIP_VLAN(struct ofpbuf *out) | |
1221 | { | |
1222 | ofpact_put_STRIP_VLAN(out)->ofpact.raw = OFPAT_RAW10_STRIP_VLAN; | |
f25d0cf3 BP |
1223 | return 0; |
1224 | } | |
1225 | ||
8f2cded4 | 1226 | static enum ofperr |
c2d936a4 | 1227 | decode_OFPAT_RAW11_POP_VLAN(struct ofpbuf *out) |
8f2cded4 | 1228 | { |
c2d936a4 BP |
1229 | ofpact_put_STRIP_VLAN(out)->ofpact.raw = OFPAT_RAW11_POP_VLAN; |
1230 | return 0; | |
1231 | } | |
f25d0cf3 | 1232 | |
c2d936a4 BP |
1233 | static void |
1234 | encode_STRIP_VLAN(const struct ofpact_null *null OVS_UNUSED, | |
1235 | enum ofp_version ofp_version, struct ofpbuf *out) | |
1236 | { | |
1237 | if (ofp_version == OFP10_VERSION) { | |
1238 | put_OFPAT10_STRIP_VLAN(out); | |
1239 | } else { | |
1240 | put_OFPAT11_POP_VLAN(out); | |
1241 | } | |
1242 | } | |
f25d0cf3 | 1243 | |
cab50449 | 1244 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1245 | parse_STRIP_VLAN(char *arg OVS_UNUSED, struct ofpbuf *ofpacts, |
1246 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1247 | { | |
1248 | ofpact_put_STRIP_VLAN(ofpacts)->ofpact.raw = OFPAT_RAW10_STRIP_VLAN; | |
1249 | return NULL; | |
1250 | } | |
1251 | ||
cab50449 | 1252 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1253 | parse_pop_vlan(struct ofpbuf *ofpacts) |
1254 | { | |
1255 | ofpact_put_STRIP_VLAN(ofpacts)->ofpact.raw = OFPAT_RAW11_POP_VLAN; | |
1256 | return NULL; | |
1257 | } | |
1258 | ||
1259 | static void | |
1260 | format_STRIP_VLAN(const struct ofpact_null *a, struct ds *s) | |
1261 | { | |
1262 | ds_put_cstr(s, (a->ofpact.raw == OFPAT_RAW11_POP_VLAN | |
1263 | ? "pop_vlan" | |
1264 | : "strip_vlan")); | |
1265 | } | |
1266 | \f | |
1267 | /* Push VLAN action. */ | |
1268 | ||
1269 | static enum ofperr | |
1270 | decode_OFPAT_RAW11_PUSH_VLAN(ovs_be16 eth_type, struct ofpbuf *out) | |
1271 | { | |
1272 | if (eth_type != htons(ETH_TYPE_VLAN_8021Q)) { | |
1273 | /* XXX 802.1AD(QinQ) isn't supported at the moment */ | |
1274 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
f25d0cf3 | 1275 | } |
c2d936a4 BP |
1276 | ofpact_put_PUSH_VLAN(out); |
1277 | return 0; | |
1278 | } | |
f25d0cf3 | 1279 | |
c2d936a4 BP |
1280 | static void |
1281 | encode_PUSH_VLAN(const struct ofpact_null *null OVS_UNUSED, | |
1282 | enum ofp_version ofp_version, struct ofpbuf *out) | |
1283 | { | |
1284 | if (ofp_version == OFP10_VERSION) { | |
1285 | /* PUSH is a side effect of a SET_VLAN_VID/PCP, which should | |
1286 | * follow this action. */ | |
1287 | } else { | |
1288 | /* XXX ETH_TYPE_VLAN_8021AD case */ | |
1289 | put_OFPAT11_PUSH_VLAN(out, htons(ETH_TYPE_VLAN_8021Q)); | |
f25d0cf3 | 1290 | } |
c2d936a4 | 1291 | } |
f25d0cf3 | 1292 | |
cab50449 | 1293 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1294 | parse_PUSH_VLAN(char *arg, struct ofpbuf *ofpacts, |
1295 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1296 | { | |
1297 | uint16_t ethertype; | |
1298 | char *error; | |
1299 | ||
1300 | *usable_protocols &= OFPUTIL_P_OF11_UP; | |
1301 | error = str_to_u16(arg, "ethertype", ðertype); | |
4cceacb9 | 1302 | if (error) { |
4cceacb9 JS |
1303 | return error; |
1304 | } | |
1305 | ||
c2d936a4 BP |
1306 | if (ethertype != ETH_TYPE_VLAN_8021Q) { |
1307 | /* XXX ETH_TYPE_VLAN_8021AD case isn't supported */ | |
1308 | return xasprintf("%s: not a valid VLAN ethertype", arg); | |
f25d0cf3 | 1309 | } |
c2d936a4 BP |
1310 | |
1311 | ofpact_put_PUSH_VLAN(ofpacts); | |
1312 | return NULL; | |
d01c980f BP |
1313 | } |
1314 | ||
c2d936a4 BP |
1315 | static void |
1316 | format_PUSH_VLAN(const struct ofpact_null *a OVS_UNUSED, struct ds *s) | |
8f2cded4 | 1317 | { |
c2d936a4 BP |
1318 | /* XXX 802.1AD case*/ |
1319 | ds_put_format(s, "push_vlan:%#"PRIx16, ETH_TYPE_VLAN_8021Q); | |
8f2cded4 | 1320 | } |
d01c980f | 1321 | \f |
c2d936a4 BP |
1322 | /* Action structure for OFPAT10_SET_DL_SRC/DST and OFPAT11_SET_DL_SRC/DST. */ |
1323 | struct ofp_action_dl_addr { | |
1324 | ovs_be16 type; /* Type. */ | |
1325 | ovs_be16 len; /* Length is 16. */ | |
1326 | uint8_t dl_addr[OFP_ETH_ALEN]; /* Ethernet address. */ | |
1327 | uint8_t pad[6]; | |
1328 | }; | |
1329 | OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16); | |
d01c980f | 1330 | |
d01c980f | 1331 | static enum ofperr |
c2d936a4 BP |
1332 | decode_OFPAT_RAW_SET_DL_SRC(const struct ofp_action_dl_addr *a, |
1333 | struct ofpbuf *out) | |
d01c980f | 1334 | { |
c2d936a4 BP |
1335 | memcpy(ofpact_put_SET_ETH_SRC(out)->mac, a->dl_addr, ETH_ADDR_LEN); |
1336 | return 0; | |
1337 | } | |
3ddcaf2d | 1338 | |
c2d936a4 BP |
1339 | static enum ofperr |
1340 | decode_OFPAT_RAW_SET_DL_DST(const struct ofp_action_dl_addr *a, | |
1341 | struct ofpbuf *out) | |
1342 | { | |
1343 | memcpy(ofpact_put_SET_ETH_DST(out)->mac, a->dl_addr, ETH_ADDR_LEN); | |
1344 | return 0; | |
1345 | } | |
d01c980f | 1346 | |
c2d936a4 BP |
1347 | static void |
1348 | encode_SET_ETH_addr(const struct ofpact_mac *mac, enum ofp_version ofp_version, | |
1349 | enum ofp_raw_action_type raw, enum mf_field_id field, | |
1350 | struct ofpbuf *out) | |
1351 | { | |
1352 | const uint8_t *addr = mac->mac; | |
d01c980f | 1353 | |
c2d936a4 BP |
1354 | if (ofp_version < OFP12_VERSION) { |
1355 | struct ofp_action_dl_addr *oada; | |
1356 | ||
1357 | oada = ofpact_put_raw(out, ofp_version, raw, 0); | |
1358 | memcpy(oada->dl_addr, addr, ETH_ADDR_LEN); | |
1359 | } else { | |
1360 | ofpact_put_set_field(out, ofp_version, field, | |
1361 | eth_addr_to_uint64(addr)); | |
d01c980f BP |
1362 | } |
1363 | } | |
1364 | ||
c2d936a4 BP |
1365 | static void |
1366 | encode_SET_ETH_SRC(const struct ofpact_mac *mac, enum ofp_version ofp_version, | |
1367 | struct ofpbuf *out) | |
b2dd70be | 1368 | { |
c2d936a4 BP |
1369 | encode_SET_ETH_addr(mac, ofp_version, OFPAT_RAW_SET_DL_SRC, MFF_ETH_SRC, |
1370 | out); | |
b2dd70be | 1371 | |
c2d936a4 | 1372 | } |
b2dd70be | 1373 | |
c2d936a4 BP |
1374 | static void |
1375 | encode_SET_ETH_DST(const struct ofpact_mac *mac, | |
1376 | enum ofp_version ofp_version, | |
1377 | struct ofpbuf *out) | |
1378 | { | |
1379 | encode_SET_ETH_addr(mac, ofp_version, OFPAT_RAW_SET_DL_DST, MFF_ETH_DST, | |
1380 | out); | |
b2dd70be | 1381 | |
c2d936a4 | 1382 | } |
b2dd70be | 1383 | |
cab50449 | 1384 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1385 | parse_SET_ETH_SRC(char *arg, struct ofpbuf *ofpacts, |
1386 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1387 | { | |
1388 | return str_to_mac(arg, ofpact_put_SET_ETH_SRC(ofpacts)->mac); | |
1389 | } | |
1390 | ||
cab50449 | 1391 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1392 | parse_SET_ETH_DST(char *arg, struct ofpbuf *ofpacts, |
1393 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1394 | { | |
1395 | return str_to_mac(arg, ofpact_put_SET_ETH_DST(ofpacts)->mac); | |
b2dd70be JR |
1396 | } |
1397 | ||
1398 | static void | |
c2d936a4 | 1399 | format_SET_ETH_SRC(const struct ofpact_mac *a, struct ds *s) |
b2dd70be | 1400 | { |
c2d936a4 BP |
1401 | ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT, ETH_ADDR_ARGS(a->mac)); |
1402 | } | |
b2dd70be | 1403 | |
c2d936a4 BP |
1404 | static void |
1405 | format_SET_ETH_DST(const struct ofpact_mac *a, struct ds *s) | |
1406 | { | |
1407 | ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT, ETH_ADDR_ARGS(a->mac)); | |
1408 | } | |
1409 | \f | |
1410 | /* Set IPv4 address actions. */ | |
b2dd70be | 1411 | |
c2d936a4 BP |
1412 | static enum ofperr |
1413 | decode_OFPAT_RAW_SET_NW_SRC(ovs_be32 ipv4, struct ofpbuf *out) | |
1414 | { | |
1415 | ofpact_put_SET_IPV4_SRC(out)->ipv4 = ipv4; | |
1416 | return 0; | |
b2dd70be JR |
1417 | } |
1418 | ||
c2d936a4 BP |
1419 | static enum ofperr |
1420 | decode_OFPAT_RAW_SET_NW_DST(ovs_be32 ipv4, struct ofpbuf *out) | |
b2dd70be | 1421 | { |
c2d936a4 BP |
1422 | ofpact_put_SET_IPV4_DST(out)->ipv4 = ipv4; |
1423 | return 0; | |
1424 | } | |
b2dd70be | 1425 | |
c2d936a4 BP |
1426 | static void |
1427 | encode_SET_IPV4_addr(const struct ofpact_ipv4 *ipv4, | |
1428 | enum ofp_version ofp_version, | |
1429 | enum ofp_raw_action_type raw, enum mf_field_id field, | |
1430 | struct ofpbuf *out) | |
1431 | { | |
1432 | ovs_be32 addr = ipv4->ipv4; | |
1433 | if (ofp_version < OFP12_VERSION) { | |
1434 | ofpact_put_raw(out, ofp_version, raw, ntohl(addr)); | |
b2dd70be | 1435 | } else { |
c2d936a4 | 1436 | ofpact_put_set_field(out, ofp_version, field, ntohl(addr)); |
b2dd70be JR |
1437 | } |
1438 | } | |
1439 | ||
a6fd70bb | 1440 | static void |
c2d936a4 BP |
1441 | encode_SET_IPV4_SRC(const struct ofpact_ipv4 *ipv4, |
1442 | enum ofp_version ofp_version, struct ofpbuf *out) | |
a6fd70bb | 1443 | { |
c2d936a4 BP |
1444 | encode_SET_IPV4_addr(ipv4, ofp_version, OFPAT_RAW_SET_NW_SRC, MFF_IPV4_SRC, |
1445 | out); | |
1446 | } | |
a6fd70bb | 1447 | |
c2d936a4 BP |
1448 | static void |
1449 | encode_SET_IPV4_DST(const struct ofpact_ipv4 *ipv4, | |
1450 | enum ofp_version ofp_version, struct ofpbuf *out) | |
1451 | { | |
1452 | encode_SET_IPV4_addr(ipv4, ofp_version, OFPAT_RAW_SET_NW_DST, MFF_IPV4_DST, | |
1453 | out); | |
1454 | } | |
a6fd70bb | 1455 | |
cab50449 | 1456 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1457 | parse_SET_IPV4_SRC(char *arg, struct ofpbuf *ofpacts, |
1458 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1459 | { | |
1460 | return str_to_ip(arg, &ofpact_put_SET_IPV4_SRC(ofpacts)->ipv4); | |
1461 | } | |
a6fd70bb | 1462 | |
cab50449 | 1463 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1464 | parse_SET_IPV4_DST(char *arg, struct ofpbuf *ofpacts, |
1465 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1466 | { | |
1467 | return str_to_ip(arg, &ofpact_put_SET_IPV4_DST(ofpacts)->ipv4); | |
1468 | } | |
a6fd70bb | 1469 | |
c2d936a4 BP |
1470 | static void |
1471 | format_SET_IPV4_SRC(const struct ofpact_ipv4 *a, struct ds *s) | |
1472 | { | |
1473 | ds_put_format(s, "mod_nw_src:"IP_FMT, IP_ARGS(a->ipv4)); | |
1474 | } | |
097d4939 | 1475 | |
c2d936a4 BP |
1476 | static void |
1477 | format_SET_IPV4_DST(const struct ofpact_ipv4 *a, struct ds *s) | |
1478 | { | |
1479 | ds_put_format(s, "mod_nw_dst:"IP_FMT, IP_ARGS(a->ipv4)); | |
1480 | } | |
1481 | \f | |
1482 | /* Set IPv4/v6 TOS actions. */ | |
097d4939 | 1483 | |
c2d936a4 BP |
1484 | static enum ofperr |
1485 | decode_OFPAT_RAW_SET_NW_TOS(uint8_t dscp, struct ofpbuf *out) | |
1486 | { | |
1487 | if (dscp & ~IP_DSCP_MASK) { | |
1488 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
1489 | } else { | |
1490 | ofpact_put_SET_IP_DSCP(out)->dscp = dscp; | |
1491 | return 0; | |
a6fd70bb JR |
1492 | } |
1493 | } | |
1494 | ||
a6fd70bb | 1495 | static void |
c2d936a4 BP |
1496 | encode_SET_IP_DSCP(const struct ofpact_dscp *dscp, |
1497 | enum ofp_version ofp_version, struct ofpbuf *out) | |
a6fd70bb | 1498 | { |
c2d936a4 BP |
1499 | if (ofp_version < OFP12_VERSION) { |
1500 | put_OFPAT_SET_NW_TOS(out, ofp_version, dscp->dscp); | |
1501 | } else { | |
1502 | ofpact_put_set_field(out, ofp_version, | |
1503 | MFF_IP_DSCP_SHIFTED, dscp->dscp >> 2); | |
1504 | } | |
1505 | } | |
a6fd70bb | 1506 | |
cab50449 | 1507 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1508 | parse_SET_IP_DSCP(char *arg, struct ofpbuf *ofpacts, |
1509 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1510 | { | |
1511 | uint8_t tos; | |
1512 | char *error; | |
a6fd70bb | 1513 | |
c2d936a4 BP |
1514 | error = str_to_u8(arg, "TOS", &tos); |
1515 | if (error) { | |
1516 | return error; | |
1517 | } | |
a6fd70bb | 1518 | |
c2d936a4 BP |
1519 | if (tos & ~IP_DSCP_MASK) { |
1520 | return xasprintf("%s: not a valid TOS", arg); | |
a6fd70bb | 1521 | } |
c2d936a4 BP |
1522 | ofpact_put_SET_IP_DSCP(ofpacts)->dscp = tos; |
1523 | return NULL; | |
a6fd70bb JR |
1524 | } |
1525 | ||
b2dd70be | 1526 | static void |
c2d936a4 | 1527 | format_SET_IP_DSCP(const struct ofpact_dscp *a, struct ds *s) |
b2dd70be | 1528 | { |
c2d936a4 BP |
1529 | ds_put_format(s, "mod_nw_tos:%d", a->dscp); |
1530 | } | |
1531 | \f | |
1532 | /* Set IPv4/v6 ECN actions. */ | |
b2dd70be | 1533 | |
c2d936a4 BP |
1534 | static enum ofperr |
1535 | decode_OFPAT_RAW11_SET_NW_ECN(uint8_t ecn, struct ofpbuf *out) | |
1536 | { | |
1537 | if (ecn & ~IP_ECN_MASK) { | |
1538 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
b2dd70be | 1539 | } else { |
c2d936a4 BP |
1540 | ofpact_put_SET_IP_ECN(out)->ecn = ecn; |
1541 | return 0; | |
b2dd70be JR |
1542 | } |
1543 | } | |
1544 | ||
c2d936a4 BP |
1545 | static void |
1546 | encode_SET_IP_ECN(const struct ofpact_ecn *ip_ecn, | |
1547 | enum ofp_version ofp_version, struct ofpbuf *out) | |
d01c980f | 1548 | { |
c2d936a4 BP |
1549 | uint8_t ecn = ip_ecn->ecn; |
1550 | if (ofp_version == OFP10_VERSION) { | |
1551 | /* XXX */ | |
1552 | } else if (ofp_version == OFP11_VERSION) { | |
1553 | put_OFPAT11_SET_NW_ECN(out, ecn); | |
1554 | } else { | |
1555 | ofpact_put_set_field(out, ofp_version, MFF_IP_ECN, ecn); | |
1556 | } | |
1557 | } | |
d01c980f | 1558 | |
cab50449 | 1559 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1560 | parse_SET_IP_ECN(char *arg, struct ofpbuf *ofpacts, |
1561 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1562 | { | |
1563 | uint8_t ecn; | |
1564 | char *error; | |
d01c980f | 1565 | |
c2d936a4 | 1566 | error = str_to_u8(arg, "ECN", &ecn); |
d01c980f BP |
1567 | if (error) { |
1568 | return error; | |
1569 | } | |
1570 | ||
c2d936a4 BP |
1571 | if (ecn & ~IP_ECN_MASK) { |
1572 | return xasprintf("%s: not a valid ECN", arg); | |
1573 | } | |
1574 | ofpact_put_SET_IP_ECN(ofpacts)->ecn = ecn; | |
1575 | return NULL; | |
d01c980f BP |
1576 | } |
1577 | ||
c2d936a4 BP |
1578 | static void |
1579 | format_SET_IP_ECN(const struct ofpact_ecn *a, struct ds *s) | |
1580 | { | |
1581 | ds_put_format(s, "mod_nw_ecn:%d", a->ecn); | |
1582 | } | |
1583 | \f | |
1584 | /* Set IPv4/v6 TTL actions. */ | |
1585 | ||
d01c980f | 1586 | static enum ofperr |
c2d936a4 | 1587 | decode_OFPAT_RAW11_SET_NW_TTL(uint8_t ttl, struct ofpbuf *out) |
d01c980f | 1588 | { |
c2d936a4 BP |
1589 | ofpact_put_SET_IP_TTL(out)->ttl = ttl; |
1590 | return 0; | |
1591 | } | |
1592 | ||
1593 | static void | |
1594 | encode_SET_IP_TTL(const struct ofpact_ip_ttl *ttl, | |
1595 | enum ofp_version ofp_version, struct ofpbuf *out) | |
1596 | { | |
1597 | if (ofp_version >= OFP11_VERSION) { | |
1598 | put_OFPAT11_SET_NW_TTL(out, ttl->ttl); | |
1599 | } else { | |
1600 | /* XXX */ | |
1601 | } | |
1602 | } | |
1603 | ||
cab50449 | 1604 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1605 | parse_SET_IP_TTL(char *arg, struct ofpbuf *ofpacts, |
1606 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1607 | { | |
1608 | uint8_t ttl; | |
1609 | char *error; | |
d01c980f | 1610 | |
c2d936a4 | 1611 | error = str_to_u8(arg, "TTL", &ttl); |
d01c980f BP |
1612 | if (error) { |
1613 | return error; | |
1614 | } | |
1615 | ||
c2d936a4 BP |
1616 | ofpact_put_SET_IP_TTL(ofpacts)->ttl = ttl; |
1617 | return NULL; | |
1618 | } | |
d01c980f | 1619 | |
c2d936a4 BP |
1620 | static void |
1621 | format_SET_IP_TTL(const struct ofpact_ip_ttl *a, struct ds *s) | |
1622 | { | |
1623 | ds_put_format(s, "mod_nw_ttl:%d", a->ttl); | |
1624 | } | |
1625 | \f | |
1626 | /* Set TCP/UDP/SCTP port actions. */ | |
d01c980f | 1627 | |
c2d936a4 BP |
1628 | static enum ofperr |
1629 | decode_OFPAT_RAW_SET_TP_SRC(ovs_be16 port, struct ofpbuf *out) | |
1630 | { | |
1631 | ofpact_put_SET_L4_SRC_PORT(out)->port = ntohs(port); | |
1632 | return 0; | |
1633 | } | |
d01c980f | 1634 | |
c2d936a4 BP |
1635 | static enum ofperr |
1636 | decode_OFPAT_RAW_SET_TP_DST(ovs_be16 port, struct ofpbuf *out) | |
1637 | { | |
1638 | ofpact_put_SET_L4_DST_PORT(out)->port = ntohs(port); | |
1639 | return 0; | |
1640 | } | |
d01c980f | 1641 | |
c2d936a4 BP |
1642 | static void |
1643 | encode_SET_L4_port(const struct ofpact_l4_port *l4_port, | |
1644 | enum ofp_version ofp_version, enum ofp_raw_action_type raw, | |
1645 | enum mf_field_id field, struct ofpbuf *out) | |
1646 | { | |
1647 | uint16_t port = l4_port->port; | |
3e34fbdd | 1648 | |
c2d936a4 BP |
1649 | if (ofp_version >= OFP12_VERSION && field != MFF_N_IDS) { |
1650 | ofpact_put_set_field(out, ofp_version, field, port); | |
1651 | } else { | |
1652 | ofpact_put_raw(out, ofp_version, raw, port); | |
1653 | } | |
1654 | } | |
8e61c110 | 1655 | |
c2d936a4 BP |
1656 | static void |
1657 | encode_SET_L4_SRC_PORT(const struct ofpact_l4_port *l4_port, | |
1658 | enum ofp_version ofp_version, struct ofpbuf *out) | |
1659 | { | |
1660 | uint8_t proto = l4_port->flow_ip_proto; | |
1661 | enum mf_field_id field = (proto == IPPROTO_TCP ? MFF_TCP_SRC | |
1662 | : proto == IPPROTO_UDP ? MFF_UDP_SRC | |
1663 | : proto == IPPROTO_SCTP ? MFF_SCTP_SRC | |
1664 | : MFF_N_IDS); | |
276c4e7a | 1665 | |
c2d936a4 BP |
1666 | encode_SET_L4_port(l4_port, ofp_version, OFPAT_RAW_SET_TP_SRC, field, out); |
1667 | } | |
d01c980f | 1668 | |
c2d936a4 BP |
1669 | static void |
1670 | encode_SET_L4_DST_PORT(const struct ofpact_l4_port *l4_port, | |
1671 | enum ofp_version ofp_version, | |
1672 | struct ofpbuf *out) | |
1673 | { | |
1674 | uint8_t proto = l4_port->flow_ip_proto; | |
1675 | enum mf_field_id field = (proto == IPPROTO_TCP ? MFF_TCP_DST | |
1676 | : proto == IPPROTO_UDP ? MFF_UDP_DST | |
1677 | : proto == IPPROTO_SCTP ? MFF_SCTP_DST | |
1678 | : MFF_N_IDS); | |
d01c980f | 1679 | |
c2d936a4 BP |
1680 | encode_SET_L4_port(l4_port, ofp_version, OFPAT_RAW_SET_TP_DST, field, out); |
1681 | } | |
7bcb1506 | 1682 | |
cab50449 | 1683 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1684 | parse_SET_L4_SRC_PORT(char *arg, struct ofpbuf *ofpacts, |
1685 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1686 | { | |
1687 | return str_to_u16(arg, "source port", | |
1688 | &ofpact_put_SET_L4_SRC_PORT(ofpacts)->port); | |
1689 | } | |
d01c980f | 1690 | |
cab50449 | 1691 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1692 | parse_SET_L4_DST_PORT(char *arg, struct ofpbuf *ofpacts, |
1693 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1694 | { | |
1695 | return str_to_u16(arg, "destination port", | |
1696 | &ofpact_put_SET_L4_DST_PORT(ofpacts)->port); | |
1697 | } | |
d01c980f | 1698 | |
c2d936a4 BP |
1699 | static void |
1700 | format_SET_L4_SRC_PORT(const struct ofpact_l4_port *a, struct ds *s) | |
1701 | { | |
1702 | ds_put_format(s, "mod_tp_src:%d", a->port); | |
1703 | } | |
d01c980f | 1704 | |
c2d936a4 BP |
1705 | static void |
1706 | format_SET_L4_DST_PORT(const struct ofpact_l4_port *a, struct ds *s) | |
1707 | { | |
1708 | ds_put_format(s, "mod_tp_dst:%d", a->port); | |
1709 | } | |
1710 | \f | |
73178f20 BP |
1711 | /* Action structure for OFPAT_COPY_FIELD. */ |
1712 | struct ofp15_action_copy_field { | |
1713 | ovs_be16 type; /* OFPAT_COPY_FIELD. */ | |
1714 | ovs_be16 len; /* Length is padded to 64 bits. */ | |
1715 | ovs_be16 n_bits; /* Number of bits to copy. */ | |
1716 | ovs_be16 src_offset; /* Starting bit offset in source. */ | |
1717 | ovs_be16 dst_offset; /* Starting bit offset in destination. */ | |
650763d8 | 1718 | uint8_t pad[2]; |
f13cdd73 BP |
1719 | /* Followed by: |
1720 | * - OXM header for source field. | |
1721 | * - OXM header for destination field. | |
1722 | * - Padding with 0-bytes to a multiple of 8 bytes. | |
650763d8 BP |
1723 | * The "pad2" member is the beginning of the above. */ |
1724 | uint8_t pad2[4]; | |
73178f20 | 1725 | }; |
f13cdd73 | 1726 | OFP_ASSERT(sizeof(struct ofp15_action_copy_field) == 16); |
73178f20 | 1727 | |
914624f8 BP |
1728 | /* Action structure for OpenFlow 1.3 extension copy-field action.. */ |
1729 | struct onf_action_copy_field { | |
1730 | ovs_be16 type; /* OFPAT_EXPERIMENTER. */ | |
1731 | ovs_be16 len; /* Length is padded to 64 bits. */ | |
1732 | ovs_be32 experimenter; /* ONF_VENDOR_ID. */ | |
1733 | ovs_be16 exp_type; /* 3200. */ | |
1734 | uint8_t pad[2]; /* Not used. */ | |
1735 | ovs_be16 n_bits; /* Number of bits to copy. */ | |
1736 | ovs_be16 src_offset; /* Starting bit offset in source. */ | |
1737 | ovs_be16 dst_offset; /* Starting bit offset in destination. */ | |
1738 | uint8_t pad2[2]; /* Not used. */ | |
1739 | /* Followed by: | |
1740 | * - OXM header for source field. | |
1741 | * - OXM header for destination field. | |
1742 | * - Padding with 0-bytes (either 0 or 4 of them) to a multiple of 8 bytes. | |
1743 | * The "pad3" member is the beginning of the above. */ | |
1744 | uint8_t pad3[4]; /* Not used. */ | |
1745 | }; | |
1746 | OFP_ASSERT(sizeof(struct onf_action_copy_field) == 24); | |
1747 | ||
c2d936a4 BP |
1748 | /* Action structure for NXAST_REG_MOVE. |
1749 | * | |
1750 | * Copies src[src_ofs:src_ofs+n_bits] to dst[dst_ofs:dst_ofs+n_bits], where | |
1751 | * a[b:c] denotes the bits within 'a' numbered 'b' through 'c' (not including | |
1752 | * bit 'c'). Bit numbering starts at 0 for the least-significant bit, 1 for | |
1753 | * the next most significant bit, and so on. | |
1754 | * | |
1755 | * 'src' and 'dst' are nxm_header values with nxm_hasmask=0. (It doesn't make | |
1756 | * sense to use nxm_hasmask=1 because the action does not do any kind of | |
1757 | * matching; it uses the actual value of a field.) | |
1758 | * | |
1759 | * The following nxm_header values are potentially acceptable as 'src': | |
1760 | * | |
1761 | * - NXM_OF_IN_PORT | |
1762 | * - NXM_OF_ETH_DST | |
1763 | * - NXM_OF_ETH_SRC | |
1764 | * - NXM_OF_ETH_TYPE | |
1765 | * - NXM_OF_VLAN_TCI | |
1766 | * - NXM_OF_IP_TOS | |
1767 | * - NXM_OF_IP_PROTO | |
1768 | * - NXM_OF_IP_SRC | |
1769 | * - NXM_OF_IP_DST | |
1770 | * - NXM_OF_TCP_SRC | |
1771 | * - NXM_OF_TCP_DST | |
1772 | * - NXM_OF_UDP_SRC | |
1773 | * - NXM_OF_UDP_DST | |
1774 | * - NXM_OF_ICMP_TYPE | |
1775 | * - NXM_OF_ICMP_CODE | |
1776 | * - NXM_OF_ARP_OP | |
1777 | * - NXM_OF_ARP_SPA | |
1778 | * - NXM_OF_ARP_TPA | |
1779 | * - NXM_NX_TUN_ID | |
1780 | * - NXM_NX_ARP_SHA | |
1781 | * - NXM_NX_ARP_THA | |
1782 | * - NXM_NX_ICMPV6_TYPE | |
1783 | * - NXM_NX_ICMPV6_CODE | |
1784 | * - NXM_NX_ND_SLL | |
1785 | * - NXM_NX_ND_TLL | |
1786 | * - NXM_NX_REG(idx) for idx in the switch's accepted range. | |
1787 | * - NXM_NX_PKT_MARK | |
1788 | * - NXM_NX_TUN_IPV4_SRC | |
1789 | * - NXM_NX_TUN_IPV4_DST | |
1790 | * | |
1791 | * The following nxm_header values are potentially acceptable as 'dst': | |
1792 | * | |
1793 | * - NXM_OF_ETH_DST | |
1794 | * - NXM_OF_ETH_SRC | |
1795 | * - NXM_OF_IP_TOS | |
1796 | * - NXM_OF_IP_SRC | |
1797 | * - NXM_OF_IP_DST | |
1798 | * - NXM_OF_TCP_SRC | |
1799 | * - NXM_OF_TCP_DST | |
1800 | * - NXM_OF_UDP_SRC | |
1801 | * - NXM_OF_UDP_DST | |
1802 | * - NXM_NX_ARP_SHA | |
1803 | * - NXM_NX_ARP_THA | |
1804 | * - NXM_OF_ARP_OP | |
1805 | * - NXM_OF_ARP_SPA | |
1806 | * - NXM_OF_ARP_TPA | |
1807 | * Modifying any of the above fields changes the corresponding packet | |
1808 | * header. | |
1809 | * | |
1810 | * - NXM_OF_IN_PORT | |
1811 | * | |
1812 | * - NXM_NX_REG(idx) for idx in the switch's accepted range. | |
1813 | * | |
1814 | * - NXM_NX_PKT_MARK | |
1815 | * | |
1816 | * - NXM_OF_VLAN_TCI. Modifying this field's value has side effects on the | |
1817 | * packet's 802.1Q header. Setting a value with CFI=0 removes the 802.1Q | |
1818 | * header (if any), ignoring the other bits. Setting a value with CFI=1 | |
1819 | * adds or modifies the 802.1Q header appropriately, setting the TCI field | |
1820 | * to the field's new value (with the CFI bit masked out). | |
1821 | * | |
1822 | * - NXM_NX_TUN_ID, NXM_NX_TUN_IPV4_SRC, NXM_NX_TUN_IPV4_DST. Modifying | |
1823 | * any of these values modifies the corresponding tunnel header field used | |
1824 | * for the packet's next tunnel encapsulation, if allowed by the | |
1825 | * configuration of the output tunnel port. | |
1826 | * | |
1827 | * A given nxm_header value may be used as 'src' or 'dst' only on a flow whose | |
1828 | * nx_match satisfies its prerequisites. For example, NXM_OF_IP_TOS may be | |
1829 | * used only if the flow's nx_match includes an nxm_entry that specifies | |
1830 | * nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0, and nxm_value=0x0800. | |
1831 | * | |
1832 | * The switch will reject actions for which src_ofs+n_bits is greater than the | |
1833 | * width of 'src' or dst_ofs+n_bits is greater than the width of 'dst' with | |
1834 | * error type OFPET_BAD_ACTION, code OFPBAC_BAD_ARGUMENT. | |
1835 | * | |
1836 | * This action behaves properly when 'src' overlaps with 'dst', that is, it | |
1837 | * behaves as if 'src' were copied out to a temporary buffer, then the | |
1838 | * temporary buffer copied to 'dst'. | |
1839 | */ | |
1840 | struct nx_action_reg_move { | |
1841 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
1842 | ovs_be16 len; /* Length is 24. */ | |
1843 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
1844 | ovs_be16 subtype; /* NXAST_REG_MOVE. */ | |
1845 | ovs_be16 n_bits; /* Number of bits. */ | |
1846 | ovs_be16 src_ofs; /* Starting bit offset in source. */ | |
1847 | ovs_be16 dst_ofs; /* Starting bit offset in destination. */ | |
bad8a439 BP |
1848 | /* Followed by: |
1849 | * - OXM/NXM header for source field (4 or 8 bytes). | |
1850 | * - OXM/NXM header for destination field (4 or 8 bytes). | |
1851 | * - Padding with 0-bytes to a multiple of 8 bytes, if necessary. */ | |
c2d936a4 | 1852 | }; |
bad8a439 | 1853 | OFP_ASSERT(sizeof(struct nx_action_reg_move) == 16); |
ff14eb7a | 1854 | |
73178f20 | 1855 | static enum ofperr |
914624f8 BP |
1856 | decode_copy_field__(ovs_be16 src_offset, ovs_be16 dst_offset, ovs_be16 n_bits, |
1857 | const void *action, ovs_be16 action_len, size_t oxm_offset, | |
1858 | struct ofpbuf *ofpacts) | |
73178f20 BP |
1859 | { |
1860 | struct ofpact_reg_move *move; | |
f13cdd73 | 1861 | enum ofperr error; |
f13cdd73 | 1862 | struct ofpbuf b; |
73178f20 BP |
1863 | |
1864 | move = ofpact_put_REG_MOVE(ofpacts); | |
914624f8 BP |
1865 | move->ofpact.raw = ONFACT_RAW13_COPY_FIELD; |
1866 | move->src.ofs = ntohs(src_offset); | |
1867 | move->src.n_bits = ntohs(n_bits); | |
1868 | move->dst.ofs = ntohs(dst_offset); | |
1869 | move->dst.n_bits = ntohs(n_bits); | |
1870 | ||
1871 | ofpbuf_use_const(&b, action, ntohs(action_len)); | |
1872 | ofpbuf_pull(&b, oxm_offset); | |
f13cdd73 BP |
1873 | error = nx_pull_header(&b, &move->src.field, NULL); |
1874 | if (error) { | |
1875 | return error; | |
1876 | } | |
1877 | error = nx_pull_header(&b, &move->dst.field, NULL); | |
1878 | if (error) { | |
1879 | return error; | |
1880 | } | |
f13cdd73 | 1881 | |
6fd6ed71 | 1882 | if (!is_all_zeros(b.data, b.size)) { |
f13cdd73 BP |
1883 | return OFPERR_NXBRC_MUST_BE_ZERO; |
1884 | } | |
1885 | ||
73178f20 BP |
1886 | return nxm_reg_move_check(move, NULL); |
1887 | } | |
1888 | ||
914624f8 BP |
1889 | static enum ofperr |
1890 | decode_OFPAT_RAW15_COPY_FIELD(const struct ofp15_action_copy_field *oacf, | |
1891 | struct ofpbuf *ofpacts) | |
1892 | { | |
1893 | return decode_copy_field__(oacf->src_offset, oacf->dst_offset, | |
1894 | oacf->n_bits, oacf, oacf->len, | |
1895 | OBJECT_OFFSETOF(oacf, pad2), ofpacts); | |
1896 | } | |
1897 | ||
1898 | static enum ofperr | |
1899 | decode_ONFACT_RAW13_COPY_FIELD(const struct onf_action_copy_field *oacf, | |
1900 | struct ofpbuf *ofpacts) | |
1901 | { | |
1902 | return decode_copy_field__(oacf->src_offset, oacf->dst_offset, | |
1903 | oacf->n_bits, oacf, oacf->len, | |
1904 | OBJECT_OFFSETOF(oacf, pad3), ofpacts); | |
1905 | } | |
1906 | ||
c2d936a4 BP |
1907 | static enum ofperr |
1908 | decode_NXAST_RAW_REG_MOVE(const struct nx_action_reg_move *narm, | |
1909 | struct ofpbuf *ofpacts) | |
1910 | { | |
1911 | struct ofpact_reg_move *move; | |
bad8a439 BP |
1912 | enum ofperr error; |
1913 | struct ofpbuf b; | |
0c20dbe4 | 1914 | |
c2d936a4 | 1915 | move = ofpact_put_REG_MOVE(ofpacts); |
914624f8 | 1916 | move->ofpact.raw = NXAST_RAW_REG_MOVE; |
c2d936a4 BP |
1917 | move->src.ofs = ntohs(narm->src_ofs); |
1918 | move->src.n_bits = ntohs(narm->n_bits); | |
c2d936a4 BP |
1919 | move->dst.ofs = ntohs(narm->dst_ofs); |
1920 | move->dst.n_bits = ntohs(narm->n_bits); | |
d01c980f | 1921 | |
bad8a439 BP |
1922 | ofpbuf_use_const(&b, narm, ntohs(narm->len)); |
1923 | ofpbuf_pull(&b, sizeof *narm); | |
1924 | error = nx_pull_header(&b, &move->src.field, NULL); | |
1925 | if (error) { | |
1926 | return error; | |
1927 | } | |
1928 | error = nx_pull_header(&b, &move->dst.field, NULL); | |
1929 | if (error) { | |
1930 | return error; | |
1931 | } | |
6fd6ed71 | 1932 | if (!is_all_zeros(b.data, b.size)) { |
bad8a439 BP |
1933 | return OFPERR_NXBRC_MUST_BE_ZERO; |
1934 | } | |
1935 | ||
c2d936a4 BP |
1936 | return nxm_reg_move_check(move, NULL); |
1937 | } | |
d01c980f | 1938 | |
c2d936a4 BP |
1939 | static void |
1940 | encode_REG_MOVE(const struct ofpact_reg_move *move, | |
73178f20 BP |
1941 | enum ofp_version ofp_version, struct ofpbuf *out) |
1942 | { | |
914624f8 BP |
1943 | /* For OpenFlow 1.3, the choice of ONFACT_RAW13_COPY_FIELD versus |
1944 | * NXAST_RAW_REG_MOVE is somewhat difficult. Neither one is guaranteed to | |
1945 | * be supported by every OpenFlow 1.3 implementation. It would be ideal to | |
1946 | * probe for support. Until we have that ability, we currently prefer | |
1947 | * NXAST_RAW_REG_MOVE for backward compatibility with older Open vSwitch | |
1948 | * versions. */ | |
6fd6ed71 | 1949 | size_t start_ofs = out->size; |
73178f20 | 1950 | if (ofp_version >= OFP15_VERSION) { |
bad8a439 | 1951 | struct ofp15_action_copy_field *copy = put_OFPAT15_COPY_FIELD(out); |
73178f20 BP |
1952 | copy->n_bits = htons(move->dst.n_bits); |
1953 | copy->src_offset = htons(move->src.ofs); | |
1954 | copy->dst_offset = htons(move->dst.ofs); | |
6fd6ed71 | 1955 | out->size = out->size - sizeof copy->pad2; |
f13cdd73 BP |
1956 | nx_put_header(out, move->src.field->id, ofp_version, false); |
1957 | nx_put_header(out, move->dst.field->id, ofp_version, false); | |
914624f8 BP |
1958 | } else if (ofp_version == OFP13_VERSION |
1959 | && move->ofpact.raw == ONFACT_RAW13_COPY_FIELD) { | |
1960 | struct onf_action_copy_field *copy = put_ONFACT13_COPY_FIELD(out); | |
1961 | copy->n_bits = htons(move->dst.n_bits); | |
1962 | copy->src_offset = htons(move->src.ofs); | |
1963 | copy->dst_offset = htons(move->dst.ofs); | |
6fd6ed71 | 1964 | out->size = out->size - sizeof copy->pad3; |
914624f8 BP |
1965 | nx_put_header(out, move->src.field->id, ofp_version, false); |
1966 | nx_put_header(out, move->dst.field->id, ofp_version, false); | |
73178f20 | 1967 | } else { |
bad8a439 | 1968 | struct nx_action_reg_move *narm = put_NXAST_REG_MOVE(out); |
73178f20 BP |
1969 | narm->n_bits = htons(move->dst.n_bits); |
1970 | narm->src_ofs = htons(move->src.ofs); | |
1971 | narm->dst_ofs = htons(move->dst.ofs); | |
bad8a439 BP |
1972 | nx_put_header(out, move->src.field->id, 0, false); |
1973 | nx_put_header(out, move->dst.field->id, 0, false); | |
73178f20 | 1974 | } |
bad8a439 | 1975 | pad_ofpat(out, start_ofs); |
c2d936a4 | 1976 | } |
e9536ecb | 1977 | |
cab50449 | 1978 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
1979 | parse_REG_MOVE(const char *arg, struct ofpbuf *ofpacts, |
1980 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
1981 | { | |
1982 | struct ofpact_reg_move *move = ofpact_put_REG_MOVE(ofpacts); | |
1983 | const char *full_arg = arg; | |
1984 | char *error; | |
097d4939 | 1985 | |
c2d936a4 BP |
1986 | error = mf_parse_subfield__(&move->src, &arg); |
1987 | if (error) { | |
1988 | return error; | |
1989 | } | |
1990 | if (strncmp(arg, "->", 2)) { | |
1991 | return xasprintf("%s: missing `->' following source", full_arg); | |
1992 | } | |
1993 | arg += 2; | |
1994 | error = mf_parse_subfield(&move->dst, arg); | |
1995 | if (error) { | |
1996 | return error; | |
1997 | } | |
097d4939 | 1998 | |
c2d936a4 BP |
1999 | if (move->src.n_bits != move->dst.n_bits) { |
2000 | return xasprintf("%s: source field is %d bits wide but destination is " | |
2001 | "%d bits wide", full_arg, | |
2002 | move->src.n_bits, move->dst.n_bits); | |
2003 | } | |
2004 | return NULL; | |
2005 | } | |
0f3f3c3d | 2006 | |
c2d936a4 BP |
2007 | static void |
2008 | format_REG_MOVE(const struct ofpact_reg_move *a, struct ds *s) | |
2009 | { | |
2010 | nxm_format_reg_move(a, s); | |
2011 | } | |
2012 | \f | |
7eb4b1f1 BP |
2013 | /* Action structure for OFPAT12_SET_FIELD. */ |
2014 | struct ofp12_action_set_field { | |
2015 | ovs_be16 type; /* OFPAT12_SET_FIELD. */ | |
2016 | ovs_be16 len; /* Length is padded to 64 bits. */ | |
2017 | ||
2018 | /* Followed by: | |
2019 | * - An OXM header, value, and (in OpenFlow 1.5+) optionally a mask. | |
2020 | * - Enough 0-bytes to pad out to a multiple of 64 bits. | |
2021 | * | |
2022 | * The "pad" member is the beginning of the above. */ | |
2023 | uint8_t pad[4]; | |
2024 | }; | |
2025 | OFP_ASSERT(sizeof(struct ofp12_action_set_field) == 8); | |
2026 | ||
c2d936a4 BP |
2027 | /* Action structure for NXAST_REG_LOAD. |
2028 | * | |
2029 | * Copies value[0:n_bits] to dst[ofs:ofs+n_bits], where a[b:c] denotes the bits | |
2030 | * within 'a' numbered 'b' through 'c' (not including bit 'c'). Bit numbering | |
2031 | * starts at 0 for the least-significant bit, 1 for the next most significant | |
2032 | * bit, and so on. | |
2033 | * | |
2034 | * 'dst' is an nxm_header with nxm_hasmask=0. See the documentation for | |
2035 | * NXAST_REG_MOVE, above, for the permitted fields and for the side effects of | |
2036 | * loading them. | |
2037 | * | |
2038 | * The 'ofs' and 'n_bits' fields are combined into a single 'ofs_nbits' field | |
2039 | * to avoid enlarging the structure by another 8 bytes. To allow 'n_bits' to | |
2040 | * take a value between 1 and 64 (inclusive) while taking up only 6 bits, it is | |
2041 | * also stored as one less than its true value: | |
2042 | * | |
2043 | * 15 6 5 0 | |
2044 | * +------------------------------+------------------+ | |
2045 | * | ofs | n_bits - 1 | | |
2046 | * +------------------------------+------------------+ | |
2047 | * | |
2048 | * The switch will reject actions for which ofs+n_bits is greater than the | |
2049 | * width of 'dst', or in which any bits in 'value' with value 2**n_bits or | |
2050 | * greater are set to 1, with error type OFPET_BAD_ACTION, code | |
2051 | * OFPBAC_BAD_ARGUMENT. | |
2052 | */ | |
2053 | struct nx_action_reg_load { | |
2054 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
2055 | ovs_be16 len; /* Length is 24. */ | |
2056 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
2057 | ovs_be16 subtype; /* NXAST_REG_LOAD. */ | |
2058 | ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */ | |
2059 | ovs_be32 dst; /* Destination register. */ | |
2060 | ovs_be64 value; /* Immediate value. */ | |
2061 | }; | |
2062 | OFP_ASSERT(sizeof(struct nx_action_reg_load) == 24); | |
b676167a | 2063 | |
bad8a439 BP |
2064 | /* Action structure for NXAST_REG_LOAD2. |
2065 | * | |
2066 | * Compared to OFPAT_SET_FIELD, we can use this to set whole or partial fields | |
2067 | * in any OpenFlow version. Compared to NXAST_REG_LOAD, we can use this to set | |
2068 | * OXM experimenter fields. */ | |
2069 | struct nx_action_reg_load2 { | |
2070 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
2071 | ovs_be16 len; /* At least 16. */ | |
2072 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
2073 | ovs_be16 subtype; /* NXAST_SET_FIELD. */ | |
2074 | ||
2075 | /* Followed by: | |
2076 | * - An NXM/OXM header, value, and optionally a mask. | |
2077 | * - Enough 0-bytes to pad out to a multiple of 64 bits. | |
2078 | * | |
2079 | * The "pad" member is the beginning of the above. */ | |
2080 | uint8_t pad[6]; | |
2081 | }; | |
2082 | OFP_ASSERT(sizeof(struct nx_action_reg_load2) == 16); | |
2083 | ||
c2d936a4 | 2084 | static enum ofperr |
7eb4b1f1 BP |
2085 | decode_ofpat_set_field(const struct ofp12_action_set_field *oasf, |
2086 | bool may_mask, struct ofpbuf *ofpacts) | |
7fdb60a7 | 2087 | { |
c2d936a4 | 2088 | struct ofpact_set_field *sf; |
178742f9 BP |
2089 | enum ofperr error; |
2090 | struct ofpbuf b; | |
7fdb60a7 | 2091 | |
178742f9 BP |
2092 | sf = ofpact_put_SET_FIELD(ofpacts); |
2093 | ||
2094 | ofpbuf_use_const(&b, oasf, ntohs(oasf->len)); | |
7eb4b1f1 BP |
2095 | ofpbuf_pull(&b, OBJECT_OFFSETOF(oasf, pad)); |
2096 | error = nx_pull_entry(&b, &sf->field, &sf->value, | |
2097 | may_mask ? &sf->mask : NULL); | |
178742f9 | 2098 | if (error) { |
178742f9 BP |
2099 | return (error == OFPERR_OFPBMC_BAD_MASK |
2100 | ? OFPERR_OFPBAC_BAD_SET_MASK | |
2101 | : error); | |
c2d936a4 | 2102 | } |
7eb4b1f1 BP |
2103 | if (!may_mask) { |
2104 | memset(&sf->mask, 0xff, sf->field->n_bytes); | |
2105 | } | |
178742f9 | 2106 | |
6fd6ed71 | 2107 | if (!is_all_zeros(b.data, b.size)) { |
c2d936a4 BP |
2108 | return OFPERR_OFPBAC_BAD_SET_ARGUMENT; |
2109 | } | |
7fdb60a7 | 2110 | |
178742f9 BP |
2111 | /* OpenFlow says specifically that one may not set OXM_OF_IN_PORT via |
2112 | * Set-Field. */ | |
2113 | if (sf->field->id == MFF_IN_PORT_OXM) { | |
2114 | return OFPERR_OFPBAC_BAD_SET_ARGUMENT; | |
c2d936a4 | 2115 | } |
178742f9 | 2116 | |
c2d936a4 | 2117 | /* oxm_length is now validated to be compatible with mf_value. */ |
178742f9 BP |
2118 | if (!sf->field->writable) { |
2119 | VLOG_WARN_RL(&rl, "destination field %s is not writable", | |
2120 | sf->field->name); | |
c2d936a4 BP |
2121 | return OFPERR_OFPBAC_BAD_SET_ARGUMENT; |
2122 | } | |
c2d936a4 | 2123 | |
d3cb080e | 2124 | /* The value must be valid for match. OpenFlow 1.5 also says, |
7eb4b1f1 BP |
2125 | * "In an OXM_OF_VLAN_VID set-field action, the OFPVID_PRESENT bit must be |
2126 | * a 1-bit in oxm_value and in oxm_mask." */ | |
178742f9 BP |
2127 | if (!mf_is_value_valid(sf->field, &sf->value) |
2128 | || (sf->field->id == MFF_VLAN_VID | |
31c9ed6c BP |
2129 | && (!(sf->mask.be16 & htons(OFPVID12_PRESENT)) |
2130 | || !(sf->value.be16 & htons(OFPVID12_PRESENT))))) { | |
c2d936a4 | 2131 | struct ds ds = DS_EMPTY_INITIALIZER; |
178742f9 | 2132 | mf_format(sf->field, &sf->value, NULL, &ds); |
c2d936a4 | 2133 | VLOG_WARN_RL(&rl, "Invalid value for set field %s: %s", |
178742f9 | 2134 | sf->field->name, ds_cstr(&ds)); |
c2d936a4 BP |
2135 | ds_destroy(&ds); |
2136 | ||
2137 | return OFPERR_OFPBAC_BAD_SET_ARGUMENT; | |
7fdb60a7 | 2138 | } |
c2d936a4 | 2139 | return 0; |
7fdb60a7 SH |
2140 | } |
2141 | ||
7eb4b1f1 BP |
2142 | static enum ofperr |
2143 | decode_OFPAT_RAW12_SET_FIELD(const struct ofp12_action_set_field *oasf, | |
2144 | struct ofpbuf *ofpacts) | |
2145 | { | |
2146 | return decode_ofpat_set_field(oasf, false, ofpacts); | |
2147 | } | |
2148 | ||
2149 | static enum ofperr | |
2150 | decode_OFPAT_RAW15_SET_FIELD(const struct ofp12_action_set_field *oasf, | |
2151 | struct ofpbuf *ofpacts) | |
2152 | { | |
2153 | return decode_ofpat_set_field(oasf, true, ofpacts); | |
2154 | } | |
2155 | ||
2156 | static enum ofperr | |
2157 | decode_NXAST_RAW_REG_LOAD(const struct nx_action_reg_load *narl, | |
2158 | struct ofpbuf *out) | |
2159 | { | |
2160 | struct ofpact_set_field *sf = ofpact_put_reg_load(out); | |
2161 | struct mf_subfield dst; | |
2162 | enum ofperr error; | |
2163 | ||
2164 | sf->ofpact.raw = NXAST_RAW_REG_LOAD; | |
2165 | ||
2166 | dst.field = mf_from_nxm_header(ntohl(narl->dst)); | |
2167 | dst.ofs = nxm_decode_ofs(narl->ofs_nbits); | |
2168 | dst.n_bits = nxm_decode_n_bits(narl->ofs_nbits); | |
2169 | error = mf_check_dst(&dst, NULL); | |
2170 | if (error) { | |
2171 | return error; | |
2172 | } | |
2173 | ||
2174 | /* Reject 'narl' if a bit numbered 'n_bits' or higher is set to 1 in | |
2175 | * narl->value. */ | |
2176 | if (dst.n_bits < 64 && ntohll(narl->value) >> dst.n_bits) { | |
2177 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
2178 | } | |
2179 | ||
2180 | sf->field = dst.field; | |
2181 | bitwise_put(ntohll(narl->value), | |
2182 | &sf->value, dst.field->n_bytes, dst.ofs, | |
2183 | dst.n_bits); | |
2184 | bitwise_put(UINT64_MAX, | |
2185 | &sf->mask, dst.field->n_bytes, dst.ofs, | |
2186 | dst.n_bits); | |
2187 | ||
2188 | return 0; | |
2189 | } | |
2190 | ||
bad8a439 BP |
2191 | static enum ofperr |
2192 | decode_NXAST_RAW_REG_LOAD2(const struct nx_action_reg_load2 *narl, | |
2193 | struct ofpbuf *out) | |
2194 | { | |
2195 | struct ofpact_set_field *sf; | |
2196 | enum ofperr error; | |
2197 | struct ofpbuf b; | |
2198 | ||
2199 | sf = ofpact_put_SET_FIELD(out); | |
2200 | sf->ofpact.raw = NXAST_RAW_REG_LOAD2; | |
2201 | ||
2202 | ofpbuf_use_const(&b, narl, ntohs(narl->len)); | |
2203 | ofpbuf_pull(&b, OBJECT_OFFSETOF(narl, pad)); | |
2204 | error = nx_pull_entry(&b, &sf->field, &sf->value, &sf->mask); | |
2205 | if (error) { | |
2206 | return error; | |
2207 | } | |
6fd6ed71 | 2208 | if (!is_all_zeros(b.data, b.size)) { |
bad8a439 BP |
2209 | return OFPERR_OFPBAC_BAD_SET_ARGUMENT; |
2210 | } | |
2211 | ||
2212 | if (!sf->field->writable) { | |
2213 | VLOG_WARN_RL(&rl, "destination field %s is not writable", | |
2214 | sf->field->name); | |
2215 | return OFPERR_OFPBAC_BAD_SET_ARGUMENT; | |
2216 | } | |
2217 | return 0; | |
2218 | } | |
2219 | ||
7fdb60a7 | 2220 | static void |
c2d936a4 | 2221 | ofpact_put_set_field(struct ofpbuf *openflow, enum ofp_version ofp_version, |
178742f9 | 2222 | enum mf_field_id field, uint64_t value_) |
7fdb60a7 | 2223 | { |
7eb4b1f1 | 2224 | struct ofp12_action_set_field *oasf OVS_UNUSED; |
178742f9 | 2225 | int n_bytes = mf_from_id(field)->n_bytes; |
6fd6ed71 | 2226 | size_t start_ofs = openflow->size; |
178742f9 | 2227 | union mf_value value; |
7fdb60a7 | 2228 | |
178742f9 | 2229 | value.be64 = htonll(value_ << (8 * (8 - n_bytes))); |
7fdb60a7 | 2230 | |
7eb4b1f1 | 2231 | oasf = put_OFPAT12_SET_FIELD(openflow); |
6fd6ed71 | 2232 | openflow->size = openflow->size - sizeof oasf->pad; |
178742f9 BP |
2233 | nx_put_entry(openflow, field, ofp_version, &value, NULL); |
2234 | pad_ofpat(openflow, start_ofs); | |
7fdb60a7 SH |
2235 | } |
2236 | ||
7eb4b1f1 BP |
2237 | static bool |
2238 | next_load_segment(const struct ofpact_set_field *sf, | |
2239 | struct mf_subfield *dst, uint64_t *value) | |
2240 | { | |
fa078489 BP |
2241 | int n_bits = sf->field->n_bits; |
2242 | int n_bytes = sf->field->n_bytes; | |
7eb4b1f1 BP |
2243 | int start = dst->ofs + dst->n_bits; |
2244 | ||
fa078489 | 2245 | if (start < n_bits) { |
7eb4b1f1 | 2246 | dst->field = sf->field; |
fa078489 BP |
2247 | dst->ofs = bitwise_scan(&sf->mask, n_bytes, 1, start, n_bits); |
2248 | if (dst->ofs < n_bits) { | |
2249 | dst->n_bits = bitwise_scan(&sf->mask, n_bytes, 0, dst->ofs + 1, | |
2250 | MIN(dst->ofs + 64, n_bits)) - dst->ofs; | |
2251 | *value = bitwise_get(&sf->value, n_bytes, dst->ofs, dst->n_bits); | |
7eb4b1f1 BP |
2252 | return true; |
2253 | } | |
2254 | } | |
2255 | return false; | |
2256 | } | |
178742f9 | 2257 | |
7eb4b1f1 | 2258 | /* Convert 'sf' to a series of REG_LOADs. */ |
7fdb60a7 | 2259 | static void |
c2d936a4 | 2260 | set_field_to_nxast(const struct ofpact_set_field *sf, struct ofpbuf *openflow) |
7fdb60a7 | 2261 | { |
bad8a439 BP |
2262 | /* If 'sf' cannot be encoded as NXAST_REG_LOAD because it requires an |
2263 | * experimenter OXM (or if it came in as NXAST_REG_LOAD2), encode as | |
2264 | * NXAST_REG_LOAD2. Otherwise use NXAST_REG_LOAD, which is backward | |
2265 | * compatible. */ | |
2266 | if (sf->ofpact.raw == NXAST_RAW_REG_LOAD2 | |
2267 | || !mf_nxm_header(sf->field->id)) { | |
2268 | struct nx_action_reg_load2 *narl OVS_UNUSED; | |
6fd6ed71 | 2269 | size_t start_ofs = openflow->size; |
bad8a439 BP |
2270 | |
2271 | narl = put_NXAST_REG_LOAD2(openflow); | |
6fd6ed71 | 2272 | openflow->size = openflow->size - sizeof narl->pad; |
bad8a439 BP |
2273 | nx_put_entry(openflow, sf->field->id, 0, &sf->value, &sf->mask); |
2274 | pad_ofpat(openflow, start_ofs); | |
2275 | } else { | |
2276 | struct mf_subfield dst; | |
2277 | uint64_t value; | |
7eb4b1f1 | 2278 | |
bad8a439 BP |
2279 | dst.ofs = dst.n_bits = 0; |
2280 | while (next_load_segment(sf, &dst, &value)) { | |
2281 | struct nx_action_reg_load *narl = put_NXAST_REG_LOAD(openflow); | |
2282 | narl->ofs_nbits = nxm_encode_ofs_nbits(dst.ofs, dst.n_bits); | |
2283 | narl->dst = htonl(mf_nxm_header(dst.field->id)); | |
2284 | narl->value = htonll(value); | |
2285 | } | |
7fdb60a7 SH |
2286 | } |
2287 | } | |
2288 | ||
7eb4b1f1 BP |
2289 | /* Convert 'sf', which must set an entire field, to standard OpenFlow 1.0/1.1 |
2290 | * actions, if we can, falling back to Nicira extensions if we must. | |
7fdb60a7 | 2291 | * |
c2d936a4 BP |
2292 | * We check only meta-flow types that can appear within set field actions and |
2293 | * that have a mapping to compatible action types. These struct mf_field | |
2294 | * definitions have a defined OXM or NXM header value and specify the field as | |
2295 | * writable. */ | |
2296 | static void | |
2297 | set_field_to_legacy_openflow(const struct ofpact_set_field *sf, | |
2298 | enum ofp_version ofp_version, | |
2299 | struct ofpbuf *out) | |
7fdb60a7 | 2300 | { |
c2d936a4 BP |
2301 | switch ((int) sf->field->id) { |
2302 | case MFF_VLAN_TCI: { | |
2303 | ovs_be16 tci = sf->value.be16; | |
2304 | bool cfi = (tci & htons(VLAN_CFI)) != 0; | |
2305 | uint16_t vid = vlan_tci_to_vid(tci); | |
2306 | uint8_t pcp = vlan_tci_to_pcp(tci); | |
2307 | ||
2308 | if (ofp_version < OFP11_VERSION) { | |
2309 | /* NXM_OF_VLAN_TCI to OpenFlow 1.0 mapping: | |
2310 | * | |
2311 | * If CFI=1, Add or modify VLAN VID & PCP. | |
2312 | * If CFI=0, strip VLAN header, if any. | |
2313 | */ | |
2314 | if (cfi) { | |
2315 | put_OFPAT10_SET_VLAN_VID(out, vid); | |
2316 | put_OFPAT10_SET_VLAN_PCP(out, pcp); | |
2317 | } else { | |
2318 | put_OFPAT10_STRIP_VLAN(out); | |
2319 | } | |
2320 | } else { | |
2321 | /* NXM_OF_VLAN_TCI to OpenFlow 1.1 mapping: | |
2322 | * | |
2323 | * If CFI=1, Add or modify VLAN VID & PCP. | |
2324 | * OpenFlow 1.1 set actions only apply if the packet | |
2325 | * already has VLAN tags. To be sure that is the case | |
2326 | * we have to push a VLAN header. As we do not support | |
2327 | * multiple layers of VLANs, this is a no-op, if a VLAN | |
2328 | * header already exists. This may backfire, however, | |
2329 | * when we start supporting multiple layers of VLANs. | |
2330 | * If CFI=0, strip VLAN header, if any. | |
2331 | */ | |
2332 | if (cfi) { | |
2333 | /* Push a VLAN tag, if one was not seen at action validation | |
2334 | * time. */ | |
2335 | if (!sf->flow_has_vlan) { | |
2336 | put_OFPAT11_PUSH_VLAN(out, htons(ETH_TYPE_VLAN_8021Q)); | |
2337 | } | |
2338 | put_OFPAT11_SET_VLAN_VID(out, vid); | |
2339 | put_OFPAT11_SET_VLAN_PCP(out, pcp); | |
2340 | } else { | |
2341 | /* If the flow did not match on vlan, we have no way of | |
2342 | * knowing if the vlan tag exists, so we must POP just to be | |
2343 | * sure. */ | |
2344 | put_OFPAT11_POP_VLAN(out); | |
2345 | } | |
2346 | } | |
2347 | break; | |
2348 | } | |
7fdb60a7 | 2349 | |
c2d936a4 BP |
2350 | case MFF_VLAN_VID: { |
2351 | uint16_t vid = ntohs(sf->value.be16) & VLAN_VID_MASK; | |
2352 | if (ofp_version == OFP10_VERSION) { | |
2353 | put_OFPAT10_SET_VLAN_VID(out, vid); | |
2354 | } else { | |
2355 | put_OFPAT11_SET_VLAN_VID(out, vid); | |
2356 | } | |
2357 | break; | |
2358 | } | |
2359 | ||
2360 | case MFF_VLAN_PCP: | |
2361 | if (ofp_version == OFP10_VERSION) { | |
2362 | put_OFPAT10_SET_VLAN_PCP(out, sf->value.u8); | |
2363 | } else { | |
2364 | put_OFPAT11_SET_VLAN_PCP(out, sf->value.u8); | |
2365 | } | |
2366 | break; | |
2367 | ||
2368 | case MFF_ETH_SRC: | |
2369 | memcpy(put_OFPAT_SET_DL_SRC(out, ofp_version)->dl_addr, | |
2370 | sf->value.mac, ETH_ADDR_LEN); | |
2371 | break; | |
2372 | ||
2373 | case MFF_ETH_DST: | |
2374 | memcpy(put_OFPAT_SET_DL_DST(out, ofp_version)->dl_addr, | |
2375 | sf->value.mac, ETH_ADDR_LEN); | |
2376 | break; | |
2377 | ||
2378 | case MFF_IPV4_SRC: | |
2379 | put_OFPAT_SET_NW_SRC(out, ofp_version, sf->value.be32); | |
2380 | break; | |
2381 | ||
2382 | case MFF_IPV4_DST: | |
2383 | put_OFPAT_SET_NW_DST(out, ofp_version, sf->value.be32); | |
2384 | break; | |
2385 | ||
2386 | case MFF_IP_DSCP: | |
2387 | put_OFPAT_SET_NW_TOS(out, ofp_version, sf->value.u8); | |
2388 | break; | |
2389 | ||
2390 | case MFF_IP_DSCP_SHIFTED: | |
2391 | put_OFPAT_SET_NW_TOS(out, ofp_version, sf->value.u8 << 2); | |
2392 | break; | |
2393 | ||
2394 | case MFF_TCP_SRC: | |
2395 | case MFF_UDP_SRC: | |
2396 | put_OFPAT_SET_TP_SRC(out, sf->value.be16); | |
2397 | break; | |
2398 | ||
2399 | case MFF_TCP_DST: | |
2400 | case MFF_UDP_DST: | |
2401 | put_OFPAT_SET_TP_DST(out, sf->value.be16); | |
2402 | break; | |
2403 | ||
2404 | default: | |
2405 | set_field_to_nxast(sf, out); | |
2406 | break; | |
7fdb60a7 SH |
2407 | } |
2408 | } | |
2409 | ||
7eb4b1f1 BP |
2410 | static void |
2411 | set_field_to_set_field(const struct ofpact_set_field *sf, | |
2412 | enum ofp_version ofp_version, struct ofpbuf *out) | |
2413 | { | |
2414 | struct ofp12_action_set_field *oasf OVS_UNUSED; | |
6fd6ed71 | 2415 | size_t start_ofs = out->size; |
7eb4b1f1 BP |
2416 | |
2417 | oasf = put_OFPAT12_SET_FIELD(out); | |
6fd6ed71 | 2418 | out->size = out->size - sizeof oasf->pad; |
7eb4b1f1 BP |
2419 | nx_put_entry(out, sf->field->id, ofp_version, &sf->value, &sf->mask); |
2420 | pad_ofpat(out, start_ofs); | |
2421 | } | |
2422 | ||
c2d936a4 BP |
2423 | static void |
2424 | encode_SET_FIELD(const struct ofpact_set_field *sf, | |
2425 | enum ofp_version ofp_version, struct ofpbuf *out) | |
2426 | { | |
7eb4b1f1 | 2427 | if (ofp_version >= OFP15_VERSION) { |
bad8a439 BP |
2428 | /* OF1.5+ only has Set-Field (reg_load is redundant so we drop it |
2429 | * entirely). */ | |
7eb4b1f1 | 2430 | set_field_to_set_field(sf, ofp_version, out); |
bad8a439 BP |
2431 | } else if (sf->ofpact.raw == NXAST_RAW_REG_LOAD || |
2432 | sf->ofpact.raw == NXAST_RAW_REG_LOAD2) { | |
2433 | /* It came in as reg_load, send it out the same way. */ | |
7eb4b1f1 BP |
2434 | set_field_to_nxast(sf, out); |
2435 | } else if (ofp_version < OFP12_VERSION) { | |
2436 | /* OpenFlow 1.0 and 1.1 don't have Set-Field. */ | |
c2d936a4 | 2437 | set_field_to_legacy_openflow(sf, ofp_version, out); |
7eb4b1f1 BP |
2438 | } else if (is_all_ones((const uint8_t *) &sf->mask, sf->field->n_bytes)) { |
2439 | /* We're encoding to OpenFlow 1.2, 1.3, or 1.4. The action sets an | |
2440 | * entire field, so encode it as OFPAT_SET_FIELD. */ | |
2441 | set_field_to_set_field(sf, ofp_version, out); | |
c2d936a4 | 2442 | } else { |
7eb4b1f1 BP |
2443 | /* We're encoding to OpenFlow 1.2, 1.3, or 1.4. The action cannot be |
2444 | * encoded as OFPAT_SET_FIELD because it does not set an entire field, | |
2445 | * so encode it as reg_load. */ | |
2446 | set_field_to_nxast(sf, out); | |
c2d936a4 BP |
2447 | } |
2448 | } | |
2449 | ||
2450 | /* Parses a "set_field" action with argument 'arg', appending the parsed | |
2451 | * action to 'ofpacts'. | |
2452 | * | |
2453 | * Returns NULL if successful, otherwise a malloc()'d string describing the | |
2454 | * error. The caller is responsible for freeing the returned string. */ | |
cab50449 | 2455 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
2456 | set_field_parse__(char *arg, struct ofpbuf *ofpacts, |
2457 | enum ofputil_protocol *usable_protocols) | |
7fdb60a7 | 2458 | { |
c2d936a4 BP |
2459 | struct ofpact_set_field *sf = ofpact_put_SET_FIELD(ofpacts); |
2460 | char *value; | |
2461 | char *delim; | |
2462 | char *key; | |
2463 | const struct mf_field *mf; | |
2464 | char *error; | |
7fdb60a7 | 2465 | |
c2d936a4 BP |
2466 | value = arg; |
2467 | delim = strstr(arg, "->"); | |
2468 | if (!delim) { | |
2469 | return xasprintf("%s: missing `->'", arg); | |
2470 | } | |
2471 | if (strlen(delim) <= strlen("->")) { | |
2472 | return xasprintf("%s: missing field name following `->'", arg); | |
2473 | } | |
e3f8f887 | 2474 | |
c2d936a4 BP |
2475 | key = delim + strlen("->"); |
2476 | mf = mf_from_name(key); | |
2477 | if (!mf) { | |
2478 | return xasprintf("%s is not a valid OXM field name", key); | |
2479 | } | |
2480 | if (!mf->writable) { | |
2481 | return xasprintf("%s is read-only", key); | |
2482 | } | |
2483 | sf->field = mf; | |
2484 | delim[0] = '\0'; | |
7eb4b1f1 | 2485 | error = mf_parse(mf, value, &sf->value, &sf->mask); |
7fdb60a7 SH |
2486 | if (error) { |
2487 | return error; | |
2488 | } | |
2489 | ||
c2d936a4 BP |
2490 | if (!mf_is_value_valid(mf, &sf->value)) { |
2491 | return xasprintf("%s is not a valid value for field %s", value, key); | |
7fdb60a7 SH |
2492 | } |
2493 | ||
a4ce8b25 | 2494 | *usable_protocols &= mf->usable_protocols_exact; |
c2d936a4 | 2495 | return NULL; |
7fdb60a7 SH |
2496 | } |
2497 | ||
c2d936a4 BP |
2498 | /* Parses 'arg' as the argument to a "set_field" action, and appends such an |
2499 | * action to 'ofpacts'. | |
2500 | * | |
2501 | * Returns NULL if successful, otherwise a malloc()'d string describing the | |
2502 | * error. The caller is responsible for freeing the returned string. */ | |
cab50449 | 2503 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
2504 | parse_SET_FIELD(const char *arg, struct ofpbuf *ofpacts, |
2505 | enum ofputil_protocol *usable_protocols) | |
2506 | { | |
2507 | char *copy = xstrdup(arg); | |
2508 | char *error = set_field_parse__(copy, ofpacts, usable_protocols); | |
2509 | free(copy); | |
2510 | return error; | |
2511 | } | |
a359d5ad | 2512 | |
cab50449 | 2513 | static char * OVS_WARN_UNUSED_RESULT |
7eb4b1f1 BP |
2514 | parse_reg_load(char *arg, struct ofpbuf *ofpacts) |
2515 | { | |
2516 | struct ofpact_set_field *sf = ofpact_put_reg_load(ofpacts); | |
2517 | const char *full_arg = arg; | |
2518 | uint64_t value = strtoull(arg, (char **) &arg, 0); | |
2519 | struct mf_subfield dst; | |
2520 | char *error; | |
2521 | ||
2522 | if (strncmp(arg, "->", 2)) { | |
2523 | return xasprintf("%s: missing `->' following value", full_arg); | |
2524 | } | |
2525 | arg += 2; | |
2526 | error = mf_parse_subfield(&dst, arg); | |
2527 | if (error) { | |
2528 | return error; | |
2529 | } | |
2530 | ||
2531 | if (dst.n_bits < 64 && (value >> dst.n_bits) != 0) { | |
2532 | return xasprintf("%s: value %"PRIu64" does not fit into %d bits", | |
2533 | full_arg, value, dst.n_bits); | |
2534 | } | |
2535 | ||
2536 | sf->field = dst.field; | |
2537 | memset(&sf->value, 0, sizeof sf->value); | |
2538 | bitwise_put(value, &sf->value, dst.field->n_bytes, dst.ofs, dst.n_bits); | |
2539 | bitwise_put(UINT64_MAX, &sf->mask, | |
2540 | dst.field->n_bytes, dst.ofs, dst.n_bits); | |
2541 | return NULL; | |
2542 | } | |
2543 | ||
c2d936a4 BP |
2544 | static void |
2545 | format_SET_FIELD(const struct ofpact_set_field *a, struct ds *s) | |
2546 | { | |
7eb4b1f1 BP |
2547 | if (a->ofpact.raw == NXAST_RAW_REG_LOAD) { |
2548 | struct mf_subfield dst; | |
2549 | uint64_t value; | |
2550 | ||
2551 | dst.ofs = dst.n_bits = 0; | |
2552 | while (next_load_segment(a, &dst, &value)) { | |
2553 | ds_put_format(s, "load:%#"PRIx64"->", value); | |
2554 | mf_format_subfield(&dst, s); | |
2555 | ds_put_char(s, ','); | |
2556 | } | |
2557 | ds_chomp(s, ','); | |
2558 | } else { | |
2559 | ds_put_cstr(s, "set_field:"); | |
2560 | mf_format(a->field, &a->value, &a->mask, s); | |
2561 | ds_put_format(s, "->%s", a->field->name); | |
2562 | } | |
2563 | } | |
2564 | ||
2565 | /* Appends an OFPACT_SET_FIELD ofpact to 'ofpacts' and returns it. The ofpact | |
2566 | * is marked such that, if possible, it will be translated to OpenFlow as | |
2567 | * NXAST_REG_LOAD extension actions rather than OFPAT_SET_FIELD, either because | |
2568 | * that was the way that the action was expressed when it came into OVS or for | |
2569 | * backward compatibility. */ | |
2570 | struct ofpact_set_field * | |
2571 | ofpact_put_reg_load(struct ofpbuf *ofpacts) | |
2572 | { | |
2573 | struct ofpact_set_field *sf = ofpact_put_SET_FIELD(ofpacts); | |
2574 | sf->ofpact.raw = NXAST_RAW_REG_LOAD; | |
2575 | return sf; | |
c2d936a4 BP |
2576 | } |
2577 | \f | |
2578 | /* Action structure for NXAST_STACK_PUSH and NXAST_STACK_POP. | |
2579 | * | |
2580 | * Pushes (or pops) field[offset: offset + n_bits] to (or from) | |
2581 | * top of the stack. | |
2582 | */ | |
2583 | struct nx_action_stack { | |
2584 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
2585 | ovs_be16 len; /* Length is 16. */ | |
2586 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
2587 | ovs_be16 subtype; /* NXAST_STACK_PUSH or NXAST_STACK_POP. */ | |
2588 | ovs_be16 offset; /* Bit offset into the field. */ | |
bad8a439 BP |
2589 | /* Followed by: |
2590 | * - OXM/NXM header for field to push or pop (4 or 8 bytes). | |
2591 | * - ovs_be16 'n_bits', the number of bits to extract from the field. | |
2592 | * - Enough 0-bytes to pad out the action to 24 bytes. */ | |
2593 | uint8_t pad[12]; /* See above. */ | |
a359d5ad | 2594 | }; |
c2d936a4 | 2595 | OFP_ASSERT(sizeof(struct nx_action_stack) == 24); |
a359d5ad | 2596 | |
bad8a439 | 2597 | static enum ofperr |
c2d936a4 BP |
2598 | decode_stack_action(const struct nx_action_stack *nasp, |
2599 | struct ofpact_stack *stack_action) | |
a359d5ad | 2600 | { |
bad8a439 BP |
2601 | enum ofperr error; |
2602 | struct ofpbuf b; | |
2603 | ||
c2d936a4 | 2604 | stack_action->subfield.ofs = ntohs(nasp->offset); |
bad8a439 BP |
2605 | |
2606 | ofpbuf_use_const(&b, nasp, sizeof *nasp); | |
2607 | ofpbuf_pull(&b, OBJECT_OFFSETOF(nasp, pad)); | |
2608 | error = nx_pull_header(&b, &stack_action->subfield.field, NULL); | |
2609 | if (error) { | |
2610 | return error; | |
2611 | } | |
6fd6ed71 | 2612 | stack_action->subfield.n_bits = ntohs(*(const ovs_be16 *) b.data); |
bad8a439 | 2613 | ofpbuf_pull(&b, 2); |
6fd6ed71 | 2614 | if (!is_all_zeros(b.data, b.size)) { |
bad8a439 BP |
2615 | return OFPERR_NXBRC_MUST_BE_ZERO; |
2616 | } | |
2617 | ||
2618 | return 0; | |
a359d5ad IY |
2619 | } |
2620 | ||
c2d936a4 BP |
2621 | static enum ofperr |
2622 | decode_NXAST_RAW_STACK_PUSH(const struct nx_action_stack *nasp, | |
2623 | struct ofpbuf *ofpacts) | |
a359d5ad | 2624 | { |
c2d936a4 | 2625 | struct ofpact_stack *push = ofpact_put_STACK_PUSH(ofpacts); |
bad8a439 BP |
2626 | enum ofperr error = decode_stack_action(nasp, push); |
2627 | return error ? error : nxm_stack_push_check(push, NULL); | |
a359d5ad IY |
2628 | } |
2629 | ||
c2d936a4 BP |
2630 | static enum ofperr |
2631 | decode_NXAST_RAW_STACK_POP(const struct nx_action_stack *nasp, | |
2632 | struct ofpbuf *ofpacts) | |
084c53de | 2633 | { |
c2d936a4 | 2634 | struct ofpact_stack *pop = ofpact_put_STACK_POP(ofpacts); |
bad8a439 BP |
2635 | enum ofperr error = decode_stack_action(nasp, pop); |
2636 | return error ? error : nxm_stack_pop_check(pop, NULL); | |
084c53de BP |
2637 | } |
2638 | ||
c2d936a4 BP |
2639 | static void |
2640 | encode_STACK_op(const struct ofpact_stack *stack_action, | |
2641 | struct nx_action_stack *nasp) | |
c0621c39 | 2642 | { |
bad8a439 BP |
2643 | struct ofpbuf b; |
2644 | ovs_be16 n_bits; | |
2645 | ||
c2d936a4 | 2646 | nasp->offset = htons(stack_action->subfield.ofs); |
bad8a439 BP |
2647 | |
2648 | ofpbuf_use_stack(&b, nasp, ntohs(nasp->len)); | |
2649 | ofpbuf_put_uninit(&b, OBJECT_OFFSETOF(nasp, pad)); | |
2650 | nx_put_header(&b, stack_action->subfield.field->id, 0, false); | |
2651 | n_bits = htons(stack_action->subfield.n_bits); | |
2652 | ofpbuf_put(&b, &n_bits, sizeof n_bits); | |
c0621c39 AW |
2653 | } |
2654 | ||
c2d936a4 BP |
2655 | static void |
2656 | encode_STACK_PUSH(const struct ofpact_stack *stack, | |
2657 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
2658 | { | |
2659 | encode_STACK_op(stack, put_NXAST_STACK_PUSH(out)); | |
2660 | } | |
8e97815e | 2661 | |
c2d936a4 BP |
2662 | static void |
2663 | encode_STACK_POP(const struct ofpact_stack *stack, | |
2664 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
8e97815e | 2665 | { |
c2d936a4 BP |
2666 | encode_STACK_op(stack, put_NXAST_STACK_POP(out)); |
2667 | } | |
8e97815e | 2668 | |
cab50449 | 2669 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
2670 | parse_STACK_PUSH(char *arg, struct ofpbuf *ofpacts, |
2671 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
2672 | { | |
2673 | return nxm_parse_stack_action(ofpact_put_STACK_PUSH(ofpacts), arg); | |
2674 | } | |
8e97815e | 2675 | |
cab50449 | 2676 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
2677 | parse_STACK_POP(char *arg, struct ofpbuf *ofpacts, |
2678 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
2679 | { | |
2680 | return nxm_parse_stack_action(ofpact_put_STACK_POP(ofpacts), arg); | |
8e97815e BP |
2681 | } |
2682 | ||
c2d936a4 BP |
2683 | static void |
2684 | format_STACK_PUSH(const struct ofpact_stack *a, struct ds *s) | |
8e97815e | 2685 | { |
c2d936a4 BP |
2686 | nxm_format_stack_push(a, s); |
2687 | } | |
8e97815e | 2688 | |
c2d936a4 BP |
2689 | static void |
2690 | format_STACK_POP(const struct ofpact_stack *a, struct ds *s) | |
2691 | { | |
2692 | nxm_format_stack_pop(a, s); | |
2693 | } | |
2694 | \f | |
2695 | /* Action structure for NXAST_DEC_TTL_CNT_IDS. | |
2696 | * | |
2697 | * If the packet is not IPv4 or IPv6, does nothing. For IPv4 or IPv6, if the | |
2698 | * TTL or hop limit is at least 2, decrements it by 1. Otherwise, if TTL or | |
2699 | * hop limit is 0 or 1, sends a packet-in to the controllers with each of the | |
2700 | * 'n_controllers' controller IDs specified in 'cnt_ids'. | |
2701 | * | |
2702 | * (This differs from NXAST_DEC_TTL in that for NXAST_DEC_TTL the packet-in is | |
2703 | * sent only to controllers with id 0.) | |
2704 | */ | |
2705 | struct nx_action_cnt_ids { | |
2706 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
2707 | ovs_be16 len; /* Length including slaves. */ | |
2708 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
2709 | ovs_be16 subtype; /* NXAST_DEC_TTL_CNT_IDS. */ | |
2710 | ||
2711 | ovs_be16 n_controllers; /* Number of controllers. */ | |
2712 | uint8_t zeros[4]; /* Must be zero. */ | |
2713 | ||
2714 | /* Followed by 1 or more controller ids. | |
2715 | * | |
2716 | * uint16_t cnt_ids[]; // Controller ids. | |
2717 | * uint8_t pad[]; // Must be 0 to 8-byte align cnt_ids[]. | |
2718 | */ | |
2719 | }; | |
2720 | OFP_ASSERT(sizeof(struct nx_action_cnt_ids) == 16); | |
2721 | ||
2722 | static enum ofperr | |
2723 | decode_OFPAT_RAW_DEC_NW_TTL(struct ofpbuf *out) | |
2724 | { | |
2725 | uint16_t id = 0; | |
2726 | struct ofpact_cnt_ids *ids; | |
2727 | enum ofperr error = 0; | |
2728 | ||
2729 | ids = ofpact_put_DEC_TTL(out); | |
2730 | ids->n_controllers = 1; | |
2731 | ofpbuf_put(out, &id, sizeof id); | |
6fd6ed71 | 2732 | ids = out->header; |
c2d936a4 BP |
2733 | ofpact_update_len(out, &ids->ofpact); |
2734 | return error; | |
2735 | } | |
2736 | ||
2737 | static enum ofperr | |
2738 | decode_NXAST_RAW_DEC_TTL_CNT_IDS(const struct nx_action_cnt_ids *nac_ids, | |
2739 | struct ofpbuf *out) | |
2740 | { | |
2741 | struct ofpact_cnt_ids *ids; | |
2742 | size_t ids_size; | |
2743 | int i; | |
2744 | ||
2745 | ids = ofpact_put_DEC_TTL(out); | |
2746 | ids->ofpact.raw = NXAST_RAW_DEC_TTL_CNT_IDS; | |
2747 | ids->n_controllers = ntohs(nac_ids->n_controllers); | |
2748 | ids_size = ntohs(nac_ids->len) - sizeof *nac_ids; | |
2749 | ||
2750 | if (!is_all_zeros(nac_ids->zeros, sizeof nac_ids->zeros)) { | |
2751 | return OFPERR_NXBRC_MUST_BE_ZERO; | |
8e97815e | 2752 | } |
c2d936a4 BP |
2753 | |
2754 | if (ids_size < ids->n_controllers * sizeof(ovs_be16)) { | |
2755 | VLOG_WARN_RL(&rl, "Nicira action dec_ttl_cnt_ids only has %"PRIuSIZE" " | |
2756 | "bytes allocated for controller ids. %"PRIuSIZE" bytes " | |
2757 | "are required for %"PRIu16" controllers.", | |
2758 | ids_size, ids->n_controllers * sizeof(ovs_be16), | |
2759 | ids->n_controllers); | |
2760 | return OFPERR_OFPBAC_BAD_LEN; | |
2761 | } | |
2762 | ||
2763 | for (i = 0; i < ids->n_controllers; i++) { | |
2764 | uint16_t id = ntohs(((ovs_be16 *)(nac_ids + 1))[i]); | |
2765 | ofpbuf_put(out, &id, sizeof id); | |
6fd6ed71 | 2766 | ids = out->header; |
c2d936a4 BP |
2767 | } |
2768 | ||
2769 | ofpact_update_len(out, &ids->ofpact); | |
2770 | ||
2771 | return 0; | |
8e97815e BP |
2772 | } |
2773 | ||
c2d936a4 BP |
2774 | static void |
2775 | encode_DEC_TTL(const struct ofpact_cnt_ids *dec_ttl, | |
2776 | enum ofp_version ofp_version, struct ofpbuf *out) | |
8e97815e | 2777 | { |
c2d936a4 BP |
2778 | if (dec_ttl->ofpact.raw == NXAST_RAW_DEC_TTL_CNT_IDS |
2779 | || dec_ttl->n_controllers != 1 | |
2780 | || dec_ttl->cnt_ids[0] != 0) { | |
2781 | struct nx_action_cnt_ids *nac_ids = put_NXAST_DEC_TTL_CNT_IDS(out); | |
2782 | int ids_len = ROUND_UP(2 * dec_ttl->n_controllers, OFP_ACTION_ALIGN); | |
2783 | ovs_be16 *ids; | |
2784 | size_t i; | |
8e97815e | 2785 | |
c2d936a4 BP |
2786 | nac_ids->len = htons(ntohs(nac_ids->len) + ids_len); |
2787 | nac_ids->n_controllers = htons(dec_ttl->n_controllers); | |
2788 | ||
2789 | ids = ofpbuf_put_zeros(out, ids_len); | |
2790 | for (i = 0; i < dec_ttl->n_controllers; i++) { | |
2791 | ids[i] = htons(dec_ttl->cnt_ids[i]); | |
8e97815e | 2792 | } |
c2d936a4 BP |
2793 | } else { |
2794 | put_OFPAT_DEC_NW_TTL(out, ofp_version); | |
8e97815e | 2795 | } |
8e97815e BP |
2796 | } |
2797 | ||
c2d936a4 BP |
2798 | static void |
2799 | parse_noargs_dec_ttl(struct ofpbuf *ofpacts) | |
d01c980f | 2800 | { |
c2d936a4 BP |
2801 | struct ofpact_cnt_ids *ids; |
2802 | uint16_t id = 0; | |
2803 | ||
2804 | ofpact_put_DEC_TTL(ofpacts); | |
2805 | ofpbuf_put(ofpacts, &id, sizeof id); | |
6fd6ed71 | 2806 | ids = ofpacts->header; |
c2d936a4 BP |
2807 | ids->n_controllers++; |
2808 | ofpact_update_len(ofpacts, &ids->ofpact); | |
d01c980f BP |
2809 | } |
2810 | ||
cab50449 | 2811 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
2812 | parse_DEC_TTL(char *arg, struct ofpbuf *ofpacts, |
2813 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
d01c980f | 2814 | { |
c2d936a4 BP |
2815 | if (*arg == '\0') { |
2816 | parse_noargs_dec_ttl(ofpacts); | |
2817 | } else { | |
2818 | struct ofpact_cnt_ids *ids; | |
2819 | char *cntr; | |
2820 | ||
2821 | ids = ofpact_put_DEC_TTL(ofpacts); | |
2822 | ids->ofpact.raw = NXAST_RAW_DEC_TTL_CNT_IDS; | |
2823 | for (cntr = strtok_r(arg, ", ", &arg); cntr != NULL; | |
2824 | cntr = strtok_r(NULL, ", ", &arg)) { | |
2825 | uint16_t id = atoi(cntr); | |
2826 | ||
2827 | ofpbuf_put(ofpacts, &id, sizeof id); | |
6fd6ed71 | 2828 | ids = ofpacts->header; |
c2d936a4 BP |
2829 | ids->n_controllers++; |
2830 | } | |
2831 | if (!ids->n_controllers) { | |
2832 | return xstrdup("dec_ttl_cnt_ids: expected at least one controller " | |
2833 | "id."); | |
2834 | } | |
2835 | ofpact_update_len(ofpacts, &ids->ofpact); | |
2836 | } | |
2837 | return NULL; | |
d01c980f BP |
2838 | } |
2839 | ||
c2d936a4 BP |
2840 | static void |
2841 | format_DEC_TTL(const struct ofpact_cnt_ids *a, struct ds *s) | |
d01c980f | 2842 | { |
c2d936a4 | 2843 | size_t i; |
d01c980f | 2844 | |
c2d936a4 BP |
2845 | ds_put_cstr(s, "dec_ttl"); |
2846 | if (a->ofpact.raw == NXAST_RAW_DEC_TTL_CNT_IDS) { | |
2847 | ds_put_cstr(s, "("); | |
2848 | for (i = 0; i < a->n_controllers; i++) { | |
2849 | if (i) { | |
2850 | ds_put_cstr(s, ","); | |
d01c980f | 2851 | } |
c2d936a4 BP |
2852 | ds_put_format(s, "%"PRIu16, a->cnt_ids[i]); |
2853 | } | |
2854 | ds_put_cstr(s, ")"); | |
d01c980f BP |
2855 | } |
2856 | } | |
c2d936a4 BP |
2857 | \f |
2858 | /* Set MPLS label actions. */ | |
d01c980f BP |
2859 | |
2860 | static enum ofperr | |
c2d936a4 | 2861 | decode_OFPAT_RAW_SET_MPLS_LABEL(ovs_be32 label, struct ofpbuf *out) |
d01c980f | 2862 | { |
c2d936a4 BP |
2863 | ofpact_put_SET_MPLS_LABEL(out)->label = label; |
2864 | return 0; | |
2865 | } | |
d01c980f | 2866 | |
c2d936a4 BP |
2867 | static void |
2868 | encode_SET_MPLS_LABEL(const struct ofpact_mpls_label *label, | |
2869 | enum ofp_version ofp_version, | |
2870 | struct ofpbuf *out) | |
2871 | { | |
2872 | if (ofp_version < OFP12_VERSION) { | |
2873 | put_OFPAT_SET_MPLS_LABEL(out, ofp_version, label->label); | |
2874 | } else { | |
2875 | ofpact_put_set_field(out, ofp_version, MFF_MPLS_LABEL, | |
2876 | ntohl(label->label)); | |
d01c980f | 2877 | } |
c2d936a4 | 2878 | } |
d01c980f | 2879 | |
cab50449 | 2880 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
2881 | parse_SET_MPLS_LABEL(char *arg, struct ofpbuf *ofpacts, |
2882 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
2883 | { | |
2884 | struct ofpact_mpls_label *mpls_label = ofpact_put_SET_MPLS_LABEL(ofpacts); | |
2885 | if (*arg == '\0') { | |
2886 | return xstrdup("set_mpls_label: expected label."); | |
d01c980f | 2887 | } |
c2d936a4 BP |
2888 | |
2889 | mpls_label->label = htonl(atoi(arg)); | |
2890 | return NULL; | |
d01c980f BP |
2891 | } |
2892 | ||
2893 | static void | |
c2d936a4 | 2894 | format_SET_MPLS_LABEL(const struct ofpact_mpls_label *a, struct ds *s) |
d01c980f | 2895 | { |
c2d936a4 | 2896 | ds_put_format(s, "set_mpls_label(%"PRIu32")", ntohl(a->label)); |
d01c980f | 2897 | } |
c2d936a4 BP |
2898 | \f |
2899 | /* Set MPLS TC actions. */ | |
d01c980f | 2900 | |
c2d936a4 BP |
2901 | static enum ofperr |
2902 | decode_OFPAT_RAW_SET_MPLS_TC(uint8_t tc, struct ofpbuf *out) | |
d01c980f | 2903 | { |
c2d936a4 BP |
2904 | ofpact_put_SET_MPLS_TC(out)->tc = tc; |
2905 | return 0; | |
2906 | } | |
d01c980f | 2907 | |
c2d936a4 BP |
2908 | static void |
2909 | encode_SET_MPLS_TC(const struct ofpact_mpls_tc *tc, | |
2910 | enum ofp_version ofp_version, struct ofpbuf *out) | |
2911 | { | |
2912 | if (ofp_version < OFP12_VERSION) { | |
2913 | put_OFPAT_SET_MPLS_TC(out, ofp_version, tc->tc); | |
2914 | } else { | |
2915 | ofpact_put_set_field(out, ofp_version, MFF_MPLS_TC, tc->tc); | |
8f2cded4 | 2916 | } |
c2d936a4 | 2917 | } |
8f2cded4 | 2918 | |
cab50449 | 2919 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
2920 | parse_SET_MPLS_TC(char *arg, struct ofpbuf *ofpacts, |
2921 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
2922 | { | |
2923 | struct ofpact_mpls_tc *mpls_tc = ofpact_put_SET_MPLS_TC(ofpacts); | |
d01c980f | 2924 | |
c2d936a4 BP |
2925 | if (*arg == '\0') { |
2926 | return xstrdup("set_mpls_tc: expected tc."); | |
d01c980f BP |
2927 | } |
2928 | ||
c2d936a4 BP |
2929 | mpls_tc->tc = atoi(arg); |
2930 | return NULL; | |
2931 | } | |
d01c980f | 2932 | |
c2d936a4 BP |
2933 | static void |
2934 | format_SET_MPLS_TC(const struct ofpact_mpls_tc *a, struct ds *s) | |
2935 | { | |
2936 | ds_put_format(s, "set_mpls_ttl(%"PRIu8")", a->tc); | |
2937 | } | |
2938 | \f | |
2939 | /* Set MPLS TTL actions. */ | |
d01c980f | 2940 | |
c2d936a4 BP |
2941 | static enum ofperr |
2942 | decode_OFPAT_RAW_SET_MPLS_TTL(uint8_t ttl, struct ofpbuf *out) | |
2943 | { | |
2944 | ofpact_put_SET_MPLS_TTL(out)->ttl = ttl; | |
2945 | return 0; | |
2946 | } | |
638a19b0 | 2947 | |
c2d936a4 BP |
2948 | static void |
2949 | encode_SET_MPLS_TTL(const struct ofpact_mpls_ttl *ttl, | |
2950 | enum ofp_version ofp_version, struct ofpbuf *out) | |
2951 | { | |
2952 | put_OFPAT_SET_MPLS_TTL(out, ofp_version, ttl->ttl); | |
2953 | } | |
638a19b0 | 2954 | |
c2d936a4 BP |
2955 | /* Parses 'arg' as the argument to a "set_mpls_ttl" action, and appends such an |
2956 | * action to 'ofpacts'. | |
2957 | * | |
2958 | * Returns NULL if successful, otherwise a malloc()'d string describing the | |
2959 | * error. The caller is responsible for freeing the returned string. */ | |
cab50449 | 2960 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
2961 | parse_SET_MPLS_TTL(char *arg, struct ofpbuf *ofpacts, |
2962 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
2963 | { | |
2964 | struct ofpact_mpls_ttl *mpls_ttl = ofpact_put_SET_MPLS_TTL(ofpacts); | |
d01c980f | 2965 | |
c2d936a4 BP |
2966 | if (*arg == '\0') { |
2967 | return xstrdup("set_mpls_ttl: expected ttl."); | |
b19e8793 | 2968 | } |
7fdb60a7 | 2969 | |
c2d936a4 BP |
2970 | mpls_ttl->ttl = atoi(arg); |
2971 | return NULL; | |
2972 | } | |
4cceacb9 | 2973 | |
c2d936a4 BP |
2974 | static void |
2975 | format_SET_MPLS_TTL(const struct ofpact_mpls_ttl *a, struct ds *s) | |
2976 | { | |
2977 | ds_put_format(s, "set_mpls_ttl(%"PRIu8")", a->ttl); | |
2978 | } | |
2979 | \f | |
2980 | /* Decrement MPLS TTL actions. */ | |
4cceacb9 | 2981 | |
c2d936a4 BP |
2982 | static enum ofperr |
2983 | decode_OFPAT_RAW_DEC_MPLS_TTL(struct ofpbuf *out) | |
2984 | { | |
2985 | ofpact_put_DEC_MPLS_TTL(out); | |
2986 | return 0; | |
2987 | } | |
8dd54666 | 2988 | |
c2d936a4 BP |
2989 | static void |
2990 | encode_DEC_MPLS_TTL(const struct ofpact_null *null OVS_UNUSED, | |
2991 | enum ofp_version ofp_version, struct ofpbuf *out) | |
2992 | { | |
2993 | put_OFPAT_DEC_MPLS_TTL(out, ofp_version); | |
2994 | } | |
2995 | ||
cab50449 | 2996 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
2997 | parse_DEC_MPLS_TTL(char *arg OVS_UNUSED, struct ofpbuf *ofpacts, |
2998 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
2999 | { | |
3000 | ofpact_put_DEC_MPLS_TTL(ofpacts); | |
3001 | return NULL; | |
3002 | } | |
3003 | ||
3004 | static void | |
3005 | format_DEC_MPLS_TTL(const struct ofpact_null *a OVS_UNUSED, struct ds *s) | |
3006 | { | |
3007 | ds_put_cstr(s, "dec_mpls_ttl"); | |
3008 | } | |
3009 | \f | |
3010 | /* Push MPLS label action. */ | |
3011 | ||
3012 | static enum ofperr | |
3013 | decode_OFPAT_RAW_PUSH_MPLS(ovs_be16 ethertype, struct ofpbuf *out) | |
3014 | { | |
3015 | struct ofpact_push_mpls *oam; | |
3016 | ||
3017 | if (!eth_type_mpls(ethertype)) { | |
3018 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
8dd54666 | 3019 | } |
c2d936a4 BP |
3020 | oam = ofpact_put_PUSH_MPLS(out); |
3021 | oam->ethertype = ethertype; | |
d01c980f | 3022 | |
c2d936a4 BP |
3023 | return 0; |
3024 | } | |
3025 | ||
3026 | static void | |
3027 | encode_PUSH_MPLS(const struct ofpact_push_mpls *push_mpls, | |
3028 | enum ofp_version ofp_version, struct ofpbuf *out) | |
3029 | { | |
3030 | put_OFPAT_PUSH_MPLS(out, ofp_version, push_mpls->ethertype); | |
3031 | } | |
3032 | ||
cab50449 | 3033 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
3034 | parse_PUSH_MPLS(char *arg, struct ofpbuf *ofpacts, |
3035 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
3036 | { | |
3037 | uint16_t ethertype; | |
3038 | char *error; | |
3039 | ||
3040 | error = str_to_u16(arg, "push_mpls", ðertype); | |
3041 | if (!error) { | |
3042 | ofpact_put_PUSH_MPLS(ofpacts)->ethertype = htons(ethertype); | |
d01c980f BP |
3043 | } |
3044 | return error; | |
3045 | } | |
c2d936a4 BP |
3046 | |
3047 | static void | |
3048 | format_PUSH_MPLS(const struct ofpact_push_mpls *a, struct ds *s) | |
3049 | { | |
3050 | ds_put_format(s, "push_mpls:0x%04"PRIx16, ntohs(a->ethertype)); | |
3051 | } | |
d01c980f | 3052 | \f |
c2d936a4 BP |
3053 | /* Pop MPLS label action. */ |
3054 | ||
3055 | static enum ofperr | |
3056 | decode_OFPAT_RAW_POP_MPLS(ovs_be16 ethertype, struct ofpbuf *out) | |
57ad4e9e | 3057 | { |
c2d936a4 BP |
3058 | ofpact_put_POP_MPLS(out)->ethertype = ethertype; |
3059 | return 0; | |
3060 | } | |
57ad4e9e | 3061 | |
c2d936a4 BP |
3062 | static void |
3063 | encode_POP_MPLS(const struct ofpact_pop_mpls *pop_mpls, | |
3064 | enum ofp_version ofp_version, struct ofpbuf *out) | |
3065 | { | |
3066 | put_OFPAT_POP_MPLS(out, ofp_version, pop_mpls->ethertype); | |
3067 | } | |
3068 | ||
cab50449 | 3069 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
3070 | parse_POP_MPLS(char *arg, struct ofpbuf *ofpacts, |
3071 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
3072 | { | |
3073 | uint16_t ethertype; | |
3074 | char *error; | |
3075 | ||
3076 | error = str_to_u16(arg, "pop_mpls", ðertype); | |
3077 | if (!error) { | |
3078 | ofpact_put_POP_MPLS(ofpacts)->ethertype = htons(ethertype); | |
57ad4e9e | 3079 | } |
c2d936a4 | 3080 | return error; |
57ad4e9e BP |
3081 | } |
3082 | ||
ba2fe8e9 | 3083 | static void |
c2d936a4 | 3084 | format_POP_MPLS(const struct ofpact_pop_mpls *a, struct ds *s) |
ba2fe8e9 | 3085 | { |
c2d936a4 | 3086 | ds_put_format(s, "pop_mpls:0x%04"PRIx16, ntohs(a->ethertype)); |
ba2fe8e9 | 3087 | } |
c2d936a4 BP |
3088 | \f |
3089 | /* Set tunnel ID actions. */ | |
ba2fe8e9 | 3090 | |
f25d0cf3 | 3091 | static enum ofperr |
c2d936a4 | 3092 | decode_NXAST_RAW_SET_TUNNEL(uint32_t tun_id, struct ofpbuf *out) |
f25d0cf3 | 3093 | { |
c2d936a4 BP |
3094 | struct ofpact_tunnel *tunnel = ofpact_put_SET_TUNNEL(out); |
3095 | tunnel->ofpact.raw = NXAST_RAW_SET_TUNNEL; | |
3096 | tunnel->tun_id = tun_id; | |
3097 | return 0; | |
3098 | } | |
f25d0cf3 | 3099 | |
c2d936a4 BP |
3100 | static enum ofperr |
3101 | decode_NXAST_RAW_SET_TUNNEL64(uint64_t tun_id, struct ofpbuf *out) | |
3102 | { | |
3103 | struct ofpact_tunnel *tunnel = ofpact_put_SET_TUNNEL(out); | |
3104 | tunnel->ofpact.raw = NXAST_RAW_SET_TUNNEL64; | |
3105 | tunnel->tun_id = tun_id; | |
3106 | return 0; | |
3107 | } | |
f25d0cf3 | 3108 | |
c2d936a4 BP |
3109 | static void |
3110 | encode_SET_TUNNEL(const struct ofpact_tunnel *tunnel, | |
3111 | enum ofp_version ofp_version, struct ofpbuf *out) | |
3112 | { | |
3113 | uint64_t tun_id = tunnel->tun_id; | |
f25d0cf3 | 3114 | |
c2d936a4 BP |
3115 | if (ofp_version < OFP12_VERSION) { |
3116 | if (tun_id <= UINT32_MAX | |
3117 | && tunnel->ofpact.raw != NXAST_RAW_SET_TUNNEL64) { | |
3118 | put_NXAST_SET_TUNNEL(out, tun_id); | |
3119 | } else { | |
3120 | put_NXAST_SET_TUNNEL64(out, tun_id); | |
f25d0cf3 | 3121 | } |
c2d936a4 BP |
3122 | } else { |
3123 | ofpact_put_set_field(out, ofp_version, MFF_TUN_ID, tun_id); | |
3124 | } | |
3125 | } | |
f25d0cf3 | 3126 | |
cab50449 | 3127 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
3128 | parse_set_tunnel(char *arg, struct ofpbuf *ofpacts, |
3129 | enum ofp_raw_action_type raw) | |
3130 | { | |
3131 | struct ofpact_tunnel *tunnel; | |
ca287d20 | 3132 | |
c2d936a4 BP |
3133 | tunnel = ofpact_put_SET_TUNNEL(ofpacts); |
3134 | tunnel->ofpact.raw = raw; | |
3135 | return str_to_u64(arg, &tunnel->tun_id); | |
3136 | } | |
8621547c | 3137 | |
cab50449 | 3138 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
3139 | parse_SET_TUNNEL(char *arg, struct ofpbuf *ofpacts, |
3140 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
3141 | { | |
3142 | return parse_set_tunnel(arg, ofpacts, NXAST_RAW_SET_TUNNEL); | |
3143 | } | |
8621547c | 3144 | |
c2d936a4 BP |
3145 | static void |
3146 | format_SET_TUNNEL(const struct ofpact_tunnel *a, struct ds *s) | |
3147 | { | |
3148 | ds_put_format(s, "set_tunnel%s:%#"PRIx64, | |
3149 | (a->tun_id > UINT32_MAX | |
3150 | || a->ofpact.raw == NXAST_RAW_SET_TUNNEL64 ? "64" : ""), | |
3151 | a->tun_id); | |
3152 | } | |
3153 | \f | |
3154 | /* Set queue action. */ | |
8621547c | 3155 | |
c2d936a4 BP |
3156 | static enum ofperr |
3157 | decode_OFPAT_RAW_SET_QUEUE(uint32_t queue_id, struct ofpbuf *out) | |
3158 | { | |
3159 | ofpact_put_SET_QUEUE(out)->queue_id = queue_id; | |
3160 | return 0; | |
3161 | } | |
8621547c | 3162 | |
c2d936a4 BP |
3163 | static void |
3164 | encode_SET_QUEUE(const struct ofpact_queue *queue, | |
3165 | enum ofp_version ofp_version, struct ofpbuf *out) | |
3166 | { | |
3167 | put_OFPAT_SET_QUEUE(out, ofp_version, queue->queue_id); | |
3168 | } | |
8621547c | 3169 | |
cab50449 | 3170 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
3171 | parse_SET_QUEUE(char *arg, struct ofpbuf *ofpacts, |
3172 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
3173 | { | |
3174 | return str_to_u32(arg, &ofpact_put_SET_QUEUE(ofpacts)->queue_id); | |
3175 | } | |
8621547c | 3176 | |
c2d936a4 BP |
3177 | static void |
3178 | format_SET_QUEUE(const struct ofpact_queue *a, struct ds *s) | |
3179 | { | |
3180 | ds_put_format(s, "set_queue:%"PRIu32, a->queue_id); | |
3181 | } | |
3182 | \f | |
3183 | /* Pop queue action. */ | |
1e7db674 | 3184 | |
c2d936a4 BP |
3185 | static enum ofperr |
3186 | decode_NXAST_RAW_POP_QUEUE(struct ofpbuf *out) | |
3187 | { | |
3188 | ofpact_put_POP_QUEUE(out); | |
3189 | return 0; | |
3190 | } | |
f25d0cf3 | 3191 | |
c2d936a4 BP |
3192 | static void |
3193 | encode_POP_QUEUE(const struct ofpact_null *null OVS_UNUSED, | |
3194 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
3195 | { | |
3196 | put_NXAST_POP_QUEUE(out); | |
3197 | } | |
f25d0cf3 | 3198 | |
cab50449 | 3199 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
3200 | parse_POP_QUEUE(const char *arg OVS_UNUSED, struct ofpbuf *ofpacts, |
3201 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
3202 | { | |
3203 | ofpact_put_POP_QUEUE(ofpacts); | |
3204 | return NULL; | |
3205 | } | |
f25d0cf3 | 3206 | |
c2d936a4 BP |
3207 | static void |
3208 | format_POP_QUEUE(const struct ofpact_null *a OVS_UNUSED, struct ds *s) | |
3209 | { | |
3210 | ds_put_cstr(s, "pop_queue"); | |
3211 | } | |
3212 | \f | |
3213 | /* Action structure for NXAST_FIN_TIMEOUT. | |
3214 | * | |
3215 | * This action changes the idle timeout or hard timeout, or both, of this | |
3216 | * OpenFlow rule when the rule matches a TCP packet with the FIN or RST flag. | |
3217 | * When such a packet is observed, the action reduces the rule's idle timeout | |
3218 | * to 'fin_idle_timeout' and its hard timeout to 'fin_hard_timeout'. This | |
3219 | * action has no effect on an existing timeout that is already shorter than the | |
3220 | * one that the action specifies. A 'fin_idle_timeout' or 'fin_hard_timeout' | |
3221 | * of zero has no effect on the respective timeout. | |
3222 | * | |
3223 | * 'fin_idle_timeout' and 'fin_hard_timeout' are measured in seconds. | |
3224 | * 'fin_hard_timeout' specifies time since the flow's creation, not since the | |
3225 | * receipt of the FIN or RST. | |
3226 | * | |
3227 | * This is useful for quickly discarding learned TCP flows that otherwise will | |
3228 | * take a long time to expire. | |
3229 | * | |
3230 | * This action is intended for use with an OpenFlow rule that matches only a | |
3231 | * single TCP flow. If the rule matches multiple TCP flows (e.g. it wildcards | |
3232 | * all TCP traffic, or all TCP traffic to a particular port), then any FIN or | |
3233 | * RST in any of those flows will cause the entire OpenFlow rule to expire | |
3234 | * early, which is not normally desirable. | |
3235 | */ | |
3236 | struct nx_action_fin_timeout { | |
3237 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
3238 | ovs_be16 len; /* 16. */ | |
3239 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
3240 | ovs_be16 subtype; /* NXAST_FIN_TIMEOUT. */ | |
3241 | ovs_be16 fin_idle_timeout; /* New idle timeout, if nonzero. */ | |
3242 | ovs_be16 fin_hard_timeout; /* New hard timeout, if nonzero. */ | |
3243 | ovs_be16 pad; /* Must be zero. */ | |
3244 | }; | |
3245 | OFP_ASSERT(sizeof(struct nx_action_fin_timeout) == 16); | |
f25d0cf3 | 3246 | |
c2d936a4 BP |
3247 | static enum ofperr |
3248 | decode_NXAST_RAW_FIN_TIMEOUT(const struct nx_action_fin_timeout *naft, | |
3249 | struct ofpbuf *out) | |
3250 | { | |
3251 | struct ofpact_fin_timeout *oft; | |
8621547c | 3252 | |
c2d936a4 BP |
3253 | oft = ofpact_put_FIN_TIMEOUT(out); |
3254 | oft->fin_idle_timeout = ntohs(naft->fin_idle_timeout); | |
3255 | oft->fin_hard_timeout = ntohs(naft->fin_hard_timeout); | |
3256 | return 0; | |
3257 | } | |
f25d0cf3 | 3258 | |
c2d936a4 BP |
3259 | static void |
3260 | encode_FIN_TIMEOUT(const struct ofpact_fin_timeout *fin_timeout, | |
3261 | enum ofp_version ofp_version OVS_UNUSED, | |
3262 | struct ofpbuf *out) | |
3263 | { | |
3264 | struct nx_action_fin_timeout *naft = put_NXAST_FIN_TIMEOUT(out); | |
3265 | naft->fin_idle_timeout = htons(fin_timeout->fin_idle_timeout); | |
3266 | naft->fin_hard_timeout = htons(fin_timeout->fin_hard_timeout); | |
3267 | } | |
f25d0cf3 | 3268 | |
cab50449 | 3269 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
3270 | parse_FIN_TIMEOUT(char *arg, struct ofpbuf *ofpacts, |
3271 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
3272 | { | |
3273 | struct ofpact_fin_timeout *oft = ofpact_put_FIN_TIMEOUT(ofpacts); | |
3274 | char *key, *value; | |
f25d0cf3 | 3275 | |
c2d936a4 BP |
3276 | while (ofputil_parse_key_value(&arg, &key, &value)) { |
3277 | char *error; | |
b02475c5 | 3278 | |
c2d936a4 BP |
3279 | if (!strcmp(key, "idle_timeout")) { |
3280 | error = str_to_u16(value, key, &oft->fin_idle_timeout); | |
3281 | } else if (!strcmp(key, "hard_timeout")) { | |
3282 | error = str_to_u16(value, key, &oft->fin_hard_timeout); | |
3283 | } else { | |
3284 | error = xasprintf("invalid key '%s' in 'fin_timeout' argument", | |
3285 | key); | |
8621547c | 3286 | } |
8dd54666 | 3287 | |
c2d936a4 BP |
3288 | if (error) { |
3289 | return error; | |
9cae45dc | 3290 | } |
9cae45dc | 3291 | } |
c2d936a4 BP |
3292 | return NULL; |
3293 | } | |
e3b56933 | 3294 | |
c2d936a4 BP |
3295 | static void |
3296 | format_FIN_TIMEOUT(const struct ofpact_fin_timeout *a, struct ds *s) | |
3297 | { | |
3298 | ds_put_cstr(s, "fin_timeout("); | |
3299 | if (a->fin_idle_timeout) { | |
3300 | ds_put_format(s, "idle_timeout=%"PRIu16",", a->fin_idle_timeout); | |
7e9f8266 | 3301 | } |
c2d936a4 BP |
3302 | if (a->fin_hard_timeout) { |
3303 | ds_put_format(s, "hard_timeout=%"PRIu16",", a->fin_hard_timeout); | |
f25d0cf3 | 3304 | } |
c2d936a4 BP |
3305 | ds_chomp(s, ','); |
3306 | ds_put_char(s, ')'); | |
f25d0cf3 | 3307 | } |
c2d936a4 BP |
3308 | \f |
3309 | /* Action structures for NXAST_RESUBMIT and NXAST_RESUBMIT_TABLE. | |
eca39bce | 3310 | * |
c2d936a4 | 3311 | * These actions search one of the switch's flow tables: |
ba2fe8e9 | 3312 | * |
c2d936a4 BP |
3313 | * - For NXAST_RESUBMIT_TABLE only, if the 'table' member is not 255, then |
3314 | * it specifies the table to search. | |
ca287d20 | 3315 | * |
c2d936a4 BP |
3316 | * - Otherwise (for NXAST_RESUBMIT_TABLE with a 'table' of 255, or for |
3317 | * NXAST_RESUBMIT regardless of 'table'), it searches the current flow | |
3318 | * table, that is, the OpenFlow flow table that contains the flow from | |
3319 | * which this action was obtained. If this action did not come from a | |
3320 | * flow table (e.g. it came from an OFPT_PACKET_OUT message), then table 0 | |
3321 | * is the current table. | |
3322 | * | |
3323 | * The flow table lookup uses a flow that may be slightly modified from the | |
3324 | * original lookup: | |
3325 | * | |
3326 | * - For NXAST_RESUBMIT, the 'in_port' member of struct nx_action_resubmit | |
3327 | * is used as the flow's in_port. | |
3328 | * | |
3329 | * - For NXAST_RESUBMIT_TABLE, if the 'in_port' member is not OFPP_IN_PORT, | |
3330 | * then its value is used as the flow's in_port. Otherwise, the original | |
3331 | * in_port is used. | |
3332 | * | |
3333 | * - If actions that modify the flow (e.g. OFPAT_SET_VLAN_VID) precede the | |
3334 | * resubmit action, then the flow is updated with the new values. | |
3335 | * | |
3336 | * Following the lookup, the original in_port is restored. | |
3337 | * | |
3338 | * If the modified flow matched in the flow table, then the corresponding | |
3339 | * actions are executed. Afterward, actions following the resubmit in the | |
3340 | * original set of actions, if any, are executed; any changes made to the | |
3341 | * packet (e.g. changes to VLAN) by secondary actions persist when those | |
3342 | * actions are executed, although the original in_port is restored. | |
3343 | * | |
3344 | * Resubmit actions may be used any number of times within a set of actions. | |
3345 | * | |
3346 | * Resubmit actions may nest to an implementation-defined depth. Beyond this | |
3347 | * implementation-defined depth, further resubmit actions are simply ignored. | |
3348 | * | |
3349 | * NXAST_RESUBMIT ignores 'table' and 'pad'. NXAST_RESUBMIT_TABLE requires | |
3350 | * 'pad' to be all-bits-zero. | |
3351 | * | |
3352 | * Open vSwitch 1.0.1 and earlier did not support recursion. Open vSwitch | |
3353 | * before 1.2.90 did not support NXAST_RESUBMIT_TABLE. | |
3354 | */ | |
3355 | struct nx_action_resubmit { | |
3356 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
3357 | ovs_be16 len; /* Length is 16. */ | |
3358 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
3359 | ovs_be16 subtype; /* NXAST_RESUBMIT. */ | |
3360 | ovs_be16 in_port; /* New in_port for checking flow table. */ | |
3361 | uint8_t table; /* NXAST_RESUBMIT_TABLE: table to use. */ | |
3362 | uint8_t pad[3]; | |
3363 | }; | |
3364 | OFP_ASSERT(sizeof(struct nx_action_resubmit) == 16); | |
3365 | ||
3366 | static enum ofperr | |
3367 | decode_NXAST_RAW_RESUBMIT(uint16_t port, struct ofpbuf *out) | |
f25d0cf3 | 3368 | { |
c2d936a4 | 3369 | struct ofpact_resubmit *resubmit; |
f25d0cf3 | 3370 | |
c2d936a4 BP |
3371 | resubmit = ofpact_put_RESUBMIT(out); |
3372 | resubmit->ofpact.raw = NXAST_RAW_RESUBMIT; | |
3373 | resubmit->in_port = u16_to_ofp(port); | |
3374 | resubmit->table_id = 0xff; | |
3375 | return 0; | |
f25d0cf3 | 3376 | } |
4cceacb9 | 3377 | |
c2d936a4 BP |
3378 | static enum ofperr |
3379 | decode_NXAST_RAW_RESUBMIT_TABLE(const struct nx_action_resubmit *nar, | |
3380 | struct ofpbuf *out) | |
ba2fe8e9 | 3381 | { |
c2d936a4 | 3382 | struct ofpact_resubmit *resubmit; |
ba2fe8e9 | 3383 | |
c2d936a4 BP |
3384 | if (nar->pad[0] || nar->pad[1] || nar->pad[2]) { |
3385 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
3386 | } | |
3387 | ||
3388 | resubmit = ofpact_put_RESUBMIT(out); | |
3389 | resubmit->ofpact.raw = NXAST_RAW_RESUBMIT_TABLE; | |
3390 | resubmit->in_port = u16_to_ofp(ntohs(nar->in_port)); | |
3391 | resubmit->table_id = nar->table; | |
3392 | return 0; | |
ba2fe8e9 BP |
3393 | } |
3394 | ||
c2d936a4 BP |
3395 | static void |
3396 | encode_RESUBMIT(const struct ofpact_resubmit *resubmit, | |
3397 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
4cceacb9 | 3398 | { |
c2d936a4 | 3399 | uint16_t in_port = ofp_to_u16(resubmit->in_port); |
4cceacb9 | 3400 | |
c2d936a4 BP |
3401 | if (resubmit->table_id == 0xff |
3402 | && resubmit->ofpact.raw != NXAST_RAW_RESUBMIT_TABLE) { | |
3403 | put_NXAST_RESUBMIT(out, in_port); | |
3404 | } else { | |
3405 | struct nx_action_resubmit *nar = put_NXAST_RESUBMIT_TABLE(out); | |
3406 | nar->table = resubmit->table_id; | |
3407 | nar->in_port = htons(in_port); | |
3408 | } | |
3409 | } | |
6813ee7c | 3410 | |
cab50449 | 3411 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
3412 | parse_RESUBMIT(char *arg, struct ofpbuf *ofpacts, |
3413 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
3414 | { | |
3415 | struct ofpact_resubmit *resubmit; | |
3416 | char *in_port_s, *table_s; | |
6813ee7c | 3417 | |
c2d936a4 | 3418 | resubmit = ofpact_put_RESUBMIT(ofpacts); |
8f2cded4 | 3419 | |
c2d936a4 BP |
3420 | in_port_s = strsep(&arg, ","); |
3421 | if (in_port_s && in_port_s[0]) { | |
3422 | if (!ofputil_port_from_string(in_port_s, &resubmit->in_port)) { | |
3423 | return xasprintf("%s: resubmit to unknown port", in_port_s); | |
8f2cded4 | 3424 | } |
c2d936a4 BP |
3425 | } else { |
3426 | resubmit->in_port = OFPP_IN_PORT; | |
3427 | } | |
4cceacb9 | 3428 | |
c2d936a4 BP |
3429 | table_s = strsep(&arg, ","); |
3430 | if (table_s && table_s[0]) { | |
3431 | uint32_t table_id = 0; | |
3432 | char *error; | |
3433 | ||
3434 | error = str_to_u32(table_s, &table_id); | |
3435 | if (error) { | |
3436 | return error; | |
3437 | } | |
3438 | resubmit->table_id = table_id; | |
3439 | } else { | |
3440 | resubmit->table_id = 255; | |
4cceacb9 JS |
3441 | } |
3442 | ||
c2d936a4 BP |
3443 | if (resubmit->in_port == OFPP_IN_PORT && resubmit->table_id == 255) { |
3444 | return xstrdup("at least one \"in_port\" or \"table\" must be " | |
3445 | "specified on resubmit"); | |
3446 | } | |
3447 | return NULL; | |
3448 | } | |
3449 | ||
3450 | static void | |
3451 | format_RESUBMIT(const struct ofpact_resubmit *a, struct ds *s) | |
3452 | { | |
3453 | if (a->in_port != OFPP_IN_PORT && a->table_id == 255) { | |
3454 | ds_put_cstr(s, "resubmit:"); | |
3455 | ofputil_format_port(a->in_port, s); | |
3456 | } else { | |
3457 | ds_put_format(s, "resubmit("); | |
3458 | if (a->in_port != OFPP_IN_PORT) { | |
3459 | ofputil_format_port(a->in_port, s); | |
3460 | } | |
3461 | ds_put_char(s, ','); | |
3462 | if (a->table_id != 255) { | |
3463 | ds_put_format(s, "%"PRIu8, a->table_id); | |
3464 | } | |
3465 | ds_put_char(s, ')'); | |
3466 | } | |
3467 | } | |
3468 | \f | |
3469 | /* Action structure for NXAST_LEARN. | |
3470 | * | |
3471 | * This action adds or modifies a flow in an OpenFlow table, similar to | |
3472 | * OFPT_FLOW_MOD with OFPFC_MODIFY_STRICT as 'command'. The new flow has the | |
3473 | * specified idle timeout, hard timeout, priority, cookie, and flags. The new | |
3474 | * flow's match criteria and actions are built by applying each of the series | |
3475 | * of flow_mod_spec elements included as part of the action. | |
3476 | * | |
3477 | * A flow_mod_spec starts with a 16-bit header. A header that is all-bits-0 is | |
3478 | * a no-op used for padding the action as a whole to a multiple of 8 bytes in | |
3479 | * length. Otherwise, the flow_mod_spec can be thought of as copying 'n_bits' | |
3480 | * bits from a source to a destination. In this case, the header contains | |
3481 | * multiple fields: | |
3482 | * | |
3483 | * 15 14 13 12 11 10 0 | |
3484 | * +------+---+------+---------------------------------+ | |
3485 | * | 0 |src| dst | n_bits | | |
3486 | * +------+---+------+---------------------------------+ | |
3487 | * | |
3488 | * The meaning and format of a flow_mod_spec depends on 'src' and 'dst'. The | |
3489 | * following table summarizes the meaning of each possible combination. | |
3490 | * Details follow the table: | |
3491 | * | |
3492 | * src dst meaning | |
3493 | * --- --- ---------------------------------------------------------- | |
3494 | * 0 0 Add match criteria based on value in a field. | |
3495 | * 1 0 Add match criteria based on an immediate value. | |
3496 | * 0 1 Add NXAST_REG_LOAD action to copy field into a different field. | |
3497 | * 1 1 Add NXAST_REG_LOAD action to load immediate value into a field. | |
3498 | * 0 2 Add OFPAT_OUTPUT action to output to port from specified field. | |
3499 | * All other combinations are undefined and not allowed. | |
3500 | * | |
3501 | * The flow_mod_spec header is followed by a source specification and a | |
3502 | * destination specification. The format and meaning of the source | |
3503 | * specification depends on 'src': | |
3504 | * | |
3505 | * - If 'src' is 0, the source bits are taken from a field in the flow to | |
3506 | * which this action is attached. (This should be a wildcarded field. If | |
3507 | * its value is fully specified then the source bits being copied have | |
3508 | * constant values.) | |
3509 | * | |
3510 | * The source specification is an ovs_be32 'field' and an ovs_be16 'ofs'. | |
3511 | * 'field' is an nxm_header with nxm_hasmask=0, and 'ofs' the starting bit | |
3512 | * offset within that field. The source bits are field[ofs:ofs+n_bits-1]. | |
3513 | * 'field' and 'ofs' are subject to the same restrictions as the source | |
3514 | * field in NXAST_REG_MOVE. | |
3515 | * | |
3516 | * - If 'src' is 1, the source bits are a constant value. The source | |
3517 | * specification is (n_bits+15)/16*2 bytes long. Taking those bytes as a | |
3518 | * number in network order, the source bits are the 'n_bits' | |
3519 | * least-significant bits. The switch will report an error if other bits | |
3520 | * in the constant are nonzero. | |
3521 | * | |
3522 | * The flow_mod_spec destination specification, for 'dst' of 0 or 1, is an | |
3523 | * ovs_be32 'field' and an ovs_be16 'ofs'. 'field' is an nxm_header with | |
3524 | * nxm_hasmask=0 and 'ofs' is a starting bit offset within that field. The | |
3525 | * meaning of the flow_mod_spec depends on 'dst': | |
3526 | * | |
3527 | * - If 'dst' is 0, the flow_mod_spec specifies match criteria for the new | |
3528 | * flow. The new flow matches only if bits field[ofs:ofs+n_bits-1] in a | |
3529 | * packet equal the source bits. 'field' may be any nxm_header with | |
3530 | * nxm_hasmask=0 that is allowed in NXT_FLOW_MOD. | |
3531 | * | |
3532 | * Order is significant. Earlier flow_mod_specs must satisfy any | |
3533 | * prerequisites for matching fields specified later, by copying constant | |
3534 | * values into prerequisite fields. | |
3535 | * | |
3536 | * The switch will reject flow_mod_specs that do not satisfy NXM masking | |
3537 | * restrictions. | |
3538 | * | |
3539 | * - If 'dst' is 1, the flow_mod_spec specifies an NXAST_REG_LOAD action for | |
3540 | * the new flow. The new flow copies the source bits into | |
3541 | * field[ofs:ofs+n_bits-1]. Actions are executed in the same order as the | |
3542 | * flow_mod_specs. | |
3543 | * | |
3544 | * A single NXAST_REG_LOAD action writes no more than 64 bits, so n_bits | |
3545 | * greater than 64 yields multiple NXAST_REG_LOAD actions. | |
3546 | * | |
3547 | * The flow_mod_spec destination spec for 'dst' of 2 (when 'src' is 0) is | |
3548 | * empty. It has the following meaning: | |
3549 | * | |
3550 | * - The flow_mod_spec specifies an OFPAT_OUTPUT action for the new flow. | |
3551 | * The new flow outputs to the OpenFlow port specified by the source field. | |
3552 | * Of the special output ports with value OFPP_MAX or larger, OFPP_IN_PORT, | |
3553 | * OFPP_FLOOD, OFPP_LOCAL, and OFPP_ALL are supported. Other special ports | |
3554 | * may not be used. | |
3555 | * | |
3556 | * Resource Management | |
3557 | * ------------------- | |
3558 | * | |
3559 | * A switch has a finite amount of flow table space available for learning. | |
3560 | * When this space is exhausted, no new learning table entries will be learned | |
3561 | * until some existing flow table entries expire. The controller should be | |
3562 | * prepared to handle this by flooding (which can be implemented as a | |
3563 | * low-priority flow). | |
3564 | * | |
3565 | * If a learned flow matches a single TCP stream with a relatively long | |
3566 | * timeout, one may make the best of resource constraints by setting | |
3567 | * 'fin_idle_timeout' or 'fin_hard_timeout' (both measured in seconds), or | |
3568 | * both, to shorter timeouts. When either of these is specified as a nonzero | |
3569 | * value, OVS adds a NXAST_FIN_TIMEOUT action, with the specified timeouts, to | |
3570 | * the learned flow. | |
3571 | * | |
3572 | * Examples | |
3573 | * -------- | |
3574 | * | |
3575 | * The following examples give a prose description of the flow_mod_specs along | |
3576 | * with informal notation for how those would be represented and a hex dump of | |
3577 | * the bytes that would be required. | |
3578 | * | |
3579 | * These examples could work with various nx_action_learn parameters. Typical | |
3580 | * values would be idle_timeout=OFP_FLOW_PERMANENT, hard_timeout=60, | |
3581 | * priority=OFP_DEFAULT_PRIORITY, flags=0, table_id=10. | |
3582 | * | |
3583 | * 1. Learn input port based on the source MAC, with lookup into | |
3584 | * NXM_NX_REG1[16:31] by resubmit to in_port=99: | |
3585 | * | |
3586 | * Match on in_port=99: | |
3587 | * ovs_be16(src=1, dst=0, n_bits=16), 20 10 | |
3588 | * ovs_be16(99), 00 63 | |
3589 | * ovs_be32(NXM_OF_IN_PORT), ovs_be16(0) 00 00 00 02 00 00 | |
3590 | * | |
3591 | * Match Ethernet destination on Ethernet source from packet: | |
3592 | * ovs_be16(src=0, dst=0, n_bits=48), 00 30 | |
3593 | * ovs_be32(NXM_OF_ETH_SRC), ovs_be16(0) 00 00 04 06 00 00 | |
3594 | * ovs_be32(NXM_OF_ETH_DST), ovs_be16(0) 00 00 02 06 00 00 | |
3595 | * | |
3596 | * Set NXM_NX_REG1[16:31] to the packet's input port: | |
3597 | * ovs_be16(src=0, dst=1, n_bits=16), 08 10 | |
3598 | * ovs_be32(NXM_OF_IN_PORT), ovs_be16(0) 00 00 00 02 00 00 | |
3599 | * ovs_be32(NXM_NX_REG1), ovs_be16(16) 00 01 02 04 00 10 | |
3600 | * | |
3601 | * Given a packet that arrived on port A with Ethernet source address B, | |
3602 | * this would set up the flow "in_port=99, dl_dst=B, | |
3603 | * actions=load:A->NXM_NX_REG1[16..31]". | |
3604 | * | |
3605 | * In syntax accepted by ovs-ofctl, this action is: learn(in_port=99, | |
3606 | * NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], | |
3607 | * load:NXM_OF_IN_PORT[]->NXM_NX_REG1[16..31]) | |
3608 | * | |
3609 | * 2. Output to input port based on the source MAC and VLAN VID, with lookup | |
3610 | * into NXM_NX_REG1[16:31]: | |
3611 | * | |
3612 | * Match on same VLAN ID as packet: | |
3613 | * ovs_be16(src=0, dst=0, n_bits=12), 00 0c | |
3614 | * ovs_be32(NXM_OF_VLAN_TCI), ovs_be16(0) 00 00 08 02 00 00 | |
3615 | * ovs_be32(NXM_OF_VLAN_TCI), ovs_be16(0) 00 00 08 02 00 00 | |
3616 | * | |
3617 | * Match Ethernet destination on Ethernet source from packet: | |
3618 | * ovs_be16(src=0, dst=0, n_bits=48), 00 30 | |
3619 | * ovs_be32(NXM_OF_ETH_SRC), ovs_be16(0) 00 00 04 06 00 00 | |
3620 | * ovs_be32(NXM_OF_ETH_DST), ovs_be16(0) 00 00 02 06 00 00 | |
3621 | * | |
3622 | * Output to the packet's input port: | |
3623 | * ovs_be16(src=0, dst=2, n_bits=16), 10 10 | |
3624 | * ovs_be32(NXM_OF_IN_PORT), ovs_be16(0) 00 00 00 02 00 00 | |
3625 | * | |
3626 | * Given a packet that arrived on port A with Ethernet source address B in | |
3627 | * VLAN C, this would set up the flow "dl_dst=B, vlan_vid=C, | |
3628 | * actions=output:A". | |
3629 | * | |
3630 | * In syntax accepted by ovs-ofctl, this action is: | |
3631 | * learn(NXM_OF_VLAN_TCI[0..11], NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], | |
3632 | * output:NXM_OF_IN_PORT[]) | |
3633 | * | |
3634 | * 3. Here's a recipe for a very simple-minded MAC learning switch. It uses a | |
3635 | * 10-second MAC expiration time to make it easier to see what's going on | |
3636 | * | |
3637 | * ovs-vsctl del-controller br0 | |
3638 | * ovs-ofctl del-flows br0 | |
3639 | * ovs-ofctl add-flow br0 "table=0 actions=learn(table=1, \ | |
3640 | hard_timeout=10, NXM_OF_VLAN_TCI[0..11], \ | |
3641 | NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], \ | |
3642 | output:NXM_OF_IN_PORT[]), resubmit(,1)" | |
3643 | * ovs-ofctl add-flow br0 "table=1 priority=0 actions=flood" | |
3644 | * | |
3645 | * You can then dump the MAC learning table with: | |
3646 | * | |
3647 | * ovs-ofctl dump-flows br0 table=1 | |
3648 | * | |
3649 | * Usage Advice | |
3650 | * ------------ | |
3651 | * | |
3652 | * For best performance, segregate learned flows into a table that is not used | |
3653 | * for any other flows except possibly for a lowest-priority "catch-all" flow | |
3654 | * (a flow with no match criteria). If different learning actions specify | |
3655 | * different match criteria, use different tables for the learned flows. | |
3656 | * | |
3657 | * The meaning of 'hard_timeout' and 'idle_timeout' can be counterintuitive. | |
3658 | * These timeouts apply to the flow that is added, which means that a flow with | |
3659 | * an idle timeout will expire when no traffic has been sent *to* the learned | |
3660 | * address. This is not usually the intent in MAC learning; instead, we want | |
3661 | * the MAC learn entry to expire when no traffic has been sent *from* the | |
3662 | * learned address. Use a hard timeout for that. | |
3663 | */ | |
3664 | struct nx_action_learn { | |
3665 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
3666 | ovs_be16 len; /* At least 24. */ | |
3667 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
3668 | ovs_be16 subtype; /* NXAST_LEARN. */ | |
3669 | ovs_be16 idle_timeout; /* Idle time before discarding (seconds). */ | |
3670 | ovs_be16 hard_timeout; /* Max time before discarding (seconds). */ | |
3671 | ovs_be16 priority; /* Priority level of flow entry. */ | |
3672 | ovs_be64 cookie; /* Cookie for new flow. */ | |
3673 | ovs_be16 flags; /* NX_LEARN_F_*. */ | |
3674 | uint8_t table_id; /* Table to insert flow entry. */ | |
3675 | uint8_t pad; /* Must be zero. */ | |
3676 | ovs_be16 fin_idle_timeout; /* Idle timeout after FIN, if nonzero. */ | |
3677 | ovs_be16 fin_hard_timeout; /* Hard timeout after FIN, if nonzero. */ | |
3678 | /* Followed by a sequence of flow_mod_spec elements, as described above, | |
3679 | * until the end of the action is reached. */ | |
3680 | }; | |
3681 | OFP_ASSERT(sizeof(struct nx_action_learn) == 32); | |
3682 | ||
3683 | static ovs_be16 | |
3684 | get_be16(const void **pp) | |
3685 | { | |
3686 | const ovs_be16 *p = *pp; | |
3687 | ovs_be16 value = *p; | |
3688 | *pp = p + 1; | |
3689 | return value; | |
3690 | } | |
3691 | ||
3692 | static ovs_be32 | |
3693 | get_be32(const void **pp) | |
3694 | { | |
3695 | const ovs_be32 *p = *pp; | |
3696 | ovs_be32 value = get_unaligned_be32(p); | |
3697 | *pp = p + 1; | |
3698 | return value; | |
3699 | } | |
3700 | ||
3701 | static void | |
3702 | get_subfield(int n_bits, const void **p, struct mf_subfield *sf) | |
3703 | { | |
3704 | sf->field = mf_from_nxm_header(ntohl(get_be32(p))); | |
3705 | sf->ofs = ntohs(get_be16(p)); | |
3706 | sf->n_bits = n_bits; | |
3707 | } | |
3708 | ||
3709 | static unsigned int | |
3710 | learn_min_len(uint16_t header) | |
3711 | { | |
3712 | int n_bits = header & NX_LEARN_N_BITS_MASK; | |
3713 | int src_type = header & NX_LEARN_SRC_MASK; | |
3714 | int dst_type = header & NX_LEARN_DST_MASK; | |
3715 | unsigned int min_len; | |
3716 | ||
3717 | min_len = 0; | |
3718 | if (src_type == NX_LEARN_SRC_FIELD) { | |
3719 | min_len += sizeof(ovs_be32); /* src_field */ | |
3720 | min_len += sizeof(ovs_be16); /* src_ofs */ | |
3721 | } else { | |
3722 | min_len += DIV_ROUND_UP(n_bits, 16); | |
3723 | } | |
3724 | if (dst_type == NX_LEARN_DST_MATCH || | |
3725 | dst_type == NX_LEARN_DST_LOAD) { | |
3726 | min_len += sizeof(ovs_be32); /* dst_field */ | |
3727 | min_len += sizeof(ovs_be16); /* dst_ofs */ | |
3728 | } | |
3729 | return min_len; | |
3730 | } | |
3731 | ||
3732 | /* Converts 'nal' into a "struct ofpact_learn" and appends that struct to | |
3733 | * 'ofpacts'. Returns 0 if successful, otherwise an OFPERR_*. */ | |
3734 | static enum ofperr | |
3735 | decode_NXAST_RAW_LEARN(const struct nx_action_learn *nal, | |
3736 | struct ofpbuf *ofpacts) | |
3737 | { | |
3738 | struct ofpact_learn *learn; | |
3739 | const void *p, *end; | |
3740 | ||
3741 | if (nal->pad) { | |
3742 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
3743 | } | |
3744 | ||
3745 | learn = ofpact_put_LEARN(ofpacts); | |
3746 | ||
3747 | learn->idle_timeout = ntohs(nal->idle_timeout); | |
3748 | learn->hard_timeout = ntohs(nal->hard_timeout); | |
3749 | learn->priority = ntohs(nal->priority); | |
3750 | learn->cookie = nal->cookie; | |
3751 | learn->table_id = nal->table_id; | |
3752 | learn->fin_idle_timeout = ntohs(nal->fin_idle_timeout); | |
3753 | learn->fin_hard_timeout = ntohs(nal->fin_hard_timeout); | |
3754 | ||
3755 | learn->flags = ntohs(nal->flags); | |
3756 | if (learn->flags & ~(NX_LEARN_F_SEND_FLOW_REM | | |
3757 | NX_LEARN_F_DELETE_LEARNED)) { | |
3758 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
3759 | } | |
3760 | ||
3761 | if (learn->table_id == 0xff) { | |
3762 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
3763 | } | |
3764 | ||
3765 | end = (char *) nal + ntohs(nal->len); | |
3766 | for (p = nal + 1; p != end; ) { | |
3767 | struct ofpact_learn_spec *spec; | |
3768 | uint16_t header = ntohs(get_be16(&p)); | |
3769 | ||
3770 | if (!header) { | |
3771 | break; | |
3772 | } | |
3773 | ||
3774 | spec = ofpbuf_put_zeros(ofpacts, sizeof *spec); | |
6fd6ed71 | 3775 | learn = ofpacts->header; |
c2d936a4 BP |
3776 | learn->n_specs++; |
3777 | ||
3778 | spec->src_type = header & NX_LEARN_SRC_MASK; | |
3779 | spec->dst_type = header & NX_LEARN_DST_MASK; | |
3780 | spec->n_bits = header & NX_LEARN_N_BITS_MASK; | |
3781 | ||
3782 | /* Check for valid src and dst type combination. */ | |
3783 | if (spec->dst_type == NX_LEARN_DST_MATCH || | |
3784 | spec->dst_type == NX_LEARN_DST_LOAD || | |
3785 | (spec->dst_type == NX_LEARN_DST_OUTPUT && | |
3786 | spec->src_type == NX_LEARN_SRC_FIELD)) { | |
3787 | /* OK. */ | |
3788 | } else { | |
3789 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
3790 | } | |
3791 | ||
3792 | /* Check that the arguments don't overrun the end of the action. */ | |
3793 | if ((char *) end - (char *) p < learn_min_len(header)) { | |
3794 | return OFPERR_OFPBAC_BAD_LEN; | |
3795 | } | |
3796 | ||
3797 | /* Get the source. */ | |
3798 | if (spec->src_type == NX_LEARN_SRC_FIELD) { | |
3799 | get_subfield(spec->n_bits, &p, &spec->src); | |
3800 | } else { | |
3801 | int p_bytes = 2 * DIV_ROUND_UP(spec->n_bits, 16); | |
3802 | ||
3803 | bitwise_copy(p, p_bytes, 0, | |
3804 | &spec->src_imm, sizeof spec->src_imm, 0, | |
3805 | spec->n_bits); | |
3806 | p = (const uint8_t *) p + p_bytes; | |
3807 | } | |
3808 | ||
3809 | /* Get the destination. */ | |
3810 | if (spec->dst_type == NX_LEARN_DST_MATCH || | |
3811 | spec->dst_type == NX_LEARN_DST_LOAD) { | |
3812 | get_subfield(spec->n_bits, &p, &spec->dst); | |
3813 | } | |
3814 | } | |
3815 | ofpact_update_len(ofpacts, &learn->ofpact); | |
3816 | ||
3817 | if (!is_all_zeros(p, (char *) end - (char *) p)) { | |
3818 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
3819 | } | |
3820 | ||
3821 | return 0; | |
3822 | } | |
3823 | ||
3824 | static void | |
3825 | put_be16(struct ofpbuf *b, ovs_be16 x) | |
3826 | { | |
3827 | ofpbuf_put(b, &x, sizeof x); | |
3828 | } | |
3829 | ||
3830 | static void | |
3831 | put_be32(struct ofpbuf *b, ovs_be32 x) | |
3832 | { | |
3833 | ofpbuf_put(b, &x, sizeof x); | |
3834 | } | |
3835 | ||
3836 | static void | |
3837 | put_u16(struct ofpbuf *b, uint16_t x) | |
3838 | { | |
3839 | put_be16(b, htons(x)); | |
3840 | } | |
3841 | ||
3842 | static void | |
3843 | put_u32(struct ofpbuf *b, uint32_t x) | |
3844 | { | |
3845 | put_be32(b, htonl(x)); | |
3846 | } | |
3847 | ||
3848 | static void | |
3849 | encode_LEARN(const struct ofpact_learn *learn, | |
3850 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
3851 | { | |
3852 | const struct ofpact_learn_spec *spec; | |
3853 | struct nx_action_learn *nal; | |
3854 | size_t start_ofs; | |
3855 | ||
6fd6ed71 | 3856 | start_ofs = out->size; |
c2d936a4 BP |
3857 | nal = put_NXAST_LEARN(out); |
3858 | nal->idle_timeout = htons(learn->idle_timeout); | |
3859 | nal->hard_timeout = htons(learn->hard_timeout); | |
3860 | nal->fin_idle_timeout = htons(learn->fin_idle_timeout); | |
3861 | nal->fin_hard_timeout = htons(learn->fin_hard_timeout); | |
3862 | nal->priority = htons(learn->priority); | |
3863 | nal->cookie = learn->cookie; | |
3864 | nal->flags = htons(learn->flags); | |
3865 | nal->table_id = learn->table_id; | |
3866 | ||
3867 | for (spec = learn->specs; spec < &learn->specs[learn->n_specs]; spec++) { | |
3868 | put_u16(out, spec->n_bits | spec->dst_type | spec->src_type); | |
3869 | ||
3870 | if (spec->src_type == NX_LEARN_SRC_FIELD) { | |
508a9338 | 3871 | put_u32(out, mf_nxm_header(spec->src.field->id)); |
c2d936a4 BP |
3872 | put_u16(out, spec->src.ofs); |
3873 | } else { | |
3874 | size_t n_dst_bytes = 2 * DIV_ROUND_UP(spec->n_bits, 16); | |
3875 | uint8_t *bits = ofpbuf_put_zeros(out, n_dst_bytes); | |
3876 | bitwise_copy(&spec->src_imm, sizeof spec->src_imm, 0, | |
3877 | bits, n_dst_bytes, 0, | |
3878 | spec->n_bits); | |
3879 | } | |
3880 | ||
3881 | if (spec->dst_type == NX_LEARN_DST_MATCH || | |
3882 | spec->dst_type == NX_LEARN_DST_LOAD) { | |
508a9338 | 3883 | put_u32(out, mf_nxm_header(spec->dst.field->id)); |
c2d936a4 BP |
3884 | put_u16(out, spec->dst.ofs); |
3885 | } | |
3886 | } | |
3887 | ||
178742f9 | 3888 | pad_ofpat(out, start_ofs); |
c2d936a4 BP |
3889 | } |
3890 | ||
cab50449 | 3891 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
3892 | parse_LEARN(char *arg, struct ofpbuf *ofpacts, |
3893 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
3894 | { | |
3895 | return learn_parse(arg, ofpacts); | |
3896 | } | |
3897 | ||
3898 | static void | |
3899 | format_LEARN(const struct ofpact_learn *a, struct ds *s) | |
3900 | { | |
3901 | learn_format(a, s); | |
3902 | } | |
3903 | \f | |
18080541 BP |
3904 | /* Action structure for NXAST_CONJUNCTION. */ |
3905 | struct nx_action_conjunction { | |
3906 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
3907 | ovs_be16 len; /* At least 16. */ | |
3908 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
3909 | ovs_be16 subtype; /* See enum ofp_raw_action_type. */ | |
3910 | uint8_t clause; | |
3911 | uint8_t n_clauses; | |
3912 | ovs_be32 id; | |
3913 | }; | |
3914 | OFP_ASSERT(sizeof(struct nx_action_conjunction) == 16); | |
3915 | ||
3916 | static void | |
3917 | add_conjunction(struct ofpbuf *out, | |
3918 | uint32_t id, uint8_t clause, uint8_t n_clauses) | |
3919 | { | |
3920 | struct ofpact_conjunction *oc; | |
3921 | ||
3922 | oc = ofpact_put_CONJUNCTION(out); | |
3923 | oc->id = id; | |
3924 | oc->clause = clause; | |
3925 | oc->n_clauses = n_clauses; | |
3926 | } | |
3927 | ||
3928 | static enum ofperr | |
3929 | decode_NXAST_RAW_CONJUNCTION(const struct nx_action_conjunction *nac, | |
3930 | struct ofpbuf *out) | |
3931 | { | |
3932 | if (nac->n_clauses < 2 || nac->n_clauses > 64 | |
3933 | || nac->clause >= nac->n_clauses) { | |
3934 | return OFPERR_NXBAC_BAD_CONJUNCTION; | |
3935 | } else { | |
3936 | add_conjunction(out, ntohl(nac->id), nac->clause, nac->n_clauses); | |
3937 | return 0; | |
3938 | } | |
3939 | } | |
3940 | ||
3941 | static void | |
3942 | encode_CONJUNCTION(const struct ofpact_conjunction *oc, | |
3943 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
3944 | { | |
3945 | struct nx_action_conjunction *nac = put_NXAST_CONJUNCTION(out); | |
3946 | nac->clause = oc->clause; | |
3947 | nac->n_clauses = oc->n_clauses; | |
3948 | nac->id = htonl(oc->id); | |
3949 | } | |
3950 | ||
3951 | static void | |
3952 | format_CONJUNCTION(const struct ofpact_conjunction *oc, struct ds *s) | |
3953 | { | |
3954 | ds_put_format(s, "conjunction(%"PRIu32",%"PRIu8"/%"PRIu8")", | |
3955 | oc->id, oc->clause + 1, oc->n_clauses); | |
3956 | } | |
3957 | ||
3958 | static char * OVS_WARN_UNUSED_RESULT | |
3959 | parse_CONJUNCTION(const char *arg, struct ofpbuf *ofpacts, | |
3960 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
3961 | { | |
3962 | uint8_t n_clauses; | |
3963 | uint8_t clause; | |
3964 | uint32_t id; | |
3965 | int n; | |
3966 | ||
3967 | if (!ovs_scan(arg, "%"SCNi32" , %"SCNu8" / %"SCNu8" %n", | |
3968 | &id, &clause, &n_clauses, &n) || n != strlen(arg)) { | |
3969 | return xstrdup("\"conjunction\" syntax is \"conjunction(id,i/n)\""); | |
3970 | } | |
3971 | ||
3972 | if (n_clauses < 2) { | |
3973 | return xstrdup("conjunction must have at least 2 clauses"); | |
3974 | } else if (n_clauses > 64) { | |
3975 | return xstrdup("conjunction must have at most 64 clauses"); | |
3976 | } else if (clause < 1) { | |
3977 | return xstrdup("clause index must be positive"); | |
3978 | } else if (clause > n_clauses) { | |
3979 | return xstrdup("clause index must be less than or equal to " | |
3980 | "number of clauses"); | |
3981 | } | |
3982 | ||
3983 | add_conjunction(ofpacts, id, clause - 1, n_clauses); | |
3984 | return NULL; | |
3985 | } | |
3986 | \f | |
c2d936a4 BP |
3987 | /* Action structure for NXAST_MULTIPATH. |
3988 | * | |
3989 | * This action performs the following steps in sequence: | |
3990 | * | |
3991 | * 1. Hashes the fields designated by 'fields', one of NX_HASH_FIELDS_*. | |
3992 | * Refer to the definition of "enum nx_mp_fields" for details. | |
3993 | * | |
3994 | * The 'basis' value is used as a universal hash parameter, that is, | |
3995 | * different values of 'basis' yield different hash functions. The | |
3996 | * particular universal hash function used is implementation-defined. | |
3997 | * | |
3998 | * The hashed fields' values are drawn from the current state of the | |
3999 | * flow, including all modifications that have been made by actions up to | |
4000 | * this point. | |
4001 | * | |
4002 | * 2. Applies the multipath link choice algorithm specified by 'algorithm', | |
4003 | * one of NX_MP_ALG_*. Refer to the definition of "enum nx_mp_algorithm" | |
4004 | * for details. | |
4005 | * | |
4006 | * The output of the algorithm is 'link', an unsigned integer less than | |
4007 | * or equal to 'max_link'. | |
4008 | * | |
4009 | * Some algorithms use 'arg' as an additional argument. | |
4010 | * | |
4011 | * 3. Stores 'link' in dst[ofs:ofs+n_bits]. The format and semantics of | |
4012 | * 'dst' and 'ofs_nbits' are similar to those for the NXAST_REG_LOAD | |
4013 | * action. | |
4014 | * | |
4015 | * The switch will reject actions that have an unknown 'fields', or an unknown | |
4016 | * 'algorithm', or in which ofs+n_bits is greater than the width of 'dst', or | |
4017 | * in which 'max_link' is greater than or equal to 2**n_bits, with error type | |
4018 | * OFPET_BAD_ACTION, code OFPBAC_BAD_ARGUMENT. | |
4019 | */ | |
4020 | struct nx_action_multipath { | |
4021 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
4022 | ovs_be16 len; /* Length is 32. */ | |
4023 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
4024 | ovs_be16 subtype; /* NXAST_MULTIPATH. */ | |
4025 | ||
4026 | /* What fields to hash and how. */ | |
4027 | ovs_be16 fields; /* One of NX_HASH_FIELDS_*. */ | |
4028 | ovs_be16 basis; /* Universal hash parameter. */ | |
4029 | ovs_be16 pad0; | |
4030 | ||
4031 | /* Multipath link choice algorithm to apply to hash value. */ | |
4032 | ovs_be16 algorithm; /* One of NX_MP_ALG_*. */ | |
4033 | ovs_be16 max_link; /* Number of output links, minus 1. */ | |
4034 | ovs_be32 arg; /* Algorithm-specific argument. */ | |
4035 | ovs_be16 pad1; | |
4036 | ||
4037 | /* Where to store the result. */ | |
4038 | ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */ | |
4039 | ovs_be32 dst; /* Destination. */ | |
4040 | }; | |
4041 | OFP_ASSERT(sizeof(struct nx_action_multipath) == 32); | |
4042 | ||
4043 | static enum ofperr | |
4044 | decode_NXAST_RAW_MULTIPATH(const struct nx_action_multipath *nam, | |
4045 | struct ofpbuf *out) | |
4046 | { | |
4047 | uint32_t n_links = ntohs(nam->max_link) + 1; | |
4048 | size_t min_n_bits = log_2_ceil(n_links); | |
4049 | struct ofpact_multipath *mp; | |
4050 | ||
4051 | mp = ofpact_put_MULTIPATH(out); | |
4052 | mp->fields = ntohs(nam->fields); | |
4053 | mp->basis = ntohs(nam->basis); | |
4054 | mp->algorithm = ntohs(nam->algorithm); | |
4055 | mp->max_link = ntohs(nam->max_link); | |
4056 | mp->arg = ntohl(nam->arg); | |
4057 | mp->dst.field = mf_from_nxm_header(ntohl(nam->dst)); | |
4058 | mp->dst.ofs = nxm_decode_ofs(nam->ofs_nbits); | |
4059 | mp->dst.n_bits = nxm_decode_n_bits(nam->ofs_nbits); | |
4060 | ||
4061 | if (!flow_hash_fields_valid(mp->fields)) { | |
4062 | VLOG_WARN_RL(&rl, "unsupported fields %d", (int) mp->fields); | |
4063 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
4064 | } else if (mp->algorithm != NX_MP_ALG_MODULO_N | |
4065 | && mp->algorithm != NX_MP_ALG_HASH_THRESHOLD | |
4066 | && mp->algorithm != NX_MP_ALG_HRW | |
4067 | && mp->algorithm != NX_MP_ALG_ITER_HASH) { | |
4068 | VLOG_WARN_RL(&rl, "unsupported algorithm %d", (int) mp->algorithm); | |
4069 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
4070 | } else if (mp->dst.n_bits < min_n_bits) { | |
4071 | VLOG_WARN_RL(&rl, "multipath action requires at least %"PRIuSIZE" bits for " | |
4072 | "%"PRIu32" links", min_n_bits, n_links); | |
4073 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
4074 | } | |
4075 | ||
4076 | return multipath_check(mp, NULL); | |
4077 | } | |
4078 | ||
4079 | static void | |
4080 | encode_MULTIPATH(const struct ofpact_multipath *mp, | |
4081 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
4082 | { | |
4083 | struct nx_action_multipath *nam = put_NXAST_MULTIPATH(out); | |
4084 | ||
4085 | nam->fields = htons(mp->fields); | |
4086 | nam->basis = htons(mp->basis); | |
4087 | nam->algorithm = htons(mp->algorithm); | |
4088 | nam->max_link = htons(mp->max_link); | |
4089 | nam->arg = htonl(mp->arg); | |
4090 | nam->ofs_nbits = nxm_encode_ofs_nbits(mp->dst.ofs, mp->dst.n_bits); | |
508a9338 | 4091 | nam->dst = htonl(mf_nxm_header(mp->dst.field->id)); |
c2d936a4 BP |
4092 | } |
4093 | ||
cab50449 | 4094 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
4095 | parse_MULTIPATH(const char *arg, struct ofpbuf *ofpacts, |
4096 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
4097 | { | |
4098 | return multipath_parse(ofpact_put_MULTIPATH(ofpacts), arg); | |
4099 | } | |
4100 | ||
4101 | static void | |
4102 | format_MULTIPATH(const struct ofpact_multipath *a, struct ds *s) | |
4103 | { | |
4104 | multipath_format(a, s); | |
4105 | } | |
4106 | \f | |
4107 | /* Action structure for NXAST_NOTE. | |
4108 | * | |
4109 | * This action has no effect. It is variable length. The switch does not | |
4110 | * attempt to interpret the user-defined 'note' data in any way. A controller | |
4111 | * can use this action to attach arbitrary metadata to a flow. | |
4112 | * | |
4113 | * This action might go away in the future. | |
4114 | */ | |
4115 | struct nx_action_note { | |
4116 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
4117 | ovs_be16 len; /* A multiple of 8, but at least 16. */ | |
4118 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
4119 | ovs_be16 subtype; /* NXAST_NOTE. */ | |
4120 | uint8_t note[6]; /* Start of user-defined data. */ | |
4121 | /* Possibly followed by additional user-defined data. */ | |
4122 | }; | |
4123 | OFP_ASSERT(sizeof(struct nx_action_note) == 16); | |
4124 | ||
4125 | static enum ofperr | |
4126 | decode_NXAST_RAW_NOTE(const struct nx_action_note *nan, struct ofpbuf *out) | |
4127 | { | |
4128 | struct ofpact_note *note; | |
4129 | unsigned int length; | |
4130 | ||
4131 | length = ntohs(nan->len) - offsetof(struct nx_action_note, note); | |
4132 | note = ofpact_put(out, OFPACT_NOTE, | |
4133 | offsetof(struct ofpact_note, data) + length); | |
4134 | note->length = length; | |
4135 | memcpy(note->data, nan->note, length); | |
4136 | ||
4137 | return 0; | |
4138 | } | |
4139 | ||
4140 | static void | |
4141 | encode_NOTE(const struct ofpact_note *note, | |
4142 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
4143 | { | |
6fd6ed71 | 4144 | size_t start_ofs = out->size; |
c2d936a4 BP |
4145 | struct nx_action_note *nan; |
4146 | unsigned int remainder; | |
4147 | unsigned int len; | |
4148 | ||
4149 | put_NXAST_NOTE(out); | |
6fd6ed71 | 4150 | out->size = out->size - sizeof nan->note; |
c2d936a4 BP |
4151 | |
4152 | ofpbuf_put(out, note->data, note->length); | |
4153 | ||
6fd6ed71 | 4154 | len = out->size - start_ofs; |
c2d936a4 BP |
4155 | remainder = len % OFP_ACTION_ALIGN; |
4156 | if (remainder) { | |
4157 | ofpbuf_put_zeros(out, OFP_ACTION_ALIGN - remainder); | |
4158 | } | |
4159 | nan = ofpbuf_at(out, start_ofs, sizeof *nan); | |
6fd6ed71 | 4160 | nan->len = htons(out->size - start_ofs); |
c2d936a4 BP |
4161 | } |
4162 | ||
cab50449 | 4163 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
4164 | parse_NOTE(const char *arg, struct ofpbuf *ofpacts, |
4165 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
4166 | { | |
4167 | struct ofpact_note *note; | |
4168 | ||
4169 | note = ofpact_put_NOTE(ofpacts); | |
4170 | while (*arg != '\0') { | |
4171 | uint8_t byte; | |
4172 | bool ok; | |
4173 | ||
4174 | if (*arg == '.') { | |
4175 | arg++; | |
4176 | } | |
4177 | if (*arg == '\0') { | |
4178 | break; | |
4179 | } | |
4180 | ||
4181 | byte = hexits_value(arg, 2, &ok); | |
4182 | if (!ok) { | |
4183 | return xstrdup("bad hex digit in `note' argument"); | |
4184 | } | |
4185 | ofpbuf_put(ofpacts, &byte, 1); | |
4186 | ||
6fd6ed71 | 4187 | note = ofpacts->header; |
c2d936a4 BP |
4188 | note->length++; |
4189 | ||
4190 | arg += 2; | |
4191 | } | |
4192 | ofpact_update_len(ofpacts, ¬e->ofpact); | |
4193 | return NULL; | |
4194 | } | |
4195 | ||
4196 | static void | |
4197 | format_NOTE(const struct ofpact_note *a, struct ds *s) | |
4198 | { | |
4199 | size_t i; | |
4200 | ||
4201 | ds_put_cstr(s, "note:"); | |
4202 | for (i = 0; i < a->length; i++) { | |
4203 | if (i) { | |
4204 | ds_put_char(s, '.'); | |
4205 | } | |
4206 | ds_put_format(s, "%02"PRIx8, a->data[i]); | |
4207 | } | |
4208 | } | |
4209 | \f | |
4210 | /* Exit action. */ | |
4211 | ||
4212 | static enum ofperr | |
4213 | decode_NXAST_RAW_EXIT(struct ofpbuf *out) | |
4214 | { | |
4215 | ofpact_put_EXIT(out); | |
4216 | return 0; | |
4217 | } | |
4218 | ||
4219 | static void | |
4220 | encode_EXIT(const struct ofpact_null *null OVS_UNUSED, | |
4221 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
4222 | { | |
4223 | put_NXAST_EXIT(out); | |
4224 | } | |
4225 | ||
cab50449 | 4226 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
4227 | parse_EXIT(char *arg OVS_UNUSED, struct ofpbuf *ofpacts, |
4228 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
4229 | { | |
4230 | ofpact_put_EXIT(ofpacts); | |
4231 | return NULL; | |
4232 | } | |
4233 | ||
4234 | static void | |
4235 | format_EXIT(const struct ofpact_null *a OVS_UNUSED, struct ds *s) | |
4236 | { | |
4237 | ds_put_cstr(s, "exit"); | |
4238 | } | |
4239 | \f | |
e672ff9b JR |
4240 | /* Unroll xlate action. */ |
4241 | ||
4242 | static void | |
4243 | encode_UNROLL_XLATE(const struct ofpact_unroll_xlate *unroll OVS_UNUSED, | |
4244 | enum ofp_version ofp_version OVS_UNUSED, | |
4245 | struct ofpbuf *out OVS_UNUSED) | |
4246 | { | |
4247 | OVS_NOT_REACHED(); | |
4248 | } | |
4249 | ||
4250 | static char * OVS_WARN_UNUSED_RESULT | |
4251 | parse_UNROLL_XLATE(char *arg OVS_UNUSED, struct ofpbuf *ofpacts OVS_UNUSED, | |
4252 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
4253 | { | |
4254 | OVS_NOT_REACHED(); | |
4255 | return NULL; | |
4256 | } | |
4257 | ||
4258 | static void | |
4259 | format_UNROLL_XLATE(const struct ofpact_unroll_xlate *a OVS_UNUSED, | |
4260 | struct ds *s) | |
4261 | { | |
4262 | ds_put_cstr(s, "unroll_xlate"); | |
4263 | } | |
4264 | \f | |
c2d936a4 BP |
4265 | /* Action structure for NXAST_SAMPLE. |
4266 | * | |
4267 | * Samples matching packets with the given probability and sends them | |
4268 | * each to the set of collectors identified with the given ID. The | |
4269 | * probability is expressed as a number of packets to be sampled out | |
4270 | * of USHRT_MAX packets, and must be >0. | |
4271 | * | |
4272 | * When sending packet samples to IPFIX collectors, the IPFIX flow | |
4273 | * record sent for each sampled packet is associated with the given | |
4274 | * observation domain ID and observation point ID. Each IPFIX flow | |
4275 | * record contain the sampled packet's headers when executing this | |
4276 | * rule. If a sampled packet's headers are modified by previous | |
4277 | * actions in the flow, those modified headers are sent. */ | |
4278 | struct nx_action_sample { | |
4279 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
4280 | ovs_be16 len; /* Length is 24. */ | |
4281 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
4282 | ovs_be16 subtype; /* NXAST_SAMPLE. */ | |
4283 | ovs_be16 probability; /* Fraction of packets to sample. */ | |
4284 | ovs_be32 collector_set_id; /* ID of collector set in OVSDB. */ | |
4285 | ovs_be32 obs_domain_id; /* ID of sampling observation domain. */ | |
4286 | ovs_be32 obs_point_id; /* ID of sampling observation point. */ | |
4287 | }; | |
4288 | OFP_ASSERT(sizeof(struct nx_action_sample) == 24); | |
4289 | ||
4290 | static enum ofperr | |
4291 | decode_NXAST_RAW_SAMPLE(const struct nx_action_sample *nas, struct ofpbuf *out) | |
4292 | { | |
4293 | struct ofpact_sample *sample; | |
4294 | ||
4295 | sample = ofpact_put_SAMPLE(out); | |
4296 | sample->probability = ntohs(nas->probability); | |
4297 | sample->collector_set_id = ntohl(nas->collector_set_id); | |
4298 | sample->obs_domain_id = ntohl(nas->obs_domain_id); | |
4299 | sample->obs_point_id = ntohl(nas->obs_point_id); | |
4300 | ||
4301 | if (sample->probability == 0) { | |
4302 | return OFPERR_OFPBAC_BAD_ARGUMENT; | |
4303 | } | |
4304 | ||
4305 | return 0; | |
4306 | } | |
4307 | ||
4308 | static void | |
4309 | encode_SAMPLE(const struct ofpact_sample *sample, | |
4310 | enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out) | |
4311 | { | |
4312 | struct nx_action_sample *nas; | |
4313 | ||
4314 | nas = put_NXAST_SAMPLE(out); | |
4315 | nas->probability = htons(sample->probability); | |
4316 | nas->collector_set_id = htonl(sample->collector_set_id); | |
4317 | nas->obs_domain_id = htonl(sample->obs_domain_id); | |
4318 | nas->obs_point_id = htonl(sample->obs_point_id); | |
4319 | } | |
4320 | ||
4321 | /* Parses 'arg' as the argument to a "sample" action, and appends such an | |
4322 | * action to 'ofpacts'. | |
4323 | * | |
4324 | * Returns NULL if successful, otherwise a malloc()'d string describing the | |
4325 | * error. The caller is responsible for freeing the returned string. */ | |
cab50449 | 4326 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
4327 | parse_SAMPLE(char *arg, struct ofpbuf *ofpacts, |
4328 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
4329 | { | |
4330 | struct ofpact_sample *os = ofpact_put_SAMPLE(ofpacts); | |
4331 | char *key, *value; | |
4332 | ||
4333 | while (ofputil_parse_key_value(&arg, &key, &value)) { | |
4334 | char *error = NULL; | |
4335 | ||
4336 | if (!strcmp(key, "probability")) { | |
4337 | error = str_to_u16(value, "probability", &os->probability); | |
4338 | if (!error && os->probability == 0) { | |
4339 | error = xasprintf("invalid probability value \"%s\"", value); | |
4340 | } | |
4341 | } else if (!strcmp(key, "collector_set_id")) { | |
4342 | error = str_to_u32(value, &os->collector_set_id); | |
4343 | } else if (!strcmp(key, "obs_domain_id")) { | |
4344 | error = str_to_u32(value, &os->obs_domain_id); | |
4345 | } else if (!strcmp(key, "obs_point_id")) { | |
4346 | error = str_to_u32(value, &os->obs_point_id); | |
4347 | } else { | |
4348 | error = xasprintf("invalid key \"%s\" in \"sample\" argument", | |
4349 | key); | |
4350 | } | |
4351 | if (error) { | |
4352 | return error; | |
4353 | } | |
4354 | } | |
4355 | if (os->probability == 0) { | |
4356 | return xstrdup("non-zero \"probability\" must be specified on sample"); | |
4357 | } | |
4358 | return NULL; | |
4359 | } | |
4360 | ||
4361 | static void | |
4362 | format_SAMPLE(const struct ofpact_sample *a, struct ds *s) | |
4363 | { | |
4364 | ds_put_format(s, "sample(probability=%"PRIu16",collector_set_id=%"PRIu32 | |
4365 | ",obs_domain_id=%"PRIu32",obs_point_id=%"PRIu32")", | |
4366 | a->probability, a->collector_set_id, | |
4367 | a->obs_domain_id, a->obs_point_id); | |
4368 | } | |
4369 | \f | |
4370 | /* Meter instruction. */ | |
4371 | ||
4372 | static void | |
4373 | encode_METER(const struct ofpact_meter *meter, | |
4374 | enum ofp_version ofp_version, struct ofpbuf *out) | |
4375 | { | |
4376 | if (ofp_version >= OFP13_VERSION) { | |
4377 | instruction_put_OFPIT13_METER(out)->meter_id = htonl(meter->meter_id); | |
4378 | } | |
4379 | } | |
4380 | ||
cab50449 | 4381 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
4382 | parse_METER(char *arg, struct ofpbuf *ofpacts, |
4383 | enum ofputil_protocol *usable_protocols) | |
4384 | { | |
4385 | *usable_protocols &= OFPUTIL_P_OF13_UP; | |
4386 | return str_to_u32(arg, &ofpact_put_METER(ofpacts)->meter_id); | |
4387 | } | |
4388 | ||
4389 | static void | |
4390 | format_METER(const struct ofpact_meter *a, struct ds *s) | |
4391 | { | |
4392 | ds_put_format(s, "meter:%"PRIu32, a->meter_id); | |
4393 | } | |
4394 | \f | |
4395 | /* Clear-Actions instruction. */ | |
4396 | ||
4397 | static void | |
4398 | encode_CLEAR_ACTIONS(const struct ofpact_null *null OVS_UNUSED, | |
4399 | enum ofp_version ofp_version OVS_UNUSED, | |
4400 | struct ofpbuf *out OVS_UNUSED) | |
4401 | { | |
4402 | if (ofp_version > OFP10_VERSION) { | |
4403 | instruction_put_OFPIT11_CLEAR_ACTIONS(out); | |
4404 | } | |
4405 | } | |
4406 | ||
cab50449 | 4407 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
4408 | parse_CLEAR_ACTIONS(char *arg OVS_UNUSED, struct ofpbuf *ofpacts, |
4409 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
4410 | { | |
4411 | ofpact_put_CLEAR_ACTIONS(ofpacts); | |
4412 | return NULL; | |
4413 | } | |
4414 | ||
4415 | static void | |
4416 | format_CLEAR_ACTIONS(const struct ofpact_null *a OVS_UNUSED, struct ds *s) | |
4417 | { | |
4418 | ds_put_cstr(s, "clear_actions"); | |
4419 | } | |
4420 | \f | |
4421 | /* Write-Actions instruction. */ | |
4422 | ||
4423 | static void | |
4424 | encode_WRITE_ACTIONS(const struct ofpact_nest *actions, | |
4425 | enum ofp_version ofp_version, struct ofpbuf *out) | |
4426 | { | |
4427 | if (ofp_version > OFP10_VERSION) { | |
6fd6ed71 | 4428 | const size_t ofs = out->size; |
c2d936a4 BP |
4429 | |
4430 | instruction_put_OFPIT11_WRITE_ACTIONS(out); | |
4431 | ofpacts_put_openflow_actions(actions->actions, | |
4432 | ofpact_nest_get_action_len(actions), | |
4433 | out, ofp_version); | |
4434 | ofpacts_update_instruction_actions(out, ofs); | |
4435 | } | |
4436 | } | |
4437 | ||
cab50449 | 4438 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
4439 | parse_WRITE_ACTIONS(char *arg, struct ofpbuf *ofpacts, |
4440 | enum ofputil_protocol *usable_protocols) | |
4441 | { | |
4442 | struct ofpact_nest *on; | |
4443 | char *error; | |
4444 | size_t ofs; | |
4445 | ||
4446 | /* Pull off existing actions or instructions. */ | |
4447 | ofpact_pad(ofpacts); | |
6fd6ed71 | 4448 | ofs = ofpacts->size; |
c2d936a4 BP |
4449 | ofpbuf_pull(ofpacts, ofs); |
4450 | ||
4451 | /* Add a Write-Actions instruction and then pull it off. */ | |
4452 | ofpact_put(ofpacts, OFPACT_WRITE_ACTIONS, sizeof *on); | |
4453 | ofpbuf_pull(ofpacts, sizeof *on); | |
4454 | ||
4455 | /* Parse nested actions. | |
4456 | * | |
4457 | * We pulled off "write-actions" and the previous actions because the | |
4458 | * OFPACT_WRITE_ACTIONS is only partially constructed: its length is such | |
4459 | * that it doesn't actually include the nested actions. That means that | |
4460 | * ofpacts_parse() would reject them as being part of an Apply-Actions that | |
4461 | * follows a Write-Actions, which is an invalid order. */ | |
4462 | error = ofpacts_parse(arg, ofpacts, usable_protocols, false); | |
4463 | ||
4464 | /* Put the Write-Actions back on and update its length. */ | |
4465 | on = ofpbuf_push_uninit(ofpacts, sizeof *on); | |
6fd6ed71 | 4466 | on->ofpact.len = ofpacts->size; |
c2d936a4 BP |
4467 | |
4468 | /* Put any previous actions or instructions back on. */ | |
4469 | ofpbuf_push_uninit(ofpacts, ofs); | |
4470 | ||
4471 | return error; | |
4472 | } | |
4473 | ||
4474 | static void | |
4475 | format_WRITE_ACTIONS(const struct ofpact_nest *a, struct ds *s) | |
4476 | { | |
4477 | ds_put_cstr(s, "write_actions("); | |
4478 | ofpacts_format(a->actions, ofpact_nest_get_action_len(a), s); | |
4479 | ds_put_char(s, ')'); | |
4480 | } | |
4481 | \f | |
4482 | /* Action structure for NXAST_WRITE_METADATA. | |
4483 | * | |
4484 | * Modifies the 'mask' bits of the metadata value. */ | |
4485 | struct nx_action_write_metadata { | |
4486 | ovs_be16 type; /* OFPAT_VENDOR. */ | |
4487 | ovs_be16 len; /* Length is 32. */ | |
4488 | ovs_be32 vendor; /* NX_VENDOR_ID. */ | |
4489 | ovs_be16 subtype; /* NXAST_WRITE_METADATA. */ | |
4490 | uint8_t zeros[6]; /* Must be zero. */ | |
4491 | ovs_be64 metadata; /* Metadata register. */ | |
4492 | ovs_be64 mask; /* Metadata mask. */ | |
4493 | }; | |
4494 | OFP_ASSERT(sizeof(struct nx_action_write_metadata) == 32); | |
4495 | ||
4496 | static enum ofperr | |
4497 | decode_NXAST_RAW_WRITE_METADATA(const struct nx_action_write_metadata *nawm, | |
4498 | struct ofpbuf *out) | |
4499 | { | |
4500 | struct ofpact_metadata *om; | |
4501 | ||
4502 | if (!is_all_zeros(nawm->zeros, sizeof nawm->zeros)) { | |
4503 | return OFPERR_NXBRC_MUST_BE_ZERO; | |
4504 | } | |
4505 | ||
4506 | om = ofpact_put_WRITE_METADATA(out); | |
4507 | om->metadata = nawm->metadata; | |
4508 | om->mask = nawm->mask; | |
4509 | ||
4510 | return 0; | |
4511 | } | |
4512 | ||
4513 | static void | |
4514 | encode_WRITE_METADATA(const struct ofpact_metadata *metadata, | |
4515 | enum ofp_version ofp_version, struct ofpbuf *out) | |
4516 | { | |
4517 | if (ofp_version == OFP10_VERSION) { | |
4518 | struct nx_action_write_metadata *nawm; | |
4519 | ||
4520 | nawm = put_NXAST_WRITE_METADATA(out); | |
4521 | nawm->metadata = metadata->metadata; | |
4522 | nawm->mask = metadata->mask; | |
4523 | } else { | |
4524 | struct ofp11_instruction_write_metadata *oiwm; | |
4525 | ||
4526 | oiwm = instruction_put_OFPIT11_WRITE_METADATA(out); | |
4527 | oiwm->metadata = metadata->metadata; | |
4528 | oiwm->metadata_mask = metadata->mask; | |
4529 | } | |
4530 | } | |
4531 | ||
cab50449 | 4532 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
4533 | parse_WRITE_METADATA(char *arg, struct ofpbuf *ofpacts, |
4534 | enum ofputil_protocol *usable_protocols) | |
4535 | { | |
4536 | struct ofpact_metadata *om; | |
4537 | char *mask = strchr(arg, '/'); | |
4538 | ||
4539 | *usable_protocols &= OFPUTIL_P_NXM_OF11_UP; | |
4540 | ||
4541 | om = ofpact_put_WRITE_METADATA(ofpacts); | |
4542 | if (mask) { | |
4543 | char *error; | |
4544 | ||
4545 | *mask = '\0'; | |
4546 | error = str_to_be64(mask + 1, &om->mask); | |
4547 | if (error) { | |
4548 | return error; | |
4549 | } | |
4550 | } else { | |
4551 | om->mask = OVS_BE64_MAX; | |
4552 | } | |
4553 | ||
4554 | return str_to_be64(arg, &om->metadata); | |
4555 | } | |
4556 | ||
4557 | static void | |
4558 | format_WRITE_METADATA(const struct ofpact_metadata *a, struct ds *s) | |
4559 | { | |
4560 | ds_put_format(s, "write_metadata:%#"PRIx64, ntohll(a->metadata)); | |
4561 | if (a->mask != OVS_BE64_MAX) { | |
4562 | ds_put_format(s, "/%#"PRIx64, ntohll(a->mask)); | |
4563 | } | |
4cceacb9 | 4564 | } |
f25d0cf3 | 4565 | \f |
c2d936a4 | 4566 | /* Goto-Table instruction. */ |
f25d0cf3 BP |
4567 | |
4568 | static void | |
c2d936a4 BP |
4569 | encode_GOTO_TABLE(const struct ofpact_goto_table *goto_table, |
4570 | enum ofp_version ofp_version, struct ofpbuf *out) | |
f25d0cf3 | 4571 | { |
c2d936a4 BP |
4572 | if (ofp_version == OFP10_VERSION) { |
4573 | struct nx_action_resubmit *nar; | |
f25d0cf3 | 4574 | |
c2d936a4 BP |
4575 | nar = put_NXAST_RESUBMIT_TABLE(out); |
4576 | nar->table = goto_table->table_id; | |
4577 | nar->in_port = htons(ofp_to_u16(OFPP_IN_PORT)); | |
4578 | } else { | |
4579 | struct ofp11_instruction_goto_table *oigt; | |
4580 | ||
4581 | oigt = instruction_put_OFPIT11_GOTO_TABLE(out); | |
4582 | oigt->table_id = goto_table->table_id; | |
4583 | memset(oigt->pad, 0, sizeof oigt->pad); | |
4584 | } | |
4585 | } | |
4586 | ||
cab50449 | 4587 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
4588 | parse_GOTO_TABLE(char *arg, struct ofpbuf *ofpacts, |
4589 | enum ofputil_protocol *usable_protocols OVS_UNUSED) | |
4590 | { | |
4591 | struct ofpact_goto_table *ogt = ofpact_put_GOTO_TABLE(ofpacts); | |
4592 | char *table_s = strsep(&arg, ","); | |
4593 | if (!table_s || !table_s[0]) { | |
4594 | return xstrdup("instruction goto-table needs table id"); | |
4595 | } | |
4596 | return str_to_u8(table_s, "table", &ogt->table_id); | |
4597 | } | |
4598 | ||
4599 | static void | |
4600 | format_GOTO_TABLE(const struct ofpact_goto_table *a, struct ds *s) | |
4601 | { | |
4602 | ds_put_format(s, "goto_table:%"PRIu8, a->table_id); | |
4603 | } | |
4604 | \f | |
4605 | static void | |
5ad4b3f8 | 4606 | log_bad_action(const struct ofp_action_header *actions, size_t actions_len, |
c2d936a4 BP |
4607 | const struct ofp_action_header *bad_action, enum ofperr error) |
4608 | { | |
4609 | if (!VLOG_DROP_WARN(&rl)) { | |
4610 | struct ds s; | |
4611 | ||
4612 | ds_init(&s); | |
5ad4b3f8 | 4613 | ds_put_hex_dump(&s, actions, actions_len, 0, false); |
c2d936a4 BP |
4614 | VLOG_WARN("bad action at offset %#"PRIxPTR" (%s):\n%s", |
4615 | (char *)bad_action - (char *)actions, | |
4616 | ofperr_get_name(error), ds_cstr(&s)); | |
4617 | ds_destroy(&s); | |
4618 | } | |
4619 | } | |
4620 | ||
4621 | static enum ofperr | |
4622 | ofpacts_decode(const void *actions, size_t actions_len, | |
4623 | enum ofp_version ofp_version, struct ofpbuf *ofpacts) | |
4624 | { | |
4625 | struct ofpbuf openflow; | |
4626 | ||
4627 | ofpbuf_use_const(&openflow, actions, actions_len); | |
6fd6ed71 PS |
4628 | while (openflow.size) { |
4629 | const struct ofp_action_header *action = openflow.data; | |
c2d936a4 BP |
4630 | enum ofp_raw_action_type raw; |
4631 | enum ofperr error; | |
4632 | uint64_t arg; | |
4633 | ||
4634 | error = ofpact_pull_raw(&openflow, ofp_version, &raw, &arg); | |
4635 | if (!error) { | |
4636 | error = ofpact_decode(action, raw, arg, ofpacts); | |
4637 | } | |
4638 | ||
4639 | if (error) { | |
5ad4b3f8 | 4640 | log_bad_action(actions, actions_len, action, error); |
c2d936a4 BP |
4641 | return error; |
4642 | } | |
4643 | } | |
4644 | ||
4645 | ofpact_pad(ofpacts); | |
4646 | return 0; | |
4647 | } | |
4648 | ||
4649 | static enum ofperr | |
4650 | ofpacts_pull_openflow_actions__(struct ofpbuf *openflow, | |
4651 | unsigned int actions_len, | |
4652 | enum ofp_version version, | |
4653 | uint32_t allowed_ovsinsts, | |
4654 | struct ofpbuf *ofpacts) | |
4655 | { | |
4656 | const struct ofp_action_header *actions; | |
4657 | enum ofperr error; | |
4658 | ||
4659 | ofpbuf_clear(ofpacts); | |
4660 | ||
4661 | if (actions_len % OFP_ACTION_ALIGN != 0) { | |
4662 | VLOG_WARN_RL(&rl, "OpenFlow message actions length %u is not a " | |
4663 | "multiple of %d", actions_len, OFP_ACTION_ALIGN); | |
4664 | return OFPERR_OFPBRC_BAD_LEN; | |
4665 | } | |
4666 | ||
4667 | actions = ofpbuf_try_pull(openflow, actions_len); | |
4668 | if (actions == NULL) { | |
4669 | VLOG_WARN_RL(&rl, "OpenFlow message actions length %u exceeds " | |
4670 | "remaining message length (%"PRIu32")", | |
6fd6ed71 | 4671 | actions_len, openflow->size); |
c2d936a4 BP |
4672 | return OFPERR_OFPBRC_BAD_LEN; |
4673 | } | |
4674 | ||
4675 | error = ofpacts_decode(actions, actions_len, version, ofpacts); | |
4676 | if (error) { | |
4677 | ofpbuf_clear(ofpacts); | |
4678 | return error; | |
4679 | } | |
4680 | ||
6fd6ed71 | 4681 | error = ofpacts_verify(ofpacts->data, ofpacts->size, |
c2d936a4 BP |
4682 | allowed_ovsinsts); |
4683 | if (error) { | |
4684 | ofpbuf_clear(ofpacts); | |
4685 | } | |
4686 | return error; | |
4687 | } | |
4688 | ||
4689 | /* Attempts to convert 'actions_len' bytes of OpenFlow actions from the | |
4690 | * front of 'openflow' into ofpacts. On success, replaces any existing content | |
4691 | * in 'ofpacts' by the converted ofpacts; on failure, clears 'ofpacts'. | |
4692 | * Returns 0 if successful, otherwise an OpenFlow error. | |
4693 | * | |
4694 | * Actions are processed according to their OpenFlow version which | |
4695 | * is provided in the 'version' parameter. | |
4696 | * | |
4697 | * In most places in OpenFlow, actions appear encapsulated in instructions, so | |
4698 | * you should call ofpacts_pull_openflow_instructions() instead of this | |
4699 | * function. | |
4700 | * | |
4701 | * The parsed actions are valid generically, but they may not be valid in a | |
4702 | * specific context. For example, port numbers up to OFPP_MAX are valid | |
4703 | * generically, but specific datapaths may only support port numbers in a | |
4704 | * smaller range. Use ofpacts_check() to additional check whether actions are | |
4705 | * valid in a specific context. */ | |
4706 | enum ofperr | |
4707 | ofpacts_pull_openflow_actions(struct ofpbuf *openflow, | |
4708 | unsigned int actions_len, | |
4709 | enum ofp_version version, | |
4710 | struct ofpbuf *ofpacts) | |
4711 | { | |
4712 | return ofpacts_pull_openflow_actions__(openflow, actions_len, version, | |
4713 | 1u << OVSINST_OFPIT11_APPLY_ACTIONS, | |
4714 | ofpacts); | |
4715 | } | |
4716 | \f | |
4717 | /* OpenFlow 1.1 actions. */ | |
4718 | ||
4719 | ||
4720 | /* True if an action sets the value of a field | |
4721 | * in a way that is compatibile with the action set. | |
1b0ee636 | 4722 | * The field can be set via either a set or a move action. |
c2d936a4 BP |
4723 | * False otherwise. */ |
4724 | static bool | |
1b0ee636 | 4725 | ofpact_is_set_or_move_action(const struct ofpact *a) |
c2d936a4 BP |
4726 | { |
4727 | switch (a->type) { | |
4728 | case OFPACT_SET_FIELD: | |
1b0ee636 | 4729 | case OFPACT_REG_MOVE: |
c2d936a4 BP |
4730 | case OFPACT_SET_ETH_DST: |
4731 | case OFPACT_SET_ETH_SRC: | |
4732 | case OFPACT_SET_IP_DSCP: | |
4733 | case OFPACT_SET_IP_ECN: | |
4734 | case OFPACT_SET_IP_TTL: | |
4735 | case OFPACT_SET_IPV4_DST: | |
4736 | case OFPACT_SET_IPV4_SRC: | |
4737 | case OFPACT_SET_L4_DST_PORT: | |
4738 | case OFPACT_SET_L4_SRC_PORT: | |
4739 | case OFPACT_SET_MPLS_LABEL: | |
4740 | case OFPACT_SET_MPLS_TC: | |
4741 | case OFPACT_SET_MPLS_TTL: | |
4742 | case OFPACT_SET_QUEUE: | |
4743 | case OFPACT_SET_TUNNEL: | |
4744 | case OFPACT_SET_VLAN_PCP: | |
4745 | case OFPACT_SET_VLAN_VID: | |
4746 | return true; | |
4747 | case OFPACT_BUNDLE: | |
4748 | case OFPACT_CLEAR_ACTIONS: | |
4749 | case OFPACT_CONTROLLER: | |
4750 | case OFPACT_DEC_MPLS_TTL: | |
4751 | case OFPACT_DEC_TTL: | |
4752 | case OFPACT_ENQUEUE: | |
4753 | case OFPACT_EXIT: | |
e672ff9b | 4754 | case OFPACT_UNROLL_XLATE: |
c2d936a4 BP |
4755 | case OFPACT_FIN_TIMEOUT: |
4756 | case OFPACT_GOTO_TABLE: | |
4757 | case OFPACT_GROUP: | |
4758 | case OFPACT_LEARN: | |
18080541 | 4759 | case OFPACT_CONJUNCTION: |
c2d936a4 BP |
4760 | case OFPACT_METER: |
4761 | case OFPACT_MULTIPATH: | |
4762 | case OFPACT_NOTE: | |
4763 | case OFPACT_OUTPUT: | |
4764 | case OFPACT_OUTPUT_REG: | |
4765 | case OFPACT_POP_MPLS: | |
4766 | case OFPACT_POP_QUEUE: | |
4767 | case OFPACT_PUSH_MPLS: | |
4768 | case OFPACT_PUSH_VLAN: | |
c2d936a4 BP |
4769 | case OFPACT_RESUBMIT: |
4770 | case OFPACT_SAMPLE: | |
4771 | case OFPACT_STACK_POP: | |
4772 | case OFPACT_STACK_PUSH: | |
4773 | case OFPACT_STRIP_VLAN: | |
4774 | case OFPACT_WRITE_ACTIONS: | |
4775 | case OFPACT_WRITE_METADATA: | |
4776 | return false; | |
4777 | default: | |
4778 | OVS_NOT_REACHED(); | |
4779 | } | |
4780 | } | |
4781 | ||
4782 | /* True if an action is allowed in the action set. | |
4783 | * False otherwise. */ | |
4784 | static bool | |
4785 | ofpact_is_allowed_in_actions_set(const struct ofpact *a) | |
4786 | { | |
4787 | switch (a->type) { | |
4788 | case OFPACT_DEC_MPLS_TTL: | |
4789 | case OFPACT_DEC_TTL: | |
4790 | case OFPACT_GROUP: | |
4791 | case OFPACT_OUTPUT: | |
4792 | case OFPACT_POP_MPLS: | |
4793 | case OFPACT_PUSH_MPLS: | |
4794 | case OFPACT_PUSH_VLAN: | |
1b0ee636 | 4795 | case OFPACT_REG_MOVE: |
c2d936a4 BP |
4796 | case OFPACT_SET_FIELD: |
4797 | case OFPACT_SET_ETH_DST: | |
4798 | case OFPACT_SET_ETH_SRC: | |
4799 | case OFPACT_SET_IP_DSCP: | |
4800 | case OFPACT_SET_IP_ECN: | |
4801 | case OFPACT_SET_IP_TTL: | |
4802 | case OFPACT_SET_IPV4_DST: | |
4803 | case OFPACT_SET_IPV4_SRC: | |
4804 | case OFPACT_SET_L4_DST_PORT: | |
4805 | case OFPACT_SET_L4_SRC_PORT: | |
4806 | case OFPACT_SET_MPLS_LABEL: | |
4807 | case OFPACT_SET_MPLS_TC: | |
4808 | case OFPACT_SET_MPLS_TTL: | |
4809 | case OFPACT_SET_QUEUE: | |
4810 | case OFPACT_SET_TUNNEL: | |
4811 | case OFPACT_SET_VLAN_PCP: | |
4812 | case OFPACT_SET_VLAN_VID: | |
4813 | case OFPACT_STRIP_VLAN: | |
4814 | return true; | |
4815 | ||
4816 | /* In general these actions are excluded because they are not part of | |
4817 | * the OpenFlow specification nor map to actions that are defined in | |
4818 | * the specification. Thus the order in which they should be applied | |
4819 | * in the action set is undefined. */ | |
4820 | case OFPACT_BUNDLE: | |
4821 | case OFPACT_CONTROLLER: | |
4822 | case OFPACT_ENQUEUE: | |
4823 | case OFPACT_EXIT: | |
e672ff9b | 4824 | case OFPACT_UNROLL_XLATE: |
c2d936a4 BP |
4825 | case OFPACT_FIN_TIMEOUT: |
4826 | case OFPACT_LEARN: | |
18080541 | 4827 | case OFPACT_CONJUNCTION: |
c2d936a4 BP |
4828 | case OFPACT_MULTIPATH: |
4829 | case OFPACT_NOTE: | |
4830 | case OFPACT_OUTPUT_REG: | |
4831 | case OFPACT_POP_QUEUE: | |
c2d936a4 BP |
4832 | case OFPACT_RESUBMIT: |
4833 | case OFPACT_SAMPLE: | |
4834 | case OFPACT_STACK_POP: | |
4835 | case OFPACT_STACK_PUSH: | |
4836 | ||
4837 | /* The action set may only include actions and thus | |
4838 | * may not include any instructions */ | |
4839 | case OFPACT_CLEAR_ACTIONS: | |
4840 | case OFPACT_GOTO_TABLE: | |
4841 | case OFPACT_METER: | |
4842 | case OFPACT_WRITE_ACTIONS: | |
4843 | case OFPACT_WRITE_METADATA: | |
4844 | return false; | |
4845 | default: | |
4846 | OVS_NOT_REACHED(); | |
4847 | } | |
f25d0cf3 BP |
4848 | } |
4849 | ||
c2d936a4 | 4850 | /* Append ofpact 'a' onto the tail of 'out' */ |
f25d0cf3 | 4851 | static void |
c2d936a4 | 4852 | ofpact_copy(struct ofpbuf *out, const struct ofpact *a) |
f25d0cf3 | 4853 | { |
c2d936a4 | 4854 | ofpbuf_put(out, a, OFPACT_ALIGN(a->len)); |
f25d0cf3 BP |
4855 | } |
4856 | ||
c2d936a4 BP |
4857 | /* Copies the last ofpact whose type is 'filter' from 'in' to 'out'. */ |
4858 | static bool | |
4859 | ofpacts_copy_last(struct ofpbuf *out, const struct ofpbuf *in, | |
4860 | enum ofpact_type filter) | |
f25d0cf3 | 4861 | { |
c2d936a4 BP |
4862 | const struct ofpact *target; |
4863 | const struct ofpact *a; | |
f25d0cf3 | 4864 | |
c2d936a4 | 4865 | target = NULL; |
6fd6ed71 | 4866 | OFPACT_FOR_EACH (a, in->data, in->size) { |
c2d936a4 BP |
4867 | if (a->type == filter) { |
4868 | target = a; | |
4869 | } | |
4870 | } | |
4871 | if (target) { | |
4872 | ofpact_copy(out, target); | |
f25d0cf3 | 4873 | } |
c2d936a4 | 4874 | return target != NULL; |
f25d0cf3 BP |
4875 | } |
4876 | ||
c2d936a4 BP |
4877 | /* Append all ofpacts, for which 'filter' returns true, from 'in' to 'out'. |
4878 | * The order of appended ofpacts is preserved between 'in' and 'out' */ | |
4cceacb9 | 4879 | static void |
c2d936a4 BP |
4880 | ofpacts_copy_all(struct ofpbuf *out, const struct ofpbuf *in, |
4881 | bool (*filter)(const struct ofpact *)) | |
4cceacb9 | 4882 | { |
c2d936a4 | 4883 | const struct ofpact *a; |
4cceacb9 | 4884 | |
6fd6ed71 | 4885 | OFPACT_FOR_EACH (a, in->data, in->size) { |
c2d936a4 BP |
4886 | if (filter(a)) { |
4887 | ofpact_copy(out, a); | |
4888 | } | |
4889 | } | |
4cceacb9 JS |
4890 | } |
4891 | ||
c2d936a4 BP |
4892 | /* Reads 'action_set', which contains ofpacts accumulated by |
4893 | * OFPACT_WRITE_ACTIONS instructions, and writes equivalent actions to be | |
4894 | * executed directly into 'action_list'. (These names correspond to the | |
4895 | * "Action Set" and "Action List" terms used in OpenFlow 1.1+.) | |
4896 | * | |
4897 | * In general this involves appending the last instance of each action that is | |
e672ff9b | 4898 | * admissible in the action set in the order described in the OpenFlow |
c2d936a4 BP |
4899 | * specification. |
4900 | * | |
4901 | * Exceptions: | |
4902 | * + output action is only appended if no group action was present in 'in'. | |
4903 | * + As a simplification all set actions are copied in the order the are | |
4904 | * provided in 'in' as many set actions applied to a field has the same | |
4905 | * affect as only applying the last action that sets a field and | |
4906 | * duplicates are removed by do_xlate_actions(). | |
4907 | * This has an unwanted side-effect of compsoting multiple | |
4908 | * LOAD_REG actions that touch different regions of the same field. */ | |
4909 | void | |
4910 | ofpacts_execute_action_set(struct ofpbuf *action_list, | |
4911 | const struct ofpbuf *action_set) | |
f25d0cf3 | 4912 | { |
c2d936a4 BP |
4913 | /* The OpenFlow spec "Action Set" section specifies this order. */ |
4914 | ofpacts_copy_last(action_list, action_set, OFPACT_STRIP_VLAN); | |
4915 | ofpacts_copy_last(action_list, action_set, OFPACT_POP_MPLS); | |
4916 | ofpacts_copy_last(action_list, action_set, OFPACT_PUSH_MPLS); | |
4917 | ofpacts_copy_last(action_list, action_set, OFPACT_PUSH_VLAN); | |
4918 | ofpacts_copy_last(action_list, action_set, OFPACT_DEC_TTL); | |
4919 | ofpacts_copy_last(action_list, action_set, OFPACT_DEC_MPLS_TTL); | |
1b0ee636 | 4920 | ofpacts_copy_all(action_list, action_set, ofpact_is_set_or_move_action); |
c2d936a4 | 4921 | ofpacts_copy_last(action_list, action_set, OFPACT_SET_QUEUE); |
f25d0cf3 | 4922 | |
c2d936a4 BP |
4923 | /* If both OFPACT_GROUP and OFPACT_OUTPUT are present, OpenFlow says that |
4924 | * we should execute only OFPACT_GROUP. | |
4925 | * | |
4926 | * If neither OFPACT_GROUP nor OFPACT_OUTPUT is present, then we can drop | |
4927 | * all the actions because there's no point in modifying a packet that will | |
4928 | * not be sent anywhere. */ | |
4929 | if (!ofpacts_copy_last(action_list, action_set, OFPACT_GROUP) && | |
2e34a6a3 SS |
4930 | !ofpacts_copy_last(action_list, action_set, OFPACT_OUTPUT) && |
4931 | !ofpacts_copy_last(action_list, action_set, OFPACT_RESUBMIT)) { | |
c2d936a4 | 4932 | ofpbuf_clear(action_list); |
f25d0cf3 | 4933 | } |
f25d0cf3 BP |
4934 | } |
4935 | ||
f25d0cf3 | 4936 | |
c2d936a4 BP |
4937 | static enum ofperr |
4938 | ofpacts_decode_for_action_set(const struct ofp_action_header *in, | |
4939 | size_t n_in, enum ofp_version version, | |
4940 | struct ofpbuf *out) | |
c2d967a5 | 4941 | { |
c2d936a4 BP |
4942 | enum ofperr error; |
4943 | struct ofpact *a; | |
6fd6ed71 | 4944 | size_t start = out->size; |
c2d967a5 | 4945 | |
c2d936a4 | 4946 | error = ofpacts_decode(in, n_in, version, out); |
c2d967a5 | 4947 | |
c2d936a4 BP |
4948 | if (error) { |
4949 | return error; | |
4950 | } | |
4951 | ||
6fd6ed71 | 4952 | OFPACT_FOR_EACH (a, ofpact_end(out->data, start), out->size - start) { |
c2d936a4 BP |
4953 | if (!ofpact_is_allowed_in_actions_set(a)) { |
4954 | VLOG_WARN_RL(&rl, "disallowed action in action set"); | |
4955 | return OFPERR_OFPBAC_BAD_TYPE; | |
c2d967a5 MM |
4956 | } |
4957 | } | |
c2d936a4 BP |
4958 | |
4959 | return 0; | |
c2d967a5 | 4960 | } |
c2d936a4 BP |
4961 | \f |
4962 | /* OpenFlow 1.1 instructions. */ | |
c2d967a5 | 4963 | |
c2d936a4 BP |
4964 | struct instruction_type_info { |
4965 | enum ovs_instruction_type type; | |
4966 | const char *name; | |
4967 | }; | |
4968 | ||
4969 | static const struct instruction_type_info inst_info[] = { | |
4970 | #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) {OVSINST_##ENUM, NAME}, | |
4971 | OVS_INSTRUCTIONS | |
4972 | #undef DEFINE_INST | |
4973 | }; | |
4974 | ||
4975 | const char * | |
4976 | ovs_instruction_name_from_type(enum ovs_instruction_type type) | |
f25d0cf3 | 4977 | { |
c2d936a4 | 4978 | return inst_info[type].name; |
f25d0cf3 BP |
4979 | } |
4980 | ||
c2d936a4 BP |
4981 | int |
4982 | ovs_instruction_type_from_name(const char *name) | |
29089a54 | 4983 | { |
c2d936a4 BP |
4984 | const struct instruction_type_info *p; |
4985 | for (p = inst_info; p < &inst_info[ARRAY_SIZE(inst_info)]; p++) { | |
4986 | if (!strcasecmp(name, p->name)) { | |
4987 | return p->type; | |
4988 | } | |
4989 | } | |
4990 | return -1; | |
29089a54 RL |
4991 | } |
4992 | ||
c2d936a4 BP |
4993 | enum ovs_instruction_type |
4994 | ovs_instruction_type_from_ofpact_type(enum ofpact_type type) | |
f25d0cf3 | 4995 | { |
c2d936a4 BP |
4996 | switch (type) { |
4997 | case OFPACT_METER: | |
4998 | return OVSINST_OFPIT13_METER; | |
4999 | case OFPACT_CLEAR_ACTIONS: | |
5000 | return OVSINST_OFPIT11_CLEAR_ACTIONS; | |
5001 | case OFPACT_WRITE_ACTIONS: | |
5002 | return OVSINST_OFPIT11_WRITE_ACTIONS; | |
5003 | case OFPACT_WRITE_METADATA: | |
5004 | return OVSINST_OFPIT11_WRITE_METADATA; | |
5005 | case OFPACT_GOTO_TABLE: | |
5006 | return OVSINST_OFPIT11_GOTO_TABLE; | |
5007 | case OFPACT_OUTPUT: | |
5008 | case OFPACT_GROUP: | |
f25d0cf3 | 5009 | case OFPACT_CONTROLLER: |
c2d936a4 | 5010 | case OFPACT_ENQUEUE: |
f25d0cf3 | 5011 | case OFPACT_OUTPUT_REG: |
f25d0cf3 | 5012 | case OFPACT_BUNDLE: |
c2d936a4 BP |
5013 | case OFPACT_SET_VLAN_VID: |
5014 | case OFPACT_SET_VLAN_PCP: | |
5015 | case OFPACT_STRIP_VLAN: | |
5016 | case OFPACT_PUSH_VLAN: | |
5017 | case OFPACT_SET_ETH_SRC: | |
5018 | case OFPACT_SET_ETH_DST: | |
5019 | case OFPACT_SET_IPV4_SRC: | |
5020 | case OFPACT_SET_IPV4_DST: | |
5021 | case OFPACT_SET_IP_DSCP: | |
5022 | case OFPACT_SET_IP_ECN: | |
5023 | case OFPACT_SET_IP_TTL: | |
5024 | case OFPACT_SET_L4_SRC_PORT: | |
5025 | case OFPACT_SET_L4_DST_PORT: | |
f25d0cf3 | 5026 | case OFPACT_REG_MOVE: |
c2d936a4 | 5027 | case OFPACT_SET_FIELD: |
bd85dac1 | 5028 | case OFPACT_STACK_PUSH: |
bd85dac1 | 5029 | case OFPACT_STACK_POP: |
f25d0cf3 | 5030 | case OFPACT_DEC_TTL: |
097d4939 | 5031 | case OFPACT_SET_MPLS_LABEL: |
097d4939 | 5032 | case OFPACT_SET_MPLS_TC: |
0f3f3c3d | 5033 | case OFPACT_SET_MPLS_TTL: |
b676167a | 5034 | case OFPACT_DEC_MPLS_TTL: |
c2d936a4 BP |
5035 | case OFPACT_PUSH_MPLS: |
5036 | case OFPACT_POP_MPLS: | |
f25d0cf3 | 5037 | case OFPACT_SET_TUNNEL: |
c2d936a4 BP |
5038 | case OFPACT_SET_QUEUE: |
5039 | case OFPACT_POP_QUEUE: | |
5040 | case OFPACT_FIN_TIMEOUT: | |
5041 | case OFPACT_RESUBMIT: | |
5042 | case OFPACT_LEARN: | |
18080541 | 5043 | case OFPACT_CONJUNCTION: |
c2d936a4 BP |
5044 | case OFPACT_MULTIPATH: |
5045 | case OFPACT_NOTE: | |
5046 | case OFPACT_EXIT: | |
e672ff9b | 5047 | case OFPACT_UNROLL_XLATE: |
c2d936a4 BP |
5048 | case OFPACT_SAMPLE: |
5049 | default: | |
5050 | return OVSINST_OFPIT11_APPLY_ACTIONS; | |
5051 | } | |
5052 | } | |
5053 | ||
5054 | enum ofperr | |
5055 | ovs_instruction_type_from_inst_type(enum ovs_instruction_type *instruction_type, | |
5056 | const uint16_t inst_type) | |
5057 | { | |
5058 | switch (inst_type) { | |
5059 | ||
5060 | #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \ | |
5061 | case ENUM: \ | |
5062 | *instruction_type = OVSINST_##ENUM; \ | |
5063 | return 0; | |
5064 | OVS_INSTRUCTIONS | |
5065 | #undef DEFINE_INST | |
5066 | ||
5067 | default: | |
5068 | return OFPERR_OFPBIC_UNKNOWN_INST; | |
5069 | } | |
5070 | } | |
5071 | ||
5072 | /* Two-way translation between OVS's internal "OVSINST_*" representation of | |
5073 | * instructions and the "OFPIT_*" representation used in OpenFlow. */ | |
5074 | struct ovsinst_map { | |
5075 | enum ovs_instruction_type ovsinst; /* Internal name for instruction. */ | |
5076 | int ofpit; /* OFPIT_* number from OpenFlow spec. */ | |
5077 | }; | |
5078 | ||
5079 | static const struct ovsinst_map * | |
5080 | get_ovsinst_map(enum ofp_version version) | |
5081 | { | |
5082 | /* OpenFlow 1.1 and 1.2 instructions. */ | |
5083 | static const struct ovsinst_map of11[] = { | |
5084 | { OVSINST_OFPIT11_GOTO_TABLE, 1 }, | |
5085 | { OVSINST_OFPIT11_WRITE_METADATA, 2 }, | |
5086 | { OVSINST_OFPIT11_WRITE_ACTIONS, 3 }, | |
5087 | { OVSINST_OFPIT11_APPLY_ACTIONS, 4 }, | |
5088 | { OVSINST_OFPIT11_CLEAR_ACTIONS, 5 }, | |
5089 | { 0, -1 }, | |
5090 | }; | |
f25d0cf3 | 5091 | |
c2d936a4 BP |
5092 | /* OpenFlow 1.3+ instructions. */ |
5093 | static const struct ovsinst_map of13[] = { | |
5094 | { OVSINST_OFPIT11_GOTO_TABLE, 1 }, | |
5095 | { OVSINST_OFPIT11_WRITE_METADATA, 2 }, | |
5096 | { OVSINST_OFPIT11_WRITE_ACTIONS, 3 }, | |
5097 | { OVSINST_OFPIT11_APPLY_ACTIONS, 4 }, | |
5098 | { OVSINST_OFPIT11_CLEAR_ACTIONS, 5 }, | |
5099 | { OVSINST_OFPIT13_METER, 6 }, | |
5100 | { 0, -1 }, | |
5101 | }; | |
4cceacb9 | 5102 | |
c2d936a4 BP |
5103 | return version < OFP13_VERSION ? of11 : of13; |
5104 | } | |
f25d0cf3 | 5105 | |
c2d936a4 BP |
5106 | /* Converts 'ovsinst_bitmap', a bitmap whose bits correspond to OVSINST_* |
5107 | * values, into a bitmap of instructions suitable for OpenFlow 'version' | |
5108 | * (OFP11_VERSION or later), and returns the result. */ | |
5109 | ovs_be32 | |
5110 | ovsinst_bitmap_to_openflow(uint32_t ovsinst_bitmap, enum ofp_version version) | |
5111 | { | |
5112 | uint32_t ofpit_bitmap = 0; | |
5113 | const struct ovsinst_map *x; | |
f25d0cf3 | 5114 | |
c2d936a4 BP |
5115 | for (x = get_ovsinst_map(version); x->ofpit >= 0; x++) { |
5116 | if (ovsinst_bitmap & (1u << x->ovsinst)) { | |
5117 | ofpit_bitmap |= 1u << x->ofpit; | |
5118 | } | |
5119 | } | |
5120 | return htonl(ofpit_bitmap); | |
5121 | } | |
f25d0cf3 | 5122 | |
c2d936a4 BP |
5123 | /* Converts 'ofpit_bitmap', a bitmap of instructions from an OpenFlow message |
5124 | * with the given 'version' (OFP11_VERSION or later) into a bitmap whose bits | |
5125 | * correspond to OVSINST_* values, and returns the result. */ | |
5126 | uint32_t | |
5127 | ovsinst_bitmap_from_openflow(ovs_be32 ofpit_bitmap, enum ofp_version version) | |
5128 | { | |
5129 | uint32_t ovsinst_bitmap = 0; | |
5130 | const struct ovsinst_map *x; | |
f25d0cf3 | 5131 | |
c2d936a4 BP |
5132 | for (x = get_ovsinst_map(version); x->ofpit >= 0; x++) { |
5133 | if (ofpit_bitmap & htonl(1u << x->ofpit)) { | |
5134 | ovsinst_bitmap |= 1u << x->ovsinst; | |
5135 | } | |
5136 | } | |
5137 | return ovsinst_bitmap; | |
5138 | } | |
f25d0cf3 | 5139 | |
c2d936a4 BP |
5140 | static inline struct ofp11_instruction * |
5141 | instruction_next(const struct ofp11_instruction *inst) | |
5142 | { | |
5143 | return ((struct ofp11_instruction *) (void *) | |
5144 | ((uint8_t *) inst + ntohs(inst->len))); | |
5145 | } | |
f25d0cf3 | 5146 | |
c2d936a4 BP |
5147 | static inline bool |
5148 | instruction_is_valid(const struct ofp11_instruction *inst, | |
5149 | size_t n_instructions) | |
5150 | { | |
5151 | uint16_t len = ntohs(inst->len); | |
5152 | return (!(len % OFP11_INSTRUCTION_ALIGN) | |
5153 | && len >= sizeof *inst | |
5154 | && len / sizeof *inst <= n_instructions); | |
5155 | } | |
f25d0cf3 | 5156 | |
c2d936a4 BP |
5157 | /* This macro is careful to check for instructions with bad lengths. */ |
5158 | #define INSTRUCTION_FOR_EACH(ITER, LEFT, INSTRUCTIONS, N_INSTRUCTIONS) \ | |
5159 | for ((ITER) = (INSTRUCTIONS), (LEFT) = (N_INSTRUCTIONS); \ | |
5160 | (LEFT) > 0 && instruction_is_valid(ITER, LEFT); \ | |
5161 | ((LEFT) -= (ntohs((ITER)->len) \ | |
5162 | / sizeof(struct ofp11_instruction)), \ | |
5163 | (ITER) = instruction_next(ITER))) | |
f25d0cf3 | 5164 | |
c2d936a4 BP |
5165 | static enum ofperr |
5166 | decode_openflow11_instruction(const struct ofp11_instruction *inst, | |
5167 | enum ovs_instruction_type *type) | |
5168 | { | |
5169 | uint16_t len = ntohs(inst->len); | |
b02475c5 | 5170 | |
c2d936a4 BP |
5171 | switch (inst->type) { |
5172 | case CONSTANT_HTONS(OFPIT11_EXPERIMENTER): | |
5173 | return OFPERR_OFPBIC_BAD_EXPERIMENTER; | |
b02475c5 | 5174 | |
c2d936a4 BP |
5175 | #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \ |
5176 | case CONSTANT_HTONS(ENUM): \ | |
5177 | if (EXTENSIBLE \ | |
5178 | ? len >= sizeof(struct STRUCT) \ | |
5179 | : len == sizeof(struct STRUCT)) { \ | |
5180 | *type = OVSINST_##ENUM; \ | |
5181 | return 0; \ | |
5182 | } else { \ | |
5183 | return OFPERR_OFPBIC_BAD_LEN; \ | |
5184 | } | |
5185 | OVS_INSTRUCTIONS | |
5186 | #undef DEFINE_INST | |
29089a54 | 5187 | |
c2d936a4 BP |
5188 | default: |
5189 | return OFPERR_OFPBIC_UNKNOWN_INST; | |
f25d0cf3 BP |
5190 | } |
5191 | } | |
f25d0cf3 | 5192 | |
c2d936a4 BP |
5193 | static enum ofperr |
5194 | decode_openflow11_instructions(const struct ofp11_instruction insts[], | |
5195 | size_t n_insts, | |
5196 | const struct ofp11_instruction *out[]) | |
f25d0cf3 | 5197 | { |
c2d936a4 BP |
5198 | const struct ofp11_instruction *inst; |
5199 | size_t left; | |
f25d0cf3 | 5200 | |
c2d936a4 BP |
5201 | memset(out, 0, N_OVS_INSTRUCTIONS * sizeof *out); |
5202 | INSTRUCTION_FOR_EACH (inst, left, insts, n_insts) { | |
5203 | enum ovs_instruction_type type; | |
5204 | enum ofperr error; | |
f25d0cf3 | 5205 | |
c2d936a4 BP |
5206 | error = decode_openflow11_instruction(inst, &type); |
5207 | if (error) { | |
5208 | return error; | |
5209 | } | |
f25d0cf3 | 5210 | |
c2d936a4 BP |
5211 | if (out[type]) { |
5212 | return OFPERR_OFPBIC_DUP_INST; | |
5213 | } | |
5214 | out[type] = inst; | |
5215 | } | |
5216 | ||
5217 | if (left) { | |
5218 | VLOG_WARN_RL(&rl, "bad instruction format at offset %"PRIuSIZE, | |
5219 | (n_insts - left) * sizeof *inst); | |
5220 | return OFPERR_OFPBIC_BAD_LEN; | |
5221 | } | |
5222 | return 0; | |
f25d0cf3 BP |
5223 | } |
5224 | ||
5225 | static void | |
c2d936a4 BP |
5226 | get_actions_from_instruction(const struct ofp11_instruction *inst, |
5227 | const struct ofp_action_header **actions, | |
5228 | size_t *actions_len) | |
f25d0cf3 | 5229 | { |
c2d936a4 BP |
5230 | *actions = ALIGNED_CAST(const struct ofp_action_header *, inst + 1); |
5231 | *actions_len = ntohs(inst->len) - sizeof *inst; | |
5232 | } | |
f25d0cf3 | 5233 | |
c2d936a4 BP |
5234 | enum ofperr |
5235 | ofpacts_pull_openflow_instructions(struct ofpbuf *openflow, | |
5236 | unsigned int instructions_len, | |
5237 | enum ofp_version version, | |
5238 | struct ofpbuf *ofpacts) | |
5239 | { | |
5240 | const struct ofp11_instruction *instructions; | |
5241 | const struct ofp11_instruction *insts[N_OVS_INSTRUCTIONS]; | |
5242 | enum ofperr error; | |
f25d0cf3 | 5243 | |
c2d936a4 BP |
5244 | if (version == OFP10_VERSION) { |
5245 | return ofpacts_pull_openflow_actions__(openflow, instructions_len, | |
5246 | version, | |
5247 | (1u << N_OVS_INSTRUCTIONS) - 1, | |
5248 | ofpacts); | |
5249 | } | |
f25d0cf3 | 5250 | |
c2d936a4 | 5251 | ofpbuf_clear(ofpacts); |
f25d0cf3 | 5252 | |
c2d936a4 BP |
5253 | if (instructions_len % OFP11_INSTRUCTION_ALIGN != 0) { |
5254 | VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u is not a " | |
5255 | "multiple of %d", | |
5256 | instructions_len, OFP11_INSTRUCTION_ALIGN); | |
5257 | error = OFPERR_OFPBIC_BAD_LEN; | |
5258 | goto exit; | |
5259 | } | |
f25d0cf3 | 5260 | |
c2d936a4 BP |
5261 | instructions = ofpbuf_try_pull(openflow, instructions_len); |
5262 | if (instructions == NULL) { | |
5263 | VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u exceeds " | |
5264 | "remaining message length (%"PRIu32")", | |
6fd6ed71 | 5265 | instructions_len, openflow->size); |
c2d936a4 BP |
5266 | error = OFPERR_OFPBIC_BAD_LEN; |
5267 | goto exit; | |
5268 | } | |
f25d0cf3 | 5269 | |
c2d936a4 BP |
5270 | error = decode_openflow11_instructions( |
5271 | instructions, instructions_len / OFP11_INSTRUCTION_ALIGN, | |
5272 | insts); | |
5273 | if (error) { | |
5274 | goto exit; | |
5275 | } | |
f25d0cf3 | 5276 | |
c2d936a4 BP |
5277 | if (insts[OVSINST_OFPIT13_METER]) { |
5278 | const struct ofp13_instruction_meter *oim; | |
5279 | struct ofpact_meter *om; | |
f25d0cf3 | 5280 | |
c2d936a4 BP |
5281 | oim = ALIGNED_CAST(const struct ofp13_instruction_meter *, |
5282 | insts[OVSINST_OFPIT13_METER]); | |
f25d0cf3 | 5283 | |
c2d936a4 BP |
5284 | om = ofpact_put_METER(ofpacts); |
5285 | om->meter_id = ntohl(oim->meter_id); | |
5286 | } | |
5287 | if (insts[OVSINST_OFPIT11_APPLY_ACTIONS]) { | |
5288 | const struct ofp_action_header *actions; | |
5289 | size_t actions_len; | |
f25d0cf3 | 5290 | |
c2d936a4 BP |
5291 | get_actions_from_instruction(insts[OVSINST_OFPIT11_APPLY_ACTIONS], |
5292 | &actions, &actions_len); | |
5293 | error = ofpacts_decode(actions, actions_len, version, ofpacts); | |
5294 | if (error) { | |
5295 | goto exit; | |
5296 | } | |
5297 | } | |
5298 | if (insts[OVSINST_OFPIT11_CLEAR_ACTIONS]) { | |
5299 | instruction_get_OFPIT11_CLEAR_ACTIONS( | |
5300 | insts[OVSINST_OFPIT11_CLEAR_ACTIONS]); | |
5301 | ofpact_put_CLEAR_ACTIONS(ofpacts); | |
5302 | } | |
5303 | if (insts[OVSINST_OFPIT11_WRITE_ACTIONS]) { | |
5304 | struct ofpact_nest *on; | |
5305 | const struct ofp_action_header *actions; | |
5306 | size_t actions_len; | |
5307 | size_t start; | |
f25d0cf3 | 5308 | |
c2d936a4 | 5309 | ofpact_pad(ofpacts); |
6fd6ed71 | 5310 | start = ofpacts->size; |
c2d936a4 BP |
5311 | on = ofpact_put(ofpacts, OFPACT_WRITE_ACTIONS, |
5312 | offsetof(struct ofpact_nest, actions)); | |
5313 | get_actions_from_instruction(insts[OVSINST_OFPIT11_WRITE_ACTIONS], | |
5314 | &actions, &actions_len); | |
5315 | error = ofpacts_decode_for_action_set(actions, actions_len, | |
5316 | version, ofpacts); | |
5317 | if (error) { | |
5318 | goto exit; | |
5319 | } | |
5320 | on = ofpbuf_at_assert(ofpacts, start, sizeof *on); | |
6fd6ed71 | 5321 | on->ofpact.len = ofpacts->size - start; |
c2d936a4 BP |
5322 | } |
5323 | if (insts[OVSINST_OFPIT11_WRITE_METADATA]) { | |
5324 | const struct ofp11_instruction_write_metadata *oiwm; | |
5325 | struct ofpact_metadata *om; | |
ca287d20 | 5326 | |
c2d936a4 BP |
5327 | oiwm = ALIGNED_CAST(const struct ofp11_instruction_write_metadata *, |
5328 | insts[OVSINST_OFPIT11_WRITE_METADATA]); | |
8dd54666 | 5329 | |
c2d936a4 BP |
5330 | om = ofpact_put_WRITE_METADATA(ofpacts); |
5331 | om->metadata = oiwm->metadata; | |
5332 | om->mask = oiwm->metadata_mask; | |
5333 | } | |
5334 | if (insts[OVSINST_OFPIT11_GOTO_TABLE]) { | |
5335 | const struct ofp11_instruction_goto_table *oigt; | |
5336 | struct ofpact_goto_table *ogt; | |
7395c052 | 5337 | |
c2d936a4 BP |
5338 | oigt = instruction_get_OFPIT11_GOTO_TABLE( |
5339 | insts[OVSINST_OFPIT11_GOTO_TABLE]); | |
5340 | ogt = ofpact_put_GOTO_TABLE(ofpacts); | |
5341 | ogt->table_id = oigt->table_id; | |
5342 | } | |
e3f8f887 | 5343 | |
6fd6ed71 | 5344 | error = ofpacts_verify(ofpacts->data, ofpacts->size, |
c2d936a4 BP |
5345 | (1u << N_OVS_INSTRUCTIONS) - 1); |
5346 | exit: | |
5347 | if (error) { | |
5348 | ofpbuf_clear(ofpacts); | |
f25d0cf3 | 5349 | } |
c2d936a4 | 5350 | return error; |
f25d0cf3 | 5351 | } |
d01c980f | 5352 | |
c2d936a4 BP |
5353 | /* Update the length of the instruction that begins at offset 'ofs' within |
5354 | * 'openflow' and contains nested actions that extend to the end of 'openflow'. | |
5355 | * If the instruction contains no nested actions, deletes it entirely. */ | |
d01c980f | 5356 | static void |
c2d936a4 | 5357 | ofpacts_update_instruction_actions(struct ofpbuf *openflow, size_t ofs) |
d01c980f | 5358 | { |
c2d936a4 | 5359 | struct ofp11_instruction_actions *oia; |
d01c980f | 5360 | |
c2d936a4 | 5361 | oia = ofpbuf_at_assert(openflow, ofs, sizeof *oia); |
6fd6ed71 PS |
5362 | if (openflow->size > ofs + sizeof *oia) { |
5363 | oia->len = htons(openflow->size - ofs); | |
c2d936a4 | 5364 | } else { |
6fd6ed71 | 5365 | openflow->size = ofs; |
c2d936a4 | 5366 | } |
d01c980f | 5367 | } |
c2d936a4 BP |
5368 | \f |
5369 | /* Checks that 'port' is a valid output port for OFPACT_OUTPUT, given that the | |
5370 | * switch will never have more than 'max_ports' ports. Returns 0 if 'port' is | |
5371 | * valid, otherwise an OpenFlow error code. */ | |
5372 | enum ofperr | |
5373 | ofpact_check_output_port(ofp_port_t port, ofp_port_t max_ports) | |
99086062 | 5374 | { |
c2d936a4 BP |
5375 | switch (port) { |
5376 | case OFPP_IN_PORT: | |
5377 | case OFPP_TABLE: | |
5378 | case OFPP_NORMAL: | |
5379 | case OFPP_FLOOD: | |
5380 | case OFPP_ALL: | |
5381 | case OFPP_CONTROLLER: | |
5382 | case OFPP_NONE: | |
5383 | case OFPP_LOCAL: | |
5384 | return 0; | |
5385 | ||
5386 | default: | |
5387 | if (ofp_to_u16(port) < ofp_to_u16(max_ports)) { | |
5388 | return 0; | |
5389 | } | |
5390 | return OFPERR_OFPBAC_BAD_OUT_PORT; | |
99086062 BP |
5391 | } |
5392 | } | |
5393 | ||
c2d936a4 BP |
5394 | /* Removes the protocols that require consistency between match and actions |
5395 | * (that's everything but OpenFlow 1.0) from '*usable_protocols'. | |
5396 | * | |
5397 | * (An example of an inconsistency between match and actions is a flow that | |
5398 | * does not match on an MPLS Ethertype but has an action that pops an MPLS | |
5399 | * label.) */ | |
d01c980f | 5400 | static void |
c2d936a4 BP |
5401 | inconsistent_match(enum ofputil_protocol *usable_protocols) |
5402 | { | |
5403 | *usable_protocols &= OFPUTIL_P_OF10_ANY; | |
5404 | } | |
5405 | ||
5406 | /* May modify flow->dl_type, flow->nw_proto and flow->vlan_tci, | |
5407 | * caller must restore them. | |
5408 | * | |
5409 | * Modifies some actions, filling in fields that could not be properly set | |
5410 | * without context. */ | |
5411 | static enum ofperr | |
5412 | ofpact_check__(enum ofputil_protocol *usable_protocols, struct ofpact *a, | |
5413 | struct flow *flow, ofp_port_t max_ports, | |
5414 | uint8_t table_id, uint8_t n_tables) | |
d01c980f | 5415 | { |
c2d936a4 BP |
5416 | const struct ofpact_enqueue *enqueue; |
5417 | const struct mf_field *mf; | |
5418 | ||
d01c980f BP |
5419 | switch (a->type) { |
5420 | case OFPACT_OUTPUT: | |
c2d936a4 BP |
5421 | return ofpact_check_output_port(ofpact_get_OUTPUT(a)->port, |
5422 | max_ports); | |
5423 | ||
5424 | case OFPACT_CONTROLLER: | |
5425 | return 0; | |
d01c980f BP |
5426 | |
5427 | case OFPACT_ENQUEUE: | |
c2d936a4 BP |
5428 | enqueue = ofpact_get_ENQUEUE(a); |
5429 | if (ofp_to_u16(enqueue->port) >= ofp_to_u16(max_ports) | |
5430 | && enqueue->port != OFPP_IN_PORT | |
5431 | && enqueue->port != OFPP_LOCAL) { | |
5432 | return OFPERR_OFPBAC_BAD_OUT_PORT; | |
5433 | } | |
5434 | return 0; | |
5435 | ||
5436 | case OFPACT_OUTPUT_REG: | |
5437 | return mf_check_src(&ofpact_get_OUTPUT_REG(a)->src, flow); | |
5438 | ||
5439 | case OFPACT_BUNDLE: | |
5440 | return bundle_check(ofpact_get_BUNDLE(a), max_ports, flow); | |
d01c980f BP |
5441 | |
5442 | case OFPACT_SET_VLAN_VID: | |
c2d936a4 BP |
5443 | /* Remember if we saw a vlan tag in the flow to aid translating to |
5444 | * OpenFlow 1.1+ if need be. */ | |
5445 | ofpact_get_SET_VLAN_VID(a)->flow_has_vlan = | |
5446 | (flow->vlan_tci & htons(VLAN_CFI)) == htons(VLAN_CFI); | |
5447 | if (!(flow->vlan_tci & htons(VLAN_CFI)) && | |
5448 | !ofpact_get_SET_VLAN_VID(a)->push_vlan_if_needed) { | |
5449 | inconsistent_match(usable_protocols); | |
5450 | } | |
5451 | /* Temporary mark that we have a vlan tag. */ | |
5452 | flow->vlan_tci |= htons(VLAN_CFI); | |
5453 | return 0; | |
d01c980f BP |
5454 | |
5455 | case OFPACT_SET_VLAN_PCP: | |
c2d936a4 BP |
5456 | /* Remember if we saw a vlan tag in the flow to aid translating to |
5457 | * OpenFlow 1.1+ if need be. */ | |
5458 | ofpact_get_SET_VLAN_PCP(a)->flow_has_vlan = | |
5459 | (flow->vlan_tci & htons(VLAN_CFI)) == htons(VLAN_CFI); | |
5460 | if (!(flow->vlan_tci & htons(VLAN_CFI)) && | |
5461 | !ofpact_get_SET_VLAN_PCP(a)->push_vlan_if_needed) { | |
5462 | inconsistent_match(usable_protocols); | |
5463 | } | |
5464 | /* Temporary mark that we have a vlan tag. */ | |
5465 | flow->vlan_tci |= htons(VLAN_CFI); | |
5466 | return 0; | |
d01c980f BP |
5467 | |
5468 | case OFPACT_STRIP_VLAN: | |
c2d936a4 BP |
5469 | if (!(flow->vlan_tci & htons(VLAN_CFI))) { |
5470 | inconsistent_match(usable_protocols); | |
5471 | } | |
5472 | /* Temporary mark that we have no vlan tag. */ | |
5473 | flow->vlan_tci = htons(0); | |
5474 | return 0; | |
d01c980f | 5475 | |
3e34fbdd | 5476 | case OFPACT_PUSH_VLAN: |
c2d936a4 BP |
5477 | if (flow->vlan_tci & htons(VLAN_CFI)) { |
5478 | /* Multiple VLAN headers not supported. */ | |
5479 | return OFPERR_OFPBAC_BAD_TAG; | |
5480 | } | |
5481 | /* Temporary mark that we have a vlan tag. */ | |
5482 | flow->vlan_tci |= htons(VLAN_CFI); | |
5483 | return 0; | |
276c4e7a | 5484 | |
d01c980f | 5485 | case OFPACT_SET_ETH_SRC: |
d01c980f | 5486 | case OFPACT_SET_ETH_DST: |
c2d936a4 | 5487 | return 0; |
d01c980f BP |
5488 | |
5489 | case OFPACT_SET_IPV4_SRC: | |
d01c980f | 5490 | case OFPACT_SET_IPV4_DST: |
c2d936a4 BP |
5491 | if (flow->dl_type != htons(ETH_TYPE_IP)) { |
5492 | inconsistent_match(usable_protocols); | |
5493 | } | |
5494 | return 0; | |
d01c980f | 5495 | |
04f01c24 | 5496 | case OFPACT_SET_IP_DSCP: |
ff14eb7a | 5497 | case OFPACT_SET_IP_ECN: |
0c20dbe4 | 5498 | case OFPACT_SET_IP_TTL: |
7bcb1506 | 5499 | case OFPACT_DEC_TTL: |
c2d936a4 BP |
5500 | if (!is_ip_any(flow)) { |
5501 | inconsistent_match(usable_protocols); | |
5502 | } | |
5503 | return 0; | |
b02475c5 | 5504 | |
c2d936a4 | 5505 | case OFPACT_SET_L4_SRC_PORT: |
c2d936a4 | 5506 | case OFPACT_SET_L4_DST_PORT: |
b8778a0d | 5507 | if (!is_ip_any(flow) || (flow->nw_frag & FLOW_NW_FRAG_LATER) || |
c2d936a4 BP |
5508 | (flow->nw_proto != IPPROTO_TCP && flow->nw_proto != IPPROTO_UDP |
5509 | && flow->nw_proto != IPPROTO_SCTP)) { | |
5510 | inconsistent_match(usable_protocols); | |
5511 | } | |
5512 | /* Note on which transport protocol the port numbers are set. | |
5513 | * This allows this set action to be converted to an OF1.2 set field | |
5514 | * action. */ | |
b8778a0d JR |
5515 | if (a->type == OFPACT_SET_L4_SRC_PORT) { |
5516 | ofpact_get_SET_L4_SRC_PORT(a)->flow_ip_proto = flow->nw_proto; | |
5517 | } else { | |
5518 | ofpact_get_SET_L4_DST_PORT(a)->flow_ip_proto = flow->nw_proto; | |
5519 | } | |
c2d936a4 | 5520 | return 0; |
b02475c5 | 5521 | |
c2d936a4 BP |
5522 | case OFPACT_REG_MOVE: |
5523 | return nxm_reg_move_check(ofpact_get_REG_MOVE(a), flow); | |
8dd54666 | 5524 | |
e3f8f887 | 5525 | case OFPACT_SET_FIELD: |
c2d936a4 BP |
5526 | mf = ofpact_get_SET_FIELD(a)->field; |
5527 | /* Require OXM_OF_VLAN_VID to have an existing VLAN header. */ | |
5528 | if (!mf_are_prereqs_ok(mf, flow) || | |
5529 | (mf->id == MFF_VLAN_VID && !(flow->vlan_tci & htons(VLAN_CFI)))) { | |
5530 | VLOG_WARN_RL(&rl, "set_field %s lacks correct prerequisities", | |
5531 | mf->name); | |
5532 | return OFPERR_OFPBAC_MATCH_INCONSISTENT; | |
5533 | } | |
5534 | /* Remember if we saw a vlan tag in the flow to aid translating to | |
5535 | * OpenFlow 1.1 if need be. */ | |
5536 | ofpact_get_SET_FIELD(a)->flow_has_vlan = | |
5537 | (flow->vlan_tci & htons(VLAN_CFI)) == htons(VLAN_CFI); | |
5538 | if (mf->id == MFF_VLAN_TCI) { | |
5539 | /* The set field may add or remove the vlan tag, | |
5540 | * Mark the status temporarily. */ | |
5541 | flow->vlan_tci = ofpact_get_SET_FIELD(a)->value.be16; | |
5542 | } | |
5543 | return 0; | |
e3f8f887 | 5544 | |
bd85dac1 | 5545 | case OFPACT_STACK_PUSH: |
c2d936a4 BP |
5546 | return nxm_stack_push_check(ofpact_get_STACK_PUSH(a), flow); |
5547 | ||
bd85dac1 | 5548 | case OFPACT_STACK_POP: |
c2d936a4 BP |
5549 | return nxm_stack_pop_check(ofpact_get_STACK_POP(a), flow); |
5550 | ||
5551 | case OFPACT_SET_MPLS_LABEL: | |
5552 | case OFPACT_SET_MPLS_TC: | |
5553 | case OFPACT_SET_MPLS_TTL: | |
5554 | case OFPACT_DEC_MPLS_TTL: | |
5555 | if (!eth_type_mpls(flow->dl_type)) { | |
5556 | inconsistent_match(usable_protocols); | |
5557 | } | |
5558 | return 0; | |
5559 | ||
d01c980f | 5560 | case OFPACT_SET_TUNNEL: |
c2d936a4 | 5561 | case OFPACT_SET_QUEUE: |
d01c980f | 5562 | case OFPACT_POP_QUEUE: |
d01c980f | 5563 | case OFPACT_RESUBMIT: |
c2d936a4 BP |
5564 | return 0; |
5565 | ||
5566 | case OFPACT_FIN_TIMEOUT: | |
5567 | if (flow->nw_proto != IPPROTO_TCP) { | |
5568 | inconsistent_match(usable_protocols); | |
5569 | } | |
5570 | return 0; | |
5571 | ||
d01c980f | 5572 | case OFPACT_LEARN: |
c2d936a4 BP |
5573 | return learn_check(ofpact_get_LEARN(a), flow); |
5574 | ||
18080541 BP |
5575 | case OFPACT_CONJUNCTION: |
5576 | return 0; | |
5577 | ||
d01c980f | 5578 | case OFPACT_MULTIPATH: |
c2d936a4 BP |
5579 | return multipath_check(ofpact_get_MULTIPATH(a), flow); |
5580 | ||
d01c980f BP |
5581 | case OFPACT_NOTE: |
5582 | case OFPACT_EXIT: | |
c2d936a4 | 5583 | return 0; |
d01c980f | 5584 | |
c2d936a4 BP |
5585 | case OFPACT_PUSH_MPLS: |
5586 | flow->dl_type = ofpact_get_PUSH_MPLS(a)->ethertype; | |
5587 | /* The packet is now MPLS and the MPLS payload is opaque. | |
5588 | * Thus nothing can be assumed about the network protocol. | |
5589 | * Temporarily mark that we have no nw_proto. */ | |
5590 | flow->nw_proto = 0; | |
5591 | return 0; | |
1e7db674 | 5592 | |
c2d936a4 BP |
5593 | case OFPACT_POP_MPLS: |
5594 | if (!eth_type_mpls(flow->dl_type)) { | |
5595 | inconsistent_match(usable_protocols); | |
5596 | } | |
5597 | flow->dl_type = ofpact_get_POP_MPLS(a)->ethertype; | |
5598 | return 0; | |
1e7db674 | 5599 | |
c2d936a4 BP |
5600 | case OFPACT_SAMPLE: |
5601 | return 0; | |
1e7db674 | 5602 | |
c2d936a4 BP |
5603 | case OFPACT_CLEAR_ACTIONS: |
5604 | return 0; | |
1e7db674 | 5605 | |
c2d936a4 BP |
5606 | case OFPACT_WRITE_ACTIONS: { |
5607 | /* Use a temporary copy of 'usable_protocols' because we can't check | |
5608 | * consistency of an action set. */ | |
5609 | struct ofpact_nest *on = ofpact_get_WRITE_ACTIONS(a); | |
5610 | enum ofputil_protocol p = *usable_protocols; | |
5611 | return ofpacts_check(on->actions, ofpact_nest_get_action_len(on), | |
5612 | flow, max_ports, table_id, n_tables, &p); | |
5613 | } | |
1e7db674 | 5614 | |
c2d936a4 BP |
5615 | case OFPACT_WRITE_METADATA: |
5616 | return 0; | |
1e7db674 | 5617 | |
c2d936a4 BP |
5618 | case OFPACT_METER: { |
5619 | uint32_t mid = ofpact_get_METER(a)->meter_id; | |
5620 | if (mid == 0 || mid > OFPM13_MAX) { | |
5621 | return OFPERR_OFPMMFC_INVALID_METER; | |
5622 | } | |
5623 | return 0; | |
5624 | } | |
1e7db674 | 5625 | |
c2d936a4 BP |
5626 | case OFPACT_GOTO_TABLE: { |
5627 | uint8_t goto_table = ofpact_get_GOTO_TABLE(a)->table_id; | |
5628 | if ((table_id != 255 && goto_table <= table_id) | |
5629 | || (n_tables != 255 && goto_table >= n_tables)) { | |
8c87971e | 5630 | return OFPERR_OFPBIC_BAD_TABLE_ID; |
c2d936a4 BP |
5631 | } |
5632 | return 0; | |
5633 | } | |
1e7db674 | 5634 | |
c2d936a4 BP |
5635 | case OFPACT_GROUP: |
5636 | return 0; | |
1e7db674 | 5637 | |
e672ff9b JR |
5638 | case OFPACT_UNROLL_XLATE: |
5639 | /* UNROLL is an internal action that should never be seen via | |
5640 | * OpenFlow. */ | |
5641 | return OFPERR_OFPBAC_BAD_TYPE; | |
5642 | ||
c2d936a4 BP |
5643 | default: |
5644 | OVS_NOT_REACHED(); | |
5645 | } | |
5646 | } | |
1e7db674 | 5647 | |
c2d936a4 BP |
5648 | /* Checks that the 'ofpacts_len' bytes of actions in 'ofpacts' are |
5649 | * appropriate for a packet with the prerequisites satisfied by 'flow' in a | |
5650 | * switch with no more than 'max_ports' ports. | |
5651 | * | |
5652 | * If 'ofpacts' and 'flow' are inconsistent with one another, un-sets in | |
5653 | * '*usable_protocols' the protocols that forbid the inconsistency. (An | |
5654 | * example of an inconsistency between match and actions is a flow that does | |
5655 | * not match on an MPLS Ethertype but has an action that pops an MPLS label.) | |
5656 | * | |
5657 | * May annotate ofpacts with information gathered from the 'flow'. | |
5658 | * | |
5659 | * May temporarily modify 'flow', but restores the changes before returning. */ | |
5660 | enum ofperr | |
5661 | ofpacts_check(struct ofpact ofpacts[], size_t ofpacts_len, | |
5662 | struct flow *flow, ofp_port_t max_ports, | |
5663 | uint8_t table_id, uint8_t n_tables, | |
5664 | enum ofputil_protocol *usable_protocols) | |
5665 | { | |
5666 | struct ofpact *a; | |
5667 | ovs_be16 dl_type = flow->dl_type; | |
5668 | ovs_be16 vlan_tci = flow->vlan_tci; | |
5669 | uint8_t nw_proto = flow->nw_proto; | |
5670 | enum ofperr error = 0; | |
1e7db674 | 5671 | |
c2d936a4 BP |
5672 | OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { |
5673 | error = ofpact_check__(usable_protocols, a, flow, | |
5674 | max_ports, table_id, n_tables); | |
5675 | if (error) { | |
1e7db674 | 5676 | break; |
c2d936a4 BP |
5677 | } |
5678 | } | |
5679 | /* Restore fields that may have been modified. */ | |
5680 | flow->dl_type = dl_type; | |
5681 | flow->vlan_tci = vlan_tci; | |
5682 | flow->nw_proto = nw_proto; | |
5683 | return error; | |
5684 | } | |
1e7db674 | 5685 | |
c2d936a4 BP |
5686 | /* Like ofpacts_check(), but reports inconsistencies as |
5687 | * OFPERR_OFPBAC_MATCH_INCONSISTENT rather than clearing bits. */ | |
5688 | enum ofperr | |
5689 | ofpacts_check_consistency(struct ofpact ofpacts[], size_t ofpacts_len, | |
5690 | struct flow *flow, ofp_port_t max_ports, | |
5691 | uint8_t table_id, uint8_t n_tables, | |
5692 | enum ofputil_protocol usable_protocols) | |
5693 | { | |
5694 | enum ofputil_protocol p = usable_protocols; | |
5695 | enum ofperr error; | |
1e7db674 | 5696 | |
c2d936a4 BP |
5697 | error = ofpacts_check(ofpacts, ofpacts_len, flow, max_ports, |
5698 | table_id, n_tables, &p); | |
5699 | return (error ? error | |
5700 | : p != usable_protocols ? OFPERR_OFPBAC_MATCH_INCONSISTENT | |
5701 | : 0); | |
5702 | } | |
097d4939 | 5703 | |
18080541 BP |
5704 | /* Verifies that the 'ofpacts_len' bytes of actions in 'ofpacts' are in the |
5705 | * appropriate order as defined by the OpenFlow spec and as required by Open | |
5706 | * vSwitch. | |
5707 | * | |
5708 | * 'allowed_ovsinsts' is a bitmap of OVSINST_* values, in which 1-bits indicate | |
5709 | * instructions that are allowed within 'ofpacts[]'. */ | |
c2d936a4 BP |
5710 | static enum ofperr |
5711 | ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len, | |
5712 | uint32_t allowed_ovsinsts) | |
5713 | { | |
5714 | const struct ofpact *a; | |
5715 | enum ovs_instruction_type inst; | |
097d4939 | 5716 | |
c2d936a4 BP |
5717 | inst = OVSINST_OFPIT13_METER; |
5718 | OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { | |
5719 | enum ovs_instruction_type next; | |
1e7db674 | 5720 | |
18080541 BP |
5721 | if (a->type == OFPACT_CONJUNCTION) { |
5722 | OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { | |
5723 | if (a->type != OFPACT_CONJUNCTION) { | |
5724 | VLOG_WARN("when %s action is present, it must be the only " | |
5725 | "kind of action used", ofpact_name(a->type)); | |
5726 | return OFPERR_NXBAC_BAD_CONJUNCTION; | |
5727 | } | |
5728 | } | |
5729 | return 0; | |
5730 | } | |
5731 | ||
c2d936a4 BP |
5732 | next = ovs_instruction_type_from_ofpact_type(a->type); |
5733 | if (a > ofpacts | |
5734 | && (inst == OVSINST_OFPIT11_APPLY_ACTIONS | |
5735 | ? next < inst | |
5736 | : next <= inst)) { | |
5737 | const char *name = ovs_instruction_name_from_type(inst); | |
5738 | const char *next_name = ovs_instruction_name_from_type(next); | |
1e7db674 | 5739 | |
c2d936a4 BP |
5740 | if (next == inst) { |
5741 | VLOG_WARN("duplicate %s instruction not allowed, for OpenFlow " | |
5742 | "1.1+ compatibility", name); | |
5743 | } else { | |
5744 | VLOG_WARN("invalid instruction ordering: %s must appear " | |
5745 | "before %s, for OpenFlow 1.1+ compatibility", | |
5746 | next_name, name); | |
5747 | } | |
5748 | return OFPERR_OFPBAC_UNSUPPORTED_ORDER; | |
5749 | } | |
5750 | if (!((1u << next) & allowed_ovsinsts)) { | |
5751 | const char *name = ovs_instruction_name_from_type(next); | |
1e7db674 | 5752 | |
c2d936a4 BP |
5753 | VLOG_WARN("%s instruction not allowed here", name); |
5754 | return OFPERR_OFPBIC_UNSUP_INST; | |
1e7db674 | 5755 | } |
c2d936a4 BP |
5756 | |
5757 | inst = next; | |
5758 | } | |
5759 | ||
5760 | return 0; | |
5761 | } | |
5762 | \f | |
5763 | /* Converting ofpacts to OpenFlow. */ | |
5764 | ||
5765 | static void | |
5766 | encode_ofpact(const struct ofpact *a, enum ofp_version ofp_version, | |
5767 | struct ofpbuf *out) | |
5768 | { | |
5769 | switch (a->type) { | |
5770 | #define OFPACT(ENUM, STRUCT, MEMBER, NAME) \ | |
5771 | case OFPACT_##ENUM: \ | |
355ead69 GS |
5772 | encode_##ENUM(ofpact_get_##ENUM(a), ofp_version, out); \ |
5773 | return; | |
c2d936a4 BP |
5774 | OFPACTS |
5775 | #undef OFPACT | |
5776 | default: | |
5777 | OVS_NOT_REACHED(); | |
1e7db674 | 5778 | } |
e3f8f887 JR |
5779 | } |
5780 | ||
5781 | /* Converts the 'ofpacts_len' bytes of ofpacts in 'ofpacts' into OpenFlow | |
5782 | * actions in 'openflow', appending the actions to any existing data in | |
d01c980f | 5783 | * 'openflow'. */ |
a07c15bc | 5784 | size_t |
e3f8f887 JR |
5785 | ofpacts_put_openflow_actions(const struct ofpact ofpacts[], size_t ofpacts_len, |
5786 | struct ofpbuf *openflow, | |
5787 | enum ofp_version ofp_version) | |
d01c980f BP |
5788 | { |
5789 | const struct ofpact *a; | |
6fd6ed71 | 5790 | size_t start_size = openflow->size; |
d01c980f BP |
5791 | |
5792 | OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { | |
c2d936a4 | 5793 | encode_ofpact(a, ofp_version, openflow); |
d01c980f | 5794 | } |
6fd6ed71 | 5795 | return openflow->size - start_size; |
d01c980f BP |
5796 | } |
5797 | ||
c2d936a4 BP |
5798 | static enum ovs_instruction_type |
5799 | ofpact_is_apply_actions(const struct ofpact *a) | |
d01c980f | 5800 | { |
c2d936a4 BP |
5801 | return (ovs_instruction_type_from_ofpact_type(a->type) |
5802 | == OVSINST_OFPIT11_APPLY_ACTIONS); | |
d01c980f | 5803 | } |
8dd54666 IY |
5804 | |
5805 | void | |
e3f8f887 JR |
5806 | ofpacts_put_openflow_instructions(const struct ofpact ofpacts[], |
5807 | size_t ofpacts_len, | |
5808 | struct ofpbuf *openflow, | |
5809 | enum ofp_version ofp_version) | |
8dd54666 | 5810 | { |
c2d936a4 | 5811 | const struct ofpact *end = ofpact_end(ofpacts, ofpacts_len); |
8dd54666 IY |
5812 | const struct ofpact *a; |
5813 | ||
8f2cded4 BP |
5814 | if (ofp_version == OFP10_VERSION) { |
5815 | ofpacts_put_openflow_actions(ofpacts, ofpacts_len, openflow, | |
5816 | ofp_version); | |
5817 | return; | |
5818 | } | |
e3f8f887 | 5819 | |
c2d936a4 BP |
5820 | a = ofpacts; |
5821 | while (a < end) { | |
5822 | if (ofpact_is_apply_actions(a)) { | |
6fd6ed71 | 5823 | size_t ofs = openflow->size; |
8dd54666 IY |
5824 | |
5825 | instruction_put_OFPIT11_APPLY_ACTIONS(openflow); | |
c2d936a4 BP |
5826 | do { |
5827 | encode_ofpact(a, ofp_version, openflow); | |
5828 | a = ofpact_next(a); | |
5829 | } while (a < end && ofpact_is_apply_actions(a)); | |
7fdb60a7 | 5830 | ofpacts_update_instruction_actions(openflow, ofs); |
c2d936a4 BP |
5831 | } else { |
5832 | encode_ofpact(a, ofp_version, openflow); | |
5833 | a = ofpact_next(a); | |
8dd54666 IY |
5834 | } |
5835 | } | |
5836 | } | |
d01c980f | 5837 | \f |
08d1e234 BP |
5838 | /* Sets of supported actions. */ |
5839 | ||
5840 | /* Two-way translation between OVS's internal "OFPACT_*" representation of | |
5841 | * actions and the "OFPAT_*" representation used in some OpenFlow version. | |
5842 | * (OFPAT_* numbering varies from one OpenFlow version to another, so a given | |
5843 | * instance is specific to one OpenFlow version.) */ | |
5844 | struct ofpact_map { | |
5845 | enum ofpact_type ofpact; /* Internal name for action type. */ | |
5846 | int ofpat; /* OFPAT_* number from OpenFlow spec. */ | |
5847 | }; | |
5848 | ||
5849 | static const struct ofpact_map * | |
5850 | get_ofpact_map(enum ofp_version version) | |
5851 | { | |
5852 | /* OpenFlow 1.0 actions. */ | |
5853 | static const struct ofpact_map of10[] = { | |
5854 | { OFPACT_OUTPUT, 0 }, | |
5855 | { OFPACT_SET_VLAN_VID, 1 }, | |
5856 | { OFPACT_SET_VLAN_PCP, 2 }, | |
5857 | { OFPACT_STRIP_VLAN, 3 }, | |
5858 | { OFPACT_SET_ETH_SRC, 4 }, | |
5859 | { OFPACT_SET_ETH_DST, 5 }, | |
5860 | { OFPACT_SET_IPV4_SRC, 6 }, | |
5861 | { OFPACT_SET_IPV4_DST, 7 }, | |
5862 | { OFPACT_SET_IP_DSCP, 8 }, | |
5863 | { OFPACT_SET_L4_SRC_PORT, 9 }, | |
5864 | { OFPACT_SET_L4_DST_PORT, 10 }, | |
5865 | { OFPACT_ENQUEUE, 11 }, | |
5866 | { 0, -1 }, | |
5867 | }; | |
5868 | ||
5869 | /* OpenFlow 1.1 actions. */ | |
5870 | static const struct ofpact_map of11[] = { | |
5871 | { OFPACT_OUTPUT, 0 }, | |
5872 | { OFPACT_SET_VLAN_VID, 1 }, | |
5873 | { OFPACT_SET_VLAN_PCP, 2 }, | |
5874 | { OFPACT_SET_ETH_SRC, 3 }, | |
5875 | { OFPACT_SET_ETH_DST, 4 }, | |
5876 | { OFPACT_SET_IPV4_SRC, 5 }, | |
5877 | { OFPACT_SET_IPV4_DST, 6 }, | |
5878 | { OFPACT_SET_IP_DSCP, 7 }, | |
5879 | { OFPACT_SET_IP_ECN, 8 }, | |
5880 | { OFPACT_SET_L4_SRC_PORT, 9 }, | |
5881 | { OFPACT_SET_L4_DST_PORT, 10 }, | |
5882 | /* OFPAT_COPY_TTL_OUT (11) not supported. */ | |
5883 | /* OFPAT_COPY_TTL_IN (12) not supported. */ | |
5884 | { OFPACT_SET_MPLS_LABEL, 13 }, | |
5885 | { OFPACT_SET_MPLS_TC, 14 }, | |
5886 | { OFPACT_SET_MPLS_TTL, 15 }, | |
5887 | { OFPACT_DEC_MPLS_TTL, 16 }, | |
5888 | { OFPACT_PUSH_VLAN, 17 }, | |
5889 | { OFPACT_STRIP_VLAN, 18 }, | |
5890 | { OFPACT_PUSH_MPLS, 19 }, | |
5891 | { OFPACT_POP_MPLS, 20 }, | |
5892 | { OFPACT_SET_QUEUE, 21 }, | |
5893 | { OFPACT_GROUP, 22 }, | |
5894 | { OFPACT_SET_IP_TTL, 23 }, | |
5895 | { OFPACT_DEC_TTL, 24 }, | |
5896 | { 0, -1 }, | |
5897 | }; | |
5898 | ||
5899 | /* OpenFlow 1.2, 1.3, and 1.4 actions. */ | |
5900 | static const struct ofpact_map of12[] = { | |
5901 | { OFPACT_OUTPUT, 0 }, | |
5902 | /* OFPAT_COPY_TTL_OUT (11) not supported. */ | |
5903 | /* OFPAT_COPY_TTL_IN (12) not supported. */ | |
5904 | { OFPACT_SET_MPLS_TTL, 15 }, | |
5905 | { OFPACT_DEC_MPLS_TTL, 16 }, | |
5906 | { OFPACT_PUSH_VLAN, 17 }, | |
5907 | { OFPACT_STRIP_VLAN, 18 }, | |
5908 | { OFPACT_PUSH_MPLS, 19 }, | |
5909 | { OFPACT_POP_MPLS, 20 }, | |
5910 | { OFPACT_SET_QUEUE, 21 }, | |
5911 | { OFPACT_GROUP, 22 }, | |
5912 | { OFPACT_SET_IP_TTL, 23 }, | |
5913 | { OFPACT_DEC_TTL, 24 }, | |
5914 | { OFPACT_SET_FIELD, 25 }, | |
5915 | /* OF1.3+ OFPAT_PUSH_PBB (26) not supported. */ | |
5916 | /* OF1.3+ OFPAT_POP_PBB (27) not supported. */ | |
5917 | { 0, -1 }, | |
5918 | }; | |
5919 | ||
5920 | switch (version) { | |
5921 | case OFP10_VERSION: | |
5922 | return of10; | |
5923 | ||
5924 | case OFP11_VERSION: | |
5925 | return of11; | |
5926 | ||
5927 | case OFP12_VERSION: | |
5928 | case OFP13_VERSION: | |
5929 | case OFP14_VERSION: | |
5930 | case OFP15_VERSION: | |
5931 | default: | |
5932 | return of12; | |
5933 | } | |
5934 | } | |
5935 | ||
5936 | /* Converts 'ofpacts_bitmap', a bitmap whose bits correspond to OFPACT_* | |
5937 | * values, into a bitmap of actions suitable for OpenFlow 'version', and | |
5938 | * returns the result. */ | |
5939 | ovs_be32 | |
5940 | ofpact_bitmap_to_openflow(uint64_t ofpacts_bitmap, enum ofp_version version) | |
5941 | { | |
5942 | uint32_t openflow_bitmap = 0; | |
5943 | const struct ofpact_map *x; | |
5944 | ||
5945 | for (x = get_ofpact_map(version); x->ofpat >= 0; x++) { | |
5946 | if (ofpacts_bitmap & (UINT64_C(1) << x->ofpact)) { | |
5947 | openflow_bitmap |= 1u << x->ofpat; | |
5948 | } | |
5949 | } | |
5950 | return htonl(openflow_bitmap); | |
5951 | } | |
5952 | ||
5953 | /* Converts 'ofpat_bitmap', a bitmap of actions from an OpenFlow message with | |
5954 | * the given 'version' into a bitmap whose bits correspond to OFPACT_* values, | |
5955 | * and returns the result. */ | |
5956 | uint64_t | |
5957 | ofpact_bitmap_from_openflow(ovs_be32 ofpat_bitmap, enum ofp_version version) | |
5958 | { | |
5959 | uint64_t ofpact_bitmap = 0; | |
5960 | const struct ofpact_map *x; | |
5961 | ||
5962 | for (x = get_ofpact_map(version); x->ofpat >= 0; x++) { | |
5963 | if (ofpat_bitmap & htonl(1u << x->ofpat)) { | |
5964 | ofpact_bitmap |= UINT64_C(1) << x->ofpact; | |
5965 | } | |
5966 | } | |
5967 | return ofpact_bitmap; | |
5968 | } | |
5969 | ||
5970 | /* Appends to 's' a string representation of the set of OFPACT_* represented | |
5971 | * by 'ofpacts_bitmap'. */ | |
5972 | void | |
5973 | ofpact_bitmap_format(uint64_t ofpacts_bitmap, struct ds *s) | |
5974 | { | |
5975 | if (!ofpacts_bitmap) { | |
5976 | ds_put_cstr(s, "<none>"); | |
5977 | } else { | |
5978 | while (ofpacts_bitmap) { | |
5979 | ds_put_format(s, "%s ", | |
5980 | ofpact_name(rightmost_1bit_idx(ofpacts_bitmap))); | |
5981 | ofpacts_bitmap = zero_rightmost_1bit(ofpacts_bitmap); | |
5982 | } | |
5983 | ds_chomp(s, ' '); | |
5984 | } | |
5985 | } | |
5986 | \f | |
f25d0cf3 BP |
5987 | /* Returns true if 'action' outputs to 'port', false otherwise. */ |
5988 | static bool | |
4e022ec0 | 5989 | ofpact_outputs_to_port(const struct ofpact *ofpact, ofp_port_t port) |
f25d0cf3 BP |
5990 | { |
5991 | switch (ofpact->type) { | |
5992 | case OFPACT_OUTPUT: | |
5993 | return ofpact_get_OUTPUT(ofpact)->port == port; | |
5994 | case OFPACT_ENQUEUE: | |
5995 | return ofpact_get_ENQUEUE(ofpact)->port == port; | |
5996 | case OFPACT_CONTROLLER: | |
5997 | return port == OFPP_CONTROLLER; | |
5998 | ||
5999 | case OFPACT_OUTPUT_REG: | |
6000 | case OFPACT_BUNDLE: | |
6001 | case OFPACT_SET_VLAN_VID: | |
6002 | case OFPACT_SET_VLAN_PCP: | |
6003 | case OFPACT_STRIP_VLAN: | |
3e34fbdd | 6004 | case OFPACT_PUSH_VLAN: |
f25d0cf3 BP |
6005 | case OFPACT_SET_ETH_SRC: |
6006 | case OFPACT_SET_ETH_DST: | |
6007 | case OFPACT_SET_IPV4_SRC: | |
6008 | case OFPACT_SET_IPV4_DST: | |
04f01c24 | 6009 | case OFPACT_SET_IP_DSCP: |
ff14eb7a | 6010 | case OFPACT_SET_IP_ECN: |
0c20dbe4 | 6011 | case OFPACT_SET_IP_TTL: |
f25d0cf3 BP |
6012 | case OFPACT_SET_L4_SRC_PORT: |
6013 | case OFPACT_SET_L4_DST_PORT: | |
6014 | case OFPACT_REG_MOVE: | |
b2dd70be | 6015 | case OFPACT_SET_FIELD: |
bd85dac1 AZ |
6016 | case OFPACT_STACK_PUSH: |
6017 | case OFPACT_STACK_POP: | |
f25d0cf3 | 6018 | case OFPACT_DEC_TTL: |
097d4939 JR |
6019 | case OFPACT_SET_MPLS_LABEL: |
6020 | case OFPACT_SET_MPLS_TC: | |
0f3f3c3d | 6021 | case OFPACT_SET_MPLS_TTL: |
b676167a | 6022 | case OFPACT_DEC_MPLS_TTL: |
f25d0cf3 | 6023 | case OFPACT_SET_TUNNEL: |
4cceacb9 | 6024 | case OFPACT_WRITE_METADATA: |
f25d0cf3 BP |
6025 | case OFPACT_SET_QUEUE: |
6026 | case OFPACT_POP_QUEUE: | |
6027 | case OFPACT_FIN_TIMEOUT: | |
6028 | case OFPACT_RESUBMIT: | |
6029 | case OFPACT_LEARN: | |
18080541 | 6030 | case OFPACT_CONJUNCTION: |
f25d0cf3 | 6031 | case OFPACT_MULTIPATH: |
f25d0cf3 BP |
6032 | case OFPACT_NOTE: |
6033 | case OFPACT_EXIT: | |
e672ff9b | 6034 | case OFPACT_UNROLL_XLATE: |
b02475c5 SH |
6035 | case OFPACT_PUSH_MPLS: |
6036 | case OFPACT_POP_MPLS: | |
29089a54 | 6037 | case OFPACT_SAMPLE: |
b19e8793 | 6038 | case OFPACT_CLEAR_ACTIONS: |
7fdb60a7 | 6039 | case OFPACT_WRITE_ACTIONS: |
8dd54666 | 6040 | case OFPACT_GOTO_TABLE: |
638a19b0 | 6041 | case OFPACT_METER: |
7395c052 | 6042 | case OFPACT_GROUP: |
f25d0cf3 BP |
6043 | default: |
6044 | return false; | |
6045 | } | |
6046 | } | |
6047 | ||
6048 | /* Returns true if any action in the 'ofpacts_len' bytes of 'ofpacts' outputs | |
6049 | * to 'port', false otherwise. */ | |
6050 | bool | |
6051 | ofpacts_output_to_port(const struct ofpact *ofpacts, size_t ofpacts_len, | |
4e022ec0 | 6052 | ofp_port_t port) |
c2d936a4 BP |
6053 | { |
6054 | const struct ofpact *a; | |
f25d0cf3 | 6055 | |
c2d936a4 BP |
6056 | OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { |
6057 | if (ofpact_outputs_to_port(a, port)) { | |
6058 | return true; | |
6059 | } | |
6060 | } | |
f25d0cf3 | 6061 | |
c2d936a4 BP |
6062 | return false; |
6063 | } | |
f25d0cf3 | 6064 | |
c2d936a4 BP |
6065 | /* Returns true if any action in the 'ofpacts_len' bytes of 'ofpacts' outputs |
6066 | * to 'group', false otherwise. */ | |
6067 | bool | |
6068 | ofpacts_output_to_group(const struct ofpact *ofpacts, size_t ofpacts_len, | |
6069 | uint32_t group_id) | |
6070 | { | |
6071 | const struct ofpact *a; | |
b02475c5 | 6072 | |
c2d936a4 BP |
6073 | OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { |
6074 | if (a->type == OFPACT_GROUP | |
6075 | && ofpact_get_GROUP(a)->group_id == group_id) { | |
6076 | return true; | |
6077 | } | |
6078 | } | |
b02475c5 | 6079 | |
c2d936a4 BP |
6080 | return false; |
6081 | } | |
8dd54666 | 6082 | |
c2d936a4 BP |
6083 | bool |
6084 | ofpacts_equal(const struct ofpact *a, size_t a_len, | |
6085 | const struct ofpact *b, size_t b_len) | |
6086 | { | |
6087 | return a_len == b_len && !memcmp(a, b, a_len); | |
6088 | } | |
29089a54 | 6089 | |
c2d936a4 BP |
6090 | /* Finds the OFPACT_METER action, if any, in the 'ofpacts_len' bytes of |
6091 | * 'ofpacts'. If found, returns its meter ID; if not, returns 0. | |
6092 | * | |
6093 | * This function relies on the order of 'ofpacts' being correct (as checked by | |
6094 | * ofpacts_verify()). */ | |
6095 | uint32_t | |
6096 | ofpacts_get_meter(const struct ofpact ofpacts[], size_t ofpacts_len) | |
6097 | { | |
6098 | const struct ofpact *a; | |
7fdb60a7 | 6099 | |
c2d936a4 BP |
6100 | OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { |
6101 | enum ovs_instruction_type inst; | |
b19e8793 | 6102 | |
c2d936a4 BP |
6103 | inst = ovs_instruction_type_from_ofpact_type(a->type); |
6104 | if (a->type == OFPACT_METER) { | |
6105 | return ofpact_get_METER(a)->meter_id; | |
6106 | } else if (inst > OVSINST_OFPIT13_METER) { | |
6107 | break; | |
4cceacb9 | 6108 | } |
c2d936a4 | 6109 | } |
638a19b0 | 6110 | |
c2d936a4 BP |
6111 | return 0; |
6112 | } | |
6113 | \f | |
6114 | /* Formatting ofpacts. */ | |
7395c052 | 6115 | |
c2d936a4 BP |
6116 | static void |
6117 | ofpact_format(const struct ofpact *a, struct ds *s) | |
6118 | { | |
6119 | switch (a->type) { | |
6120 | #define OFPACT(ENUM, STRUCT, MEMBER, NAME) \ | |
6121 | case OFPACT_##ENUM: \ | |
6122 | format_##ENUM(ALIGNED_CAST(const struct STRUCT *, a), s); \ | |
6123 | break; | |
6124 | OFPACTS | |
6125 | #undef OFPACT | |
6126 | default: | |
6127 | OVS_NOT_REACHED(); | |
f25d0cf3 BP |
6128 | } |
6129 | } | |
6130 | ||
6131 | /* Appends a string representing the 'ofpacts_len' bytes of ofpacts in | |
6132 | * 'ofpacts' to 'string'. */ | |
6133 | void | |
6134 | ofpacts_format(const struct ofpact *ofpacts, size_t ofpacts_len, | |
6135 | struct ds *string) | |
6136 | { | |
f25d0cf3 BP |
6137 | if (!ofpacts_len) { |
6138 | ds_put_cstr(string, "drop"); | |
6139 | } else { | |
6140 | const struct ofpact *a; | |
6141 | ||
6142 | OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { | |
6143 | if (a != ofpacts) { | |
6144 | ds_put_cstr(string, ","); | |
6145 | } | |
8dd54666 | 6146 | |
5dca28b5 | 6147 | /* XXX write-actions */ |
f25d0cf3 BP |
6148 | ofpact_format(a, string); |
6149 | } | |
6150 | } | |
6151 | } | |
6152 | \f | |
6153 | /* Internal use by helpers. */ | |
6154 | ||
6155 | void * | |
6156 | ofpact_put(struct ofpbuf *ofpacts, enum ofpact_type type, size_t len) | |
6157 | { | |
6158 | struct ofpact *ofpact; | |
6159 | ||
6160 | ofpact_pad(ofpacts); | |
6fd6ed71 PS |
6161 | ofpacts->header = ofpbuf_put_uninit(ofpacts, len); |
6162 | ofpact = ofpacts->header; | |
f25d0cf3 BP |
6163 | ofpact_init(ofpact, type, len); |
6164 | return ofpact; | |
6165 | } | |
6166 | ||
6167 | void | |
6168 | ofpact_init(struct ofpact *ofpact, enum ofpact_type type, size_t len) | |
6169 | { | |
6170 | memset(ofpact, 0, len); | |
6171 | ofpact->type = type; | |
c2d936a4 | 6172 | ofpact->raw = -1; |
f25d0cf3 BP |
6173 | ofpact->len = len; |
6174 | } | |
6175 | \f | |
6176 | /* Updates 'ofpact->len' to the number of bytes in the tail of 'ofpacts' | |
6177 | * starting at 'ofpact'. | |
6178 | * | |
6179 | * This is the correct way to update a variable-length ofpact's length after | |
6180 | * adding the variable-length part of the payload. (See the large comment | |
6181 | * near the end of ofp-actions.h for more information.) */ | |
6182 | void | |
6183 | ofpact_update_len(struct ofpbuf *ofpacts, struct ofpact *ofpact) | |
6184 | { | |
6fd6ed71 | 6185 | ovs_assert(ofpact == ofpacts->header); |
f25d0cf3 BP |
6186 | ofpact->len = (char *) ofpbuf_tail(ofpacts) - (char *) ofpact; |
6187 | } | |
6188 | ||
6189 | /* Pads out 'ofpacts' to a multiple of OFPACT_ALIGNTO bytes in length. Each | |
6190 | * ofpact_put_<ENUM>() calls this function automatically beforehand, but the | |
6191 | * client must call this itself after adding the final ofpact to an array of | |
6192 | * them. | |
6193 | * | |
6194 | * (The consequences of failing to call this function are probably not dire. | |
6195 | * OFPACT_FOR_EACH will calculate a pointer beyond the end of the ofpacts, but | |
6196 | * not dereference it. That's undefined behavior, technically, but it will not | |
6197 | * cause a real problem on common systems. Still, it seems better to call | |
6198 | * it.) */ | |
6199 | void | |
6200 | ofpact_pad(struct ofpbuf *ofpacts) | |
6201 | { | |
6fd6ed71 | 6202 | unsigned int pad = PAD_SIZE(ofpacts->size, OFPACT_ALIGNTO); |
f6e984d7 BP |
6203 | if (pad) { |
6204 | ofpbuf_put_zeros(ofpacts, pad); | |
f25d0cf3 BP |
6205 | } |
6206 | } | |
c2d936a4 BP |
6207 | \f |
6208 | ||
6209 | ||
6210 | ||
cab50449 | 6211 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
6212 | ofpact_parse(enum ofpact_type type, char *value, struct ofpbuf *ofpacts, |
6213 | enum ofputil_protocol *usable_protocols) | |
6214 | { | |
6215 | switch (type) { | |
6216 | #define OFPACT(ENUM, STRUCT, MEMBER, NAME) \ | |
6217 | case OFPACT_##ENUM: \ | |
6218 | return parse_##ENUM(value, ofpacts, usable_protocols); | |
6219 | OFPACTS | |
6220 | #undef OFPACT | |
6221 | default: | |
6222 | OVS_NOT_REACHED(); | |
6223 | } | |
6224 | } | |
6225 | ||
6226 | static bool | |
6227 | ofpact_type_from_name(const char *name, enum ofpact_type *type) | |
6228 | { | |
6229 | #define OFPACT(ENUM, STRUCT, MEMBER, NAME) \ | |
6230 | if (!strcasecmp(name, NAME)) { \ | |
6231 | *type = OFPACT_##ENUM; \ | |
6232 | return true; \ | |
6233 | } | |
6234 | OFPACTS | |
6235 | #undef OFPACT | |
6236 | ||
6237 | return false; | |
6238 | } | |
6239 | ||
6240 | /* Parses 'str' as a series of instructions, and appends them to 'ofpacts'. | |
6241 | * | |
6242 | * Returns NULL if successful, otherwise a malloc()'d string describing the | |
6243 | * error. The caller is responsible for freeing the returned string. */ | |
cab50449 | 6244 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
6245 | ofpacts_parse__(char *str, struct ofpbuf *ofpacts, |
6246 | enum ofputil_protocol *usable_protocols, | |
6247 | bool allow_instructions) | |
6248 | { | |
6249 | int prev_inst = -1; | |
6250 | enum ofperr retval; | |
6251 | char *key, *value; | |
6252 | bool drop = false; | |
6253 | char *pos; | |
6254 | ||
6255 | pos = str; | |
6256 | while (ofputil_parse_key_value(&pos, &key, &value)) { | |
6257 | enum ovs_instruction_type inst = OVSINST_OFPIT11_APPLY_ACTIONS; | |
6258 | enum ofpact_type type; | |
6259 | char *error = NULL; | |
6260 | ofp_port_t port; | |
6261 | ||
6262 | if (ofpact_type_from_name(key, &type)) { | |
6263 | error = ofpact_parse(type, value, ofpacts, usable_protocols); | |
6264 | inst = ovs_instruction_type_from_ofpact_type(type); | |
6265 | } else if (!strcasecmp(key, "mod_vlan_vid")) { | |
6266 | error = parse_set_vlan_vid(value, ofpacts, true); | |
6267 | } else if (!strcasecmp(key, "mod_vlan_pcp")) { | |
6268 | error = parse_set_vlan_pcp(value, ofpacts, true); | |
6269 | } else if (!strcasecmp(key, "set_nw_ttl")) { | |
6270 | error = parse_SET_IP_TTL(value, ofpacts, usable_protocols); | |
6271 | } else if (!strcasecmp(key, "pop_vlan")) { | |
6272 | error = parse_pop_vlan(ofpacts); | |
6273 | } else if (!strcasecmp(key, "set_tunnel64")) { | |
6274 | error = parse_set_tunnel(value, ofpacts, | |
6275 | NXAST_RAW_SET_TUNNEL64); | |
7eb4b1f1 BP |
6276 | } else if (!strcasecmp(key, "load")) { |
6277 | error = parse_reg_load(value, ofpacts); | |
c2d936a4 BP |
6278 | } else if (!strcasecmp(key, "bundle_load")) { |
6279 | error = parse_bundle_load(value, ofpacts); | |
6280 | } else if (!strcasecmp(key, "drop")) { | |
6281 | drop = true; | |
6282 | } else if (!strcasecmp(key, "apply_actions")) { | |
6283 | return xstrdup("apply_actions is the default instruction"); | |
6284 | } else if (ofputil_port_from_string(key, &port)) { | |
6285 | ofpact_put_OUTPUT(ofpacts)->port = port; | |
6286 | } else { | |
6287 | return xasprintf("unknown action %s", key); | |
6288 | } | |
6289 | if (error) { | |
6290 | return error; | |
6291 | } | |
6292 | ||
6293 | if (inst != OVSINST_OFPIT11_APPLY_ACTIONS) { | |
6294 | if (!allow_instructions) { | |
6295 | return xasprintf("only actions are allowed here (not " | |
6296 | "instruction %s)", | |
6297 | ovs_instruction_name_from_type(inst)); | |
6298 | } | |
6299 | if (inst == prev_inst) { | |
6300 | return xasprintf("instruction %s may be specified only once", | |
6301 | ovs_instruction_name_from_type(inst)); | |
6302 | } | |
6303 | } | |
6304 | if (prev_inst != -1 && inst < prev_inst) { | |
6305 | return xasprintf("instruction %s must be specified before %s", | |
6306 | ovs_instruction_name_from_type(inst), | |
6307 | ovs_instruction_name_from_type(prev_inst)); | |
6308 | } | |
6309 | prev_inst = inst; | |
6310 | } | |
6311 | ofpact_pad(ofpacts); | |
6312 | ||
6fd6ed71 | 6313 | if (drop && ofpacts->size) { |
c2d936a4 BP |
6314 | return xstrdup("\"drop\" must not be accompanied by any other action " |
6315 | "or instruction"); | |
6316 | } | |
6317 | ||
6fd6ed71 | 6318 | retval = ofpacts_verify(ofpacts->data, ofpacts->size, |
c2d936a4 BP |
6319 | (allow_instructions |
6320 | ? (1u << N_OVS_INSTRUCTIONS) - 1 | |
6321 | : 1u << OVSINST_OFPIT11_APPLY_ACTIONS)); | |
6322 | if (retval) { | |
6323 | return xstrdup("Incorrect instruction ordering"); | |
6324 | } | |
6325 | ||
6326 | return NULL; | |
6327 | } | |
6328 | ||
cab50449 | 6329 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
6330 | ofpacts_parse(char *str, struct ofpbuf *ofpacts, |
6331 | enum ofputil_protocol *usable_protocols, bool allow_instructions) | |
6332 | { | |
6fd6ed71 | 6333 | uint32_t orig_size = ofpacts->size; |
c2d936a4 BP |
6334 | char *error = ofpacts_parse__(str, ofpacts, usable_protocols, |
6335 | allow_instructions); | |
6336 | if (error) { | |
6fd6ed71 | 6337 | ofpacts->size = orig_size; |
c2d936a4 BP |
6338 | } |
6339 | return error; | |
6340 | } | |
6341 | ||
cab50449 | 6342 | static char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
6343 | ofpacts_parse_copy(const char *s_, struct ofpbuf *ofpacts, |
6344 | enum ofputil_protocol *usable_protocols, | |
6345 | bool allow_instructions) | |
6346 | { | |
6347 | char *error, *s; | |
6348 | ||
6349 | *usable_protocols = OFPUTIL_P_ANY; | |
6350 | ||
6351 | s = xstrdup(s_); | |
6352 | error = ofpacts_parse(s, ofpacts, usable_protocols, allow_instructions); | |
6353 | free(s); | |
6354 | ||
6355 | return error; | |
6356 | } | |
6357 | ||
6358 | /* Parses 's' as a set of OpenFlow actions and appends the actions to | |
6359 | * 'ofpacts'. | |
6360 | * | |
6361 | * Returns NULL if successful, otherwise a malloc()'d string describing the | |
6362 | * error. The caller is responsible for freeing the returned string. */ | |
cab50449 | 6363 | char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
6364 | ofpacts_parse_actions(const char *s, struct ofpbuf *ofpacts, |
6365 | enum ofputil_protocol *usable_protocols) | |
6366 | { | |
6367 | return ofpacts_parse_copy(s, ofpacts, usable_protocols, false); | |
6368 | } | |
6369 | ||
6370 | /* Parses 's' as a set of OpenFlow instructions and appends the instructions to | |
6371 | * 'ofpacts'. | |
6372 | * | |
6373 | * Returns NULL if successful, otherwise a malloc()'d string describing the | |
6374 | * error. The caller is responsible for freeing the returned string. */ | |
cab50449 | 6375 | char * OVS_WARN_UNUSED_RESULT |
c2d936a4 BP |
6376 | ofpacts_parse_instructions(const char *s, struct ofpbuf *ofpacts, |
6377 | enum ofputil_protocol *usable_protocols) | |
6378 | { | |
6379 | return ofpacts_parse_copy(s, ofpacts, usable_protocols, true); | |
6380 | } | |
08d1e234 BP |
6381 | |
6382 | const char * | |
6383 | ofpact_name(enum ofpact_type type) | |
6384 | { | |
6385 | switch (type) { | |
6386 | #define OFPACT(ENUM, STRUCT, MEMBER, NAME) case OFPACT_##ENUM: return NAME; | |
6387 | OFPACTS | |
6388 | #undef OFPACT | |
6389 | } | |
6390 | return "<unknown>"; | |
6391 | } | |
c2d936a4 BP |
6392 | \f |
6393 | /* Low-level action decoding and encoding functions. */ | |
6394 | ||
6395 | /* Everything needed to identify a particular OpenFlow action. */ | |
6396 | struct ofpact_hdrs { | |
6397 | uint32_t vendor; /* 0 if standard, otherwise a vendor code. */ | |
6398 | uint16_t type; /* Type if standard, otherwise subtype. */ | |
6399 | uint8_t ofp_version; /* From ofp_header. */ | |
6400 | }; | |
6401 | ||
6402 | /* Information about a particular OpenFlow action. */ | |
6403 | struct ofpact_raw_instance { | |
6404 | /* The action's identity. */ | |
6405 | struct ofpact_hdrs hdrs; | |
6406 | enum ofp_raw_action_type raw; | |
6407 | ||
6408 | /* Looking up the action. */ | |
6409 | struct hmap_node decode_node; /* Based on 'hdrs'. */ | |
6410 | struct hmap_node encode_node; /* Based on 'raw' + 'hdrs.ofp_version'. */ | |
6411 | ||
6412 | /* The action's encoded size. | |
6413 | * | |
6414 | * If this action is fixed-length, 'min_length' == 'max_length'. | |
6415 | * If it is variable length, then 'max_length' is ROUND_DOWN(UINT16_MAX, | |
6416 | * OFP_ACTION_ALIGN) == 65528. */ | |
6417 | unsigned short int min_length; | |
6418 | unsigned short int max_length; | |
6419 | ||
6420 | /* For actions with a simple integer numeric argument, 'arg_ofs' is the | |
6421 | * offset of that argument from the beginning of the action and 'arg_len' | |
6422 | * its length, both in bytes. | |
6423 | * | |
6424 | * For actions that take other forms, these are both zero. */ | |
6425 | unsigned short int arg_ofs; | |
6426 | unsigned short int arg_len; | |
6427 | ||
6428 | /* The name of the action, e.g. "OFPAT_OUTPUT" or "NXAST_RESUBMIT". */ | |
6429 | const char *name; | |
6430 | ||
6431 | /* If this action is deprecated, a human-readable string with a brief | |
6432 | * explanation. */ | |
6433 | const char *deprecation; | |
6434 | }; | |
6435 | ||
6436 | /* Action header. */ | |
6437 | struct ofp_action_header { | |
6438 | /* The meaning of other values of 'type' generally depends on the OpenFlow | |
6439 | * version (see enum ofp_raw_action_type). | |
6440 | * | |
6441 | * Across all OpenFlow versions, OFPAT_VENDOR indicates that 'vendor' | |
6442 | * designates an OpenFlow vendor ID and that the remainder of the action | |
6443 | * structure has a vendor-defined meaning. | |
6444 | */ | |
6445 | #define OFPAT_VENDOR 0xffff | |
6446 | ovs_be16 type; | |
6447 | ||
6448 | /* Always a multiple of 8. */ | |
6449 | ovs_be16 len; | |
6450 | ||
6451 | /* For type == OFPAT_VENDOR only, this is a vendor ID, e.g. NX_VENDOR_ID or | |
6452 | * ONF_VENDOR_ID. Other 'type's use this space for some other purpose. */ | |
6453 | ovs_be32 vendor; | |
6454 | }; | |
6455 | OFP_ASSERT(sizeof(struct ofp_action_header) == 8); | |
6456 | ||
232c1e12 BP |
6457 | /* Header for Nicira-defined actions and for ONF vendor extensions. |
6458 | * | |
6459 | * This cannot be used as an entirely generic vendor extension action header, | |
6460 | * because OpenFlow does not specify the location or size of the action | |
6461 | * subtype; it just happens that ONF extensions and Nicira extensions share | |
6462 | * this format. */ | |
6463 | struct ext_action_header { | |
c2d936a4 BP |
6464 | ovs_be16 type; /* OFPAT_VENDOR. */ |
6465 | ovs_be16 len; /* At least 16. */ | |
232c1e12 | 6466 | ovs_be32 vendor; /* NX_VENDOR_ID or ONF_VENDOR_ID. */ |
c2d936a4 BP |
6467 | ovs_be16 subtype; /* See enum ofp_raw_action_type. */ |
6468 | uint8_t pad[6]; | |
6469 | }; | |
232c1e12 | 6470 | OFP_ASSERT(sizeof(struct ext_action_header) == 16); |
c2d936a4 BP |
6471 | |
6472 | static bool | |
6473 | ofpact_hdrs_equal(const struct ofpact_hdrs *a, | |
6474 | const struct ofpact_hdrs *b) | |
6475 | { | |
6476 | return (a->vendor == b->vendor | |
6477 | && a->type == b->type | |
6478 | && a->ofp_version == b->ofp_version); | |
6479 | } | |
6480 | ||
6481 | static uint32_t | |
6482 | ofpact_hdrs_hash(const struct ofpact_hdrs *hdrs) | |
6483 | { | |
6484 | return hash_2words(hdrs->vendor, (hdrs->type << 16) | hdrs->ofp_version); | |
6485 | } | |
6486 | ||
6487 | #include "ofp-actions.inc2" | |
6488 | ||
6489 | static struct hmap * | |
6490 | ofpact_decode_hmap(void) | |
6491 | { | |
6492 | static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; | |
6493 | static struct hmap hmap; | |
6494 | ||
6495 | if (ovsthread_once_start(&once)) { | |
6496 | struct ofpact_raw_instance *inst; | |
6497 | ||
6498 | hmap_init(&hmap); | |
6499 | for (inst = all_raw_instances; | |
6500 | inst < &all_raw_instances[ARRAY_SIZE(all_raw_instances)]; | |
6501 | inst++) { | |
6502 | hmap_insert(&hmap, &inst->decode_node, | |
6503 | ofpact_hdrs_hash(&inst->hdrs)); | |
6504 | } | |
6505 | ovsthread_once_done(&once); | |
6506 | } | |
6507 | return &hmap; | |
6508 | } | |
6509 | ||
6510 | static struct hmap * | |
6511 | ofpact_encode_hmap(void) | |
6512 | { | |
6513 | static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; | |
6514 | static struct hmap hmap; | |
6515 | ||
6516 | if (ovsthread_once_start(&once)) { | |
6517 | struct ofpact_raw_instance *inst; | |
6518 | ||
6519 | hmap_init(&hmap); | |
6520 | for (inst = all_raw_instances; | |
6521 | inst < &all_raw_instances[ARRAY_SIZE(all_raw_instances)]; | |
6522 | inst++) { | |
6523 | hmap_insert(&hmap, &inst->encode_node, | |
6524 | hash_2words(inst->raw, inst->hdrs.ofp_version)); | |
6525 | } | |
6526 | ovsthread_once_done(&once); | |
6527 | } | |
6528 | return &hmap; | |
6529 | } | |
6530 | ||
6531 | static enum ofperr | |
6532 | ofpact_decode_raw(enum ofp_version ofp_version, | |
6533 | const struct ofp_action_header *oah, size_t length, | |
6534 | const struct ofpact_raw_instance **instp) | |
6535 | { | |
6536 | const struct ofpact_raw_instance *inst; | |
6537 | struct ofpact_hdrs hdrs; | |
6538 | ||
6539 | *instp = NULL; | |
6540 | if (length < sizeof *oah) { | |
6541 | return OFPERR_OFPBAC_BAD_LEN; | |
6542 | } | |
6543 | ||
6544 | /* Get base action type. */ | |
6545 | if (oah->type == htons(OFPAT_VENDOR)) { | |
6546 | /* Get vendor. */ | |
6547 | hdrs.vendor = ntohl(oah->vendor); | |
232c1e12 BP |
6548 | if (hdrs.vendor == NX_VENDOR_ID || hdrs.vendor == ONF_VENDOR_ID) { |
6549 | /* Get extension subtype. */ | |
6550 | const struct ext_action_header *nah; | |
c2d936a4 | 6551 | |
232c1e12 | 6552 | nah = ALIGNED_CAST(const struct ext_action_header *, oah); |
c2d936a4 BP |
6553 | if (length < sizeof *nah) { |
6554 | return OFPERR_OFPBAC_BAD_LEN; | |
6555 | } | |
6556 | hdrs.type = ntohs(nah->subtype); | |
6557 | } else { | |
6558 | VLOG_WARN_RL(&rl, "OpenFlow action has unknown vendor %#"PRIx32, | |
6559 | hdrs.vendor); | |
6560 | return OFPERR_OFPBAC_BAD_VENDOR; | |
6561 | } | |
6562 | } else { | |
6563 | hdrs.vendor = 0; | |
6564 | hdrs.type = ntohs(oah->type); | |
6565 | } | |
6566 | ||
6567 | hdrs.ofp_version = ofp_version; | |
6568 | HMAP_FOR_EACH_WITH_HASH (inst, decode_node, ofpact_hdrs_hash(&hdrs), | |
6569 | ofpact_decode_hmap()) { | |
6570 | if (ofpact_hdrs_equal(&hdrs, &inst->hdrs)) { | |
6571 | *instp = inst; | |
6572 | return 0; | |
6573 | } | |
6574 | } | |
6575 | ||
6576 | return (hdrs.vendor | |
6577 | ? OFPERR_OFPBAC_BAD_VENDOR_TYPE | |
6578 | : OFPERR_OFPBAC_BAD_TYPE); | |
6579 | } | |
6580 | ||
6581 | static enum ofperr | |
6582 | ofpact_pull_raw(struct ofpbuf *buf, enum ofp_version ofp_version, | |
6583 | enum ofp_raw_action_type *raw, uint64_t *arg) | |
6584 | { | |
6fd6ed71 | 6585 | const struct ofp_action_header *oah = buf->data; |
c2d936a4 BP |
6586 | const struct ofpact_raw_instance *action; |
6587 | unsigned int length; | |
6588 | enum ofperr error; | |
6589 | ||
6590 | *raw = *arg = 0; | |
6fd6ed71 | 6591 | error = ofpact_decode_raw(ofp_version, oah, buf->size, &action); |
c2d936a4 BP |
6592 | if (error) { |
6593 | return error; | |
6594 | } | |
6595 | ||
6596 | if (action->deprecation) { | |
6597 | VLOG_INFO_RL(&rl, "%s is deprecated in %s (%s)", | |
6598 | action->name, ofputil_version_to_string(ofp_version), | |
6599 | action->deprecation); | |
6600 | } | |
6601 | ||
6602 | length = ntohs(oah->len); | |
6fd6ed71 | 6603 | if (length > buf->size) { |
b153b990 | 6604 | VLOG_WARN_RL(&rl, "OpenFlow action %s length %u exceeds action buffer " |
6fd6ed71 | 6605 | "length %"PRIu32, action->name, length, buf->size); |
b153b990 BP |
6606 | return OFPERR_OFPBAC_BAD_LEN; |
6607 | } | |
c2d936a4 BP |
6608 | if (length < action->min_length || length > action->max_length) { |
6609 | VLOG_WARN_RL(&rl, "OpenFlow action %s length %u not in valid range " | |
6610 | "[%hu,%hu]", action->name, length, | |
6611 | action->min_length, action->max_length); | |
6612 | return OFPERR_OFPBAC_BAD_LEN; | |
6613 | } | |
6614 | if (length % 8) { | |
6615 | VLOG_WARN_RL(&rl, "OpenFlow action %s length %u is not a multiple " | |
6616 | "of 8", action->name, length); | |
6617 | return OFPERR_OFPBAC_BAD_LEN; | |
6618 | } | |
6619 | ||
6620 | *raw = action->raw; | |
6621 | *arg = 0; | |
6622 | if (action->arg_len) { | |
6623 | const uint8_t *p; | |
6624 | int i; | |
6625 | ||
6626 | p = ofpbuf_at_assert(buf, action->arg_ofs, action->arg_len); | |
6627 | for (i = 0; i < action->arg_len; i++) { | |
6628 | *arg = (*arg << 8) | p[i]; | |
6629 | } | |
6630 | } | |
6631 | ||
6632 | ofpbuf_pull(buf, length); | |
6633 | ||
6634 | return 0; | |
6635 | } | |
6636 | ||
6637 | static const struct ofpact_raw_instance * | |
6638 | ofpact_raw_lookup(enum ofp_version ofp_version, enum ofp_raw_action_type raw) | |
6639 | { | |
6640 | const struct ofpact_raw_instance *inst; | |
6641 | ||
6642 | HMAP_FOR_EACH_WITH_HASH (inst, encode_node, hash_2words(raw, ofp_version), | |
6643 | ofpact_encode_hmap()) { | |
6644 | if (inst->raw == raw && inst->hdrs.ofp_version == ofp_version) { | |
6645 | return inst; | |
6646 | } | |
6647 | } | |
6648 | OVS_NOT_REACHED(); | |
6649 | } | |
6650 | ||
6651 | static void * | |
6652 | ofpact_put_raw(struct ofpbuf *buf, enum ofp_version ofp_version, | |
6653 | enum ofp_raw_action_type raw, uint64_t arg) | |
6654 | { | |
6655 | const struct ofpact_raw_instance *inst; | |
6656 | struct ofp_action_header *oah; | |
6657 | const struct ofpact_hdrs *hdrs; | |
6658 | ||
6659 | inst = ofpact_raw_lookup(ofp_version, raw); | |
6660 | hdrs = &inst->hdrs; | |
6661 | ||
6662 | oah = ofpbuf_put_zeros(buf, inst->min_length); | |
6663 | oah->type = htons(hdrs->vendor ? OFPAT_VENDOR : hdrs->type); | |
6664 | oah->len = htons(inst->min_length); | |
6665 | oah->vendor = htonl(hdrs->vendor); | |
6666 | ||
6667 | switch (hdrs->vendor) { | |
6668 | case 0: | |
6669 | break; | |
6670 | ||
232c1e12 BP |
6671 | case NX_VENDOR_ID: |
6672 | case ONF_VENDOR_ID: { | |
6673 | struct ext_action_header *nah = (struct ext_action_header *) oah; | |
c2d936a4 BP |
6674 | nah->subtype = htons(hdrs->type); |
6675 | break; | |
6676 | } | |
6677 | ||
6678 | default: | |
6679 | OVS_NOT_REACHED(); | |
6680 | } | |
6681 | ||
6682 | if (inst->arg_len) { | |
6683 | uint8_t *p = (uint8_t *) oah + inst->arg_ofs + inst->arg_len; | |
6684 | int i; | |
6685 | ||
6686 | for (i = 0; i < inst->arg_len; i++) { | |
6687 | *--p = arg; | |
6688 | arg >>= 8; | |
6689 | } | |
6690 | } else { | |
6691 | ovs_assert(!arg); | |
6692 | } | |
6693 | ||
6694 | return oah; | |
6695 | } | |
178742f9 BP |
6696 | |
6697 | static void | |
6698 | pad_ofpat(struct ofpbuf *openflow, size_t start_ofs) | |
6699 | { | |
6700 | struct ofp_action_header *oah; | |
6701 | ||
6fd6ed71 | 6702 | ofpbuf_put_zeros(openflow, PAD_SIZE(openflow->size - start_ofs, 8)); |
178742f9 BP |
6703 | |
6704 | oah = ofpbuf_at_assert(openflow, start_ofs, sizeof *oah); | |
6fd6ed71 | 6705 | oah->len = htons(openflow->size - start_ofs); |
178742f9 BP |
6706 | } |
6707 |