diff mbox series

[ovs-dev,v3,1/3] ofp-prop: Add helper for parsing and storing of ovs_u128.

Message ID 20231018062850.67677-1-amusil@redhat.com
State Changes Requested
Delegated to: Ilya Maximets
Headers show
Series [ovs-dev,v3,1/3] ofp-prop: Add helper for parsing and storing of ovs_u128. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Ales Musil Oct. 18, 2023, 6:28 a.m. UTC
Add helper methods that allow us to store and parse the
ovs_u128 type.

Signed-off-by: Ales Musil <amusil@redhat.com>
---
v3: Rebase on top of current master.
v2: Add missing ofpprop_parse_be128() function.
---
 include/openvswitch/ofp-prop.h |  5 ++++
 lib/ofp-prop.c                 | 44 ++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

Comments

Eelco Chaudron Oct. 20, 2023, 2:53 p.m. UTC | #1
On 18 Oct 2023, at 8:28, Ales Musil wrote:

> Add helper methods that allow us to store and parse the
> ovs_u128 type.
>
> Signed-off-by: Ales Musil <amusil@redhat.com>

This patch looks good to me. I only reviewed the first patch, as due to a missing cover letter I was fooled and thought this series was all about this new helper ;)

I’ll leave the other two patches for the CT fooks...

Cheers,

Eelco

