Add support for connection tracking.
[cascardo/ovs.git] / lib / ofp-actions.c
index 1b7625d..5ded70e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 #include "bundle.h"
 #include "byte-order.h"
 #include "compiler.h"
+#include "dummy.h"
 #include "dynamic-string.h"
 #include "hmap.h"
 #include "learn.h"
@@ -30,7 +31,7 @@
 #include "ofpbuf.h"
 #include "unaligned.h"
 #include "util.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(ofp_actions);
 
@@ -281,6 +282,22 @@ enum ofp_raw_action_type {
 
     /* NX1.0+(29): struct nx_action_sample. */
     NXAST_RAW_SAMPLE,
+
+    /* NX1.0+(34): struct nx_action_conjunction. */
+    NXAST_RAW_CONJUNCTION,
+
+    /* NX1.0+(35): struct nx_action_conntrack, ... */
+    NXAST_RAW_CT,
+
+/* ## ------------------ ## */
+/* ## Debugging actions. ## */
+/* ## ------------------ ## */
+
+/* These are intentionally undocumented, subject to change, and ovs-vswitchd */
+/* accepts them only if started with --enable-dummy. */
+
+    /* NX1.0+(255): void. */
+    NXAST_RAW_DEBUG_RECIRC,
 };
 
 /* OpenFlow actions are always a multiple of 8 bytes in length. */
@@ -318,7 +335,8 @@ static void ofpacts_update_instruction_actions(struct ofpbuf *openflow,
 static void pad_ofpat(struct ofpbuf *openflow, size_t start_ofs);
 
 static enum ofperr ofpacts_verify(const struct ofpact[], size_t ofpacts_len,
-                                  uint32_t allowed_ovsinsts);
+                                  uint32_t allowed_ovsinsts,
+                                  enum ofpact_type outer_action);
 
 static void ofpact_put_set_field(struct ofpbuf *openflow, enum ofp_version,
                                  enum mf_field_id, uint64_t value);
@@ -330,7 +348,32 @@ static void *ofpact_put_raw(struct ofpbuf *, enum ofp_version,
 
 static char *OVS_WARN_UNUSED_RESULT ofpacts_parse(
     char *str, struct ofpbuf *ofpacts, enum ofputil_protocol *usable_protocols,
-    bool allow_instructions);
+    bool allow_instructions, enum ofpact_type outer_action);
+static enum ofperr ofpacts_pull_openflow_actions__(
+    struct ofpbuf *openflow, unsigned int actions_len,
+    enum ofp_version version, uint32_t allowed_ovsinsts,
+    struct ofpbuf *ofpacts, enum ofpact_type outer_action);
+
+/* Pull off existing actions or instructions. Used by nesting actions to keep
+ * ofpacts_parse() oblivious of actions nesting.
+ *
+ * Push the actions back on after nested parsing, e.g.:
+ *
+ *     size_t ofs = ofpacts_pull(ofpacts);
+ *     ...nested parsing...
+ *     ofpbuf_push_uninit(ofpacts, ofs);
+ */
+static size_t
+ofpacts_pull(struct ofpbuf *ofpacts)
+{
+    size_t ofs;
+
+    ofpact_pad(ofpacts);
+    ofs = ofpacts->size;
+    ofpbuf_pull(ofpacts, ofs);
+
+    return ofs;
+}
 
 #include "ofp-actions.inc1"
 \f
