Skip to content

Commit

Permalink
lib: Refactor nested netlink APIs.
Browse files Browse the repository at this point in the history
Future patches will make use of those changes.

Signed-off-by: Andy Zhou <[email protected]>
Acked-by: Jarno Rajahalme <[email protected]>
  • Loading branch information
azhou-nicira committed Mar 6, 2017
1 parent 27d931d commit ab5617d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions lib/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ab5617d

Please sign in to comment.