summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Make_global.am2
-rw-r--r--configure.ac2
-rw-r--r--include/libmnl/libmnl.h6
-rw-r--r--src/attr.c35
-rw-r--r--src/libmnl.map6
5 files changed, 45 insertions, 6 deletions
diff --git a/Make_global.am b/Make_global.am
index 1c9ed63..3665b68 100644
--- a/Make_global.am
+++ b/Make_global.am
@@ -18,7 +18,7 @@
# set age to 0.
# </snippet>
#
-LIBVERSION=0:1:0
+LIBVERSION=1:0:1
AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include
AM_CFLAGS = ${regular_CFLAGS} ${GCC_FVISIBILITY_HIDDEN}
diff --git a/configure.ac b/configure.ac
index 49c4fc0..718ab1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
dnl Process this file with autoconf to create configure.
-AC_INIT([libmnl], [1.0.2])
+AC_INIT([libmnl], [1.0.3])
AC_CONFIG_AUX_DIR([build-aux])
AC_CANONICAL_HOST
AC_CONFIG_MACRO_DIR([m4])
diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
index 1e170a9..a647fd9 100644
--- a/include/libmnl/libmnl.h
+++ b/include/libmnl/libmnl.h
@@ -156,11 +156,17 @@ extern struct nlattr *mnl_attr_next(const struct nlattr *attr);
mnl_attr_ok((attr), (char *)mnl_attr_get_payload(nest) + mnl_attr_get_payload_len(nest) - (char *)(attr)); \
(attr) = mnl_attr_next(attr))
+#define mnl_attr_for_each_payload(payload, payload_size) \
+ for ((attr) = (payload); \
+ mnl_attr_ok((attr), (char *)(payload) + payload_size - (char *)(attr)); \
+ (attr) = mnl_attr_next(attr))
+
/* TLV callback-based attribute parsers */
typedef int (*mnl_attr_cb_t)(const struct nlattr *attr, void *data);
extern int mnl_attr_parse(const struct nlmsghdr *nlh, unsigned int offset, mnl_attr_cb_t cb, void *data);
extern int mnl_attr_parse_nested(const struct nlattr *attr, mnl_attr_cb_t cb, void *data);
+extern int mnl_attr_parse_payload(const void *payload, size_t payload_len, mnl_attr_cb_t cb, void *data);
/*
* callback API
diff --git a/src/attr.c b/src/attr.c
index 55a80d6..1136c50 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -1,5 +1,5 @@
/*
- * (C) 2008-2010 by Pablo Neira Ayuso <pablo@netfilter.org>
+ * (C) 2008-2012 by Pablo Neira Ayuso <pablo@netfilter.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
@@ -304,6 +304,39 @@ mnl_attr_parse_nested(const struct nlattr *nested, mnl_attr_cb_t cb,
EXPORT_SYMBOL(mnl_attr_parse_nested);
/**
+ * mnl_attr_parse_payload - parse attributes in payload of Netlink message
+ * \param payload pointer to payload of the Netlink message
+ * \param payload_len payload length that contains the attributes
+ * \param cb callback function that is called for each attribute
+ * \param data pointer to data that is passed to the callback function
+ *
+ * This function takes a pointer to the area that contains the attributes,
+ * commonly known as the payload of the Netlink message. Thus, you have to
+ * pass a pointer to the Netlink message payload, instead of the entire
+ * message.
+ *
+ * This function allows you to iterate over the sequence of attributes that are
+ * located at some payload offset. You can then put the attributes in one array
+ * as usual, or you can use any other data structure (such as lists or trees).
+ *
+ * This function propagates the return value of the callback, which can be
+ * MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
+ */
+int
+mnl_attr_parse_payload(const void *payload, size_t payload_len,
+ mnl_attr_cb_t cb, void *data)
+{
+ int ret = MNL_CB_OK;
+ const struct nlattr *attr;
+
+ mnl_attr_for_each_payload(payload, payload_len)
+ if ((ret = cb(attr, data)) <= MNL_CB_STOP)
+ return ret;
+ return ret;
+}
+EXPORT_SYMBOL(mnl_attr_parse_payload);
+
+/**
* mnl_attr_get_u8 - returns 8-bit unsigned integer attribute payload
* \param attr pointer to netlink attribute
*
diff --git a/src/libmnl.map b/src/libmnl.map
index 3147ae0..dbc332e 100644
--- a/src/libmnl.map
+++ b/src/libmnl.map
@@ -69,6 +69,6 @@ global:
local: *;
};
-#LIBMNL_1.1 {
-# mnl_my_new_func;
-#} LIBMNL_1.0;
+LIBMNL_1.1 {
+ mnl_attr_parse_payload;
+} LIBMNL_1.0;