diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2010-04-30 12:29:17 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2010-04-30 12:29:17 +0200 |
commit | d75ac4598f2f9472dd625d284b912d417b287e1e (patch) | |
tree | 7ea83040b33754bc96435d6e1166d5c89a225e6f /src | |
parent | c1a946a824a7b870e06b9eff209ad12d11484d1a (diff) | |
download | libmnl-d75ac4598f2f9472dd625d284b912d417b287e1e.tar.gz libmnl-d75ac4598f2f9472dd625d284b912d417b287e1e.zip |
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')
-rw-r--r-- | src/attr.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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; +} |