From e52a09c5078364f0a645f407c797e68a2c1d5f04 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Mon, 22 Nov 2010 13:13:04 +0100 Subject: nl: rename nlmsg_msg_size() to nlmsg_size(), nlmsg_len() -> nlmsg_datalen() The old symbols are left around for compatibility. --- include/netlink/msg.h | 16 +++++++------- lib/attr.c | 2 +- lib/msg.c | 58 +++++++++++++++++++++++++++++++++++++++------------ 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); diff --git a/lib/attr.c b/lib/attr.c index 6147ff3..cccd50d 100644 --- a/lib/attr.c +++ b/lib/attr.c @@ -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)); } diff --git a/lib/msg.c b/lib/msg.c index f6d1ee4..95ad188 100644 --- a/lib/msg.c +++ b/lib/msg.c @@ -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); +} + /** @} */ /** diff --git a/lib/nl.c b/lib/nl.c index 4e09b9e..97a5df0 100644 --- a/lib/nl.c +++ b/lib/nl.c @@ -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 -- cgit v0.12