diff options
-rw-r--r-- | include/netlink/msg.h | 16 | ||||
-rw-r--r-- | lib/attr.c | 2 | ||||
-rw-r--r-- | lib/msg.c | 58 | ||||
-rw-r--r-- | lib/nl.c | 2 |
4 files changed, 54 insertions, 24 deletions
diff --git a/include/netlink/msg.h b/include/netlink/msg.h index e331f42..12b2061 100644 --- a/include/netlink/msg.h +++ b/include/netlink/msg.h @@ -44,15 +44,13 @@ struct nl_msg; struct nl_tree; struct ucred; -/* size calculations */ -extern int nlmsg_msg_size(int); -extern int nlmsg_total_size(int); -extern int nlmsg_padlen(int); - -/* payload access */ -extern void * nlmsg_data(const struct nlmsghdr *); -extern int nlmsg_len(const struct nlmsghdr *); -extern void * nlmsg_tail(const struct nlmsghdr *); +extern int nlmsg_size(int); +extern int nlmsg_total_size(int); +extern int nlmsg_padlen(int); + +extern void * nlmsg_data(const struct nlmsghdr *); +extern int nlmsg_datalen(const struct nlmsghdr *); +extern void * nlmsg_tail(const struct nlmsghdr *); /* attribute access */ extern struct nlattr * nlmsg_attrdata(const struct nlmsghdr *, int); @@ -1115,7 +1115,7 @@ int nla_put_nested(struct nl_msg *msg, int attrtype, struct nl_msg *nested) NL_DBG(2, "msg %p: attr <> %d: adding msg %p as nested attribute\n", msg, attrtype, nested); - return nla_put(msg, attrtype, nlmsg_len(nested->nm_nlh), + return nla_put(msg, attrtype, nlmsg_datalen(nested->nm_nlh), nlmsg_data(nested->nm_nlh)); } @@ -178,17 +178,32 @@ static void __init init_msg_size(void) */ /** - * length of netlink message not including padding - * @arg payload length of message payload + * Calculates size of netlink message based on payload length. + * @arg payload Length of payload + * + * See \ref core_msg_fmt_align for more information on alignment. + * + * @return size of netlink message without padding. */ -int nlmsg_msg_size(int payload) +int nlmsg_size(int payload) { return NLMSG_HDRLEN + payload; } +int nlmsg_msg_size(int payload) +{ + return nlmsg_size(payload); +} + /** - * length of netlink message including padding - * @arg payload length of message payload + * Calculates size of netlink message including padding based on payload length + * @arg payload Length of payload + * + * This function is idential to nlmsg_size() + nlmsg_padlen(). + * + * See \ref core_msg_fmt_align for more information on alignment. + * + * @return Size of netlink message including padding. */ int nlmsg_total_size(int payload) { @@ -196,8 +211,16 @@ int nlmsg_total_size(int payload) } /** - * length of padding at the message's tail - * @arg payload length of message payload + * Size of padding that needs to be added at end of message + * @arg payload Length of payload + * + * Calculates the number of bytes of padding which is required to be added to + * the end of the message to ensure that the next netlink message header begins + * properly aligned to NLMSG_ALIGNTO. + * + * See \ref core_msg_fmt_align for more information on alignment. + * + * @return Number of bytes of padding needed. */ int nlmsg_padlen(int payload) { @@ -207,13 +230,15 @@ int nlmsg_padlen(int payload) /** @} */ /** - * @name Payload Access + * @name Access to Message Payload * @{ */ /** - * head of message payload - * @arg nlh netlink messsage header + * Return pointer to message payload + * @arg nlh Netlink message header + * + * @return Pointer to start of message payload. */ void *nlmsg_data(const struct nlmsghdr *nlh) { @@ -226,14 +251,21 @@ void *nlmsg_tail(const struct nlmsghdr *nlh) } /** - * length of message payload - * @arg nlh netlink message header + * Return length of message payload + * @arg nlh Netlink message header + * + * @return Length of message payload in bytes. */ -int nlmsg_len(const struct nlmsghdr *nlh) +int nlmsg_datalen(const struct nlmsghdr *nlh) { return nlh->nlmsg_len - NLMSG_HDRLEN; } +int nlmsg_len(const struct nlmsghdr *nlh) +{ + return nlmsg_datalen(nlh); +} + /** @} */ /** @@ -637,7 +637,7 @@ continue_reading: else if (hdr->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *e = nlmsg_data(hdr); - if (hdr->nlmsg_len < nlmsg_msg_size(sizeof(*e))) { + if (hdr->nlmsg_len < nlmsg_size(sizeof(*e))) { /* Truncated error message, the default action * is to stop parsing. The user may overrule * this action by returning NL_SKIP or |