11#include <libnftnl/udata.h>
19EXPORT_SYMBOL(nftnl_udata_buf_alloc);
20struct nftnl_udata_buf *nftnl_udata_buf_alloc(uint32_t data_size)
22 struct nftnl_udata_buf *buf;
24 buf = malloc(
sizeof(
struct nftnl_udata_buf) + data_size);
27 buf->size = data_size;
33EXPORT_SYMBOL(nftnl_udata_buf_free);
34void nftnl_udata_buf_free(
const struct nftnl_udata_buf *buf)
39EXPORT_SYMBOL(nftnl_udata_buf_len);
40uint32_t nftnl_udata_buf_len(
const struct nftnl_udata_buf *buf)
42 return (uint32_t)(buf->end - buf->data);
45EXPORT_SYMBOL(nftnl_udata_buf_data);
46void *nftnl_udata_buf_data(
const struct nftnl_udata_buf *buf)
48 return (
void *)buf->data;
51EXPORT_SYMBOL(nftnl_udata_buf_put);
52void nftnl_udata_buf_put(
struct nftnl_udata_buf *buf,
const void *data,
55 memcpy(buf->data, data, len <= buf->size ? len : buf->size);
56 buf->end = buf->data + len;
59EXPORT_SYMBOL(nftnl_udata_start);
60struct nftnl_udata *nftnl_udata_start(
const struct nftnl_udata_buf *buf)
62 return (
struct nftnl_udata *)buf->data;
65EXPORT_SYMBOL(nftnl_udata_end);
66struct nftnl_udata *nftnl_udata_end(
const struct nftnl_udata_buf *buf)
68 return (
struct nftnl_udata *)buf->end;
71EXPORT_SYMBOL(nftnl_udata_put);
72bool nftnl_udata_put(
struct nftnl_udata_buf *buf, uint8_t type, uint32_t len,
75 struct nftnl_udata *attr;
77 if (len > UINT8_MAX || buf->size < len +
sizeof(
struct nftnl_udata))
80 attr = (
struct nftnl_udata *)buf->end;
83 memcpy(attr->value, value, len);
85 buf->end = (
char *)nftnl_udata_next(attr);
90EXPORT_SYMBOL(nftnl_udata_put_strz);
91bool nftnl_udata_put_strz(
struct nftnl_udata_buf *buf, uint8_t type,
94 return nftnl_udata_put(buf, type, strlen(strz) + 1, strz);
97EXPORT_SYMBOL(nftnl_udata_put_u32);
98bool nftnl_udata_put_u32(
struct nftnl_udata_buf *buf, uint8_t type,
101 return nftnl_udata_put(buf, type,
sizeof(data), &data);
104EXPORT_SYMBOL(nftnl_udata_type);
105uint8_t nftnl_udata_type(
const struct nftnl_udata *attr)
110EXPORT_SYMBOL(nftnl_udata_len);
111uint8_t nftnl_udata_len(
const struct nftnl_udata *attr)
116EXPORT_SYMBOL(nftnl_udata_get);
117void *nftnl_udata_get(
const struct nftnl_udata *attr)
119 return (
void *)attr->value;
122EXPORT_SYMBOL(nftnl_udata_get_u32);
123uint32_t nftnl_udata_get_u32(
const struct nftnl_udata *attr)
127 memcpy(&data, attr->value,
sizeof(data));
132EXPORT_SYMBOL(nftnl_udata_next);
133struct nftnl_udata *nftnl_udata_next(
const struct nftnl_udata *attr)
135 return (
struct nftnl_udata *)&attr->value[attr->len];
138EXPORT_SYMBOL(nftnl_udata_parse);
139int nftnl_udata_parse(
const void *data, uint32_t data_len, nftnl_udata_cb_t cb,
143 const struct nftnl_udata *attr;
145 nftnl_udata_for_each_data(data, data_len, attr) {
146 ret = cb(attr, cb_data);
154EXPORT_SYMBOL(nftnl_udata_nest_start);
155struct nftnl_udata *nftnl_udata_nest_start(
struct nftnl_udata_buf *buf,
158 struct nftnl_udata *ud = nftnl_udata_end(buf);
160 nftnl_udata_put(buf, type, 0, NULL);
165EXPORT_SYMBOL(nftnl_udata_nest_end);
166void nftnl_udata_nest_end(
struct nftnl_udata_buf *buf,
struct nftnl_udata *ud)
168 ud->len = buf->end - (
char *)ud->value;