summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/netlink/genl/genl.h4
-rw-r--r--lib/genl/genl.c89
-rw-r--r--lib/genl/mngt.c2
3 files changed, 77 insertions, 18 deletions
diff --git a/include/netlink/genl/genl.h b/include/netlink/genl/genl.h
index a2da943..e455581 100644
--- a/include/netlink/genl/genl.h
+++ b/include/netlink/genl/genl.h
@@ -35,6 +35,10 @@ extern int genlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
extern struct genlmsghdr *
genlmsg_hdr(struct nlmsghdr *);
extern void * genlmsg_data(const struct genlmsghdr *);
+extern void * genlmsg_user_hdr(const struct genlmsghdr *);
+extern void * genlmsg_user_data(const struct genlmsghdr *, const int);
+extern int genlmsg_user_datalen(const struct genlmsghdr *,
+ const int);
extern int genlmsg_len(const struct genlmsghdr *);
extern struct nlattr * genlmsg_attrdata(const struct genlmsghdr *, int);
extern int genlmsg_attrlen(const struct genlmsghdr *, int);
diff --git a/lib/genl/genl.c b/lib/genl/genl.c
index 8f2e496..569ef9e 100644
--- a/lib/genl/genl.c
+++ b/lib/genl/genl.c
@@ -213,36 +213,66 @@ struct genlmsghdr *genlmsg_hdr(struct nlmsghdr *nlh)
}
/**
- * Return pointer to message payload
+ * Return length of message payload including user header
* @arg gnlh Generic Netlink message header
*
- * Calculates the pointer to the message payload based on the pointer
- * to the generic netlink message header.
+ * @see genlmsg_data()
*
- * @note Depending on whether your own message format uses a header, the
- * returned pointer may in fact point to the user header.
+ * @return Length of user payload including an eventual user header in
+ * number of bytes.
+ */
+int genlmsg_len(const struct genlmsghdr *gnlh)
+{
+ struct nlmsghdr *nlh;
+
+ nlh = (struct nlmsghdr *)((unsigned char *) gnlh - NLMSG_HDRLEN);
+ return (nlh->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN);
+}
+
+
+/**
+ * Return pointer to user header
+ * @arg gnlh Generic Netlink message header
+ *
+ * Calculates the pointer to the user header based on the pointer to
+ * the Generic Netlink message header.
*
- * @return Pointer to generic netlink message
+ * @return Pointer to the user header
*/
-void *genlmsg_data(const struct genlmsghdr *gnlh)
+void *genlmsg_user_hdr(const struct genlmsghdr *gnlh)
{
- return ((unsigned char *) gnlh + GENL_HDRLEN);
+ return genlmsg_data(gnlh);
}
+/**
+ * Return pointer to user data
+ * @arg gnlh Generic netlink message header
+ * @arg hdrlen Length of user header
+ *
+ * Calculates the pointer to the user data based on the pointer to
+ * the Generic Netlink message header.
+ *
+ * @see genlmsg_user_datalen()
+ *
+ * @return Pointer to the user data
+ */
+void *genlmsg_user_data(const struct genlmsghdr *gnlh, const int hdrlen)
+{
+ return genlmsg_user_hdr(gnlh) + NLMSG_ALIGN(hdrlen);
+}
/**
- * Return length of message payload
+ * Return length of user data
* @arg gnlh Generic Netlink message header
+ * @arg hdrlen Length of user header
*
- * @return Length of user payload including an eventual user header in
- * number of bytes.
+ * @see genlmsg_user_data()
+ *
+ * @return Length of user data in bytes
*/
-int genlmsg_len(const struct genlmsghdr *gnlh)
+int genlmsg_user_datalen(const struct genlmsghdr *gnlh, const int hdrlen)
{
- struct nlmsghdr *nlh;
-
- nlh = (struct nlmsghdr *)((unsigned char *) gnlh - NLMSG_HDRLEN);
- return (nlh->nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN);
+ return genlmsg_len(gnlh) - NLMSG_ALIGN(hdrlen);
}
/**
@@ -250,11 +280,13 @@ int genlmsg_len(const struct genlmsghdr *gnlh)
* @arg gnlh Generic Netlink message header
* @arg hdrlen Length of user header
*
+ * @see genlmsg_attrlen()
+ *
* @return Pointer to the start of the message's attributes section.
*/
struct nlattr *genlmsg_attrdata(const struct genlmsghdr *gnlh, int hdrlen)
{
- return genlmsg_data(gnlh) + NLMSG_ALIGN(hdrlen);
+ return genlmsg_user_data(gnlh, hdrlen);
}
/**
@@ -262,6 +294,8 @@ struct nlattr *genlmsg_attrdata(const struct genlmsghdr *gnlh, int hdrlen)
* @arg gnlh Generic Netlink message header
* @arg hdrlen Length of user header
*
+ * @see genlmsg_attrdata()
+ *
* @return Length of the message section containing attributes in number
* of bytes.
*/
@@ -333,4 +367,25 @@ void *genlmsg_put(struct nl_msg *msg, uint32_t port, uint32_t seq, int family,
/** @} */
+/**
+ * @name Deprecated
+ * @{
+ */
+
+/**
+ * Return pointer to message payload
+ * @arg gnlh Generic Netlink message header
+ *
+ * @deprecated This function has been deprecated due to inability to specify
+ * the length of the user header. Use genlmsg_user_hdr()
+ * respectively genlmsg_user_data().
+ *
+ * @return Pointer to payload section
+ */
+void *genlmsg_data(const struct genlmsghdr *gnlh)
+{
+ return ((unsigned char *) gnlh + GENL_HDRLEN);
+}
+
+/** @} */
/** @} */
diff --git a/lib/genl/mngt.c b/lib/genl/mngt.c
index fd1aa03..f53aa8a 100644
--- a/lib/genl/mngt.c
+++ b/lib/genl/mngt.c
@@ -60,7 +60,7 @@ found:
.who = who,
.nlh = nlh,
.genlhdr = ghdr,
- .userhdr = genlmsg_data(ghdr),
+ .userhdr = genlmsg_user_hdr(ghdr),
.attrs = tb,
};