vconn: New function vconn_transact_noreply().
[sliver-openvswitch.git] / lib / nx-match.c
index 94d7de9..ea31c79 100644 (file)
@@ -140,18 +140,6 @@ nxm_field_bits(uint32_t header)
 \f
 /* nx_pull_match() and helpers. */
 
-static int
-parse_tci(struct cls_rule *rule, ovs_be16 tci, ovs_be16 mask)
-{
-    const flow_wildcards_t FWW_DL_TCI = FWW_DL_VLAN | FWW_DL_VLAN_PCP;
-
-    if ((rule->wc.wildcards & FWW_DL_TCI) != FWW_DL_TCI) {
-        return NXM_DUP_TYPE;
-    } else {
-        return cls_rule_set_dl_tci_masked(rule, tci, mask) ? 0 : NXM_INVALID;
-    }
-}
-
 static int
 parse_nx_reg(const struct nxm_field *f,
              struct flow *flow, struct flow_wildcards *wc,
@@ -163,9 +151,9 @@ parse_nx_reg(const struct nxm_field *f,
     } else {
         flow_wildcards_set_reg_mask(wc, idx,
                                     (NXM_HASMASK(f->header)
-                                     ? ntohl(get_unaligned_u32(maskp))
+                                     ? ntohl(get_unaligned_be32(maskp))
                                      : UINT32_MAX));
-        flow->regs[idx] = ntohl(get_unaligned_u32(value));
+        flow->regs[idx] = ntohl(get_unaligned_be32(value));
         flow->regs[idx] &= wc->reg_masks[idx];
         return 0;
     }
@@ -181,7 +169,7 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
     switch (f->index) {
         /* Metadata. */
     case NFI_NXM_OF_IN_PORT:
-        flow->in_port = ntohs(get_unaligned_u16(value));
+        flow->in_port = ntohs(get_unaligned_be16(value));
         if (flow->in_port == OFPP_LOCAL) {
             flow->in_port = ODPP_LOCAL;
         }
@@ -221,16 +209,25 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
         memcpy(flow->dl_src, value, ETH_ADDR_LEN);
         return 0;
     case NFI_NXM_OF_ETH_TYPE:
-        flow->dl_type = get_unaligned_u16(value);
+        flow->dl_type = get_unaligned_be16(value);
         return 0;
 
         /* 802.1Q header. */
     case NFI_NXM_OF_VLAN_TCI:
-        return parse_tci(rule, get_unaligned_u16(value), htons(UINT16_MAX));
-
+        if (wc->vlan_tci_mask) {
+            return NXM_DUP_TYPE;
+        } else {
+            cls_rule_set_dl_tci(rule, get_unaligned_be16(value));
+            return 0;
+        }
     case NFI_NXM_OF_VLAN_TCI_W:
-        return parse_tci(rule, get_unaligned_u16(value),
-                         get_unaligned_u16(mask));
+        if (wc->vlan_tci_mask) {
+            return NXM_DUP_TYPE;
+        } else {
+            cls_rule_set_dl_tci_masked(rule, get_unaligned_be16(value),
+                                       get_unaligned_be16(mask));
+            return 0;
+        }
 
         /* IP header. */
     case NFI_NXM_OF_IP_TOS:
@@ -250,7 +247,7 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
         if (wc->nw_src_mask) {
             return NXM_DUP_TYPE;
         } else {
-            cls_rule_set_nw_src(rule, get_unaligned_u32(value));
+            cls_rule_set_nw_src(rule, get_unaligned_be32(value));
             return 0;
         }
     case NFI_NXM_OF_IP_SRC_W:
@@ -258,8 +255,8 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
         if (wc->nw_src_mask) {
             return NXM_DUP_TYPE;
         } else {
-            ovs_be32 ip = get_unaligned_u32(value);
-            ovs_be32 netmask = get_unaligned_u32(mask);
+            ovs_be32 ip = get_unaligned_be32(value);
+            ovs_be32 netmask = get_unaligned_be32(mask);
             if (!cls_rule_set_nw_src_masked(rule, ip, netmask)) {
                 return NXM_BAD_MASK;
             }
@@ -270,7 +267,7 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
         if (wc->nw_dst_mask) {
             return NXM_DUP_TYPE;
         } else {
-            cls_rule_set_nw_dst(rule, get_unaligned_u32(value));
+            cls_rule_set_nw_dst(rule, get_unaligned_be32(value));
             return 0;
         }
     case NFI_NXM_OF_IP_DST_W:
@@ -278,8 +275,8 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
         if (wc->nw_dst_mask) {
             return NXM_DUP_TYPE;
         } else {
-            ovs_be32 ip = get_unaligned_u32(value);
-            ovs_be32 netmask = get_unaligned_u32(mask);
+            ovs_be32 ip = get_unaligned_be32(value);
+            ovs_be32 netmask = get_unaligned_be32(mask);
             if (!cls_rule_set_nw_dst_masked(rule, ip, netmask)) {
                 return NXM_BAD_MASK;
             }
@@ -288,18 +285,18 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
 
         /* TCP header. */
     case NFI_NXM_OF_TCP_SRC:
-        flow->tp_src = get_unaligned_u16(value);
+        flow->tp_src = get_unaligned_be16(value);
         return 0;
     case NFI_NXM_OF_TCP_DST:
-        flow->tp_dst = get_unaligned_u16(value);
+        flow->tp_dst = get_unaligned_be16(value);
         return 0;
 
         /* UDP header. */
     case NFI_NXM_OF_UDP_SRC:
-        flow->tp_src = get_unaligned_u16(value);
+        flow->tp_src = get_unaligned_be16(value);
         return 0;
     case NFI_NXM_OF_UDP_DST:
-        flow->tp_dst = get_unaligned_u16(value);
+        flow->tp_dst = get_unaligned_be16(value);
         return 0;
 
         /* ICMP header. */
@@ -312,16 +309,16 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
 
         /* ARP header. */
     case NFI_NXM_OF_ARP_OP:
-        if (ntohs(get_unaligned_u16(value)) > 255) {
+        if (ntohs(get_unaligned_be16(value)) > 255) {
             return NXM_BAD_VALUE;
         } else {
-            flow->nw_proto = ntohs(get_unaligned_u16(value));
+            flow->nw_proto = ntohs(get_unaligned_be16(value));
             return 0;
         }
 
         /* Tunnel ID. */
     case NFI_NXM_NX_TUN_ID:
-        flow->tun_id = htonl(ntohll(get_unaligned_u64(value)));
+        flow->tun_id = htonl(ntohll(get_unaligned_be64(value)));
         return 0;
 
         /* Registers. */
@@ -478,6 +475,23 @@ nxm_put_16w(struct ofpbuf *b, uint32_t header, ovs_be16 value, ovs_be16 mask)
     ofpbuf_put(b, &mask, sizeof mask);
 }
 
+static void
+nxm_put_16m(struct ofpbuf *b, uint32_t header, ovs_be16 value, ovs_be16 mask)
+{
+    switch (mask) {
+    case 0:
+        break;
+
+    case CONSTANT_HTONS(UINT16_MAX):
+        nxm_put_16(b, header, value);
+        break;
+
+    default:
+        nxm_put_16w(b, NXM_MAKE_WILD_HEADER(header), value, mask);
+        break;
+    }
+}
+
 static void
 nxm_put_32(struct ofpbuf *b, uint32_t header, ovs_be32 value)
 {
@@ -500,7 +514,7 @@ nxm_put_32m(struct ofpbuf *b, uint32_t header, ovs_be32 value, ovs_be32 mask)
     case 0:
         break;
 
-    case UINT32_MAX:
+    case CONSTANT_HTONL(UINT32_MAX):
         nxm_put_32(b, header, value);
         break;
 
@@ -554,7 +568,6 @@ nx_put_match(struct ofpbuf *b, const struct cls_rule *cr)
     const flow_wildcards_t wc = cr->wc.wildcards;
     const struct flow *flow = &cr->flow;
     const size_t start_len = b->size;
-    ovs_be16 vid, pcp;
     int match_len;
     int i;
 
@@ -577,32 +590,9 @@ nx_put_match(struct ofpbuf *b, const struct cls_rule *cr)
     }
 
     /* 802.1Q. */
-    vid = flow->dl_vlan & htons(VLAN_VID_MASK);
-    pcp = htons((flow->dl_vlan_pcp << VLAN_PCP_SHIFT) & VLAN_PCP_MASK);
-    switch (wc & (FWW_DL_VLAN | FWW_DL_VLAN_PCP)) {
-    case FWW_DL_VLAN | FWW_DL_VLAN_PCP:
-        break;
-    case FWW_DL_VLAN:
-        nxm_put_16w(b, NXM_OF_VLAN_TCI_W, pcp | htons(VLAN_CFI),
-                     htons(VLAN_PCP_MASK | VLAN_CFI));
-        break;
-    case FWW_DL_VLAN_PCP:
-        if (flow->dl_vlan == htons(OFP_VLAN_NONE)) {
-            nxm_put_16(b, NXM_OF_VLAN_TCI, 0);
-        } else {
-            nxm_put_16w(b, NXM_OF_VLAN_TCI_W, vid | htons(VLAN_CFI),
-                         htons(VLAN_VID_MASK | VLAN_CFI));
-        }
-        break;
-    case 0:
-        if (flow->dl_vlan == htons(OFP_VLAN_NONE)) {
-            nxm_put_16(b, NXM_OF_VLAN_TCI, 0);
-        } else {
-            nxm_put_16(b, NXM_OF_VLAN_TCI, vid | pcp | htons(VLAN_CFI));
-        }
-        break;
-    }
+    nxm_put_16m(b, NXM_OF_VLAN_TCI, flow->vlan_tci, cr->wc.vlan_tci_mask);
 
+    /* L3. */
     if (!(wc & FWW_DL_TYPE) && flow->dl_type == htons(ETH_TYPE_IP)) {
         /* IP. */
         if (!(wc & FWW_NW_TOS)) {
@@ -902,13 +892,7 @@ nxm_read_field(const struct nxm_field *src, const struct flow *flow)
         return ntohs(flow->dl_type);
 
     case NFI_NXM_OF_VLAN_TCI:
-        if (flow->dl_vlan == htons(OFP_VLAN_NONE)) {
-            return 0;
-        } else {
-            return (ntohs(flow->dl_vlan & htons(VLAN_VID_MASK))
-                    | ((flow->dl_vlan_pcp << VLAN_PCP_SHIFT) & VLAN_PCP_MASK)
-                    | VLAN_CFI);
-        }
+        return ntohs(flow->vlan_tci);
 
     case NFI_NXM_OF_IP_TOS:
         return flow->nw_tos;
@@ -1000,9 +984,7 @@ nxm_execute_reg_move(const struct nx_action_reg_move *action,
     if (NXM_IS_NX_REG(dst->header)) {
         flow->regs[NXM_NX_REG_IDX(dst->header)] = new_data;
     } else if (dst->header == NXM_OF_VLAN_TCI) {
-        ovs_be16 vlan_tci = htons(new_data & VLAN_CFI ? new_data : 0);
-        flow->dl_vlan = htons(vlan_tci_to_vid(vlan_tci));
-        flow->dl_vlan_pcp = vlan_tci_to_pcp(vlan_tci);
+        flow->vlan_tci = htons(new_data);
     } else if (dst->header == NXM_NX_TUN_ID) {
         flow->tun_id = htonl(new_data);
     } else {