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 ofp11_action_nw_ttl nw_ttl;
49 struct ofp_action_tp_port tp_port;
50 struct ofp_action_dl_addr dl_addr;
51 struct ofp10_action_enqueue enqueue;
52 struct ofp11_action_output ofp11_output;
53 struct ofp11_action_push push;
54 struct ofp11_action_pop_mpls ofp11_pop_mpls;
55 struct ofp11_action_set_queue ofp11_set_queue;
56 struct ofp11_action_mpls_ttl ofp11_mpls_ttl;
57 struct ofp11_action_group group;
58 struct ofp12_action_set_field set_field;
59 struct nx_action_header nxa_header;
60 struct nx_action_resubmit resubmit;
61 struct nx_action_set_tunnel set_tunnel;
62 struct nx_action_set_tunnel64 set_tunnel64;
63 struct nx_action_write_metadata write_metadata;
64 struct nx_action_set_queue set_queue;
65 struct nx_action_reg_move reg_move;
66 struct nx_action_reg_load reg_load;
67 struct nx_action_stack stack;
68 struct nx_action_note note;
69 struct nx_action_multipath multipath;
70 struct nx_action_bundle bundle;
71 struct nx_action_output_reg output_reg;
72 struct nx_action_cnt_ids cnt_ids;
73 struct nx_action_fin_timeout fin_timeout;
74 struct nx_action_controller controller;
75 struct nx_action_push_mpls push_mpls;
76 struct nx_action_mpls_ttl mpls_ttl;
77 struct nx_action_pop_mpls pop_mpls;
78 struct nx_action_sample sample;
79 struct nx_action_learn learn;
83 output_from_openflow10(const struct ofp10_action_output *oao,
86 struct ofpact_output *output;
88 output = ofpact_put_OUTPUT(out);
89 output->port = u16_to_ofp(ntohs(oao->port));
90 output->max_len = ntohs(oao->max_len);
92 return ofputil_check_output_port(output->port, OFPP_MAX);
96 enqueue_from_openflow10(const struct ofp10_action_enqueue *oae,
99 struct ofpact_enqueue *enqueue;
101 enqueue = ofpact_put_ENQUEUE(out);
102 enqueue->port = u16_to_ofp(ntohs(oae->port));
103 enqueue->queue = ntohl(oae->queue_id);
104 if (ofp_to_u16(enqueue->port) >= ofp_to_u16(OFPP_MAX)
105 && enqueue->port != OFPP_IN_PORT
106 && enqueue->port != OFPP_LOCAL) {
107 return OFPERR_OFPBAC_BAD_OUT_PORT;
113 resubmit_from_openflow(const struct nx_action_resubmit *nar,
116 struct ofpact_resubmit *resubmit;
118 resubmit = ofpact_put_RESUBMIT(out);
119 resubmit->ofpact.compat = OFPUTIL_NXAST_RESUBMIT;
120 resubmit->in_port = u16_to_ofp(ntohs(nar->in_port));
121 resubmit->table_id = 0xff;
125 resubmit_table_from_openflow(const struct nx_action_resubmit *nar,
128 struct ofpact_resubmit *resubmit;
130 if (nar->pad[0] || nar->pad[1] || nar->pad[2]) {
131 return OFPERR_OFPBAC_BAD_ARGUMENT;
134 resubmit = ofpact_put_RESUBMIT(out);
135 resubmit->ofpact.compat = OFPUTIL_NXAST_RESUBMIT_TABLE;
136 resubmit->in_port = u16_to_ofp(ntohs(nar->in_port));
137 resubmit->table_id = nar->table;
142 output_reg_from_openflow(const struct nx_action_output_reg *naor,
145 struct ofpact_output_reg *output_reg;
147 if (!is_all_zeros(naor->zero, sizeof naor->zero)) {
148 return OFPERR_OFPBAC_BAD_ARGUMENT;
151 output_reg = ofpact_put_OUTPUT_REG(out);
152 output_reg->src.field = mf_from_nxm_header(ntohl(naor->src));
153 output_reg->src.ofs = nxm_decode_ofs(naor->ofs_nbits);
154 output_reg->src.n_bits = nxm_decode_n_bits(naor->ofs_nbits);
155 output_reg->max_len = ntohs(naor->max_len);
157 return mf_check_src(&output_reg->src, NULL);
161 fin_timeout_from_openflow(const struct nx_action_fin_timeout *naft,
164 struct ofpact_fin_timeout *oft;
166 oft = ofpact_put_FIN_TIMEOUT(out);
167 oft->fin_idle_timeout = ntohs(naft->fin_idle_timeout);
168 oft->fin_hard_timeout = ntohs(naft->fin_hard_timeout);
172 controller_from_openflow(const struct nx_action_controller *nac,
175 struct ofpact_controller *oc;
177 oc = ofpact_put_CONTROLLER(out);
178 oc->max_len = ntohs(nac->max_len);
179 oc->controller_id = ntohs(nac->controller_id);
180 oc->reason = nac->reason;
184 metadata_from_nxast(const struct nx_action_write_metadata *nawm,
187 struct ofpact_metadata *om;
189 if (!is_all_zeros(nawm->zeros, sizeof nawm->zeros)) {
190 return OFPERR_NXBRC_MUST_BE_ZERO;
193 om = ofpact_put_WRITE_METADATA(out);
194 om->metadata = nawm->metadata;
195 om->mask = nawm->mask;
201 note_from_openflow(const struct nx_action_note *nan, struct ofpbuf *out)
203 struct ofpact_note *note;
206 length = ntohs(nan->len) - offsetof(struct nx_action_note, note);
207 note = ofpact_put(out, OFPACT_NOTE,
208 offsetof(struct ofpact_note, data) + length);
209 note->length = length;
210 memcpy(note->data, nan->note, length);
214 dec_ttl_from_openflow(struct ofpbuf *out, enum ofputil_action_code compat)
217 struct ofpact_cnt_ids *ids;
218 enum ofperr error = 0;
220 ids = ofpact_put_DEC_TTL(out);
221 ids->ofpact.compat = compat;
222 ids->n_controllers = 1;
223 ofpbuf_put(out, &id, sizeof id);
225 ofpact_update_len(out, &ids->ofpact);
230 dec_ttl_cnt_ids_from_openflow(const struct nx_action_cnt_ids *nac_ids,
233 struct ofpact_cnt_ids *ids;
237 ids = ofpact_put_DEC_TTL(out);
238 ids->ofpact.compat = OFPUTIL_NXAST_DEC_TTL_CNT_IDS;
239 ids->n_controllers = ntohs(nac_ids->n_controllers);
240 ids_size = ntohs(nac_ids->len) - sizeof *nac_ids;
242 if (!is_all_zeros(nac_ids->zeros, sizeof nac_ids->zeros)) {
243 return OFPERR_NXBRC_MUST_BE_ZERO;
246 if (ids_size < ids->n_controllers * sizeof(ovs_be16)) {
247 VLOG_WARN_RL(&rl, "Nicira action dec_ttl_cnt_ids only has %zu bytes "
248 "allocated for controller ids. %zu bytes are required for "
249 "%"PRIu16" controllers.", ids_size,
250 ids->n_controllers * sizeof(ovs_be16), ids->n_controllers);
251 return OFPERR_OFPBAC_BAD_LEN;
254 for (i = 0; i < ids->n_controllers; i++) {
255 uint16_t id = ntohs(((ovs_be16 *)(nac_ids + 1))[i]);
256 ofpbuf_put(out, &id, sizeof id);
260 ofpact_update_len(out, &ids->ofpact);
266 sample_from_openflow(const struct nx_action_sample *nas,
269 struct ofpact_sample *sample;
271 sample = ofpact_put_SAMPLE(out);
272 sample->probability = ntohs(nas->probability);
273 sample->collector_set_id = ntohl(nas->collector_set_id);
274 sample->obs_domain_id = ntohl(nas->obs_domain_id);
275 sample->obs_point_id = ntohl(nas->obs_point_id);
277 if (sample->probability == 0) {
278 return OFPERR_OFPBAC_BAD_ARGUMENT;
285 push_mpls_from_openflow(ovs_be16 ethertype, enum ofpact_mpls_position position,
288 struct ofpact_push_mpls *oam;
290 if (!eth_type_mpls(ethertype)) {
291 return OFPERR_OFPBAC_BAD_ARGUMENT;
293 oam = ofpact_put_PUSH_MPLS(out);
294 oam->ethertype = ethertype;
295 oam->position = position;
301 decode_nxast_action(const union ofp_action *a, enum ofputil_action_code *code)
303 const struct nx_action_header *nah = &a->nxa_header;
304 uint16_t len = ntohs(a->header.len);
306 if (len < sizeof(struct nx_action_header)) {
307 return OFPERR_OFPBAC_BAD_LEN;
308 } else if (a->vendor.vendor != CONSTANT_HTONL(NX_VENDOR_ID)) {
309 return OFPERR_OFPBAC_BAD_VENDOR;
312 switch (nah->subtype) {
313 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
314 case CONSTANT_HTONS(ENUM): \
316 ? len >= sizeof(struct STRUCT) \
317 : len == sizeof(struct STRUCT)) { \
318 *code = OFPUTIL_##ENUM; \
321 return OFPERR_OFPBAC_BAD_LEN; \
324 #include "ofp-util.def"
326 case CONSTANT_HTONS(NXAST_SNAT__OBSOLETE):
327 case CONSTANT_HTONS(NXAST_DROP_SPOOFED_ARP__OBSOLETE):
329 return OFPERR_OFPBAC_BAD_TYPE;
333 /* Parses 'a' to determine its type. On success stores the correct type into
334 * '*code' and returns 0. On failure returns an OFPERR_* error code and
335 * '*code' is indeterminate.
337 * The caller must have already verified that 'a''s length is potentially
338 * correct (that is, a->header.len is nonzero and a multiple of
339 * OFP_ACTION_ALIGN and no longer than the amount of space allocated to 'a').
341 * This function verifies that 'a''s length is correct for the type of action
342 * that it represents. */
344 decode_openflow10_action(const union ofp_action *a,
345 enum ofputil_action_code *code)
348 case CONSTANT_HTONS(OFPAT10_VENDOR):
349 return decode_nxast_action(a, code);
351 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
352 case CONSTANT_HTONS(ENUM): \
353 if (a->header.len == htons(sizeof(struct STRUCT))) { \
354 *code = OFPUTIL_##ENUM; \
357 return OFPERR_OFPBAC_BAD_LEN; \
360 #include "ofp-util.def"
363 return OFPERR_OFPBAC_BAD_TYPE;
368 ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code,
371 struct ofpact_tunnel *tunnel;
372 enum ofperr error = 0;
375 case OFPUTIL_ACTION_INVALID:
376 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) case OFPUTIL_##ENUM:
377 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
378 #include "ofp-util.def"
381 case OFPUTIL_NXAST_RESUBMIT:
382 resubmit_from_openflow(&a->resubmit, out);
385 case OFPUTIL_NXAST_SET_TUNNEL:
386 tunnel = ofpact_put_SET_TUNNEL(out);
387 tunnel->ofpact.compat = code;
388 tunnel->tun_id = ntohl(a->set_tunnel.tun_id);
391 case OFPUTIL_NXAST_WRITE_METADATA:
392 error = metadata_from_nxast(&a->write_metadata, out);
395 case OFPUTIL_NXAST_SET_QUEUE:
396 ofpact_put_SET_QUEUE(out)->queue_id = ntohl(a->set_queue.queue_id);
399 case OFPUTIL_NXAST_POP_QUEUE:
400 ofpact_put_POP_QUEUE(out);
403 case OFPUTIL_NXAST_REG_MOVE:
404 error = nxm_reg_move_from_openflow(&a->reg_move, out);
407 case OFPUTIL_NXAST_REG_LOAD:
408 error = nxm_reg_load_from_openflow(&a->reg_load, out);
411 case OFPUTIL_NXAST_STACK_PUSH:
412 error = nxm_stack_push_from_openflow(&a->stack, out);
415 case OFPUTIL_NXAST_STACK_POP:
416 error = nxm_stack_pop_from_openflow(&a->stack, out);
419 case OFPUTIL_NXAST_NOTE:
420 note_from_openflow(&a->note, out);
423 case OFPUTIL_NXAST_SET_TUNNEL64:
424 tunnel = ofpact_put_SET_TUNNEL(out);
425 tunnel->ofpact.compat = code;
426 tunnel->tun_id = ntohll(a->set_tunnel64.tun_id);
429 case OFPUTIL_NXAST_MULTIPATH:
430 error = multipath_from_openflow(&a->multipath,
431 ofpact_put_MULTIPATH(out));
434 case OFPUTIL_NXAST_BUNDLE:
435 case OFPUTIL_NXAST_BUNDLE_LOAD:
436 error = bundle_from_openflow(&a->bundle, out);
439 case OFPUTIL_NXAST_OUTPUT_REG:
440 error = output_reg_from_openflow(&a->output_reg, out);
443 case OFPUTIL_NXAST_RESUBMIT_TABLE:
444 error = resubmit_table_from_openflow(&a->resubmit, out);
447 case OFPUTIL_NXAST_LEARN:
448 error = learn_from_openflow(&a->learn, out);
451 case OFPUTIL_NXAST_EXIT:
452 ofpact_put_EXIT(out);
455 case OFPUTIL_NXAST_DEC_TTL:
456 error = dec_ttl_from_openflow(out, code);
459 case OFPUTIL_NXAST_DEC_TTL_CNT_IDS:
460 error = dec_ttl_cnt_ids_from_openflow(&a->cnt_ids, out);
463 case OFPUTIL_NXAST_FIN_TIMEOUT:
464 fin_timeout_from_openflow(&a->fin_timeout, out);
467 case OFPUTIL_NXAST_CONTROLLER:
468 controller_from_openflow(&a->controller, out);
471 case OFPUTIL_NXAST_PUSH_MPLS:
472 error = push_mpls_from_openflow(a->push_mpls.ethertype,
473 OFPACT_MPLS_AFTER_VLAN, out);
476 case OFPUTIL_NXAST_SET_MPLS_TTL:
477 ofpact_put_SET_MPLS_TTL(out)->ttl = a->mpls_ttl.ttl;
480 case OFPUTIL_NXAST_DEC_MPLS_TTL:
481 ofpact_put_DEC_MPLS_TTL(out);
484 case OFPUTIL_NXAST_POP_MPLS:
485 if (eth_type_mpls(a->pop_mpls.ethertype)) {
486 return OFPERR_OFPBAC_BAD_ARGUMENT;
488 ofpact_put_POP_MPLS(out)->ethertype = a->pop_mpls.ethertype;
491 case OFPUTIL_NXAST_SAMPLE:
492 error = sample_from_openflow(&a->sample, out);
500 ofpact_from_openflow10(const union ofp_action *a, struct ofpbuf *out)
502 enum ofputil_action_code code;
505 error = decode_openflow10_action(a, &code);
511 case OFPUTIL_ACTION_INVALID:
512 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
513 #include "ofp-util.def"
516 case OFPUTIL_OFPAT10_OUTPUT:
517 return output_from_openflow10(&a->output10, out);
519 case OFPUTIL_OFPAT10_SET_VLAN_VID:
520 if (a->vlan_vid.vlan_vid & ~htons(0xfff)) {
521 return OFPERR_OFPBAC_BAD_ARGUMENT;
523 ofpact_put_SET_VLAN_VID(out)->vlan_vid = ntohs(a->vlan_vid.vlan_vid);
526 case OFPUTIL_OFPAT10_SET_VLAN_PCP:
527 if (a->vlan_pcp.vlan_pcp & ~7) {
528 return OFPERR_OFPBAC_BAD_ARGUMENT;
530 ofpact_put_SET_VLAN_PCP(out)->vlan_pcp = a->vlan_pcp.vlan_pcp;
533 case OFPUTIL_OFPAT10_STRIP_VLAN:
534 ofpact_put_STRIP_VLAN(out);
537 case OFPUTIL_OFPAT10_SET_DL_SRC:
538 memcpy(ofpact_put_SET_ETH_SRC(out)->mac, a->dl_addr.dl_addr,
542 case OFPUTIL_OFPAT10_SET_DL_DST:
543 memcpy(ofpact_put_SET_ETH_DST(out)->mac, a->dl_addr.dl_addr,
547 case OFPUTIL_OFPAT10_SET_NW_SRC:
548 ofpact_put_SET_IPV4_SRC(out)->ipv4 = a->nw_addr.nw_addr;
551 case OFPUTIL_OFPAT10_SET_NW_DST:
552 ofpact_put_SET_IPV4_DST(out)->ipv4 = a->nw_addr.nw_addr;
555 case OFPUTIL_OFPAT10_SET_NW_TOS:
556 if (a->nw_tos.nw_tos & ~IP_DSCP_MASK) {
557 return OFPERR_OFPBAC_BAD_ARGUMENT;
559 ofpact_put_SET_IP_DSCP(out)->dscp = a->nw_tos.nw_tos;
562 case OFPUTIL_OFPAT10_SET_TP_SRC:
563 ofpact_put_SET_L4_SRC_PORT(out)->port = ntohs(a->tp_port.tp_port);
566 case OFPUTIL_OFPAT10_SET_TP_DST:
567 ofpact_put_SET_L4_DST_PORT(out)->port = ntohs(a->tp_port.tp_port);
571 case OFPUTIL_OFPAT10_ENQUEUE:
572 error = enqueue_from_openflow10(&a->enqueue, out);
575 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
576 #include "ofp-util.def"
577 return ofpact_from_nxast(a, code, out);
583 static inline union ofp_action *
584 action_next(const union ofp_action *a)
586 return ((union ofp_action *) (void *)
587 ((uint8_t *) a + ntohs(a->header.len)));
591 action_is_valid(const union ofp_action *a, size_t max_actions)
593 uint16_t len = ntohs(a->header.len);
594 return (!(len % OFP_ACTION_ALIGN)
595 && len >= OFP_ACTION_ALIGN
596 && len / OFP_ACTION_ALIGN <= max_actions);
599 /* This macro is careful to check for actions with bad lengths. */
600 #define ACTION_FOR_EACH(ITER, LEFT, ACTIONS, MAX_ACTIONS) \
601 for ((ITER) = (ACTIONS), (LEFT) = (MAX_ACTIONS); \
602 (LEFT) > 0 && action_is_valid(ITER, LEFT); \
603 ((LEFT) -= ntohs((ITER)->header.len) / OFP_ACTION_ALIGN, \
604 (ITER) = action_next(ITER)))
607 log_bad_action(const union ofp_action *actions, size_t max_actions,
608 const union ofp_action *bad_action, enum ofperr error)
610 if (!VLOG_DROP_WARN(&rl)) {
614 ds_put_hex_dump(&s, actions, max_actions * OFP_ACTION_ALIGN, 0, false);
615 VLOG_WARN("bad action at offset %#tx (%s):\n%s",
616 (char *)bad_action - (char *)actions,
617 ofperr_get_name(error), ds_cstr(&s));
623 ofpacts_from_openflow(const union ofp_action *in, size_t n_in,
625 enum ofperr (*ofpact_from_openflow)(
626 const union ofp_action *a, struct ofpbuf *out))
628 const union ofp_action *a;
631 ACTION_FOR_EACH (a, left, in, n_in) {
632 enum ofperr error = ofpact_from_openflow(a, out);
634 log_bad_action(in, n_in, a, error);
639 enum ofperr error = OFPERR_OFPBAC_BAD_LEN;
640 log_bad_action(in, n_in, a, error);
649 ofpacts_from_openflow10(const union ofp_action *in, size_t n_in,
652 return ofpacts_from_openflow(in, n_in, out, ofpact_from_openflow10);
656 ofpacts_pull_actions(struct ofpbuf *openflow, unsigned int actions_len,
657 struct ofpbuf *ofpacts,
658 enum ofperr (*translate)(const union ofp_action *actions,
660 struct ofpbuf *ofpacts))
662 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
663 const union ofp_action *actions;
666 ofpbuf_clear(ofpacts);
668 if (actions_len % OFP_ACTION_ALIGN != 0) {
669 VLOG_WARN_RL(&rl, "OpenFlow message actions length %u is not a "
670 "multiple of %d", actions_len, OFP_ACTION_ALIGN);
671 return OFPERR_OFPBRC_BAD_LEN;
674 actions = ofpbuf_try_pull(openflow, actions_len);
675 if (actions == NULL) {
676 VLOG_WARN_RL(&rl, "OpenFlow message actions length %u exceeds "
677 "remaining message length (%zu)",
678 actions_len, openflow->size);
679 return OFPERR_OFPBRC_BAD_LEN;
682 error = translate(actions, actions_len / OFP_ACTION_ALIGN, ofpacts);
684 ofpbuf_clear(ofpacts);
688 error = ofpacts_verify(ofpacts->data, ofpacts->size);
690 ofpbuf_clear(ofpacts);
695 /* Attempts to convert 'actions_len' bytes of OpenFlow 1.0 actions from the
696 * front of 'openflow' into ofpacts. On success, replaces any existing content
697 * in 'ofpacts' by the converted ofpacts; on failure, clears 'ofpacts'.
698 * Returns 0 if successful, otherwise an OpenFlow error.
700 * The parsed actions are valid generically, but they may not be valid in a
701 * specific context. For example, port numbers up to OFPP_MAX are valid
702 * generically, but specific datapaths may only support port numbers in a
703 * smaller range. Use ofpacts_check() to additional check whether actions are
704 * valid in a specific context. */
706 ofpacts_pull_openflow10(struct ofpbuf *openflow, unsigned int actions_len,
707 struct ofpbuf *ofpacts)
709 return ofpacts_pull_actions(openflow, actions_len, ofpacts,
710 ofpacts_from_openflow10);
713 /* OpenFlow 1.1 actions. */
715 /* Parses 'a' to determine its type. On success stores the correct type into
716 * '*code' and returns 0. On failure returns an OFPERR_* error code and
717 * '*code' is indeterminate.
719 * The caller must have already verified that 'a''s length is potentially
720 * correct (that is, a->header.len is nonzero and a multiple of
721 * OFP_ACTION_ALIGN and no longer than the amount of space allocated to 'a').
723 * This function verifies that 'a''s length is correct for the type of action
724 * that it represents. */
726 decode_openflow11_action(const union ofp_action *a,
727 enum ofputil_action_code *code)
732 case CONSTANT_HTONS(OFPAT11_EXPERIMENTER):
733 return decode_nxast_action(a, code);
735 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
736 case CONSTANT_HTONS(ENUM): \
737 len = ntohs(a->header.len); \
739 ? len >= sizeof(struct STRUCT) \
740 : len == sizeof(struct STRUCT)) { \
741 *code = OFPUTIL_##ENUM; \
744 return OFPERR_OFPBAC_BAD_LEN; \
747 #include "ofp-util.def"
750 return OFPERR_OFPBAC_BAD_TYPE;
755 output_from_openflow11(const struct ofp11_action_output *oao,
758 struct ofpact_output *output;
761 output = ofpact_put_OUTPUT(out);
762 output->max_len = ntohs(oao->max_len);
764 error = ofputil_port_from_ofp11(oao->port, &output->port);
769 return ofputil_check_output_port(output->port, OFPP_MAX);
773 ofpact_from_openflow11(const union ofp_action *a, struct ofpbuf *out)
775 enum ofputil_action_code code;
778 error = decode_openflow11_action(a, &code);
784 case OFPUTIL_ACTION_INVALID:
785 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) case OFPUTIL_##ENUM:
786 #include "ofp-util.def"
789 case OFPUTIL_OFPAT11_OUTPUT:
790 return output_from_openflow11(&a->ofp11_output, out);
792 case OFPUTIL_OFPAT11_SET_VLAN_VID:
793 if (a->vlan_vid.vlan_vid & ~htons(0xfff)) {
794 return OFPERR_OFPBAC_BAD_ARGUMENT;
796 ofpact_put_SET_VLAN_VID(out)->vlan_vid = ntohs(a->vlan_vid.vlan_vid);
799 case OFPUTIL_OFPAT11_SET_VLAN_PCP:
800 if (a->vlan_pcp.vlan_pcp & ~7) {
801 return OFPERR_OFPBAC_BAD_ARGUMENT;
803 ofpact_put_SET_VLAN_PCP(out)->vlan_pcp = a->vlan_pcp.vlan_pcp;
806 case OFPUTIL_OFPAT11_PUSH_VLAN:
807 if (a->push.ethertype != htons(ETH_TYPE_VLAN_8021Q)) {
808 /* XXX 802.1AD(QinQ) isn't supported at the moment */
809 return OFPERR_OFPBAC_BAD_ARGUMENT;
811 ofpact_put_PUSH_VLAN(out);
814 case OFPUTIL_OFPAT11_POP_VLAN:
815 ofpact_put_STRIP_VLAN(out);
818 case OFPUTIL_OFPAT11_SET_QUEUE:
819 ofpact_put_SET_QUEUE(out)->queue_id =
820 ntohl(a->ofp11_set_queue.queue_id);
823 case OFPUTIL_OFPAT11_SET_DL_SRC:
824 memcpy(ofpact_put_SET_ETH_SRC(out)->mac, a->dl_addr.dl_addr,
828 case OFPUTIL_OFPAT11_SET_DL_DST:
829 memcpy(ofpact_put_SET_ETH_DST(out)->mac, a->dl_addr.dl_addr,
833 case OFPUTIL_OFPAT11_DEC_NW_TTL:
834 dec_ttl_from_openflow(out, code);
837 case OFPUTIL_OFPAT11_SET_NW_SRC:
838 ofpact_put_SET_IPV4_SRC(out)->ipv4 = a->nw_addr.nw_addr;
841 case OFPUTIL_OFPAT11_SET_NW_DST:
842 ofpact_put_SET_IPV4_DST(out)->ipv4 = a->nw_addr.nw_addr;
845 case OFPUTIL_OFPAT11_SET_NW_TOS:
846 if (a->nw_tos.nw_tos & ~IP_DSCP_MASK) {
847 return OFPERR_OFPBAC_BAD_ARGUMENT;
849 ofpact_put_SET_IP_DSCP(out)->dscp = a->nw_tos.nw_tos;
852 case OFPUTIL_OFPAT11_SET_NW_ECN:
853 if (a->nw_ecn.nw_ecn & ~IP_ECN_MASK) {
854 return OFPERR_OFPBAC_BAD_ARGUMENT;
856 ofpact_put_SET_IP_ECN(out)->ecn = a->nw_ecn.nw_ecn;
859 case OFPUTIL_OFPAT11_SET_NW_TTL:
860 ofpact_put_SET_IP_TTL(out)->ttl = a->nw_ttl.nw_ttl;
863 case OFPUTIL_OFPAT11_SET_TP_SRC:
864 ofpact_put_SET_L4_SRC_PORT(out)->port = ntohs(a->tp_port.tp_port);
867 case OFPUTIL_OFPAT11_SET_TP_DST:
868 ofpact_put_SET_L4_DST_PORT(out)->port = ntohs(a->tp_port.tp_port);
871 case OFPUTIL_OFPAT12_SET_FIELD:
872 return nxm_reg_load_from_openflow12_set_field(&a->set_field, out);
874 case OFPUTIL_OFPAT11_SET_MPLS_TTL:
875 ofpact_put_SET_MPLS_TTL(out)->ttl = a->ofp11_mpls_ttl.mpls_ttl;
878 case OFPUTIL_OFPAT11_DEC_MPLS_TTL:
879 ofpact_put_DEC_MPLS_TTL(out);
882 case OFPUTIL_OFPAT11_PUSH_MPLS:
883 error = push_mpls_from_openflow(a->push.ethertype,
884 OFPACT_MPLS_AFTER_VLAN, out);
887 case OFPUTIL_OFPAT11_POP_MPLS:
888 if (eth_type_mpls(a->ofp11_pop_mpls.ethertype)) {
889 return OFPERR_OFPBAC_BAD_ARGUMENT;
891 ofpact_put_POP_MPLS(out)->ethertype = a->ofp11_pop_mpls.ethertype;
894 case OFPUTIL_OFPAT11_GROUP:
895 ofpact_put_GROUP(out)->group_id = ntohl(a->group.group_id);
898 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
899 #include "ofp-util.def"
900 return ofpact_from_nxast(a, code, out);
907 ofpacts_from_openflow11(const union ofp_action *in, size_t n_in,
910 return ofpacts_from_openflow(in, n_in, out, ofpact_from_openflow11);
913 /* True if an action sets the value of a field
914 * in a way that is compatibile with the action set.
915 * False otherwise. */
917 ofpact_is_set_action(const struct ofpact *a)
920 case OFPACT_REG_LOAD:
921 case OFPACT_SET_ETH_DST:
922 case OFPACT_SET_ETH_SRC:
923 case OFPACT_SET_IP_DSCP:
924 case OFPACT_SET_IP_ECN:
925 case OFPACT_SET_IP_TTL:
926 case OFPACT_SET_IPV4_DST:
927 case OFPACT_SET_IPV4_SRC:
928 case OFPACT_SET_L4_DST_PORT:
929 case OFPACT_SET_L4_SRC_PORT:
930 case OFPACT_SET_MPLS_TTL:
931 case OFPACT_SET_QUEUE:
932 case OFPACT_SET_TUNNEL:
933 case OFPACT_SET_VLAN_PCP:
934 case OFPACT_SET_VLAN_VID:
937 case OFPACT_CLEAR_ACTIONS:
938 case OFPACT_CONTROLLER:
939 case OFPACT_DEC_MPLS_TTL:
943 case OFPACT_FIN_TIMEOUT:
944 case OFPACT_GOTO_TABLE:
948 case OFPACT_MULTIPATH:
951 case OFPACT_OUTPUT_REG:
952 case OFPACT_POP_MPLS:
953 case OFPACT_POP_QUEUE:
954 case OFPACT_PUSH_MPLS:
955 case OFPACT_PUSH_VLAN:
956 case OFPACT_REG_MOVE:
957 case OFPACT_RESUBMIT:
959 case OFPACT_STACK_POP:
960 case OFPACT_STACK_PUSH:
961 case OFPACT_STRIP_VLAN:
962 case OFPACT_WRITE_ACTIONS:
963 case OFPACT_WRITE_METADATA:
970 /* True if an action is allowed in the action set.
971 * False otherwise. */
973 ofpact_is_allowed_in_actions_set(const struct ofpact *a)
976 case OFPACT_DEC_MPLS_TTL:
980 case OFPACT_POP_MPLS:
981 case OFPACT_PUSH_MPLS:
982 case OFPACT_PUSH_VLAN:
983 case OFPACT_REG_LOAD:
984 case OFPACT_SET_ETH_DST:
985 case OFPACT_SET_ETH_SRC:
986 case OFPACT_SET_IP_DSCP:
987 case OFPACT_SET_IP_ECN:
988 case OFPACT_SET_IP_TTL:
989 case OFPACT_SET_IPV4_DST:
990 case OFPACT_SET_IPV4_SRC:
991 case OFPACT_SET_L4_DST_PORT:
992 case OFPACT_SET_L4_SRC_PORT:
993 case OFPACT_SET_MPLS_TTL:
994 case OFPACT_SET_QUEUE:
995 case OFPACT_SET_TUNNEL:
996 case OFPACT_SET_VLAN_PCP:
997 case OFPACT_SET_VLAN_VID:
998 case OFPACT_STRIP_VLAN:
1001 /* In general these actions are excluded because they are not part of
1002 * the OpenFlow specification nor map to actions that are defined in
1003 * the specification. Thus the order in which they should be applied
1004 * in the action set is undefined. */
1006 case OFPACT_CONTROLLER:
1007 case OFPACT_ENQUEUE:
1009 case OFPACT_FIN_TIMEOUT:
1011 case OFPACT_MULTIPATH:
1013 case OFPACT_OUTPUT_REG:
1014 case OFPACT_POP_QUEUE:
1015 case OFPACT_REG_MOVE:
1016 case OFPACT_RESUBMIT:
1018 case OFPACT_STACK_POP:
1019 case OFPACT_STACK_PUSH:
1021 /* The action set may only include actions and thus
1022 * may not include any instructions */
1023 case OFPACT_CLEAR_ACTIONS:
1024 case OFPACT_GOTO_TABLE:
1026 case OFPACT_WRITE_ACTIONS:
1027 case OFPACT_WRITE_METADATA:
1034 /* Append ofpact 'a' onto the tail of 'out' */
1036 ofpact_copy(struct ofpbuf *out, const struct ofpact *a)
1038 ofpbuf_put(out, a, OFPACT_ALIGN(a->len));
1041 /* Copies the last ofpact whose type is 'filter' from 'in' to 'out'. */
1043 ofpacts_copy_last(struct ofpbuf *out, const struct ofpbuf *in,
1044 enum ofpact_type filter)
1046 const struct ofpact *target;
1047 const struct ofpact *a;
1050 OFPACT_FOR_EACH (a, in->data, in->size) {
1051 if (a->type == filter) {
1056 ofpact_copy(out, target);
1058 return target != NULL;
1061 /* Append all ofpacts, for which 'filter' returns true, from 'in' to 'out'.
1062 * The order of appended ofpacts is preserved between 'in' and 'out' */
1064 ofpacts_copy_all(struct ofpbuf *out, const struct ofpbuf *in,
1065 bool (*filter)(const struct ofpact *))
1067 const struct ofpact *a;
1069 OFPACT_FOR_EACH (a, in->data, in->size) {
1071 ofpact_copy(out, a);
1076 /* Reads 'action_set', which contains ofpacts accumulated by
1077 * OFPACT_WRITE_ACTIONS instructions, and writes equivalent actions to be
1078 * executed directly into 'action_list'. (These names correspond to the
1079 * "Action Set" and "Action List" terms used in OpenFlow 1.1+.)
1081 * In general this involves appending the last instance of each action that is
1082 * adimissible in the action set in the order described in the OpenFlow
1086 * + output action is only appended if no group action was present in 'in'.
1087 * + As a simplification all set actions are copied in the order the are
1088 * provided in 'in' as many set actions applied to a field has the same
1089 * affect as only applying the last action that sets a field and
1090 * duplicates are removed by do_xlate_actions().
1091 * This has an unwanted side-effect of compsoting multiple
1092 * LOAD_REG actions that touch different regions of the same field. */
1094 ofpacts_execute_action_set(struct ofpbuf *action_list,
1095 const struct ofpbuf *action_set)
1097 /* The OpenFlow spec "Action Set" section specifies this order. */
1098 ofpacts_copy_last(action_list, action_set, OFPACT_STRIP_VLAN);
1099 ofpacts_copy_last(action_list, action_set, OFPACT_POP_MPLS);
1100 ofpacts_copy_last(action_list, action_set, OFPACT_PUSH_MPLS);
1101 ofpacts_copy_last(action_list, action_set, OFPACT_PUSH_VLAN);
1102 ofpacts_copy_last(action_list, action_set, OFPACT_DEC_TTL);
1103 ofpacts_copy_last(action_list, action_set, OFPACT_DEC_MPLS_TTL);
1104 ofpacts_copy_all(action_list, action_set, ofpact_is_set_action);
1105 ofpacts_copy_last(action_list, action_set, OFPACT_SET_QUEUE);
1107 /* If both OFPACT_GROUP and OFPACT_OUTPUT are present, OpenFlow says that
1108 * we should execute only OFPACT_GROUP.
1110 * If neither OFPACT_GROUP nor OFPACT_OUTPUT is present, then we can drop
1111 * all the actions because there's no point in modifying a packet that will
1112 * not be sent anywhere. */
1113 if (!ofpacts_copy_last(action_list, action_set, OFPACT_GROUP) &&
1114 !ofpacts_copy_last(action_list, action_set, OFPACT_OUTPUT)) {
1115 ofpbuf_clear(action_list);
1121 ofpacts_from_openflow11_for_action_set(const union ofp_action *in,
1122 size_t n_in, struct ofpbuf *out)
1126 size_t start = out->size;
1128 error = ofpacts_from_openflow11(in, n_in, out);
1133 OFPACT_FOR_EACH (a, ofpact_end(out->data, start), out->size - start) {
1134 if (!ofpact_is_allowed_in_actions_set(a)) {
1135 VLOG_WARN_RL(&rl, "disallowed action in action set");
1136 return OFPERR_OFPBAC_BAD_TYPE;
1145 ofpact_from_openflow13(const union ofp_action *a, struct ofpbuf *out)
1147 enum ofputil_action_code code;
1150 error = decode_openflow11_action(a, &code);
1155 if (code == OFPUTIL_OFPAT11_PUSH_MPLS) {
1156 struct ofp11_action_push *oap = (struct ofp11_action_push *)a;
1157 error = push_mpls_from_openflow(oap->ethertype,
1158 OFPACT_MPLS_BEFORE_VLAN, out);
1160 error = ofpact_from_openflow11(a, out);
1167 ofpacts_from_openflow13(const union ofp_action *in, size_t n_in,
1170 return ofpacts_from_openflow(in, n_in, out, ofpact_from_openflow13);
1173 /* OpenFlow 1.1 instructions. */
1175 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \
1176 static inline const struct STRUCT * OVS_UNUSED \
1177 instruction_get_##ENUM(const struct ofp11_instruction *inst)\
1179 ovs_assert(inst->type == htons(ENUM)); \
1180 return ALIGNED_CAST(struct STRUCT *, inst); \
1183 static inline void OVS_UNUSED \
1184 instruction_init_##ENUM(struct STRUCT *s) \
1186 memset(s, 0, sizeof *s); \
1187 s->type = htons(ENUM); \
1188 s->len = htons(sizeof *s); \
1191 static inline struct STRUCT * OVS_UNUSED \
1192 instruction_put_##ENUM(struct ofpbuf *buf) \
1194 struct STRUCT *s = ofpbuf_put_uninit(buf, sizeof *s); \
1195 instruction_init_##ENUM(s); \
1201 struct instruction_type_info {
1202 enum ovs_instruction_type type;
1206 static const struct instruction_type_info inst_info[] = {
1207 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) {OVSINST_##ENUM, NAME},
1213 ovs_instruction_name_from_type(enum ovs_instruction_type type)
1215 return inst_info[type].name;
1219 ovs_instruction_type_from_name(const char *name)
1221 const struct instruction_type_info *p;
1222 for (p = inst_info; p < &inst_info[ARRAY_SIZE(inst_info)]; p++) {
1223 if (!strcasecmp(name, p->name)) {
1230 enum ovs_instruction_type
1231 ovs_instruction_type_from_ofpact_type(enum ofpact_type type)
1235 return OVSINST_OFPIT13_METER;
1236 case OFPACT_CLEAR_ACTIONS:
1237 return OVSINST_OFPIT11_CLEAR_ACTIONS;
1238 case OFPACT_WRITE_ACTIONS:
1239 return OVSINST_OFPIT11_WRITE_ACTIONS;
1240 case OFPACT_WRITE_METADATA:
1241 return OVSINST_OFPIT11_WRITE_METADATA;
1242 case OFPACT_GOTO_TABLE:
1243 return OVSINST_OFPIT11_GOTO_TABLE;
1246 case OFPACT_CONTROLLER:
1247 case OFPACT_ENQUEUE:
1248 case OFPACT_OUTPUT_REG:
1250 case OFPACT_SET_VLAN_VID:
1251 case OFPACT_SET_VLAN_PCP:
1252 case OFPACT_STRIP_VLAN:
1253 case OFPACT_PUSH_VLAN:
1254 case OFPACT_SET_ETH_SRC:
1255 case OFPACT_SET_ETH_DST:
1256 case OFPACT_SET_IPV4_SRC:
1257 case OFPACT_SET_IPV4_DST:
1258 case OFPACT_SET_IP_DSCP:
1259 case OFPACT_SET_IP_ECN:
1260 case OFPACT_SET_IP_TTL:
1261 case OFPACT_SET_L4_SRC_PORT:
1262 case OFPACT_SET_L4_DST_PORT:
1263 case OFPACT_REG_MOVE:
1264 case OFPACT_REG_LOAD:
1265 case OFPACT_STACK_PUSH:
1266 case OFPACT_STACK_POP:
1267 case OFPACT_DEC_TTL:
1268 case OFPACT_SET_MPLS_TTL:
1269 case OFPACT_DEC_MPLS_TTL:
1270 case OFPACT_PUSH_MPLS:
1271 case OFPACT_POP_MPLS:
1272 case OFPACT_SET_TUNNEL:
1273 case OFPACT_SET_QUEUE:
1274 case OFPACT_POP_QUEUE:
1275 case OFPACT_FIN_TIMEOUT:
1276 case OFPACT_RESUBMIT:
1278 case OFPACT_MULTIPATH:
1283 return OVSINST_OFPIT11_APPLY_ACTIONS;
1287 static inline struct ofp11_instruction *
1288 instruction_next(const struct ofp11_instruction *inst)
1290 return ((struct ofp11_instruction *) (void *)
1291 ((uint8_t *) inst + ntohs(inst->len)));
1295 instruction_is_valid(const struct ofp11_instruction *inst,
1296 size_t n_instructions)
1298 uint16_t len = ntohs(inst->len);
1299 return (!(len % OFP11_INSTRUCTION_ALIGN)
1300 && len >= sizeof *inst
1301 && len / sizeof *inst <= n_instructions);
1304 /* This macro is careful to check for instructions with bad lengths. */
1305 #define INSTRUCTION_FOR_EACH(ITER, LEFT, INSTRUCTIONS, N_INSTRUCTIONS) \
1306 for ((ITER) = (INSTRUCTIONS), (LEFT) = (N_INSTRUCTIONS); \
1307 (LEFT) > 0 && instruction_is_valid(ITER, LEFT); \
1308 ((LEFT) -= (ntohs((ITER)->len) \
1309 / sizeof(struct ofp11_instruction)), \
1310 (ITER) = instruction_next(ITER)))
1313 decode_openflow11_instruction(const struct ofp11_instruction *inst,
1314 enum ovs_instruction_type *type)
1316 uint16_t len = ntohs(inst->len);
1318 switch (inst->type) {
1319 case CONSTANT_HTONS(OFPIT11_EXPERIMENTER):
1320 return OFPERR_OFPBIC_BAD_EXPERIMENTER;
1322 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \
1323 case CONSTANT_HTONS(ENUM): \
1325 ? len >= sizeof(struct STRUCT) \
1326 : len == sizeof(struct STRUCT)) { \
1327 *type = OVSINST_##ENUM; \
1330 return OFPERR_OFPBIC_BAD_LEN; \
1336 return OFPERR_OFPBIC_UNKNOWN_INST;
1341 decode_openflow11_instructions(const struct ofp11_instruction insts[],
1343 const struct ofp11_instruction *out[])
1345 const struct ofp11_instruction *inst;
1348 memset(out, 0, N_OVS_INSTRUCTIONS * sizeof *out);
1349 INSTRUCTION_FOR_EACH (inst, left, insts, n_insts) {
1350 enum ovs_instruction_type type;
1353 error = decode_openflow11_instruction(inst, &type);
1359 return OFPERR_ONFBIC_DUP_INSTRUCTION;
1365 VLOG_WARN_RL(&rl, "bad instruction format at offset %zu",
1366 (n_insts - left) * sizeof *inst);
1367 return OFPERR_OFPBIC_BAD_LEN;
1373 get_actions_from_instruction(const struct ofp11_instruction *inst,
1374 const union ofp_action **actions,
1375 size_t *max_actions)
1377 *actions = ALIGNED_CAST(const union ofp_action *, inst + 1);
1378 *max_actions = (ntohs(inst->len) - sizeof *inst) / OFP11_INSTRUCTION_ALIGN;
1381 /* Attempts to convert 'actions_len' bytes of OpenFlow actions from the
1382 * front of 'openflow' into ofpacts. On success, replaces any existing content
1383 * in 'ofpacts' by the converted ofpacts; on failure, clears 'ofpacts'.
1384 * Returns 0 if successful, otherwise an OpenFlow error.
1386 * Actions are processed according to their OpenFlow version which
1387 * is provided in the 'version' parameter.
1389 * In most places in OpenFlow 1.1 and 1.2, actions appear encapsulated in
1390 * instructions, so you should call ofpacts_pull_openflow11_instructions()
1391 * instead of this function.
1393 * The parsed actions are valid generically, but they may not be valid in a
1394 * specific context. For example, port numbers up to OFPP_MAX are valid
1395 * generically, but specific datapaths may only support port numbers in a
1396 * smaller range. Use ofpacts_check() to additional check whether actions are
1397 * valid in a specific context. */
1399 ofpacts_pull_openflow11_actions(struct ofpbuf *openflow,
1400 enum ofp_version version,
1401 unsigned int actions_len,
1402 struct ofpbuf *ofpacts)
1408 return ofpacts_pull_actions(openflow, actions_len, ofpacts,
1409 ofpacts_from_openflow11);
1411 return ofpacts_pull_actions(openflow, actions_len, ofpacts,
1412 ofpacts_from_openflow13);
1419 ofpacts_pull_openflow11_instructions(struct ofpbuf *openflow,
1420 enum ofp_version version,
1421 unsigned int instructions_len,
1422 struct ofpbuf *ofpacts)
1424 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1425 const struct ofp11_instruction *instructions;
1426 const struct ofp11_instruction *insts[N_OVS_INSTRUCTIONS];
1429 ofpbuf_clear(ofpacts);
1431 if (instructions_len % OFP11_INSTRUCTION_ALIGN != 0) {
1432 VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u is not a "
1434 instructions_len, OFP11_INSTRUCTION_ALIGN);
1435 error = OFPERR_OFPBIC_BAD_LEN;
1439 instructions = ofpbuf_try_pull(openflow, instructions_len);
1440 if (instructions == NULL) {
1441 VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u exceeds "
1442 "remaining message length (%zu)",
1443 instructions_len, openflow->size);
1444 error = OFPERR_OFPBIC_BAD_LEN;
1448 error = decode_openflow11_instructions(
1449 instructions, instructions_len / OFP11_INSTRUCTION_ALIGN,
1455 if (insts[OVSINST_OFPIT13_METER]) {
1456 const struct ofp13_instruction_meter *oim;
1457 struct ofpact_meter *om;
1459 oim = ALIGNED_CAST(const struct ofp13_instruction_meter *,
1460 insts[OVSINST_OFPIT13_METER]);
1462 om = ofpact_put_METER(ofpacts);
1463 om->meter_id = ntohl(oim->meter_id);
1465 if (insts[OVSINST_OFPIT11_APPLY_ACTIONS]) {
1466 const union ofp_action *actions;
1469 get_actions_from_instruction(insts[OVSINST_OFPIT11_APPLY_ACTIONS],
1470 &actions, &max_actions);
1475 error = ofpacts_from_openflow11(actions, max_actions, ofpacts);
1478 error = ofpacts_from_openflow13(actions, max_actions, ofpacts);
1487 if (insts[OVSINST_OFPIT11_CLEAR_ACTIONS]) {
1488 instruction_get_OFPIT11_CLEAR_ACTIONS(
1489 insts[OVSINST_OFPIT11_CLEAR_ACTIONS]);
1490 ofpact_put_CLEAR_ACTIONS(ofpacts);
1492 if (insts[OVSINST_OFPIT11_WRITE_ACTIONS]) {
1493 struct ofpact_nest *on;
1494 const union ofp_action *actions;
1498 ofpact_pad(ofpacts);
1499 start = ofpacts->size;
1500 on = ofpact_put(ofpacts, OFPACT_WRITE_ACTIONS,
1501 offsetof(struct ofpact_nest, actions));
1502 get_actions_from_instruction(insts[OVSINST_OFPIT11_WRITE_ACTIONS],
1503 &actions, &max_actions);
1504 error = ofpacts_from_openflow11_for_action_set(actions, max_actions,
1509 on = ofpbuf_at_assert(ofpacts, start, sizeof *on);
1510 on->ofpact.len = ofpacts->size - start;
1512 if (insts[OVSINST_OFPIT11_WRITE_METADATA]) {
1513 const struct ofp11_instruction_write_metadata *oiwm;
1514 struct ofpact_metadata *om;
1516 oiwm = ALIGNED_CAST(const struct ofp11_instruction_write_metadata *,
1517 insts[OVSINST_OFPIT11_WRITE_METADATA]);
1519 om = ofpact_put_WRITE_METADATA(ofpacts);
1520 om->metadata = oiwm->metadata;
1521 om->mask = oiwm->metadata_mask;
1523 if (insts[OVSINST_OFPIT11_GOTO_TABLE]) {
1524 const struct ofp11_instruction_goto_table *oigt;
1525 struct ofpact_goto_table *ogt;
1527 oigt = instruction_get_OFPIT11_GOTO_TABLE(
1528 insts[OVSINST_OFPIT11_GOTO_TABLE]);
1529 ogt = ofpact_put_GOTO_TABLE(ofpacts);
1530 ogt->table_id = oigt->table_id;
1533 error = ofpacts_verify(ofpacts->data, ofpacts->size);
1536 ofpbuf_clear(ofpacts);
1541 /* May modify flow->dl_type, caller must restore it. */
1543 ofpact_check__(const struct ofpact *a, struct flow *flow, ofp_port_t max_ports,
1546 const struct ofpact_enqueue *enqueue;
1550 return ofputil_check_output_port(ofpact_get_OUTPUT(a)->port,
1553 case OFPACT_CONTROLLER:
1556 case OFPACT_ENQUEUE:
1557 enqueue = ofpact_get_ENQUEUE(a);
1558 if (ofp_to_u16(enqueue->port) >= ofp_to_u16(max_ports)
1559 && enqueue->port != OFPP_IN_PORT
1560 && enqueue->port != OFPP_LOCAL) {
1561 return OFPERR_OFPBAC_BAD_OUT_PORT;
1565 case OFPACT_OUTPUT_REG:
1566 return mf_check_src(&ofpact_get_OUTPUT_REG(a)->src, flow);
1569 return bundle_check(ofpact_get_BUNDLE(a), max_ports, flow);
1571 case OFPACT_SET_VLAN_VID:
1572 case OFPACT_SET_VLAN_PCP:
1573 case OFPACT_STRIP_VLAN:
1574 case OFPACT_PUSH_VLAN:
1575 case OFPACT_SET_ETH_SRC:
1576 case OFPACT_SET_ETH_DST:
1577 case OFPACT_SET_IPV4_SRC:
1578 case OFPACT_SET_IPV4_DST:
1579 case OFPACT_SET_IP_DSCP:
1580 case OFPACT_SET_IP_ECN:
1581 case OFPACT_SET_IP_TTL:
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_IP_TTL:
1970 case OFPACT_SET_L4_SRC_PORT:
1971 case OFPACT_SET_L4_DST_PORT:
1972 case OFPACT_WRITE_ACTIONS:
1973 case OFPACT_CLEAR_ACTIONS:
1974 case OFPACT_GOTO_TABLE:
1980 /* Converting ofpacts to OpenFlow 1.0. */
1983 ofpact_output_to_openflow10(const struct ofpact_output *output,
1986 struct ofp10_action_output *oao;
1988 oao = ofputil_put_OFPAT10_OUTPUT(out);
1989 oao->port = htons(ofp_to_u16(output->port));
1990 oao->max_len = htons(output->max_len);
1994 ofpact_enqueue_to_openflow10(const struct ofpact_enqueue *enqueue,
1997 struct ofp10_action_enqueue *oae;
1999 oae = ofputil_put_OFPAT10_ENQUEUE(out);
2000 oae->port = htons(ofp_to_u16(enqueue->port));
2001 oae->queue_id = htonl(enqueue->queue);
2005 ofpact_to_openflow10(const struct ofpact *a, struct ofpbuf *out)
2009 ofpact_output_to_openflow10(ofpact_get_OUTPUT(a), out);
2012 case OFPACT_ENQUEUE:
2013 ofpact_enqueue_to_openflow10(ofpact_get_ENQUEUE(a), out);
2016 case OFPACT_SET_VLAN_VID:
2017 ofputil_put_OFPAT10_SET_VLAN_VID(out)->vlan_vid
2018 = htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid);
2021 case OFPACT_SET_VLAN_PCP:
2022 ofputil_put_OFPAT10_SET_VLAN_PCP(out)->vlan_pcp
2023 = ofpact_get_SET_VLAN_PCP(a)->vlan_pcp;
2026 case OFPACT_STRIP_VLAN:
2027 ofputil_put_OFPAT10_STRIP_VLAN(out);
2030 case OFPACT_SET_ETH_SRC:
2031 memcpy(ofputil_put_OFPAT10_SET_DL_SRC(out)->dl_addr,
2032 ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
2035 case OFPACT_SET_ETH_DST:
2036 memcpy(ofputil_put_OFPAT10_SET_DL_DST(out)->dl_addr,
2037 ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
2040 case OFPACT_SET_IPV4_SRC:
2041 ofputil_put_OFPAT10_SET_NW_SRC(out)->nw_addr
2042 = ofpact_get_SET_IPV4_SRC(a)->ipv4;
2045 case OFPACT_SET_IPV4_DST:
2046 ofputil_put_OFPAT10_SET_NW_DST(out)->nw_addr
2047 = ofpact_get_SET_IPV4_DST(a)->ipv4;
2050 case OFPACT_SET_IP_DSCP:
2051 ofputil_put_OFPAT10_SET_NW_TOS(out)->nw_tos
2052 = ofpact_get_SET_IP_DSCP(a)->dscp;
2055 case OFPACT_SET_L4_SRC_PORT:
2056 ofputil_put_OFPAT10_SET_TP_SRC(out)->tp_port
2057 = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
2060 case OFPACT_SET_L4_DST_PORT:
2061 ofputil_put_OFPAT10_SET_TP_DST(out)->tp_port
2062 = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
2065 case OFPACT_PUSH_VLAN:
2066 case OFPACT_CLEAR_ACTIONS:
2067 case OFPACT_WRITE_ACTIONS:
2068 case OFPACT_GOTO_TABLE:
2076 case OFPACT_CONTROLLER:
2077 case OFPACT_OUTPUT_REG:
2079 case OFPACT_REG_MOVE:
2080 case OFPACT_REG_LOAD:
2081 case OFPACT_STACK_PUSH:
2082 case OFPACT_STACK_POP:
2083 case OFPACT_DEC_TTL:
2084 case OFPACT_SET_IP_ECN:
2085 case OFPACT_SET_IP_TTL:
2086 case OFPACT_SET_MPLS_TTL:
2087 case OFPACT_DEC_MPLS_TTL:
2088 case OFPACT_SET_TUNNEL:
2089 case OFPACT_WRITE_METADATA:
2090 case OFPACT_SET_QUEUE:
2091 case OFPACT_POP_QUEUE:
2092 case OFPACT_FIN_TIMEOUT:
2093 case OFPACT_RESUBMIT:
2095 case OFPACT_MULTIPATH:
2098 case OFPACT_PUSH_MPLS:
2099 case OFPACT_POP_MPLS:
2101 ofpact_to_nxast(a, out);
2106 /* Converts the 'ofpacts_len' bytes of ofpacts in 'ofpacts' into OpenFlow 1.0
2107 * actions in 'openflow', appending the actions to any existing data in
2110 ofpacts_put_openflow10(const struct ofpact ofpacts[], size_t ofpacts_len,
2111 struct ofpbuf *openflow)
2113 const struct ofpact *a;
2115 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2116 ofpact_to_openflow10(a, openflow);
2120 /* Converting ofpacts to OpenFlow 1.1. */
2123 ofpact_output_to_openflow11(const struct ofpact_output *output,
2126 struct ofp11_action_output *oao;
2128 oao = ofputil_put_OFPAT11_OUTPUT(out);
2129 oao->port = ofputil_port_to_ofp11(output->port);
2130 oao->max_len = htons(output->max_len);
2134 ofpact_dec_ttl_to_openflow11(const struct ofpact_cnt_ids *dec_ttl,
2137 if (dec_ttl->n_controllers == 1 && dec_ttl->cnt_ids[0] == 0
2138 && (!dec_ttl->ofpact.compat ||
2139 dec_ttl->ofpact.compat == OFPUTIL_OFPAT11_DEC_NW_TTL)) {
2140 ofputil_put_OFPAT11_DEC_NW_TTL(out);
2142 ofpact_dec_ttl_to_nxast(dec_ttl, out);
2147 ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out)
2151 return ofpact_output_to_openflow11(ofpact_get_OUTPUT(a), out);
2153 case OFPACT_ENQUEUE:
2157 case OFPACT_SET_VLAN_VID:
2158 ofputil_put_OFPAT11_SET_VLAN_VID(out)->vlan_vid
2159 = htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid);
2162 case OFPACT_SET_VLAN_PCP:
2163 ofputil_put_OFPAT11_SET_VLAN_PCP(out)->vlan_pcp
2164 = ofpact_get_SET_VLAN_PCP(a)->vlan_pcp;
2167 case OFPACT_STRIP_VLAN:
2168 ofputil_put_OFPAT11_POP_VLAN(out);
2171 case OFPACT_PUSH_VLAN:
2172 /* XXX ETH_TYPE_VLAN_8021AD case */
2173 ofputil_put_OFPAT11_PUSH_VLAN(out)->ethertype =
2174 htons(ETH_TYPE_VLAN_8021Q);
2177 case OFPACT_SET_QUEUE:
2178 ofputil_put_OFPAT11_SET_QUEUE(out)->queue_id
2179 = htonl(ofpact_get_SET_QUEUE(a)->queue_id);
2182 case OFPACT_SET_ETH_SRC:
2183 memcpy(ofputil_put_OFPAT11_SET_DL_SRC(out)->dl_addr,
2184 ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
2187 case OFPACT_SET_ETH_DST:
2188 memcpy(ofputil_put_OFPAT11_SET_DL_DST(out)->dl_addr,
2189 ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
2192 case OFPACT_SET_IPV4_SRC:
2193 ofputil_put_OFPAT11_SET_NW_SRC(out)->nw_addr
2194 = ofpact_get_SET_IPV4_SRC(a)->ipv4;
2197 case OFPACT_SET_IPV4_DST:
2198 ofputil_put_OFPAT11_SET_NW_DST(out)->nw_addr
2199 = ofpact_get_SET_IPV4_DST(a)->ipv4;
2202 case OFPACT_SET_IP_DSCP:
2203 ofputil_put_OFPAT11_SET_NW_TOS(out)->nw_tos
2204 = ofpact_get_SET_IP_DSCP(a)->dscp;
2207 case OFPACT_SET_IP_ECN:
2208 ofputil_put_OFPAT11_SET_NW_ECN(out)->nw_ecn
2209 = ofpact_get_SET_IP_ECN(a)->ecn;
2212 case OFPACT_SET_IP_TTL:
2213 ofputil_put_OFPAT11_SET_NW_TTL(out)->nw_ttl
2214 = ofpact_get_SET_IP_TTL(a)->ttl;
2217 case OFPACT_SET_L4_SRC_PORT:
2218 ofputil_put_OFPAT11_SET_TP_SRC(out)->tp_port
2219 = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
2222 case OFPACT_SET_L4_DST_PORT:
2223 ofputil_put_OFPAT11_SET_TP_DST(out)->tp_port
2224 = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
2227 case OFPACT_DEC_TTL:
2228 ofpact_dec_ttl_to_openflow11(ofpact_get_DEC_TTL(a), out);
2231 case OFPACT_SET_MPLS_TTL:
2232 ofputil_put_OFPAT11_SET_MPLS_TTL(out)->mpls_ttl
2233 = ofpact_get_SET_MPLS_TTL(a)->ttl;
2236 case OFPACT_DEC_MPLS_TTL:
2237 ofputil_put_OFPAT11_DEC_MPLS_TTL(out);
2240 case OFPACT_WRITE_METADATA:
2241 /* OpenFlow 1.1 uses OFPIT_WRITE_METADATA to express this action. */
2244 case OFPACT_PUSH_MPLS:
2245 ofputil_put_OFPAT11_PUSH_MPLS(out)->ethertype =
2246 ofpact_get_PUSH_MPLS(a)->ethertype;
2249 case OFPACT_POP_MPLS:
2250 ofputil_put_OFPAT11_POP_MPLS(out)->ethertype =
2251 ofpact_get_POP_MPLS(a)->ethertype;
2255 case OFPACT_CLEAR_ACTIONS:
2256 case OFPACT_WRITE_ACTIONS:
2257 case OFPACT_GOTO_TABLE:
2262 ofputil_put_OFPAT11_GROUP(out)->group_id =
2263 htonl(ofpact_get_GROUP(a)->group_id);
2266 case OFPACT_CONTROLLER:
2267 case OFPACT_OUTPUT_REG:
2269 case OFPACT_REG_MOVE:
2270 case OFPACT_REG_LOAD:
2271 case OFPACT_STACK_PUSH:
2272 case OFPACT_STACK_POP:
2273 case OFPACT_SET_TUNNEL:
2274 case OFPACT_POP_QUEUE:
2275 case OFPACT_FIN_TIMEOUT:
2276 case OFPACT_RESUBMIT:
2278 case OFPACT_MULTIPATH:
2282 ofpact_to_nxast(a, out);
2287 /* Converts the ofpacts in 'ofpacts' (terminated by OFPACT_END) into OpenFlow
2288 * 1.1 actions in 'openflow', appending the actions to any existing data in
2291 ofpacts_put_openflow11_actions(const struct ofpact ofpacts[],
2292 size_t ofpacts_len, struct ofpbuf *openflow)
2294 const struct ofpact *a;
2295 size_t start_size = openflow->size;
2297 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2298 ofpact_to_openflow11(a, openflow);
2301 return openflow->size - start_size;
2305 ofpacts_update_instruction_actions(struct ofpbuf *openflow, size_t ofs)
2307 struct ofp11_instruction_actions *oia;
2309 /* Update the instruction's length (or, if it's empty, delete it). */
2310 oia = ofpbuf_at_assert(openflow, ofs, sizeof *oia);
2311 if (openflow->size > ofs + sizeof *oia) {
2312 oia->len = htons(openflow->size - ofs);
2314 openflow->size = ofs;
2319 ofpacts_put_openflow11_instructions(const struct ofpact ofpacts[],
2321 struct ofpbuf *openflow)
2323 const struct ofpact *a;
2325 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2326 switch (ovs_instruction_type_from_ofpact_type(a->type)) {
2327 case OVSINST_OFPIT11_CLEAR_ACTIONS:
2328 instruction_put_OFPIT11_CLEAR_ACTIONS(openflow);
2331 case OVSINST_OFPIT11_GOTO_TABLE: {
2332 struct ofp11_instruction_goto_table *oigt;
2333 oigt = instruction_put_OFPIT11_GOTO_TABLE(openflow);
2334 oigt->table_id = ofpact_get_GOTO_TABLE(a)->table_id;
2335 memset(oigt->pad, 0, sizeof oigt->pad);
2339 case OVSINST_OFPIT11_WRITE_METADATA: {
2340 const struct ofpact_metadata *om;
2341 struct ofp11_instruction_write_metadata *oiwm;
2343 om = ofpact_get_WRITE_METADATA(a);
2344 oiwm = instruction_put_OFPIT11_WRITE_METADATA(openflow);
2345 oiwm->metadata = om->metadata;
2346 oiwm->metadata_mask = om->mask;
2350 case OVSINST_OFPIT13_METER: {
2351 const struct ofpact_meter *om;
2352 struct ofp13_instruction_meter *oim;
2354 om = ofpact_get_METER(a);
2355 oim = instruction_put_OFPIT13_METER(openflow);
2356 oim->meter_id = htonl(om->meter_id);
2360 case OVSINST_OFPIT11_APPLY_ACTIONS: {
2361 const size_t ofs = openflow->size;
2362 const size_t ofpacts_len_left =
2363 (uint8_t*)ofpact_end(ofpacts, ofpacts_len) - (uint8_t*)a;
2364 const struct ofpact *action;
2365 const struct ofpact *processed = a;
2367 instruction_put_OFPIT11_APPLY_ACTIONS(openflow);
2368 OFPACT_FOR_EACH(action, a, ofpacts_len_left) {
2369 if (ovs_instruction_type_from_ofpact_type(action->type)
2370 != OVSINST_OFPIT11_APPLY_ACTIONS) {
2373 ofpact_to_openflow11(action, openflow);
2376 ofpacts_update_instruction_actions(openflow, ofs);
2381 case OVSINST_OFPIT11_WRITE_ACTIONS: {
2382 const size_t ofs = openflow->size;
2383 const struct ofpact_nest *on;
2385 on = ofpact_get_WRITE_ACTIONS(a);
2386 instruction_put_OFPIT11_WRITE_ACTIONS(openflow);
2387 ofpacts_put_openflow11_actions(on->actions,
2388 ofpact_nest_get_action_len(on),
2390 ofpacts_update_instruction_actions(openflow, ofs);
2398 /* Returns true if 'action' outputs to 'port', false otherwise. */
2400 ofpact_outputs_to_port(const struct ofpact *ofpact, ofp_port_t port)
2402 switch (ofpact->type) {
2404 return ofpact_get_OUTPUT(ofpact)->port == port;
2405 case OFPACT_ENQUEUE:
2406 return ofpact_get_ENQUEUE(ofpact)->port == port;
2407 case OFPACT_CONTROLLER:
2408 return port == OFPP_CONTROLLER;
2410 case OFPACT_OUTPUT_REG:
2412 case OFPACT_SET_VLAN_VID:
2413 case OFPACT_SET_VLAN_PCP:
2414 case OFPACT_STRIP_VLAN:
2415 case OFPACT_PUSH_VLAN:
2416 case OFPACT_SET_ETH_SRC:
2417 case OFPACT_SET_ETH_DST:
2418 case OFPACT_SET_IPV4_SRC:
2419 case OFPACT_SET_IPV4_DST:
2420 case OFPACT_SET_IP_DSCP:
2421 case OFPACT_SET_IP_ECN:
2422 case OFPACT_SET_IP_TTL:
2423 case OFPACT_SET_L4_SRC_PORT:
2424 case OFPACT_SET_L4_DST_PORT:
2425 case OFPACT_REG_MOVE:
2426 case OFPACT_REG_LOAD:
2427 case OFPACT_STACK_PUSH:
2428 case OFPACT_STACK_POP:
2429 case OFPACT_DEC_TTL:
2430 case OFPACT_SET_MPLS_TTL:
2431 case OFPACT_DEC_MPLS_TTL:
2432 case OFPACT_SET_TUNNEL:
2433 case OFPACT_WRITE_METADATA:
2434 case OFPACT_SET_QUEUE:
2435 case OFPACT_POP_QUEUE:
2436 case OFPACT_FIN_TIMEOUT:
2437 case OFPACT_RESUBMIT:
2439 case OFPACT_MULTIPATH:
2442 case OFPACT_PUSH_MPLS:
2443 case OFPACT_POP_MPLS:
2445 case OFPACT_CLEAR_ACTIONS:
2446 case OFPACT_WRITE_ACTIONS:
2447 case OFPACT_GOTO_TABLE:
2455 /* Returns true if any action in the 'ofpacts_len' bytes of 'ofpacts' outputs
2456 * to 'port', false otherwise. */
2458 ofpacts_output_to_port(const struct ofpact *ofpacts, size_t ofpacts_len,
2461 const struct ofpact *a;
2463 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2464 if (ofpact_outputs_to_port(a, port)) {
2472 /* Returns true if any action in the 'ofpacts_len' bytes of 'ofpacts' outputs
2473 * to 'group', false otherwise. */
2475 ofpacts_output_to_group(const struct ofpact *ofpacts, size_t ofpacts_len,
2478 const struct ofpact *a;
2480 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2481 if (a->type == OFPACT_GROUP
2482 && ofpact_get_GROUP(a)->group_id == group_id) {
2491 ofpacts_equal(const struct ofpact *a, size_t a_len,
2492 const struct ofpact *b, size_t b_len)
2494 return a_len == b_len && !memcmp(a, b, a_len);
2497 /* Finds the OFPACT_METER action, if any, in the 'ofpacts_len' bytes of
2498 * 'ofpacts'. If found, returns its meter ID; if not, returns 0.
2500 * This function relies on the order of 'ofpacts' being correct (as checked by
2501 * ofpacts_verify()). */
2503 ofpacts_get_meter(const struct ofpact ofpacts[], size_t ofpacts_len)
2505 const struct ofpact *a;
2507 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2508 enum ovs_instruction_type inst;
2510 inst = ovs_instruction_type_from_ofpact_type(a->type);
2511 if (a->type == OFPACT_METER) {
2512 return ofpact_get_METER(a)->meter_id;
2513 } else if (inst > OVSINST_OFPIT13_METER) {
2521 /* Formatting ofpacts. */
2524 print_note(const struct ofpact_note *note, struct ds *string)
2528 ds_put_cstr(string, "note:");
2529 for (i = 0; i < note->length; i++) {
2531 ds_put_char(string, '.');
2533 ds_put_format(string, "%02"PRIx8, note->data[i]);
2538 print_dec_ttl(const struct ofpact_cnt_ids *ids,
2543 ds_put_cstr(s, "dec_ttl");
2544 if (ids->ofpact.compat == OFPUTIL_NXAST_DEC_TTL_CNT_IDS) {
2545 ds_put_cstr(s, "(");
2546 for (i = 0; i < ids->n_controllers; i++) {
2548 ds_put_cstr(s, ",");
2550 ds_put_format(s, "%"PRIu16, ids->cnt_ids[i]);
2552 ds_put_cstr(s, ")");
2557 print_fin_timeout(const struct ofpact_fin_timeout *fin_timeout,
2560 ds_put_cstr(s, "fin_timeout(");
2561 if (fin_timeout->fin_idle_timeout) {
2562 ds_put_format(s, "idle_timeout=%"PRIu16",",
2563 fin_timeout->fin_idle_timeout);
2565 if (fin_timeout->fin_hard_timeout) {
2566 ds_put_format(s, "hard_timeout=%"PRIu16",",
2567 fin_timeout->fin_hard_timeout);
2570 ds_put_char(s, ')');
2574 ofpact_format(const struct ofpact *a, struct ds *s)
2576 const struct ofpact_enqueue *enqueue;
2577 const struct ofpact_resubmit *resubmit;
2578 const struct ofpact_controller *controller;
2579 const struct ofpact_metadata *metadata;
2580 const struct ofpact_tunnel *tunnel;
2581 const struct ofpact_sample *sample;
2586 port = ofpact_get_OUTPUT(a)->port;
2587 if (ofp_to_u16(port) < ofp_to_u16(OFPP_MAX)) {
2588 ds_put_format(s, "output:%"PRIu16, port);
2590 ofputil_format_port(port, s);
2591 if (port == OFPP_CONTROLLER) {
2592 ds_put_format(s, ":%"PRIu16, ofpact_get_OUTPUT(a)->max_len);
2597 case OFPACT_CONTROLLER:
2598 controller = ofpact_get_CONTROLLER(a);
2599 if (controller->reason == OFPR_ACTION &&
2600 controller->controller_id == 0) {
2601 ds_put_format(s, "CONTROLLER:%"PRIu16,
2602 ofpact_get_CONTROLLER(a)->max_len);
2604 enum ofp_packet_in_reason reason = controller->reason;
2606 ds_put_cstr(s, "controller(");
2607 if (reason != OFPR_ACTION) {
2608 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
2610 ds_put_format(s, "reason=%s,",
2611 ofputil_packet_in_reason_to_string(
2612 reason, reasonbuf, sizeof reasonbuf));
2614 if (controller->max_len != UINT16_MAX) {
2615 ds_put_format(s, "max_len=%"PRIu16",", controller->max_len);
2617 if (controller->controller_id != 0) {
2618 ds_put_format(s, "id=%"PRIu16",", controller->controller_id);
2621 ds_put_char(s, ')');
2625 case OFPACT_ENQUEUE:
2626 enqueue = ofpact_get_ENQUEUE(a);
2627 ds_put_format(s, "enqueue:");
2628 ofputil_format_port(enqueue->port, s);
2629 ds_put_format(s, "q%"PRIu32, enqueue->queue);
2632 case OFPACT_OUTPUT_REG:
2633 ds_put_cstr(s, "output:");
2634 mf_format_subfield(&ofpact_get_OUTPUT_REG(a)->src, s);
2638 bundle_format(ofpact_get_BUNDLE(a), s);
2641 case OFPACT_SET_VLAN_VID:
2642 ds_put_format(s, "mod_vlan_vid:%"PRIu16,
2643 ofpact_get_SET_VLAN_VID(a)->vlan_vid);
2646 case OFPACT_SET_VLAN_PCP:
2647 ds_put_format(s, "mod_vlan_pcp:%"PRIu8,
2648 ofpact_get_SET_VLAN_PCP(a)->vlan_pcp);
2651 case OFPACT_STRIP_VLAN:
2652 ds_put_cstr(s, "strip_vlan");
2655 case OFPACT_PUSH_VLAN:
2656 /* XXX 802.1AD case*/
2657 ds_put_format(s, "push_vlan:%#"PRIx16, ETH_TYPE_VLAN_8021Q);
2660 case OFPACT_SET_ETH_SRC:
2661 ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT,
2662 ETH_ADDR_ARGS(ofpact_get_SET_ETH_SRC(a)->mac));
2665 case OFPACT_SET_ETH_DST:
2666 ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT,
2667 ETH_ADDR_ARGS(ofpact_get_SET_ETH_DST(a)->mac));
2670 case OFPACT_SET_IPV4_SRC:
2671 ds_put_format(s, "mod_nw_src:"IP_FMT,
2672 IP_ARGS(ofpact_get_SET_IPV4_SRC(a)->ipv4));
2675 case OFPACT_SET_IPV4_DST:
2676 ds_put_format(s, "mod_nw_dst:"IP_FMT,
2677 IP_ARGS(ofpact_get_SET_IPV4_DST(a)->ipv4));
2680 case OFPACT_SET_IP_DSCP:
2681 ds_put_format(s, "mod_nw_tos:%d", ofpact_get_SET_IP_DSCP(a)->dscp);
2684 case OFPACT_SET_IP_ECN:
2685 ds_put_format(s, "mod_nw_ecn:%d", ofpact_get_SET_IP_ECN(a)->ecn);
2688 case OFPACT_SET_IP_TTL:
2689 ds_put_format(s, "mod_nw_ttl:%d", ofpact_get_SET_IP_TTL(a)->ttl);
2692 case OFPACT_SET_L4_SRC_PORT:
2693 ds_put_format(s, "mod_tp_src:%d", ofpact_get_SET_L4_SRC_PORT(a)->port);
2696 case OFPACT_SET_L4_DST_PORT:
2697 ds_put_format(s, "mod_tp_dst:%d", ofpact_get_SET_L4_DST_PORT(a)->port);
2700 case OFPACT_REG_MOVE:
2701 nxm_format_reg_move(ofpact_get_REG_MOVE(a), s);
2704 case OFPACT_REG_LOAD:
2705 nxm_format_reg_load(ofpact_get_REG_LOAD(a), s);
2708 case OFPACT_STACK_PUSH:
2709 nxm_format_stack_push(ofpact_get_STACK_PUSH(a), s);
2712 case OFPACT_STACK_POP:
2713 nxm_format_stack_pop(ofpact_get_STACK_POP(a), s);
2716 case OFPACT_DEC_TTL:
2717 print_dec_ttl(ofpact_get_DEC_TTL(a), s);
2720 case OFPACT_SET_MPLS_TTL:
2721 ds_put_format(s, "set_mpls_ttl(%"PRIu8")",
2722 ofpact_get_SET_MPLS_TTL(a)->ttl);
2725 case OFPACT_DEC_MPLS_TTL:
2726 ds_put_cstr(s, "dec_mpls_ttl");
2729 case OFPACT_SET_TUNNEL:
2730 tunnel = ofpact_get_SET_TUNNEL(a);
2731 ds_put_format(s, "set_tunnel%s:%#"PRIx64,
2732 (tunnel->tun_id > UINT32_MAX
2733 || a->compat == OFPUTIL_NXAST_SET_TUNNEL64 ? "64" : ""),
2737 case OFPACT_SET_QUEUE:
2738 ds_put_format(s, "set_queue:%"PRIu32,
2739 ofpact_get_SET_QUEUE(a)->queue_id);
2742 case OFPACT_POP_QUEUE:
2743 ds_put_cstr(s, "pop_queue");
2746 case OFPACT_FIN_TIMEOUT:
2747 print_fin_timeout(ofpact_get_FIN_TIMEOUT(a), s);
2750 case OFPACT_RESUBMIT:
2751 resubmit = ofpact_get_RESUBMIT(a);
2752 if (resubmit->in_port != OFPP_IN_PORT && resubmit->table_id == 255) {
2753 ds_put_cstr(s, "resubmit:");
2754 ofputil_format_port(resubmit->in_port, s);
2756 ds_put_format(s, "resubmit(");
2757 if (resubmit->in_port != OFPP_IN_PORT) {
2758 ofputil_format_port(resubmit->in_port, s);
2760 ds_put_char(s, ',');
2761 if (resubmit->table_id != 255) {
2762 ds_put_format(s, "%"PRIu8, resubmit->table_id);
2764 ds_put_char(s, ')');
2769 learn_format(ofpact_get_LEARN(a), s);
2772 case OFPACT_MULTIPATH:
2773 multipath_format(ofpact_get_MULTIPATH(a), s);
2777 print_note(ofpact_get_NOTE(a), s);
2780 case OFPACT_PUSH_MPLS:
2781 ds_put_format(s, "push_mpls:0x%04"PRIx16,
2782 ntohs(ofpact_get_PUSH_MPLS(a)->ethertype));
2785 case OFPACT_POP_MPLS:
2786 ds_put_format(s, "pop_mpls:0x%04"PRIx16,
2787 ntohs(ofpact_get_POP_MPLS(a)->ethertype));
2791 ds_put_cstr(s, "exit");
2795 sample = ofpact_get_SAMPLE(a);
2797 s, "sample(probability=%"PRIu16",collector_set_id=%"PRIu32
2798 ",obs_domain_id=%"PRIu32",obs_point_id=%"PRIu32")",
2799 sample->probability, sample->collector_set_id,
2800 sample->obs_domain_id, sample->obs_point_id);
2803 case OFPACT_WRITE_ACTIONS: {
2804 struct ofpact_nest *on = ofpact_get_WRITE_ACTIONS(a);
2805 ds_put_format(s, "%s(",
2806 ovs_instruction_name_from_type(
2807 OVSINST_OFPIT11_WRITE_ACTIONS));
2808 ofpacts_format(on->actions, ofpact_nest_get_action_len(on), s);
2809 ds_put_char(s, ')');
2813 case OFPACT_CLEAR_ACTIONS:
2814 ds_put_format(s, "%s",
2815 ovs_instruction_name_from_type(
2816 OVSINST_OFPIT11_CLEAR_ACTIONS));
2819 case OFPACT_WRITE_METADATA:
2820 metadata = ofpact_get_WRITE_METADATA(a);
2821 ds_put_format(s, "%s:%#"PRIx64,
2822 ovs_instruction_name_from_type(
2823 OVSINST_OFPIT11_WRITE_METADATA),
2824 ntohll(metadata->metadata));
2825 if (metadata->mask != OVS_BE64_MAX) {
2826 ds_put_format(s, "/%#"PRIx64, ntohll(metadata->mask));
2830 case OFPACT_GOTO_TABLE:
2831 ds_put_format(s, "%s:%"PRIu8,
2832 ovs_instruction_name_from_type(
2833 OVSINST_OFPIT11_GOTO_TABLE),
2834 ofpact_get_GOTO_TABLE(a)->table_id);
2838 ds_put_format(s, "%s:%"PRIu32,
2839 ovs_instruction_name_from_type(OVSINST_OFPIT13_METER),
2840 ofpact_get_METER(a)->meter_id);
2844 ds_put_format(s, "group:%"PRIu32,
2845 ofpact_get_GROUP(a)->group_id);
2850 /* Appends a string representing the 'ofpacts_len' bytes of ofpacts in
2851 * 'ofpacts' to 'string'. */
2853 ofpacts_format(const struct ofpact *ofpacts, size_t ofpacts_len,
2857 ds_put_cstr(string, "drop");
2859 const struct ofpact *a;
2861 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2863 ds_put_cstr(string, ",");
2866 /* XXX write-actions */
2867 ofpact_format(a, string);
2872 /* Internal use by helpers. */
2875 ofpact_put(struct ofpbuf *ofpacts, enum ofpact_type type, size_t len)
2877 struct ofpact *ofpact;
2879 ofpact_pad(ofpacts);
2880 ofpact = ofpacts->l2 = ofpbuf_put_uninit(ofpacts, len);
2881 ofpact_init(ofpact, type, len);
2886 ofpact_init(struct ofpact *ofpact, enum ofpact_type type, size_t len)
2888 memset(ofpact, 0, len);
2889 ofpact->type = type;
2890 ofpact->compat = OFPUTIL_ACTION_INVALID;
2894 /* Updates 'ofpact->len' to the number of bytes in the tail of 'ofpacts'
2895 * starting at 'ofpact'.
2897 * This is the correct way to update a variable-length ofpact's length after
2898 * adding the variable-length part of the payload. (See the large comment
2899 * near the end of ofp-actions.h for more information.) */
2901 ofpact_update_len(struct ofpbuf *ofpacts, struct ofpact *ofpact)
2903 ovs_assert(ofpact == ofpacts->l2);
2904 ofpact->len = (char *) ofpbuf_tail(ofpacts) - (char *) ofpact;
2907 /* Pads out 'ofpacts' to a multiple of OFPACT_ALIGNTO bytes in length. Each
2908 * ofpact_put_<ENUM>() calls this function automatically beforehand, but the
2909 * client must call this itself after adding the final ofpact to an array of
2912 * (The consequences of failing to call this function are probably not dire.
2913 * OFPACT_FOR_EACH will calculate a pointer beyond the end of the ofpacts, but
2914 * not dereference it. That's undefined behavior, technically, but it will not
2915 * cause a real problem on common systems. Still, it seems better to call
2918 ofpact_pad(struct ofpbuf *ofpacts)
2920 unsigned int rem = ofpacts->size % OFPACT_ALIGNTO;
2922 ofpbuf_put_zeros(ofpacts, OFPACT_ALIGNTO - rem);
2927 ofpact_set_field_init(struct ofpact_reg_load *load, const struct mf_field *mf,
2930 load->ofpact.compat = OFPUTIL_OFPAT12_SET_FIELD;
2931 load->dst.field = mf;
2933 load->dst.n_bits = mf->n_bits;
2934 bitwise_copy(src, mf->n_bytes, load->dst.ofs,
2935 &load->subvalue, sizeof load->subvalue, 0, mf->n_bits);