7#include <libnftnl/udata.h>
15EXPORT_SYMBOL(nftnl_udata_buf_alloc);
16struct nftnl_udata_buf *nftnl_udata_buf_alloc(uint32_t data_size)
18 struct nftnl_udata_buf *buf;
20 buf = malloc(
sizeof(
struct nftnl_udata_buf) + data_size);
23 buf->size = data_size;
29EXPORT_SYMBOL(nftnl_udata_buf_free);
30void nftnl_udata_buf_free(
const struct nftnl_udata_buf *buf)
35EXPORT_SYMBOL(nftnl_udata_buf_len);
36uint32_t nftnl_udata_buf_len(
const struct nftnl_udata_buf *buf)
38 return (uint32_t)(buf->end - buf->data);
41static uint32_t nftnl_udata_buf_space(
const struct nftnl_udata_buf *buf)
43 return buf->size - nftnl_udata_buf_len(buf);
46EXPORT_SYMBOL(nftnl_udata_buf_data);
47void *nftnl_udata_buf_data(
const struct nftnl_udata_buf *buf)
49 return (
void *)buf->data;
52EXPORT_SYMBOL(nftnl_udata_buf_put);
53void nftnl_udata_buf_put(
struct nftnl_udata_buf *buf,
const void *data,
56 memcpy(buf->data, data, len <= buf->size ? len : buf->size);
57 buf->end = buf->data + len;
60EXPORT_SYMBOL(nftnl_udata_start);
61struct nftnl_udata *nftnl_udata_start(
const struct nftnl_udata_buf *buf)
63 return (
struct nftnl_udata *)buf->data;
66EXPORT_SYMBOL(nftnl_udata_end);
67struct nftnl_udata *nftnl_udata_end(
const struct nftnl_udata_buf *buf)
69 return (
struct nftnl_udata *)buf->end;
72EXPORT_SYMBOL(nftnl_udata_put);
73bool nftnl_udata_put(
struct nftnl_udata_buf *buf, uint8_t type, uint32_t len,
76 struct nftnl_udata *attr;
78 if (len > UINT8_MAX ||
79 nftnl_udata_buf_space(buf) < len +
sizeof(
struct nftnl_udata))
82 attr = (
struct nftnl_udata *)buf->end;
85 memcpy(attr->value, value, len);
87 buf->end = (
char *)nftnl_udata_next(attr);
92EXPORT_SYMBOL(nftnl_udata_put_strz);
93bool nftnl_udata_put_strz(
struct nftnl_udata_buf *buf, uint8_t type,
96 return nftnl_udata_put(buf, type, strlen(strz) + 1, strz);
99EXPORT_SYMBOL(nftnl_udata_put_u32);
100bool nftnl_udata_put_u32(
struct nftnl_udata_buf *buf, uint8_t type,
103 return nftnl_udata_put(buf, type,
sizeof(data), &data);
106EXPORT_SYMBOL(nftnl_udata_type);
107uint8_t nftnl_udata_type(
const struct nftnl_udata *attr)
112EXPORT_SYMBOL(nftnl_udata_len);
113uint8_t nftnl_udata_len(
const struct nftnl_udata *attr)
118EXPORT_SYMBOL(nftnl_udata_get);
119void *nftnl_udata_get(
const struct nftnl_udata *attr)
121 return (
void *)attr->value;
124EXPORT_SYMBOL(nftnl_udata_get_u32);
125uint32_t nftnl_udata_get_u32(
const struct nftnl_udata *attr)
129 memcpy(&data, attr->value,
sizeof(data));
134EXPORT_SYMBOL(nftnl_udata_next);
135struct nftnl_udata *nftnl_udata_next(
const struct nftnl_udata *attr)
137 return (
struct nftnl_udata *)&attr->value[attr->len];
140EXPORT_SYMBOL(nftnl_udata_parse);
141int nftnl_udata_parse(
const void *data, uint32_t data_len, nftnl_udata_cb_t cb,
145 const struct nftnl_udata *attr;
147 nftnl_udata_for_each_data(data, data_len, attr) {
148 ret = cb(attr, cb_data);
156EXPORT_SYMBOL(nftnl_udata_nest_start);
157struct nftnl_udata *nftnl_udata_nest_start(
struct nftnl_udata_buf *buf,
160 struct nftnl_udata *ud = nftnl_udata_end(buf);
162 nftnl_udata_put(buf, type, 0, NULL);
167EXPORT_SYMBOL(nftnl_udata_nest_end);
168void nftnl_udata_nest_end(
struct nftnl_udata_buf *buf,
struct nftnl_udata *ud)
170 ud->len = buf->end - (
char *)ud->value;