diff options
author | Thomas Graf <tgraf@suug.ch> | 2013-03-13 15:53:07 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2013-03-14 11:46:01 (GMT) |
commit | 9e6cdbf6fc60f95e232c4ca34004606da9536d01 (patch) | |
tree | 16ee3ee5574e986e1875df669cba6c541c0aaffb /lib | |
parent | 4d7680c19c131175e2ec431de9a026230c968a7e (diff) | |
download | libnl-9e6cdbf6fc60f95e232c4ca34004606da9536d01.zip libnl-9e6cdbf6fc60f95e232c4ca34004606da9536d01.tar.gz libnl-9e6cdbf6fc60f95e232c4ca34004606da9536d01.tar.bz2 |
attr: Add nla_nest_cancel() to remove partially added nested attributes
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/attr.c | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -820,8 +820,7 @@ int nla_nest_end(struct nl_msg *msg, struct nlattr *start) * Kernel can't handle empty nested attributes, trim the * attribute header again */ - msg->nm_nlh->nlmsg_len -= NLA_HDRLEN; - memset(nlmsg_tail(msg->nm_nlh), 0, NLA_HDRLEN); + nla_nest_cancel(msg, start); return 0; } @@ -850,6 +849,28 @@ int nla_nest_end(struct nl_msg *msg, struct nlattr *start) } /** + * Cancel the addition of a nested attribute + * @arg msg Netlink message + * @arg attr Nested netlink attribute + * + * Removes any partially added nested Netlink attribute from the message + * by resetting the message to the size before the call to nla_nest_start() + * and by overwriting any potentially touched message segments with 0. + */ +void nla_nest_cancel(struct nl_msg *msg, struct nlattr *attr) +{ + ssize_t len; + + len = (void *) nlmsg_tail(msg->nm_nlh) - (void *) attr; + if (len < 0) + BUG(); + else if (len > 0) { + msg->nm_nlh->nlmsg_len -= len; + memset(nlmsg_tail(msg->nm_nlh), 0, len); + } +} + +/** * Create attribute index based on nested attribute * @arg tb Index array to be filled (maxtype+1 elements). * @arg maxtype Maximum attribute type expected and accepted. |