[ovs-dev] [PATCH 04/11] nx-match: Enable senders of NXM fields to specify length.

Jesse Gross jesse at nicira.com
Fri Jun 19 23:13:18 UTC 2015


Currently when an NXM field is encoded, the caller must specify
the length of the data being provided. However, this data is
always placed into a field of standard length. In order to
support variable length options, the length field must also
alter the size in the header. The previous implementation
already required callers to pass in the exact (fixed) size of
the field or it would not work properly, so there is no danger
that this will change the behavior for non-variable length
fields.

Signed-off-by: Jesse Gross <jesse at nicira.com>
---
 lib/nx-match.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/nx-match.c b/lib/nx-match.c
index e539a9f..c92f12d 100644
--- a/lib/nx-match.c
+++ b/lib/nx-match.c
@@ -194,6 +194,9 @@ static const struct nxm_field *nxm_field_by_mf_id(enum mf_field_id,
                                                   enum ofp_version);
 
 static void nx_put_header__(struct ofpbuf *, uint64_t header, bool masked);
+static void nx_put_header_len(struct ofpbuf *, enum mf_field_id field,
+                              enum ofp_version version, bool masked,
+                              size_t n_bytes);
 
 /* Rate limit for nx_match parse errors.  These always indicate a bug in the
  * peer and so there's not much point in showing a lot of them. */
@@ -671,7 +674,7 @@ static void
 nxm_put_unmasked(struct ofpbuf *b, enum mf_field_id field,
                  enum ofp_version version, const void *value, size_t n_bytes)
 {
-    nx_put_header(b, field, version, false);
+    nx_put_header_len(b, field, version, false, n_bytes);
     ofpbuf_put(b, value, n_bytes);
 }
 
@@ -681,7 +684,7 @@ nxm_put(struct ofpbuf *b, enum mf_field_id field, enum ofp_version version,
 {
     if (!is_all_zeros(mask, n_bytes)) {
         bool masked = !is_all_ones(mask, n_bytes);
-        nx_put_header(b, field, version, masked);
+        nx_put_header_len(b, field, version, masked, n_bytes);
         ofpbuf_put(b, value, n_bytes);
         if (masked) {
             ofpbuf_put(b, mask, n_bytes);
@@ -1185,6 +1188,19 @@ nx_put_header(struct ofpbuf *b, enum mf_field_id field,
     nx_put_header__(b, mf_oxm_header(field, version), masked);
 }
 
+static void
+nx_put_header_len(struct ofpbuf *b, enum mf_field_id field,
+                  enum ofp_version version, bool masked, size_t n_bytes)
+{
+    uint64_t header = mf_oxm_header(field, version);
+
+    header = NXM_HEADER(nxm_vendor(header), nxm_class(header),
+                        nxm_field(header), false,
+                        nxm_experimenter_len(header) + n_bytes);
+
+    nx_put_header__(b, header, masked);
+}
+
 void
 nx_put_entry(struct ofpbuf *b,
              enum mf_field_id field, enum ofp_version version,
-- 
2.1.0




More information about the dev mailing list