Future patches will make use of those changes. Signed-off-by: Andy Zhou <az...@ovn.org> --- lib/netlink.c | 19 ++++++++++++++++--- lib/netlink.h | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/lib/netlink.c b/lib/netlink.c index ad7d35a..ae4c72a 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 7646f91..bb4dbf6 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); -- 1.8.3.1 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev