diff options
author | Andy Zhou <azhou@ovn.org> | 2017-01-12 17:08:53 -0800 |
---|---|---|
committer | Andy Zhou <azhou@ovn.org> | 2017-01-23 22:58:27 -0800 |
commit | bf6b1d052e793ebadd48b05b6595319caa08c026 (patch) | |
tree | 98e4baec9ea94059843e8f0b16a764fcbf894f3b | |
parent | 0526761391dbced4e5fa306cc68913b8ad050b38 (diff) | |
download | openvswitch-bf6b1d052e793ebadd48b05b6595319caa08c026.tar.gz |
lib: Add nl_msg_end_non_empty_nested()
Later patch will make use of nl_msg_end_non_empty_nested()
Signed-off-by: Andy Zhou <azhou@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
-rw-r--r-- | lib/netlink.c | 13 | ||||
-rw-r--r-- | lib/netlink.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/netlink.c b/lib/netlink.c index 4715d68d8..ad7d35af4 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 b931a412f..7646f91da 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); |