11 #include <libnftnl/udata.h>
19 EXPORT_SYMBOL(nftnl_udata_buf_alloc);
20 struct 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;
33 EXPORT_SYMBOL(nftnl_udata_buf_free);
34 void nftnl_udata_buf_free(
const struct nftnl_udata_buf *buf)
39 EXPORT_SYMBOL(nftnl_udata_buf_len);
40 uint32_t nftnl_udata_buf_len(
const struct nftnl_udata_buf *buf)
42 return (uint32_t)(buf->end - buf->data);
45 EXPORT_SYMBOL(nftnl_udata_buf_data);
46 void *nftnl_udata_buf_data(
const struct nftnl_udata_buf *buf)
48 return (
void *)buf->data;
51 EXPORT_SYMBOL(nftnl_udata_buf_put);
52 void 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;
59 EXPORT_SYMBOL(nftnl_udata_start);
60 struct nftnl_udata *nftnl_udata_start(
const struct nftnl_udata_buf *buf)
62 return (
struct nftnl_udata *)buf->data;
65 EXPORT_SYMBOL(nftnl_udata_end);
66 struct nftnl_udata *nftnl_udata_end(
const struct nftnl_udata_buf *buf)
68 return (
struct nftnl_udata *)buf->end;
71 EXPORT_SYMBOL(nftnl_udata_put);
72 bool 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);
90 EXPORT_SYMBOL(nftnl_udata_put_strz);
91 bool nftnl_udata_put_strz(
struct nftnl_udata_buf *buf, uint8_t type,
94 return nftnl_udata_put(buf, type, strlen(strz) + 1, strz);
97 EXPORT_SYMBOL(nftnl_udata_put_u32);
98 bool nftnl_udata_put_u32(
struct nftnl_udata_buf *buf, uint8_t type,
101 return nftnl_udata_put(buf, type,
sizeof(data), &data);
104 EXPORT_SYMBOL(nftnl_udata_type);
105 uint8_t nftnl_udata_type(
const struct nftnl_udata *attr)
110 EXPORT_SYMBOL(nftnl_udata_len);
111 uint8_t nftnl_udata_len(
const struct nftnl_udata *attr)
116 EXPORT_SYMBOL(nftnl_udata_get);
117 void *nftnl_udata_get(
const struct nftnl_udata *attr)
119 return (
void *)attr->value;
122 EXPORT_SYMBOL(nftnl_udata_get_u32);
123 uint32_t nftnl_udata_get_u32(
const struct nftnl_udata *attr)
127 memcpy(&data, attr->value,
sizeof(data));
132 EXPORT_SYMBOL(nftnl_udata_next);
133 struct nftnl_udata *nftnl_udata_next(
const struct nftnl_udata *attr)
135 return (
struct nftnl_udata *)&attr->value[attr->len];
138 EXPORT_SYMBOL(nftnl_udata_parse);
139 int 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);