summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Zhou <azhou@ovn.org>2017-02-14 14:39:48 -0800
committerAndy Zhou <azhou@ovn.org>2017-03-06 14:36:25 -0800
commitab5617dbda3213827312ea46dc889d8a756b6fff (patch)
treef584c65cc6b7ba65cac0d57f61f6001ebb474784
parent27d931da3ac758f580d6ff89410d29ce886d9936 (diff)
downloadopenvswitch-ab5617dbda3213827312ea46dc889d8a756b6fff.tar.gz
lib: Refactor nested netlink APIs.
Future patches will make use of those changes. Signed-off-by: Andy Zhou <azhou@ovn.org> Acked-by: Jarno Rajahalme <jarno@ovn.org>
-rw-r--r--lib/netlink.c19
-rw-r--r--lib/netlink.h3
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/netlink.c b/lib/netlink.c
index ad7d35af4..ae4c72a55 100644
--- a/lib/netlink.c
+++ b/lib/netlink.c
@@ -467,16 +467,29 @@ 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'. */
+/* Cancel a nested Netlink attribute in 'msg'. 'offset' should be the value
+ * returned by nl_msg_start_nested(). */
void
+nl_msg_cancel_nested(struct ofpbuf *msg, size_t offset)
+{
+ 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'.
+ *
+ * Return true if the nested message has been dropped. */
+bool
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;
+ nl_msg_cancel_nested(msg, offset);
+ return true;
+ } else {
+ return false;
}
}
diff --git a/lib/netlink.h b/lib/netlink.h
index 7646f91da..bb4dbf661 100644
--- a/lib/netlink.h
+++ b/lib/netlink.h
@@ -79,7 +79,8 @@ 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_cancel_nested(struct ofpbuf *, size_t offset);
+bool 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);