diff mbox

[ovs-dev,1/3] lib: Add nl_msg_end_non_empty_nested()

Message ID 1484352826-46375-1-git-send-email-azhou@ovn.org
State Superseded
Delegated to: Daniele Di Proietto
Headers show

Commit Message

Andy Zhou Jan. 14, 2017, 12:13 a.m. UTC
Later patch will make use of this function.

Signed-off-by: Andy Zhou <azhou@ovn.org>
---
 lib/netlink.c | 13 +++++++++++++
 lib/netlink.h |  1 +
 2 files changed, 14 insertions(+)

Comments

Jarno Rajahalme Jan. 20, 2017, 1:54 a.m. UTC | #1
Acked-by: Jarno Rajahalme <jarno@ovn.org>

> On Jan 13, 2017, at 4:13 PM, Andy Zhou <azhou@ovn.org> wrote:
> 
> Later patch will make use of this function.

IMO it would be good for the commit message to also include the name of the function without referencing the title.

> 
> Signed-off-by: Andy Zhou <azhou@ovn.org>
> ---
> lib/netlink.c | 13 +++++++++++++
> lib/netlink.h |  1 +
> 2 files changed, 14 insertions(+)
> 
> diff --git a/lib/netlink.c b/lib/netlink.c
> index 4715d68..ad7d35a 100644
> --- a/lib/netlink.c
> +++ b/lib/netlink.c
> @@ -467,6 +467,19 @@ nl_msg_end_nested(struct ofpbuf *msg, size_t offset)
>     attr->nla_len = msg->size - offset;
> }
> 
> +/* Same as nls_msg_end_nested() when the nested Netlink contains non empty
> + * message. Otherwise, drop the nested message header from 'msg'.    */
> +void
> +nl_msg_end_non_empty_nested(struct ofpbuf *msg, size_t offset)
> +{
> +    nl_msg_end_nested(msg, offset);
> +
> +    struct nlattr *attr = ofpbuf_at_assert(msg, offset, sizeof *attr);
> +    if (!nl_attr_get_size(attr)) {
> +        msg->size = offset;
> +    }
> +}
> +
> /* Appends a nested Netlink attribute of the given 'type', with the 'size'
>  * bytes of content starting at 'data', to 'msg'. */
> void
> diff --git a/lib/netlink.h b/lib/netlink.h
> index b931a41..7646f91 100644
> --- a/lib/netlink.h
> +++ b/lib/netlink.h
> @@ -79,6 +79,7 @@ void nl_msg_put_string(struct ofpbuf *, uint16_t type, const char *value);
> 
> size_t nl_msg_start_nested(struct ofpbuf *, uint16_t type);
> void nl_msg_end_nested(struct ofpbuf *, size_t offset);
> +void nl_msg_end_non_empty_nested(struct ofpbuf *, size_t offset);
> void nl_msg_put_nested(struct ofpbuf *, uint16_t type,
>                        const void *data, size_t size);
> 
> -- 
> 2.7.4
> 
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
diff mbox

Patch

diff --git a/lib/netlink.c b/lib/netlink.c
index 4715d68..ad7d35a 100644
--- a/lib/netlink.c
+++ b/lib/netlink.c
@@ -467,6 +467,19 @@  nl_msg_end_nested(struct ofpbuf *msg, size_t offset)
     attr->nla_len = msg->size - offset;
 }
 
+/* Same as nls_msg_end_nested() when the nested Netlink contains non empty
+ * message. Otherwise, drop the nested message header from 'msg'.    */
+void
+nl_msg_end_non_empty_nested(struct ofpbuf *msg, size_t offset)
+{
+    nl_msg_end_nested(msg, offset);
+
+    struct nlattr *attr = ofpbuf_at_assert(msg, offset, sizeof *attr);
+    if (!nl_attr_get_size(attr)) {
+        msg->size = offset;
+    }
+}
+
 /* Appends a nested Netlink attribute of the given 'type', with the 'size'
  * bytes of content starting at 'data', to 'msg'. */
 void
diff --git a/lib/netlink.h b/lib/netlink.h
index b931a41..7646f91 100644
--- a/lib/netlink.h
+++ b/lib/netlink.h
@@ -79,6 +79,7 @@  void nl_msg_put_string(struct ofpbuf *, uint16_t type, const char *value);
 
 size_t nl_msg_start_nested(struct ofpbuf *, uint16_t type);
 void nl_msg_end_nested(struct ofpbuf *, size_t offset);
+void nl_msg_end_non_empty_nested(struct ofpbuf *, size_t offset);
 void nl_msg_put_nested(struct ofpbuf *, uint16_t type,
                        const void *data, size_t size);