summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libmnl/libmnl.h4
-rw-r--r--src/attr.c32
2 files changed, 36 insertions, 0 deletions
diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
index 95167a3..d4bb7ed 100644
--- a/include/libmnl/libmnl.h
+++ b/include/libmnl/libmnl.h
@@ -85,6 +85,10 @@ extern void mnl_attr_put_u64(struct nlmsghdr *nlh, uint16_t type, uint64_t data)
extern void mnl_attr_put_str(struct nlmsghdr *nlh, uint16_t type, const void *data);
extern void mnl_attr_put_str_null(struct nlmsghdr *nlh, uint16_t type, const void *data);
+/* TLV attribute nesting */
+extern struct nlattr *mnl_attr_nest_start(struct nlmsghdr *nlh, uint16_t type);
+extern void mnl_attr_nest_end(struct nlmsghdr *nlh, struct nlattr *start);
+
/* TLV validation */
extern int mnl_attr_type_valid(const struct nlattr *attr, uint16_t maxtype);
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;
+}