2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "ofp-actions.h"
20 #include "byte-order.h"
22 #include "dynamic-string.h"
24 #include "meta-flow.h"
25 #include "multipath.h"
32 VLOG_DEFINE_THIS_MODULE(ofp_actions);
34 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
36 /* Converting OpenFlow 1.0 to ofpacts. */
40 struct ofp_action_header header;
41 struct ofp_action_vendor_header vendor;
42 struct ofp10_action_output output10;
43 struct ofp_action_vlan_vid vlan_vid;
44 struct ofp_action_vlan_pcp vlan_pcp;
45 struct ofp_action_nw_addr nw_addr;
46 struct ofp_action_nw_tos nw_tos;
47 struct ofp11_action_nw_ecn nw_ecn;
48 struct ofp_action_tp_port tp_port;
50 OFP_ASSERT(sizeof(union ofp_action) == 8);
53 output_from_openflow10(const struct ofp10_action_output *oao,
56 struct ofpact_output *output;
58 output = ofpact_put_OUTPUT(out);
59 output->port = u16_to_ofp(ntohs(oao->port));
60 output->max_len = ntohs(oao->max_len);
62 return ofputil_check_output_port(output->port, OFPP_MAX);
66 enqueue_from_openflow10(const struct ofp10_action_enqueue *oae,
69 struct ofpact_enqueue *enqueue;
71 enqueue = ofpact_put_ENQUEUE(out);
72 enqueue->port = u16_to_ofp(ntohs(oae->port));
73 enqueue->queue = ntohl(oae->queue_id);
74 if (ofp_to_u16(enqueue->port) >= ofp_to_u16(OFPP_MAX)
75 && enqueue->port != OFPP_IN_PORT
76 && enqueue->port != OFPP_LOCAL) {
77 return OFPERR_OFPBAC_BAD_OUT_PORT;
83 resubmit_from_openflow(const struct nx_action_resubmit *nar,
86 struct ofpact_resubmit *resubmit;
88 resubmit = ofpact_put_RESUBMIT(out);
89 resubmit->ofpact.compat = OFPUTIL_NXAST_RESUBMIT;
90 resubmit->in_port = u16_to_ofp(ntohs(nar->in_port));
91 resubmit->table_id = 0xff;
95 resubmit_table_from_openflow(const struct nx_action_resubmit *nar,
98 struct ofpact_resubmit *resubmit;
100 if (nar->pad[0] || nar->pad[1] || nar->pad[2]) {
101 return OFPERR_OFPBAC_BAD_ARGUMENT;
104 resubmit = ofpact_put_RESUBMIT(out);
105 resubmit->ofpact.compat = OFPUTIL_NXAST_RESUBMIT_TABLE;
106 resubmit->in_port = u16_to_ofp(ntohs(nar->in_port));
107 resubmit->table_id = nar->table;
112 output_reg_from_openflow(const struct nx_action_output_reg *naor,
115 struct ofpact_output_reg *output_reg;
117 if (!is_all_zeros(naor->zero, sizeof naor->zero)) {
118 return OFPERR_OFPBAC_BAD_ARGUMENT;
121 output_reg = ofpact_put_OUTPUT_REG(out);
122 output_reg->src.field = mf_from_nxm_header(ntohl(naor->src));
123 output_reg->src.ofs = nxm_decode_ofs(naor->ofs_nbits);
124 output_reg->src.n_bits = nxm_decode_n_bits(naor->ofs_nbits);
125 output_reg->max_len = ntohs(naor->max_len);
127 return mf_check_src(&output_reg->src, NULL);
131 fin_timeout_from_openflow(const struct nx_action_fin_timeout *naft,
134 struct ofpact_fin_timeout *oft;
136 oft = ofpact_put_FIN_TIMEOUT(out);
137 oft->fin_idle_timeout = ntohs(naft->fin_idle_timeout);
138 oft->fin_hard_timeout = ntohs(naft->fin_hard_timeout);
142 controller_from_openflow(const struct nx_action_controller *nac,
145 struct ofpact_controller *oc;
147 oc = ofpact_put_CONTROLLER(out);
148 oc->max_len = ntohs(nac->max_len);
149 oc->controller_id = ntohs(nac->controller_id);
150 oc->reason = nac->reason;
154 metadata_from_nxast(const struct nx_action_write_metadata *nawm,
157 struct ofpact_metadata *om;
159 if (!is_all_zeros(nawm->zeros, sizeof nawm->zeros)) {
160 return OFPERR_NXBRC_MUST_BE_ZERO;
163 om = ofpact_put_WRITE_METADATA(out);
164 om->metadata = nawm->metadata;
165 om->mask = nawm->mask;
171 note_from_openflow(const struct nx_action_note *nan, struct ofpbuf *out)
173 struct ofpact_note *note;
176 length = ntohs(nan->len) - offsetof(struct nx_action_note, note);
177 note = ofpact_put(out, OFPACT_NOTE,
178 offsetof(struct ofpact_note, data) + length);
179 note->length = length;
180 memcpy(note->data, nan->note, length);
184 dec_ttl_from_openflow(struct ofpbuf *out, enum ofputil_action_code compat)
187 struct ofpact_cnt_ids *ids;
188 enum ofperr error = 0;
190 ids = ofpact_put_DEC_TTL(out);
191 ids->ofpact.compat = compat;
192 ids->n_controllers = 1;
193 ofpbuf_put(out, &id, sizeof id);
195 ofpact_update_len(out, &ids->ofpact);
200 dec_ttl_cnt_ids_from_openflow(const struct nx_action_cnt_ids *nac_ids,
203 struct ofpact_cnt_ids *ids;
207 ids = ofpact_put_DEC_TTL(out);
208 ids->ofpact.compat = OFPUTIL_NXAST_DEC_TTL_CNT_IDS;
209 ids->n_controllers = ntohs(nac_ids->n_controllers);
210 ids_size = ntohs(nac_ids->len) - sizeof *nac_ids;
212 if (!is_all_zeros(nac_ids->zeros, sizeof nac_ids->zeros)) {
213 return OFPERR_NXBRC_MUST_BE_ZERO;
216 if (ids_size < ids->n_controllers * sizeof(ovs_be16)) {
217 VLOG_WARN_RL(&rl, "Nicira action dec_ttl_cnt_ids only has %zu bytes "
218 "allocated for controller ids. %zu bytes are required for "
219 "%"PRIu16" controllers.", ids_size,
220 ids->n_controllers * sizeof(ovs_be16), ids->n_controllers);
221 return OFPERR_OFPBAC_BAD_LEN;
224 for (i = 0; i < ids->n_controllers; i++) {
225 uint16_t id = ntohs(((ovs_be16 *)(nac_ids + 1))[i]);
226 ofpbuf_put(out, &id, sizeof id);
230 ofpact_update_len(out, &ids->ofpact);
236 sample_from_openflow(const struct nx_action_sample *nas,
239 struct ofpact_sample *sample;
241 sample = ofpact_put_SAMPLE(out);
242 sample->probability = ntohs(nas->probability);
243 sample->collector_set_id = ntohl(nas->collector_set_id);
244 sample->obs_domain_id = ntohl(nas->obs_domain_id);
245 sample->obs_point_id = ntohl(nas->obs_point_id);
247 if (sample->probability == 0) {
248 return OFPERR_OFPBAC_BAD_ARGUMENT;
255 push_mpls_from_openflow(ovs_be16 ethertype, enum ofpact_mpls_position position,
258 struct ofpact_push_mpls *oam;
260 if (!eth_type_mpls(ethertype)) {
261 return OFPERR_OFPBAC_BAD_ARGUMENT;
263 oam = ofpact_put_PUSH_MPLS(out);
264 oam->ethertype = ethertype;
265 oam->position = position;
271 decode_nxast_action(const union ofp_action *a, enum ofputil_action_code *code)
273 const struct nx_action_header *nah = (const struct nx_action_header *) a;
274 uint16_t len = ntohs(a->header.len);
276 if (len < sizeof(struct nx_action_header)) {
277 return OFPERR_OFPBAC_BAD_LEN;
278 } else if (a->vendor.vendor != CONSTANT_HTONL(NX_VENDOR_ID)) {
279 return OFPERR_OFPBAC_BAD_VENDOR;
282 switch (nah->subtype) {
283 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
284 case CONSTANT_HTONS(ENUM): \
286 ? len >= sizeof(struct STRUCT) \
287 : len == sizeof(struct STRUCT)) { \
288 *code = OFPUTIL_##ENUM; \
291 return OFPERR_OFPBAC_BAD_LEN; \
294 #include "ofp-util.def"
296 case CONSTANT_HTONS(NXAST_SNAT__OBSOLETE):
297 case CONSTANT_HTONS(NXAST_DROP_SPOOFED_ARP__OBSOLETE):
299 return OFPERR_OFPBAC_BAD_TYPE;
303 /* Parses 'a' to determine its type. On success stores the correct type into
304 * '*code' and returns 0. On failure returns an OFPERR_* error code and
305 * '*code' is indeterminate.
307 * The caller must have already verified that 'a''s length is potentially
308 * correct (that is, a->header.len is nonzero and a multiple of sizeof(union
309 * ofp_action) and no longer than the amount of space allocated to 'a').
311 * This function verifies that 'a''s length is correct for the type of action
312 * that it represents. */
314 decode_openflow10_action(const union ofp_action *a,
315 enum ofputil_action_code *code)
318 case CONSTANT_HTONS(OFPAT10_VENDOR):
319 return decode_nxast_action(a, code);
321 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
322 case CONSTANT_HTONS(ENUM): \
323 if (a->header.len == htons(sizeof(struct STRUCT))) { \
324 *code = OFPUTIL_##ENUM; \
327 return OFPERR_OFPBAC_BAD_LEN; \
330 #include "ofp-util.def"
333 return OFPERR_OFPBAC_BAD_TYPE;
338 ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code,
341 const struct nx_action_resubmit *nar;
342 const struct nx_action_set_tunnel *nast;
343 const struct nx_action_set_queue *nasq;
344 const struct nx_action_note *nan;
345 const struct nx_action_set_tunnel64 *nast64;
346 const struct nx_action_write_metadata *nawm;
347 struct ofpact_tunnel *tunnel;
348 enum ofperr error = 0;
351 case OFPUTIL_ACTION_INVALID:
352 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) case OFPUTIL_##ENUM:
353 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
354 #include "ofp-util.def"
357 case OFPUTIL_NXAST_RESUBMIT:
358 resubmit_from_openflow((const struct nx_action_resubmit *) a, out);
361 case OFPUTIL_NXAST_SET_TUNNEL:
362 nast = (const struct nx_action_set_tunnel *) a;
363 tunnel = ofpact_put_SET_TUNNEL(out);
364 tunnel->ofpact.compat = code;
365 tunnel->tun_id = ntohl(nast->tun_id);
368 case OFPUTIL_NXAST_WRITE_METADATA:
369 nawm = ALIGNED_CAST(const struct nx_action_write_metadata *, a);
370 error = metadata_from_nxast(nawm, out);
373 case OFPUTIL_NXAST_SET_QUEUE:
374 nasq = (const struct nx_action_set_queue *) a;
375 ofpact_put_SET_QUEUE(out)->queue_id = ntohl(nasq->queue_id);
378 case OFPUTIL_NXAST_POP_QUEUE:
379 ofpact_put_POP_QUEUE(out);
382 case OFPUTIL_NXAST_REG_MOVE:
383 error = nxm_reg_move_from_openflow(
384 (const struct nx_action_reg_move *) a, out);
387 case OFPUTIL_NXAST_REG_LOAD:
388 error = nxm_reg_load_from_openflow(
389 ALIGNED_CAST(const struct nx_action_reg_load *, a), out);
392 case OFPUTIL_NXAST_STACK_PUSH:
393 error = nxm_stack_push_from_openflow(
394 (const struct nx_action_stack *) a, out);
397 case OFPUTIL_NXAST_STACK_POP:
398 error = nxm_stack_pop_from_openflow(
399 (const struct nx_action_stack *) a, out);
402 case OFPUTIL_NXAST_NOTE:
403 nan = (const struct nx_action_note *) a;
404 note_from_openflow(nan, out);
407 case OFPUTIL_NXAST_SET_TUNNEL64:
408 nast64 = ALIGNED_CAST(const struct nx_action_set_tunnel64 *, a);
409 tunnel = ofpact_put_SET_TUNNEL(out);
410 tunnel->ofpact.compat = code;
411 tunnel->tun_id = ntohll(nast64->tun_id);
414 case OFPUTIL_NXAST_MULTIPATH:
415 error = multipath_from_openflow((const struct nx_action_multipath *) a,
416 ofpact_put_MULTIPATH(out));
419 case OFPUTIL_NXAST_BUNDLE:
420 case OFPUTIL_NXAST_BUNDLE_LOAD:
421 error = bundle_from_openflow((const struct nx_action_bundle *) a, out);
424 case OFPUTIL_NXAST_OUTPUT_REG:
425 error = output_reg_from_openflow(
426 (const struct nx_action_output_reg *) a, out);
429 case OFPUTIL_NXAST_RESUBMIT_TABLE:
430 nar = (const struct nx_action_resubmit *) a;
431 error = resubmit_table_from_openflow(nar, out);
434 case OFPUTIL_NXAST_LEARN:
435 error = learn_from_openflow(
436 ALIGNED_CAST(const struct nx_action_learn *, a), out);
439 case OFPUTIL_NXAST_EXIT:
440 ofpact_put_EXIT(out);
443 case OFPUTIL_NXAST_DEC_TTL:
444 error = dec_ttl_from_openflow(out, code);
447 case OFPUTIL_NXAST_DEC_TTL_CNT_IDS:
448 error = dec_ttl_cnt_ids_from_openflow(
449 (const struct nx_action_cnt_ids *) a, out);
452 case OFPUTIL_NXAST_FIN_TIMEOUT:
453 fin_timeout_from_openflow(
454 (const struct nx_action_fin_timeout *) a, out);
457 case OFPUTIL_NXAST_CONTROLLER:
458 controller_from_openflow((const struct nx_action_controller *) a, out);
461 case OFPUTIL_NXAST_PUSH_MPLS: {
462 struct nx_action_push_mpls *nxapm = (struct nx_action_push_mpls *)a;
463 error = push_mpls_from_openflow(nxapm->ethertype,
464 OFPACT_MPLS_AFTER_VLAN, out);
468 case OFPUTIL_NXAST_SET_MPLS_TTL: {
469 struct nx_action_mpls_ttl *nxamt = (struct nx_action_mpls_ttl *)a;
470 ofpact_put_SET_MPLS_TTL(out)->ttl = nxamt->ttl;
474 case OFPUTIL_NXAST_DEC_MPLS_TTL:
475 ofpact_put_DEC_MPLS_TTL(out);
478 case OFPUTIL_NXAST_POP_MPLS: {
479 struct nx_action_pop_mpls *nxapm = (struct nx_action_pop_mpls *)a;
480 if (eth_type_mpls(nxapm->ethertype)) {
481 return OFPERR_OFPBAC_BAD_ARGUMENT;
483 ofpact_put_POP_MPLS(out)->ethertype = nxapm->ethertype;
487 case OFPUTIL_NXAST_SAMPLE:
488 error = sample_from_openflow(
489 (const struct nx_action_sample *) a, out);
497 ofpact_from_openflow10(const union ofp_action *a, struct ofpbuf *out)
499 enum ofputil_action_code code;
502 error = decode_openflow10_action(a, &code);
508 case OFPUTIL_ACTION_INVALID:
509 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
510 #include "ofp-util.def"
513 case OFPUTIL_OFPAT10_OUTPUT:
514 return output_from_openflow10(&a->output10, out);
516 case OFPUTIL_OFPAT10_SET_VLAN_VID:
517 if (a->vlan_vid.vlan_vid & ~htons(0xfff)) {
518 return OFPERR_OFPBAC_BAD_ARGUMENT;
520 ofpact_put_SET_VLAN_VID(out)->vlan_vid = ntohs(a->vlan_vid.vlan_vid);
523 case OFPUTIL_OFPAT10_SET_VLAN_PCP:
524 if (a->vlan_pcp.vlan_pcp & ~7) {
525 return OFPERR_OFPBAC_BAD_ARGUMENT;
527 ofpact_put_SET_VLAN_PCP(out)->vlan_pcp = a->vlan_pcp.vlan_pcp;
530 case OFPUTIL_OFPAT10_STRIP_VLAN:
531 ofpact_put_STRIP_VLAN(out);
534 case OFPUTIL_OFPAT10_SET_DL_SRC:
535 memcpy(ofpact_put_SET_ETH_SRC(out)->mac,
536 ((const struct ofp_action_dl_addr *) a)->dl_addr, ETH_ADDR_LEN);
539 case OFPUTIL_OFPAT10_SET_DL_DST:
540 memcpy(ofpact_put_SET_ETH_DST(out)->mac,
541 ((const struct ofp_action_dl_addr *) a)->dl_addr, ETH_ADDR_LEN);
544 case OFPUTIL_OFPAT10_SET_NW_SRC:
545 ofpact_put_SET_IPV4_SRC(out)->ipv4 = a->nw_addr.nw_addr;
548 case OFPUTIL_OFPAT10_SET_NW_DST:
549 ofpact_put_SET_IPV4_DST(out)->ipv4 = a->nw_addr.nw_addr;
552 case OFPUTIL_OFPAT10_SET_NW_TOS:
553 if (a->nw_tos.nw_tos & ~IP_DSCP_MASK) {
554 return OFPERR_OFPBAC_BAD_ARGUMENT;
556 ofpact_put_SET_IP_DSCP(out)->dscp = a->nw_tos.nw_tos;
559 case OFPUTIL_OFPAT10_SET_TP_SRC:
560 ofpact_put_SET_L4_SRC_PORT(out)->port = ntohs(a->tp_port.tp_port);
563 case OFPUTIL_OFPAT10_SET_TP_DST:
564 ofpact_put_SET_L4_DST_PORT(out)->port = ntohs(a->tp_port.tp_port);
568 case OFPUTIL_OFPAT10_ENQUEUE:
569 error = enqueue_from_openflow10((const struct ofp10_action_enqueue *) a,
573 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
574 #include "ofp-util.def"
575 return ofpact_from_nxast(a, code, out);
581 static inline union ofp_action *
582 action_next(const union ofp_action *a)
584 return ((union ofp_action *) (void *)
585 ((uint8_t *) a + ntohs(a->header.len)));
589 action_is_valid(const union ofp_action *a, size_t n_actions)
591 uint16_t len = ntohs(a->header.len);
592 return (!(len % OFP_ACTION_ALIGN)
594 && len / sizeof *a <= n_actions);
597 /* This macro is careful to check for actions with bad lengths. */
598 #define ACTION_FOR_EACH(ITER, LEFT, ACTIONS, N_ACTIONS) \
599 for ((ITER) = (ACTIONS), (LEFT) = (N_ACTIONS); \
600 (LEFT) > 0 && action_is_valid(ITER, LEFT); \
601 ((LEFT) -= ntohs((ITER)->header.len) / sizeof(union ofp_action), \
602 (ITER) = action_next(ITER)))
605 log_bad_action(const union ofp_action *actions, size_t n_actions, size_t ofs,
608 if (!VLOG_DROP_WARN(&rl)) {
612 ds_put_hex_dump(&s, actions, n_actions * sizeof *actions, 0, false);
613 VLOG_WARN("bad action at offset %#zx (%s):\n%s",
614 ofs * sizeof *actions, ofperr_get_name(error), ds_cstr(&s));
620 ofpacts_from_openflow(const union ofp_action *in, size_t n_in,
622 enum ofperr (*ofpact_from_openflow)(
623 const union ofp_action *a, struct ofpbuf *out))
625 const union ofp_action *a;
628 ACTION_FOR_EACH (a, left, in, n_in) {
629 enum ofperr error = ofpact_from_openflow(a, out);
631 log_bad_action(in, n_in, a - in, error);
636 enum ofperr error = OFPERR_OFPBAC_BAD_LEN;
637 log_bad_action(in, n_in, n_in - left, error);
646 ofpacts_from_openflow10(const union ofp_action *in, size_t n_in,
649 return ofpacts_from_openflow(in, n_in, out, ofpact_from_openflow10);
653 ofpacts_pull_actions(struct ofpbuf *openflow, unsigned int actions_len,
654 struct ofpbuf *ofpacts,
655 enum ofperr (*translate)(const union ofp_action *actions,
657 struct ofpbuf *ofpacts))
659 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
660 const union ofp_action *actions;
663 ofpbuf_clear(ofpacts);
665 if (actions_len % OFP_ACTION_ALIGN != 0) {
666 VLOG_WARN_RL(&rl, "OpenFlow message actions length %u is not a "
667 "multiple of %d", actions_len, OFP_ACTION_ALIGN);
668 return OFPERR_OFPBRC_BAD_LEN;
671 actions = ofpbuf_try_pull(openflow, actions_len);
672 if (actions == NULL) {
673 VLOG_WARN_RL(&rl, "OpenFlow message actions length %u exceeds "
674 "remaining message length (%zu)",
675 actions_len, openflow->size);
676 return OFPERR_OFPBRC_BAD_LEN;
679 error = translate(actions, actions_len / OFP_ACTION_ALIGN, ofpacts);
681 ofpbuf_clear(ofpacts);
685 error = ofpacts_verify(ofpacts->data, ofpacts->size);
687 ofpbuf_clear(ofpacts);
692 /* Attempts to convert 'actions_len' bytes of OpenFlow 1.0 actions from the
693 * front of 'openflow' into ofpacts. On success, replaces any existing content
694 * in 'ofpacts' by the converted ofpacts; on failure, clears 'ofpacts'.
695 * Returns 0 if successful, otherwise an OpenFlow error.
697 * The parsed actions are valid generically, but they may not be valid in a
698 * specific context. For example, port numbers up to OFPP_MAX are valid
699 * generically, but specific datapaths may only support port numbers in a
700 * smaller range. Use ofpacts_check() to additional check whether actions are
701 * valid in a specific context. */
703 ofpacts_pull_openflow10(struct ofpbuf *openflow, unsigned int actions_len,
704 struct ofpbuf *ofpacts)
706 return ofpacts_pull_actions(openflow, actions_len, ofpacts,
707 ofpacts_from_openflow10);
710 /* OpenFlow 1.1 actions. */
712 /* Parses 'a' to determine its type. On success stores the correct type into
713 * '*code' and returns 0. On failure returns an OFPERR_* error code and
714 * '*code' is indeterminate.
716 * The caller must have already verified that 'a''s length is potentially
717 * correct (that is, a->header.len is nonzero and a multiple of sizeof(union
718 * ofp_action) and no longer than the amount of space allocated to 'a').
720 * This function verifies that 'a''s length is correct for the type of action
721 * that it represents. */
723 decode_openflow11_action(const union ofp_action *a,
724 enum ofputil_action_code *code)
729 case CONSTANT_HTONS(OFPAT11_EXPERIMENTER):
730 return decode_nxast_action(a, code);
732 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
733 case CONSTANT_HTONS(ENUM): \
734 len = ntohs(a->header.len); \
736 ? len >= sizeof(struct STRUCT) \
737 : len == sizeof(struct STRUCT)) { \
738 *code = OFPUTIL_##ENUM; \
741 return OFPERR_OFPBAC_BAD_LEN; \
744 #include "ofp-util.def"
747 return OFPERR_OFPBAC_BAD_TYPE;
752 output_from_openflow11(const struct ofp11_action_output *oao,
755 struct ofpact_output *output;
758 output = ofpact_put_OUTPUT(out);
759 output->max_len = ntohs(oao->max_len);
761 error = ofputil_port_from_ofp11(oao->port, &output->port);
766 return ofputil_check_output_port(output->port, OFPP_MAX);
770 ofpact_from_openflow11(const union ofp_action *a, struct ofpbuf *out)
772 enum ofputil_action_code code;
775 error = decode_openflow11_action(a, &code);
781 case OFPUTIL_ACTION_INVALID:
782 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) case OFPUTIL_##ENUM:
783 #include "ofp-util.def"
786 case OFPUTIL_OFPAT11_OUTPUT:
787 return output_from_openflow11((const struct ofp11_action_output *) a,
790 case OFPUTIL_OFPAT11_SET_VLAN_VID:
791 if (a->vlan_vid.vlan_vid & ~htons(0xfff)) {
792 return OFPERR_OFPBAC_BAD_ARGUMENT;
794 ofpact_put_SET_VLAN_VID(out)->vlan_vid = ntohs(a->vlan_vid.vlan_vid);
797 case OFPUTIL_OFPAT11_SET_VLAN_PCP:
798 if (a->vlan_pcp.vlan_pcp & ~7) {
799 return OFPERR_OFPBAC_BAD_ARGUMENT;
801 ofpact_put_SET_VLAN_PCP(out)->vlan_pcp = a->vlan_pcp.vlan_pcp;
804 case OFPUTIL_OFPAT11_PUSH_VLAN:
805 if (((const struct ofp11_action_push *)a)->ethertype !=
806 htons(ETH_TYPE_VLAN_8021Q)) {
807 /* XXX 802.1AD(QinQ) isn't supported at the moment */
808 return OFPERR_OFPBAC_BAD_ARGUMENT;
810 ofpact_put_PUSH_VLAN(out);
813 case OFPUTIL_OFPAT11_POP_VLAN:
814 ofpact_put_STRIP_VLAN(out);
817 case OFPUTIL_OFPAT11_SET_QUEUE:
818 ofpact_put_SET_QUEUE(out)->queue_id =
819 ntohl(((const struct ofp11_action_set_queue *)a)->queue_id);
822 case OFPUTIL_OFPAT11_SET_DL_SRC:
823 memcpy(ofpact_put_SET_ETH_SRC(out)->mac,
824 ((const struct ofp_action_dl_addr *) a)->dl_addr, ETH_ADDR_LEN);
827 case OFPUTIL_OFPAT11_SET_DL_DST:
828 memcpy(ofpact_put_SET_ETH_DST(out)->mac,
829 ((const struct ofp_action_dl_addr *) a)->dl_addr, ETH_ADDR_LEN);
832 case OFPUTIL_OFPAT11_DEC_NW_TTL:
833 dec_ttl_from_openflow(out, code);
836 case OFPUTIL_OFPAT11_SET_NW_SRC:
837 ofpact_put_SET_IPV4_SRC(out)->ipv4 = a->nw_addr.nw_addr;
840 case OFPUTIL_OFPAT11_SET_NW_DST:
841 ofpact_put_SET_IPV4_DST(out)->ipv4 = a->nw_addr.nw_addr;
844 case OFPUTIL_OFPAT11_SET_NW_TOS:
845 if (a->nw_tos.nw_tos & ~IP_DSCP_MASK) {
846 return OFPERR_OFPBAC_BAD_ARGUMENT;
848 ofpact_put_SET_IP_DSCP(out)->dscp = a->nw_tos.nw_tos;
851 case OFPUTIL_OFPAT11_SET_NW_ECN:
852 if (a->nw_ecn.nw_ecn & ~IP_ECN_MASK) {
853 return OFPERR_OFPBAC_BAD_ARGUMENT;
855 ofpact_put_SET_IP_ECN(out)->ecn = a->nw_ecn.nw_ecn;
858 case OFPUTIL_OFPAT11_SET_TP_SRC:
859 ofpact_put_SET_L4_SRC_PORT(out)->port = ntohs(a->tp_port.tp_port);
862 case OFPUTIL_OFPAT11_SET_TP_DST:
863 ofpact_put_SET_L4_DST_PORT(out)->port = ntohs(a->tp_port.tp_port);
866 case OFPUTIL_OFPAT12_SET_FIELD:
867 return nxm_reg_load_from_openflow12_set_field(
868 (const struct ofp12_action_set_field *)a, out);
870 case OFPUTIL_OFPAT11_SET_MPLS_TTL: {
871 struct ofp11_action_mpls_ttl *oamt = (struct ofp11_action_mpls_ttl *)a;
872 ofpact_put_SET_MPLS_TTL(out)->ttl = oamt->mpls_ttl;
876 case OFPUTIL_OFPAT11_DEC_MPLS_TTL:
877 ofpact_put_DEC_MPLS_TTL(out);
880 case OFPUTIL_OFPAT11_PUSH_MPLS: {
881 struct ofp11_action_push *oap = (struct ofp11_action_push *)a;
882 error = push_mpls_from_openflow(oap->ethertype,
883 OFPACT_MPLS_AFTER_VLAN, out);
887 case OFPUTIL_OFPAT11_POP_MPLS: {
888 struct ofp11_action_pop_mpls *oapm = (struct ofp11_action_pop_mpls *)a;
889 if (eth_type_mpls(oapm->ethertype)) {
890 return OFPERR_OFPBAC_BAD_ARGUMENT;
892 ofpact_put_POP_MPLS(out)->ethertype = oapm->ethertype;
896 case OFPUTIL_OFPAT11_GROUP: {
897 struct ofp11_action_group *oag = (struct ofp11_action_group *)a;
898 ofpact_put_GROUP(out)->group_id = ntohl(oag->group_id);
902 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
903 #include "ofp-util.def"
904 return ofpact_from_nxast(a, code, out);
911 ofpacts_from_openflow11(const union ofp_action *in, size_t n_in,
914 return ofpacts_from_openflow(in, n_in, out, ofpact_from_openflow11);
917 /* True if an action sets the value of a field
918 * in a way that is compatibile with the action set.
919 * False otherwise. */
921 ofpact_is_set_action(const struct ofpact *a)
924 case OFPACT_REG_LOAD:
925 case OFPACT_SET_ETH_DST:
926 case OFPACT_SET_ETH_SRC:
927 case OFPACT_SET_IP_DSCP:
928 case OFPACT_SET_IP_ECN:
929 case OFPACT_SET_IPV4_DST:
930 case OFPACT_SET_IPV4_SRC:
931 case OFPACT_SET_L4_DST_PORT:
932 case OFPACT_SET_L4_SRC_PORT:
933 case OFPACT_SET_MPLS_TTL:
934 case OFPACT_SET_QUEUE:
935 case OFPACT_SET_TUNNEL:
936 case OFPACT_SET_VLAN_PCP:
937 case OFPACT_SET_VLAN_VID:
940 case OFPACT_CLEAR_ACTIONS:
941 case OFPACT_CONTROLLER:
942 case OFPACT_DEC_MPLS_TTL:
946 case OFPACT_FIN_TIMEOUT:
947 case OFPACT_GOTO_TABLE:
951 case OFPACT_MULTIPATH:
954 case OFPACT_OUTPUT_REG:
955 case OFPACT_POP_MPLS:
956 case OFPACT_POP_QUEUE:
957 case OFPACT_PUSH_MPLS:
958 case OFPACT_PUSH_VLAN:
959 case OFPACT_REG_MOVE:
960 case OFPACT_RESUBMIT:
962 case OFPACT_STACK_POP:
963 case OFPACT_STACK_PUSH:
964 case OFPACT_STRIP_VLAN:
965 case OFPACT_WRITE_ACTIONS:
966 case OFPACT_WRITE_METADATA:
973 /* True if an action is allowed in the action set.
974 * False otherwise. */
976 ofpact_is_allowed_in_actions_set(const struct ofpact *a)
979 case OFPACT_DEC_MPLS_TTL:
983 case OFPACT_POP_MPLS:
984 case OFPACT_PUSH_MPLS:
985 case OFPACT_PUSH_VLAN:
986 case OFPACT_REG_LOAD:
987 case OFPACT_SET_ETH_DST:
988 case OFPACT_SET_ETH_SRC:
989 case OFPACT_SET_IP_DSCP:
990 case OFPACT_SET_IP_ECN:
991 case OFPACT_SET_IPV4_DST:
992 case OFPACT_SET_IPV4_SRC:
993 case OFPACT_SET_L4_DST_PORT:
994 case OFPACT_SET_L4_SRC_PORT:
995 case OFPACT_SET_MPLS_TTL:
996 case OFPACT_SET_QUEUE:
997 case OFPACT_SET_TUNNEL:
998 case OFPACT_SET_VLAN_PCP:
999 case OFPACT_SET_VLAN_VID:
1000 case OFPACT_STRIP_VLAN:
1003 /* In general these actions are excluded because they are not part of
1004 * the OpenFlow specification nor map to actions that are defined in
1005 * the specification. Thus the order in which they should be applied
1006 * in the action set is undefined. */
1008 case OFPACT_CONTROLLER:
1009 case OFPACT_ENQUEUE:
1011 case OFPACT_FIN_TIMEOUT:
1013 case OFPACT_MULTIPATH:
1015 case OFPACT_OUTPUT_REG:
1016 case OFPACT_POP_QUEUE:
1017 case OFPACT_REG_MOVE:
1018 case OFPACT_RESUBMIT:
1020 case OFPACT_STACK_POP:
1021 case OFPACT_STACK_PUSH:
1023 /* The action set may only include actions and thus
1024 * may not include any instructions */
1025 case OFPACT_CLEAR_ACTIONS:
1026 case OFPACT_GOTO_TABLE:
1028 case OFPACT_WRITE_ACTIONS:
1029 case OFPACT_WRITE_METADATA:
1036 /* Append ofpact 'a' onto the tail of 'out' */
1038 ofpact_copy(struct ofpbuf *out, const struct ofpact *a)
1040 ofpbuf_put(out, a, OFPACT_ALIGN(a->len));
1043 /* Copies the last ofpact whose type is 'filter' from 'in' to 'out'. */
1045 ofpacts_copy_last(struct ofpbuf *out, const struct ofpbuf *in,
1046 enum ofpact_type filter)
1048 const struct ofpact *target;
1049 const struct ofpact *a;
1052 OFPACT_FOR_EACH (a, in->data, in->size) {
1053 if (a->type == filter) {
1058 ofpact_copy(out, target);
1060 return target != NULL;
1063 /* Append all ofpacts, for which 'filter' returns true, from 'in' to 'out'.
1064 * The order of appended ofpacts is preserved between 'in' and 'out' */
1066 ofpacts_copy_all(struct ofpbuf *out, const struct ofpbuf *in,
1067 bool (*filter)(const struct ofpact *))
1069 const struct ofpact *a;
1071 OFPACT_FOR_EACH (a, in->data, in->size) {
1073 ofpact_copy(out, a);
1078 /* Reads 'action_set', which contains ofpacts accumulated by
1079 * OFPACT_WRITE_ACTIONS instructions, and writes equivalent actions to be
1080 * executed directly into 'action_list'. (These names correspond to the
1081 * "Action Set" and "Action List" terms used in OpenFlow 1.1+.)
1083 * In general this involves appending the last instance of each action that is
1084 * adimissible in the action set in the order described in the OpenFlow
1088 * + output action is only appended if no group action was present in 'in'.
1089 * + As a simplification all set actions are copied in the order the are
1090 * provided in 'in' as many set actions applied to a field has the same
1091 * affect as only applying the last action that sets a field and
1092 * duplicates are removed by do_xlate_actions().
1093 * This has an unwanted side-effect of compsoting multiple
1094 * LOAD_REG actions that touch different regions of the same field. */
1096 ofpacts_execute_action_set(struct ofpbuf *action_list,
1097 const struct ofpbuf *action_set)
1099 /* The OpenFlow spec "Action Set" section specifies this order. */
1100 ofpacts_copy_last(action_list, action_set, OFPACT_STRIP_VLAN);
1101 ofpacts_copy_last(action_list, action_set, OFPACT_POP_MPLS);
1102 ofpacts_copy_last(action_list, action_set, OFPACT_PUSH_MPLS);
1103 ofpacts_copy_last(action_list, action_set, OFPACT_PUSH_VLAN);
1104 ofpacts_copy_last(action_list, action_set, OFPACT_DEC_TTL);
1105 ofpacts_copy_last(action_list, action_set, OFPACT_DEC_MPLS_TTL);
1106 ofpacts_copy_all(action_list, action_set, ofpact_is_set_action);
1107 ofpacts_copy_last(action_list, action_set, OFPACT_SET_QUEUE);
1109 /* If both OFPACT_GROUP and OFPACT_OUTPUT are present, OpenFlow says that
1110 * we should execute only OFPACT_GROUP.
1112 * If neither OFPACT_GROUP nor OFPACT_OUTPUT is present, then we can drop
1113 * all the actions because there's no point in modifying a packet that will
1114 * not be sent anywhere. */
1115 if (!ofpacts_copy_last(action_list, action_set, OFPACT_GROUP) &&
1116 !ofpacts_copy_last(action_list, action_set, OFPACT_OUTPUT)) {
1117 ofpbuf_clear(action_list);
1123 ofpacts_from_openflow11_for_action_set(const union ofp_action *in,
1124 size_t n_in, struct ofpbuf *out)
1128 size_t start = out->size;
1130 error = ofpacts_from_openflow11(in, n_in, out);
1135 OFPACT_FOR_EACH (a, ofpact_end(out->data, start), out->size - start) {
1136 if (!ofpact_is_allowed_in_actions_set(a)) {
1137 VLOG_WARN_RL(&rl, "disallowed action in action set");
1138 return OFPERR_OFPBAC_BAD_TYPE;
1147 ofpact_from_openflow13(const union ofp_action *a, struct ofpbuf *out)
1149 enum ofputil_action_code code;
1152 error = decode_openflow11_action(a, &code);
1157 if (code == OFPUTIL_OFPAT11_PUSH_MPLS) {
1158 struct ofp11_action_push *oap = (struct ofp11_action_push *)a;
1159 error = push_mpls_from_openflow(oap->ethertype,
1160 OFPACT_MPLS_BEFORE_VLAN, out);
1162 error = ofpact_from_openflow11(a, out);
1169 ofpacts_from_openflow13(const union ofp_action *in, size_t n_in,
1172 return ofpacts_from_openflow(in, n_in, out, ofpact_from_openflow13);
1175 /* OpenFlow 1.1 instructions. */
1177 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \
1178 static inline const struct STRUCT * OVS_UNUSED \
1179 instruction_get_##ENUM(const struct ofp11_instruction *inst)\
1181 ovs_assert(inst->type == htons(ENUM)); \
1182 return ALIGNED_CAST(struct STRUCT *, inst); \
1185 static inline void OVS_UNUSED \
1186 instruction_init_##ENUM(struct STRUCT *s) \
1188 memset(s, 0, sizeof *s); \
1189 s->type = htons(ENUM); \
1190 s->len = htons(sizeof *s); \
1193 static inline struct STRUCT * OVS_UNUSED \
1194 instruction_put_##ENUM(struct ofpbuf *buf) \
1196 struct STRUCT *s = ofpbuf_put_uninit(buf, sizeof *s); \
1197 instruction_init_##ENUM(s); \
1203 struct instruction_type_info {
1204 enum ovs_instruction_type type;
1208 static const struct instruction_type_info inst_info[] = {
1209 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) {OVSINST_##ENUM, NAME},
1215 ovs_instruction_name_from_type(enum ovs_instruction_type type)
1217 return inst_info[type].name;
1221 ovs_instruction_type_from_name(const char *name)
1223 const struct instruction_type_info *p;
1224 for (p = inst_info; p < &inst_info[ARRAY_SIZE(inst_info)]; p++) {
1225 if (!strcasecmp(name, p->name)) {
1232 enum ovs_instruction_type
1233 ovs_instruction_type_from_ofpact_type(enum ofpact_type type)
1237 return OVSINST_OFPIT13_METER;
1238 case OFPACT_CLEAR_ACTIONS:
1239 return OVSINST_OFPIT11_CLEAR_ACTIONS;
1240 case OFPACT_WRITE_ACTIONS:
1241 return OVSINST_OFPIT11_WRITE_ACTIONS;
1242 case OFPACT_WRITE_METADATA:
1243 return OVSINST_OFPIT11_WRITE_METADATA;
1244 case OFPACT_GOTO_TABLE:
1245 return OVSINST_OFPIT11_GOTO_TABLE;
1248 case OFPACT_CONTROLLER:
1249 case OFPACT_ENQUEUE:
1250 case OFPACT_OUTPUT_REG:
1252 case OFPACT_SET_VLAN_VID:
1253 case OFPACT_SET_VLAN_PCP:
1254 case OFPACT_STRIP_VLAN:
1255 case OFPACT_PUSH_VLAN:
1256 case OFPACT_SET_ETH_SRC:
1257 case OFPACT_SET_ETH_DST:
1258 case OFPACT_SET_IPV4_SRC:
1259 case OFPACT_SET_IPV4_DST:
1260 case OFPACT_SET_IP_DSCP:
1261 case OFPACT_SET_IP_ECN:
1262 case OFPACT_SET_L4_SRC_PORT:
1263 case OFPACT_SET_L4_DST_PORT:
1264 case OFPACT_REG_MOVE:
1265 case OFPACT_REG_LOAD:
1266 case OFPACT_STACK_PUSH:
1267 case OFPACT_STACK_POP:
1268 case OFPACT_DEC_TTL:
1269 case OFPACT_SET_MPLS_TTL:
1270 case OFPACT_DEC_MPLS_TTL:
1271 case OFPACT_PUSH_MPLS:
1272 case OFPACT_POP_MPLS:
1273 case OFPACT_SET_TUNNEL:
1274 case OFPACT_SET_QUEUE:
1275 case OFPACT_POP_QUEUE:
1276 case OFPACT_FIN_TIMEOUT:
1277 case OFPACT_RESUBMIT:
1279 case OFPACT_MULTIPATH:
1284 return OVSINST_OFPIT11_APPLY_ACTIONS;
1288 static inline struct ofp11_instruction *
1289 instruction_next(const struct ofp11_instruction *inst)
1291 return ((struct ofp11_instruction *) (void *)
1292 ((uint8_t *) inst + ntohs(inst->len)));
1296 instruction_is_valid(const struct ofp11_instruction *inst,
1297 size_t n_instructions)
1299 uint16_t len = ntohs(inst->len);
1300 return (!(len % OFP11_INSTRUCTION_ALIGN)
1301 && len >= sizeof *inst
1302 && len / sizeof *inst <= n_instructions);
1305 /* This macro is careful to check for instructions with bad lengths. */
1306 #define INSTRUCTION_FOR_EACH(ITER, LEFT, INSTRUCTIONS, N_INSTRUCTIONS) \
1307 for ((ITER) = (INSTRUCTIONS), (LEFT) = (N_INSTRUCTIONS); \
1308 (LEFT) > 0 && instruction_is_valid(ITER, LEFT); \
1309 ((LEFT) -= (ntohs((ITER)->len) \
1310 / sizeof(struct ofp11_instruction)), \
1311 (ITER) = instruction_next(ITER)))
1314 decode_openflow11_instruction(const struct ofp11_instruction *inst,
1315 enum ovs_instruction_type *type)
1317 uint16_t len = ntohs(inst->len);
1319 switch (inst->type) {
1320 case CONSTANT_HTONS(OFPIT11_EXPERIMENTER):
1321 return OFPERR_OFPBIC_BAD_EXPERIMENTER;
1323 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \
1324 case CONSTANT_HTONS(ENUM): \
1326 ? len >= sizeof(struct STRUCT) \
1327 : len == sizeof(struct STRUCT)) { \
1328 *type = OVSINST_##ENUM; \
1331 return OFPERR_OFPBIC_BAD_LEN; \
1337 return OFPERR_OFPBIC_UNKNOWN_INST;
1342 decode_openflow11_instructions(const struct ofp11_instruction insts[],
1344 const struct ofp11_instruction *out[])
1346 const struct ofp11_instruction *inst;
1349 memset(out, 0, N_OVS_INSTRUCTIONS * sizeof *out);
1350 INSTRUCTION_FOR_EACH (inst, left, insts, n_insts) {
1351 enum ovs_instruction_type type;
1354 error = decode_openflow11_instruction(inst, &type);
1360 return OFPERR_ONFBIC_DUP_INSTRUCTION;
1366 VLOG_WARN_RL(&rl, "bad instruction format at offset %zu",
1367 (n_insts - left) * sizeof *inst);
1368 return OFPERR_OFPBIC_BAD_LEN;
1374 get_actions_from_instruction(const struct ofp11_instruction *inst,
1375 const union ofp_action **actions,
1378 *actions = ALIGNED_CAST(const union ofp_action *, inst + 1);
1379 *n_actions = (ntohs(inst->len) - sizeof *inst) / OFP11_INSTRUCTION_ALIGN;
1382 /* Attempts to convert 'actions_len' bytes of OpenFlow actions from the
1383 * front of 'openflow' into ofpacts. On success, replaces any existing content
1384 * in 'ofpacts' by the converted ofpacts; on failure, clears 'ofpacts'.
1385 * Returns 0 if successful, otherwise an OpenFlow error.
1387 * Actions are processed according to their OpenFlow version which
1388 * is provided in the 'version' parameter.
1390 * In most places in OpenFlow 1.1 and 1.2, actions appear encapsulated in
1391 * instructions, so you should call ofpacts_pull_openflow11_instructions()
1392 * instead of this function.
1394 * The parsed actions are valid generically, but they may not be valid in a
1395 * specific context. For example, port numbers up to OFPP_MAX are valid
1396 * generically, but specific datapaths may only support port numbers in a
1397 * smaller range. Use ofpacts_check() to additional check whether actions are
1398 * valid in a specific context. */
1400 ofpacts_pull_openflow11_actions(struct ofpbuf *openflow,
1401 enum ofp_version version,
1402 unsigned int actions_len,
1403 struct ofpbuf *ofpacts)
1409 return ofpacts_pull_actions(openflow, actions_len, ofpacts,
1410 ofpacts_from_openflow11);
1412 return ofpacts_pull_actions(openflow, actions_len, ofpacts,
1413 ofpacts_from_openflow13);
1420 ofpacts_pull_openflow11_instructions(struct ofpbuf *openflow,
1421 enum ofp_version version,
1422 unsigned int instructions_len,
1423 struct ofpbuf *ofpacts)
1425 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1426 const struct ofp11_instruction *instructions;
1427 const struct ofp11_instruction *insts[N_OVS_INSTRUCTIONS];
1430 ofpbuf_clear(ofpacts);
1432 if (instructions_len % OFP11_INSTRUCTION_ALIGN != 0) {
1433 VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u is not a "
1435 instructions_len, OFP11_INSTRUCTION_ALIGN);
1436 error = OFPERR_OFPBIC_BAD_LEN;
1440 instructions = ofpbuf_try_pull(openflow, instructions_len);
1441 if (instructions == NULL) {
1442 VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u exceeds "
1443 "remaining message length (%zu)",
1444 instructions_len, openflow->size);
1445 error = OFPERR_OFPBIC_BAD_LEN;
1449 error = decode_openflow11_instructions(
1450 instructions, instructions_len / OFP11_INSTRUCTION_ALIGN,
1456 if (insts[OVSINST_OFPIT13_METER]) {
1457 const struct ofp13_instruction_meter *oim;
1458 struct ofpact_meter *om;
1460 oim = ALIGNED_CAST(const struct ofp13_instruction_meter *,
1461 insts[OVSINST_OFPIT13_METER]);
1463 om = ofpact_put_METER(ofpacts);
1464 om->meter_id = ntohl(oim->meter_id);
1466 if (insts[OVSINST_OFPIT11_APPLY_ACTIONS]) {
1467 const union ofp_action *actions;
1470 get_actions_from_instruction(insts[OVSINST_OFPIT11_APPLY_ACTIONS],
1471 &actions, &n_actions);
1476 error = ofpacts_from_openflow11(actions, n_actions, ofpacts);
1479 error = ofpacts_from_openflow13(actions, n_actions, ofpacts);
1488 if (insts[OVSINST_OFPIT11_CLEAR_ACTIONS]) {
1489 instruction_get_OFPIT11_CLEAR_ACTIONS(
1490 insts[OVSINST_OFPIT11_CLEAR_ACTIONS]);
1491 ofpact_put_CLEAR_ACTIONS(ofpacts);
1493 if (insts[OVSINST_OFPIT11_WRITE_ACTIONS]) {
1494 struct ofpact_nest *on;
1495 const union ofp_action *actions;
1499 ofpact_pad(ofpacts);
1500 start = ofpacts->size;
1501 on = ofpact_put(ofpacts, OFPACT_WRITE_ACTIONS,
1502 offsetof(struct ofpact_nest, actions));
1503 get_actions_from_instruction(insts[OVSINST_OFPIT11_WRITE_ACTIONS],
1504 &actions, &n_actions);
1505 error = ofpacts_from_openflow11_for_action_set(actions, n_actions,
1510 on = ofpbuf_at_assert(ofpacts, start, sizeof *on);
1511 on->ofpact.len = ofpacts->size - start;
1513 if (insts[OVSINST_OFPIT11_WRITE_METADATA]) {
1514 const struct ofp11_instruction_write_metadata *oiwm;
1515 struct ofpact_metadata *om;
1517 oiwm = ALIGNED_CAST(const struct ofp11_instruction_write_metadata *,
1518 insts[OVSINST_OFPIT11_WRITE_METADATA]);
1520 om = ofpact_put_WRITE_METADATA(ofpacts);
1521 om->metadata = oiwm->metadata;
1522 om->mask = oiwm->metadata_mask;
1524 if (insts[OVSINST_OFPIT11_GOTO_TABLE]) {
1525 const struct ofp11_instruction_goto_table *oigt;
1526 struct ofpact_goto_table *ogt;
1528 oigt = instruction_get_OFPIT11_GOTO_TABLE(
1529 insts[OVSINST_OFPIT11_GOTO_TABLE]);
1530 ogt = ofpact_put_GOTO_TABLE(ofpacts);
1531 ogt->table_id = oigt->table_id;
1534 error = ofpacts_verify(ofpacts->data, ofpacts->size);
1537 ofpbuf_clear(ofpacts);
1542 /* May modify flow->dl_type, caller must restore it. */
1544 ofpact_check__(const struct ofpact *a, struct flow *flow, ofp_port_t max_ports,
1547 const struct ofpact_enqueue *enqueue;
1551 return ofputil_check_output_port(ofpact_get_OUTPUT(a)->port,
1554 case OFPACT_CONTROLLER:
1557 case OFPACT_ENQUEUE:
1558 enqueue = ofpact_get_ENQUEUE(a);
1559 if (ofp_to_u16(enqueue->port) >= ofp_to_u16(max_ports)
1560 && enqueue->port != OFPP_IN_PORT
1561 && enqueue->port != OFPP_LOCAL) {
1562 return OFPERR_OFPBAC_BAD_OUT_PORT;
1566 case OFPACT_OUTPUT_REG:
1567 return mf_check_src(&ofpact_get_OUTPUT_REG(a)->src, flow);
1570 return bundle_check(ofpact_get_BUNDLE(a), max_ports, flow);
1572 case OFPACT_SET_VLAN_VID:
1573 case OFPACT_SET_VLAN_PCP:
1574 case OFPACT_STRIP_VLAN:
1575 case OFPACT_PUSH_VLAN:
1576 case OFPACT_SET_ETH_SRC:
1577 case OFPACT_SET_ETH_DST:
1578 case OFPACT_SET_IPV4_SRC:
1579 case OFPACT_SET_IPV4_DST:
1580 case OFPACT_SET_IP_DSCP:
1581 case OFPACT_SET_IP_ECN:
1582 case OFPACT_SET_L4_SRC_PORT:
1583 case OFPACT_SET_L4_DST_PORT:
1586 case OFPACT_REG_MOVE:
1587 return nxm_reg_move_check(ofpact_get_REG_MOVE(a), flow);
1589 case OFPACT_REG_LOAD:
1590 return nxm_reg_load_check(ofpact_get_REG_LOAD(a), flow);
1592 case OFPACT_STACK_PUSH:
1593 return nxm_stack_push_check(ofpact_get_STACK_PUSH(a), flow);
1595 case OFPACT_STACK_POP:
1596 return nxm_stack_pop_check(ofpact_get_STACK_POP(a), flow);
1598 case OFPACT_DEC_TTL:
1599 case OFPACT_SET_MPLS_TTL:
1600 case OFPACT_DEC_MPLS_TTL:
1601 case OFPACT_SET_TUNNEL:
1602 case OFPACT_SET_QUEUE:
1603 case OFPACT_POP_QUEUE:
1604 case OFPACT_FIN_TIMEOUT:
1605 case OFPACT_RESUBMIT:
1609 return learn_check(ofpact_get_LEARN(a), flow);
1611 case OFPACT_MULTIPATH:
1612 return multipath_check(ofpact_get_MULTIPATH(a), flow);
1618 case OFPACT_PUSH_MPLS:
1619 flow->dl_type = ofpact_get_PUSH_MPLS(a)->ethertype;
1622 case OFPACT_POP_MPLS:
1623 flow->dl_type = ofpact_get_POP_MPLS(a)->ethertype;
1629 case OFPACT_CLEAR_ACTIONS:
1632 case OFPACT_WRITE_ACTIONS: {
1633 struct ofpact_nest *on = ofpact_get_WRITE_ACTIONS(a);
1634 return ofpacts_check(on->actions, ofpact_nest_get_action_len(on),
1635 flow, max_ports, table_id);
1638 case OFPACT_WRITE_METADATA:
1641 case OFPACT_METER: {
1642 uint32_t mid = ofpact_get_METER(a)->meter_id;
1643 if (mid == 0 || mid > OFPM13_MAX) {
1644 return OFPERR_OFPMMFC_INVALID_METER;
1649 case OFPACT_GOTO_TABLE:
1650 if (ofpact_get_GOTO_TABLE(a)->table_id <= table_id) {
1651 return OFPERR_OFPBRC_BAD_TABLE_ID;
1663 /* Checks that the 'ofpacts_len' bytes of actions in 'ofpacts' are
1664 * appropriate for a packet with the prerequisites satisfied by 'flow' in a
1665 * switch with no more than 'max_ports' ports.
1667 * May temporarily modify 'flow', but restores the changes before returning. */
1669 ofpacts_check(const struct ofpact ofpacts[], size_t ofpacts_len,
1670 struct flow *flow, ofp_port_t max_ports, uint8_t table_id)
1672 const struct ofpact *a;
1673 ovs_be16 dl_type = flow->dl_type;
1674 enum ofperr error = 0;
1676 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
1677 error = ofpact_check__(a, flow, max_ports, table_id);
1682 flow->dl_type = dl_type; /* Restore. */
1686 /* Verifies that the 'ofpacts_len' bytes of actions in 'ofpacts' are
1687 * in the appropriate order as defined by the OpenFlow spec. */
1689 ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len)
1691 const struct ofpact *a;
1692 enum ovs_instruction_type inst;
1694 inst = OVSINST_OFPIT11_APPLY_ACTIONS;
1695 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
1696 enum ovs_instruction_type next;
1698 next = ovs_instruction_type_from_ofpact_type(a->type);
1699 if (inst == OVSINST_OFPIT11_APPLY_ACTIONS
1702 const char *name = ovs_instruction_name_from_type(inst);
1703 const char *next_name = ovs_instruction_name_from_type(next);
1706 VLOG_WARN("duplicate %s instruction not allowed, for OpenFlow "
1707 "1.1+ compatibility", name);
1709 VLOG_WARN("invalid instruction ordering: %s must appear "
1710 "before %s, for OpenFlow 1.1+ compatibility",
1713 return OFPERR_OFPBAC_UNSUPPORTED_ORDER;
1722 /* Converting ofpacts to Nicira OpenFlow extensions. */
1725 ofpact_output_reg_to_nxast(const struct ofpact_output_reg *output_reg,
1728 struct nx_action_output_reg *naor = ofputil_put_NXAST_OUTPUT_REG(out);
1730 naor->ofs_nbits = nxm_encode_ofs_nbits(output_reg->src.ofs,
1731 output_reg->src.n_bits);
1732 naor->src = htonl(output_reg->src.field->nxm_header);
1733 naor->max_len = htons(output_reg->max_len);
1737 ofpact_resubmit_to_nxast(const struct ofpact_resubmit *resubmit,
1740 struct nx_action_resubmit *nar;
1742 if (resubmit->table_id == 0xff
1743 && resubmit->ofpact.compat != OFPUTIL_NXAST_RESUBMIT_TABLE) {
1744 nar = ofputil_put_NXAST_RESUBMIT(out);
1746 nar = ofputil_put_NXAST_RESUBMIT_TABLE(out);
1747 nar->table = resubmit->table_id;
1749 nar->in_port = htons(ofp_to_u16(resubmit->in_port));
1753 ofpact_set_tunnel_to_nxast(const struct ofpact_tunnel *tunnel,
1756 uint64_t tun_id = tunnel->tun_id;
1758 if (tun_id <= UINT32_MAX
1759 && tunnel->ofpact.compat != OFPUTIL_NXAST_SET_TUNNEL64) {
1760 ofputil_put_NXAST_SET_TUNNEL(out)->tun_id = htonl(tun_id);
1762 ofputil_put_NXAST_SET_TUNNEL64(out)->tun_id = htonll(tun_id);
1767 ofpact_write_metadata_to_nxast(const struct ofpact_metadata *om,
1770 struct nx_action_write_metadata *nawm;
1772 nawm = ofputil_put_NXAST_WRITE_METADATA(out);
1773 nawm->metadata = om->metadata;
1774 nawm->mask = om->mask;
1778 ofpact_note_to_nxast(const struct ofpact_note *note, struct ofpbuf *out)
1780 size_t start_ofs = out->size;
1781 struct nx_action_note *nan;
1782 unsigned int remainder;
1785 nan = ofputil_put_NXAST_NOTE(out);
1786 out->size -= sizeof nan->note;
1788 ofpbuf_put(out, note->data, note->length);
1790 len = out->size - start_ofs;
1791 remainder = len % OFP_ACTION_ALIGN;
1793 ofpbuf_put_zeros(out, OFP_ACTION_ALIGN - remainder);
1795 nan = ofpbuf_at(out, start_ofs, sizeof *nan);
1796 nan->len = htons(out->size - start_ofs);
1800 ofpact_controller_to_nxast(const struct ofpact_controller *oc,
1803 struct nx_action_controller *nac;
1805 nac = ofputil_put_NXAST_CONTROLLER(out);
1806 nac->max_len = htons(oc->max_len);
1807 nac->controller_id = htons(oc->controller_id);
1808 nac->reason = oc->reason;
1812 ofpact_dec_ttl_to_nxast(const struct ofpact_cnt_ids *oc_ids,
1815 if (oc_ids->ofpact.compat == OFPUTIL_NXAST_DEC_TTL) {
1816 ofputil_put_NXAST_DEC_TTL(out);
1818 struct nx_action_cnt_ids *nac_ids =
1819 ofputil_put_NXAST_DEC_TTL_CNT_IDS(out);
1820 int ids_len = ROUND_UP(2 * oc_ids->n_controllers, OFP_ACTION_ALIGN);
1824 nac_ids->len = htons(ntohs(nac_ids->len) + ids_len);
1825 nac_ids->n_controllers = htons(oc_ids->n_controllers);
1827 ids = ofpbuf_put_zeros(out, ids_len);
1828 for (i = 0; i < oc_ids->n_controllers; i++) {
1829 ids[i] = htons(oc_ids->cnt_ids[i]);
1835 ofpact_fin_timeout_to_nxast(const struct ofpact_fin_timeout *fin_timeout,
1838 struct nx_action_fin_timeout *naft = ofputil_put_NXAST_FIN_TIMEOUT(out);
1839 naft->fin_idle_timeout = htons(fin_timeout->fin_idle_timeout);
1840 naft->fin_hard_timeout = htons(fin_timeout->fin_hard_timeout);
1844 ofpact_sample_to_nxast(const struct ofpact_sample *os,
1847 struct nx_action_sample *nas;
1849 nas = ofputil_put_NXAST_SAMPLE(out);
1850 nas->probability = htons(os->probability);
1851 nas->collector_set_id = htonl(os->collector_set_id);
1852 nas->obs_domain_id = htonl(os->obs_domain_id);
1853 nas->obs_point_id = htonl(os->obs_point_id);
1857 ofpact_to_nxast(const struct ofpact *a, struct ofpbuf *out)
1860 case OFPACT_CONTROLLER:
1861 ofpact_controller_to_nxast(ofpact_get_CONTROLLER(a), out);
1864 case OFPACT_OUTPUT_REG:
1865 ofpact_output_reg_to_nxast(ofpact_get_OUTPUT_REG(a), out);
1869 bundle_to_nxast(ofpact_get_BUNDLE(a), out);
1872 case OFPACT_REG_MOVE:
1873 nxm_reg_move_to_nxast(ofpact_get_REG_MOVE(a), out);
1876 case OFPACT_REG_LOAD:
1877 nxm_reg_load_to_nxast(ofpact_get_REG_LOAD(a), out);
1880 case OFPACT_STACK_PUSH:
1881 nxm_stack_push_to_nxast(ofpact_get_STACK_PUSH(a), out);
1884 case OFPACT_STACK_POP:
1885 nxm_stack_pop_to_nxast(ofpact_get_STACK_POP(a), out);
1888 case OFPACT_DEC_TTL:
1889 ofpact_dec_ttl_to_nxast(ofpact_get_DEC_TTL(a), out);
1892 case OFPACT_SET_MPLS_TTL:
1893 ofputil_put_NXAST_SET_MPLS_TTL(out)->ttl
1894 = ofpact_get_SET_MPLS_TTL(a)->ttl;
1897 case OFPACT_DEC_MPLS_TTL:
1898 ofputil_put_NXAST_DEC_MPLS_TTL(out);
1901 case OFPACT_SET_TUNNEL:
1902 ofpact_set_tunnel_to_nxast(ofpact_get_SET_TUNNEL(a), out);
1905 case OFPACT_WRITE_METADATA:
1906 ofpact_write_metadata_to_nxast(ofpact_get_WRITE_METADATA(a), out);
1909 case OFPACT_SET_QUEUE:
1910 ofputil_put_NXAST_SET_QUEUE(out)->queue_id
1911 = htonl(ofpact_get_SET_QUEUE(a)->queue_id);
1914 case OFPACT_POP_QUEUE:
1915 ofputil_put_NXAST_POP_QUEUE(out);
1918 case OFPACT_FIN_TIMEOUT:
1919 ofpact_fin_timeout_to_nxast(ofpact_get_FIN_TIMEOUT(a), out);
1922 case OFPACT_RESUBMIT:
1923 ofpact_resubmit_to_nxast(ofpact_get_RESUBMIT(a), out);
1927 learn_to_nxast(ofpact_get_LEARN(a), out);
1930 case OFPACT_MULTIPATH:
1931 multipath_to_nxast(ofpact_get_MULTIPATH(a), out);
1935 ofpact_note_to_nxast(ofpact_get_NOTE(a), out);
1939 ofputil_put_NXAST_EXIT(out);
1942 case OFPACT_PUSH_MPLS:
1943 ofputil_put_NXAST_PUSH_MPLS(out)->ethertype =
1944 ofpact_get_PUSH_MPLS(a)->ethertype;
1947 case OFPACT_POP_MPLS:
1948 ofputil_put_NXAST_POP_MPLS(out)->ethertype =
1949 ofpact_get_POP_MPLS(a)->ethertype;
1953 ofpact_sample_to_nxast(ofpact_get_SAMPLE(a), out);
1958 case OFPACT_ENQUEUE:
1959 case OFPACT_SET_VLAN_VID:
1960 case OFPACT_SET_VLAN_PCP:
1961 case OFPACT_STRIP_VLAN:
1962 case OFPACT_PUSH_VLAN:
1963 case OFPACT_SET_ETH_SRC:
1964 case OFPACT_SET_ETH_DST:
1965 case OFPACT_SET_IPV4_SRC:
1966 case OFPACT_SET_IPV4_DST:
1967 case OFPACT_SET_IP_DSCP:
1968 case OFPACT_SET_IP_ECN:
1969 case OFPACT_SET_L4_SRC_PORT:
1970 case OFPACT_SET_L4_DST_PORT:
1971 case OFPACT_WRITE_ACTIONS:
1972 case OFPACT_CLEAR_ACTIONS:
1973 case OFPACT_GOTO_TABLE:
1979 /* Converting ofpacts to OpenFlow 1.0. */
1982 ofpact_output_to_openflow10(const struct ofpact_output *output,
1985 struct ofp10_action_output *oao;
1987 oao = ofputil_put_OFPAT10_OUTPUT(out);
1988 oao->port = htons(ofp_to_u16(output->port));
1989 oao->max_len = htons(output->max_len);
1993 ofpact_enqueue_to_openflow10(const struct ofpact_enqueue *enqueue,
1996 struct ofp10_action_enqueue *oae;
1998 oae = ofputil_put_OFPAT10_ENQUEUE(out);
1999 oae->port = htons(ofp_to_u16(enqueue->port));
2000 oae->queue_id = htonl(enqueue->queue);
2004 ofpact_to_openflow10(const struct ofpact *a, struct ofpbuf *out)
2008 ofpact_output_to_openflow10(ofpact_get_OUTPUT(a), out);
2011 case OFPACT_ENQUEUE:
2012 ofpact_enqueue_to_openflow10(ofpact_get_ENQUEUE(a), out);
2015 case OFPACT_SET_VLAN_VID:
2016 ofputil_put_OFPAT10_SET_VLAN_VID(out)->vlan_vid
2017 = htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid);
2020 case OFPACT_SET_VLAN_PCP:
2021 ofputil_put_OFPAT10_SET_VLAN_PCP(out)->vlan_pcp
2022 = ofpact_get_SET_VLAN_PCP(a)->vlan_pcp;
2025 case OFPACT_STRIP_VLAN:
2026 ofputil_put_OFPAT10_STRIP_VLAN(out);
2029 case OFPACT_SET_ETH_SRC:
2030 memcpy(ofputil_put_OFPAT10_SET_DL_SRC(out)->dl_addr,
2031 ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
2034 case OFPACT_SET_ETH_DST:
2035 memcpy(ofputil_put_OFPAT10_SET_DL_DST(out)->dl_addr,
2036 ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
2039 case OFPACT_SET_IPV4_SRC:
2040 ofputil_put_OFPAT10_SET_NW_SRC(out)->nw_addr
2041 = ofpact_get_SET_IPV4_SRC(a)->ipv4;
2044 case OFPACT_SET_IPV4_DST:
2045 ofputil_put_OFPAT10_SET_NW_DST(out)->nw_addr
2046 = ofpact_get_SET_IPV4_DST(a)->ipv4;
2049 case OFPACT_SET_IP_DSCP:
2050 ofputil_put_OFPAT10_SET_NW_TOS(out)->nw_tos
2051 = ofpact_get_SET_IP_DSCP(a)->dscp;
2054 case OFPACT_SET_L4_SRC_PORT:
2055 ofputil_put_OFPAT10_SET_TP_SRC(out)->tp_port
2056 = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
2059 case OFPACT_SET_L4_DST_PORT:
2060 ofputil_put_OFPAT10_SET_TP_DST(out)->tp_port
2061 = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
2064 case OFPACT_PUSH_VLAN:
2065 case OFPACT_CLEAR_ACTIONS:
2066 case OFPACT_WRITE_ACTIONS:
2067 case OFPACT_GOTO_TABLE:
2075 case OFPACT_CONTROLLER:
2076 case OFPACT_OUTPUT_REG:
2078 case OFPACT_REG_MOVE:
2079 case OFPACT_REG_LOAD:
2080 case OFPACT_STACK_PUSH:
2081 case OFPACT_STACK_POP:
2082 case OFPACT_DEC_TTL:
2083 case OFPACT_SET_IP_ECN:
2084 case OFPACT_SET_MPLS_TTL:
2085 case OFPACT_DEC_MPLS_TTL:
2086 case OFPACT_SET_TUNNEL:
2087 case OFPACT_WRITE_METADATA:
2088 case OFPACT_SET_QUEUE:
2089 case OFPACT_POP_QUEUE:
2090 case OFPACT_FIN_TIMEOUT:
2091 case OFPACT_RESUBMIT:
2093 case OFPACT_MULTIPATH:
2096 case OFPACT_PUSH_MPLS:
2097 case OFPACT_POP_MPLS:
2099 ofpact_to_nxast(a, out);
2104 /* Converts the 'ofpacts_len' bytes of ofpacts in 'ofpacts' into OpenFlow 1.0
2105 * actions in 'openflow', appending the actions to any existing data in
2108 ofpacts_put_openflow10(const struct ofpact ofpacts[], size_t ofpacts_len,
2109 struct ofpbuf *openflow)
2111 const struct ofpact *a;
2113 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2114 ofpact_to_openflow10(a, openflow);
2118 /* Converting ofpacts to OpenFlow 1.1. */
2121 ofpact_output_to_openflow11(const struct ofpact_output *output,
2124 struct ofp11_action_output *oao;
2126 oao = ofputil_put_OFPAT11_OUTPUT(out);
2127 oao->port = ofputil_port_to_ofp11(output->port);
2128 oao->max_len = htons(output->max_len);
2132 ofpact_dec_ttl_to_openflow11(const struct ofpact_cnt_ids *dec_ttl,
2135 if (dec_ttl->n_controllers == 1 && dec_ttl->cnt_ids[0] == 0
2136 && (!dec_ttl->ofpact.compat ||
2137 dec_ttl->ofpact.compat == OFPUTIL_OFPAT11_DEC_NW_TTL)) {
2138 ofputil_put_OFPAT11_DEC_NW_TTL(out);
2140 ofpact_dec_ttl_to_nxast(dec_ttl, out);
2145 ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out)
2149 return ofpact_output_to_openflow11(ofpact_get_OUTPUT(a), out);
2151 case OFPACT_ENQUEUE:
2155 case OFPACT_SET_VLAN_VID:
2156 ofputil_put_OFPAT11_SET_VLAN_VID(out)->vlan_vid
2157 = htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid);
2160 case OFPACT_SET_VLAN_PCP:
2161 ofputil_put_OFPAT11_SET_VLAN_PCP(out)->vlan_pcp
2162 = ofpact_get_SET_VLAN_PCP(a)->vlan_pcp;
2165 case OFPACT_STRIP_VLAN:
2166 ofputil_put_OFPAT11_POP_VLAN(out);
2169 case OFPACT_PUSH_VLAN:
2170 /* XXX ETH_TYPE_VLAN_8021AD case */
2171 ofputil_put_OFPAT11_PUSH_VLAN(out)->ethertype =
2172 htons(ETH_TYPE_VLAN_8021Q);
2175 case OFPACT_SET_QUEUE:
2176 ofputil_put_OFPAT11_SET_QUEUE(out)->queue_id
2177 = htonl(ofpact_get_SET_QUEUE(a)->queue_id);
2180 case OFPACT_SET_ETH_SRC:
2181 memcpy(ofputil_put_OFPAT11_SET_DL_SRC(out)->dl_addr,
2182 ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
2185 case OFPACT_SET_ETH_DST:
2186 memcpy(ofputil_put_OFPAT11_SET_DL_DST(out)->dl_addr,
2187 ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
2190 case OFPACT_SET_IPV4_SRC:
2191 ofputil_put_OFPAT11_SET_NW_SRC(out)->nw_addr
2192 = ofpact_get_SET_IPV4_SRC(a)->ipv4;
2195 case OFPACT_SET_IPV4_DST:
2196 ofputil_put_OFPAT11_SET_NW_DST(out)->nw_addr
2197 = ofpact_get_SET_IPV4_DST(a)->ipv4;
2200 case OFPACT_SET_IP_DSCP:
2201 ofputil_put_OFPAT11_SET_NW_TOS(out)->nw_tos
2202 = ofpact_get_SET_IP_DSCP(a)->dscp;
2205 case OFPACT_SET_IP_ECN:
2206 ofputil_put_OFPAT11_SET_NW_ECN(out)->nw_ecn
2207 = ofpact_get_SET_IP_ECN(a)->ecn;
2210 case OFPACT_SET_L4_SRC_PORT:
2211 ofputil_put_OFPAT11_SET_TP_SRC(out)->tp_port
2212 = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
2215 case OFPACT_SET_L4_DST_PORT:
2216 ofputil_put_OFPAT11_SET_TP_DST(out)->tp_port
2217 = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
2220 case OFPACT_DEC_TTL:
2221 ofpact_dec_ttl_to_openflow11(ofpact_get_DEC_TTL(a), out);
2224 case OFPACT_SET_MPLS_TTL:
2225 ofputil_put_OFPAT11_SET_MPLS_TTL(out)->mpls_ttl
2226 = ofpact_get_SET_MPLS_TTL(a)->ttl;
2229 case OFPACT_DEC_MPLS_TTL:
2230 ofputil_put_OFPAT11_DEC_MPLS_TTL(out);
2233 case OFPACT_WRITE_METADATA:
2234 /* OpenFlow 1.1 uses OFPIT_WRITE_METADATA to express this action. */
2237 case OFPACT_PUSH_MPLS:
2238 ofputil_put_OFPAT11_PUSH_MPLS(out)->ethertype =
2239 ofpact_get_PUSH_MPLS(a)->ethertype;
2242 case OFPACT_POP_MPLS:
2243 ofputil_put_OFPAT11_POP_MPLS(out)->ethertype =
2244 ofpact_get_POP_MPLS(a)->ethertype;
2248 case OFPACT_CLEAR_ACTIONS:
2249 case OFPACT_WRITE_ACTIONS:
2250 case OFPACT_GOTO_TABLE:
2255 ofputil_put_OFPAT11_GROUP(out)->group_id =
2256 htonl(ofpact_get_GROUP(a)->group_id);
2259 case OFPACT_CONTROLLER:
2260 case OFPACT_OUTPUT_REG:
2262 case OFPACT_REG_MOVE:
2263 case OFPACT_REG_LOAD:
2264 case OFPACT_STACK_PUSH:
2265 case OFPACT_STACK_POP:
2266 case OFPACT_SET_TUNNEL:
2267 case OFPACT_POP_QUEUE:
2268 case OFPACT_FIN_TIMEOUT:
2269 case OFPACT_RESUBMIT:
2271 case OFPACT_MULTIPATH:
2275 ofpact_to_nxast(a, out);
2280 /* Converts the ofpacts in 'ofpacts' (terminated by OFPACT_END) into OpenFlow
2281 * 1.1 actions in 'openflow', appending the actions to any existing data in
2284 ofpacts_put_openflow11_actions(const struct ofpact ofpacts[],
2285 size_t ofpacts_len, struct ofpbuf *openflow)
2287 const struct ofpact *a;
2288 size_t start_size = openflow->size;
2290 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2291 ofpact_to_openflow11(a, openflow);
2294 return openflow->size - start_size;
2298 ofpacts_update_instruction_actions(struct ofpbuf *openflow, size_t ofs)
2300 struct ofp11_instruction_actions *oia;
2302 /* Update the instruction's length (or, if it's empty, delete it). */
2303 oia = ofpbuf_at_assert(openflow, ofs, sizeof *oia);
2304 if (openflow->size > ofs + sizeof *oia) {
2305 oia->len = htons(openflow->size - ofs);
2307 openflow->size = ofs;
2312 ofpacts_put_openflow11_instructions(const struct ofpact ofpacts[],
2314 struct ofpbuf *openflow)
2316 const struct ofpact *a;
2318 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2319 switch (ovs_instruction_type_from_ofpact_type(a->type)) {
2320 case OVSINST_OFPIT11_CLEAR_ACTIONS:
2321 instruction_put_OFPIT11_CLEAR_ACTIONS(openflow);
2324 case OVSINST_OFPIT11_GOTO_TABLE: {
2325 struct ofp11_instruction_goto_table *oigt;
2326 oigt = instruction_put_OFPIT11_GOTO_TABLE(openflow);
2327 oigt->table_id = ofpact_get_GOTO_TABLE(a)->table_id;
2328 memset(oigt->pad, 0, sizeof oigt->pad);
2332 case OVSINST_OFPIT11_WRITE_METADATA: {
2333 const struct ofpact_metadata *om;
2334 struct ofp11_instruction_write_metadata *oiwm;
2336 om = ofpact_get_WRITE_METADATA(a);
2337 oiwm = instruction_put_OFPIT11_WRITE_METADATA(openflow);
2338 oiwm->metadata = om->metadata;
2339 oiwm->metadata_mask = om->mask;
2343 case OVSINST_OFPIT13_METER: {
2344 const struct ofpact_meter *om;
2345 struct ofp13_instruction_meter *oim;
2347 om = ofpact_get_METER(a);
2348 oim = instruction_put_OFPIT13_METER(openflow);
2349 oim->meter_id = htonl(om->meter_id);
2353 case OVSINST_OFPIT11_APPLY_ACTIONS: {
2354 const size_t ofs = openflow->size;
2355 const size_t ofpacts_len_left =
2356 (uint8_t*)ofpact_end(ofpacts, ofpacts_len) - (uint8_t*)a;
2357 const struct ofpact *action;
2358 const struct ofpact *processed = a;
2360 instruction_put_OFPIT11_APPLY_ACTIONS(openflow);
2361 OFPACT_FOR_EACH(action, a, ofpacts_len_left) {
2362 if (ovs_instruction_type_from_ofpact_type(action->type)
2363 != OVSINST_OFPIT11_APPLY_ACTIONS) {
2366 ofpact_to_openflow11(action, openflow);
2369 ofpacts_update_instruction_actions(openflow, ofs);
2374 case OVSINST_OFPIT11_WRITE_ACTIONS: {
2375 const size_t ofs = openflow->size;
2376 const struct ofpact_nest *on;
2378 on = ofpact_get_WRITE_ACTIONS(a);
2379 instruction_put_OFPIT11_WRITE_ACTIONS(openflow);
2380 ofpacts_put_openflow11_actions(on->actions,
2381 ofpact_nest_get_action_len(on),
2383 ofpacts_update_instruction_actions(openflow, ofs);
2391 /* Returns true if 'action' outputs to 'port', false otherwise. */
2393 ofpact_outputs_to_port(const struct ofpact *ofpact, ofp_port_t port)
2395 switch (ofpact->type) {
2397 return ofpact_get_OUTPUT(ofpact)->port == port;
2398 case OFPACT_ENQUEUE:
2399 return ofpact_get_ENQUEUE(ofpact)->port == port;
2400 case OFPACT_CONTROLLER:
2401 return port == OFPP_CONTROLLER;
2403 case OFPACT_OUTPUT_REG:
2405 case OFPACT_SET_VLAN_VID:
2406 case OFPACT_SET_VLAN_PCP:
2407 case OFPACT_STRIP_VLAN:
2408 case OFPACT_PUSH_VLAN:
2409 case OFPACT_SET_ETH_SRC:
2410 case OFPACT_SET_ETH_DST:
2411 case OFPACT_SET_IPV4_SRC:
2412 case OFPACT_SET_IPV4_DST:
2413 case OFPACT_SET_IP_DSCP:
2414 case OFPACT_SET_IP_ECN:
2415 case OFPACT_SET_L4_SRC_PORT:
2416 case OFPACT_SET_L4_DST_PORT:
2417 case OFPACT_REG_MOVE:
2418 case OFPACT_REG_LOAD:
2419 case OFPACT_STACK_PUSH:
2420 case OFPACT_STACK_POP:
2421 case OFPACT_DEC_TTL:
2422 case OFPACT_SET_MPLS_TTL:
2423 case OFPACT_DEC_MPLS_TTL:
2424 case OFPACT_SET_TUNNEL:
2425 case OFPACT_WRITE_METADATA:
2426 case OFPACT_SET_QUEUE:
2427 case OFPACT_POP_QUEUE:
2428 case OFPACT_FIN_TIMEOUT:
2429 case OFPACT_RESUBMIT:
2431 case OFPACT_MULTIPATH:
2434 case OFPACT_PUSH_MPLS:
2435 case OFPACT_POP_MPLS:
2437 case OFPACT_CLEAR_ACTIONS:
2438 case OFPACT_WRITE_ACTIONS:
2439 case OFPACT_GOTO_TABLE:
2447 /* Returns true if any action in the 'ofpacts_len' bytes of 'ofpacts' outputs
2448 * to 'port', false otherwise. */
2450 ofpacts_output_to_port(const struct ofpact *ofpacts, size_t ofpacts_len,
2453 const struct ofpact *a;
2455 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2456 if (ofpact_outputs_to_port(a, port)) {
2464 /* Returns true if any action in the 'ofpacts_len' bytes of 'ofpacts' outputs
2465 * to 'group', false otherwise. */
2467 ofpacts_output_to_group(const struct ofpact *ofpacts, size_t ofpacts_len,
2470 const struct ofpact *a;
2472 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2473 if (a->type == OFPACT_GROUP
2474 && ofpact_get_GROUP(a)->group_id == group_id) {
2483 ofpacts_equal(const struct ofpact *a, size_t a_len,
2484 const struct ofpact *b, size_t b_len)
2486 return a_len == b_len && !memcmp(a, b, a_len);
2489 /* Finds the OFPACT_METER action, if any, in the 'ofpacts_len' bytes of
2490 * 'ofpacts'. If found, returns its meter ID; if not, returns 0.
2492 * This function relies on the order of 'ofpacts' being correct (as checked by
2493 * ofpacts_verify()). */
2495 ofpacts_get_meter(const struct ofpact ofpacts[], size_t ofpacts_len)
2497 const struct ofpact *a;
2499 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2500 enum ovs_instruction_type inst;
2502 inst = ovs_instruction_type_from_ofpact_type(a->type);
2503 if (a->type == OFPACT_METER) {
2504 return ofpact_get_METER(a)->meter_id;
2505 } else if (inst > OVSINST_OFPIT13_METER) {
2513 /* Formatting ofpacts. */
2516 print_note(const struct ofpact_note *note, struct ds *string)
2520 ds_put_cstr(string, "note:");
2521 for (i = 0; i < note->length; i++) {
2523 ds_put_char(string, '.');
2525 ds_put_format(string, "%02"PRIx8, note->data[i]);
2530 print_dec_ttl(const struct ofpact_cnt_ids *ids,
2535 ds_put_cstr(s, "dec_ttl");
2536 if (ids->ofpact.compat == OFPUTIL_NXAST_DEC_TTL_CNT_IDS) {
2537 ds_put_cstr(s, "(");
2538 for (i = 0; i < ids->n_controllers; i++) {
2540 ds_put_cstr(s, ",");
2542 ds_put_format(s, "%"PRIu16, ids->cnt_ids[i]);
2544 ds_put_cstr(s, ")");
2549 print_fin_timeout(const struct ofpact_fin_timeout *fin_timeout,
2552 ds_put_cstr(s, "fin_timeout(");
2553 if (fin_timeout->fin_idle_timeout) {
2554 ds_put_format(s, "idle_timeout=%"PRIu16",",
2555 fin_timeout->fin_idle_timeout);
2557 if (fin_timeout->fin_hard_timeout) {
2558 ds_put_format(s, "hard_timeout=%"PRIu16",",
2559 fin_timeout->fin_hard_timeout);
2562 ds_put_char(s, ')');
2566 ofpact_format(const struct ofpact *a, struct ds *s)
2568 const struct ofpact_enqueue *enqueue;
2569 const struct ofpact_resubmit *resubmit;
2570 const struct ofpact_controller *controller;
2571 const struct ofpact_metadata *metadata;
2572 const struct ofpact_tunnel *tunnel;
2573 const struct ofpact_sample *sample;
2578 port = ofpact_get_OUTPUT(a)->port;
2579 if (ofp_to_u16(port) < ofp_to_u16(OFPP_MAX)) {
2580 ds_put_format(s, "output:%"PRIu16, port);
2582 ofputil_format_port(port, s);
2583 if (port == OFPP_CONTROLLER) {
2584 ds_put_format(s, ":%"PRIu16, ofpact_get_OUTPUT(a)->max_len);
2589 case OFPACT_CONTROLLER:
2590 controller = ofpact_get_CONTROLLER(a);
2591 if (controller->reason == OFPR_ACTION &&
2592 controller->controller_id == 0) {
2593 ds_put_format(s, "CONTROLLER:%"PRIu16,
2594 ofpact_get_CONTROLLER(a)->max_len);
2596 enum ofp_packet_in_reason reason = controller->reason;
2598 ds_put_cstr(s, "controller(");
2599 if (reason != OFPR_ACTION) {
2600 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
2602 ds_put_format(s, "reason=%s,",
2603 ofputil_packet_in_reason_to_string(
2604 reason, reasonbuf, sizeof reasonbuf));
2606 if (controller->max_len != UINT16_MAX) {
2607 ds_put_format(s, "max_len=%"PRIu16",", controller->max_len);
2609 if (controller->controller_id != 0) {
2610 ds_put_format(s, "id=%"PRIu16",", controller->controller_id);
2613 ds_put_char(s, ')');
2617 case OFPACT_ENQUEUE:
2618 enqueue = ofpact_get_ENQUEUE(a);
2619 ds_put_format(s, "enqueue:");
2620 ofputil_format_port(enqueue->port, s);
2621 ds_put_format(s, "q%"PRIu32, enqueue->queue);
2624 case OFPACT_OUTPUT_REG:
2625 ds_put_cstr(s, "output:");
2626 mf_format_subfield(&ofpact_get_OUTPUT_REG(a)->src, s);
2630 bundle_format(ofpact_get_BUNDLE(a), s);
2633 case OFPACT_SET_VLAN_VID:
2634 ds_put_format(s, "mod_vlan_vid:%"PRIu16,
2635 ofpact_get_SET_VLAN_VID(a)->vlan_vid);
2638 case OFPACT_SET_VLAN_PCP:
2639 ds_put_format(s, "mod_vlan_pcp:%"PRIu8,
2640 ofpact_get_SET_VLAN_PCP(a)->vlan_pcp);
2643 case OFPACT_STRIP_VLAN:
2644 ds_put_cstr(s, "strip_vlan");
2647 case OFPACT_PUSH_VLAN:
2648 /* XXX 802.1AD case*/
2649 ds_put_format(s, "push_vlan:%#"PRIx16, ETH_TYPE_VLAN_8021Q);
2652 case OFPACT_SET_ETH_SRC:
2653 ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT,
2654 ETH_ADDR_ARGS(ofpact_get_SET_ETH_SRC(a)->mac));
2657 case OFPACT_SET_ETH_DST:
2658 ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT,
2659 ETH_ADDR_ARGS(ofpact_get_SET_ETH_DST(a)->mac));
2662 case OFPACT_SET_IPV4_SRC:
2663 ds_put_format(s, "mod_nw_src:"IP_FMT,
2664 IP_ARGS(ofpact_get_SET_IPV4_SRC(a)->ipv4));
2667 case OFPACT_SET_IPV4_DST:
2668 ds_put_format(s, "mod_nw_dst:"IP_FMT,
2669 IP_ARGS(ofpact_get_SET_IPV4_DST(a)->ipv4));
2672 case OFPACT_SET_IP_DSCP:
2673 ds_put_format(s, "mod_nw_tos:%d", ofpact_get_SET_IP_DSCP(a)->dscp);
2676 case OFPACT_SET_IP_ECN:
2677 ds_put_format(s, "mod_nw_ecn:%d", ofpact_get_SET_IP_ECN(a)->ecn);
2680 case OFPACT_SET_L4_SRC_PORT:
2681 ds_put_format(s, "mod_tp_src:%d", ofpact_get_SET_L4_SRC_PORT(a)->port);
2684 case OFPACT_SET_L4_DST_PORT:
2685 ds_put_format(s, "mod_tp_dst:%d", ofpact_get_SET_L4_DST_PORT(a)->port);
2688 case OFPACT_REG_MOVE:
2689 nxm_format_reg_move(ofpact_get_REG_MOVE(a), s);
2692 case OFPACT_REG_LOAD:
2693 nxm_format_reg_load(ofpact_get_REG_LOAD(a), s);
2696 case OFPACT_STACK_PUSH:
2697 nxm_format_stack_push(ofpact_get_STACK_PUSH(a), s);
2700 case OFPACT_STACK_POP:
2701 nxm_format_stack_pop(ofpact_get_STACK_POP(a), s);
2704 case OFPACT_DEC_TTL:
2705 print_dec_ttl(ofpact_get_DEC_TTL(a), s);
2708 case OFPACT_SET_MPLS_TTL:
2709 ds_put_format(s, "set_mpls_ttl(%"PRIu8")",
2710 ofpact_get_SET_MPLS_TTL(a)->ttl);
2713 case OFPACT_DEC_MPLS_TTL:
2714 ds_put_cstr(s, "dec_mpls_ttl");
2717 case OFPACT_SET_TUNNEL:
2718 tunnel = ofpact_get_SET_TUNNEL(a);
2719 ds_put_format(s, "set_tunnel%s:%#"PRIx64,
2720 (tunnel->tun_id > UINT32_MAX
2721 || a->compat == OFPUTIL_NXAST_SET_TUNNEL64 ? "64" : ""),
2725 case OFPACT_SET_QUEUE:
2726 ds_put_format(s, "set_queue:%"PRIu32,
2727 ofpact_get_SET_QUEUE(a)->queue_id);
2730 case OFPACT_POP_QUEUE:
2731 ds_put_cstr(s, "pop_queue");
2734 case OFPACT_FIN_TIMEOUT:
2735 print_fin_timeout(ofpact_get_FIN_TIMEOUT(a), s);
2738 case OFPACT_RESUBMIT:
2739 resubmit = ofpact_get_RESUBMIT(a);
2740 if (resubmit->in_port != OFPP_IN_PORT && resubmit->table_id == 255) {
2741 ds_put_cstr(s, "resubmit:");
2742 ofputil_format_port(resubmit->in_port, s);
2744 ds_put_format(s, "resubmit(");
2745 if (resubmit->in_port != OFPP_IN_PORT) {
2746 ofputil_format_port(resubmit->in_port, s);
2748 ds_put_char(s, ',');
2749 if (resubmit->table_id != 255) {
2750 ds_put_format(s, "%"PRIu8, resubmit->table_id);
2752 ds_put_char(s, ')');
2757 learn_format(ofpact_get_LEARN(a), s);
2760 case OFPACT_MULTIPATH:
2761 multipath_format(ofpact_get_MULTIPATH(a), s);
2765 print_note(ofpact_get_NOTE(a), s);
2768 case OFPACT_PUSH_MPLS:
2769 ds_put_format(s, "push_mpls:0x%04"PRIx16,
2770 ntohs(ofpact_get_PUSH_MPLS(a)->ethertype));
2773 case OFPACT_POP_MPLS:
2774 ds_put_format(s, "pop_mpls:0x%04"PRIx16,
2775 ntohs(ofpact_get_POP_MPLS(a)->ethertype));
2779 ds_put_cstr(s, "exit");
2783 sample = ofpact_get_SAMPLE(a);
2785 s, "sample(probability=%"PRIu16",collector_set_id=%"PRIu32
2786 ",obs_domain_id=%"PRIu32",obs_point_id=%"PRIu32")",
2787 sample->probability, sample->collector_set_id,
2788 sample->obs_domain_id, sample->obs_point_id);
2791 case OFPACT_WRITE_ACTIONS: {
2792 struct ofpact_nest *on = ofpact_get_WRITE_ACTIONS(a);
2793 ds_put_format(s, "%s(",
2794 ovs_instruction_name_from_type(
2795 OVSINST_OFPIT11_WRITE_ACTIONS));
2796 ofpacts_format(on->actions, ofpact_nest_get_action_len(on), s);
2797 ds_put_char(s, ')');
2801 case OFPACT_CLEAR_ACTIONS:
2802 ds_put_format(s, "%s",
2803 ovs_instruction_name_from_type(
2804 OVSINST_OFPIT11_CLEAR_ACTIONS));
2807 case OFPACT_WRITE_METADATA:
2808 metadata = ofpact_get_WRITE_METADATA(a);
2809 ds_put_format(s, "%s:%#"PRIx64,
2810 ovs_instruction_name_from_type(
2811 OVSINST_OFPIT11_WRITE_METADATA),
2812 ntohll(metadata->metadata));
2813 if (metadata->mask != OVS_BE64_MAX) {
2814 ds_put_format(s, "/%#"PRIx64, ntohll(metadata->mask));
2818 case OFPACT_GOTO_TABLE:
2819 ds_put_format(s, "%s:%"PRIu8,
2820 ovs_instruction_name_from_type(
2821 OVSINST_OFPIT11_GOTO_TABLE),
2822 ofpact_get_GOTO_TABLE(a)->table_id);
2826 ds_put_format(s, "%s:%"PRIu32,
2827 ovs_instruction_name_from_type(OVSINST_OFPIT13_METER),
2828 ofpact_get_METER(a)->meter_id);
2832 ds_put_format(s, "group:%"PRIu32,
2833 ofpact_get_GROUP(a)->group_id);
2838 /* Appends a string representing the 'ofpacts_len' bytes of ofpacts in
2839 * 'ofpacts' to 'string'. */
2841 ofpacts_format(const struct ofpact *ofpacts, size_t ofpacts_len,
2845 ds_put_cstr(string, "drop");
2847 const struct ofpact *a;
2849 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2851 ds_put_cstr(string, ",");
2854 /* XXX write-actions */
2855 ofpact_format(a, string);
2860 /* Internal use by helpers. */
2863 ofpact_put(struct ofpbuf *ofpacts, enum ofpact_type type, size_t len)
2865 struct ofpact *ofpact;
2867 ofpact_pad(ofpacts);
2868 ofpact = ofpacts->l2 = ofpbuf_put_uninit(ofpacts, len);
2869 ofpact_init(ofpact, type, len);
2874 ofpact_init(struct ofpact *ofpact, enum ofpact_type type, size_t len)
2876 memset(ofpact, 0, len);
2877 ofpact->type = type;
2878 ofpact->compat = OFPUTIL_ACTION_INVALID;
2882 /* Updates 'ofpact->len' to the number of bytes in the tail of 'ofpacts'
2883 * starting at 'ofpact'.
2885 * This is the correct way to update a variable-length ofpact's length after
2886 * adding the variable-length part of the payload. (See the large comment
2887 * near the end of ofp-actions.h for more information.) */
2889 ofpact_update_len(struct ofpbuf *ofpacts, struct ofpact *ofpact)
2891 ovs_assert(ofpact == ofpacts->l2);
2892 ofpact->len = (char *) ofpbuf_tail(ofpacts) - (char *) ofpact;
2895 /* Pads out 'ofpacts' to a multiple of OFPACT_ALIGNTO bytes in length. Each
2896 * ofpact_put_<ENUM>() calls this function automatically beforehand, but the
2897 * client must call this itself after adding the final ofpact to an array of
2900 * (The consequences of failing to call this function are probably not dire.
2901 * OFPACT_FOR_EACH will calculate a pointer beyond the end of the ofpacts, but
2902 * not dereference it. That's undefined behavior, technically, but it will not
2903 * cause a real problem on common systems. Still, it seems better to call
2906 ofpact_pad(struct ofpbuf *ofpacts)
2908 unsigned int rem = ofpacts->size % OFPACT_ALIGNTO;
2910 ofpbuf_put_zeros(ofpacts, OFPACT_ALIGNTO - rem);
2915 ofpact_set_field_init(struct ofpact_reg_load *load, const struct mf_field *mf,
2918 load->ofpact.compat = OFPUTIL_OFPAT12_SET_FIELD;
2919 load->dst.field = mf;
2921 load->dst.n_bits = mf->n_bits;
2922 bitwise_copy(src, mf->n_bytes, load->dst.ofs,
2923 &load->subvalue, sizeof load->subvalue, 0, mf->n_bits);