* [RFC] genl: Add utility function no append nested attribute into a message
@ 2015-02-18 13:06 Tomasz Bursztyka
2015-02-24 9:14 ` Tomasz Bursztyka
0 siblings, 1 reply; 4+ messages in thread
From: Tomasz Bursztyka @ 2015-02-18 13:06 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 2258 bytes --]
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC] genl: Add utility function no append nested attribute into a message
2015-02-18 13:06 [RFC] genl: Add utility function no append nested attribute into a message Tomasz Bursztyka
@ 2015-02-24 9:14 ` Tomasz Bursztyka
2015-02-24 17:14 ` Marcel Holtmann
0 siblings, 1 reply; 4+ messages in thread
From: Tomasz Bursztyka @ 2015-02-24 9:14 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 197 bytes --]
Hi Marcel,
I need your input on that one.
I am not 100% sure it needs to align the message once we set the length
of the nested arguments. Does it needs to set some padding then?
Tomasz
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] genl: Add utility function no append nested attribute into a message
2015-02-24 9:14 ` Tomasz Bursztyka
@ 2015-02-24 17:14 ` Marcel Holtmann
2015-02-25 11:25 ` Tomasz Bursztyka
0 siblings, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2015-02-24 17:14 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 333 bytes --]
Hi Tomasz,
> I need your input on that one.
> I am not 100% sure it needs to align the message once we set the length
> of the nested arguments. Does it needs to set some padding then?
if it is the last one, then you might not need to. However if it is not the last one, then you do need to align it.
Regards
Marcel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] genl: Add utility function no append nested attribute into a message
2015-02-24 17:14 ` Marcel Holtmann
@ 2015-02-25 11:25 ` Tomasz Bursztyka
0 siblings, 0 replies; 4+ messages in thread
From: Tomasz Bursztyka @ 2015-02-25 11:25 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 351 bytes --]
Hi Marcel,
>> I need your input on that one.
>> I am not 100% sure it needs to align the message once we set the length
>> of the nested arguments. Does it needs to set some padding then?
> if it is the last one, then you might not need to. However if it is not the last one, then you do need to align it.
Let's always align then.
Tomasz
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-02-25 11:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-18 13:06 [RFC] genl: Add utility function no append nested attribute into a message Tomasz Bursztyka
2015-02-24 9:14 ` Tomasz Bursztyka
2015-02-24 17:14 ` Marcel Holtmann
2015-02-25 11:25 ` Tomasz Bursztyka
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.