summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2012-04-13 16:30:44 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2012-05-18 01:02:49 +0200
commit00b82dd6c9ad4765ebc2f59e395a6749acc0738a (patch)
tree494683b4a8f8f46191bda3fe4d4999cd63259fd4 /src
parent5373fe81ca557a8f846fd6c0b68ee389808cfc3b (diff)
downloadlibmnl-00b82dd6c9ad4765ebc2f59e395a6749acc0738a.tar.gz
libmnl-00b82dd6c9ad4765ebc2f59e395a6749acc0738a.zip
parse: add mnl_attr_for_each_payload
This function allows you to parse the payload of the Netlink message. Thus, you can skip the headers and go down to the part of the message you want to parse. This patch has updated the LIBVERSION and it also bumps the version to 1.0.3, in case that someone wants to package some snapshot, not to mess with the new symbol we have added. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/attr.c35
-rw-r--r--src/libmnl.map6
2 files changed, 37 insertions, 4 deletions
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;