From eadc7a04ea1fbb71987aeb8d1b7aaa6135cfbf5f Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 17 Dec 2010 10:28:38 +0100 Subject: attr: add put function that allows to check buffer size This patch adds a set of function that allows to check the size of the buffer. This is useful for attribute batching. This is strongly based on a patch from Jozsef. Signed-off-by: Jozsef Kadlecsik Signed-off-by: Pablo Neira Ayuso --- include/libmnl/libmnl.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h index 5b8d78c..1237b6d 100644 --- a/include/libmnl/libmnl.h +++ b/include/libmnl/libmnl.h @@ -93,8 +93,18 @@ 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 char *data); extern void mnl_attr_put_strz(struct nlmsghdr *nlh, uint16_t type, const char *data); +/* TLV attribute putters with buffer boundary checkings */ +extern bool mnl_attr_put_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, size_t len, const void *data); +extern bool mnl_attr_put_u8_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint8_t data); +extern bool mnl_attr_put_u16_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint16_t data); +extern bool mnl_attr_put_u32_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint32_t data); +extern bool mnl_attr_put_u64_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint64_t data); +extern bool mnl_attr_put_str_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, const char *data); +extern bool mnl_attr_put_strz_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, const char *data); + /* TLV attribute nesting */ extern struct nlattr *mnl_attr_nest_start(struct nlmsghdr *nlh, uint16_t type); +extern struct nlattr *mnl_attr_nest_start_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type); extern void mnl_attr_nest_end(struct nlmsghdr *nlh, struct nlattr *start); extern void mnl_attr_nest_cancel(struct nlmsghdr *nlh, struct nlattr *start); -- cgit v1.2.3