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);
45static uint32_t nftnl_udata_buf_space(
const struct nftnl_udata_buf *buf)
47 return buf->size - nftnl_udata_buf_len(buf);
50EXPORT_SYMBOL(nftnl_udata_buf_data);
51void *nftnl_udata_buf_data(
const struct nftnl_udata_buf *buf)
53 return (
void *)buf->data;
56EXPORT_SYMBOL(nftnl_udata_buf_put);
57void nftnl_udata_buf_put(
struct nftnl_udata_buf *buf,
const void *data,
60 memcpy(buf->data, data, len <= buf->size ? len : buf->size);
61 buf->end = buf->data + len;
64EXPORT_SYMBOL(nftnl_udata_start);
65struct nftnl_udata *nftnl_udata_start(
const struct nftnl_udata_buf *buf)
67 return (
struct nftnl_udata *)buf->data;
70EXPORT_SYMBOL(nftnl_udata_end);
71struct nftnl_udata *nftnl_udata_end(
const struct nftnl_udata_buf *buf)
73 return (
struct nftnl_udata *)buf->end;
76EXPORT_SYMBOL(nftnl_udata_put);
77bool nftnl_udata_put(
struct nftnl_udata_buf *buf, uint8_t type, uint32_t len,
80 struct nftnl_udata *attr;
82 if (len > UINT8_MAX ||
83 nftnl_udata_buf_space(buf) < len +
sizeof(
struct nftnl_udata))
86 attr = (
struct nftnl_udata *)buf->end;
89 memcpy(attr->value, value, len);
91 buf->end = (
char *)nftnl_udata_next(attr);
96EXPORT_SYMBOL(nftnl_udata_put_strz);
97bool nftnl_udata_put_strz(
struct nftnl_udata_buf *buf, uint8_t type,
100 return nftnl_udata_put(buf, type, strlen(strz) + 1, strz);
103EXPORT_SYMBOL(nftnl_udata_put_u32);
104bool nftnl_udata_put_u32(
struct nftnl_udata_buf *buf, uint8_t type,
107 return nftnl_udata_put(buf, type,
sizeof(data), &data);
110EXPORT_SYMBOL(nftnl_udata_type);
111uint8_t nftnl_udata_type(
const struct nftnl_udata *attr)
116EXPORT_SYMBOL(nftnl_udata_len);
117uint8_t nftnl_udata_len(
const struct nftnl_udata *attr)
122EXPORT_SYMBOL(nftnl_udata_get);
123void *nftnl_udata_get(
const struct nftnl_udata *attr)
125 return (
void *)attr->value;
128EXPORT_SYMBOL(nftnl_udata_get_u32);
129uint32_t nftnl_udata_get_u32(
const struct nftnl_udata *attr)
133 memcpy(&data, attr->value,
sizeof(data));
138EXPORT_SYMBOL(nftnl_udata_next);
139struct nftnl_udata *nftnl_udata_next(
const struct nftnl_udata *attr)
141 return (
struct nftnl_udata *)&attr->value[attr->len];
144EXPORT_SYMBOL(nftnl_udata_parse);
145int nftnl_udata_parse(
const void *data, uint32_t data_len, nftnl_udata_cb_t cb,
149 const struct nftnl_udata *attr;
151 nftnl_udata_for_each_data(data, data_len, attr) {
152 ret = cb(attr, cb_data);
160EXPORT_SYMBOL(nftnl_udata_nest_start);
161struct nftnl_udata *nftnl_udata_nest_start(
struct nftnl_udata_buf *buf,
164 struct nftnl_udata *ud = nftnl_udata_end(buf);
166 nftnl_udata_put(buf, type, 0, NULL);
171EXPORT_SYMBOL(nftnl_udata_nest_end);
172void nftnl_udata_nest_end(
struct nftnl_udata_buf *buf,
struct nftnl_udata *ud)
174 ud->len = buf->end - (
char *)ud->value;