Add count_mpls_labels() which counts LSEs present in an array.
This is a more general form of flow_count_mpls_labels().

This is in preparation for using count_mpls_labels()
in parse_odp_key_mask_attr() where no struct flow is available.

Signed-off-by: Simon Horman <ho...@verge.net.au>
---
 lib/flow.c | 36 ++++++++++++++++++++++++++++--------
 lib/flow.h |  1 +
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index e7fe4d3..95cb9ab 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -1046,6 +1046,26 @@ flow_set_vlan_pcp(struct flow *flow, uint8_t pcp)
     flow->vlan_tci |= htons((pcp << VLAN_PCP_SHIFT) | VLAN_CFI);
 }
 
+/* Returns the number of MPLS LSEs present in 'mpls_lse' which
+ * may contain at most 'len' LSEs.
+ *
+ * Traverses mpls_lse stopping at the first entry that has the BoS bit set.
+ * If no such entry exists then len is returned.
+ */
+int
+count_mpls_labels(const ovs_be32 *mpls_lse, int len)
+{
+    int i;
+
+    for (i = 0; i < len; i++) {
+        if (mpls_lse[i] & htonl(MPLS_BOS_MASK)) {
+            return i + 1;
+        }
+    }
+
+    return len;
+}
+
 /* Returns the number of MPLS LSEs present in 'flow'
  *
  * Returns 0 if the 'dl_type' of 'flow' is not an MPLS ethernet type.
@@ -1060,19 +1080,19 @@ flow_count_mpls_labels(const struct flow *flow, struct 
flow_wildcards *wc)
         wc->masks.dl_type = OVS_BE16_MAX;
     }
     if (eth_type_mpls(flow->dl_type)) {
-        int i;
-        int len = FLOW_MAX_MPLS_LABELS;
+        int n;
 
-        for (i = 0; i < len; i++) {
-            if (wc) {
+        n = count_mpls_labels(flow->mpls_lse, FLOW_MAX_MPLS_LABELS);
+
+        if (wc) {
+            int i;
+
+            for (i = 0; i < n; i++) {
                 wc->masks.mpls_lse[i] |= htonl(MPLS_BOS_MASK);
             }
-            if (flow->mpls_lse[i] & htonl(MPLS_BOS_MASK)) {
-                return i + 1;
-            }
         }
 
-        return len;
+        return n;
     } else {
         return 0;
     }
diff --git a/lib/flow.h b/lib/flow.h
index 3109a84..498502e 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -198,6 +198,7 @@ void flow_set_dl_vlan(struct flow *, ovs_be16 vid);
 void flow_set_vlan_vid(struct flow *, ovs_be16 vid);
 void flow_set_vlan_pcp(struct flow *, uint8_t pcp);
 
+int count_mpls_labels(const ovs_be32 *, int len);
 int flow_count_mpls_labels(const struct flow *, struct flow_wildcards *);
 int flow_count_common_mpls_labels(const struct flow *a, int an,
                                   const struct flow *b, int bn,
-- 
1.8.5.2

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to