It will fill-in a l_genl_attr structure with the necessary information
where the nested attribute starts. Thus at the end, it will update the
nested attribute with the final length.
---
ell/genl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
ell/genl.h | 3 +++
2 files changed, 51 insertions(+)
diff --git a/ell/genl.c b/ell/genl.c
index 2ef6a34..5484d33 100644
--- a/ell/genl.c
+++ b/ell/genl.c
@@ -707,6 +707,54 @@ bool l_genl_msg_append_attr(struct l_genl_msg *msg, uint16_t type,
return true;
}
+bool l_genl_msg_append_init_recurse(struct l_genl_msg *msg, uint16_t type,
+ struct l_genl_attr *nested)
+{
+ struct nlattr *nla;
+
+ if (!msg || !nested)
+ return false;
+
+ nla = msg->data + msg->len;
+ nla->nla_len = NLA_HDRLEN;
+ nla->nla_type = type;
+
+ if (!l_genl_msg_append_attr(msg, type, 0, NULL))
+ return false;
+
+ nested->msg = msg;
+ nested->data = nla;
+ nested->len = 0;
+ nested->next_data = NULL;
+ nested->next_len = 0;
+
+ return true;
+}
+
+bool l_genl_msg_append_end_recurse(struct l_genl_attr *nested)
+{
+ struct l_genl_msg *msg;
+ struct nlattr *nla;
+ uint32_t len;
+
+ if (!nested || !nested->msg)
+ return false;
+
+ msg = nested->msg;
+ len = nested->data - msg->data;
+ nla = msg->data + len;
+
+ len = msg->len - len;
+ if (len <= NLA_HDRLEN)
+ return false;
+
+ nla->nla_len = len;
+
+ // Should we check msg alignement again?
+
+ return true;
+}
+
#define NLA_OK(nla,len) ((len) >= (int) sizeof(struct nlattr) && \
(nla)->nla_len >= sizeof(struct nlattr) && \
(nla)->nla_len <= (len))
diff --git a/ell/genl.h b/ell/genl.h
index c628b8c..13fe149 100644
--- a/ell/genl.h
+++ b/ell/genl.h
@@ -71,6 +71,9 @@ int l_genl_msg_get_error(struct l_genl_msg *msg);
bool l_genl_msg_append_attr(struct l_genl_msg *msg, uint16_t type,
uint16_t len, const void *data);
+bool l_genl_msg_append_init_recurse(struct l_genl_msg *msg, uint16_t type,
+ struct l_genl_attr *nested);
+bool l_genl_msg_append_end_recurse(struct l_genl_attr *nested);
bool l_genl_attr_init(struct l_genl_attr *attr, struct l_genl_msg *msg);
bool l_genl_attr_next(struct l_genl_attr *attr, uint16_t *type,
--
2.0.5