nx-match: Fix bug in "move" action.
[sliver-openvswitch.git] / lib / nx-match.c
index 6c48d02..cccf6fe 100644 (file)
@@ -162,6 +162,8 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
     struct flow_wildcards *wc = &rule->wc;
     struct flow *flow = &rule->flow;
 
+    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 1);
+
     switch (f->index) {
         /* Metadata. */
     case NFI_NXM_OF_IN_PORT:
@@ -706,6 +708,8 @@ nx_put_match(struct ofpbuf *b, const struct cls_rule *cr)
     int match_len;
     int i;
 
+    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 1);
+
     /* Metadata. */
     if (!(wc & FWW_IN_PORT)) {
         uint16_t in_port = flow->in_port;
@@ -1366,6 +1370,14 @@ nxm_write_field(const struct nxm_field *dst, struct flow *flow,
                 uint64_t new_value)
 {
     switch (dst->index) {
+    case NFI_NXM_OF_ETH_DST:
+        eth_addr_from_uint64(new_value, flow->dl_dst);
+        break;
+
+    case NFI_NXM_OF_ETH_SRC:
+        eth_addr_from_uint64(new_value, flow->dl_src);
+        break;
+
     case NFI_NXM_OF_VLAN_TCI:
         flow->vlan_tci = htons(new_value);
         break;
@@ -1395,21 +1407,34 @@ nxm_write_field(const struct nxm_field *dst, struct flow *flow,
 #error
 #endif
 
-    case NFI_NXM_OF_IN_PORT:
-    case NFI_NXM_OF_ETH_DST:
-    case NFI_NXM_OF_ETH_SRC:
-    case NFI_NXM_OF_ETH_TYPE:
     case NFI_NXM_OF_IP_TOS:
-    case NFI_NXM_OF_IP_PROTO:
-    case NFI_NXM_OF_ARP_OP:
+        flow->nw_tos = new_value & IP_DSCP_MASK;
+        break;
+
     case NFI_NXM_OF_IP_SRC:
-    case NFI_NXM_OF_ARP_SPA:
+        flow->nw_src = htonl(new_value);
+        break;
+
     case NFI_NXM_OF_IP_DST:
-    case NFI_NXM_OF_ARP_TPA:
+        flow->nw_dst = htonl(new_value);
+        break;
+
     case NFI_NXM_OF_TCP_SRC:
     case NFI_NXM_OF_UDP_SRC:
+        flow->tp_src = htons(new_value);
+        break;
+
     case NFI_NXM_OF_TCP_DST:
     case NFI_NXM_OF_UDP_DST:
+        flow->tp_dst = htons(new_value);
+        break;
+
+    case NFI_NXM_OF_IN_PORT:
+    case NFI_NXM_OF_ETH_TYPE:
+    case NFI_NXM_OF_IP_PROTO:
+    case NFI_NXM_OF_ARP_OP:
+    case NFI_NXM_OF_ARP_SPA:
+    case NFI_NXM_OF_ARP_TPA:
     case NFI_NXM_OF_ICMP_TYPE:
     case NFI_NXM_OF_ICMP_CODE:
     case NFI_NXM_NX_TUN_ID_W:
@@ -1446,7 +1471,7 @@ nxm_execute_reg_move(const struct nx_action_reg_move *action,
     /* Get the interesting bits of the source field. */
     const struct nxm_field *src = nxm_field_lookup(ntohl(action->src));
     int src_ofs = ntohs(action->src_ofs);
-    uint64_t src_data = nxm_read_field(src, flow) & (mask << src_ofs);
+    uint64_t src_data = (nxm_read_field(src, flow) >> src_ofs) & mask;
 
     nxm_reg_load(action->dst,
                  nxm_encode_ofs_nbits(ntohs(action->dst_ofs), n_bits),