11 #include <libnftnl/udata.h>
19 struct nftnl_udata_buf *nftnl_udata_buf_alloc(uint32_t data_size)
21 struct nftnl_udata_buf *buf;
23 buf = malloc(
sizeof(
struct nftnl_udata_buf) + data_size);
26 buf->size = data_size;
31 EXPORT_SYMBOL(nftnl_udata_buf_alloc);
33 void nftnl_udata_buf_free(
const struct nftnl_udata_buf *buf)
37 EXPORT_SYMBOL(nftnl_udata_buf_free);
39 uint32_t nftnl_udata_buf_len(
const struct nftnl_udata_buf *buf)
41 return (uint32_t)(buf->end - buf->data);
43 EXPORT_SYMBOL(nftnl_udata_buf_len);
45 void *nftnl_udata_buf_data(
const struct nftnl_udata_buf *buf)
47 return (
void *)buf->data;
49 EXPORT_SYMBOL(nftnl_udata_buf_data);
51 void nftnl_udata_buf_put(
struct nftnl_udata_buf *buf,
const void *data,
54 memcpy(buf->data, data, len <= buf->size ? len : buf->size);
55 buf->end = buf->data + len;
57 EXPORT_SYMBOL(nftnl_udata_buf_put);
59 struct nftnl_udata *nftnl_udata_start(
const struct nftnl_udata_buf *buf)
61 return (
struct nftnl_udata *)buf->data;
63 EXPORT_SYMBOL(nftnl_udata_start);
65 struct nftnl_udata *nftnl_udata_end(
const struct nftnl_udata_buf *buf)
67 return (
struct nftnl_udata *)buf->end;
69 EXPORT_SYMBOL(nftnl_udata_end);
71 bool nftnl_udata_put(
struct nftnl_udata_buf *buf, uint8_t type, uint32_t len,
74 struct nftnl_udata *attr;
76 if (buf->size < len +
sizeof(
struct nftnl_udata))
79 attr = (
struct nftnl_udata *)buf->end;
82 memcpy(attr->value, value, len);
84 buf->end = (
char *)nftnl_udata_next(attr);
88 EXPORT_SYMBOL(nftnl_udata_put);
90 bool nftnl_udata_put_strz(
struct nftnl_udata_buf *buf, uint8_t type,
93 return nftnl_udata_put(buf, type, strlen(strz) + 1, strz);
95 EXPORT_SYMBOL(nftnl_udata_put_strz);
97 uint8_t nftnl_udata_type(
const struct nftnl_udata *attr)
101 EXPORT_SYMBOL(nftnl_udata_type);
103 uint8_t nftnl_udata_len(
const struct nftnl_udata *attr)
107 EXPORT_SYMBOL(nftnl_udata_len);
109 void *nftnl_udata_get(
const struct nftnl_udata *attr)
111 return (
void *)attr->value;
113 EXPORT_SYMBOL(nftnl_udata_get);
115 struct nftnl_udata *nftnl_udata_next(
const struct nftnl_udata *attr)
117 return (
struct nftnl_udata *)&attr->value[attr->len];
119 EXPORT_SYMBOL(nftnl_udata_next);
121 int nftnl_udata_parse(
const void *data, uint32_t data_len, nftnl_udata_cb_t cb,
125 const struct nftnl_udata *attr;
127 nftnl_udata_for_each_data(data, data_len, attr) {
128 ret = cb(attr, cb_data);
135 EXPORT_SYMBOL(nftnl_udata_parse);