summaryrefslogtreecommitdiffstats
path: root/src/attr.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2010-04-30 12:29:17 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2010-04-30 12:29:17 +0200
commitd75ac4598f2f9472dd625d284b912d417b287e1e (patch)
tree7ea83040b33754bc96435d6e1166d5c89a225e6f /src/attr.c
parentc1a946a824a7b870e06b9eff209ad12d11484d1a (diff)
add helpers to nest attributes
Based on code from Jozsef Kadlecsik and its ipset-5 implementation. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/attr.c')
-rw-r--r--src/attr.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/attr.c b/src/attr.c
index e8ce2ea..37fa798 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -454,3 +454,35 @@ void mnl_attr_put_str_null(struct nlmsghdr *nlh, uint16_t type, const void *data
{
mnl_attr_put(nlh, type, strlen(data)+1, data);
}
+
+/**
+ * mnl_attr_nest_start - start an attribute nest
+ * @nlh: pointer to the netlink message
+ * @type: netlink attribute type
+ *
+ * This function adds the attribute header that identifies the beginning of
+ * an attribute nest. This function always returns a valid pointer to the
+ * beginning of the nest.
+ */
+struct nlattr *mnl_attr_nest_start(struct nlmsghdr *nlh, uint16_t type)
+{
+ struct nlattr *start = mnl_nlmsg_get_payload_tail(nlh);
+
+ /* set start->nla_len in mnl_attr_nest_end() */
+ start->nla_type = NLA_F_NESTED | type;
+ nlh->nlmsg_len += MNL_ALIGN(sizeof(struct nlattr));
+
+ return start;
+}
+
+/**
+ * mnl_attr_nest_end - end an attribute nest
+ * @nlh: pointer to the netlink message
+ * @start: pointer to the attribute nest returned by mnl_attr_nest_start()
+ *
+ * This function updates the attribute header that identifies the nest.
+ */
+void mnl_attr_nest_end(struct nlmsghdr *nlh, struct nlattr *start)
+{
+ start->nla_len = mnl_nlmsg_get_payload_tail(nlh) - (void *)start;
+}