Acked-by: Eelco Chaudron <echaudro@redhat.com>
Ilya Maximets Oct. 24, 2023, 9:04 p.m. UTC | #2
On 10/18/23 08:28, Ales Musil wrote:
> Add helper methods that allow us to store and parse the
> ovs_u128 type.
> 
> Signed-off-by: Ales Musil <amusil@redhat.com>
> ---
> v3: Rebase on top of current master.
> v2: Add missing ofpprop_parse_be128() function.
> ---
>  include/openvswitch/ofp-prop.h |  5 ++++
>  lib/ofp-prop.c                 | 44 ++++++++++++++++++++++++++++++++++
>  2 files changed, 49 insertions(+)
> 
> diff --git a/include/openvswitch/ofp-prop.h b/include/openvswitch/ofp-prop.h
> index e676f8dc0..451f5dae2 100644
> --- a/include/openvswitch/ofp-prop.h
> +++ b/include/openvswitch/ofp-prop.h
> @@ -84,10 +84,13 @@ enum ofperr ofpprop_pull(struct ofpbuf *msg, struct ofpbuf *property,
>  enum ofperr ofpprop_parse_be16(const struct ofpbuf *, ovs_be16 *value);
>  enum ofperr ofpprop_parse_be32(const struct ofpbuf *, ovs_be32 *value);
>  enum ofperr ofpprop_parse_be64(const struct ofpbuf *, ovs_be64 *value);
> +enum ofperr ofpprop_parse_be128(const struct ofpbuf *property,
> +                                ovs_be128 *value);
>  enum ofperr ofpprop_parse_u8(const struct ofpbuf *, uint8_t *value);
>  enum ofperr ofpprop_parse_u16(const struct ofpbuf *, uint16_t *value);
>  enum ofperr ofpprop_parse_u32(const struct ofpbuf *, uint32_t *value);
>  enum ofperr ofpprop_parse_u64(const struct ofpbuf *, uint64_t *value);
> +enum ofperr ofpprop_parse_u128(const struct ofpbuf *, ovs_u128 *value);
>  enum ofperr ofpprop_parse_uuid(const struct ofpbuf *, struct uuid *);
>  enum ofperr ofpprop_parse_nested(const struct ofpbuf *, struct ofpbuf *);
>  
> @@ -98,10 +101,12 @@ void *ofpprop_put_zeros(struct ofpbuf *, uint64_t type, size_t len);
>  void ofpprop_put_be16(struct ofpbuf *, uint64_t type, ovs_be16 value);
>  void ofpprop_put_be32(struct ofpbuf *, uint64_t type, ovs_be32 value);
>  void ofpprop_put_be64(struct ofpbuf *, uint64_t type, ovs_be64 value);
> +void ofpprop_put_be128(struct ofpbuf *, uint64_t type, ovs_be128 value);
>  void ofpprop_put_u8(struct ofpbuf *, uint64_t type, uint8_t value);
>  void ofpprop_put_u16(struct ofpbuf *, uint64_t type, uint16_t value);
>  void ofpprop_put_u32(struct ofpbuf *, uint64_t type, uint32_t value);
>  void ofpprop_put_u64(struct ofpbuf *, uint64_t type, uint64_t value);
> +void ofpprop_put_u128(struct ofpbuf *, uint64_t type, ovs_u128 value);
>  void ofpprop_put_bitmap(struct ofpbuf *, uint64_t type, uint64_t bitmap);
>  void ofpprop_put_flag(struct ofpbuf *, uint64_t type);
>  void ofpprop_put_uuid(struct ofpbuf *, uint64_t type, const struct uuid *);
> diff --git a/lib/ofp-prop.c b/lib/ofp-prop.c
> index 8b2d8a85a..9b3be3ffb 100644
> --- a/lib/ofp-prop.c
> +++ b/lib/ofp-prop.c
> @@ -184,6 +184,20 @@ ofpprop_parse_be64(const struct ofpbuf *property, ovs_be64 *value)
>      return 0;
>  }
>  
> +/* Attempts to parse 'property' as a property containing a 128-bit value.  If
> + * successful, stores the value into '*value' and returns 0; otherwise returns
> + * an OpenFlow error. */
> +enum ofperr
> +ofpprop_parse_be128(const struct ofpbuf *property, ovs_be128 *value)
> +{
> +    ovs_be128 *p = property->msg;
> +    if (ofpbuf_msgsize(property) != sizeof *p) {
> +        return OFPERR_OFPBPC_BAD_LEN;
> +    }
> +    *value = *p;
> +    return 0;
> +}
> +
>  /* Attempts to parse 'property' as a property containing a 8-bit value.  If
>   * successful, stores the value into '*value' and returns 0; otherwise returns
>   * an OpenFlow error. */
> @@ -250,6 +264,20 @@ ofpprop_parse_u64(const struct ofpbuf *property, uint64_t *value)
>      return 0;
>  }
>  
> +/* Attempts to parse 'property' as a property containing a 128-bit value.  If
> + * successful, stores the value into '*value' and returns 0; otherwise returns
> + * an OpenFlow error. */
> +enum ofperr
> +ofpprop_parse_u128(const struct ofpbuf *property, ovs_u128 *value)
> +{
> +    ovs_be128 *p = property->msg;
> +    if (ofpbuf_msgsize(property) != sizeof *p) {
> +        return OFPERR_OFPBPC_BAD_LEN;
> +    }
> +    *value = ntoh128(*p);
> +    return 0;
> +}
> +
>  /* Attempts to parse 'property' as a property containing a UUID.  If
>   * successful, stores the value into '*uuid' and returns 0; otherwise returns
>   * an OpenFlow error. */
> @@ -351,6 +379,15 @@ ofpprop_put_be64(struct ofpbuf *msg, uint64_t type, ovs_be64 value)
>      ofpprop_end(msg, start);
>  }
>  
> +/* Adds a property with the given 'type' and 128-bit 'value' to 'msg'. */
> +void
> +ofpprop_put_be128(struct ofpbuf *msg, uint64_t type, ovs_be128 value)
> +{
> +    size_t start = ofpprop_start(msg, type);
> +    ofpbuf_put(msg, &value, sizeof value);
> +    ofpprop_end(msg, start);

This should be just ofpprop_put(msg, type, &value, sizeof value);

> +}
> +
>  /* Adds a property with the given 'type' and 8-bit 'value' to 'msg'. */
>  void
>  ofpprop_put_u8(struct ofpbuf *msg, uint64_t type, uint8_t value)
> @@ -381,6 +418,13 @@ ofpprop_put_u64(struct ofpbuf *msg, uint64_t type, uint64_t value)
>      ofpprop_put_be64(msg, type, htonll(value));
>  }
>  
> +/* Adds a property with the given 'type' and 64-bit 'value' to 'msg'. */
> +void
> +ofpprop_put_u128(struct ofpbuf *msg, uint64_t type, ovs_u128 value)
> +{
> +    ofpprop_put_be128(msg, type, hton128(value));
> +}
> +
>  /* Appends a property to 'msg' whose type is 'type' and whose contents is a
>   * series of property headers, one for each 1-bit in 'bitmap'. */
>  void
diff mbox series

Patch