@@ -363,6 +406,7 @@ OFP_ASSERT(sizeof(struct ofp11_action_output) == 16);
 
 static enum ofperr
 decode_OFPAT_RAW10_OUTPUT(const struct ofp10_action_output *oao,
+                          enum ofp_version ofp_version OVS_UNUSED,
                           struct ofpbuf *out)
 {
     struct ofpact_output *output;
@@ -376,7 +420,8 @@ decode_OFPAT_RAW10_OUTPUT(const struct ofp10_action_output *oao,
 
 static enum ofperr
 decode_OFPAT_RAW11_OUTPUT(const struct ofp11_action_output *oao,
-                       struct ofpbuf *out)
+                          enum ofp_version ofp_version OVS_UNUSED,
+                          struct ofpbuf *out)
 {
     struct ofpact_output *output;
     enum ofperr error;
@@ -449,7 +494,9 @@ format_OUTPUT(const struct ofpact_output *a, struct ds *s)
 /* Group actions. */
 
 static enum ofperr
-decode_OFPAT_RAW11_GROUP(uint32_t group_id, struct ofpbuf *out)
+decode_OFPAT_RAW11_GROUP(uint32_t group_id,
+                         enum ofp_version ofp_version OVS_UNUSED,
+                         struct ofpbuf *out)
 {
     ofpact_put_GROUP(out)->group_id = group_id;
     return 0;
@@ -505,6 +552,7 @@ OFP_ASSERT(sizeof(struct nx_action_controller) == 16);
 
 static enum ofperr
 decode_NXAST_RAW_CONTROLLER(const struct nx_action_controller *nac,
+                            enum ofp_version ofp_version OVS_UNUSED,
                             struct ofpbuf *out)
 {
     struct ofpact_controller *oc;
@@ -628,6 +676,7 @@ OFP_ASSERT(sizeof(struct ofp10_action_enqueue) == 16);
 
 static enum ofperr
 decode_OFPAT_RAW10_ENQUEUE(const struct ofp10_action_enqueue *oae,
+                           enum ofp_version ofp_version OVS_UNUSED,
                            struct ofpbuf *out)
 {
     struct ofpact_enqueue *enqueue;
@@ -740,6 +789,7 @@ OFP_ASSERT(sizeof(struct nx_action_output_reg2) == 24);
 
 static enum ofperr
 decode_NXAST_RAW_OUTPUT_REG(const struct nx_action_output_reg *naor,
+                            enum ofp_version ofp_version OVS_UNUSED,
                             struct ofpbuf *out)
 {
     struct ofpact_output_reg *output_reg;
@@ -760,7 +810,8 @@ decode_NXAST_RAW_OUTPUT_REG(const struct nx_action_output_reg *naor,
 
 static enum ofperr
 decode_NXAST_RAW_OUTPUT_REG2(const struct nx_action_output_reg2 *naor,
-                            struct ofpbuf *out)
+                             enum ofp_version ofp_version OVS_UNUSED,
+                             struct ofpbuf *out)
 {
     struct ofpact_output_reg *output_reg;
     enum ofperr error;
@@ -778,7 +829,7 @@ decode_NXAST_RAW_OUTPUT_REG2(const struct nx_action_output_reg2 *naor,
     if (error) {
         return error;
     }
-    if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+    if (!is_all_zeros(b.data, b.size)) {
         return OFPERR_NXBRC_MUST_BE_ZERO;
     }
 
@@ -796,15 +847,15 @@ encode_OUTPUT_REG(const struct ofpact_output_reg *output_reg,
     if (output_reg->ofpact.raw == NXAST_RAW_OUTPUT_REG2
         || !mf_nxm_header(output_reg->src.field->id)) {
         struct nx_action_output_reg2 *naor = put_NXAST_OUTPUT_REG2(out);
-        size_t size = ofpbuf_size(out);
+        size_t size = out->size;
 
         naor->ofs_nbits = nxm_encode_ofs_nbits(output_reg->src.ofs,
                                                output_reg->src.n_bits);
         naor->max_len = htons(output_reg->max_len);
 
-        ofpbuf_set_size(out, size - sizeof naor->pad);
+        out->size = size - sizeof naor->pad;
         nx_put_header(out, output_reg->src.field->id, 0, false);
-        ofpbuf_set_size(out, size);
+        out->size = size;
     } else {
         struct nx_action_output_reg *naor = put_NXAST_OUTPUT_REG(out);
 
@@ -966,7 +1017,7 @@ decode_bundle(bool load, const struct nx_action_bundle *nab,
         ofpbuf_put(ofpacts, &ofp_port, sizeof ofp_port);
     }
 
-    bundle = ofpacts->frame;
+    bundle = ofpacts->header;
     ofpact_update_len(ofpacts, &bundle->ofpact);
 
     if (!error) {
@@ -976,13 +1027,16 @@ decode_bundle(bool load, const struct nx_action_bundle *nab,
 }
 
 static enum ofperr
-decode_NXAST_RAW_BUNDLE(const struct nx_action_bundle *nab, struct ofpbuf *out)
+decode_NXAST_RAW_BUNDLE(const struct nx_action_bundle *nab,
+                        enum ofp_version ofp_version OVS_UNUSED,
+                        struct ofpbuf *out)
 {
     return decode_bundle(false, nab, out);
 }
 
 static enum ofperr
 decode_NXAST_RAW_BUNDLE_LOAD(const struct nx_action_bundle *nab,
+                             enum ofp_version ofp_version OVS_UNUSED,
                              struct ofpbuf *out)
 {
     return decode_bundle(true, nab, out);
@@ -1054,13 +1108,17 @@ decode_set_vlan_vid(uint16_t vid, bool push_vlan_if_needed, struct ofpbuf *out)
 }
 
 static enum ofperr
-decode_OFPAT_RAW10_SET_VLAN_VID(uint16_t vid, struct ofpbuf *out)
+decode_OFPAT_RAW10_SET_VLAN_VID(uint16_t vid,
+                                enum ofp_version ofp_version OVS_UNUSED,
+                                struct ofpbuf *out)
 {
     return decode_set_vlan_vid(vid, true, out);
 }
 
 static enum ofperr
-decode_OFPAT_RAW11_SET_VLAN_VID(uint16_t vid, struct ofpbuf *out)
+decode_OFPAT_RAW11_SET_VLAN_VID(uint16_t vid,
+                                enum ofp_version ofp_version OVS_UNUSED,
+                                struct ofpbuf *out)
 {
     return decode_set_vlan_vid(vid, false, out);
 }
@@ -1141,13 +1199,17 @@ decode_set_vlan_pcp(uint8_t pcp, bool push_vlan_if_needed, struct ofpbuf *out)
 }
 
 static enum ofperr
-decode_OFPAT_RAW10_SET_VLAN_PCP(uint8_t pcp, struct ofpbuf *out)
+decode_OFPAT_RAW10_SET_VLAN_PCP(uint8_t pcp,
+                                enum ofp_version ofp_version OVS_UNUSED,
+                                struct ofpbuf *out)
 {
     return decode_set_vlan_pcp(pcp, true, out);
 }
 
 static enum ofperr
-decode_OFPAT_RAW11_SET_VLAN_PCP(uint8_t pcp, struct ofpbuf *out)
+decode_OFPAT_RAW11_SET_VLAN_PCP(uint8_t pcp,
+                                enum ofp_version ofp_version OVS_UNUSED,
+                                struct ofpbuf *out)
 {
     return decode_set_vlan_pcp(pcp, false, out);
 }
@@ -1264,7 +1326,9 @@ format_STRIP_VLAN(const struct ofpact_null *a, struct ds *s)
 /* Push VLAN action. */
 
 static enum ofperr
-decode_OFPAT_RAW11_PUSH_VLAN(ovs_be16 eth_type, struct ofpbuf *out)
+decode_OFPAT_RAW11_PUSH_VLAN(ovs_be16 eth_type,
+                             enum ofp_version ofp_version OVS_UNUSED,
+                             struct ofpbuf *out)
 {
     if (eth_type != htons(ETH_TYPE_VLAN_8021Q)) {
         /* XXX 802.1AD(QinQ) isn't supported at the moment */
@@ -1320,24 +1384,26 @@ format_PUSH_VLAN(const struct ofpact_null *a OVS_UNUSED, struct ds *s)
 struct ofp_action_dl_addr {
     ovs_be16 type;                  /* Type. */
     ovs_be16 len;                   /* Length is 16. */
-    uint8_t dl_addr[OFP_ETH_ALEN];  /* Ethernet address. */
+    struct eth_addr dl_addr;        /* Ethernet address. */
     uint8_t pad[6];
 };
 OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);
 
 static enum ofperr
 decode_OFPAT_RAW_SET_DL_SRC(const struct ofp_action_dl_addr *a,
+                            enum ofp_version ofp_version OVS_UNUSED,
                             struct ofpbuf *out)
 {
-    memcpy(ofpact_put_SET_ETH_SRC(out)->mac, a->dl_addr, ETH_ADDR_LEN);
+    ofpact_put_SET_ETH_SRC(out)->mac = a->dl_addr;
     return 0;
 }
 
 static enum ofperr
 decode_OFPAT_RAW_SET_DL_DST(const struct ofp_action_dl_addr *a,
+                            enum ofp_version ofp_version OVS_UNUSED,
                             struct ofpbuf *out)
 {
-    memcpy(ofpact_put_SET_ETH_DST(out)->mac, a->dl_addr, ETH_ADDR_LEN);
+    ofpact_put_SET_ETH_DST(out)->mac = a->dl_addr;
     return 0;
 }
 
@@ -1346,16 +1412,14 @@ encode_SET_ETH_addr(const struct ofpact_mac *mac, enum ofp_version ofp_version,
                     enum ofp_raw_action_type raw, enum mf_field_id field,
                     struct ofpbuf *out)
 {
-    const uint8_t *addr = mac->mac;
-
     if (ofp_version < OFP12_VERSION) {
         struct ofp_action_dl_addr *oada;
 
         oada = ofpact_put_raw(out, ofp_version, raw, 0);
-        memcpy(oada->dl_addr, addr, ETH_ADDR_LEN);
+        oada->dl_addr = mac->mac;
     } else {
         ofpact_put_set_field(out, ofp_version, field,
-                             eth_addr_to_uint64(addr));
+                             eth_addr_to_uint64(mac->mac));
     }
 }
 
@@ -1382,14 +1446,14 @@ static char * OVS_WARN_UNUSED_RESULT
 parse_SET_ETH_SRC(char *arg, struct ofpbuf *ofpacts,
                  enum ofputil_protocol *usable_protocols OVS_UNUSED)
 {
-    return str_to_mac(arg, ofpact_put_SET_ETH_SRC(ofpacts)->mac);
+    return str_to_mac(arg, &ofpact_put_SET_ETH_SRC(ofpacts)->mac);
 }
 
 static char * OVS_WARN_UNUSED_RESULT
 parse_SET_ETH_DST(char *arg, struct ofpbuf *ofpacts,
                  enum ofputil_protocol *usable_protocols OVS_UNUSED)
 {
-    return str_to_mac(arg, ofpact_put_SET_ETH_DST(ofpacts)->mac);
+    return str_to_mac(arg, &ofpact_put_SET_ETH_DST(ofpacts)->mac);
 }
 
 static void
@@ -1407,14 +1471,18 @@ format_SET_ETH_DST(const struct ofpact_mac *a, struct ds *s)
 /* Set IPv4 address actions. */
 
 static enum ofperr
-decode_OFPAT_RAW_SET_NW_SRC(ovs_be32 ipv4, struct ofpbuf *out)
+decode_OFPAT_RAW_SET_NW_SRC(ovs_be32 ipv4,
+                            enum ofp_version ofp_version OVS_UNUSED,
+                            struct ofpbuf *out)
 {
     ofpact_put_SET_IPV4_SRC(out)->ipv4 = ipv4;
     return 0;
 }
 
 static enum ofperr
-decode_OFPAT_RAW_SET_NW_DST(ovs_be32 ipv4, struct ofpbuf *out)
+decode_OFPAT_RAW_SET_NW_DST(ovs_be32 ipv4,
+                            enum ofp_version ofp_version OVS_UNUSED,
+                            struct ofpbuf *out)
 {
     ofpact_put_SET_IPV4_DST(out)->ipv4 = ipv4;
     return 0;
@@ -1479,7 +1547,9 @@ format_SET_IPV4_DST(const struct ofpact_ipv4 *a, struct ds *s)
 /* Set IPv4/v6 TOS actions. */
 
 static enum ofperr
-decode_OFPAT_RAW_SET_NW_TOS(uint8_t dscp, struct ofpbuf *out)
+decode_OFPAT_RAW_SET_NW_TOS(uint8_t dscp,
+                            enum ofp_version ofp_version OVS_UNUSED,
+                            struct ofpbuf *out)
 {
     if (dscp & ~IP_DSCP_MASK) {
         return OFPERR_OFPBAC_BAD_ARGUMENT;
@@ -1529,7 +1599,9 @@ format_SET_IP_DSCP(const struct ofpact_dscp *a, struct ds *s)
 /* Set IPv4/v6 ECN actions. */
 
 static enum ofperr
-decode_OFPAT_RAW11_SET_NW_ECN(uint8_t ecn, struct ofpbuf *out)
+decode_OFPAT_RAW11_SET_NW_ECN(uint8_t ecn,
+                              enum ofp_version ofp_version OVS_UNUSED,
+                              struct ofpbuf *out)
 {
     if (ecn & ~IP_ECN_MASK) {
         return OFPERR_OFPBAC_BAD_ARGUMENT;
@@ -1581,7 +1653,9 @@ format_SET_IP_ECN(const struct ofpact_ecn *a, struct ds *s)
 /* Set IPv4/v6 TTL actions. */
 
 static enum ofperr
-decode_OFPAT_RAW11_SET_NW_TTL(uint8_t ttl, struct ofpbuf *out)
+decode_OFPAT_RAW11_SET_NW_TTL(uint8_t ttl,
+                              enum ofp_version ofp_version OVS_UNUSED,
+                              struct ofpbuf *out)
 {
     ofpact_put_SET_IP_TTL(out)->ttl = ttl;
     return 0;
@@ -1623,14 +1697,18 @@ format_SET_IP_TTL(const struct ofpact_ip_ttl *a, struct ds *s)
 /* Set TCP/UDP/SCTP port actions. */
 
 static enum ofperr
-decode_OFPAT_RAW_SET_TP_SRC(ovs_be16 port, struct ofpbuf *out)
+decode_OFPAT_RAW_SET_TP_SRC(ovs_be16 port,
+                            enum ofp_version ofp_version OVS_UNUSED,
+                            struct ofpbuf *out)
 {
     ofpact_put_SET_L4_SRC_PORT(out)->port = ntohs(port);
     return 0;
 }
 
 static enum ofperr
-decode_OFPAT_RAW_SET_TP_DST(ovs_be16 port, struct ofpbuf *out)
+decode_OFPAT_RAW_SET_TP_DST(ovs_be16 port,
+                            enum ofp_version ofp_version OVS_UNUSED,
+                            struct ofpbuf *out)
 {
     ofpact_put_SET_L4_DST_PORT(out)->port = ntohs(port);
     return 0;
@@ -1876,7 +1954,7 @@ decode_copy_field__(ovs_be16 src_offset, ovs_be16 dst_offset, ovs_be16 n_bits,
         return error;
     }
 
-    if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+    if (!is_all_zeros(b.data, b.size)) {
         return OFPERR_NXBRC_MUST_BE_ZERO;
     }
 
@@ -1885,6 +1963,7 @@ decode_copy_field__(ovs_be16 src_offset, ovs_be16 dst_offset, ovs_be16 n_bits,
 
 static enum ofperr
 decode_OFPAT_RAW15_COPY_FIELD(const struct ofp15_action_copy_field *oacf,
+                              enum ofp_version ofp_version OVS_UNUSED,
                               struct ofpbuf *ofpacts)
 {
     return decode_copy_field__(oacf->src_offset, oacf->dst_offset,
@@ -1894,6 +1973,7 @@ decode_OFPAT_RAW15_COPY_FIELD(const struct ofp15_action_copy_field *oacf,
 
 static enum ofperr
 decode_ONFACT_RAW13_COPY_FIELD(const struct onf_action_copy_field *oacf,
+                               enum ofp_version ofp_version OVS_UNUSED,
                                struct ofpbuf *ofpacts)
 {
     return decode_copy_field__(oacf->src_offset, oacf->dst_offset,
@@ -1903,6 +1983,7 @@ decode_ONFACT_RAW13_COPY_FIELD(const struct onf_action_copy_field *oacf,
 
 static enum ofperr
 decode_NXAST_RAW_REG_MOVE(const struct nx_action_reg_move *narm,
+                          enum ofp_version ofp_version OVS_UNUSED,
                           struct ofpbuf *ofpacts)
 {
     struct ofpact_reg_move *move;
@@ -1926,7 +2007,7 @@ decode_NXAST_RAW_REG_MOVE(const struct nx_action_reg_move *narm,
     if (error) {
         return error;
     }
-    if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+    if (!is_all_zeros(b.data, b.size)) {
         return OFPERR_NXBRC_MUST_BE_ZERO;
     }
 
@@ -1943,13 +2024,13 @@ encode_REG_MOVE(const struct ofpact_reg_move *move,
      * probe for support.  Until we have that ability, we currently prefer
      * NXAST_RAW_REG_MOVE for backward compatibility with older Open vSwitch
      * versions.  */
-    size_t start_ofs = ofpbuf_size(out);
+    size_t start_ofs = out->size;
     if (ofp_version >= OFP15_VERSION) {
         struct ofp15_action_copy_field *copy = put_OFPAT15_COPY_FIELD(out);
         copy->n_bits = htons(move->dst.n_bits);
         copy->src_offset = htons(move->src.ofs);
         copy->dst_offset = htons(move->dst.ofs);
-        ofpbuf_set_size(out, ofpbuf_size(out) - sizeof copy->pad2);
+        out->size = out->size - sizeof copy->pad2;
         nx_put_header(out, move->src.field->id, ofp_version, false);
         nx_put_header(out, move->dst.field->id, ofp_version, false);
     } else if (ofp_version == OFP13_VERSION
@@ -1958,7 +2039,7 @@ encode_REG_MOVE(const struct ofpact_reg_move *move,
         copy->n_bits = htons(move->dst.n_bits);
         copy->src_offset = htons(move->src.ofs);
         copy->dst_offset = htons(move->dst.ofs);
-        ofpbuf_set_size(out, ofpbuf_size(out) - sizeof copy->pad3);
+        out->size = out->size - sizeof copy->pad3;
         nx_put_header(out, move->src.field->id, ofp_version, false);
         nx_put_header(out, move->dst.field->id, ofp_version, false);
     } else {
@@ -2101,7 +2182,7 @@ decode_ofpat_set_field(const struct ofp12_action_set_field *oasf,
         memset(&sf->mask, 0xff, sf->field->n_bytes);
     }
 
-    if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+    if (!is_all_zeros(b.data, b.size)) {
         return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
     }
 
@@ -2118,7 +2199,7 @@ decode_ofpat_set_field(const struct ofp12_action_set_field *oasf,
         return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
     }
 
-    /* The value must be valid for match.  The OpenFlow 1.5 draft also says,
+    /* The value must be valid for match.  OpenFlow 1.5 also says,
      * "In an OXM_OF_VLAN_VID set-field action, the OFPVID_PRESENT bit must be
      * a 1-bit in oxm_value and in oxm_mask." */
     if (!mf_is_value_valid(sf->field, &sf->value)
@@ -2138,6 +2219,7 @@ decode_ofpat_set_field(const struct ofp12_action_set_field *oasf,
 
 static enum ofperr
 decode_OFPAT_RAW12_SET_FIELD(const struct ofp12_action_set_field *oasf,
+                             enum ofp_version ofp_version OVS_UNUSED,
                              struct ofpbuf *ofpacts)
 {
     return decode_ofpat_set_field(oasf, false, ofpacts);
@@ -2145,6 +2227,7 @@ decode_OFPAT_RAW12_SET_FIELD(const struct ofp12_action_set_field *oasf,
 
 static enum ofperr
 decode_OFPAT_RAW15_SET_FIELD(const struct ofp12_action_set_field *oasf,
+                             enum ofp_version ofp_version OVS_UNUSED,
                              struct ofpbuf *ofpacts)
 {
     return decode_ofpat_set_field(oasf, true, ofpacts);
@@ -2152,6 +2235,7 @@ decode_OFPAT_RAW15_SET_FIELD(const struct ofp12_action_set_field *oasf,
 
 static enum ofperr
 decode_NXAST_RAW_REG_LOAD(const struct nx_action_reg_load *narl,
+                          enum ofp_version ofp_version OVS_UNUSED,
                           struct ofpbuf *out)
 {
     struct ofpact_set_field *sf = ofpact_put_reg_load(out);
@@ -2187,6 +2271,7 @@ decode_NXAST_RAW_REG_LOAD(const struct nx_action_reg_load *narl,
 
 static enum ofperr
 decode_NXAST_RAW_REG_LOAD2(const struct nx_action_reg_load2 *narl,
+                           enum ofp_version ofp_version OVS_UNUSED,
                            struct ofpbuf *out)
 {
     struct ofpact_set_field *sf;
@@ -2202,7 +2287,7 @@ decode_NXAST_RAW_REG_LOAD2(const struct nx_action_reg_load2 *narl,
     if (error) {
         return error;
     }
-    if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+    if (!is_all_zeros(b.data, b.size)) {
         return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
     }
 
@@ -2220,13 +2305,13 @@ ofpact_put_set_field(struct ofpbuf *openflow, enum ofp_version ofp_version,
 {
     struct ofp12_action_set_field *oasf OVS_UNUSED;
     int n_bytes = mf_from_id(field)->n_bytes;
-    size_t start_ofs = ofpbuf_size(openflow);
+    size_t start_ofs = openflow->size;
     union mf_value value;
 
     value.be64 = htonll(value_ << (8 * (8 - n_bytes)));
 
     oasf = put_OFPAT12_SET_FIELD(openflow);
-    ofpbuf_set_size(openflow, ofpbuf_size(openflow) - sizeof oasf->pad);
+    openflow->size = openflow->size - sizeof oasf->pad;
     nx_put_entry(openflow, field, ofp_version, &value, NULL);
     pad_ofpat(openflow, start_ofs);
 }
@@ -2257,16 +2342,16 @@ static void
 set_field_to_nxast(const struct ofpact_set_field *sf, struct ofpbuf *openflow)
 {
     /* If 'sf' cannot be encoded as NXAST_REG_LOAD because it requires an
-     * experimenter OXM (or if it came in as NXAST_REG_LOAD2), encode as
-     * NXAST_REG_LOAD2.  Otherwise use NXAST_REG_LOAD, which is backward
-     * compatible. */
+     * experimenter OXM or is variable length (or if it came in as
+     * NXAST_REG_LOAD2), encode as NXAST_REG_LOAD2.  Otherwise use
+     * NXAST_REG_LOAD, which is backward compatible. */
     if (sf->ofpact.raw == NXAST_RAW_REG_LOAD2
-        || !mf_nxm_header(sf->field->id)) {
+        || !mf_nxm_header(sf->field->id) || sf->field->variable_len) {
         struct nx_action_reg_load2 *narl OVS_UNUSED;
-        size_t start_ofs = ofpbuf_size(openflow);
+        size_t start_ofs = openflow->size;
 
         narl = put_NXAST_REG_LOAD2(openflow);
-        ofpbuf_set_size(openflow, ofpbuf_size(openflow) - sizeof narl->pad);
+        openflow->size = openflow->size - sizeof narl->pad;
         nx_put_entry(openflow, sf->field->id, 0, &sf->value, &sf->mask);
         pad_ofpat(openflow, start_ofs);
     } else {
@@ -2363,13 +2448,11 @@ set_field_to_legacy_openflow(const struct ofpact_set_field *sf,
         break;
 
     case MFF_ETH_SRC:
-        memcpy(put_OFPAT_SET_DL_SRC(out, ofp_version)->dl_addr,
-               sf->value.mac, ETH_ADDR_LEN);
+        put_OFPAT_SET_DL_SRC(out, ofp_version)->dl_addr = sf->value.mac;
         break;
 
     case MFF_ETH_DST:
-        memcpy(put_OFPAT_SET_DL_DST(out, ofp_version)->dl_addr,
-               sf->value.mac, ETH_ADDR_LEN);
+        put_OFPAT_SET_DL_DST(out, ofp_version)->dl_addr = sf->value.mac;
         break;
 
     case MFF_IPV4_SRC:
@@ -2409,10 +2492,10 @@ set_field_to_set_field(const struct ofpact_set_field *sf,
                        enum ofp_version ofp_version, struct ofpbuf *out)
 {
     struct ofp12_action_set_field *oasf OVS_UNUSED;
-    size_t start_ofs = ofpbuf_size(out);
+    size_t start_ofs = out->size;
 
     oasf = put_OFPAT12_SET_FIELD(out);
-    ofpbuf_set_size(out, ofpbuf_size(out) - sizeof oasf->pad);
+    out->size = out->size - sizeof oasf->pad;
     nx_put_entry(out, sf->field->id, ofp_version, &sf->value, &sf->mask);
     pad_ofpat(out, start_ofs);
 }
@@ -2444,6 +2527,39 @@ encode_SET_FIELD(const struct ofpact_set_field *sf,
     }
 }
 
+/* Parses the input argument 'arg' into the key, value, and delimiter
+ * components that are common across the reg_load and set_field action format.
+ *
+ * With an argument like "1->metadata", sets the following pointers to
+ * point within 'arg':
+ * key: "metadata"
+ * value: "1"
+ * delim: "->"
+ *
+ * Returns NULL if successful, otherwise a malloc()'d string describing the
+ * error.  The caller is responsible for freeing the returned string. */
+static char * OVS_WARN_UNUSED_RESULT
+set_field_split_str(char *arg, char **key, char **value, char **delim)
+{
+    char *value_end;
+
+    *value = arg;
+    value_end = strstr(arg, "->");
+    *key = value_end + strlen("->");
+    if (delim) {
+        *delim = value_end;
+    }
+
+    if (!value_end) {
+        return xasprintf("%s: missing `->'", arg);
+    }
+    if (strlen(value_end) <= strlen("->")) {
+        return xasprintf("%s: missing field name following `->'", arg);
+    }
+
+    return NULL;
+}
+
 /* Parses a "set_field" action with argument 'arg', appending the parsed
  * action to 'ofpacts'.
  *
@@ -2460,16 +2576,11 @@ set_field_parse__(char *arg, struct ofpbuf *ofpacts,
     const struct mf_field *mf;
     char *error;
 
-    value = arg;
-    delim = strstr(arg, "->");
-    if (!delim) {
-        return xasprintf("%s: missing `->'", arg);
-    }
-    if (strlen(delim) <= strlen("->")) {
-        return xasprintf("%s: missing field name following `->'", arg);
+    error = set_field_split_str(arg, &key, &value, &delim);
+    if (error) {
+        return error;
     }
 
-    key = delim + strlen("->");
     mf = mf_from_name(key);
     if (!mf) {
         return xasprintf("%s is not a valid OXM field name", key);
@@ -2511,30 +2622,44 @@ static char * OVS_WARN_UNUSED_RESULT
 parse_reg_load(char *arg, struct ofpbuf *ofpacts)
 {
     struct ofpact_set_field *sf = ofpact_put_reg_load(ofpacts);
-    const char *full_arg = arg;
-    uint64_t value = strtoull(arg, (char **) &arg, 0);
     struct mf_subfield dst;
+    char *key, *value_str;
+    union mf_value value;
     char *error;
 
-    if (strncmp(arg, "->", 2)) {
-        return xasprintf("%s: missing `->' following value", full_arg);
+    error = set_field_split_str(arg, &key, &value_str, NULL);
+    if (error) {
+        return error;
     }
-    arg += 2;
-    error = mf_parse_subfield(&dst, arg);
+
+    error = mf_parse_subfield(&dst, key);
     if (error) {
         return error;
     }
 
-    if (dst.n_bits < 64 && (value >> dst.n_bits) != 0) {
-        return xasprintf("%s: value %"PRIu64" does not fit into %d bits",
-                         full_arg, value, dst.n_bits);
+    if (parse_int_string(value_str, (uint8_t *)&value, dst.field->n_bytes,
+                         &key)) {
+        return xasprintf("%s: cannot parse integer value", arg);
+    }
+
+    if (!bitwise_is_all_zeros(&value, dst.field->n_bytes, dst.n_bits,
+                              dst.field->n_bytes * 8 - dst.n_bits)) {
+        struct ds ds;
+
+        ds_init(&ds);
+        mf_format(dst.field, &value, NULL, &ds);
+        error = xasprintf("%s: value %s does not fit into %d bits",
+                          arg, ds_cstr(&ds), dst.n_bits);
+        ds_destroy(&ds);
+        return error;
     }
 
     sf->field = dst.field;
     memset(&sf->value, 0, sizeof sf->value);
-    bitwise_put(value, &sf->value, dst.field->n_bytes, dst.ofs, dst.n_bits);
-    bitwise_put(UINT64_MAX, &sf->mask,
-                dst.field->n_bytes, dst.ofs, dst.n_bits);
+    bitwise_copy(&value, dst.field->n_bytes, 0, &sf->value,
+                 dst.field->n_bytes, dst.ofs, dst.n_bits);
+    bitwise_one(&sf->mask, dst.field->n_bytes, dst.ofs, dst.n_bits);
+
     return NULL;
 }
 
@@ -2606,9 +2731,9 @@ decode_stack_action(const struct nx_action_stack *nasp,
     if (error) {
         return error;
     }
-    stack_action->subfield.n_bits = ntohs(*(const ovs_be16 *) ofpbuf_data(&b));
+    stack_action->subfield.n_bits = ntohs(*(const ovs_be16 *) b.data);
     ofpbuf_pull(&b, 2);
-    if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+    if (!is_all_zeros(b.data, b.size)) {
         return OFPERR_NXBRC_MUST_BE_ZERO;
     }
 
@@ -2617,7 +2742,8 @@ decode_stack_action(const struct nx_action_stack *nasp,
 
 static enum ofperr
 decode_NXAST_RAW_STACK_PUSH(const struct nx_action_stack *nasp,
-                             struct ofpbuf *ofpacts)
+                            enum ofp_version ofp_version OVS_UNUSED,
+                            struct ofpbuf *ofpacts)
 {
     struct ofpact_stack *push = ofpact_put_STACK_PUSH(ofpacts);
     enum ofperr error = decode_stack_action(nasp, push);
@@ -2626,6 +2752,7 @@ decode_NXAST_RAW_STACK_PUSH(const struct nx_action_stack *nasp,
 
 static enum ofperr
 decode_NXAST_RAW_STACK_POP(const struct nx_action_stack *nasp,
+                           enum ofp_version ofp_version OVS_UNUSED,
                            struct ofpbuf *ofpacts)
 {
     struct ofpact_stack *pop = ofpact_put_STACK_POP(ofpacts);
@@ -2726,13 +2853,14 @@ decode_OFPAT_RAW_DEC_NW_TTL(struct ofpbuf *out)
     ids = ofpact_put_DEC_TTL(out);
     ids->n_controllers = 1;
     ofpbuf_put(out, &id, sizeof id);
-    ids = out->frame;
+    ids = out->header;
     ofpact_update_len(out, &ids->ofpact);
     return error;
 }
 
 static enum ofperr
 decode_NXAST_RAW_DEC_TTL_CNT_IDS(const struct nx_action_cnt_ids *nac_ids,
+                                 enum ofp_version ofp_version OVS_UNUSED,
                                  struct ofpbuf *out)
 {
     struct ofpact_cnt_ids *ids;
@@ -2760,7 +2888,7 @@ decode_NXAST_RAW_DEC_TTL_CNT_IDS(const struct nx_action_cnt_ids *nac_ids,
     for (i = 0; i < ids->n_controllers; i++) {
         uint16_t id = ntohs(((ovs_be16 *)(nac_ids + 1))[i]);
         ofpbuf_put(out, &id, sizeof id);
-        ids = out->frame;
+        ids = out->header;
     }
 
     ofpact_update_len(out, &ids->ofpact);
@@ -2800,7 +2928,7 @@ parse_noargs_dec_ttl(struct ofpbuf *ofpacts)
 
     ofpact_put_DEC_TTL(ofpacts);
     ofpbuf_put(ofpacts, &id, sizeof id);
-    ids = ofpacts->frame;
+    ids = ofpacts->header;
     ids->n_controllers++;
     ofpact_update_len(ofpacts, &ids->ofpact);
 }
@@ -2822,7 +2950,7 @@ parse_DEC_TTL(char *arg, struct ofpbuf *ofpacts,
             uint16_t id = atoi(cntr);
 
             ofpbuf_put(ofpacts, &id, sizeof id);
-            ids = ofpacts->frame;
+            ids = ofpacts->header;
             ids->n_controllers++;
         }
         if (!ids->n_controllers) {
@@ -2855,7 +2983,9 @@ format_DEC_TTL(const struct ofpact_cnt_ids *a, struct ds *s)
 /* Set MPLS label actions. */
 
 static enum ofperr
-decode_OFPAT_RAW_SET_MPLS_LABEL(ovs_be32 label, struct ofpbuf *out)
+decode_OFPAT_RAW_SET_MPLS_LABEL(ovs_be32 label,
+                                enum ofp_version ofp_version OVS_UNUSED,
+                                struct ofpbuf *out)
 {
     ofpact_put_SET_MPLS_LABEL(out)->label = label;
     return 0;
@@ -2896,7 +3026,9 @@ format_SET_MPLS_LABEL(const struct ofpact_mpls_label *a, struct ds *s)
 /* Set MPLS TC actions. */
 
 static enum ofperr
-decode_OFPAT_RAW_SET_MPLS_TC(uint8_t tc, struct ofpbuf *out)
+decode_OFPAT_RAW_SET_MPLS_TC(uint8_t tc,
+                             enum ofp_version ofp_version OVS_UNUSED,
+                             struct ofpbuf *out)
 {
     ofpact_put_SET_MPLS_TC(out)->tc = tc;
     return 0;
@@ -2936,7 +3068,9 @@ format_SET_MPLS_TC(const struct ofpact_mpls_tc *a, struct ds *s)
 /* Set MPLS TTL actions. */
 
 static enum ofperr
-decode_OFPAT_RAW_SET_MPLS_TTL(uint8_t ttl, struct ofpbuf *out)
+decode_OFPAT_RAW_SET_MPLS_TTL(uint8_t ttl,
+                              enum ofp_version ofp_version OVS_UNUSED,
+                              struct ofpbuf *out)
 {
     ofpact_put_SET_MPLS_TTL(out)->ttl = ttl;
     return 0;
@@ -3007,7 +3141,9 @@ format_DEC_MPLS_TTL(const struct ofpact_null *a OVS_UNUSED, struct ds *s)
 /* Push MPLS label action. */
 
 static enum ofperr
-decode_OFPAT_RAW_PUSH_MPLS(ovs_be16 ethertype, struct ofpbuf *out)
+decode_OFPAT_RAW_PUSH_MPLS(ovs_be16 ethertype,
+                           enum ofp_version ofp_version OVS_UNUSED,
+                           struct ofpbuf *out)
 {
     struct ofpact_push_mpls *oam;
 
@@ -3050,7 +3186,9 @@ format_PUSH_MPLS(const struct ofpact_push_mpls *a, struct ds *s)
 /* Pop MPLS label action. */
 
 static enum ofperr
-decode_OFPAT_RAW_POP_MPLS(ovs_be16 ethertype, struct ofpbuf *out)
+decode_OFPAT_RAW_POP_MPLS(ovs_be16 ethertype,
+                          enum ofp_version ofp_version OVS_UNUSED,
+                          struct ofpbuf *out)
 {
     ofpact_put_POP_MPLS(out)->ethertype = ethertype;
     return 0;
@@ -3086,7 +3224,9 @@ format_POP_MPLS(const struct ofpact_pop_mpls *a, struct ds *s)
 /* Set tunnel ID actions. */
 
 static enum ofperr
-decode_NXAST_RAW_SET_TUNNEL(uint32_t tun_id, struct ofpbuf *out)
+decode_NXAST_RAW_SET_TUNNEL(uint32_t tun_id,
+                            enum ofp_version ofp_version OVS_UNUSED,
+                            struct ofpbuf *out)
 {
     struct ofpact_tunnel *tunnel = ofpact_put_SET_TUNNEL(out);
     tunnel->ofpact.raw = NXAST_RAW_SET_TUNNEL;
@@ -3095,7 +3235,9 @@ decode_NXAST_RAW_SET_TUNNEL(uint32_t tun_id, struct ofpbuf *out)
 }
 
 static enum ofperr
-decode_NXAST_RAW_SET_TUNNEL64(uint64_t tun_id, struct ofpbuf *out)
+decode_NXAST_RAW_SET_TUNNEL64(uint64_t tun_id,
+                              enum ofp_version ofp_version OVS_UNUSED,
+                              struct ofpbuf *out)
 {
     struct ofpact_tunnel *tunnel = ofpact_put_SET_TUNNEL(out);
     tunnel->ofpact.raw = NXAST_RAW_SET_TUNNEL64;
@@ -3151,7 +3293,9 @@ format_SET_TUNNEL(const struct ofpact_tunnel *a, struct ds *s)
 /* Set queue action. */
 
 static enum ofperr
-decode_OFPAT_RAW_SET_QUEUE(uint32_t queue_id, struct ofpbuf *out)
+decode_OFPAT_RAW_SET_QUEUE(uint32_t queue_id,
+                           enum ofp_version ofp_version OVS_UNUSED,
+                           struct ofpbuf *out)
 {
     ofpact_put_SET_QUEUE(out)->queue_id = queue_id;
     return 0;
@@ -3243,6 +3387,7 @@ OFP_ASSERT(sizeof(struct nx_action_fin_timeout) == 16);
 
 static enum ofperr
 decode_NXAST_RAW_FIN_TIMEOUT(const struct nx_action_fin_timeout *naft,
+                             enum ofp_version ofp_version OVS_UNUSED,
                              struct ofpbuf *out)
 {
     struct ofpact_fin_timeout *oft;
@@ -3361,7 +3506,9 @@ struct nx_action_resubmit {
 OFP_ASSERT(sizeof(struct nx_action_resubmit) == 16);
 
 static enum ofperr
-decode_NXAST_RAW_RESUBMIT(uint16_t port, struct ofpbuf *out)
+decode_NXAST_RAW_RESUBMIT(uint16_t port,
+                          enum ofp_version ofp_version OVS_UNUSED,
+                          struct ofpbuf *out)
 {
     struct ofpact_resubmit *resubmit;
 
@@ -3374,6 +3521,7 @@ decode_NXAST_RAW_RESUBMIT(uint16_t port, struct ofpbuf *out)
 
 static enum ofperr
 decode_NXAST_RAW_RESUBMIT_TABLE(const struct nx_action_resubmit *nar,
+                                enum ofp_version ofp_version OVS_UNUSED,
                                 struct ofpbuf *out)
 {
     struct ofpact_resubmit *resubmit;
@@ -3657,7 +3805,24 @@ format_RESUBMIT(const struct ofpact_resubmit *a, struct ds *s)
  * address.  This is not usually the intent in MAC learning; instead, we want
  * the MAC learn entry to expire when no traffic has been sent *from* the
  * learned address.  Use a hard timeout for that.
- */
+ *
+ *
+ * Visibility of Changes
+ * ---------------------
+ *
+ * Prior to Open vSwitch 2.4, any changes made by a "learn" action in a given
+ * flow translation are visible to flow table lookups made later in the flow
+ * translation.  This means that, in the example above, a MAC learned by the
+ * learn action in table 0 would be found in table 1 (if the packet being
+ * processed had the same source and destination MAC address).
+ *
+ * In Open vSwitch 2.4 and later, changes to a flow table (whether to add or
+ * modify a flow) by a "learn" action are visible only for later flow
+ * translations, not for later lookups within the same flow translation.  In
+ * the MAC learning example, a MAC learned by the learn action in table 0 would
+ * not be found in table 1 if the flow translation would resubmit to table 1
+ * after the processing of the learn action, meaning that if this MAC had not
+ * been learned before then the packet would be flooded. */
 struct nx_action_learn {
     ovs_be16 type;              /* OFPAT_VENDOR. */
     ovs_be16 len;               /* At least 24. */
@@ -3730,6 +3895,7 @@ learn_min_len(uint16_t header)
  * 'ofpacts'.  Returns 0 if successful, otherwise an OFPERR_*. */
 static enum ofperr
 decode_NXAST_RAW_LEARN(const struct nx_action_learn *nal,
+                       enum ofp_version ofp_version OVS_UNUSED,
                        struct ofpbuf *ofpacts)
 {
     struct ofpact_learn *learn;
@@ -3769,7 +3935,7 @@ decode_NXAST_RAW_LEARN(const struct nx_action_learn *nal,
         }
 
         spec = ofpbuf_put_zeros(ofpacts, sizeof *spec);
-        learn = ofpacts->frame;
+        learn = ofpacts->header;
         learn->n_specs++;
 
         spec->src_type = header & NX_LEARN_SRC_MASK;
@@ -3850,7 +4016,7 @@ encode_LEARN(const struct ofpact_learn *learn,
     struct nx_action_learn *nal;
     size_t start_ofs;
 
-    start_ofs = ofpbuf_size(out);
+    start_ofs = out->size;
     nal = put_NXAST_LEARN(out);
     nal->idle_timeout = htons(learn->idle_timeout);
     nal->hard_timeout = htons(learn->hard_timeout);
@@ -3898,6 +4064,90 @@ format_LEARN(const struct ofpact_learn *a, struct ds *s)
     learn_format(a, s);
 }
 \f
+/* Action structure for NXAST_CONJUNCTION. */
+struct nx_action_conjunction {
+    ovs_be16 type;                  /* OFPAT_VENDOR. */
+    ovs_be16 len;                   /* At least 16. */
+    ovs_be32 vendor;                /* NX_VENDOR_ID. */
+    ovs_be16 subtype;               /* See enum ofp_raw_action_type. */
+    uint8_t clause;
+    uint8_t n_clauses;
+    ovs_be32 id;
+};
+OFP_ASSERT(sizeof(struct nx_action_conjunction) == 16);
+
+static void
+add_conjunction(struct ofpbuf *out,
+                uint32_t id, uint8_t clause, uint8_t n_clauses)
+{
+    struct ofpact_conjunction *oc;
+
+    oc = ofpact_put_CONJUNCTION(out);
+    oc->id = id;
+    oc->clause = clause;
+    oc->n_clauses = n_clauses;
+}
+
+static enum ofperr
+decode_NXAST_RAW_CONJUNCTION(const struct nx_action_conjunction *nac,
+                             enum ofp_version ofp_version OVS_UNUSED,
+                             struct ofpbuf *out)
+{
+    if (nac->n_clauses < 2 || nac->n_clauses > 64
+        || nac->clause >= nac->n_clauses) {
+        return OFPERR_NXBAC_BAD_CONJUNCTION;
+    } else {
+        add_conjunction(out, ntohl(nac->id), nac->clause, nac->n_clauses);
+        return 0;
+    }
+}
+
+static void
+encode_CONJUNCTION(const struct ofpact_conjunction *oc,
+                   enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out)
+{
+    struct nx_action_conjunction *nac = put_NXAST_CONJUNCTION(out);
+    nac->clause = oc->clause;
+    nac->n_clauses = oc->n_clauses;
+    nac->id = htonl(oc->id);
+}
+
+static void
+format_CONJUNCTION(const struct ofpact_conjunction *oc, struct ds *s)
+{
+    ds_put_format(s, "conjunction(%"PRIu32",%"PRIu8"/%"PRIu8")",
+                  oc->id, oc->clause + 1, oc->n_clauses);
+}
+
+static char * OVS_WARN_UNUSED_RESULT
+parse_CONJUNCTION(const char *arg, struct ofpbuf *ofpacts,
+                  enum ofputil_protocol *usable_protocols OVS_UNUSED)
+{
+    uint8_t n_clauses;
+    uint8_t clause;
+    uint32_t id;
+    int n;
+
+    if (!ovs_scan(arg, "%"SCNi32" , %"SCNu8" / %"SCNu8" %n",
+                  &id, &clause, &n_clauses, &n) || n != strlen(arg)) {
+        return xstrdup("\"conjunction\" syntax is \"conjunction(id,i/n)\"");
+    }
+
+    if (n_clauses < 2) {
+        return xstrdup("conjunction must have at least 2 clauses");
+    } else if (n_clauses > 64) {
+        return xstrdup("conjunction must have at most 64 clauses");
+    } else if (clause < 1) {
+        return xstrdup("clause index must be positive");
+    } else if (clause > n_clauses) {
+        return xstrdup("clause index must be less than or equal to "
+                       "number of clauses");
+    }
+
+    add_conjunction(ofpacts, id, clause - 1, n_clauses);
+    return NULL;
+}
+\f
 /* Action structure for NXAST_MULTIPATH.
  *
  * This action performs the following steps in sequence:
@@ -3956,6 +4206,7 @@ OFP_ASSERT(sizeof(struct nx_action_multipath) == 32);
 
 static enum ofperr
 decode_NXAST_RAW_MULTIPATH(const struct nx_action_multipath *nam,
+                           enum ofp_version ofp_version OVS_UNUSED,
                            struct ofpbuf *out)
 {
     uint32_t n_links = ntohs(nam->max_link) + 1;
@@ -4037,7 +4288,9 @@ struct nx_action_note {
 OFP_ASSERT(sizeof(struct nx_action_note) == 16);
 
 static enum ofperr
-decode_NXAST_RAW_NOTE(const struct nx_action_note *nan, struct ofpbuf *out)
+decode_NXAST_RAW_NOTE(const struct nx_action_note *nan,
+                      enum ofp_version ofp_version OVS_UNUSED,
+                      struct ofpbuf *out)
 {
     struct ofpact_note *note;
     unsigned int length;
@@ -4055,23 +4308,23 @@ static void
 encode_NOTE(const struct ofpact_note *note,
             enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out)
 {
-    size_t start_ofs = ofpbuf_size(out);
+    size_t start_ofs = out->size;
     struct nx_action_note *nan;
     unsigned int remainder;
     unsigned int len;
 
     put_NXAST_NOTE(out);
-    ofpbuf_set_size(out, ofpbuf_size(out) - sizeof nan->note);
+    out->size = out->size - sizeof nan->note;
 
     ofpbuf_put(out, note->data, note->length);
 
-    len = ofpbuf_size(out) - start_ofs;
+    len = out->size - start_ofs;
     remainder = len % OFP_ACTION_ALIGN;
     if (remainder) {
         ofpbuf_put_zeros(out, OFP_ACTION_ALIGN - remainder);
     }
     nan = ofpbuf_at(out, start_ofs, sizeof *nan);
-    nan->len = htons(ofpbuf_size(out) - start_ofs);
+    nan->len = htons(out->size - start_ofs);
 }
 
 static char * OVS_WARN_UNUSED_RESULT
@@ -4098,7 +4351,7 @@ parse_NOTE(const char *arg, struct ofpbuf *ofpacts,
         }
         ofpbuf_put(ofpacts, &byte, 1);
 
-        note = ofpacts->frame;
+        note = ofpacts->header;
         note->length++;
 
         arg += 2;
@@ -4151,6 +4404,31 @@ format_EXIT(const struct ofpact_null *a OVS_UNUSED, struct ds *s)
     ds_put_cstr(s, "exit");
 }
 \f
+/* Unroll xlate action. */
+
+static void
+encode_UNROLL_XLATE(const struct ofpact_unroll_xlate *unroll OVS_UNUSED,
+                    enum ofp_version ofp_version OVS_UNUSED,
+                    struct ofpbuf *out OVS_UNUSED)
+{
+    OVS_NOT_REACHED();
+}
+
+static char * OVS_WARN_UNUSED_RESULT
+parse_UNROLL_XLATE(char *arg OVS_UNUSED, struct ofpbuf *ofpacts OVS_UNUSED,
+                   enum ofputil_protocol *usable_protocols OVS_UNUSED)
+{
+    OVS_NOT_REACHED();
+    return NULL;
+}
+
+static void
+format_UNROLL_XLATE(const struct ofpact_unroll_xlate *a OVS_UNUSED,
+                    struct ds *s)
+{
+    ds_put_cstr(s, "unroll_xlate");
+}
+\f
 /* Action structure for NXAST_SAMPLE.
  *
  * Samples matching packets with the given probability and sends them
@@ -4177,7 +4455,9 @@ struct nx_action_sample {
 OFP_ASSERT(sizeof(struct nx_action_sample) == 24);
 
 static enum ofperr
-decode_NXAST_RAW_SAMPLE(const struct nx_action_sample *nas, struct ofpbuf *out)
+decode_NXAST_RAW_SAMPLE(const struct nx_action_sample *nas,
+                        enum ofp_version ofp_version OVS_UNUSED,
+                        struct ofpbuf *out)
 {
     struct ofpact_sample *sample;
 
@@ -4256,6 +4536,281 @@ format_SAMPLE(const struct ofpact_sample *a, struct ds *s)
                   a->obs_domain_id, a->obs_point_id);
 }
 \f
+/* debug_recirc instruction. */
+
+static bool enable_debug;
+
+void
+ofpact_dummy_enable(void)
+{
+    enable_debug = true;
+}
+
+static enum ofperr
+decode_NXAST_RAW_DEBUG_RECIRC(struct ofpbuf *out)
+{
+    if (!enable_debug) {
+        return OFPERR_OFPBAC_BAD_VENDOR_TYPE;
+    }
+
+    ofpact_put_DEBUG_RECIRC(out);
+    return 0;
+}
+
+static void
+encode_DEBUG_RECIRC(const struct ofpact_null *n OVS_UNUSED,
+                    enum ofp_version ofp_version OVS_UNUSED,
+                    struct ofpbuf *out)
+{
+    put_NXAST_DEBUG_RECIRC(out);
+}
+
+static char * OVS_WARN_UNUSED_RESULT
+parse_DEBUG_RECIRC(char *arg OVS_UNUSED, struct ofpbuf *ofpacts,
+                   enum ofputil_protocol *usable_protocols OVS_UNUSED)
+{
+    ofpact_put_DEBUG_RECIRC(ofpacts);
+    return NULL;
+}
+
+static void
+format_DEBUG_RECIRC(const struct ofpact_null *a OVS_UNUSED, struct ds *s)
+{
+    ds_put_cstr(s, "debug_recirc");
+}
+
+/* Action structure for NXAST_CT.
+ *
+ * Pass traffic to the connection tracker.
+ *
+ * There are two important concepts to understanding the connection tracking
+ * interface: Packet state and Connection state. Packets may be "Untracked" or
+ * "Tracked". Connections may be "Uncommitted" or "Committed".
+ *
+ *   - Packet State:
+ *
+ *      Untracked packets have not yet passed through the connection tracker,
+ *      and the connection state for such packets is unknown. In most cases,
+ *      packets entering the OpenFlow pipeline will initially be in the
+ *      untracked state. Untracked packets may become tracked by executing
+ *      NXAST_CT with a "recirc_table" specified. This makes various aspects
+ *      about the connection available, in particular the connection state.
+ *
+ *      Tracked packets have previously passed through the connection tracker.
+ *      These packets will remain tracked through until the end of the OpenFlow
+ *      pipeline. Tracked packets which have NXAST_CT executed with a
+ *      "recirc_table" specified will return to the tracked state.
+ *
+ *      The packet state is only significant for the duration of packet
+ *      processing within the OpenFlow pipeline.
+ *
+ *   - Connection State:
+ *
+ *      Multiple packets may be associated with a single connection. Initially,
+ *      all connections are uncommitted. The connection state corresponding to
+ *      a packet is available in the NXM_NX_CT_STATE field for tracked packets.
+ *
+ *      Uncommitted connections have no state stored about them. Uncommitted
+ *      connections may transition into the committed state by executing
+ *      NXAST_CT with the NX_CT_F_COMMIT flag.
+ *
+ *      Once a connection becomes committed, information may be gathered about
+ *      the connection by passing subsequent packets through the connection
+ *      tracker, and the state of the connection will be stored beyond the
+ *      lifetime of packet processing.
+ *
+ *      Connections may transition back into the uncommitted state due to
+ *      external timers, or due to the contents of packets that are sent to the
+ *      connection tracker. This behaviour is outside of the scope of the
+ *      OpenFlow interface.
+ *
+ * The "zone" specifies a context within which the tracking is done:
+ *
+ *      The connection tracking zone is a 16-bit number. Each zone is an
+ *      independent connection tracking context. The connection state for each
+ *      connection is completely separate for each zone, so if a connection
+ *      is committed to zone A, then it will remain uncommitted in zone B.
+ *      If NXAST_CT is executed with the same zone multiple times, later
+ *      executions have no effect.
+ *
+ *      If 'zone_src' is nonzero, this specifies that the zone should be
+ *      sourced from a field zone_src[ofs:ofs+nbits]. The format and semantics
+ *      of 'zone_src' and 'zone_ofs_nbits' are similar to those for the
+ *      NXAST_REG_LOAD action. The acceptable nxm_header values for 'zone_src'
+ *      are the same as the acceptable nxm_header values for the 'src' field of
+ *      NXAST_REG_MOVE.
+ *
+ *      If 'zone_src' is zero, then the value of 'zone_imm' will be used as the
+ *      connection tracking zone.
+ *
+ * The "recirc_table" allows NXM_NX_CT_* fields to become available:
+ *
+ *      If "recirc_table" has a value other than NX_CT_RECIRC_NONE, then the
+ *      packet will be logically cloned prior to executing this action. One
+ *      copy will be sent to the connection tracker, then will be re-injected
+ *      into the OpenFlow pipeline beginning at the OpenFlow table specified in
+ *      this field. When the packet re-enters the pipeline, the NXM_NX_CT_*
+ *      fields will be populated. The original instance of the packet will
+ *      continue the current actions list. This can be thought of as similar to
+ *      the effect of the "output" action: One copy is sent out (in this case,
+ *      to the connection tracker), but the current copy continues processing.
+ *
+ *      It is strongly recommended that this table is later than the current
+ *      table, to prevent loops.
+ */
+struct nx_action_conntrack {
+    ovs_be16 type;              /* OFPAT_VENDOR. */
+    ovs_be16 len;               /* At least 24. */
+    ovs_be32 vendor;            /* NX_VENDOR_ID. */
+    ovs_be16 subtype;           /* NXAST_CT. */
+    ovs_be16 flags;             /* Zero or more NX_CT_F_* flags.
+                                 * Unspecified flag bits must be zero. */
+    ovs_be32 zone_src;          /* Connection tracking context. */
+    union {
+        ovs_be16 zone_ofs_nbits;/* Range to use from source field. */
+        ovs_be16 zone_imm;      /* Immediate value for zone. */
+    };
+    uint8_t recirc_table;       /* Recirculate to a specific table, or
+                                   NX_CT_RECIRC_NONE for no recirculation. */
+    uint8_t pad[5];             /* Zeroes */
+    /* Followed by a sequence of zero or more OpenFlow actions. The length of
+     * these is included in 'len'. */
+};
+OFP_ASSERT(sizeof(struct nx_action_conntrack) == 24);
+
+static enum ofperr
+decode_ct_zone(const struct nx_action_conntrack *nac,
+               struct ofpact_conntrack *out)
+{
+    if (nac->zone_src) {
+        enum ofperr error;
+
+        out->zone_src.field = mf_from_nxm_header(ntohl(nac->zone_src));
+        out->zone_src.ofs = nxm_decode_ofs(nac->zone_ofs_nbits);
+        out->zone_src.n_bits = nxm_decode_n_bits(nac->zone_ofs_nbits);
+        error = mf_check_src(&out->zone_src, NULL);
+        if (error) {
+            return error;
+        }
+
+        if (out->zone_src.n_bits != 16) {
+            VLOG_WARN_RL(&rl, "zone n_bits %d not within valid range [16..16]",
+                         out->zone_src.n_bits);
+            return OFPERR_OFPBAC_BAD_SET_LEN;
+        }
+    } else {
+        out->zone_src.field = NULL;
+        out->zone_imm = ntohs(nac->zone_imm);
+    }
+
+    return 0;
+}
+
+static enum ofperr
+decode_NXAST_RAW_CT(const struct nx_action_conntrack *nac,
+                    enum ofp_version ofp_version OVS_UNUSED,
+                    struct ofpbuf *out)
+{
+    struct ofpact_conntrack *conntrack;
+    int error = 0;
+
+    conntrack = ofpact_put_CT(out);
+    conntrack->flags = ntohs(nac->flags);
+    error = decode_ct_zone(nac, conntrack);
+    if (error) {
+        goto out;
+    }
+    conntrack->recirc_table = nac->recirc_table;
+
+out:
+    return error;
+}
+
+static void
+encode_CT(const struct ofpact_conntrack *conntrack,
+          enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out)
+{
+    struct nx_action_conntrack *nac;
+
+    nac = put_NXAST_CT(out);
+    nac->flags = htons(conntrack->flags);
+    if (conntrack->zone_src.field) {
+        nac->zone_src = htonl(mf_nxm_header(conntrack->zone_src.field->id));
+        nac->zone_ofs_nbits = nxm_encode_ofs_nbits(conntrack->zone_src.ofs,
+                                                   conntrack->zone_src.n_bits);
+    } else {
+        nac->zone_src = htonl(0);
+        nac->zone_imm = htons(conntrack->zone_imm);
+    }
+    nac->recirc_table = conntrack->recirc_table;
+}
+
+/* Parses 'arg' as the argument to a "ct" action, and appends such an
+ * action to 'ofpacts'.
+ *
+ * Returns NULL if successful, otherwise a malloc()'d string describing the
+ * error.  The caller is responsible for freeing the returned string. */
+static char * OVS_WARN_UNUSED_RESULT
+parse_CT(char *arg, struct ofpbuf *ofpacts,
+         enum ofputil_protocol *usable_protocols OVS_UNUSED)
+{
+    struct ofpact_conntrack *oc;
+    char *error = NULL;
+    char *key, *value;
+
+    oc = ofpact_put_CT(ofpacts);
+    oc->flags = 0;
+    oc->recirc_table = NX_CT_RECIRC_NONE;
+    while (ofputil_parse_key_value(&arg, &key, &value)) {
+        if (!strcmp(key, "commit")) {
+            oc->flags |= NX_CT_F_COMMIT;
+        } else if (!strcmp(key, "table")) {
+            error = str_to_u8(value, "recirc_table", &oc->recirc_table);
+            if (!error && oc->recirc_table == NX_CT_RECIRC_NONE) {
+                error = xasprintf("invalid table %#"PRIx16, oc->recirc_table);
+            }
+        } else if (!strcmp(key, "zone")) {
+            error = str_to_u16(value, "zone", &oc->zone_imm);
+
+            if (error) {
+                free(error);
+                error = mf_parse_subfield(&oc->zone_src, value);
+                if (error) {
+                    return error;
+                }
+            }
+        } else {
+            error = xasprintf("invalid argument to \"ct\" action: `%s'", key);
+        }
+        if (error) {
+            break;
+        }
+    }
+
+    return error;
+}
+
+static void
+format_CT(const struct ofpact_conntrack *a, struct ds *s)
+{
+    ds_put_cstr(s, "ct(");
+    if (a->flags & NX_CT_F_COMMIT) {
+        ds_put_cstr(s, "commit,");
+    }
+    if (a->recirc_table != NX_CT_RECIRC_NONE) {
+        ds_put_format(s, "table=%"PRIu8",", a->recirc_table);
+    }
+    if (a->zone_src.field) {
+        ds_put_format(s, "zone=");
+        mf_format_subfield(&a->zone_src, s);
+        ds_put_char(s, ',');
+    } else if (a->zone_imm) {
+        ds_put_format(s, "zone=%"PRIu16",", a->zone_imm);
+    }
+    ds_chomp(s, ',');
+    ds_put_char(s, ')');
+}
+\f
 /* Meter instruction. */
 
 static void
@@ -4314,7 +4869,7 @@ encode_WRITE_ACTIONS(const struct ofpact_nest *actions,
                      enum ofp_version ofp_version, struct ofpbuf *out)
 {
     if (ofp_version > OFP10_VERSION) {
-        const size_t ofs = ofpbuf_size(out);
+        const size_t ofs = out->size;
 
         instruction_put_OFPIT11_WRITE_ACTIONS(out);
         ofpacts_put_openflow_actions(actions->actions,
@@ -4328,14 +4883,9 @@ static char * OVS_WARN_UNUSED_RESULT
 parse_WRITE_ACTIONS(char *arg, struct ofpbuf *ofpacts,
                     enum ofputil_protocol *usable_protocols)
 {
+    size_t ofs = ofpacts_pull(ofpacts);
     struct ofpact_nest *on;
     char *error;
-    size_t ofs;
-
-    /* Pull off existing actions or instructions. */
-    ofpact_pad(ofpacts);
-    ofs = ofpbuf_size(ofpacts);
-    ofpbuf_pull(ofpacts, ofs);
 
     /* Add a Write-Actions instruction and then pull it off. */
     ofpact_put(ofpacts, OFPACT_WRITE_ACTIONS, sizeof *on);
@@ -4348,11 +4898,12 @@ parse_WRITE_ACTIONS(char *arg, struct ofpbuf *ofpacts,
      * that it doesn't actually include the nested actions.  That means that
      * ofpacts_parse() would reject them as being part of an Apply-Actions that
      * follows a Write-Actions, which is an invalid order.  */
-    error = ofpacts_parse(arg, ofpacts, usable_protocols, false);
+    error = ofpacts_parse(arg, ofpacts, usable_protocols, false,
+                          OFPACT_WRITE_ACTIONS);
 
     /* Put the Write-Actions back on and update its length. */
     on = ofpbuf_push_uninit(ofpacts, sizeof *on);
-    on->ofpact.len = ofpbuf_size(ofpacts);
+    on->ofpact.len = ofpacts->size;
 
     /* Put any previous actions or instructions back on. */
     ofpbuf_push_uninit(ofpacts, ofs);
@@ -4384,6 +4935,7 @@ OFP_ASSERT(sizeof(struct nx_action_write_metadata) == 32);
 
 static enum ofperr
 decode_NXAST_RAW_WRITE_METADATA(const struct nx_action_write_metadata *nawm,
+                                enum ofp_version ofp_version OVS_UNUSED,
                                 struct ofpbuf *out)
 {
     struct ofpact_metadata *om;
@@ -4514,15 +5066,15 @@ ofpacts_decode(const void *actions, size_t actions_len,
     struct ofpbuf openflow;
 
     ofpbuf_use_const(&openflow, actions, actions_len);
-    while (ofpbuf_size(&openflow)) {
-        const struct ofp_action_header *action = ofpbuf_data(&openflow);
+    while (openflow.size) {
+        const struct ofp_action_header *action = openflow.data;
         enum ofp_raw_action_type raw;
         enum ofperr error;
         uint64_t arg;
 
         error = ofpact_pull_raw(&openflow, ofp_version, &raw, &arg);
         if (!error) {
-            error = ofpact_decode(action, raw, arg, ofpacts);
+            error = ofpact_decode(action, raw, ofp_version, arg, ofpacts);
         }
 
         if (error) {
@@ -4540,12 +5092,15 @@ ofpacts_pull_openflow_actions__(struct ofpbuf *openflow,
                                 unsigned int actions_len,
                                 enum ofp_version version,
                                 uint32_t allowed_ovsinsts,
-                                struct ofpbuf *ofpacts)
+                                struct ofpbuf *ofpacts,
+                                enum ofpact_type outer_action)
 {
     const struct ofp_action_header *actions;
     enum ofperr error;
 
-    ofpbuf_clear(ofpacts);
+    if (!outer_action) {
+        ofpbuf_clear(ofpacts);
+    }
 
     if (actions_len % OFP_ACTION_ALIGN != 0) {
         VLOG_WARN_RL(&rl, "OpenFlow message actions length %u is not a "
@@ -4557,7 +5112,7 @@ ofpacts_pull_openflow_actions__(struct ofpbuf *openflow,
     if (actions == NULL) {
         VLOG_WARN_RL(&rl, "OpenFlow message actions length %u exceeds "
                      "remaining message length (%"PRIu32")",
-                     actions_len, ofpbuf_size(openflow));
+                     actions_len, openflow->size);
         return OFPERR_OFPBRC_BAD_LEN;
     }
 
@@ -4567,8 +5122,8 @@ ofpacts_pull_openflow_actions__(struct ofpbuf *openflow,
         return error;
     }
 
-    error = ofpacts_verify(ofpbuf_data(ofpacts), ofpbuf_size(ofpacts),
-                           allowed_ovsinsts);
+    error = ofpacts_verify(ofpacts->data, ofpacts->size, allowed_ovsinsts,
+                           outer_action);
     if (error) {
         ofpbuf_clear(ofpacts);
     }
@@ -4600,7 +5155,7 @@ ofpacts_pull_openflow_actions(struct ofpbuf *openflow,
 {
     return ofpacts_pull_openflow_actions__(openflow, actions_len, version,
                                            1u << OVSINST_OFPIT11_APPLY_ACTIONS,
-                                           ofpacts);
+                                           ofpacts, 0);
 }
 \f
 /* OpenFlow 1.1 actions. */
@@ -4635,15 +5190,18 @@ ofpact_is_set_or_move_action(const struct ofpact *a)
         return true;
     case OFPACT_BUNDLE:
     case OFPACT_CLEAR_ACTIONS:
+    case OFPACT_CT:
     case OFPACT_CONTROLLER:
     case OFPACT_DEC_MPLS_TTL:
     case OFPACT_DEC_TTL:
     case OFPACT_ENQUEUE:
     case OFPACT_EXIT:
+    case OFPACT_UNROLL_XLATE:
     case OFPACT_FIN_TIMEOUT:
     case OFPACT_GOTO_TABLE:
     case OFPACT_GROUP:
     case OFPACT_LEARN:
+    case OFPACT_CONJUNCTION:
     case OFPACT_METER:
     case OFPACT_MULTIPATH:
     case OFPACT_NOTE:
@@ -4660,6 +5218,7 @@ ofpact_is_set_or_move_action(const struct ofpact *a)
     case OFPACT_STRIP_VLAN:
     case OFPACT_WRITE_ACTIONS:
     case OFPACT_WRITE_METADATA:
+    case OFPACT_DEBUG_RECIRC:
         return false;
     default:
         OVS_NOT_REACHED();
@@ -4706,10 +5265,13 @@ ofpact_is_allowed_in_actions_set(const struct ofpact *a)
      * in the action set is undefined. */
     case OFPACT_BUNDLE:
     case OFPACT_CONTROLLER:
+    case OFPACT_CT:
     case OFPACT_ENQUEUE:
     case OFPACT_EXIT:
+    case OFPACT_UNROLL_XLATE:
     case OFPACT_FIN_TIMEOUT:
     case OFPACT_LEARN:
+    case OFPACT_CONJUNCTION:
     case OFPACT_MULTIPATH:
     case OFPACT_NOTE:
     case OFPACT_OUTPUT_REG:
@@ -4718,6 +5280,7 @@ ofpact_is_allowed_in_actions_set(const struct ofpact *a)
     case OFPACT_SAMPLE:
     case OFPACT_STACK_POP:
     case OFPACT_STACK_PUSH:
+    case OFPACT_DEBUG_RECIRC:
 
     /* The action set may only include actions and thus
      * may not include any instructions */
@@ -4748,7 +5311,7 @@ ofpacts_copy_last(struct ofpbuf *out, const struct ofpbuf *in,
     const struct ofpact *a;
 
     target = NULL;
-    OFPACT_FOR_EACH (a, ofpbuf_data(in), ofpbuf_size(in)) {
+    OFPACT_FOR_EACH (a, in->data, in->size) {
         if (a->type == filter) {
             target = a;
         }
@@ -4767,7 +5330,7 @@ ofpacts_copy_all(struct ofpbuf *out, const struct ofpbuf *in,
 {
     const struct ofpact *a;
 
-    OFPACT_FOR_EACH (a, ofpbuf_data(in), ofpbuf_size(in)) {
+    OFPACT_FOR_EACH (a, in->data, in->size) {
         if (filter(a)) {
             ofpact_copy(out, a);
         }
@@ -4780,7 +5343,7 @@ ofpacts_copy_all(struct ofpbuf *out, const struct ofpbuf *in,
  * "Action Set" and "Action List" terms used in OpenFlow 1.1+.)
  *
  * In general this involves appending the last instance of each action that is
- * adimissible in the action set in the order described in the OpenFlow
+ * admissible in the action set in the order described in the OpenFlow
  * specification.
  *
  * Exceptions:
@@ -4826,7 +5389,7 @@ ofpacts_decode_for_action_set(const struct ofp_action_header *in,
 {
     enum ofperr error;
     struct ofpact *a;
-    size_t start = ofpbuf_size(out);
+    size_t start = out->size;
 
     error = ofpacts_decode(in, n_in, version, out);
 
@@ -4834,7 +5397,7 @@ ofpacts_decode_for_action_set(const struct ofp_action_header *in,
         return error;
     }
 
-    OFPACT_FOR_EACH (a, ofpact_end(ofpbuf_data(out), start), ofpbuf_size(out) - start) {
+    OFPACT_FOR_EACH (a, ofpact_end(out->data, start), out->size - start) {
         if (!ofpact_is_allowed_in_actions_set(a)) {
             VLOG_WARN_RL(&rl, "disallowed action in action set");
             return OFPERR_OFPBAC_BAD_TYPE;
@@ -4925,10 +5488,14 @@ ovs_instruction_type_from_ofpact_type(enum ofpact_type type)
     case OFPACT_FIN_TIMEOUT:
     case OFPACT_RESUBMIT:
     case OFPACT_LEARN:
+    case OFPACT_CONJUNCTION:
     case OFPACT_MULTIPATH:
     case OFPACT_NOTE:
     case OFPACT_EXIT:
+    case OFPACT_UNROLL_XLATE:
     case OFPACT_SAMPLE:
+    case OFPACT_DEBUG_RECIRC:
+    case OFPACT_CT:
     default:
         return OVSINST_OFPIT11_APPLY_ACTIONS;
     }
@@ -5128,7 +5695,7 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
         return ofpacts_pull_openflow_actions__(openflow, instructions_len,
                                                version,
                                                (1u << N_OVS_INSTRUCTIONS) - 1,
-                                               ofpacts);
+                                               ofpacts, 0);
     }
 
     ofpbuf_clear(ofpacts);
@@ -5145,7 +5712,7 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
     if (instructions == NULL) {
         VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u exceeds "
                      "remaining message length (%"PRIu32")",
-                     instructions_len, ofpbuf_size(openflow));
+                     instructions_len, openflow->size);
         error = OFPERR_OFPBIC_BAD_LEN;
         goto exit;
     }
@@ -5190,9 +5757,9 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
         size_t start;
 
         ofpact_pad(ofpacts);
-        start = ofpbuf_size(ofpacts);
-        on = ofpact_put(ofpacts, OFPACT_WRITE_ACTIONS,
-                        offsetof(struct ofpact_nest, actions));
+        start = ofpacts->size;
+        ofpact_put(ofpacts, OFPACT_WRITE_ACTIONS,
+                   offsetof(struct ofpact_nest, actions));
         get_actions_from_instruction(insts[OVSINST_OFPIT11_WRITE_ACTIONS],
                                      &actions, &actions_len);
         error = ofpacts_decode_for_action_set(actions, actions_len,
@@ -5201,7 +5768,7 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
             goto exit;
         }
         on = ofpbuf_at_assert(ofpacts, start, sizeof *on);
-        on->ofpact.len = ofpbuf_size(ofpacts) - start;
+        on->ofpact.len = ofpacts->size - start;
     }
     if (insts[OVSINST_OFPIT11_WRITE_METADATA]) {
         const struct ofp11_instruction_write_metadata *oiwm;
@@ -5224,8 +5791,8 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
         ogt->table_id = oigt->table_id;
     }
 
-    error = ofpacts_verify(ofpbuf_data(ofpacts), ofpbuf_size(ofpacts),
-                           (1u << N_OVS_INSTRUCTIONS) - 1);
+    error = ofpacts_verify(ofpacts->data, ofpacts->size,
+                           (1u << N_OVS_INSTRUCTIONS) - 1, 0);
 exit:
     if (error) {
         ofpbuf_clear(ofpacts);
@@ -5242,10 +5809,10 @@ ofpacts_update_instruction_actions(struct ofpbuf *openflow, size_t ofs)
     struct ofp11_instruction_actions *oia;
 
     oia = ofpbuf_at_assert(openflow, ofs, sizeof *oia);
-    if (ofpbuf_size(openflow) > ofs + sizeof *oia) {
-        oia->len = htons(ofpbuf_size(openflow) - ofs);
+    if (openflow->size > ofs + sizeof *oia) {
+        oia->len = htons(openflow->size - ofs);
     } else {
-        ofpbuf_set_size(openflow, ofs);
+        openflow->size = ofs;
     }
 }
 \f
@@ -5262,10 +5829,12 @@ ofpact_check_output_port(ofp_port_t port, ofp_port_t max_ports)
     case OFPP_FLOOD:
     case OFPP_ALL:
     case OFPP_CONTROLLER:
-    case OFPP_NONE:
     case OFPP_LOCAL:
         return 0;
 
+    case OFPP_NONE:
+        return OFPERR_OFPBAC_BAD_OUT_PORT;
+
     default:
         if (ofp_to_u16(port) < ofp_to_u16(max_ports)) {
             return 0;
@@ -5455,6 +6024,9 @@ ofpact_check__(enum ofputil_protocol *usable_protocols, struct ofpact *a,
     case OFPACT_LEARN:
         return learn_check(ofpact_get_LEARN(a), flow);
 
+    case OFPACT_CONJUNCTION:
+        return 0;
+
     case OFPACT_MULTIPATH:
         return multipath_check(ofpact_get_MULTIPATH(a), flow);
 
@@ -5480,6 +6052,20 @@ ofpact_check__(enum ofputil_protocol *usable_protocols, struct ofpact *a,
     case OFPACT_SAMPLE:
         return 0;
 
+    case OFPACT_CT: {
+        struct ofpact_conntrack *oc = ofpact_get_CT(a);
+
+        if (!dl_type_is_ip_any(flow->dl_type)
+            || (flow->ct_state & CS_INVALID && oc->flags & NX_CT_F_COMMIT)) {
+            inconsistent_match(usable_protocols);
+        }
+
+        if (oc->zone_src.field) {
+            return mf_check_src(&oc->zone_src, flow);
+        }
+        return 0;
+    }
+
     case OFPACT_CLEAR_ACTIONS:
         return 0;
 
@@ -5515,6 +6101,14 @@ ofpact_check__(enum ofputil_protocol *usable_protocols, struct ofpact *a,
     case OFPACT_GROUP:
         return 0;
 
+    case OFPACT_UNROLL_XLATE:
+        /* UNROLL is an internal action that should never be seen via
+         * OpenFlow. */
+        return OFPERR_OFPBAC_BAD_TYPE;
+
+    case OFPACT_DEBUG_RECIRC:
+        return 0;
+
     default:
         OVS_NOT_REACHED();
     }
@@ -5576,11 +6170,30 @@ ofpacts_check_consistency(struct ofpact ofpacts[], size_t ofpacts_len,
             : 0);
 }
 
-/* Verifies that the 'ofpacts_len' bytes of actions in 'ofpacts' are
- * in the appropriate order as defined by the OpenFlow spec. */
+static enum ofperr
+ofpacts_verify_nested(const struct ofpact *a, enum ofpact_type outer_action)
+{
+    if (outer_action != OFPACT_WRITE_ACTIONS) {
+        VLOG_WARN("\"%s\" action doesn't support nested action \"%s\"",
+                  ofpact_name(outer_action), ofpact_name(a->type));
+        return OFPERR_OFPBAC_BAD_ARGUMENT;
+    }
+
+    return 0;
+}
+
+/* Verifies that the 'ofpacts_len' bytes of actions in 'ofpacts' are in the
+ * appropriate order as defined by the OpenFlow spec and as required by Open
+ * vSwitch.
+ *
+ * 'allowed_ovsinsts' is a bitmap of OVSINST_* values, in which 1-bits indicate
+ * instructions that are allowed within 'ofpacts[]'.
+ *
+ * If 'outer_action' is not zero, it specifies that the actions are nested
+ * within another action of type 'outer_action'. */
 static enum ofperr
 ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len,
-               uint32_t allowed_ovsinsts)
+               uint32_t allowed_ovsinsts, enum ofpact_type outer_action)
 {
     const struct ofpact *a;
     enum ovs_instruction_type inst;
@@ -5589,6 +6202,27 @@ ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len,
     OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
         enum ovs_instruction_type next;
 
+        if (a->type == OFPACT_CONJUNCTION) {
+            OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
+                if (a->type != OFPACT_CONJUNCTION && a->type != OFPACT_NOTE) {
+                    VLOG_WARN("\"conjunction\" actions may be used along with "
+                              "\"note\" but not any other kind of action "
+                              "(such as the \"%s\" action used here)",
+                              ofpact_name(a->type));
+                    return OFPERR_NXBAC_BAD_CONJUNCTION;
+                }
+            }
+            return 0;
+        }
+
+        if (outer_action) {
+            enum ofperr error = ofpacts_verify_nested(a, outer_action);
+
+            if (error) {
+                return error;
+            }
+        }
+
         next = ovs_instruction_type_from_ofpact_type(a->type);
         if (a > ofpacts
             && (inst == OVSINST_OFPIT11_APPLY_ACTIONS
@@ -5647,12 +6281,12 @@ ofpacts_put_openflow_actions(const struct ofpact ofpacts[], size_t ofpacts_len,
                              enum ofp_version ofp_version)
 {
     const struct ofpact *a;
-    size_t start_size = ofpbuf_size(openflow);
+    size_t start_size = openflow->size;
 
     OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
         encode_ofpact(a, ofp_version, openflow);
     }
-    return ofpbuf_size(openflow) - start_size;
+    return openflow->size - start_size;
 }
 
 static enum ovs_instruction_type
@@ -5680,7 +6314,7 @@ ofpacts_put_openflow_instructions(const struct ofpact ofpacts[],
     a = ofpacts;
     while (a < end) {
         if (ofpact_is_apply_actions(a)) {
-            size_t ofs = ofpbuf_size(openflow);
+            size_t ofs = openflow->size;
 
             instruction_put_OFPIT11_APPLY_ACTIONS(openflow);
             do {
@@ -5887,9 +6521,11 @@ ofpact_outputs_to_port(const struct ofpact *ofpact, ofp_port_t port)
     case OFPACT_FIN_TIMEOUT:
     case OFPACT_RESUBMIT:
     case OFPACT_LEARN:
+    case OFPACT_CONJUNCTION:
     case OFPACT_MULTIPATH:
     case OFPACT_NOTE:
     case OFPACT_EXIT:
+    case OFPACT_UNROLL_XLATE:
     case OFPACT_PUSH_MPLS:
     case OFPACT_POP_MPLS:
     case OFPACT_SAMPLE:
@@ -5898,6 +6534,8 @@ ofpact_outputs_to_port(const struct ofpact *ofpact, ofp_port_t port)
     case OFPACT_GOTO_TABLE:
     case OFPACT_METER:
     case OFPACT_GROUP:
+    case OFPACT_DEBUG_RECIRC:
+    case OFPACT_CT:
     default:
         return false;
     }
@@ -6016,7 +6654,8 @@ ofpact_put(struct ofpbuf *ofpacts, enum ofpact_type type, size_t len)
     struct ofpact *ofpact;
 
     ofpact_pad(ofpacts);
-    ofpact = ofpacts->frame = ofpbuf_put_uninit(ofpacts, len);
+    ofpacts->header = ofpbuf_put_uninit(ofpacts, len);
+    ofpact = ofpacts->header;
     ofpact_init(ofpact, type, len);
     return ofpact;
 }
@@ -6039,7 +6678,7 @@ ofpact_init(struct ofpact *ofpact, enum ofpact_type type, size_t len)
 void
 ofpact_update_len(struct ofpbuf *ofpacts, struct ofpact *ofpact)
 {
-    ovs_assert(ofpact == ofpacts->frame);
+    ovs_assert(ofpact == ofpacts->header);
     ofpact->len = (char *) ofpbuf_tail(ofpacts) - (char *) ofpact;
 }
 
@@ -6056,7 +6695,7 @@ ofpact_update_len(struct ofpbuf *ofpacts, struct ofpact *ofpact)
 void
 ofpact_pad(struct ofpbuf *ofpacts)
 {
-    unsigned int pad = PAD_SIZE(ofpbuf_size(ofpacts), OFPACT_ALIGNTO);
+    unsigned int pad = PAD_SIZE(ofpacts->size, OFPACT_ALIGNTO);
     if (pad) {
         ofpbuf_put_zeros(ofpacts, pad);
     }
@@ -6097,11 +6736,14 @@ ofpact_type_from_name(const char *name, enum ofpact_type *type)
 /* Parses 'str' as a series of instructions, and appends them to 'ofpacts'.
  *
  * Returns NULL if successful, otherwise a malloc()'d string describing the
- * error.  The caller is responsible for freeing the returned string. */
+ * error.  The caller is responsible for freeing the returned string.
+ *
+ * If 'outer_action' is specified, indicates that the actions being parsed
+ * are nested within another action of the type specified in 'outer_action'. */
 static char * OVS_WARN_UNUSED_RESULT
 ofpacts_parse__(char *str, struct ofpbuf *ofpacts,
                 enum ofputil_protocol *usable_protocols,
-                bool allow_instructions)
+                bool allow_instructions, enum ofpact_type outer_action)
 {
     int prev_inst = -1;
     enum ofperr retval;
@@ -6167,15 +6809,16 @@ ofpacts_parse__(char *str, struct ofpbuf *ofpacts,
     }
     ofpact_pad(ofpacts);
 
-    if (drop && ofpbuf_size(ofpacts)) {
+    if (drop && ofpacts->size) {
         return xstrdup("\"drop\" must not be accompanied by any other action "
                        "or instruction");
     }
 
-    retval = ofpacts_verify(ofpbuf_data(ofpacts), ofpbuf_size(ofpacts),
+    retval = ofpacts_verify(ofpacts->data, ofpacts->size,
                             (allow_instructions
                              ? (1u << N_OVS_INSTRUCTIONS) - 1
-                             : 1u << OVSINST_OFPIT11_APPLY_ACTIONS));
+                             : 1u << OVSINST_OFPIT11_APPLY_ACTIONS),
+                            outer_action);
     if (retval) {
         return xstrdup("Incorrect instruction ordering");
     }
@@ -6185,13 +6828,14 @@ ofpacts_parse__(char *str, struct ofpbuf *ofpacts,
 
 static char * OVS_WARN_UNUSED_RESULT
 ofpacts_parse(char *str, struct ofpbuf *ofpacts,
-              enum ofputil_protocol *usable_protocols, bool allow_instructions)
+              enum ofputil_protocol *usable_protocols, bool allow_instructions,
+              enum ofpact_type outer_action)
 {
-    uint32_t orig_size = ofpbuf_size(ofpacts);
+    uint32_t orig_size = ofpacts->size;
     char *error = ofpacts_parse__(str, ofpacts, usable_protocols,
-                                  allow_instructions);
+                                  allow_instructions, outer_action);
     if (error) {
-        ofpbuf_set_size(ofpacts, orig_size);
+        ofpacts->size = orig_size;
     }
     return error;
 }
@@ -6199,21 +6843,23 @@ ofpacts_parse(char *str, struct ofpbuf *ofpacts,
 static char * OVS_WARN_UNUSED_RESULT
 ofpacts_parse_copy(const char *s_, struct ofpbuf *ofpacts,
                    enum ofputil_protocol *usable_protocols,
-                   bool allow_instructions)
+                   bool allow_instructions, enum ofpact_type outer_action)
 {
     char *error, *s;
 
     *usable_protocols = OFPUTIL_P_ANY;
 
     s = xstrdup(s_);
-    error = ofpacts_parse(s, ofpacts, usable_protocols, allow_instructions);
+    error = ofpacts_parse(s, ofpacts, usable_protocols, allow_instructions,
+                          outer_action);
     free(s);
 
     return error;
 }
 
 /* Parses 's' as a set of OpenFlow actions and appends the actions to
- * 'ofpacts'.
+ * 'ofpacts'. 'outer_action', if nonzero, specifies that 's' contains actions
+ * that are nested within the action of type 'outer_action'.
  *
  * Returns NULL if successful, otherwise a malloc()'d string describing the
  * error.  The caller is responsible for freeing the returned string. */
@@ -6221,7 +6867,7 @@ char * OVS_WARN_UNUSED_RESULT
 ofpacts_parse_actions(const char *s, struct ofpbuf *ofpacts,
                       enum ofputil_protocol *usable_protocols)
 {
-    return ofpacts_parse_copy(s, ofpacts, usable_protocols, false);
+    return ofpacts_parse_copy(s, ofpacts, usable_protocols, false, 0);
 }
 
 /* Parses 's' as a set of OpenFlow instructions and appends the instructions to
@@ -6233,7 +6879,7 @@ char * OVS_WARN_UNUSED_RESULT
 ofpacts_parse_instructions(const char *s, struct ofpbuf *ofpacts,
                            enum ofputil_protocol *usable_protocols)
 {
-    return ofpacts_parse_copy(s, ofpacts, usable_protocols, true);
+    return ofpacts_parse_copy(s, ofpacts, usable_protocols, true, 0);
 }
 
 const char *
@@ -6439,13 +7085,13 @@ static enum ofperr
 ofpact_pull_raw(struct ofpbuf *buf, enum ofp_version ofp_version,
                 enum ofp_raw_action_type *raw, uint64_t *arg)
 {
-    const struct ofp_action_header *oah = ofpbuf_data(buf);
+    const struct ofp_action_header *oah = buf->data;
     const struct ofpact_raw_instance *action;
     unsigned int length;
     enum ofperr error;
 
     *raw = *arg = 0;
-    error = ofpact_decode_raw(ofp_version, oah, ofpbuf_size(buf), &action);
+    error = ofpact_decode_raw(ofp_version, oah, buf->size, &action);
     if (error) {
         return error;
     }
@@ -6457,9 +7103,9 @@ ofpact_pull_raw(struct ofpbuf *buf, enum ofp_version ofp_version,
     }
 
     length = ntohs(oah->len);
-    if (length > ofpbuf_size(buf)) {
+    if (length > buf->size) {
         VLOG_WARN_RL(&rl, "OpenFlow action %s length %u exceeds action buffer "
-                     "length %"PRIu32, action->name, length, ofpbuf_size(buf));
+                     "length %"PRIu32, action->name, length, buf->size);
         return OFPERR_OFPBAC_BAD_LEN;
     }
     if (length < action->min_length || length > action->max_length) {
@@ -6556,9 +7202,9 @@ pad_ofpat(struct ofpbuf *openflow, size_t start_ofs)
 {
     struct ofp_action_header *oah;
 
-    ofpbuf_put_zeros(openflow, PAD_SIZE(ofpbuf_size(openflow) - start_ofs, 8));
+    ofpbuf_put_zeros(openflow, PAD_SIZE(openflow->size - start_ofs, 8));
 
     oah = ofpbuf_at_assert(openflow, start_ofs, sizeof *oah);
-    oah->len = htons(ofpbuf_size(openflow) - start_ofs);
+    oah->len = htons(openflow->size - start_ofs);
 }