[ovs-dev] [userspace clone v2 2/4] lib: Add nl_msg_end_non_empty_nested()
Andy Zhou
azhou at ovn.org
Fri Jan 20 07:07:09 UTC 2017
Later patch will make use of nl_msg_end_non_empty_nested()
Signed-off-by: Andy Zhou <azhou at ovn.org>
Acked-by: Jarno Rajahalme <jarno at 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);
--
1.9.1
More information about the dev
mailing list