diff --git a/include/openvswitch/ofp-prop.h b/include/openvswitch/ofp-prop.h
index e676f8dc0..451f5dae2 100644
--- a/include/openvswitch/ofp-prop.h
+++ b/include/openvswitch/ofp-prop.h
@@ -84,10 +84,13 @@  enum ofperr ofpprop_pull(struct ofpbuf *msg, struct ofpbuf *property,
 enum ofperr ofpprop_parse_be16(const struct ofpbuf *, ovs_be16 *value);
 enum ofperr ofpprop_parse_be32(const struct ofpbuf *, ovs_be32 *value);
 enum ofperr ofpprop_parse_be64(const struct ofpbuf *, ovs_be64 *value);
+enum ofperr ofpprop_parse_be128(const struct ofpbuf *property,
+                                ovs_be128 *value);
 enum ofperr ofpprop_parse_u8(const struct ofpbuf *, uint8_t *value);
 enum ofperr ofpprop_parse_u16(const struct ofpbuf *, uint16_t *value);
 enum ofperr ofpprop_parse_u32(const struct ofpbuf *, uint32_t *value);
 enum ofperr ofpprop_parse_u64(const struct ofpbuf *, uint64_t *value);
+enum ofperr ofpprop_parse_u128(const struct ofpbuf *, ovs_u128 *value);
 enum ofperr ofpprop_parse_uuid(const struct ofpbuf *, struct uuid *);
 enum ofperr ofpprop_parse_nested(const struct ofpbuf *, struct ofpbuf *);
 
@@ -98,10 +101,12 @@  void *ofpprop_put_zeros(struct ofpbuf *, uint64_t type, size_t len);
 void ofpprop_put_be16(struct ofpbuf *, uint64_t type, ovs_be16 value);
 void ofpprop_put_be32(struct ofpbuf *, uint64_t type, ovs_be32 value);
 void ofpprop_put_be64(struct ofpbuf *, uint64_t type, ovs_be64 value);
+void ofpprop_put_be128(struct ofpbuf *, uint64_t type, ovs_be128 value);
 void ofpprop_put_u8(struct ofpbuf *, uint64_t type, uint8_t value);
 void ofpprop_put_u16(struct ofpbuf *, uint64_t type, uint16_t value);
 void ofpprop_put_u32(struct ofpbuf *, uint64_t type, uint32_t value);
 void ofpprop_put_u64(struct ofpbuf *, uint64_t type, uint64_t value);
+void ofpprop_put_u128(struct ofpbuf *, uint64_t type, ovs_u128 value);
 void ofpprop_put_bitmap(struct ofpbuf *, uint64_t type, uint64_t bitmap);
 void ofpprop_put_flag(struct ofpbuf *, uint64_t type);
 void ofpprop_put_uuid(struct ofpbuf *, uint64_t type, const struct uuid *);
diff --git a/lib/ofp-prop.c b/lib/ofp-prop.c
index 8b2d8a85a..9b3be3ffb 100644
--- a/lib/ofp-prop.c
+++ b/lib/ofp-prop.c
@@ -184,6 +184,20 @@  ofpprop_parse_be64(const struct ofpbuf *property, ovs_be64 *value)
     return 0;
 }
 
+/* Attempts to parse 'property' as a property containing a 128-bit value.  If
+ * successful, stores the value into '*value' and returns 0; otherwise returns
+ * an OpenFlow error. */
+enum ofperr
+ofpprop_parse_be128(const struct ofpbuf *property, ovs_be128 *value)
+{
+    ovs_be128 *p = property->msg;
+    if (ofpbuf_msgsize(property) != sizeof *p) {
+        return OFPERR_OFPBPC_BAD_LEN;
+    }
+    *value = *p;
+    return 0;
+}
+
 /* Attempts to parse 'property' as a property containing a 8-bit value.  If
  * successful, stores the value into '*value' and returns 0; otherwise returns
  * an OpenFlow error. */
@@ -250,6 +264,20 @@  ofpprop_parse_u64(const struct ofpbuf *property, uint64_t *value)
     return 0;
 }
 
+/* Attempts to parse 'property' as a property containing a 128-bit value.  If
+ * successful, stores the value into '*value' and returns 0; otherwise returns
+ * an OpenFlow error. */
+enum ofperr
+ofpprop_parse_u128(const struct ofpbuf *property, ovs_u128 *value)
+{
+    ovs_be128 *p = property->msg;
+    if (ofpbuf_msgsize(property) != sizeof *p) {
+        return OFPERR_OFPBPC_BAD_LEN;
+    }
+    *value = ntoh128(*p);
+    return 0;
+}
+
 /* Attempts to parse 'property' as a property containing a UUID.  If
  * successful, stores the value into '*uuid' and returns 0; otherwise returns
  * an OpenFlow error. */
@@ -351,6 +379,15 @@  ofpprop_put_be64(struct ofpbuf *msg, uint64_t type, ovs_be64 value)
     ofpprop_end(msg, start);
 }
 
+/* Adds a property with the given 'type' and 128-bit 'value' to 'msg'. */
+void
+ofpprop_put_be128(struct ofpbuf *msg, uint64_t type, ovs_be128 value)
+{
+    size_t start = ofpprop_start(msg, type);
+    ofpbuf_put(msg, &value, sizeof value);
+    ofpprop_end(msg, start);
+}
+
 /* Adds a property with the given 'type' and 8-bit 'value' to 'msg'. */
 void
 ofpprop_put_u8(struct ofpbuf *msg, uint64_t type, uint8_t value)
@@ -381,6 +418,13 @@  ofpprop_put_u64(struct ofpbuf *msg, uint64_t type, uint64_t value)
     ofpprop_put_be64(msg, type, htonll(value));
 }
 
+/* Adds a property with the given 'type' and 64-bit 'value' to 'msg'. */
+void
+ofpprop_put_u128(struct ofpbuf *msg, uint64_t type, ovs_u128 value)
+{
+    ofpprop_put_be128(msg, type, hton128(value));
+}
+
 /* Appends a property to 'msg' whose type is 'type' and whose contents is a
  * series of property headers, one for each 1-bit in 'bitmap'. */
 void