diff options
Diffstat (limited to 'src')
36 files changed, 3719 insertions, 3720 deletions
diff --git a/src/batch.c b/src/batch.c index 3f53218..a001288 100644 --- a/src/batch.c +++ b/src/batch.c @@ -11,25 +11,25 @@ #include <libmnl/libmnl.h> #include <libnftnl/batch.h> -struct nft_batch { +struct nftnl_batch { uint32_t num_pages; - struct nft_batch_page *current_page; + struct nftnl_batch_page *current_page; uint32_t page_size; uint32_t page_overrun_size; struct list_head page_list; }; -struct nft_batch_page { +struct nftnl_batch_page { struct list_head head; struct mnl_nlmsg_batch *batch; }; -static struct nft_batch_page *nft_batch_page_alloc(struct nft_batch *batch) +static struct nftnl_batch_page *nftnl_batch_page_alloc(struct nftnl_batch *batch) { - struct nft_batch_page *page; + struct nftnl_batch_page *page; char *buf; - page = malloc(sizeof(struct nft_batch_page)); + page = malloc(sizeof(struct nftnl_batch_page)); if (page == NULL) return NULL; @@ -49,20 +49,20 @@ err1: return NULL; } -static void nft_batch_add_page(struct nft_batch_page *page, - struct nft_batch *batch) +static void nftnl_batch_add_page(struct nftnl_batch_page *page, + struct nftnl_batch *batch) { batch->current_page = page; batch->num_pages++; list_add_tail(&page->head, &batch->page_list); } -struct nft_batch *nft_batch_alloc(uint32_t pg_size, uint32_t pg_overrun_size) +struct nftnl_batch *nftnl_batch_alloc(uint32_t pg_size, uint32_t pg_overrun_size) { - struct nft_batch *batch; - struct nft_batch_page *page; + struct nftnl_batch *batch; + struct nftnl_batch_page *page; - batch = calloc(1, sizeof(struct nft_batch)); + batch = calloc(1, sizeof(struct nftnl_batch)); if (batch == NULL) return NULL; @@ -70,11 +70,11 @@ struct nft_batch *nft_batch_alloc(uint32_t pg_size, uint32_t pg_overrun_size) batch->page_overrun_size = pg_overrun_size; INIT_LIST_HEAD(&batch->page_list); - page = nft_batch_page_alloc(batch); + page = nftnl_batch_page_alloc(batch); if (page == NULL) goto err1; - nft_batch_add_page(page, batch); + nftnl_batch_add_page(page, batch); return batch; err1: free(batch); @@ -82,9 +82,9 @@ err1: } EXPORT_SYMBOL(nftnl_batch_alloc, nft_batch_alloc); -void nft_batch_free(struct nft_batch *batch) +void nftnl_batch_free(struct nftnl_batch *batch) { - struct nft_batch_page *page, *next; + struct nftnl_batch_page *page, *next; list_for_each_entry_safe(page, next, &batch->page_list, head) { free(mnl_nlmsg_batch_head(page->batch)); @@ -96,23 +96,23 @@ void nft_batch_free(struct nft_batch *batch) } EXPORT_SYMBOL(nftnl_batch_free, nft_batch_free); -int nft_batch_update(struct nft_batch *batch) +int nftnl_batch_update(struct nftnl_batch *batch) { - struct nft_batch_page *page; + struct nftnl_batch_page *page; struct nlmsghdr *last_nlh; if (mnl_nlmsg_batch_next(batch->current_page->batch)) return 0; - last_nlh = nft_batch_buffer(batch); + last_nlh = nftnl_batch_buffer(batch); - page = nft_batch_page_alloc(batch); + page = nftnl_batch_page_alloc(batch); if (page == NULL) goto err1; - nft_batch_add_page(page, batch); + nftnl_batch_add_page(page, batch); - memcpy(nft_batch_buffer(batch), last_nlh, last_nlh->nlmsg_len); + memcpy(nftnl_batch_buffer(batch), last_nlh, last_nlh->nlmsg_len); mnl_nlmsg_batch_next(batch->current_page->batch); return 0; @@ -121,19 +121,19 @@ err1: } EXPORT_SYMBOL(nftnl_batch_update, nft_batch_update); -void *nft_batch_buffer(struct nft_batch *batch) +void *nftnl_batch_buffer(struct nftnl_batch *batch) { return mnl_nlmsg_batch_current(batch->current_page->batch); } EXPORT_SYMBOL(nftnl_batch_buffer, nft_batch_buffer); -uint32_t nft_batch_buffer_len(struct nft_batch *batch) +uint32_t nftnl_batch_buffer_len(struct nftnl_batch *batch) { return mnl_nlmsg_batch_size(batch->current_page->batch); } EXPORT_SYMBOL(nftnl_batch_buffer_len, nft_batch_buffer_len); -int nft_batch_iovec_len(struct nft_batch *batch) +int nftnl_batch_iovec_len(struct nftnl_batch *batch) { int num_pages = batch->num_pages; @@ -145,9 +145,10 @@ int nft_batch_iovec_len(struct nft_batch *batch) } EXPORT_SYMBOL(nftnl_batch_iovec_len, nft_batch_iovec_len); -void nft_batch_iovec(struct nft_batch *batch, struct iovec *iov, uint32_t iovlen) +void nftnl_batch_iovec(struct nftnl_batch *batch, struct iovec *iov, + uint32_t iovlen) { - struct nft_batch_page *page; + struct nftnl_batch_page *page; int i = 0; list_for_each_entry(page, &batch->page_list, head) { diff --git a/src/buffer.c b/src/buffer.c index 97567db..57d3c0c 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -16,7 +16,7 @@ #include <libnftnl/common.h> #include "internal.h" -int nft_buf_update(struct nft_buf *b, int ret) +int nftnl_buf_update(struct nftnl_buf *b, int ret) { if (ret < 0) { b->fail = true; @@ -31,7 +31,7 @@ int nft_buf_update(struct nft_buf *b, int ret) return ret; } -int nft_buf_done(struct nft_buf *b) +int nftnl_buf_done(struct nftnl_buf *b) { if (b->fail) return -1; @@ -46,37 +46,37 @@ int nft_buf_done(struct nft_buf *b) return b->off; } -static int nft_buf_put(struct nft_buf *b, const char *fmt, ...) +static int nftnl_buf_put(struct nftnl_buf *b, const char *fmt, ...) { int ret; va_list ap; va_start(ap, fmt); ret = vsnprintf(b->buf + b->off, b->len, fmt, ap); - ret = nft_buf_update(b, ret); + ret = nftnl_buf_update(b, ret); va_end(ap); return ret; } -int nft_buf_open(struct nft_buf *b, int type, const char *tag) +int nftnl_buf_open(struct nftnl_buf *b, int type, const char *tag) { switch (type) { - case NFT_OUTPUT_XML: - return nft_buf_put(b, "<%s>", tag); - case NFT_OUTPUT_JSON: - return nft_buf_put(b, "{\"%s\":{", tag); + case NFTNL_OUTPUT_XML: + return nftnl_buf_put(b, "<%s>", tag); + case NFTNL_OUTPUT_JSON: + return nftnl_buf_put(b, "{\"%s\":{", tag); default: return 0; } } -int nft_buf_close(struct nft_buf *b, int type, const char *tag) +int nftnl_buf_close(struct nftnl_buf *b, int type, const char *tag) { switch (type) { - case NFT_OUTPUT_XML: - return nft_buf_put(b, "</%s>", tag); - case NFT_OUTPUT_JSON: + case NFTNL_OUTPUT_XML: + return nftnl_buf_put(b, "</%s>", tag); + case NFTNL_OUTPUT_JSON: /* Remove trailing comma in json */ if (b->size > 0 && b->buf[b->size - 1] == ',') { b->off--; @@ -84,102 +84,102 @@ int nft_buf_close(struct nft_buf *b, int type, const char *tag) b->len++; } - return nft_buf_put(b, "}}"); + return nftnl_buf_put(b, "}}"); default: return 0; } } -int nft_buf_open_array(struct nft_buf *b, int type, const char *tag) +int nftnl_buf_open_array(struct nftnl_buf *b, int type, const char *tag) { switch (type) { - case NFT_OUTPUT_JSON: - return nft_buf_put(b, "{\"%s\":[", tag); - case NFT_OUTPUT_XML: - return nft_buf_put(b, "<%s>", tag); + case NFTNL_OUTPUT_JSON: + return nftnl_buf_put(b, "{\"%s\":[", tag); + case NFTNL_OUTPUT_XML: + return nftnl_buf_put(b, "<%s>", tag); default: return 0; } } -int nft_buf_close_array(struct nft_buf *b, int type, const char *tag) +int nftnl_buf_close_array(struct nftnl_buf *b, int type, const char *tag) { switch (type) { - case NFT_OUTPUT_JSON: - return nft_buf_put(b, "]}"); - case NFT_OUTPUT_XML: - return nft_buf_put(b, "</%s>", tag); + case NFTNL_OUTPUT_JSON: + return nftnl_buf_put(b, "]}"); + case NFTNL_OUTPUT_XML: + return nftnl_buf_put(b, "</%s>", tag); default: return 0; } } -int nft_buf_u32(struct nft_buf *b, int type, uint32_t value, const char *tag) +int nftnl_buf_u32(struct nftnl_buf *b, int type, uint32_t value, const char *tag) { switch (type) { - case NFT_OUTPUT_XML: - return nft_buf_put(b, "<%s>%u</%s>", tag, value, tag); - case NFT_OUTPUT_JSON: - return nft_buf_put(b, "\"%s\":%u,", tag, value); + case NFTNL_OUTPUT_XML: + return nftnl_buf_put(b, "<%s>%u</%s>", tag, value, tag); + case NFTNL_OUTPUT_JSON: + return nftnl_buf_put(b, "\"%s\":%u,", tag, value); default: return 0; } } -int nft_buf_s32(struct nft_buf *b, int type, uint32_t value, const char *tag) +int nftnl_buf_s32(struct nftnl_buf *b, int type, uint32_t value, const char *tag) { switch (type) { - case NFT_OUTPUT_XML: - return nft_buf_put(b, "<%s>%d</%s>", tag, value, tag); - case NFT_OUTPUT_JSON: - return nft_buf_put(b, "\"%s\":%d,", tag, value); + case NFTNL_OUTPUT_XML: + return nftnl_buf_put(b, "<%s>%d</%s>", tag, value, tag); + case NFTNL_OUTPUT_JSON: + return nftnl_buf_put(b, "\"%s\":%d,", tag, value); default: return 0; } } -int nft_buf_u64(struct nft_buf *b, int type, uint64_t value, const char *tag) +int nftnl_buf_u64(struct nftnl_buf *b, int type, uint64_t value, const char *tag) { switch (type) { - case NFT_OUTPUT_XML: - return nft_buf_put(b, "<%s>%"PRIu64"</%s>", tag, value, tag); - case NFT_OUTPUT_JSON: - return nft_buf_put(b, "\"%s\":%"PRIu64",", tag, value); + case NFTNL_OUTPUT_XML: + return nftnl_buf_put(b, "<%s>%"PRIu64"</%s>", tag, value, tag); + case NFTNL_OUTPUT_JSON: + return nftnl_buf_put(b, "\"%s\":%"PRIu64",", tag, value); default: return 0; } } -int nft_buf_str(struct nft_buf *b, int type, const char *str, const char *tag) +int nftnl_buf_str(struct nftnl_buf *b, int type, const char *str, const char *tag) { switch (type) { - case NFT_OUTPUT_XML: - return nft_buf_put(b, "<%s>%s</%s>", tag, str, tag); - case NFT_OUTPUT_JSON: - return nft_buf_put(b, "\"%s\":\"%s\",", tag, str); + case NFTNL_OUTPUT_XML: + return nftnl_buf_put(b, "<%s>%s</%s>", tag, str, tag); + case NFTNL_OUTPUT_JSON: + return nftnl_buf_put(b, "\"%s\":\"%s\",", tag, str); default: return 0; } } -int nft_buf_reg(struct nft_buf *b, int type, union nft_data_reg *reg, +int nftnl_buf_reg(struct nftnl_buf *b, int type, union nftnl_data_reg *reg, int reg_type, const char *tag) { int ret; switch (type) { - case NFT_OUTPUT_XML: - ret = nft_buf_put(b, "<%s>", tag); - ret = nft_data_reg_snprintf(b->buf + b->off, b->len, reg, - NFT_OUTPUT_XML, 0, reg_type); - nft_buf_update(b, ret); - return nft_buf_put(b, "</%s>", tag); - case NFT_OUTPUT_JSON: - nft_buf_put(b, "\"%s\":{", tag); - ret = nft_data_reg_snprintf(b->buf + b->off, b->len, reg, - NFT_OUTPUT_JSON, 0, reg_type); - nft_buf_update(b, ret); - return nft_buf_put(b, "},"); + case NFTNL_OUTPUT_XML: + ret = nftnl_buf_put(b, "<%s>", tag); + ret = nftnl_data_reg_snprintf(b->buf + b->off, b->len, reg, + NFTNL_OUTPUT_XML, 0, reg_type); + nftnl_buf_update(b, ret); + return nftnl_buf_put(b, "</%s>", tag); + case NFTNL_OUTPUT_JSON: + nftnl_buf_put(b, "\"%s\":{", tag); + ret = nftnl_data_reg_snprintf(b->buf + b->off, b->len, reg, + NFTNL_OUTPUT_JSON, 0, reg_type); + nftnl_buf_update(b, ret); + return nftnl_buf_put(b, "},"); } return 0; } diff --git a/src/chain.c b/src/chain.c index bb9fe90..63cb91a 100644 --- a/src/chain.c +++ b/src/chain.c @@ -29,7 +29,7 @@ #include <libnftnl/chain.h> #include <buffer.h> -struct nft_chain { +struct nftnl_chain { struct list_head head; char name[NFT_CHAIN_MAXNAMELEN]; @@ -47,7 +47,7 @@ struct nft_chain { uint32_t flags; }; -static const char *nft_hooknum2str(int family, int hooknum) +static const char *nftnl_hooknum2str(int family, int hooknum) { switch (family) { case NFPROTO_IPV4: @@ -87,13 +87,13 @@ static const char *nft_hooknum2str(int family, int hooknum) return "unknown"; } -struct nft_chain *nft_chain_alloc(void) +struct nftnl_chain *nftnl_chain_alloc(void) { - return calloc(1, sizeof(struct nft_chain)); + return calloc(1, sizeof(struct nftnl_chain)); } EXPORT_SYMBOL(nftnl_chain_alloc, nft_chain_alloc); -void nft_chain_free(struct nft_chain *c) +void nftnl_chain_free(struct nftnl_chain *c) { if (c->table != NULL) xfree(c->table); @@ -106,42 +106,42 @@ void nft_chain_free(struct nft_chain *c) } EXPORT_SYMBOL(nftnl_chain_free, nft_chain_free); -bool nft_chain_attr_is_set(const struct nft_chain *c, uint16_t attr) +bool nftnl_chain_attr_is_set(const struct nftnl_chain *c, uint16_t attr) { return c->flags & (1 << attr); } EXPORT_SYMBOL(nftnl_chain_attr_is_set, nft_chain_attr_is_set); -void nft_chain_attr_unset(struct nft_chain *c, uint16_t attr) +void nftnl_chain_attr_unset(struct nftnl_chain *c, uint16_t attr) { if (!(c->flags & (1 << attr))) return; switch (attr) { - case NFT_CHAIN_ATTR_TABLE: + case NFTNL_CHAIN_ATTR_TABLE: if (c->table) { xfree(c->table); c->table = NULL; } break; - case NFT_CHAIN_ATTR_USE: + case NFTNL_CHAIN_ATTR_USE: break; - case NFT_CHAIN_ATTR_TYPE: + case NFTNL_CHAIN_ATTR_TYPE: if (c->type) { xfree(c->type); c->type = NULL; } break; - case NFT_CHAIN_ATTR_NAME: - case NFT_CHAIN_ATTR_HOOKNUM: - case NFT_CHAIN_ATTR_PRIO: - case NFT_CHAIN_ATTR_POLICY: - case NFT_CHAIN_ATTR_BYTES: - case NFT_CHAIN_ATTR_PACKETS: - case NFT_CHAIN_ATTR_HANDLE: - case NFT_CHAIN_ATTR_FAMILY: + case NFTNL_CHAIN_ATTR_NAME: + case NFTNL_CHAIN_ATTR_HOOKNUM: + case NFTNL_CHAIN_ATTR_PRIO: + case NFTNL_CHAIN_ATTR_POLICY: + case NFTNL_CHAIN_ATTR_BYTES: + case NFTNL_CHAIN_ATTR_PACKETS: + case NFTNL_CHAIN_ATTR_HANDLE: + case NFTNL_CHAIN_ATTR_FAMILY: break; - case NFT_CHAIN_ATTR_DEV: + case NFTNL_CHAIN_ATTR_DEV: if (c->dev) { xfree(c->dev); c->dev = NULL; @@ -155,65 +155,65 @@ void nft_chain_attr_unset(struct nft_chain *c, uint16_t attr) } EXPORT_SYMBOL(nftnl_chain_attr_unset, nft_chain_attr_unset); -static uint32_t nft_chain_attr_validate[NFT_CHAIN_ATTR_MAX + 1] = { - [NFT_CHAIN_ATTR_HOOKNUM] = sizeof(uint32_t), - [NFT_CHAIN_ATTR_PRIO] = sizeof(int32_t), - [NFT_CHAIN_ATTR_POLICY] = sizeof(uint32_t), - [NFT_CHAIN_ATTR_BYTES] = sizeof(uint64_t), - [NFT_CHAIN_ATTR_PACKETS] = sizeof(uint64_t), - [NFT_CHAIN_ATTR_HANDLE] = sizeof(uint64_t), - [NFT_CHAIN_ATTR_FAMILY] = sizeof(uint32_t), +static uint32_t nftnl_chain_attr_validate[NFTNL_CHAIN_ATTR_MAX + 1] = { + [NFTNL_CHAIN_ATTR_HOOKNUM] = sizeof(uint32_t), + [NFTNL_CHAIN_ATTR_PRIO] = sizeof(int32_t), + [NFTNL_CHAIN_ATTR_POLICY] = sizeof(uint32_t), + [NFTNL_CHAIN_ATTR_BYTES] = sizeof(uint64_t), + [NFTNL_CHAIN_ATTR_PACKETS] = sizeof(uint64_t), + [NFTNL_CHAIN_ATTR_HANDLE] = sizeof(uint64_t), + [NFTNL_CHAIN_ATTR_FAMILY] = sizeof(uint32_t), }; -void nft_chain_attr_set_data(struct nft_chain *c, uint16_t attr, +void nftnl_chain_attr_set_data(struct nftnl_chain *c, uint16_t attr, const void *data, uint32_t data_len) { - if (attr > NFT_CHAIN_ATTR_MAX) + if (attr > NFTNL_CHAIN_ATTR_MAX) return; - nft_assert_validate(data, nft_chain_attr_validate, attr, data_len); + nftnl_assert_validate(data, nftnl_chain_attr_validate, attr, data_len); switch(attr) { - case NFT_CHAIN_ATTR_NAME: + case NFTNL_CHAIN_ATTR_NAME: strncpy(c->name, data, NFT_CHAIN_MAXNAMELEN); break; - case NFT_CHAIN_ATTR_TABLE: + case NFTNL_CHAIN_ATTR_TABLE: if (c->table) xfree(c->table); c->table = strdup(data); break; - case NFT_CHAIN_ATTR_HOOKNUM: + case NFTNL_CHAIN_ATTR_HOOKNUM: memcpy(&c->hooknum, data, sizeof(c->hooknum)); break; - case NFT_CHAIN_ATTR_PRIO: + case NFTNL_CHAIN_ATTR_PRIO: memcpy(&c->prio, data, sizeof(c->prio)); break; - case NFT_CHAIN_ATTR_POLICY: + case NFTNL_CHAIN_ATTR_POLICY: c->policy = *((uint32_t *)data); break; - case NFT_CHAIN_ATTR_USE: + case NFTNL_CHAIN_ATTR_USE: c->use = *((uint32_t *)data); break; - case NFT_CHAIN_ATTR_BYTES: + case NFTNL_CHAIN_ATTR_BYTES: c->bytes = *((uint64_t *)data); break; - case NFT_CHAIN_ATTR_PACKETS: + case NFTNL_CHAIN_ATTR_PACKETS: c->packets = *((uint64_t *)data); break; - case NFT_CHAIN_ATTR_HANDLE: + case NFTNL_CHAIN_ATTR_HANDLE: c->handle = *((uint64_t *)data); break; - case NFT_CHAIN_ATTR_FAMILY: + case NFTNL_CHAIN_ATTR_FAMILY: c->family = *((uint32_t *)data); break; - case NFT_CHAIN_ATTR_TYPE: + case NFTNL_CHAIN_ATTR_TYPE: if (c->type) xfree(c->type); c->type = strdup(data); break; - case NFT_CHAIN_ATTR_DEV: + case NFTNL_CHAIN_ATTR_DEV: if (c->dev) xfree(c->dev); @@ -224,167 +224,167 @@ void nft_chain_attr_set_data(struct nft_chain *c, uint16_t attr, } EXPORT_SYMBOL(nftnl_chain_attr_set_data, nft_chain_attr_set_data); -void nft_chain_attr_set(struct nft_chain *c, uint16_t attr, const void *data) +void nftnl_chain_attr_set(struct nftnl_chain *c, uint16_t attr, const void *data) { - nft_chain_attr_set_data(c, attr, data, nft_chain_attr_validate[attr]); + nftnl_chain_attr_set_data(c, attr, data, nftnl_chain_attr_validate[attr]); } EXPORT_SYMBOL(nftnl_chain_attr_set, nft_chain_attr_set); -void nft_chain_attr_set_u32(struct nft_chain *c, uint16_t attr, uint32_t data) +void nftnl_chain_attr_set_u32(struct nftnl_chain *c, uint16_t attr, uint32_t data) { - nft_chain_attr_set_data(c, attr, &data, sizeof(uint32_t)); + nftnl_chain_attr_set_data(c, attr, &data, sizeof(uint32_t)); } EXPORT_SYMBOL(nftnl_chain_attr_set_u32, nft_chain_attr_set_u32); -void nft_chain_attr_set_s32(struct nft_chain *c, uint16_t attr, int32_t data) +void nftnl_chain_attr_set_s32(struct nftnl_chain *c, uint16_t attr, int32_t data) { - nft_chain_attr_set_data(c, attr, &data, sizeof(int32_t)); + nftnl_chain_attr_set_data(c, attr, &data, sizeof(int32_t)); } EXPORT_SYMBOL(nftnl_chain_attr_set_s32, nft_chain_attr_set_s32); -void nft_chain_attr_set_u64(struct nft_chain *c, uint16_t attr, uint64_t data) +void nftnl_chain_attr_set_u64(struct nftnl_chain *c, uint16_t attr, uint64_t data) { - nft_chain_attr_set_data(c, attr, &data, sizeof(uint64_t)); + nftnl_chain_attr_set_data(c, attr, &data, sizeof(uint64_t)); } EXPORT_SYMBOL(nftnl_chain_attr_set_u64, nft_chain_attr_set_u64); -void nft_chain_attr_set_u8(struct nft_chain *c, uint16_t attr, uint8_t data) +void nftnl_chain_attr_set_u8(struct nftnl_chain *c, uint16_t attr, uint8_t data) { - nft_chain_attr_set_data(c, attr, &data, sizeof(uint8_t)); + nftnl_chain_attr_set_data(c, attr, &data, sizeof(uint8_t)); } EXPORT_SYMBOL(nftnl_chain_attr_set_u8, nft_chain_attr_set_u8); -void nft_chain_attr_set_str(struct nft_chain *c, uint16_t attr, const char *str) +void nftnl_chain_attr_set_str(struct nftnl_chain *c, uint16_t attr, const char *str) { - nft_chain_attr_set_data(c, attr, str, strlen(str)); + nftnl_chain_attr_set_data(c, attr, str, strlen(str)); } EXPORT_SYMBOL(nftnl_chain_attr_set_str, nft_chain_attr_set_str); -const void *nft_chain_attr_get_data(struct nft_chain *c, uint16_t attr, +const void *nftnl_chain_attr_get_data(struct nftnl_chain *c, uint16_t attr, uint32_t *data_len) { if (!(c->flags & (1 << attr))) return NULL; switch(attr) { - case NFT_CHAIN_ATTR_NAME: + case NFTNL_CHAIN_ATTR_NAME: return c->name; - case NFT_CHAIN_ATTR_TABLE: + case NFTNL_CHAIN_ATTR_TABLE: return c->table; - case NFT_CHAIN_ATTR_HOOKNUM: + case NFTNL_CHAIN_ATTR_HOOKNUM: *data_len = sizeof(uint32_t); return &c->hooknum; - case NFT_CHAIN_ATTR_PRIO: + case NFTNL_CHAIN_ATTR_PRIO: *data_len = sizeof(int32_t); return &c->prio; - case NFT_CHAIN_ATTR_POLICY: + case NFTNL_CHAIN_ATTR_POLICY: *data_len = sizeof(uint32_t); return &c->policy; - case NFT_CHAIN_ATTR_USE: + case NFTNL_CHAIN_ATTR_USE: *data_len = sizeof(uint32_t); return &c->use; - case NFT_CHAIN_ATTR_BYTES: + case NFTNL_CHAIN_ATTR_BYTES: *data_len = sizeof(uint64_t); return &c->bytes; - case NFT_CHAIN_ATTR_PACKETS: + case NFTNL_CHAIN_ATTR_PACKETS: *data_len = sizeof(uint64_t); return &c->packets; - case NFT_CHAIN_ATTR_HANDLE: + case NFTNL_CHAIN_ATTR_HANDLE: *data_len = sizeof(uint64_t); return &c->handle; - case NFT_CHAIN_ATTR_FAMILY: + case NFTNL_CHAIN_ATTR_FAMILY: *data_len = sizeof(uint32_t); return &c->family; - case NFT_CHAIN_ATTR_TYPE: + case NFTNL_CHAIN_ATTR_TYPE: *data_len = sizeof(uint32_t); return c->type; - case NFT_CHAIN_ATTR_DEV: + case NFTNL_CHAIN_ATTR_DEV: return c->dev; } return NULL; } EXPORT_SYMBOL(nftnl_chain_attr_get_data, nft_chain_attr_get_data); -const void *nft_chain_attr_get(struct nft_chain *c, uint16_t attr) +const void *nftnl_chain_attr_get(struct nftnl_chain *c, uint16_t attr) { uint32_t data_len; - return nft_chain_attr_get_data(c, attr, &data_len); + return nftnl_chain_attr_get_data(c, attr, &data_len); } EXPORT_SYMBOL(nftnl_chain_attr_get, nft_chain_attr_get); -const char *nft_chain_attr_get_str(struct nft_chain *c, uint16_t attr) +const char *nftnl_chain_attr_get_str(struct nftnl_chain *c, uint16_t attr) { - return nft_chain_attr_get(c, attr); + return nftnl_chain_attr_get(c, attr); } EXPORT_SYMBOL(nftnl_chain_attr_get_str, nft_chain_attr_get_str); -uint32_t nft_chain_attr_get_u32(struct nft_chain *c, uint16_t attr) +uint32_t nftnl_chain_attr_get_u32(struct nftnl_chain *c, uint16_t attr) { uint32_t data_len; - const uint32_t *val = nft_chain_attr_get_data(c, attr, &data_len); + const uint32_t *val = nftnl_chain_attr_get_data(c, attr, &data_len); - nft_assert(val, attr, data_len == sizeof(uint32_t)); + nftnl_assert(val, attr, data_len == sizeof(uint32_t)); return val ? *val : 0; } EXPORT_SYMBOL(nftnl_chain_attr_get_u32, nft_chain_attr_get_u32); -int32_t nft_chain_attr_get_s32(struct nft_chain *c, uint16_t attr) +int32_t nftnl_chain_attr_get_s32(struct nftnl_chain *c, uint16_t attr) { uint32_t data_len; - const int32_t *val = nft_chain_attr_get_data(c, attr, &data_len); + const int32_t *val = nftnl_chain_attr_get_data(c, attr, &data_len); - nft_assert(val, attr, data_len == sizeof(int32_t)); + nftnl_assert(val, attr, data_len == sizeof(int32_t)); return val ? *val : 0; } EXPORT_SYMBOL(nftnl_chain_attr_get_s32, nft_chain_attr_get_s32); -uint64_t nft_chain_attr_get_u64(struct nft_chain *c, uint16_t attr) +uint64_t nftnl_chain_attr_get_u64(struct nftnl_chain *c, uint16_t attr) { uint32_t data_len; - const uint64_t *val = nft_chain_attr_get_data(c, attr, &data_len); + const uint64_t *val = nftnl_chain_attr_get_data(c, attr, &data_len); - nft_assert(val, attr, data_len == sizeof(int64_t)); + nftnl_assert(val, attr, data_len == sizeof(int64_t)); return val ? *val : 0; } EXPORT_SYMBOL(nftnl_chain_attr_get_u64, nft_chain_attr_get_u64); -uint8_t nft_chain_attr_get_u8(struct nft_chain *c, uint16_t attr) +uint8_t nftnl_chain_attr_get_u8(struct nftnl_chain *c, uint16_t attr) { uint32_t data_len; - const uint8_t *val = nft_chain_attr_get_data(c, attr, &data_len); + const uint8_t *val = nftnl_chain_attr_get_data(c, attr, &data_len); - nft_assert(val, attr, data_len == sizeof(int8_t)); + nftnl_assert(val, attr, data_len == sizeof(int8_t)); return val ? *val : 0; } EXPORT_SYMBOL(nftnl_chain_attr_get_u8, nft_chain_attr_get_u8); -void nft_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_chain *c) +void nftnl_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nftnl_chain *c) { - if (c->flags & (1 << NFT_CHAIN_ATTR_TABLE)) + if (c->flags & (1 << NFTNL_CHAIN_ATTR_TABLE)) mnl_attr_put_strz(nlh, NFTA_CHAIN_TABLE, c->table); - if (c->flags & (1 << NFT_CHAIN_ATTR_NAME)) + if (c->flags & (1 << NFTNL_CHAIN_ATTR_NAME)) mnl_attr_put_strz(nlh, NFTA_CHAIN_NAME, c->name); - if ((c->flags & (1 << NFT_CHAIN_ATTR_HOOKNUM)) && - (c->flags & (1 << NFT_CHAIN_ATTR_PRIO))) { + if ((c->flags & (1 << NFTNL_CHAIN_ATTR_HOOKNUM)) && + (c->flags & (1 << NFTNL_CHAIN_ATTR_PRIO))) { struct nlattr *nest; nest = mnl_attr_nest_start(nlh, NFTA_CHAIN_HOOK); mnl_attr_put_u32(nlh, NFTA_HOOK_HOOKNUM, htonl(c->hooknum)); mnl_attr_put_u32(nlh, NFTA_HOOK_PRIORITY, htonl(c->prio)); - if (c->flags & (1 << NFT_CHAIN_ATTR_DEV)) + if (c->flags & (1 << NFTNL_CHAIN_ATTR_DEV)) mnl_attr_put_strz(nlh, NFTA_HOOK_DEV, c->dev); mnl_attr_nest_end(nlh, nest); } - if (c->flags & (1 << NFT_CHAIN_ATTR_POLICY)) + if (c->flags & (1 << NFTNL_CHAIN_ATTR_POLICY)) mnl_attr_put_u32(nlh, NFTA_CHAIN_POLICY, htonl(c->policy)); - if (c->flags & (1 << NFT_CHAIN_ATTR_USE)) + if (c->flags & (1 << NFTNL_CHAIN_ATTR_USE)) mnl_attr_put_u32(nlh, NFTA_CHAIN_USE, htonl(c->use)); - if ((c->flags & (1 << NFT_CHAIN_ATTR_PACKETS)) && - (c->flags & (1 << NFT_CHAIN_ATTR_BYTES))) { + if ((c->flags & (1 << NFTNL_CHAIN_ATTR_PACKETS)) && + (c->flags & (1 << NFTNL_CHAIN_ATTR_BYTES))) { struct nlattr *nest; nest = mnl_attr_nest_start(nlh, NFTA_CHAIN_COUNTERS); @@ -392,14 +392,14 @@ void nft_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_chain mnl_attr_put_u64(nlh, NFTA_COUNTER_BYTES, be64toh(c->bytes)); mnl_attr_nest_end(nlh, nest); } - if (c->flags & (1 << NFT_CHAIN_ATTR_HANDLE)) + if (c->flags & (1 << NFTNL_CHAIN_ATTR_HANDLE)) mnl_attr_put_u64(nlh, NFTA_CHAIN_HANDLE, be64toh(c->handle)); - if (c->flags & (1 << NFT_CHAIN_ATTR_TYPE)) + if (c->flags & (1 << NFTNL_CHAIN_ATTR_TYPE)) mnl_attr_put_strz(nlh, NFTA_CHAIN_TYPE, c->type); } EXPORT_SYMBOL(nftnl_chain_nlmsg_build_payload, nft_chain_nlmsg_build_payload); -static int nft_chain_parse_attr_cb(const struct nlattr *attr, void *data) +static int nftnl_chain_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -434,7 +434,7 @@ static int nft_chain_parse_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_chain_parse_counters_cb(const struct nlattr *attr, void *data) +static int nftnl_chain_parse_counters_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -454,25 +454,26 @@ static int nft_chain_parse_counters_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_chain_parse_counters(struct nlattr *attr, struct nft_chain *c) +static int nftnl_chain_parse_counters(struct nlattr *attr, struct nftnl_chain *c) { struct nlattr *tb[NFTA_COUNTER_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_chain_parse_counters_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_chain_parse_counters_cb, tb) < 0) return -1; if (tb[NFTA_COUNTER_PACKETS]) { c->packets = be64toh(mnl_attr_get_u64(tb[NFTA_COUNTER_PACKETS])); - c->flags |= (1 << NFT_CHAIN_ATTR_PACKETS); + c->flags |= (1 << NFTNL_CHAIN_ATTR_PACKETS); } if (tb[NFTA_COUNTER_BYTES]) { c->bytes = be64toh(mnl_attr_get_u64(tb[NFTA_COUNTER_BYTES])); - c->flags |= (1 << NFT_CHAIN_ATTR_BYTES); + c->flags |= (1 << NFTNL_CHAIN_ATTR_BYTES); } return 0; } -static int nft_chain_parse_hook_cb(const struct nlattr *attr, void *data) + +static int nftnl_chain_parse_hook_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -496,97 +497,97 @@ static int nft_chain_parse_hook_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_chain_parse_hook(struct nlattr *attr, struct nft_chain *c) +static int nftnl_chain_parse_hook(struct nlattr *attr, struct nftnl_chain *c) { struct nlattr *tb[NFTA_HOOK_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_chain_parse_hook_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_chain_parse_hook_cb, tb) < 0) return -1; if (tb[NFTA_HOOK_HOOKNUM]) { c->hooknum = ntohl(mnl_attr_get_u32(tb[NFTA_HOOK_HOOKNUM])); - c->flags |= (1 << NFT_CHAIN_ATTR_HOOKNUM); + c->flags |= (1 << NFTNL_CHAIN_ATTR_HOOKNUM); } if (tb[NFTA_HOOK_PRIORITY]) { c->prio = ntohl(mnl_attr_get_u32(tb[NFTA_HOOK_PRIORITY])); - c->flags |= (1 << NFT_CHAIN_ATTR_PRIO); + c->flags |= (1 << NFTNL_CHAIN_ATTR_PRIO); } if (tb[NFTA_HOOK_DEV]) { c->dev = strdup(mnl_attr_get_str(tb[NFTA_HOOK_DEV])); - c->flags |= (1 << NFT_CHAIN_ATTR_DEV); + c->flags |= (1 << NFTNL_CHAIN_ATTR_DEV); } return 0; } -int nft_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_chain *c) +int nftnl_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_chain *c) { struct nlattr *tb[NFTA_CHAIN_MAX+1] = {}; struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh); int ret = 0; - if (mnl_attr_parse(nlh, sizeof(*nfg), nft_chain_parse_attr_cb, tb) < 0) + if (mnl_attr_parse(nlh, sizeof(*nfg), nftnl_chain_parse_attr_cb, tb) < 0) return -1; if (tb[NFTA_CHAIN_NAME]) { strncpy(c->name, mnl_attr_get_str(tb[NFTA_CHAIN_NAME]), NFT_CHAIN_MAXNAMELEN); - c->flags |= (1 << NFT_CHAIN_ATTR_NAME); + c->flags |= (1 << NFTNL_CHAIN_ATTR_NAME); } if (tb[NFTA_CHAIN_TABLE]) { xfree(c->table); c->table = strdup(mnl_attr_get_str(tb[NFTA_CHAIN_TABLE])); - c->flags |= (1 << NFT_CHAIN_ATTR_TABLE); + c->flags |= (1 << NFTNL_CHAIN_ATTR_TABLE); } if (tb[NFTA_CHAIN_HOOK]) { - ret = nft_chain_parse_hook(tb[NFTA_CHAIN_HOOK], c); + ret = nftnl_chain_parse_hook(tb[NFTA_CHAIN_HOOK], c); if (ret < 0) return ret; } if (tb[NFTA_CHAIN_POLICY]) { c->policy = ntohl(mnl_attr_get_u32(tb[NFTA_CHAIN_POLICY])); - c->flags |= (1 << NFT_CHAIN_ATTR_POLICY); + c->flags |= (1 << NFTNL_CHAIN_ATTR_POLICY); } if (tb[NFTA_CHAIN_USE]) { c->use = ntohl(mnl_attr_get_u32(tb[NFTA_CHAIN_USE])); - c->flags |= (1 << NFT_CHAIN_ATTR_USE); + c->flags |= (1 << NFTNL_CHAIN_ATTR_USE); } if (tb[NFTA_CHAIN_COUNTERS]) { - ret = nft_chain_parse_counters(tb[NFTA_CHAIN_COUNTERS], c); + ret = nftnl_chain_parse_counters(tb[NFTA_CHAIN_COUNTERS], c); if (ret < 0) return ret; } if (tb[NFTA_CHAIN_HANDLE]) { c->handle = be64toh(mnl_attr_get_u64(tb[NFTA_CHAIN_HANDLE])); - c->flags |= (1 << NFT_CHAIN_ATTR_HANDLE); + c->flags |= (1 << NFTNL_CHAIN_ATTR_HANDLE); } if (tb[NFTA_CHAIN_TYPE]) { xfree(c->type); c->type = strdup(mnl_attr_get_str(tb[NFTA_CHAIN_TYPE])); - c->flags |= (1 << NFT_CHAIN_ATTR_TYPE); + c->flags |= (1 << NFTNL_CHAIN_ATTR_TYPE); } c->family = nfg->nfgen_family; - c->flags |= (1 << NFT_CHAIN_ATTR_FAMILY); + c->flags |= (1 << NFTNL_CHAIN_ATTR_FAMILY); return ret; } EXPORT_SYMBOL(nftnl_chain_nlmsg_parse, nft_chain_nlmsg_parse); -static inline int nft_str2hooknum(int family, const char *hook) +static inline int nftnl_str2hooknum(int family, const char *hook) { int hooknum; for (hooknum = 0; hooknum < NF_INET_NUMHOOKS; hooknum++) { - if (strcmp(hook, nft_hooknum2str(family, hooknum)) == 0) + if (strcmp(hook, nftnl_hooknum2str(family, hooknum)) == 0) return hooknum; } return -1; } #ifdef JSON_PARSING -int nft_jansson_parse_chain(struct nft_chain *c, json_t *tree, - struct nft_parse_err *err) +int nftnl_jansson_parse_chain(struct nftnl_chain *c, json_t *tree, + struct nftnl_parse_err *err) { json_t *root; uint64_t handle, bytes, packets; @@ -594,93 +595,93 @@ int nft_jansson_parse_chain(struct nft_chain *c, json_t *tree, int32_t family, prio, hooknum, use; const char *name, *table, *type, *hooknum_str, *policy, *dev; - root = nft_jansson_get_node(tree, "chain", err); + root = nftnl_jansson_get_node(tree, "chain", err); if (root == NULL) return -1; - name = nft_jansson_parse_str(root, "name", err); + name = nftnl_jansson_parse_str(root, "name", err); if (name != NULL) - nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_NAME, name); + nftnl_chain_attr_set_str(c, NFTNL_CHAIN_ATTR_NAME, name); - if (nft_jansson_parse_val(root, "handle", NFT_TYPE_U64, &handle, + if (nftnl_jansson_parse_val(root, "handle", NFTNL_TYPE_U64, &handle, err) == 0) - nft_chain_attr_set_u64(c,NFT_CHAIN_ATTR_HANDLE, handle); + nftnl_chain_attr_set_u64(c,NFTNL_CHAIN_ATTR_HANDLE, handle); - if (nft_jansson_parse_val(root, "bytes", NFT_TYPE_U64, &bytes, + if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &bytes, err) == 0) - nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_BYTES, bytes); + nftnl_chain_attr_set_u64(c, NFTNL_CHAIN_ATTR_BYTES, bytes); - if (nft_jansson_parse_val(root, "packets", NFT_TYPE_U64, &packets, + if (nftnl_jansson_parse_val(root, "packets", NFTNL_TYPE_U64, &packets, err) == 0) - nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_PACKETS, packets); + nftnl_chain_attr_set_u64(c, NFTNL_CHAIN_ATTR_PACKETS, packets); - if (nft_jansson_parse_family(root, &family, err) == 0) - nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_FAMILY, family); + if (nftnl_jansson_parse_family(root, &family, err) == 0) + nftnl_chain_attr_set_u32(c, NFTNL_CHAIN_ATTR_FAMILY, family); - table = nft_jansson_parse_str(root, "table", err); + table = nftnl_jansson_parse_str(root, "table", err); if (table != NULL) - nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_TABLE, table); + nftnl_chain_attr_set_str(c, NFTNL_CHAIN_ATTR_TABLE, table); - if (nft_jansson_parse_val(root, "use", NFT_TYPE_U32, &use, err) == 0) - nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_USE, use); + if (nftnl_jansson_parse_val(root, "use", NFTNL_TYPE_U32, &use, err) == 0) + nftnl_chain_attr_set_u32(c, NFTNL_CHAIN_ATTR_USE, use); - if (nft_jansson_node_exist(root, "hooknum")) { - type = nft_jansson_parse_str(root, "type", err); + if (nftnl_jansson_node_exist(root, "hooknum")) { + type = nftnl_jansson_parse_str(root, "type", err); if (type != NULL) - nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_TYPE, type); + nftnl_chain_attr_set_str(c, NFTNL_CHAIN_ATTR_TYPE, type); - if (nft_jansson_parse_val(root, "prio", NFT_TYPE_S32, + if (nftnl_jansson_parse_val(root, "prio", NFTNL_TYPE_S32, &prio, err) == 0) - nft_chain_attr_set_s32(c, NFT_CHAIN_ATTR_PRIO, prio); + nftnl_chain_attr_set_s32(c, NFTNL_CHAIN_ATTR_PRIO, prio); - hooknum_str = nft_jansson_parse_str(root, "hooknum", err); + hooknum_str = nftnl_jansson_parse_str(root, "hooknum", err); if (hooknum_str != NULL) { - hooknum = nft_str2hooknum(c->family, hooknum_str); + hooknum = nftnl_str2hooknum(c->family, hooknum_str); if (hooknum == -1) return -1; - nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_HOOKNUM, + nftnl_chain_attr_set_u32(c, NFTNL_CHAIN_ATTR_HOOKNUM, hooknum); } - policy = nft_jansson_parse_str(root, "policy", err); + policy = nftnl_jansson_parse_str(root, "policy", err); if (policy != NULL) { - if (nft_str2verdict(policy, &policy_num) != 0) { + if (nftnl_str2verdict(policy, &policy_num) != 0) { errno = EINVAL; err->node_name = "policy"; - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; return -1; } - nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_POLICY, + nftnl_chain_attr_set_u32(c, NFTNL_CHAIN_ATTR_POLICY, policy_num); } - dev = nft_jansson_parse_str(root, "device", err); + dev = nftnl_jansson_parse_str(root, "device", err); if (dev != NULL) - nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_DEV, dev); + nftnl_chain_attr_set_str(c, NFTNL_CHAIN_ATTR_DEV, dev); } return 0; } #endif -static int nft_chain_json_parse(struct nft_chain *c, const void *json, - struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_chain_json_parse(struct nftnl_chain *c, const void *json, + struct nftnl_parse_err *err, + enum nftnl_parse_input input) { #ifdef JSON_PARSING json_t *tree; json_error_t error; int ret; - tree = nft_jansson_create_root(json, &error, err, input); + tree = nftnl_jansson_create_root(json, &error, err, input); if (tree == NULL) return -1; - ret = nft_jansson_parse_chain(c, tree, err); + ret = nftnl_jansson_parse_chain(c, tree, err); - nft_jansson_free_root(tree); + nftnl_jansson_free_root(tree); return ret; #else @@ -690,100 +691,100 @@ static int nft_chain_json_parse(struct nft_chain *c, const void *json, } #ifdef XML_PARSING -int nft_mxml_chain_parse(mxml_node_t *tree, struct nft_chain *c, - struct nft_parse_err *err) +int nftnl_mxml_chain_parse(mxml_node_t *tree, struct nftnl_chain *c, + struct nftnl_parse_err *err) { const char *table, *name, *hooknum_str, *policy_str, *type, *dev; int family, hooknum, policy; uint64_t handle, bytes, packets, prio, use; - name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + name = nftnl_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (name != NULL) - nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_NAME, name); + nftnl_chain_attr_set_str(c, NFTNL_CHAIN_ATTR_NAME, name); - if (nft_mxml_num_parse(tree, "handle", MXML_DESCEND_FIRST, BASE_DEC, - &handle, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_HANDLE, handle); + if (nftnl_mxml_num_parse(tree, "handle", MXML_DESCEND_FIRST, BASE_DEC, + &handle, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_chain_attr_set_u64(c, NFTNL_CHAIN_ATTR_HANDLE, handle); - if (nft_mxml_num_parse(tree, "bytes", MXML_DESCEND_FIRST, BASE_DEC, - &bytes, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_BYTES, bytes); + if (nftnl_mxml_num_parse(tree, "bytes", MXML_DESCEND_FIRST, BASE_DEC, + &bytes, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_chain_attr_set_u64(c, NFTNL_CHAIN_ATTR_BYTES, bytes); - if (nft_mxml_num_parse(tree, "packets", MXML_DESCEND_FIRST, BASE_DEC, - &packets, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_PACKETS, packets); + if (nftnl_mxml_num_parse(tree, "packets", MXML_DESCEND_FIRST, BASE_DEC, + &packets, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_chain_attr_set_u64(c, NFTNL_CHAIN_ATTR_PACKETS, packets); - table = nft_mxml_str_parse(tree, "table", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + table = nftnl_mxml_str_parse(tree, "table", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (table != NULL) - nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_TABLE, table); + nftnl_chain_attr_set_str(c, NFTNL_CHAIN_ATTR_TABLE, table); - if (nft_mxml_num_parse(tree, "use", MXML_DESCEND_FIRST, BASE_DEC, - &use, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_PACKETS, use); + if (nftnl_mxml_num_parse(tree, "use", MXML_DESCEND_FIRST, BASE_DEC, + &use, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_chain_attr_set_u64(c, NFTNL_CHAIN_ATTR_PACKETS, use); - family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + family = nftnl_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (family >= 0) - nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_FAMILY, family); + nftnl_chain_attr_set_u32(c, NFTNL_CHAIN_ATTR_FAMILY, family); - hooknum_str = nft_mxml_str_parse(tree, "hooknum", MXML_DESCEND_FIRST, - NFT_XML_OPT, err); + hooknum_str = nftnl_mxml_str_parse(tree, "hooknum", MXML_DESCEND_FIRST, + NFTNL_XML_OPT, err); if (hooknum_str != NULL) { - hooknum = nft_str2hooknum(c->family, hooknum_str); + hooknum = nftnl_str2hooknum(c->family, hooknum_str); if (hooknum < 0) return -1; - nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_HOOKNUM, hooknum); + nftnl_chain_attr_set_u32(c, NFTNL_CHAIN_ATTR_HOOKNUM, hooknum); - type = nft_mxml_str_parse(tree, "type", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + type = nftnl_mxml_str_parse(tree, "type", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (type != NULL) - nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_TYPE, type); + nftnl_chain_attr_set_str(c, NFTNL_CHAIN_ATTR_TYPE, type); - if (nft_mxml_num_parse(tree, "prio", MXML_DESCEND, BASE_DEC, - &prio, NFT_TYPE_S32, NFT_XML_MAND, + if (nftnl_mxml_num_parse(tree, "prio", MXML_DESCEND, BASE_DEC, + &prio, NFTNL_TYPE_S32, NFTNL_XML_MAND, err) == 0) - nft_chain_attr_set_s32(c, NFT_CHAIN_ATTR_PRIO, prio); + nftnl_chain_attr_set_s32(c, NFTNL_CHAIN_ATTR_PRIO, prio); - policy_str = nft_mxml_str_parse(tree, "policy", + policy_str = nftnl_mxml_str_parse(tree, "policy", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + NFTNL_XML_MAND, err); if (policy_str != NULL) { - if (nft_str2verdict(policy_str, &policy) != 0) { + if (nftnl_str2verdict(policy_str, &policy) != 0) { errno = EINVAL; err->node_name = "policy"; - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; return -1; } - nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_POLICY, + nftnl_chain_attr_set_u32(c, NFTNL_CHAIN_ATTR_POLICY, policy); } - dev = nft_mxml_str_parse(tree, "device", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + dev = nftnl_mxml_str_parse(tree, "device", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (table != NULL) - nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_DEV, dev); + nftnl_chain_attr_set_str(c, NFTNL_CHAIN_ATTR_DEV, dev); } return 0; } #endif -static int nft_chain_xml_parse(struct nft_chain *c, const void *xml, - struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_chain_xml_parse(struct nftnl_chain *c, const void *xml, + struct nftnl_parse_err *err, + enum nftnl_parse_input input) { #ifdef XML_PARSING int ret; - mxml_node_t *tree = nft_mxml_build_tree(xml, "chain", err, input); + mxml_node_t *tree = nftnl_mxml_build_tree(xml, "chain", err, input); if (tree == NULL) return -1; - ret = nft_mxml_chain_parse(tree, c, err); + ret = nftnl_mxml_chain_parse(tree, c, err); mxmlDelete(tree); return ret; #else @@ -792,19 +793,19 @@ static int nft_chain_xml_parse(struct nft_chain *c, const void *xml, #endif } -static int nft_chain_do_parse(struct nft_chain *c, enum nft_parse_type type, - const void *data, struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_chain_do_parse(struct nftnl_chain *c, enum nftnl_parse_type type, + const void *data, struct nftnl_parse_err *err, + enum nftnl_parse_input input) { int ret; - struct nft_parse_err perr; + struct nftnl_parse_err perr; switch (type) { - case NFT_PARSE_XML: - ret = nft_chain_xml_parse(c, data, &perr, input); + case NFTNL_PARSE_XML: + ret = nftnl_chain_xml_parse(c, data, &perr, input); break; - case NFT_PARSE_JSON: - ret = nft_chain_json_parse(c, data, &perr, input); + case NFTNL_PARSE_JSON: + ret = nftnl_chain_json_parse(c, data, &perr, input); break; default: ret = -1; @@ -818,78 +819,78 @@ static int nft_chain_do_parse(struct nft_chain *c, enum nft_parse_type type, return ret; } -int nft_chain_parse(struct nft_chain *c, enum nft_parse_type type, - const char *data, struct nft_parse_err *err) +int nftnl_chain_parse(struct nftnl_chain *c, enum nftnl_parse_type type, + const char *data, struct nftnl_parse_err *err) { - return nft_chain_do_parse(c, type, data, err, NFT_PARSE_BUFFER); + return nftnl_chain_do_parse(c, type, data, err, NFTNL_PARSE_BUFFER); } EXPORT_SYMBOL(nftnl_chain_parse, nft_chain_parse); -int nft_chain_parse_file(struct nft_chain *c, enum nft_parse_type type, - FILE *fp, struct nft_parse_err *err) +int nftnl_chain_parse_file(struct nftnl_chain *c, enum nftnl_parse_type type, + FILE *fp, struct nftnl_parse_err *err) { - return nft_chain_do_parse(c, type, fp, err, NFT_PARSE_FILE); + return nftnl_chain_do_parse(c, type, fp, err, NFTNL_PARSE_FILE); } EXPORT_SYMBOL(nftnl_chain_parse_file, nft_chain_parse_file); -static int nft_chain_export(char *buf, size_t size, struct nft_chain *c, +static int nftnl_chain_export(char *buf, size_t size, struct nftnl_chain *c, int type) { - NFT_BUF_INIT(b, buf, size); - - nft_buf_open(&b, type, CHAIN); - if (c->flags & (1 << NFT_CHAIN_ATTR_NAME)) - nft_buf_str(&b, type, c->name, NAME); - if (c->flags & (1 << NFT_CHAIN_ATTR_HANDLE)) - nft_buf_u64(&b, type, c->handle, HANDLE); - if (c->flags & (1 << NFT_CHAIN_ATTR_BYTES)) - nft_buf_u64(&b, type, c->bytes, BYTES); - if (c->flags & (1 << NFT_CHAIN_ATTR_PACKETS)) - nft_buf_u64(&b, type, c->packets, PACKETS); - if (c->flags & (1 << NFT_CHAIN_ATTR_TABLE)) - nft_buf_str(&b, type, c->table, TABLE); - if (c->flags & (1 << NFT_CHAIN_ATTR_FAMILY)) - nft_buf_str(&b, type, nft_family2str(c->family), FAMILY); - if (c->flags & (1 << NFT_CHAIN_ATTR_USE)) - nft_buf_u32(&b, type, c->use, USE); - if (c->flags & (1 << NFT_CHAIN_ATTR_HOOKNUM)) { - if (c->flags & (1 << NFT_CHAIN_ATTR_TYPE)) - nft_buf_str(&b, type, c->type, TYPE); - if (c->flags & (1 << NFT_CHAIN_ATTR_HOOKNUM)) - nft_buf_str(&b, type, nft_hooknum2str(c->family, + NFTNL_BUF_INIT(b, buf, size); + + nftnl_buf_open(&b, type, CHAIN); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_NAME)) + nftnl_buf_str(&b, type, c->name, NAME); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_HANDLE)) + nftnl_buf_u64(&b, type, c->handle, HANDLE); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_BYTES)) + nftnl_buf_u64(&b, type, c->bytes, BYTES); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_PACKETS)) + nftnl_buf_u64(&b, type, c->packets, PACKETS); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_TABLE)) + nftnl_buf_str(&b, type, c->table, TABLE); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_FAMILY)) + nftnl_buf_str(&b, type, nftnl_family2str(c->family), FAMILY); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_USE)) + nftnl_buf_u32(&b, type, c->use, USE); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_HOOKNUM)) { + if (c->flags & (1 << NFTNL_CHAIN_ATTR_TYPE)) + nftnl_buf_str(&b, type, c->type, TYPE); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_HOOKNUM)) + nftnl_buf_str(&b, type, nftnl_hooknum2str(c->family, c->hooknum), HOOKNUM); - if (c->flags & (1 << NFT_CHAIN_ATTR_PRIO)) - nft_buf_s32(&b, type, c->prio, PRIO); - if (c->flags & (1 << NFT_CHAIN_ATTR_POLICY)) - nft_buf_str(&b, type, nft_verdict2str(c->policy), POLICY); - if (c->flags & (1 << NFT_CHAIN_ATTR_DEV)) - nft_buf_str(&b, type, c->dev, DEVICE); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_PRIO)) + nftnl_buf_s32(&b, type, c->prio, PRIO); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_POLICY)) + nftnl_buf_str(&b, type, nftnl_verdict2str(c->policy), POLICY); + if (c->flags & (1 << NFTNL_CHAIN_ATTR_DEV)) + nftnl_buf_str(&b, type, c->dev, DEVICE); } - nft_buf_close(&b, type, CHAIN); + nftnl_buf_close(&b, type, CHAIN); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } -static int nft_chain_snprintf_default(char *buf, size_t size, - struct nft_chain *c) +static int nftnl_chain_snprintf_default(char *buf, size_t size, + struct nftnl_chain *c) { int ret, len = size, offset = 0; ret = snprintf(buf, len, "%s %s %s use %u", - nft_family2str(c->family), c->table, c->name, c->use); + nftnl_family2str(c->family), c->table, c->name, c->use); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (c->flags & (1 << NFT_CHAIN_ATTR_HOOKNUM)) { + if (c->flags & (1 << NFTNL_CHAIN_ATTR_HOOKNUM)) { ret = snprintf(buf+offset, len, " type %s hook %s prio %d policy %s " "packets %"PRIu64" bytes %"PRIu64"", - c->type, nft_hooknum2str(c->family, c->hooknum), - c->prio, nft_verdict2str(c->policy), + c->type, nftnl_hooknum2str(c->family, c->hooknum), + c->prio, nftnl_verdict2str(c->policy), c->packets, c->bytes); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (c->flags & (1 << NFT_CHAIN_ATTR_DEV)) { + if (c->flags & (1 << NFTNL_CHAIN_ATTR_DEV)) { ret = snprintf(buf+offset, len, " dev %s ", c->dev); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } @@ -898,21 +899,21 @@ static int nft_chain_snprintf_default(char *buf, size_t size, return offset; } -static int nft_chain_cmd_snprintf(char *buf, size_t size, struct nft_chain *c, +static int nftnl_chain_cmd_snprintf(char *buf, size_t size, struct nftnl_chain *c, uint32_t cmd, uint32_t type, uint32_t flags) { int ret, len = size, offset = 0; - ret = nft_cmd_header_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_header_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); switch (type) { - case NFT_OUTPUT_DEFAULT: - ret = nft_chain_snprintf_default(buf+offset, len, c); + case NFTNL_OUTPUT_DEFAULT: + ret = nftnl_chain_snprintf_default(buf+offset, len, c); break; - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - ret = nft_chain_export(buf+offset, len, c, type); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + ret = nftnl_chain_export(buf+offset, len, c, type); break; default: return -1; @@ -920,44 +921,44 @@ static int nft_chain_cmd_snprintf(char *buf, size_t size, struct nft_chain *c, SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); return offset; } -int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *c, +int nftnl_chain_snprintf(char *buf, size_t size, struct nftnl_chain *c, uint32_t type, uint32_t flags) { - return nft_chain_cmd_snprintf(buf, size, c, nft_flag2cmd(flags), type, + return nftnl_chain_cmd_snprintf(buf, size, c, nftnl_flag2cmd(flags), type, flags); } EXPORT_SYMBOL(nftnl_chain_snprintf, nft_chain_snprintf); -static inline int nft_chain_do_snprintf(char *buf, size_t size, void *c, +static inline int nftnl_chain_do_snprintf(char *buf, size_t size, void *c, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_chain_snprintf(buf, size, c, type, flags); + return nftnl_chain_snprintf(buf, size, c, type, flags); } -int nft_chain_fprintf(FILE *fp, struct nft_chain *c, uint32_t type, +int nftnl_chain_fprintf(FILE *fp, struct nftnl_chain *c, uint32_t type, uint32_t flags) { - return nft_fprintf(fp, c, NFT_CMD_UNSPEC, type, flags, - nft_chain_do_snprintf); + return nftnl_fprintf(fp, c, NFTNL_CMD_UNSPEC, type, flags, + nftnl_chain_do_snprintf); } EXPORT_SYMBOL(nftnl_chain_fprintf, nft_chain_fprintf); -struct nft_chain_list { +struct nftnl_chain_list { struct list_head list; }; -struct nft_chain_list *nft_chain_list_alloc(void) +struct nftnl_chain_list *nftnl_chain_list_alloc(void) { - struct nft_chain_list *list; + struct nftnl_chain_list *list; - list = calloc(1, sizeof(struct nft_chain_list)); + list = calloc(1, sizeof(struct nftnl_chain_list)); if (list == NULL) return NULL; @@ -967,47 +968,47 @@ struct nft_chain_list *nft_chain_list_alloc(void) } EXPORT_SYMBOL(nftnl_chain_list_alloc, nft_chain_list_alloc); -void nft_chain_list_free(struct nft_chain_list *list) +void nftnl_chain_list_free(struct nftnl_chain_list *list) { - struct nft_chain *r, *tmp; + struct nftnl_chain *r, *tmp; list_for_each_entry_safe(r, tmp, &list->list, head) { list_del(&r->head); - nft_chain_free(r); + nftnl_chain_free(r); } xfree(list); } EXPORT_SYMBOL(nftnl_chain_list_free, nft_chain_list_free); -int nft_chain_list_is_empty(struct nft_chain_list *list) +int nftnl_chain_list_is_empty(struct nftnl_chain_list *list) { return list_empty(&list->list); } EXPORT_SYMBOL(nftnl_chain_list_is_empty, nft_chain_list_is_empty); -void nft_chain_list_add(struct nft_chain *r, struct nft_chain_list *list) +void nftnl_chain_list_add(struct nftnl_chain *r, struct nftnl_chain_list *list) { list_add(&r->head, &list->list); } EXPORT_SYMBOL(nftnl_chain_list_add, nft_chain_list_add); -void nft_chain_list_add_tail(struct nft_chain *r, struct nft_chain_list *list) +void nftnl_chain_list_add_tail(struct nftnl_chain *r, struct nftnl_chain_list *list) { list_add_tail(&r->head, &list->list); } EXPORT_SYMBOL(nftnl_chain_list_add_tail, nft_chain_list_add_tail); -void nft_chain_list_del(struct nft_chain *r) +void nftnl_chain_list_del(struct nftnl_chain *r) { list_del(&r->head); } EXPORT_SYMBOL(nftnl_chain_list_del, nft_chain_list_del); -int nft_chain_list_foreach(struct nft_chain_list *chain_list, - int (*cb)(struct nft_chain *r, void *data), +int nftnl_chain_list_foreach(struct nftnl_chain_list *chain_list, + int (*cb)(struct nftnl_chain *r, void *data), void *data) { - struct nft_chain *cur, *tmp; + struct nftnl_chain *cur, *tmp; int ret; list_for_each_entry_safe(cur, tmp, &chain_list->list, head) { @@ -1019,38 +1020,38 @@ int nft_chain_list_foreach(struct nft_chain_list *chain_list, } EXPORT_SYMBOL(nftnl_chain_list_foreach, nft_chain_list_foreach); -struct nft_chain_list_iter { - struct nft_chain_list *list; - struct nft_chain *cur; +struct nftnl_chain_list_iter { + struct nftnl_chain_list *list; + struct nftnl_chain *cur; }; -struct nft_chain_list_iter *nft_chain_list_iter_create(struct nft_chain_list *l) +struct nftnl_chain_list_iter *nftnl_chain_list_iter_create(struct nftnl_chain_list *l) { - struct nft_chain_list_iter *iter; + struct nftnl_chain_list_iter *iter; - iter = calloc(1, sizeof(struct nft_chain_list_iter)); + iter = calloc(1, sizeof(struct nftnl_chain_list_iter)); if (iter == NULL) return NULL; iter->list = l; - if (nft_chain_list_is_empty(l)) + if (nftnl_chain_list_is_empty(l)) iter->cur = NULL; else - iter->cur = list_entry(l->list.next, struct nft_chain, head); + iter->cur = list_entry(l->list.next, struct nftnl_chain, head); return iter; } EXPORT_SYMBOL(nftnl_chain_list_iter_create, nft_chain_list_iter_create); -struct nft_chain *nft_chain_list_iter_next(struct nft_chain_list_iter *iter) +struct nftnl_chain *nftnl_chain_list_iter_next(struct nftnl_chain_list_iter *iter) { - struct nft_chain *r = iter->cur; + struct nftnl_chain *r = iter->cur; if (r == NULL) return NULL; /* get next chain, if any */ - iter->cur = list_entry(iter->cur->head.next, struct nft_chain, head); + iter->cur = list_entry(iter->cur->head.next, struct nftnl_chain, head); if (&iter->cur->head == iter->list->list.next) return NULL; @@ -1058,7 +1059,7 @@ struct nft_chain *nft_chain_list_iter_next(struct nft_chain_list_iter *iter) } EXPORT_SYMBOL(nftnl_chain_list_iter_next, nft_chain_list_iter_next); -void nft_chain_list_iter_destroy(struct nft_chain_list_iter *iter) +void nftnl_chain_list_iter_destroy(struct nftnl_chain_list_iter *iter) { xfree(iter); } diff --git a/src/common.c b/src/common.c index 27f9177..43d2cfd 100644 --- a/src/common.c +++ b/src/common.c @@ -22,7 +22,7 @@ #include <errno.h> #include "internal.h" -struct nlmsghdr *nft_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, +struct nlmsghdr *nftnl_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq) { struct nlmsghdr *nlh; @@ -42,39 +42,39 @@ struct nlmsghdr *nft_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, } EXPORT_SYMBOL(nftnl_nlmsg_build_hdr, nft_nlmsg_build_hdr); -struct nft_parse_err *nft_parse_err_alloc(void) +struct nftnl_parse_err *nftnl_parse_err_alloc(void) { - struct nft_parse_err *err; + struct nftnl_parse_err *err; - err = calloc(1, sizeof(struct nft_parse_err)); + err = calloc(1, sizeof(struct nftnl_parse_err)); if (err == NULL) return NULL; - err->error = NFT_PARSE_EOPNOTSUPP; + err->error = NFTNL_PARSE_EOPNOTSUPP; return err; } EXPORT_SYMBOL(nftnl_parse_err_alloc, nft_parse_err_alloc); -void nft_parse_err_free(struct nft_parse_err *err) +void nftnl_parse_err_free(struct nftnl_parse_err *err) { xfree(err); } EXPORT_SYMBOL(nftnl_parse_err_free, nft_parse_err_free); -int nft_parse_perror(const char *msg, struct nft_parse_err *err) +int nftnl_parse_perror(const char *msg, struct nftnl_parse_err *err) { switch (err->error) { - case NFT_PARSE_EBADINPUT: + case NFTNL_PARSE_EBADINPUT: return fprintf(stderr, "%s: Bad input format in line %d column %d\n", msg, err->line, err->column); - case NFT_PARSE_EMISSINGNODE: + case NFTNL_PARSE_EMISSINGNODE: return fprintf(stderr, "%s: Node \"%s\" not found\n", msg, err->node_name); - case NFT_PARSE_EBADTYPE: + case NFTNL_PARSE_EBADTYPE: return fprintf(stderr, "%s: Invalid type in node \"%s\"\n", msg, err->node_name); - case NFT_PARSE_EOPNOTSUPP: + case NFTNL_PARSE_EOPNOTSUPP: return fprintf(stderr, "%s: Operation not supported\n", msg); default: return fprintf(stderr, "%s: Undefined error\n", msg); @@ -82,83 +82,81 @@ int nft_parse_perror(const char *msg, struct nft_parse_err *err) } EXPORT_SYMBOL(nftnl_parse_perror, nft_parse_perror); -int nft_cmd_header_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type, +int nftnl_cmd_header_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type, uint32_t flags) { - NFT_BUF_INIT(b, buf, size); + NFTNL_BUF_INIT(b, buf, size); - if (cmd == NFT_CMD_UNSPEC) + if (cmd == NFTNL_CMD_UNSPEC) return 0; switch (type) { - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - nft_buf_open_array(&b, type, nft_cmd2tag(cmd)); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + nftnl_buf_open_array(&b, type, nftnl_cmd2tag(cmd)); break; default: switch (cmd) { - case NFT_CMD_ADD: + case NFTNL_CMD_ADD: return snprintf(buf, size, "%9s", "[ADD] "); - case NFT_CMD_DELETE: + case NFTNL_CMD_DELETE: return snprintf(buf, size, "%9s", "[DELETE] "); default: return snprintf(buf, size, "%9s", "[unknown] "); } break; } - return nft_buf_done(&b); + return nftnl_buf_done(&b); } - - -static int nft_cmd_header_fprintf_cb(char *buf, size_t size, void *obj, +static int nftnl_cmd_header_fprintf_cb(char *buf, size_t size, void *obj, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_cmd_header_snprintf(buf, size, cmd, type, flags); + return nftnl_cmd_header_snprintf(buf, size, cmd, type, flags); } -int nft_cmd_header_fprintf(FILE *fp, uint32_t cmd, uint32_t type, +int nftnl_cmd_header_fprintf(FILE *fp, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_fprintf(fp, NULL, cmd, type, flags, - nft_cmd_header_fprintf_cb); + return nftnl_fprintf(fp, NULL, cmd, type, flags, + nftnl_cmd_header_fprintf_cb); } -int nft_cmd_footer_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type, +int nftnl_cmd_footer_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type, uint32_t flags) { - NFT_BUF_INIT(b, buf, size); + NFTNL_BUF_INIT(b, buf, size); - if (cmd == NFT_CMD_UNSPEC) + if (cmd == NFTNL_CMD_UNSPEC) return 0; switch (type) { - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - nft_buf_close_array(&b, type, nft_cmd2tag(cmd)); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + nftnl_buf_close_array(&b, type, nftnl_cmd2tag(cmd)); break; default: return 0; } - return nft_buf_done(&b); + return nftnl_buf_done(&b); } -static int nft_cmd_footer_fprintf_cb(char *buf, size_t size, void *obj, +static int nftnl_cmd_footer_fprintf_cb(char *buf, size_t size, void *obj, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_cmd_footer_snprintf(buf, size, cmd, type, flags); + return nftnl_cmd_footer_snprintf(buf, size, cmd, type, flags); } -int nft_cmd_footer_fprintf(FILE *fp, uint32_t cmd, uint32_t type, +int nftnl_cmd_footer_fprintf(FILE *fp, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_fprintf(fp, NULL, cmd, type, flags, - nft_cmd_footer_fprintf_cb); + return nftnl_fprintf(fp, NULL, cmd, type, flags, + nftnl_cmd_footer_fprintf_cb); } -static void nft_batch_build_hdr(char *buf, uint16_t type, uint32_t seq) +static void nftnl_batch_build_hdr(char *buf, uint16_t type, uint32_t seq) { struct nlmsghdr *nlh; struct nfgenmsg *nfg; @@ -174,19 +172,19 @@ static void nft_batch_build_hdr(char *buf, uint16_t type, uint32_t seq) nfg->res_id = NFNL_SUBSYS_NFTABLES; } -void nft_batch_begin(char *buf, uint32_t seq) +void nftnl_batch_begin(char *buf, uint32_t seq) { - nft_batch_build_hdr(buf, NFNL_MSG_BATCH_BEGIN, seq); + nftnl_batch_build_hdr(buf, NFNL_MSG_BATCH_BEGIN, seq); } EXPORT_SYMBOL(nftnl_batch_begin, nft_batch_begin); -void nft_batch_end(char *buf, uint32_t seq) +void nftnl_batch_end(char *buf, uint32_t seq) { - nft_batch_build_hdr(buf, NFNL_MSG_BATCH_END, seq); + nftnl_batch_build_hdr(buf, NFNL_MSG_BATCH_END, seq); } EXPORT_SYMBOL(nftnl_batch_end, nft_batch_end); -int nft_batch_is_supported(void) +int nftnl_batch_is_supported(void) { struct mnl_socket *nl; struct mnl_nlmsg_batch *b; @@ -203,16 +201,16 @@ int nft_batch_is_supported(void) b = mnl_nlmsg_batch_start(buf, sizeof(buf)); - nft_batch_begin(mnl_nlmsg_batch_current(b), seq++); + nftnl_batch_begin(mnl_nlmsg_batch_current(b), seq++); mnl_nlmsg_batch_next(b); req_seq = seq; - nft_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(b), + nftnl_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(b), NFT_MSG_NEWSET, AF_INET, NLM_F_ACK, seq++); mnl_nlmsg_batch_next(b); - nft_batch_end(mnl_nlmsg_batch_current(b), seq++); + nftnl_batch_end(mnl_nlmsg_batch_current(b), seq++); mnl_nlmsg_batch_next(b); ret = mnl_socket_sendto(nl, mnl_nlmsg_batch_head(b), @@ -24,28 +24,28 @@ #include <libnftnl/expr.h> -struct nft_rule_expr *nft_rule_expr_alloc(const char *name) +struct nftnl_rule_expr *nftnl_rule_expr_alloc(const char *name) { - struct nft_rule_expr *expr; + struct nftnl_rule_expr *expr; struct expr_ops *ops; - ops = nft_expr_ops_lookup(name); + ops = nftnl_expr_ops_lookup(name); if (ops == NULL) return NULL; - expr = calloc(1, sizeof(struct nft_rule_expr) + ops->alloc_len); + expr = calloc(1, sizeof(struct nftnl_rule_expr) + ops->alloc_len); if (expr == NULL) return NULL; /* Manually set expression name attribute */ - expr->flags |= (1 << NFT_RULE_EXPR_ATTR_NAME); + expr->flags |= (1 << NFTNL_RULE_EXPR_ATTR_NAME); expr->ops = ops; return expr; } EXPORT_SYMBOL(nftnl_rule_expr_alloc, nft_rule_expr_alloc); -void nft_rule_expr_free(struct nft_rule_expr *expr) +void nftnl_rule_expr_free(struct nftnl_rule_expr *expr) { if (expr->ops->free) expr->ops->free(expr); @@ -54,18 +54,18 @@ void nft_rule_expr_free(struct nft_rule_expr *expr) } EXPORT_SYMBOL(nftnl_rule_expr_free, nft_rule_expr_free); -bool nft_rule_expr_is_set(const struct nft_rule_expr *expr, uint16_t type) +bool nftnl_rule_expr_is_set(const struct nftnl_rule_expr *expr, uint16_t type) { return expr->flags & (1 << type); } EXPORT_SYMBOL(nftnl_rule_expr_is_set, nft_rule_expr_is_set); void -nft_rule_expr_set(struct nft_rule_expr *expr, uint16_t type, +nftnl_rule_expr_set(struct nftnl_rule_expr *expr, uint16_t type, const void *data, uint32_t data_len) { switch(type) { - case NFT_RULE_EXPR_ATTR_NAME: /* cannot be modified */ + case NFTNL_RULE_EXPR_ATTR_NAME: /* cannot be modified */ return; default: if (expr->ops->set(expr, type, data, data_len) < 0) @@ -76,41 +76,41 @@ nft_rule_expr_set(struct nft_rule_expr *expr, uint16_t type, EXPORT_SYMBOL(nftnl_rule_expr_set, nft_rule_expr_set); void -nft_rule_expr_set_u8(struct nft_rule_expr *expr, uint16_t type, uint8_t data) +nftnl_rule_expr_set_u8(struct nftnl_rule_expr *expr, uint16_t type, uint8_t data) { - nft_rule_expr_set(expr, type, &data, sizeof(uint8_t)); + nftnl_rule_expr_set(expr, type, &data, sizeof(uint8_t)); } EXPORT_SYMBOL(nftnl_rule_expr_set_u8, nft_rule_expr_set_u8); void -nft_rule_expr_set_u16(struct nft_rule_expr *expr, uint16_t type, uint16_t data) +nftnl_rule_expr_set_u16(struct nftnl_rule_expr *expr, uint16_t type, uint16_t data) { - nft_rule_expr_set(expr, type, &data, sizeof(uint16_t)); + nftnl_rule_expr_set(expr, type, &data, sizeof(uint16_t)); } EXPORT_SYMBOL(nftnl_rule_expr_set_u16, nft_rule_expr_set_u16); void -nft_rule_expr_set_u32(struct nft_rule_expr *expr, uint16_t type, uint32_t data) +nftnl_rule_expr_set_u32(struct nftnl_rule_expr *expr, uint16_t type, uint32_t data) { - nft_rule_expr_set(expr, type, &data, sizeof(uint32_t)); + nftnl_rule_expr_set(expr, type, &data, sizeof(uint32_t)); } EXPORT_SYMBOL(nftnl_rule_expr_set_u32, nft_rule_expr_set_u32); void -nft_rule_expr_set_u64(struct nft_rule_expr *expr, uint16_t type, uint64_t data) +nftnl_rule_expr_set_u64(struct nftnl_rule_expr *expr, uint16_t type, uint64_t data) { - nft_rule_expr_set(expr, type, &data, sizeof(uint64_t)); + nftnl_rule_expr_set(expr, type, &data, sizeof(uint64_t)); } EXPORT_SYMBOL(nftnl_rule_expr_set_u64, nft_rule_expr_set_u64); void -nft_rule_expr_set_str(struct nft_rule_expr *expr, uint16_t type, const char *str) +nftnl_rule_expr_set_str(struct nftnl_rule_expr *expr, uint16_t type, const char *str) { - nft_rule_expr_set(expr, type, str, strlen(str)+1); + nftnl_rule_expr_set(expr, type, str, strlen(str)+1); } EXPORT_SYMBOL(nftnl_rule_expr_set_str, nft_rule_expr_set_str); -const void *nft_rule_expr_get(const struct nft_rule_expr *expr, +const void *nftnl_rule_expr_get(const struct nftnl_rule_expr *expr, uint16_t type, uint32_t *data_len) { const void *ret; @@ -119,7 +119,7 @@ const void *nft_rule_expr_get(const struct nft_rule_expr *expr, return NULL; switch(type) { - case NFT_RULE_EXPR_ATTR_NAME: + case NFTNL_RULE_EXPR_ATTR_NAME: ret = expr->ops->name; break; default: @@ -131,12 +131,12 @@ const void *nft_rule_expr_get(const struct nft_rule_expr *expr, } EXPORT_SYMBOL(nftnl_rule_expr_get, nft_rule_expr_get); -uint8_t nft_rule_expr_get_u8(const struct nft_rule_expr *expr, uint16_t type) +uint8_t nftnl_rule_expr_get_u8(const struct nftnl_rule_expr *expr, uint16_t type) { const void *data; uint32_t data_len; - data = nft_rule_expr_get(expr, type, &data_len); + data = nftnl_rule_expr_get(expr, type, &data_len); if (data == NULL) return 0; @@ -147,12 +147,12 @@ uint8_t nft_rule_expr_get_u8(const struct nft_rule_expr *expr, uint16_t type) } EXPORT_SYMBOL(nftnl_rule_expr_get_u8, nft_rule_expr_get_u8); -uint16_t nft_rule_expr_get_u16(const struct nft_rule_expr *expr, uint16_t type) +uint16_t nftnl_rule_expr_get_u16(const struct nftnl_rule_expr *expr, uint16_t type) { const void *data; uint32_t data_len; - data = nft_rule_expr_get(expr, type, &data_len); + data = nftnl_rule_expr_get(expr, type, &data_len); if (data == NULL) return 0; @@ -163,12 +163,12 @@ uint16_t nft_rule_expr_get_u16(const struct nft_rule_expr *expr, uint16_t type) } EXPORT_SYMBOL(nftnl_rule_expr_get_u16, nft_rule_expr_get_u16); -uint32_t nft_rule_expr_get_u32(const struct nft_rule_expr *expr, uint16_t type) +uint32_t nftnl_rule_expr_get_u32(const struct nftnl_rule_expr *expr, uint16_t type) { const void *data; uint32_t data_len; - data = nft_rule_expr_get(expr, type, &data_len); + data = nftnl_rule_expr_get(expr, type, &data_len); if (data == NULL) return 0; @@ -179,12 +179,12 @@ uint32_t nft_rule_expr_get_u32(const struct nft_rule_expr *expr, uint16_t type) } EXPORT_SYMBOL(nftnl_rule_expr_get_u32, nft_rule_expr_get_u32); -uint64_t nft_rule_expr_get_u64(const struct nft_rule_expr *expr, uint16_t type) +uint64_t nftnl_rule_expr_get_u64(const struct nftnl_rule_expr *expr, uint16_t type) { const void *data; uint32_t data_len; - data = nft_rule_expr_get(expr, type, &data_len); + data = nftnl_rule_expr_get(expr, type, &data_len); if (data == NULL) return 0; @@ -195,16 +195,16 @@ uint64_t nft_rule_expr_get_u64(const struct nft_rule_expr *expr, uint16_t type) } EXPORT_SYMBOL(nftnl_rule_expr_get_u64, nft_rule_expr_get_u64); -const char *nft_rule_expr_get_str(const struct nft_rule_expr *expr, uint16_t type) +const char *nftnl_rule_expr_get_str(const struct nftnl_rule_expr *expr, uint16_t type) { uint32_t data_len; - return (const char *)nft_rule_expr_get(expr, type, &data_len); + return (const char *)nftnl_rule_expr_get(expr, type, &data_len); } EXPORT_SYMBOL(nftnl_rule_expr_get_str, nft_rule_expr_get_str); void -nft_rule_expr_build_payload(struct nlmsghdr *nlh, struct nft_rule_expr *expr) +nftnl_rule_expr_build_payload(struct nlmsghdr *nlh, struct nftnl_rule_expr *expr) { struct nlattr *nest; @@ -215,7 +215,7 @@ nft_rule_expr_build_payload(struct nlmsghdr *nlh, struct nft_rule_expr *expr) mnl_attr_nest_end(nlh, nest); } -static int nft_rule_parse_expr_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_parse_expr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -238,15 +238,15 @@ static int nft_rule_parse_expr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -struct nft_rule_expr *nft_rule_expr_parse(struct nlattr *attr) +struct nftnl_rule_expr *nftnl_rule_expr_parse(struct nlattr *attr) { struct nlattr *tb[NFTA_EXPR_MAX+1] = {}; - struct nft_rule_expr *expr; + struct nftnl_rule_expr *expr; - if (mnl_attr_parse_nested(attr, nft_rule_parse_expr_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_parse_expr_cb, tb) < 0) goto err1; - expr = nft_rule_expr_alloc(mnl_attr_get_str(tb[NFTA_EXPR_NAME])); + expr = nftnl_rule_expr_alloc(mnl_attr_get_str(tb[NFTA_EXPR_NAME])); if (expr == NULL) goto err1; @@ -262,7 +262,7 @@ err1: return NULL; } -int nft_rule_expr_snprintf(char *buf, size_t size, struct nft_rule_expr *expr, +int nftnl_rule_expr_snprintf(char *buf, size_t size, struct nftnl_rule_expr *expr, uint32_t type, uint32_t flags) { int ret; diff --git a/src/expr/bitwise.c b/src/expr/bitwise.c index f0851b0..331fd20 100644 --- a/src/expr/bitwise.c +++ b/src/expr/bitwise.c @@ -21,35 +21,35 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_bitwise { +struct nftnl_expr_bitwise { enum nft_registers sreg; enum nft_registers dreg; unsigned int len; - union nft_data_reg mask; - union nft_data_reg xor; + union nftnl_data_reg mask; + union nftnl_data_reg xor; }; static int -nft_rule_expr_bitwise_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_bitwise_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_bitwise *bitwise = nft_expr_data(e); + struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_BITWISE_SREG: + case NFTNL_EXPR_BITWISE_SREG: bitwise->sreg = *((uint32_t *)data); break; - case NFT_EXPR_BITWISE_DREG: + case NFTNL_EXPR_BITWISE_DREG: bitwise->dreg = *((uint32_t *)data); break; - case NFT_EXPR_BITWISE_LEN: + case NFTNL_EXPR_BITWISE_LEN: bitwise->len = *((unsigned int *)data); break; - case NFT_EXPR_BITWISE_MASK: + case NFTNL_EXPR_BITWISE_MASK: memcpy(&bitwise->mask.val, data, data_len); bitwise->mask.len = data_len; break; - case NFT_EXPR_BITWISE_XOR: + case NFTNL_EXPR_BITWISE_XOR: memcpy(&bitwise->xor.val, data, data_len); bitwise->xor.len = data_len; break; @@ -60,32 +60,32 @@ nft_rule_expr_bitwise_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_bitwise_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_bitwise_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_bitwise *bitwise = nft_expr_data(e); + struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_BITWISE_SREG: + case NFTNL_EXPR_BITWISE_SREG: *data_len = sizeof(bitwise->sreg); return &bitwise->sreg; - case NFT_EXPR_BITWISE_DREG: + case NFTNL_EXPR_BITWISE_DREG: *data_len = sizeof(bitwise->dreg); return &bitwise->dreg; - case NFT_EXPR_BITWISE_LEN: + case NFTNL_EXPR_BITWISE_LEN: *data_len = sizeof(bitwise->len); return &bitwise->len; - case NFT_EXPR_BITWISE_MASK: + case NFTNL_EXPR_BITWISE_MASK: *data_len = bitwise->mask.len; return &bitwise->mask.val; - case NFT_EXPR_BITWISE_XOR: + case NFTNL_EXPR_BITWISE_XOR: *data_len = bitwise->xor.len; return &bitwise->xor.val; } return NULL; } -static int nft_rule_expr_bitwise_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_bitwise_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -112,17 +112,17 @@ static int nft_rule_expr_bitwise_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_bitwise_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_bitwise_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_bitwise *bitwise = nft_expr_data(e); + struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_BITWISE_SREG)) + if (e->flags & (1 << NFTNL_EXPR_BITWISE_SREG)) mnl_attr_put_u32(nlh, NFTA_BITWISE_SREG, htonl(bitwise->sreg)); - if (e->flags & (1 << NFT_EXPR_BITWISE_DREG)) + if (e->flags & (1 << NFTNL_EXPR_BITWISE_DREG)) mnl_attr_put_u32(nlh, NFTA_BITWISE_DREG, htonl(bitwise->dreg)); - if (e->flags & (1 << NFT_EXPR_BITWISE_LEN)) + if (e->flags & (1 << NFTNL_EXPR_BITWISE_LEN)) mnl_attr_put_u32(nlh, NFTA_BITWISE_LEN, htonl(bitwise->len)); - if (e->flags & (1 << NFT_EXPR_BITWISE_MASK)) { + if (e->flags & (1 << NFTNL_EXPR_BITWISE_MASK)) { struct nlattr *nest; nest = mnl_attr_nest_start(nlh, NFTA_BITWISE_MASK); @@ -130,7 +130,7 @@ nft_rule_expr_bitwise_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) bitwise->mask.val); mnl_attr_nest_end(nlh, nest); } - if (e->flags & (1 << NFT_EXPR_BITWISE_XOR)) { + if (e->flags & (1 << NFTNL_EXPR_BITWISE_XOR)) { struct nlattr *nest; nest = mnl_attr_nest_start(nlh, NFTA_BITWISE_XOR); @@ -141,33 +141,33 @@ nft_rule_expr_bitwise_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) } static int -nft_rule_expr_bitwise_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_bitwise_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_bitwise *bitwise = nft_expr_data(e); + struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); struct nlattr *tb[NFTA_BITWISE_MAX+1] = {}; int ret = 0; - if (mnl_attr_parse_nested(attr, nft_rule_expr_bitwise_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_bitwise_cb, tb) < 0) return -1; if (tb[NFTA_BITWISE_SREG]) { bitwise->sreg = ntohl(mnl_attr_get_u32(tb[NFTA_BITWISE_SREG])); - e->flags |= (1 << NFT_EXPR_BITWISE_SREG); + e->flags |= (1 << NFTNL_EXPR_BITWISE_SREG); } if (tb[NFTA_BITWISE_DREG]) { bitwise->dreg = ntohl(mnl_attr_get_u32(tb[NFTA_BITWISE_DREG])); - e->flags |= (1 << NFT_EXPR_BITWISE_DREG); + e->flags |= (1 << NFTNL_EXPR_BITWISE_DREG); } if (tb[NFTA_BITWISE_LEN]) { bitwise->len = ntohl(mnl_attr_get_u32(tb[NFTA_BITWISE_LEN])); - e->flags |= (1 << NFT_EXPR_BITWISE_LEN); + e->flags |= (1 << NFTNL_EXPR_BITWISE_LEN); } if (tb[NFTA_BITWISE_MASK]) { - ret = nft_parse_data(&bitwise->mask, tb[NFTA_BITWISE_MASK], NULL); + ret = nftnl_parse_data(&bitwise->mask, tb[NFTA_BITWISE_MASK], NULL); e->flags |= (1 << NFTA_BITWISE_MASK); } if (tb[NFTA_BITWISE_XOR]) { - ret = nft_parse_data(&bitwise->xor, tb[NFTA_BITWISE_XOR], NULL); + ret = nftnl_parse_data(&bitwise->xor, tb[NFTA_BITWISE_XOR], NULL); e->flags |= (1 << NFTA_BITWISE_XOR); } @@ -175,29 +175,29 @@ nft_rule_expr_bitwise_parse(struct nft_rule_expr *e, struct nlattr *attr) } static int -nft_rule_expr_bitwise_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_bitwise_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING - struct nft_expr_bitwise *bitwise = nft_expr_data(e); + struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); uint32_t reg, len; - if (nft_jansson_parse_reg(root, "sreg", NFT_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BITWISE_SREG, reg); + if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, ®, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BITWISE_SREG, reg); - if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BITWISE_DREG, reg); + if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BITWISE_DREG, reg); - if (nft_jansson_parse_val(root, "len", NFT_TYPE_U32, &len, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BITWISE_LEN, len); + if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &len, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BITWISE_LEN, len); - if (nft_jansson_data_reg_parse(root, "mask", &bitwise->mask, + if (nftnl_jansson_data_reg_parse(root, "mask", &bitwise->mask, err) == DATA_VALUE) - e->flags |= (1 << NFT_EXPR_BITWISE_MASK); + e->flags |= (1 << NFTNL_EXPR_BITWISE_MASK); - if (nft_jansson_data_reg_parse(root, "xor", &bitwise->xor, + if (nftnl_jansson_data_reg_parse(root, "xor", &bitwise->xor, err) == DATA_VALUE) - e->flags |= (1 << NFT_EXPR_BITWISE_XOR); + e->flags |= (1 << NFTNL_EXPR_BITWISE_XOR); if (bitwise->mask.len != bitwise->xor.len) return -1; @@ -210,32 +210,32 @@ nft_rule_expr_bitwise_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_bitwise_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_bitwise_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING - struct nft_expr_bitwise *bitwise = nft_expr_data(e); + struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); uint32_t sreg, dreg, len; - if (nft_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BITWISE_SREG, sreg); + if (nftnl_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BITWISE_SREG, sreg); - if (nft_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BITWISE_DREG, dreg); + if (nftnl_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BITWISE_DREG, dreg); - if (nft_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, - &len, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BITWISE_LEN, len); + if (nftnl_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, + &len, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BITWISE_LEN, len); - if (nft_mxml_data_reg_parse(tree, "mask", &bitwise->mask, NFT_XML_MAND, + if (nftnl_mxml_data_reg_parse(tree, "mask", &bitwise->mask, NFTNL_XML_MAND, err) == DATA_VALUE) - e->flags |= (1 << NFT_EXPR_BITWISE_MASK); + e->flags |= (1 << NFTNL_EXPR_BITWISE_MASK); - if (nft_mxml_data_reg_parse(tree, "xor", &bitwise->xor, NFT_XML_MAND, + if (nftnl_mxml_data_reg_parse(tree, "xor", &bitwise->xor, NFTNL_XML_MAND, err) == DATA_VALUE) - e->flags |= (1 << NFT_EXPR_BITWISE_XOR); + e->flags |= (1 << NFTNL_EXPR_BITWISE_XOR); /* Additional validation: mask and xor must use the same number of * data registers. @@ -250,60 +250,60 @@ nft_rule_expr_bitwise_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, #endif } -static int nft_rule_expr_bitwise_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_bitwise_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_bitwise *bitwise = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFT_EXPR_BITWISE_SREG)) - nft_buf_u32(&b, type, bitwise->sreg, SREG); - if (e->flags & (1 << NFT_EXPR_BITWISE_DREG)) - nft_buf_u32(&b, type, bitwise->dreg, DREG); - if (e->flags & (1 << NFT_EXPR_BITWISE_LEN)) - nft_buf_u32(&b, type, bitwise->len, LEN); - if (e->flags & (1 << NFT_EXPR_BITWISE_MASK)) - nft_buf_reg(&b, type, &bitwise->mask, DATA_VALUE, MASK); - if (e->flags & (1 << NFT_EXPR_BITWISE_XOR)) - nft_buf_reg(&b, type, &bitwise->xor, DATA_VALUE, XOR); - - return nft_buf_done(&b); + struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); + + if (e->flags & (1 << NFTNL_EXPR_BITWISE_SREG)) + nftnl_buf_u32(&b, type, bitwise->sreg, SREG); + if (e->flags & (1 << NFTNL_EXPR_BITWISE_DREG)) + nftnl_buf_u32(&b, type, bitwise->dreg, DREG); + if (e->flags & (1 << NFTNL_EXPR_BITWISE_LEN)) + nftnl_buf_u32(&b, type, bitwise->len, LEN); + if (e->flags & (1 << NFTNL_EXPR_BITWISE_MASK)) + nftnl_buf_reg(&b, type, &bitwise->mask, DATA_VALUE, MASK); + if (e->flags & (1 << NFTNL_EXPR_BITWISE_XOR)) + nftnl_buf_reg(&b, type, &bitwise->xor, DATA_VALUE, XOR); + + return nftnl_buf_done(&b); } -static int nft_rule_expr_bitwise_snprintf_default(char *buf, size_t size, - struct nft_rule_expr *e) +static int nftnl_rule_expr_bitwise_snprintf_default(char *buf, size_t size, + struct nftnl_rule_expr *e) { - struct nft_expr_bitwise *bitwise = nft_expr_data(e); + struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); int len = size, offset = 0, ret; ret = snprintf(buf, len, "reg %u = (reg=%u & ", bitwise->dreg, bitwise->sreg); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_data_reg_snprintf(buf+offset, len, &bitwise->mask, - NFT_OUTPUT_DEFAULT, 0, DATA_VALUE); + ret = nftnl_data_reg_snprintf(buf+offset, len, &bitwise->mask, + NFTNL_OUTPUT_DEFAULT, 0, DATA_VALUE); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); ret = snprintf(buf+offset, len, ") ^ "); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_data_reg_snprintf(buf+offset, len, &bitwise->xor, - NFT_OUTPUT_DEFAULT, 0, DATA_VALUE); + ret = nftnl_data_reg_snprintf(buf+offset, len, &bitwise->xor, + NFTNL_OUTPUT_DEFAULT, 0, DATA_VALUE); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); return offset; } static int -nft_rule_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_bitwise_snprintf_default(buf, size, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_bitwise_export(buf, size, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_bitwise_snprintf_default(buf, size, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_bitwise_export(buf, size, e, type); default: break; } @@ -312,13 +312,13 @@ nft_rule_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type, struct expr_ops expr_ops_bitwise = { .name = "bitwise", - .alloc_len = sizeof(struct nft_expr_bitwise), + .alloc_len = sizeof(struct nftnl_expr_bitwise), .max_attr = NFTA_BITWISE_MAX, - .set = nft_rule_expr_bitwise_set, - .get = nft_rule_expr_bitwise_get, - .parse = nft_rule_expr_bitwise_parse, - .build = nft_rule_expr_bitwise_build, - .snprintf = nft_rule_expr_bitwise_snprintf, - .xml_parse = nft_rule_expr_bitwise_xml_parse, - .json_parse = nft_rule_expr_bitwise_json_parse, + .set = nftnl_rule_expr_bitwise_set, + .get = nftnl_rule_expr_bitwise_get, + .parse = nftnl_rule_expr_bitwise_parse, + .build = nftnl_rule_expr_bitwise_build, + .snprintf = nftnl_rule_expr_bitwise_snprintf, + .xml_parse = nftnl_rule_expr_bitwise_xml_parse, + .json_parse = nftnl_rule_expr_bitwise_json_parse, }; diff --git a/src/expr/byteorder.c b/src/expr/byteorder.c index 81e5278..c37e56d 100644 --- a/src/expr/byteorder.c +++ b/src/expr/byteorder.c @@ -21,7 +21,7 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_byteorder { +struct nftnl_expr_byteorder { enum nft_registers sreg; enum nft_registers dreg; enum nft_byteorder_ops op; @@ -30,25 +30,25 @@ struct nft_expr_byteorder { }; static int -nft_rule_expr_byteorder_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_byteorder_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_byteorder *byteorder = nft_expr_data(e); + struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_BYTEORDER_SREG: + case NFTNL_EXPR_BYTEORDER_SREG: byteorder->sreg = *((uint32_t *)data); break; - case NFT_EXPR_BYTEORDER_DREG: + case NFTNL_EXPR_BYTEORDER_DREG: byteorder->dreg = *((uint32_t *)data); break; - case NFT_EXPR_BYTEORDER_OP: + case NFTNL_EXPR_BYTEORDER_OP: byteorder->op = *((uint32_t *)data); break; - case NFT_EXPR_BYTEORDER_LEN: + case NFTNL_EXPR_BYTEORDER_LEN: byteorder->len = *((unsigned int *)data); break; - case NFT_EXPR_BYTEORDER_SIZE: + case NFTNL_EXPR_BYTEORDER_SIZE: byteorder->size = *((unsigned int *)data); break; default: @@ -58,32 +58,32 @@ nft_rule_expr_byteorder_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_byteorder_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_byteorder_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_byteorder *byteorder = nft_expr_data(e); + struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_BYTEORDER_SREG: + case NFTNL_EXPR_BYTEORDER_SREG: *data_len = sizeof(byteorder->sreg); return &byteorder->sreg; - case NFT_EXPR_BYTEORDER_DREG: + case NFTNL_EXPR_BYTEORDER_DREG: *data_len = sizeof(byteorder->dreg); return &byteorder->dreg; - case NFT_EXPR_BYTEORDER_OP: + case NFTNL_EXPR_BYTEORDER_OP: *data_len = sizeof(byteorder->op); return &byteorder->op; - case NFT_EXPR_BYTEORDER_LEN: + case NFTNL_EXPR_BYTEORDER_LEN: *data_len = sizeof(byteorder->len); return &byteorder->len; - case NFT_EXPR_BYTEORDER_SIZE: + case NFTNL_EXPR_BYTEORDER_SIZE: *data_len = sizeof(byteorder->size); return &byteorder->size; } return NULL; } -static int nft_rule_expr_byteorder_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_byteorder_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -107,66 +107,66 @@ static int nft_rule_expr_byteorder_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_byteorder_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_byteorder_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_byteorder *byteorder = nft_expr_data(e); + struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_BYTEORDER_SREG)) { + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_SREG)) { mnl_attr_put_u32(nlh, NFTA_BYTEORDER_SREG, htonl(byteorder->sreg)); } - if (e->flags & (1 << NFT_EXPR_BYTEORDER_DREG)) { + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_DREG)) { mnl_attr_put_u32(nlh, NFTA_BYTEORDER_DREG, htonl(byteorder->dreg)); } - if (e->flags & (1 << NFT_EXPR_BYTEORDER_OP)) { + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_OP)) { mnl_attr_put_u32(nlh, NFTA_BYTEORDER_OP, htonl(byteorder->op)); } - if (e->flags & (1 << NFT_EXPR_BYTEORDER_LEN)) { + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_LEN)) { mnl_attr_put_u32(nlh, NFTA_BYTEORDER_LEN, htonl(byteorder->len)); } - if (e->flags & (1 << NFT_EXPR_BYTEORDER_SIZE)) { + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_SIZE)) { mnl_attr_put_u32(nlh, NFTA_BYTEORDER_SIZE, htonl(byteorder->size)); } } static int -nft_rule_expr_byteorder_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_byteorder_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_byteorder *byteorder = nft_expr_data(e); + struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e); struct nlattr *tb[NFTA_BYTEORDER_MAX+1] = {}; int ret = 0; - if (mnl_attr_parse_nested(attr, nft_rule_expr_byteorder_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_byteorder_cb, tb) < 0) return -1; if (tb[NFTA_BYTEORDER_SREG]) { byteorder->sreg = ntohl(mnl_attr_get_u32(tb[NFTA_BYTEORDER_SREG])); - e->flags |= (1 << NFT_EXPR_BYTEORDER_SREG); + e->flags |= (1 << NFTNL_EXPR_BYTEORDER_SREG); } if (tb[NFTA_BYTEORDER_DREG]) { byteorder->dreg = ntohl(mnl_attr_get_u32(tb[NFTA_BYTEORDER_DREG])); - e->flags |= (1 << NFT_EXPR_BYTEORDER_DREG); + e->flags |= (1 << NFTNL_EXPR_BYTEORDER_DREG); } if (tb[NFTA_BYTEORDER_OP]) { byteorder->op = ntohl(mnl_attr_get_u32(tb[NFTA_BYTEORDER_OP])); - e->flags |= (1 << NFT_EXPR_BYTEORDER_OP); + e->flags |= (1 << NFTNL_EXPR_BYTEORDER_OP); } if (tb[NFTA_BYTEORDER_LEN]) { byteorder->len = ntohl(mnl_attr_get_u32(tb[NFTA_BYTEORDER_LEN])); - e->flags |= (1 << NFT_EXPR_BYTEORDER_LEN); + e->flags |= (1 << NFTNL_EXPR_BYTEORDER_LEN); } if (tb[NFTA_BYTEORDER_SIZE]) { byteorder->size = ntohl(mnl_attr_get_u32(tb[NFTA_BYTEORDER_SIZE])); - e->flags |= (1 << NFT_EXPR_BYTEORDER_SIZE); + e->flags |= (1 << NFTNL_EXPR_BYTEORDER_SIZE); } return ret; @@ -185,7 +185,7 @@ static const char *bo2str(uint32_t type) return expr_byteorder_str[type]; } -static inline int nft_str2ntoh(const char *op) +static inline int nftnl_str2ntoh(const char *op) { if (strcmp(op, "ntoh") == 0) return NFT_BYTEORDER_NTOH; @@ -198,34 +198,34 @@ static inline int nft_str2ntoh(const char *op) } static int -nft_rule_expr_byteorder_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_byteorder_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *op; uint32_t sreg, dreg, len, size; int ntoh; - if (nft_jansson_parse_reg(root, "sreg", NFT_TYPE_U32, &sreg, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_SREG, sreg); + if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &sreg, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_SREG, sreg); - if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, &dreg, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_DREG, dreg); + if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &dreg, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_DREG, dreg); - op = nft_jansson_parse_str(root, "op", err); + op = nftnl_jansson_parse_str(root, "op", err); if (op != NULL) { - ntoh = nft_str2ntoh(op); + ntoh = nftnl_str2ntoh(op); if (ntoh < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_OP, ntoh); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_OP, ntoh); } - if (nft_jansson_parse_val(root, "len", NFT_TYPE_U32, &len, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_LEN, len); + if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &len, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_LEN, len); - if (nft_jansson_parse_val(root, "size", NFT_TYPE_U32, &size, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_SIZE, size); + if (nftnl_jansson_parse_val(root, "size", NFTNL_TYPE_U32, &size, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_SIZE, size); return 0; #else @@ -235,39 +235,39 @@ nft_rule_expr_byteorder_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_byteorder_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_byteorder_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *op; int32_t ntoh; uint32_t sreg, dreg, len, size; - if (nft_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_SREG, sreg); + if (nftnl_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_SREG, sreg); - if (nft_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND, NFT_XML_MAND, + if (nftnl_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND, NFTNL_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_DREG, dreg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_DREG, dreg); - op = nft_mxml_str_parse(tree, "op", MXML_DESCEND_FIRST, NFT_XML_MAND, + op = nftnl_mxml_str_parse(tree, "op", MXML_DESCEND_FIRST, NFTNL_XML_MAND, err); if (op != NULL) { - ntoh = nft_str2ntoh(op); + ntoh = nftnl_str2ntoh(op); if (ntoh < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_OP, ntoh); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_OP, ntoh); } - if (nft_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, - &len, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_LEN, len); + if (nftnl_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, + &len, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_LEN, len); - if (nft_mxml_num_parse(tree, "size", MXML_DESCEND_FIRST, BASE_DEC, - &size, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_SIZE, size); + if (nftnl_mxml_num_parse(tree, "size", MXML_DESCEND_FIRST, BASE_DEC, + &size, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_SIZE, size); return 0; #else @@ -276,30 +276,30 @@ nft_rule_expr_byteorder_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, #endif } -static int nft_rule_expr_byteorder_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_byteorder_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_byteorder *byteorder = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFT_EXPR_BYTEORDER_SREG)) - nft_buf_u32(&b, type, byteorder->sreg, SREG); - if (e->flags & (1 << NFT_EXPR_BYTEORDER_DREG)) - nft_buf_u32(&b, type, byteorder->dreg, DREG); - if (e->flags & (1 << NFT_EXPR_BYTEORDER_OP)) - nft_buf_str(&b, type, bo2str(byteorder->op), OP); - if (e->flags & (1 << NFT_EXPR_BYTEORDER_LEN)) - nft_buf_u32(&b, type, byteorder->len, LEN); - if (e->flags & (1 << NFT_EXPR_BYTEORDER_SIZE)) - nft_buf_u32(&b, type, byteorder->size, SIZE); - - return nft_buf_done(&b); + struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); + + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_SREG)) + nftnl_buf_u32(&b, type, byteorder->sreg, SREG); + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_DREG)) + nftnl_buf_u32(&b, type, byteorder->dreg, DREG); + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_OP)) + nftnl_buf_str(&b, type, bo2str(byteorder->op), OP); + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_LEN)) + nftnl_buf_u32(&b, type, byteorder->len, LEN); + if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_SIZE)) + nftnl_buf_u32(&b, type, byteorder->size, SIZE); + + return nftnl_buf_done(&b); } -static int nft_rule_expr_byteorder_snprintf_default(char *buf, size_t size, - struct nft_rule_expr *e) +static int nftnl_rule_expr_byteorder_snprintf_default(char *buf, size_t size, + struct nftnl_rule_expr *e) { - struct nft_expr_byteorder *byteorder = nft_expr_data(e); + struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e); int len = size, offset = 0, ret; ret = snprintf(buf, len, "reg %u = %s(reg %u, %u, %u) ", @@ -311,15 +311,15 @@ static int nft_rule_expr_byteorder_snprintf_default(char *buf, size_t size, } static int -nft_rule_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_byteorder_snprintf_default(buf, size, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_byteorder_export(buf, size, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_byteorder_snprintf_default(buf, size, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_byteorder_export(buf, size, e, type); default: break; } @@ -328,13 +328,13 @@ nft_rule_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type, struct expr_ops expr_ops_byteorder = { .name = "byteorder", - .alloc_len = sizeof(struct nft_expr_byteorder), + .alloc_len = sizeof(struct nftnl_expr_byteorder), .max_attr = NFTA_BYTEORDER_MAX, - .set = nft_rule_expr_byteorder_set, - .get = nft_rule_expr_byteorder_get, - .parse = nft_rule_expr_byteorder_parse, - .build = nft_rule_expr_byteorder_build, - .snprintf = nft_rule_expr_byteorder_snprintf, - .xml_parse = nft_rule_expr_byteorder_xml_parse, - .json_parse = nft_rule_expr_byteorder_json_parse, + .set = nftnl_rule_expr_byteorder_set, + .get = nftnl_rule_expr_byteorder_get, + .parse = nftnl_rule_expr_byteorder_parse, + .build = nftnl_rule_expr_byteorder_build, + .snprintf = nftnl_rule_expr_byteorder_snprintf, + .xml_parse = nftnl_rule_expr_byteorder_xml_parse, + .json_parse = nftnl_rule_expr_byteorder_json_parse, }; diff --git a/src/expr/cmp.c b/src/expr/cmp.c index 3536332..83b9afc 100644 --- a/src/expr/cmp.c +++ b/src/expr/cmp.c @@ -22,26 +22,26 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_cmp { - union nft_data_reg data; +struct nftnl_expr_cmp { + union nftnl_data_reg data; enum nft_registers sreg; enum nft_cmp_ops op; }; static int -nft_rule_expr_cmp_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_cmp_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_cmp *cmp = nft_expr_data(e); + struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_CMP_SREG: + case NFTNL_EXPR_CMP_SREG: cmp->sreg = *((uint32_t *)data); break; - case NFT_EXPR_CMP_OP: + case NFTNL_EXPR_CMP_OP: cmp->op = *((uint32_t *)data); break; - case NFT_EXPR_CMP_DATA: + case NFTNL_EXPR_CMP_DATA: memcpy(&cmp->data.val, data, data_len); cmp->data.len = data_len; break; @@ -52,26 +52,26 @@ nft_rule_expr_cmp_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_cmp_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_cmp_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_cmp *cmp = nft_expr_data(e); + struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_CMP_SREG: + case NFTNL_EXPR_CMP_SREG: *data_len = sizeof(cmp->sreg); return &cmp->sreg; - case NFT_EXPR_CMP_OP: + case NFTNL_EXPR_CMP_OP: *data_len = sizeof(cmp->op); return &cmp->op; - case NFT_EXPR_CMP_DATA: + case NFTNL_EXPR_CMP_DATA: *data_len = cmp->data.len; return &cmp->data.val; } return NULL; } -static int nft_rule_expr_cmp_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_cmp_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -96,15 +96,15 @@ static int nft_rule_expr_cmp_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_cmp_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_cmp_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_cmp *cmp = nft_expr_data(e); + struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_CMP_SREG)) + if (e->flags & (1 << NFTNL_EXPR_CMP_SREG)) mnl_attr_put_u32(nlh, NFTA_CMP_SREG, htonl(cmp->sreg)); - if (e->flags & (1 << NFT_EXPR_CMP_OP)) + if (e->flags & (1 << NFTNL_EXPR_CMP_OP)) mnl_attr_put_u32(nlh, NFTA_CMP_OP, htonl(cmp->op)); - if (e->flags & (1 << NFT_EXPR_CMP_DATA)) { + if (e->flags & (1 << NFTNL_EXPR_CMP_DATA)) { struct nlattr *nest; nest = mnl_attr_nest_start(nlh, NFTA_CMP_DATA); @@ -114,13 +114,13 @@ nft_rule_expr_cmp_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) } static int -nft_rule_expr_cmp_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_cmp_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_cmp *cmp = nft_expr_data(e); + struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); struct nlattr *tb[NFTA_CMP_MAX+1] = {}; int ret = 0; - if (mnl_attr_parse_nested(attr, nft_rule_expr_cmp_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_cmp_cb, tb) < 0) return -1; if (tb[NFTA_CMP_SREG]) { @@ -132,7 +132,7 @@ nft_rule_expr_cmp_parse(struct nft_rule_expr *e, struct nlattr *attr) e->flags |= (1 << NFTA_CMP_OP); } if (tb[NFTA_CMP_DATA]) { - ret = nft_parse_data(&cmp->data, tb[NFTA_CMP_DATA], NULL); + ret = nftnl_parse_data(&cmp->data, tb[NFTA_CMP_DATA], NULL); e->flags |= (1 << NFTA_CMP_DATA); } @@ -156,7 +156,7 @@ static const char *cmp2str(uint32_t op) return expr_cmp_str[op]; } -static inline int nft_str2cmp(const char *op) +static inline int nftnl_str2cmp(const char *op) { if (strcmp(op, "eq") == 0) return NFT_CMP_EQ; @@ -176,31 +176,31 @@ static inline int nft_str2cmp(const char *op) } } -static int nft_rule_expr_cmp_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +static int nftnl_rule_expr_cmp_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING - struct nft_expr_cmp *cmp = nft_expr_data(e); + struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); const char *op; uint32_t uval32; int base; - if (nft_jansson_parse_val(root, "sreg", NFT_TYPE_U32, &uval32, + if (nftnl_jansson_parse_val(root, "sreg", NFTNL_TYPE_U32, &uval32, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_CMP_SREG, uval32); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CMP_SREG, uval32); - op = nft_jansson_parse_str(root, "op", err); + op = nftnl_jansson_parse_str(root, "op", err); if (op != NULL) { - base = nft_str2cmp(op); + base = nftnl_str2cmp(op); if (base < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_CMP_OP, base); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CMP_OP, base); } - if (nft_jansson_data_reg_parse(root, "data", + if (nftnl_jansson_data_reg_parse(root, "data", &cmp->data, err) == DATA_VALUE) - e->flags |= (1 << NFT_EXPR_CMP_DATA); + e->flags |= (1 << NFTNL_EXPR_CMP_DATA); return 0; #else @@ -209,33 +209,33 @@ static int nft_rule_expr_cmp_json_parse(struct nft_rule_expr *e, json_t *root, #endif } -static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +static int nftnl_rule_expr_cmp_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING - struct nft_expr_cmp *cmp = nft_expr_data(e); + struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); const char *op; int32_t op_value; uint32_t sreg; - if (nft_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_CMP_SREG, sreg); + if (nftnl_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CMP_SREG, sreg); - op = nft_mxml_str_parse(tree, "op", MXML_DESCEND_FIRST, NFT_XML_MAND, + op = nftnl_mxml_str_parse(tree, "op", MXML_DESCEND_FIRST, NFTNL_XML_MAND, err); if (op != NULL) { - op_value = nft_str2cmp(op); + op_value = nftnl_str2cmp(op); if (op_value < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_CMP_OP, op_value); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CMP_OP, op_value); } - if (nft_mxml_data_reg_parse(tree, "data", - &cmp->data, NFT_XML_MAND, + if (nftnl_mxml_data_reg_parse(tree, "data", + &cmp->data, NFTNL_XML_MAND, err) == DATA_VALUE) - e->flags |= (1 << NFT_EXPR_CMP_DATA); + e->flags |= (1 << NFTNL_EXPR_CMP_DATA); return 0; #else @@ -244,49 +244,49 @@ static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, mxml_node_t *tre #endif } -static int nft_rule_expr_cmp_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_cmp_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_cmp *cmp = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_CMP_SREG)) - nft_buf_u32(&b, type, cmp->sreg, SREG); - if (e->flags & (1 << NFT_EXPR_CMP_OP)) - nft_buf_str(&b, type, cmp2str(cmp->op), OP); - if (e->flags & (1 << NFT_EXPR_CMP_DATA)) - nft_buf_reg(&b, type, &cmp->data, DATA_VALUE, DATA); + if (e->flags & (1 << NFTNL_EXPR_CMP_SREG)) + nftnl_buf_u32(&b, type, cmp->sreg, SREG); + if (e->flags & (1 << NFTNL_EXPR_CMP_OP)) + nftnl_buf_str(&b, type, cmp2str(cmp->op), OP); + if (e->flags & (1 << NFTNL_EXPR_CMP_DATA)) + nftnl_buf_reg(&b, type, &cmp->data, DATA_VALUE, DATA); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } -static int nft_rule_expr_cmp_snprintf_default(char *buf, size_t size, - struct nft_rule_expr *e) +static int nftnl_rule_expr_cmp_snprintf_default(char *buf, size_t size, + struct nftnl_rule_expr *e) { - struct nft_expr_cmp *cmp = nft_expr_data(e); + struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); int len = size, offset = 0, ret; ret = snprintf(buf, len, "%s reg %u ", expr_cmp_str[cmp->op], cmp->sreg); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_data_reg_snprintf(buf+offset, len, &cmp->data, - NFT_OUTPUT_DEFAULT, 0, DATA_VALUE); + ret = nftnl_data_reg_snprintf(buf+offset, len, &cmp->data, + NFTNL_OUTPUT_DEFAULT, 0, DATA_VALUE); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); return offset; } static int -nft_rule_expr_cmp_snprintf(char *buf, size_t size, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_cmp_snprintf(char *buf, size_t size, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_cmp_snprintf_default(buf, size, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_cmp_export(buf, size, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_cmp_snprintf_default(buf, size, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_cmp_export(buf, size, e, type); default: break; } @@ -295,13 +295,13 @@ nft_rule_expr_cmp_snprintf(char *buf, size_t size, uint32_t type, struct expr_ops expr_ops_cmp = { .name = "cmp", - .alloc_len = sizeof(struct nft_expr_cmp), + .alloc_len = sizeof(struct nftnl_expr_cmp), .max_attr = NFTA_CMP_MAX, - .set = nft_rule_expr_cmp_set, - .get = nft_rule_expr_cmp_get, - .parse = nft_rule_expr_cmp_parse, - .build = nft_rule_expr_cmp_build, - .snprintf = nft_rule_expr_cmp_snprintf, - .xml_parse = nft_rule_expr_cmp_xml_parse, - .json_parse = nft_rule_expr_cmp_json_parse, + .set = nftnl_rule_expr_cmp_set, + .get = nftnl_rule_expr_cmp_get, + .parse = nftnl_rule_expr_cmp_parse, + .build = nftnl_rule_expr_cmp_build, + .snprintf = nftnl_rule_expr_cmp_snprintf, + .xml_parse = nftnl_rule_expr_cmp_xml_parse, + .json_parse = nftnl_rule_expr_cmp_json_parse, }; diff --git a/src/expr/counter.c b/src/expr/counter.c index 55fe526..b5a9644 100644 --- a/src/expr/counter.c +++ b/src/expr/counter.c @@ -22,22 +22,22 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_counter { +struct nftnl_expr_counter { uint64_t pkts; uint64_t bytes; }; static int -nft_rule_expr_counter_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_counter_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_counter *ctr = nft_expr_data(e); + struct nftnl_expr_counter *ctr = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_CTR_BYTES: + case NFTNL_EXPR_CTR_BYTES: ctr->bytes = *((uint64_t *)data); break; - case NFT_EXPR_CTR_PACKETS: + case NFTNL_EXPR_CTR_PACKETS: ctr->pkts = *((uint64_t *)data); break; default: @@ -47,23 +47,23 @@ nft_rule_expr_counter_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_counter_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_counter_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_counter *ctr = nft_expr_data(e); + struct nftnl_expr_counter *ctr = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_CTR_BYTES: + case NFTNL_EXPR_CTR_BYTES: *data_len = sizeof(ctr->bytes); return &ctr->bytes; - case NFT_EXPR_CTR_PACKETS: + case NFTNL_EXPR_CTR_PACKETS: *data_len = sizeof(ctr->pkts); return &ctr->pkts; } return NULL; } -static int nft_rule_expr_counter_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_counter_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -84,51 +84,51 @@ static int nft_rule_expr_counter_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_counter_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_counter_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_counter *ctr = nft_expr_data(e); + struct nftnl_expr_counter *ctr = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_CTR_BYTES)) + if (e->flags & (1 << NFTNL_EXPR_CTR_BYTES)) mnl_attr_put_u64(nlh, NFTA_COUNTER_BYTES, htobe64(ctr->bytes)); - if (e->flags & (1 << NFT_EXPR_CTR_PACKETS)) + if (e->flags & (1 << NFTNL_EXPR_CTR_PACKETS)) mnl_attr_put_u64(nlh, NFTA_COUNTER_PACKETS, htobe64(ctr->pkts)); } static int -nft_rule_expr_counter_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_counter_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_counter *ctr = nft_expr_data(e); + struct nftnl_expr_counter *ctr = nftnl_expr_data(e); struct nlattr *tb[NFTA_COUNTER_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_counter_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_counter_cb, tb) < 0) return -1; if (tb[NFTA_COUNTER_BYTES]) { ctr->bytes = be64toh(mnl_attr_get_u64(tb[NFTA_COUNTER_BYTES])); - e->flags |= (1 << NFT_EXPR_CTR_BYTES); + e->flags |= (1 << NFTNL_EXPR_CTR_BYTES); } if (tb[NFTA_COUNTER_PACKETS]) { ctr->pkts = be64toh(mnl_attr_get_u64(tb[NFTA_COUNTER_PACKETS])); - e->flags |= (1 << NFT_EXPR_CTR_PACKETS); + e->flags |= (1 << NFTNL_EXPR_CTR_PACKETS); } return 0; } static int -nft_rule_expr_counter_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_counter_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING uint64_t uval64; - if (nft_jansson_parse_val(root, "pkts", NFT_TYPE_U64, &uval64, + if (nftnl_jansson_parse_val(root, "pkts", NFTNL_TYPE_U64, &uval64, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_CTR_PACKETS, uval64); + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_CTR_PACKETS, uval64); - if (nft_jansson_parse_val(root, "bytes", NFT_TYPE_U64, &uval64, + if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &uval64, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_CTR_BYTES, uval64); + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_CTR_BYTES, uval64); return 0; #else @@ -138,19 +138,19 @@ nft_rule_expr_counter_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_counter_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_counter_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING uint64_t pkts, bytes; - if (nft_mxml_num_parse(tree, "pkts", MXML_DESCEND_FIRST, BASE_DEC, - &pkts, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_CTR_PACKETS, pkts); + if (nftnl_mxml_num_parse(tree, "pkts", MXML_DESCEND_FIRST, BASE_DEC, + &pkts, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_CTR_PACKETS, pkts); - if (nft_mxml_num_parse(tree, "bytes", MXML_DESCEND_FIRST, BASE_DEC, - &bytes, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_CTR_BYTES, bytes); + if (nftnl_mxml_num_parse(tree, "bytes", MXML_DESCEND_FIRST, BASE_DEC, + &bytes, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_CTR_BYTES, bytes); return 0; #else @@ -159,39 +159,39 @@ nft_rule_expr_counter_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, #endif } -static int nft_rule_expr_counter_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_counter_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_counter *ctr = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_counter *ctr = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_CTR_PACKETS)) - nft_buf_u64(&b, type, ctr->pkts, PKTS); - if (e->flags & (1 << NFT_EXPR_CTR_BYTES)) - nft_buf_u64(&b, type, ctr->bytes, BYTES); + if (e->flags & (1 << NFTNL_EXPR_CTR_PACKETS)) + nftnl_buf_u64(&b, type, ctr->pkts, PKTS); + if (e->flags & (1 << NFTNL_EXPR_CTR_BYTES)) + nftnl_buf_u64(&b, type, ctr->bytes, BYTES); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } -static int nft_rule_expr_counter_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e) +static int nftnl_rule_expr_counter_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e) { - struct nft_expr_counter *ctr = nft_expr_data(e); + struct nftnl_expr_counter *ctr = nftnl_expr_data(e); return snprintf(buf, len, "pkts %"PRIu64" bytes %"PRIu64" ", ctr->pkts, ctr->bytes); } -static int nft_rule_expr_counter_snprintf(char *buf, size_t len, uint32_t type, +static int nftnl_rule_expr_counter_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, - struct nft_rule_expr *e) + struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_counter_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_counter_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_counter_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_counter_export(buf, len, e, type); default: break; } @@ -200,13 +200,13 @@ static int nft_rule_expr_counter_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_counter = { .name = "counter", - .alloc_len = sizeof(struct nft_expr_counter), + .alloc_len = sizeof(struct nftnl_expr_counter), .max_attr = NFTA_COUNTER_MAX, - .set = nft_rule_expr_counter_set, - .get = nft_rule_expr_counter_get, - .parse = nft_rule_expr_counter_parse, - .build = nft_rule_expr_counter_build, - .snprintf = nft_rule_expr_counter_snprintf, - .xml_parse = nft_rule_expr_counter_xml_parse, - .json_parse = nft_rule_expr_counter_json_parse, + .set = nftnl_rule_expr_counter_set, + .get = nftnl_rule_expr_counter_get, + .parse = nftnl_rule_expr_counter_parse, + .build = nftnl_rule_expr_counter_build, + .snprintf = nftnl_rule_expr_counter_snprintf, + .xml_parse = nftnl_rule_expr_counter_xml_parse, + .json_parse = nftnl_rule_expr_counter_json_parse, }; diff --git a/src/expr/ct.c b/src/expr/ct.c index b808e03..73ae33a 100644 --- a/src/expr/ct.c +++ b/src/expr/ct.c @@ -21,7 +21,7 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_ct { +struct nftnl_expr_ct { enum nft_ct_keys key; enum nft_registers dreg; enum nft_registers sreg; @@ -36,22 +36,22 @@ struct nft_expr_ct { #endif static int -nft_rule_expr_ct_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_ct_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_ct *ct = nft_expr_data(e); + struct nftnl_expr_ct *ct = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_CT_KEY: + case NFTNL_EXPR_CT_KEY: ct->key = *((uint32_t *)data); break; - case NFT_EXPR_CT_DIR: + case NFTNL_EXPR_CT_DIR: ct->dir = *((uint8_t *)data); break; - case NFT_EXPR_CT_DREG: + case NFTNL_EXPR_CT_DREG: ct->dreg = *((uint32_t *)data); break; - case NFT_EXPR_CT_SREG: + case NFTNL_EXPR_CT_SREG: ct->sreg = *((uint32_t *)data); break; default: @@ -61,29 +61,29 @@ nft_rule_expr_ct_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_ct_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_ct_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_ct *ct = nft_expr_data(e); + struct nftnl_expr_ct *ct = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_CT_KEY: + case NFTNL_EXPR_CT_KEY: *data_len = sizeof(ct->key); return &ct->key; - case NFT_EXPR_CT_DIR: + case NFTNL_EXPR_CT_DIR: *data_len = sizeof(ct->dir); return &ct->dir; - case NFT_EXPR_CT_DREG: + case NFTNL_EXPR_CT_DREG: *data_len = sizeof(ct->dreg); return &ct->dreg; - case NFT_EXPR_CT_SREG: + case NFTNL_EXPR_CT_SREG: *data_len = sizeof(ct->sreg); return &ct->sreg; } return NULL; } -static int nft_rule_expr_ct_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_ct_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -109,44 +109,44 @@ static int nft_rule_expr_ct_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_ct_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_ct_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_ct *ct = nft_expr_data(e); + struct nftnl_expr_ct *ct = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_CT_KEY)) + if (e->flags & (1 << NFTNL_EXPR_CT_KEY)) mnl_attr_put_u32(nlh, NFTA_CT_KEY, htonl(ct->key)); - if (e->flags & (1 << NFT_EXPR_CT_DREG)) + if (e->flags & (1 << NFTNL_EXPR_CT_DREG)) mnl_attr_put_u32(nlh, NFTA_CT_DREG, htonl(ct->dreg)); - if (e->flags & (1 << NFT_EXPR_CT_DIR)) + if (e->flags & (1 << NFTNL_EXPR_CT_DIR)) mnl_attr_put_u8(nlh, NFTA_CT_DIRECTION, ct->dir); - if (e->flags & (1 << NFT_EXPR_CT_SREG)) + if (e->flags & (1 << NFTNL_EXPR_CT_SREG)) mnl_attr_put_u32(nlh, NFTA_CT_SREG, htonl(ct->sreg)); } static int -nft_rule_expr_ct_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_ct_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_ct *ct = nft_expr_data(e); + struct nftnl_expr_ct *ct = nftnl_expr_data(e); struct nlattr *tb[NFTA_CT_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_ct_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_ct_cb, tb) < 0) return -1; if (tb[NFTA_CT_KEY]) { ct->key = ntohl(mnl_attr_get_u32(tb[NFTA_CT_KEY])); - e->flags |= (1 << NFT_EXPR_CT_KEY); + e->flags |= (1 << NFTNL_EXPR_CT_KEY); } if (tb[NFTA_CT_DREG]) { ct->dreg = ntohl(mnl_attr_get_u32(tb[NFTA_CT_DREG])); - e->flags |= (1 << NFT_EXPR_CT_DREG); + e->flags |= (1 << NFTNL_EXPR_CT_DREG); } if (tb[NFTA_CT_SREG]) { ct->sreg = ntohl(mnl_attr_get_u32(tb[NFTA_CT_SREG])); - e->flags |= (1 << NFT_EXPR_CT_SREG); + e->flags |= (1 << NFTNL_EXPR_CT_SREG); } if (tb[NFTA_CT_DIRECTION]) { ct->dir = mnl_attr_get_u8(tb[NFTA_CT_DIRECTION]); - e->flags |= (1 << NFT_EXPR_CT_DIR); + e->flags |= (1 << NFTNL_EXPR_CT_DIR); } return 0; @@ -216,8 +216,8 @@ static inline int str2ctdir(const char *str, uint8_t *ctdir) return -1; } -static int nft_rule_expr_ct_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +static int nftnl_rule_expr_ct_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *key_str, *dir_str; @@ -225,29 +225,29 @@ static int nft_rule_expr_ct_json_parse(struct nft_rule_expr *e, json_t *root, uint8_t dir; int key; - if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_CT_DREG, reg); + if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CT_DREG, reg); - if (nft_jansson_parse_reg(root, "sreg", NFT_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_CT_SREG, reg); + if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, ®, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CT_SREG, reg); - key_str = nft_jansson_parse_str(root, "key", err); + key_str = nftnl_jansson_parse_str(root, "key", err); if (key_str != NULL) { key = str2ctkey(key_str); if (key < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_CT_KEY, key); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CT_KEY, key); } - dir_str = nft_jansson_parse_str(root, "dir", err); + dir_str = nftnl_jansson_parse_str(root, "dir", err); if (dir_str != NULL) { if (str2ctdir(dir_str, &dir) != 0) { err->node_name = "dir"; - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; goto err; } - nft_rule_expr_set_u8(e, NFT_EXPR_CT_DIR, dir); + nftnl_rule_expr_set_u8(e, NFTNL_EXPR_CT_DIR, dir); } return 0; @@ -261,8 +261,8 @@ err: } -static int nft_rule_expr_ct_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +static int nftnl_rule_expr_ct_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *key_str, *dir_str; @@ -270,32 +270,32 @@ static int nft_rule_expr_ct_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree uint8_t dir; uint32_t dreg, sreg; - if (nft_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, - NFT_XML_OPT, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_CT_DREG, dreg); + if (nftnl_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, + NFTNL_XML_OPT, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CT_DREG, dreg); - if (nft_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, - NFT_XML_OPT, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_CT_SREG, sreg); + if (nftnl_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, + NFTNL_XML_OPT, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CT_SREG, sreg); - key_str = nft_mxml_str_parse(tree, "key", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + key_str = nftnl_mxml_str_parse(tree, "key", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (key_str != NULL) { key = str2ctkey(key_str); if (key < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_CT_KEY, key); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CT_KEY, key); } - dir_str = nft_mxml_str_parse(tree, "dir", MXML_DESCEND_FIRST, - NFT_XML_OPT, err); + dir_str = nftnl_mxml_str_parse(tree, "dir", MXML_DESCEND_FIRST, + NFTNL_XML_OPT, err); if (dir_str != NULL) { if (str2ctdir(dir_str, &dir) != 0) { err->node_name = "dir"; - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; goto err; } - nft_rule_expr_set_u8(e, NFT_EXPR_CT_DIR, dir); + nftnl_rule_expr_set_u8(e, NFTNL_EXPR_CT_DIR, dir); } return 0; @@ -309,42 +309,42 @@ err: } static int -nft_expr_ct_export(char *buf, size_t size, struct nft_rule_expr *e, int type) +nftnl_expr_ct_export(char *buf, size_t size, struct nftnl_rule_expr *e, int type) { - struct nft_expr_ct *ct = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFT_EXPR_CT_SREG)) - nft_buf_u32(&b, type, ct->sreg, SREG); - if (e->flags & (1 << NFT_EXPR_CT_DREG)) - nft_buf_u32(&b, type, ct->dreg, DREG); - if (e->flags & (1 << NFT_EXPR_CT_KEY)) - nft_buf_str(&b, type, ctkey2str(ct->key), KEY); - if (e->flags & (1 << NFT_EXPR_CT_DIR)) - nft_buf_str(&b, type, ctdir2str(ct->dir), DIR); - - return nft_buf_done(&b); + struct nftnl_expr_ct *ct = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); + + if (e->flags & (1 << NFTNL_EXPR_CT_SREG)) + nftnl_buf_u32(&b, type, ct->sreg, SREG); + if (e->flags & (1 << NFTNL_EXPR_CT_DREG)) + nftnl_buf_u32(&b, type, ct->dreg, DREG); + if (e->flags & (1 << NFTNL_EXPR_CT_KEY)) + nftnl_buf_str(&b, type, ctkey2str(ct->key), KEY); + if (e->flags & (1 << NFTNL_EXPR_CT_DIR)) + nftnl_buf_str(&b, type, ctdir2str(ct->dir), DIR); + + return nftnl_buf_done(&b); } static int -nft_expr_ct_snprintf_default(char *buf, size_t size, struct nft_rule_expr *e) +nftnl_expr_ct_snprintf_default(char *buf, size_t size, struct nftnl_rule_expr *e) { int ret, len = size, offset = 0; - struct nft_expr_ct *ct = nft_expr_data(e); + struct nftnl_expr_ct *ct = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_CT_SREG)) { + if (e->flags & (1 << NFTNL_EXPR_CT_SREG)) { ret = snprintf(buf, size, "set %s with reg %u ", ctkey2str(ct->key), ct->sreg); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (e->flags & (1 << NFT_EXPR_CT_DREG)) { + if (e->flags & (1 << NFTNL_EXPR_CT_DREG)) { ret = snprintf(buf, len, "load %s => reg %u ", ctkey2str(ct->key), ct->dreg); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (nft_rule_expr_is_set(e, NFT_EXPR_CT_DIR)) { + if (nftnl_rule_expr_is_set(e, NFTNL_EXPR_CT_DIR)) { ret = snprintf(buf+offset, len, ", dir %s ", ctdir2str(ct->dir)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -354,15 +354,15 @@ nft_expr_ct_snprintf_default(char *buf, size_t size, struct nft_rule_expr *e) } static int -nft_rule_expr_ct_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_ct_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_expr_ct_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_expr_ct_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_expr_ct_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_expr_ct_export(buf, len, e, type); default: break; } @@ -371,13 +371,13 @@ nft_rule_expr_ct_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_ct = { .name = "ct", - .alloc_len = sizeof(struct nft_expr_ct), + .alloc_len = sizeof(struct nftnl_expr_ct), .max_attr = NFTA_CT_MAX, - .set = nft_rule_expr_ct_set, - .get = nft_rule_expr_ct_get, - .parse = nft_rule_expr_ct_parse, - .build = nft_rule_expr_ct_build, - .snprintf = nft_rule_expr_ct_snprintf, - .xml_parse = nft_rule_expr_ct_xml_parse, - .json_parse = nft_rule_expr_ct_json_parse, + .set = nftnl_rule_expr_ct_set, + .get = nftnl_rule_expr_ct_get, + .parse = nftnl_rule_expr_ct_parse, + .build = nftnl_rule_expr_ct_build, + .snprintf = nftnl_rule_expr_ct_snprintf, + .xml_parse = nftnl_rule_expr_ct_xml_parse, + .json_parse = nftnl_rule_expr_ct_json_parse, }; diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c index b375db4..b85d2ef 100644 --- a/src/expr/data_reg.c +++ b/src/expr/data_reg.c @@ -25,28 +25,28 @@ #include "internal.h" #ifdef JSON_PARSING -static int nft_data_reg_verdict_json_parse(union nft_data_reg *reg, json_t *data, - struct nft_parse_err *err) +static int nftnl_data_reg_verdict_json_parse(union nftnl_data_reg *reg, json_t *data, + struct nftnl_parse_err *err) { int verdict; const char *verdict_str; const char *chain; - verdict_str = nft_jansson_parse_str(data, "verdict", err); + verdict_str = nftnl_jansson_parse_str(data, "verdict", err); if (verdict_str == NULL) return DATA_NONE; - if (nft_str2verdict(verdict_str, &verdict) != 0) { + if (nftnl_str2verdict(verdict_str, &verdict) != 0) { err->node_name = "verdict"; - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; errno = EINVAL; return -1; } reg->verdict = (uint32_t)verdict; - if (nft_jansson_node_exist(data, "chain")) { - chain = nft_jansson_parse_str(data, "chain", err); + if (nftnl_jansson_node_exist(data, "chain")) { + chain = nftnl_jansson_parse_str(data, "chain", err); if (chain == NULL) return DATA_NONE; @@ -56,71 +56,71 @@ static int nft_data_reg_verdict_json_parse(union nft_data_reg *reg, json_t *data return DATA_VERDICT; } -static int nft_data_reg_value_json_parse(union nft_data_reg *reg, json_t *data, - struct nft_parse_err *err) +static int nftnl_data_reg_value_json_parse(union nftnl_data_reg *reg, json_t *data, + struct nftnl_parse_err *err) { int i; char node_name[6]; - if (nft_jansson_parse_val(data, "len", NFT_TYPE_U8, ®->len, err) < 0) + if (nftnl_jansson_parse_val(data, "len", NFTNL_TYPE_U8, ®->len, err) < 0) return DATA_NONE; for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) { sprintf(node_name, "data%d", i); - if (nft_jansson_str2num(data, node_name, BASE_HEX, - ®->val[i], NFT_TYPE_U32, err) != 0) + if (nftnl_jansson_str2num(data, node_name, BASE_HEX, + ®->val[i], NFTNL_TYPE_U32, err) != 0) return DATA_NONE; } return DATA_VALUE; } -int nft_data_reg_json_parse(union nft_data_reg *reg, json_t *data, - struct nft_parse_err *err) +int nftnl_data_reg_json_parse(union nftnl_data_reg *reg, json_t *data, + struct nftnl_parse_err *err) { const char *type; - type = nft_jansson_parse_str(data, "type", err); + type = nftnl_jansson_parse_str(data, "type", err); if (type == NULL) return -1; /* Select what type of parsing is needed */ if (strcmp(type, "value") == 0) - return nft_data_reg_value_json_parse(reg, data, err); + return nftnl_data_reg_value_json_parse(reg, data, err); else if (strcmp(type, "verdict") == 0) - return nft_data_reg_verdict_json_parse(reg, data, err); + return nftnl_data_reg_verdict_json_parse(reg, data, err); return DATA_NONE; } #endif #ifdef XML_PARSING -static int nft_data_reg_verdict_xml_parse(union nft_data_reg *reg, +static int nftnl_data_reg_verdict_xml_parse(union nftnl_data_reg *reg, mxml_node_t *tree, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { int verdict; const char *verdict_str; const char *chain; - verdict_str = nft_mxml_str_parse(tree, "verdict", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + verdict_str = nftnl_mxml_str_parse(tree, "verdict", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (verdict_str == NULL) return DATA_NONE; - if (nft_str2verdict(verdict_str, &verdict) != 0) { + if (nftnl_str2verdict(verdict_str, &verdict) != 0) { err->node_name = "verdict"; - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; errno = EINVAL; return DATA_NONE; } reg->verdict = (uint32_t)verdict; - chain = nft_mxml_str_parse(tree, "chain", MXML_DESCEND_FIRST, - NFT_XML_OPT, err); + chain = nftnl_mxml_str_parse(tree, "chain", MXML_DESCEND_FIRST, + NFTNL_XML_OPT, err); if (chain != NULL) { if (reg->chain) xfree(reg->chain); @@ -131,31 +131,31 @@ static int nft_data_reg_verdict_xml_parse(union nft_data_reg *reg, return DATA_VERDICT; } -static int nft_data_reg_value_xml_parse(union nft_data_reg *reg, +static int nftnl_data_reg_value_xml_parse(union nftnl_data_reg *reg, mxml_node_t *tree, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { int i; char node_name[6]; - if (nft_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, - ®->len, NFT_TYPE_U8, NFT_XML_MAND, err) != 0) + if (nftnl_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, + ®->len, NFTNL_TYPE_U8, NFTNL_XML_MAND, err) != 0) return DATA_NONE; for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) { sprintf(node_name, "data%d", i); - if (nft_mxml_num_parse(tree, node_name, MXML_DESCEND_FIRST, - BASE_HEX, ®->val[i], NFT_TYPE_U32, - NFT_XML_MAND, err) != 0) + if (nftnl_mxml_num_parse(tree, node_name, MXML_DESCEND_FIRST, + BASE_HEX, ®->val[i], NFTNL_TYPE_U32, + NFTNL_XML_MAND, err) != 0) return DATA_NONE; } return DATA_VALUE; } -int nft_data_reg_xml_parse(union nft_data_reg *reg, mxml_node_t *tree, - struct nft_parse_err *err) +int nftnl_data_reg_xml_parse(union nftnl_data_reg *reg, mxml_node_t *tree, + struct nftnl_parse_err *err) { const char *type; mxml_node_t *node; @@ -171,22 +171,22 @@ int nft_data_reg_xml_parse(union nft_data_reg *reg, mxml_node_t *tree, goto err; if (strcmp(type, "value") == 0) - return nft_data_reg_value_xml_parse(reg, node, err); + return nftnl_data_reg_value_xml_parse(reg, node, err); else if (strcmp(type, "verdict") == 0) - return nft_data_reg_verdict_xml_parse(reg, node, err); + return nftnl_data_reg_verdict_xml_parse(reg, node, err); return DATA_NONE; err: errno = EINVAL; err->node_name = "reg"; - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; return DATA_NONE; } #endif static int -nft_data_reg_value_snprintf_json(char *buf, size_t size, - union nft_data_reg *reg, +nftnl_data_reg_value_snprintf_json(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret, i, j; @@ -222,8 +222,8 @@ nft_data_reg_value_snprintf_json(char *buf, size_t size, } static -int nft_data_reg_value_snprintf_xml(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +int nftnl_data_reg_value_snprintf_xml(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret, i, j; uint32_t be; @@ -258,8 +258,8 @@ int nft_data_reg_value_snprintf_xml(char *buf, size_t size, } static int -nft_data_reg_value_snprintf_default(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +nftnl_data_reg_value_snprintf_default(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret, i; @@ -272,12 +272,12 @@ nft_data_reg_value_snprintf_default(char *buf, size_t size, } static int -nft_data_reg_verdict_snprintf_def(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +nftnl_data_reg_verdict_snprintf_def(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret = 0; - ret = snprintf(buf, size, "%s ", nft_verdict2str(reg->verdict)); + ret = snprintf(buf, size, "%s ", nftnl_verdict2str(reg->verdict)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); if (reg->chain != NULL) { @@ -289,13 +289,13 @@ nft_data_reg_verdict_snprintf_def(char *buf, size_t size, } static int -nft_data_reg_verdict_snprintf_xml(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +nftnl_data_reg_verdict_snprintf_xml(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret = 0; ret = snprintf(buf, size, "<reg type=\"verdict\">" - "<verdict>%s</verdict>", nft_verdict2str(reg->verdict)); + "<verdict>%s</verdict>", nftnl_verdict2str(reg->verdict)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); if (reg->chain != NULL) { @@ -311,13 +311,13 @@ nft_data_reg_verdict_snprintf_xml(char *buf, size_t size, } static int -nft_data_reg_verdict_snprintf_json(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +nftnl_data_reg_verdict_snprintf_json(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret = 0; ret = snprintf(buf, size, "\"reg\":{\"type\":\"verdict\"," - "\"verdict\":\"%s\"", nft_verdict2str(reg->verdict)); + "\"verdict\":\"%s\"", nftnl_verdict2str(reg->verdict)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); if (reg->chain != NULL) { @@ -332,20 +332,20 @@ nft_data_reg_verdict_snprintf_json(char *buf, size_t size, return offset; } -int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg, +int nftnl_data_reg_snprintf(char *buf, size_t size, union nftnl_data_reg *reg, uint32_t output_format, uint32_t flags, int reg_type) { switch(reg_type) { case DATA_VALUE: switch(output_format) { - case NFT_OUTPUT_DEFAULT: - return nft_data_reg_value_snprintf_default(buf, size, + case NFTNL_OUTPUT_DEFAULT: + return nftnl_data_reg_value_snprintf_default(buf, size, reg, flags); - case NFT_OUTPUT_XML: - return nft_data_reg_value_snprintf_xml(buf, size, + case NFTNL_OUTPUT_XML: + return nftnl_data_reg_value_snprintf_xml(buf, size, reg, flags); - case NFT_OUTPUT_JSON: - return nft_data_reg_value_snprintf_json(buf, size, + case NFTNL_OUTPUT_JSON: + return nftnl_data_reg_value_snprintf_json(buf, size, reg, flags); default: break; @@ -353,14 +353,14 @@ int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg, case DATA_VERDICT: case DATA_CHAIN: switch(output_format) { - case NFT_OUTPUT_DEFAULT: - return nft_data_reg_verdict_snprintf_def(buf, size, + case NFTNL_OUTPUT_DEFAULT: + return nftnl_data_reg_verdict_snprintf_def(buf, size, reg, flags); - case NFT_OUTPUT_XML: - return nft_data_reg_verdict_snprintf_xml(buf, size, + case NFTNL_OUTPUT_XML: + return nftnl_data_reg_verdict_snprintf_xml(buf, size, reg, flags); - case NFT_OUTPUT_JSON: - return nft_data_reg_verdict_snprintf_json(buf, size, + case NFTNL_OUTPUT_JSON: + return nftnl_data_reg_verdict_snprintf_json(buf, size, reg, flags); default: break; @@ -372,7 +372,7 @@ int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg, return -1; } -static int nft_data_parse_cb(const struct nlattr *attr, void *data) +static int nftnl_data_parse_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -394,7 +394,7 @@ static int nft_data_parse_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_verdict_parse_cb(const struct nlattr *attr, void *data) +static int nftnl_verdict_parse_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -417,11 +417,11 @@ static int nft_verdict_parse_cb(const struct nlattr *attr, void *data) } static int -nft_parse_verdict(union nft_data_reg *data, const struct nlattr *attr, int *type) +nftnl_parse_verdict(union nftnl_data_reg *data, const struct nlattr *attr, int *type) { struct nlattr *tb[NFTA_VERDICT_MAX+1]; - if (mnl_attr_parse_nested(attr, nft_verdict_parse_cb, tb) < 0) { + if (mnl_attr_parse_nested(attr, nftnl_verdict_parse_cb, tb) < 0) { perror("mnl_attr_parse_nested"); return -1; } @@ -459,7 +459,7 @@ nft_parse_verdict(union nft_data_reg *data, const struct nlattr *attr, int *type } static int -__nft_parse_data(union nft_data_reg *data, const struct nlattr *attr) +__nftnl_parse_data(union nftnl_data_reg *data, const struct nlattr *attr) { void *orig = mnl_attr_get_payload(attr); uint32_t data_len = mnl_attr_get_payload_len(attr); @@ -476,12 +476,12 @@ __nft_parse_data(union nft_data_reg *data, const struct nlattr *attr) return 0; } -int nft_parse_data(union nft_data_reg *data, struct nlattr *attr, int *type) +int nftnl_parse_data(union nftnl_data_reg *data, struct nlattr *attr, int *type) { struct nlattr *tb[NFTA_DATA_MAX+1] = {}; int ret = 0; - if (mnl_attr_parse_nested(attr, nft_data_parse_cb, tb) < 0) { + if (mnl_attr_parse_nested(attr, nftnl_data_parse_cb, tb) < 0) { perror("mnl_attr_parse_nested"); return -1; } @@ -489,17 +489,17 @@ int nft_parse_data(union nft_data_reg *data, struct nlattr *attr, int *type) if (type) *type = DATA_VALUE; - ret = __nft_parse_data(data, tb[NFTA_DATA_VALUE]); + ret = __nftnl_parse_data(data, tb[NFTA_DATA_VALUE]); if (ret < 0) return ret; } if (tb[NFTA_DATA_VERDICT]) - ret = nft_parse_verdict(data, tb[NFTA_DATA_VERDICT], type); + ret = nftnl_parse_verdict(data, tb[NFTA_DATA_VERDICT], type); return ret; } -void nft_free_verdict(union nft_data_reg *data) +void nftnl_free_verdict(union nftnl_data_reg *data) { switch(data->verdict) { case NFT_JUMP: diff --git a/src/expr/dynset.c b/src/expr/dynset.c index e3fecf5..ffb3882 100644 --- a/src/expr/dynset.c +++ b/src/expr/dynset.c @@ -26,43 +26,43 @@ #define IFNAMSIZ 16 #endif -struct nft_expr_dynset { +struct nftnl_expr_dynset { enum nft_registers sreg_key; enum nft_registers sreg_data; enum nft_dynset_ops op; uint64_t timeout; - struct nft_rule_expr *expr; + struct nftnl_rule_expr *expr; char set_name[IFNAMSIZ]; uint32_t set_id; }; static int -nft_rule_expr_dynset_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_dynset_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_dynset *dynset = nft_expr_data(e); + struct nftnl_expr_dynset *dynset = nftnl_expr_data(e); switch (type) { - case NFT_EXPR_DYNSET_SREG_KEY: + case NFTNL_EXPR_DYNSET_SREG_KEY: dynset->sreg_key = *((uint32_t *)data); break; - case NFT_EXPR_DYNSET_SREG_DATA: + case NFTNL_EXPR_DYNSET_SREG_DATA: dynset->sreg_data = *((uint32_t *)data); break; - case NFT_EXPR_DYNSET_OP: + case NFTNL_EXPR_DYNSET_OP: dynset->op = *((uint32_t *)data); break; - case NFT_EXPR_DYNSET_TIMEOUT: + case NFTNL_EXPR_DYNSET_TIMEOUT: dynset->timeout = *((uint64_t *)data); break; - case NFT_EXPR_DYNSET_SET_NAME: + case NFTNL_EXPR_DYNSET_SET_NAME: snprintf(dynset->set_name, sizeof(dynset->set_name), "%s", (const char *)data); break; - case NFT_EXPR_DYNSET_SET_ID: + case NFTNL_EXPR_DYNSET_SET_ID: dynset->set_id = *((uint32_t *)data); break; - case NFT_EXPR_DYNSET_EXPR: + case NFTNL_EXPR_DYNSET_EXPR: dynset->expr = (void *)data; break; default: @@ -72,35 +72,35 @@ nft_rule_expr_dynset_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_dynset_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_dynset_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_dynset *dynset = nft_expr_data(e); + struct nftnl_expr_dynset *dynset = nftnl_expr_data(e); switch (type) { - case NFT_EXPR_DYNSET_SREG_KEY: + case NFTNL_EXPR_DYNSET_SREG_KEY: *data_len = sizeof(dynset->sreg_key); return &dynset->sreg_key; - case NFT_EXPR_DYNSET_SREG_DATA: + case NFTNL_EXPR_DYNSET_SREG_DATA: *data_len = sizeof(dynset->sreg_data); return &dynset->sreg_data; - case NFT_EXPR_DYNSET_OP: + case NFTNL_EXPR_DYNSET_OP: *data_len = sizeof(dynset->op); return &dynset->op; - case NFT_EXPR_DYNSET_TIMEOUT: + case NFTNL_EXPR_DYNSET_TIMEOUT: *data_len = sizeof(dynset->timeout); return &dynset->timeout; - case NFT_EXPR_DYNSET_SET_NAME: + case NFTNL_EXPR_DYNSET_SET_NAME: return dynset->set_name; - case NFT_EXPR_DYNSET_SET_ID: + case NFTNL_EXPR_DYNSET_SET_ID: return &dynset->set_id; - case NFT_EXPR_DYNSET_EXPR: + case NFTNL_EXPR_DYNSET_EXPR: return dynset->expr; } return NULL; } -static int nft_rule_expr_dynset_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_dynset_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -135,67 +135,67 @@ static int nft_rule_expr_dynset_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_dynset_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_dynset_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_dynset *dynset = nft_expr_data(e); + struct nftnl_expr_dynset *dynset = nftnl_expr_data(e); struct nlattr *nest; - if (e->flags & (1 << NFT_EXPR_DYNSET_SREG_KEY)) + if (e->flags & (1 << NFTNL_EXPR_DYNSET_SREG_KEY)) mnl_attr_put_u32(nlh, NFTA_DYNSET_SREG_KEY, htonl(dynset->sreg_key)); - if (e->flags & (1 << NFT_EXPR_DYNSET_SREG_DATA)) + if (e->flags & (1 << NFTNL_EXPR_DYNSET_SREG_DATA)) mnl_attr_put_u32(nlh, NFTA_DYNSET_SREG_DATA, htonl(dynset->sreg_data)); - if (e->flags & (1 << NFT_EXPR_DYNSET_OP)) + if (e->flags & (1 << NFTNL_EXPR_DYNSET_OP)) mnl_attr_put_u32(nlh, NFTA_DYNSET_OP, htonl(dynset->op)); - if (e->flags & (1 << NFT_EXPR_DYNSET_TIMEOUT)) + if (e->flags & (1 << NFTNL_EXPR_DYNSET_TIMEOUT)) mnl_attr_put_u64(nlh, NFTA_DYNSET_TIMEOUT, htobe64(dynset->timeout)); - if (e->flags & (1 << NFT_EXPR_DYNSET_SET_NAME)) + if (e->flags & (1 << NFTNL_EXPR_DYNSET_SET_NAME)) mnl_attr_put_strz(nlh, NFTA_DYNSET_SET_NAME, dynset->set_name); - if (e->flags & (1 << NFT_EXPR_DYNSET_SET_ID)) + if (e->flags & (1 << NFTNL_EXPR_DYNSET_SET_ID)) mnl_attr_put_u32(nlh, NFTA_DYNSET_SET_ID, htonl(dynset->set_id)); - if (e->flags & (1 << NFT_EXPR_DYNSET_EXPR)) { + if (e->flags & (1 << NFTNL_EXPR_DYNSET_EXPR)) { nest = mnl_attr_nest_start(nlh, NFTA_DYNSET_EXPR); - nft_rule_expr_build_payload(nlh, dynset->expr); + nftnl_rule_expr_build_payload(nlh, dynset->expr); mnl_attr_nest_end(nlh, nest); } } static int -nft_rule_expr_dynset_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_dynset_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_dynset *dynset = nft_expr_data(e); + struct nftnl_expr_dynset *dynset = nftnl_expr_data(e); struct nlattr *tb[NFTA_SET_MAX+1] = {}; int ret = 0; - if (mnl_attr_parse_nested(attr, nft_rule_expr_dynset_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_dynset_cb, tb) < 0) return -1; if (tb[NFTA_DYNSET_SREG_KEY]) { dynset->sreg_key = ntohl(mnl_attr_get_u32(tb[NFTA_DYNSET_SREG_KEY])); - e->flags |= (1 << NFT_EXPR_DYNSET_SREG_KEY); + e->flags |= (1 << NFTNL_EXPR_DYNSET_SREG_KEY); } if (tb[NFTA_DYNSET_SREG_DATA]) { dynset->sreg_data = ntohl(mnl_attr_get_u32(tb[NFTA_DYNSET_SREG_DATA])); - e->flags |= (1 << NFT_EXPR_DYNSET_SREG_DATA); + e->flags |= (1 << NFTNL_EXPR_DYNSET_SREG_DATA); } if (tb[NFTA_DYNSET_OP]) { dynset->op = ntohl(mnl_attr_get_u32(tb[NFTA_DYNSET_OP])); - e->flags |= (1 << NFT_EXPR_DYNSET_OP); + e->flags |= (1 << NFTNL_EXPR_DYNSET_OP); } if (tb[NFTA_DYNSET_TIMEOUT]) { dynset->timeout = be64toh(mnl_attr_get_u64(tb[NFTA_DYNSET_TIMEOUT])); - e->flags |= (1 << NFT_EXPR_DYNSET_TIMEOUT); + e->flags |= (1 << NFTNL_EXPR_DYNSET_TIMEOUT); } if (tb[NFTA_DYNSET_SET_NAME]) { strcpy(dynset->set_name, mnl_attr_get_str(tb[NFTA_DYNSET_SET_NAME])); - e->flags |= (1 << NFT_EXPR_DYNSET_SET_NAME); + e->flags |= (1 << NFTNL_EXPR_DYNSET_SET_NAME); } if (tb[NFTA_DYNSET_SET_ID]) { dynset->set_id = ntohl(mnl_attr_get_u32(tb[NFTA_DYNSET_SET_ID])); - e->flags |= (1 << NFT_EXPR_DYNSET_SET_ID); + e->flags |= (1 << NFTNL_EXPR_DYNSET_SET_ID); } if (tb[NFTA_DYNSET_EXPR]) { - e->flags |= (1 << NFT_EXPR_DYNSET_EXPR); - dynset->expr = nft_rule_expr_parse(tb[NFTA_DYNSET_EXPR]); + e->flags |= (1 << NFTNL_EXPR_DYNSET_EXPR); + dynset->expr = nftnl_rule_expr_parse(tb[NFTA_DYNSET_EXPR]); if (dynset->expr == NULL) return -1; } @@ -204,33 +204,33 @@ nft_rule_expr_dynset_parse(struct nft_rule_expr *e, struct nlattr *attr) } static int -nft_rule_expr_dynset_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_dynset_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *set_name; uint32_t uval32; uint64_t uval64; - set_name = nft_jansson_parse_str(root, "set", err); + set_name = nftnl_jansson_parse_str(root, "set", err); if (set_name != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_DYNSET_SET_NAME, set_name); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_DYNSET_SET_NAME, set_name); - if (nft_jansson_parse_reg(root, "sreg_key", - NFT_TYPE_U32, &uval32, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_DYNSET_SREG_KEY, uval32); + if (nftnl_jansson_parse_reg(root, "sreg_key", + NFTNL_TYPE_U32, &uval32, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_DYNSET_SREG_KEY, uval32); - if (nft_jansson_parse_reg(root, "sreg_data", - NFT_TYPE_U32, &uval32, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_DYNSET_SREG_DATA, uval32); + if (nftnl_jansson_parse_reg(root, "sreg_data", + NFTNL_TYPE_U32, &uval32, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_DYNSET_SREG_DATA, uval32); - if (nft_jansson_parse_val(root, "op", NFT_TYPE_U32, &uval32, + if (nftnl_jansson_parse_val(root, "op", NFTNL_TYPE_U32, &uval32, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_DYNSET_OP, uval32); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_DYNSET_OP, uval32); - if (nft_jansson_parse_val(root, "timeout", NFT_TYPE_U64, &uval64, + if (nftnl_jansson_parse_val(root, "timeout", NFTNL_TYPE_U64, &uval64, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_DYNSET_TIMEOUT, uval64); + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_DYNSET_TIMEOUT, uval64); return 0; #else @@ -240,34 +240,34 @@ nft_rule_expr_dynset_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_dynset_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_dynset_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *set_name; uint32_t uval32; uint64_t uval64; - set_name = nft_mxml_str_parse(tree, "set", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + set_name = nftnl_mxml_str_parse(tree, "set", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (set_name != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_DYNSET_SET_NAME, set_name); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_DYNSET_SET_NAME, set_name); - if (nft_mxml_reg_parse(tree, "sreg_key", &uval32, MXML_DESCEND, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_DYNSET_SREG_KEY, uval32); + if (nftnl_mxml_reg_parse(tree, "sreg_key", &uval32, MXML_DESCEND, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_DYNSET_SREG_KEY, uval32); - if (nft_mxml_reg_parse(tree, "sreg_data", &uval32, MXML_DESCEND, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_DYNSET_SREG_DATA, uval32); + if (nftnl_mxml_reg_parse(tree, "sreg_data", &uval32, MXML_DESCEND, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_DYNSET_SREG_DATA, uval32); - if (nft_mxml_num_parse(tree, "op", MXML_DESCEND_FIRST, BASE_DEC, - &uval32, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_DYNSET_OP, uval32); + if (nftnl_mxml_num_parse(tree, "op", MXML_DESCEND_FIRST, BASE_DEC, + &uval32, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_DYNSET_OP, uval32); - if (nft_mxml_num_parse(tree, "timeout", MXML_DESCEND_FIRST, BASE_DEC, - &uval64, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_DYNSET_TIMEOUT, uval64); + if (nftnl_mxml_num_parse(tree, "timeout", MXML_DESCEND_FIRST, BASE_DEC, + &uval64, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_DYNSET_TIMEOUT, uval64); return 0; #else @@ -277,20 +277,20 @@ nft_rule_expr_dynset_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, } static int -nft_rule_expr_dynset_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +nftnl_rule_expr_dynset_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_dynset *dynset = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_dynset *dynset = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_DYNSET_SET_NAME)) - nft_buf_str(&b, type, dynset->set_name, SET_NAME); - if (e->flags & (1 << NFT_EXPR_DYNSET_SREG_KEY)) - nft_buf_u32(&b, type, dynset->sreg_key, SREG_KEY); - if (e->flags & (1 << NFT_EXPR_DYNSET_SREG_DATA)) - nft_buf_u32(&b, type, dynset->sreg_data, SREG_DATA); + if (e->flags & (1 << NFTNL_EXPR_DYNSET_SET_NAME)) + nftnl_buf_str(&b, type, dynset->set_name, SET_NAME); + if (e->flags & (1 << NFTNL_EXPR_DYNSET_SREG_KEY)) + nftnl_buf_u32(&b, type, dynset->sreg_key, SREG_KEY); + if (e->flags & (1 << NFTNL_EXPR_DYNSET_SREG_DATA)) + nftnl_buf_u32(&b, type, dynset->sreg_data, SREG_DATA); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } static char *op2str_array[] = { @@ -306,35 +306,35 @@ static const char *op2str(enum nft_dynset_ops op) } static int -nft_rule_expr_dynset_snprintf_default(char *buf, size_t size, - struct nft_rule_expr *e) +nftnl_rule_expr_dynset_snprintf_default(char *buf, size_t size, + struct nftnl_rule_expr *e) { - struct nft_expr_dynset *dynset = nft_expr_data(e); - struct nft_rule_expr *expr; + struct nftnl_expr_dynset *dynset = nftnl_expr_data(e); + struct nftnl_rule_expr *expr; int len = size, offset = 0, ret; ret = snprintf(buf, len, "%s reg_key %u set %s ", op2str(dynset->op), dynset->sreg_key, dynset->set_name); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (e->flags & (1 << NFT_EXPR_DYNSET_SREG_DATA)) { + if (e->flags & (1 << NFTNL_EXPR_DYNSET_SREG_DATA)) { ret = snprintf(buf+offset, len, "sreg_data %u ", dynset->sreg_data); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (e->flags & (1 << NFT_EXPR_DYNSET_TIMEOUT)) { + if (e->flags & (1 << NFTNL_EXPR_DYNSET_TIMEOUT)) { ret = snprintf(buf+offset, len, "timeout %"PRIu64"ms ", dynset->timeout); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (e->flags & (1 << NFT_EXPR_DYNSET_EXPR)) { + if (e->flags & (1 << NFTNL_EXPR_DYNSET_EXPR)) { expr = dynset->expr; ret = snprintf(buf+offset, len, "expr [ %s ", expr->ops->name); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_rule_expr_snprintf(buf+offset, len, expr, - NFT_OUTPUT_DEFAULT, - NFT_OF_EVENT_ANY); + ret = nftnl_rule_expr_snprintf(buf+offset, len, expr, + NFTNL_OUTPUT_DEFAULT, + NFTNL_OF_EVENT_ANY); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); ret = snprintf(buf+offset, len, "] "); @@ -345,16 +345,16 @@ nft_rule_expr_dynset_snprintf_default(char *buf, size_t size, } static int -nft_rule_expr_dynset_snprintf(char *buf, size_t size, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_dynset_snprintf(char *buf, size_t size, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_dynset_snprintf_default(buf, size, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_dynset_export(buf, size, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_dynset_snprintf_default(buf, size, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_dynset_export(buf, size, e, type); default: break; } @@ -363,13 +363,13 @@ nft_rule_expr_dynset_snprintf(char *buf, size_t size, uint32_t type, struct expr_ops expr_ops_dynset = { .name = "dynset", - .alloc_len = sizeof(struct nft_expr_dynset), + .alloc_len = sizeof(struct nftnl_expr_dynset), .max_attr = NFTA_DYNSET_MAX, - .set = nft_rule_expr_dynset_set, - .get = nft_rule_expr_dynset_get, - .parse = nft_rule_expr_dynset_parse, - .build = nft_rule_expr_dynset_build, - .snprintf = nft_rule_expr_dynset_snprintf, - .xml_parse = nft_rule_expr_dynset_xml_parse, - .json_parse = nft_rule_expr_dynset_json_parse, + .set = nftnl_rule_expr_dynset_set, + .get = nftnl_rule_expr_dynset_get, + .parse = nftnl_rule_expr_dynset_parse, + .build = nftnl_rule_expr_dynset_build, + .snprintf = nftnl_rule_expr_dynset_snprintf, + .xml_parse = nftnl_rule_expr_dynset_xml_parse, + .json_parse = nftnl_rule_expr_dynset_json_parse, }; diff --git a/src/expr/exthdr.c b/src/expr/exthdr.c index a2541b4..0187f96 100644 --- a/src/expr/exthdr.c +++ b/src/expr/exthdr.c @@ -28,7 +28,7 @@ #define IPPROTO_MH 135 #endif -struct nft_expr_exthdr { +struct nftnl_expr_exthdr { enum nft_registers dreg; uint32_t offset; uint32_t len; @@ -36,22 +36,22 @@ struct nft_expr_exthdr { }; static int -nft_rule_expr_exthdr_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_exthdr_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_exthdr *exthdr = nft_expr_data(e); + struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_EXTHDR_DREG: + case NFTNL_EXPR_EXTHDR_DREG: exthdr->dreg = *((uint32_t *)data); break; - case NFT_EXPR_EXTHDR_TYPE: + case NFTNL_EXPR_EXTHDR_TYPE: exthdr->type = *((uint8_t *)data); break; - case NFT_EXPR_EXTHDR_OFFSET: + case NFTNL_EXPR_EXTHDR_OFFSET: exthdr->offset = *((uint32_t *)data); break; - case NFT_EXPR_EXTHDR_LEN: + case NFTNL_EXPR_EXTHDR_LEN: exthdr->len = *((uint32_t *)data); break; default: @@ -61,29 +61,29 @@ nft_rule_expr_exthdr_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_exthdr_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_exthdr_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_exthdr *exthdr = nft_expr_data(e); + struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_EXTHDR_DREG: + case NFTNL_EXPR_EXTHDR_DREG: *data_len = sizeof(exthdr->dreg); return &exthdr->dreg; - case NFT_EXPR_EXTHDR_TYPE: + case NFTNL_EXPR_EXTHDR_TYPE: *data_len = sizeof(exthdr->type); return &exthdr->type; - case NFT_EXPR_EXTHDR_OFFSET: + case NFTNL_EXPR_EXTHDR_OFFSET: *data_len = sizeof(exthdr->offset); return &exthdr->offset; - case NFT_EXPR_EXTHDR_LEN: + case NFTNL_EXPR_EXTHDR_LEN: *data_len = sizeof(exthdr->len); return &exthdr->len; } return NULL; } -static int nft_rule_expr_exthdr_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_exthdr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -109,44 +109,44 @@ static int nft_rule_expr_exthdr_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_exthdr_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_exthdr_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_exthdr *exthdr = nft_expr_data(e); + struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_EXTHDR_DREG)) + if (e->flags & (1 << NFTNL_EXPR_EXTHDR_DREG)) mnl_attr_put_u32(nlh, NFTA_EXTHDR_DREG, htonl(exthdr->dreg)); - if (e->flags & (1 << NFT_EXPR_EXTHDR_TYPE)) + if (e->flags & (1 << NFTNL_EXPR_EXTHDR_TYPE)) mnl_attr_put_u8(nlh, NFTA_EXTHDR_TYPE, exthdr->type); - if (e->flags & (1 << NFT_EXPR_EXTHDR_OFFSET)) + if (e->flags & (1 << NFTNL_EXPR_EXTHDR_OFFSET)) mnl_attr_put_u32(nlh, NFTA_EXTHDR_OFFSET, htonl(exthdr->offset)); - if (e->flags & (1 << NFT_EXPR_EXTHDR_LEN)) + if (e->flags & (1 << NFTNL_EXPR_EXTHDR_LEN)) mnl_attr_put_u32(nlh, NFTA_EXTHDR_LEN, htonl(exthdr->len)); } static int -nft_rule_expr_exthdr_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_exthdr_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_exthdr *exthdr = nft_expr_data(e); + struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e); struct nlattr *tb[NFTA_EXTHDR_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_exthdr_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_exthdr_cb, tb) < 0) return -1; if (tb[NFTA_EXTHDR_DREG]) { exthdr->dreg = ntohl(mnl_attr_get_u32(tb[NFTA_EXTHDR_DREG])); - e->flags |= (1 << NFT_EXPR_EXTHDR_DREG); + e->flags |= (1 << NFTNL_EXPR_EXTHDR_DREG); } if (tb[NFTA_EXTHDR_TYPE]) { exthdr->type = mnl_attr_get_u8(tb[NFTA_EXTHDR_TYPE]); - e->flags |= (1 << NFT_EXPR_EXTHDR_TYPE); + e->flags |= (1 << NFTNL_EXPR_EXTHDR_TYPE); } if (tb[NFTA_EXTHDR_OFFSET]) { exthdr->offset = ntohl(mnl_attr_get_u32(tb[NFTA_EXTHDR_OFFSET])); - e->flags |= (1 << NFT_EXPR_EXTHDR_OFFSET); + e->flags |= (1 << NFTNL_EXPR_EXTHDR_OFFSET); } if (tb[NFTA_EXTHDR_LEN]) { exthdr->len = ntohl(mnl_attr_get_u32(tb[NFTA_EXTHDR_LEN])); - e->flags |= (1 << NFT_EXPR_EXTHDR_LEN); + e->flags |= (1 << NFTNL_EXPR_EXTHDR_LEN); } return 0; @@ -187,32 +187,32 @@ static inline int str2exthdr_type(const char *str) } static int -nft_rule_expr_exthdr_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_exthdr_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *exthdr_type; uint32_t uval32; int type; - if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, &uval32, + if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &uval32, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_EXTHDR_DREG, uval32); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_EXTHDR_DREG, uval32); - exthdr_type = nft_jansson_parse_str(root, "exthdr_type", err); + exthdr_type = nftnl_jansson_parse_str(root, "exthdr_type", err); if (exthdr_type != NULL) { type = str2exthdr_type(exthdr_type); if (type < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_EXTHDR_TYPE, type); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_EXTHDR_TYPE, type); } - if (nft_jansson_parse_val(root, "offset", NFT_TYPE_U32, &uval32, + if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32, &uval32, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_EXTHDR_OFFSET, uval32); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_EXTHDR_OFFSET, uval32); - if (nft_jansson_parse_val(root, "len", NFT_TYPE_U32, &uval32, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_EXTHDR_LEN, uval32); + if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &uval32, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_EXTHDR_LEN, uval32); return 0; #else @@ -222,36 +222,36 @@ nft_rule_expr_exthdr_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_exthdr_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_exthdr_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *exthdr_type; int type; uint32_t dreg, len, offset; - if (nft_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_EXTHDR_DREG, dreg); + if (nftnl_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_EXTHDR_DREG, dreg); - exthdr_type = nft_mxml_str_parse(tree, "exthdr_type", - MXML_DESCEND_FIRST, NFT_XML_MAND, err); + exthdr_type = nftnl_mxml_str_parse(tree, "exthdr_type", + MXML_DESCEND_FIRST, NFTNL_XML_MAND, err); if (exthdr_type != NULL) { type = str2exthdr_type(exthdr_type); if (type < 0) return -1; - nft_rule_expr_set_u8(e, NFT_EXPR_EXTHDR_TYPE, type); + nftnl_rule_expr_set_u8(e, NFTNL_EXPR_EXTHDR_TYPE, type); } /* Get and set <offset> */ - if (nft_mxml_num_parse(tree, "offset", MXML_DESCEND_FIRST, BASE_DEC, - &offset, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_EXTHDR_OFFSET, offset); + if (nftnl_mxml_num_parse(tree, "offset", MXML_DESCEND_FIRST, BASE_DEC, + &offset, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_EXTHDR_OFFSET, offset); /* Get and set <len> */ - if (nft_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, - &len, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_EXTHDR_LEN, len); + if (nftnl_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, + &len, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_EXTHDR_LEN, len); return 0; #else @@ -260,28 +260,28 @@ nft_rule_expr_exthdr_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, #endif } -static int nft_rule_expr_exthdr_export(char *buf, size_t len, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_exthdr_export(char *buf, size_t len, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_exthdr *exthdr = nft_expr_data(e); - NFT_BUF_INIT(b, buf, len); - - if (e->flags & (1 << NFT_EXPR_EXTHDR_DREG)) - nft_buf_u32(&b, type, exthdr->dreg, DREG); - if (e->flags & (1 << NFT_EXPR_EXTHDR_TYPE)) - nft_buf_str(&b, type, type2str(exthdr->type), EXTHDR_TYPE); - if (e->flags & (1 << NFT_EXPR_EXTHDR_OFFSET)) - nft_buf_u32(&b, type, exthdr->offset, OFFSET); - if (e->flags & (1 << NFT_EXPR_EXTHDR_LEN)) - nft_buf_u32(&b, type, exthdr->len, LEN); - - return nft_buf_done(&b); + struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, len); + + if (e->flags & (1 << NFTNL_EXPR_EXTHDR_DREG)) + nftnl_buf_u32(&b, type, exthdr->dreg, DREG); + if (e->flags & (1 << NFTNL_EXPR_EXTHDR_TYPE)) + nftnl_buf_str(&b, type, type2str(exthdr->type), EXTHDR_TYPE); + if (e->flags & (1 << NFTNL_EXPR_EXTHDR_OFFSET)) + nftnl_buf_u32(&b, type, exthdr->offset, OFFSET); + if (e->flags & (1 << NFTNL_EXPR_EXTHDR_LEN)) + nftnl_buf_u32(&b, type, exthdr->len, LEN); + + return nftnl_buf_done(&b); } -static int nft_rule_expr_exthdr_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e) +static int nftnl_rule_expr_exthdr_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e) { - struct nft_expr_exthdr *exthdr = nft_expr_data(e); + struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e); return snprintf(buf, len, "load %ub @ %u + %u => reg %u ", exthdr->len, exthdr->type, exthdr->offset, @@ -289,15 +289,15 @@ static int nft_rule_expr_exthdr_snprintf_default(char *buf, size_t len, } static int -nft_rule_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_exthdr_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_exthdr_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_exthdr_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_exthdr_export(buf, len, e, type); default: break; } @@ -306,13 +306,13 @@ nft_rule_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_exthdr = { .name = "exthdr", - .alloc_len = sizeof(struct nft_expr_exthdr), + .alloc_len = sizeof(struct nftnl_expr_exthdr), .max_attr = NFTA_EXTHDR_MAX, - .set = nft_rule_expr_exthdr_set, - .get = nft_rule_expr_exthdr_get, - .parse = nft_rule_expr_exthdr_parse, - .build = nft_rule_expr_exthdr_build, - .snprintf = nft_rule_expr_exthdr_snprintf, - .xml_parse = nft_rule_expr_exthdr_xml_parse, - .json_parse = nft_rule_expr_exthdr_json_parse, + .set = nftnl_rule_expr_exthdr_set, + .get = nftnl_rule_expr_exthdr_get, + .parse = nftnl_rule_expr_exthdr_parse, + .build = nftnl_rule_expr_exthdr_build, + .snprintf = nftnl_rule_expr_exthdr_snprintf, + .xml_parse = nftnl_rule_expr_exthdr_xml_parse, + .json_parse = nftnl_rule_expr_exthdr_json_parse, }; diff --git a/src/expr/immediate.c b/src/expr/immediate.c index cf06190..4f3960a 100644 --- a/src/expr/immediate.c +++ b/src/expr/immediate.c @@ -20,29 +20,29 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_immediate { - union nft_data_reg data; +struct nftnl_expr_immediate { + union nftnl_data_reg data; enum nft_registers dreg; }; static int -nft_rule_expr_immediate_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_immediate_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_immediate *imm = nft_expr_data(e); + struct nftnl_expr_immediate *imm = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_IMM_DREG: + case NFTNL_EXPR_IMM_DREG: imm->dreg = *((uint32_t *)data); break; - case NFT_EXPR_IMM_DATA: + case NFTNL_EXPR_IMM_DATA: memcpy(&imm->data.val, data, data_len); imm->data.len = data_len; break; - case NFT_EXPR_IMM_VERDICT: + case NFTNL_EXPR_IMM_VERDICT: imm->data.verdict = *((uint32_t *)data); break; - case NFT_EXPR_IMM_CHAIN: + case NFTNL_EXPR_IMM_CHAIN: if (imm->data.chain) xfree(imm->data.chain); @@ -55,29 +55,29 @@ nft_rule_expr_immediate_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_immediate_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_immediate_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_immediate *imm = nft_expr_data(e); + struct nftnl_expr_immediate *imm = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_IMM_DREG: + case NFTNL_EXPR_IMM_DREG: *data_len = sizeof(imm->dreg); return &imm->dreg; - case NFT_EXPR_IMM_DATA: + case NFTNL_EXPR_IMM_DATA: *data_len = imm->data.len; return &imm->data.val; - case NFT_EXPR_IMM_VERDICT: + case NFTNL_EXPR_IMM_VERDICT: *data_len = sizeof(imm->data.verdict); return &imm->data.verdict; - case NFT_EXPR_IMM_CHAIN: + case NFTNL_EXPR_IMM_CHAIN: *data_len = strlen(imm->data.chain)+1; return imm->data.chain; } return NULL; } -static int nft_rule_expr_immediate_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_immediate_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -101,28 +101,28 @@ static int nft_rule_expr_immediate_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_immediate_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_immediate_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_immediate *imm = nft_expr_data(e); + struct nftnl_expr_immediate *imm = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_IMM_DREG)) + if (e->flags & (1 << NFTNL_EXPR_IMM_DREG)) mnl_attr_put_u32(nlh, NFTA_IMMEDIATE_DREG, htonl(imm->dreg)); /* Sane configurations allows you to set ONLY one of these two below */ - if (e->flags & (1 << NFT_EXPR_IMM_DATA)) { + if (e->flags & (1 << NFTNL_EXPR_IMM_DATA)) { struct nlattr *nest; nest = mnl_attr_nest_start(nlh, NFTA_IMMEDIATE_DATA); mnl_attr_put(nlh, NFTA_DATA_VALUE, imm->data.len, imm->data.val); mnl_attr_nest_end(nlh, nest); - } else if (e->flags & (1 << NFT_EXPR_IMM_VERDICT)) { + } else if (e->flags & (1 << NFTNL_EXPR_IMM_VERDICT)) { struct nlattr *nest1, *nest2; nest1 = mnl_attr_nest_start(nlh, NFTA_IMMEDIATE_DATA); nest2 = mnl_attr_nest_start(nlh, NFTA_DATA_VERDICT); mnl_attr_put_u32(nlh, NFTA_VERDICT_CODE, htonl(imm->data.verdict)); - if (e->flags & (1 << NFT_EXPR_IMM_CHAIN)) + if (e->flags & (1 << NFTNL_EXPR_IMM_CHAIN)) mnl_attr_put_strz(nlh, NFTA_VERDICT_CHAIN, imm->data.chain); mnl_attr_nest_end(nlh, nest1); @@ -131,39 +131,39 @@ nft_rule_expr_immediate_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) } static int -nft_rule_expr_immediate_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_immediate_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_immediate *imm = nft_expr_data(e); + struct nftnl_expr_immediate *imm = nftnl_expr_data(e); struct nlattr *tb[NFTA_IMMEDIATE_MAX+1] = {}; int ret = 0; - if (mnl_attr_parse_nested(attr, nft_rule_expr_immediate_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_immediate_cb, tb) < 0) return -1; if (tb[NFTA_IMMEDIATE_DREG]) { imm->dreg = ntohl(mnl_attr_get_u32(tb[NFTA_IMMEDIATE_DREG])); - e->flags |= (1 << NFT_EXPR_IMM_DREG); + e->flags |= (1 << NFTNL_EXPR_IMM_DREG); } if (tb[NFTA_IMMEDIATE_DATA]) { int type; - ret = nft_parse_data(&imm->data, tb[NFTA_IMMEDIATE_DATA], &type); + ret = nftnl_parse_data(&imm->data, tb[NFTA_IMMEDIATE_DATA], &type); if (ret < 0) return ret; switch(type) { case DATA_VALUE: /* real immediate data to be loaded to destination */ - e->flags |= (1 << NFT_EXPR_IMM_DATA); + e->flags |= (1 << NFTNL_EXPR_IMM_DATA); break; case DATA_VERDICT: - /* NF_ACCEPT, NF_DROP, NF_QUEUE and NFT_RETURN case */ - e->flags |= (1 << NFT_EXPR_IMM_VERDICT); + /* NF_ACCEPT, NF_DROP, NF_QUEUE and NFTNL_RETURN case */ + e->flags |= (1 << NFTNL_EXPR_IMM_VERDICT); break; case DATA_CHAIN: - /* NFT_GOTO and NFT_JUMP case */ - e->flags |= (1 << NFT_EXPR_IMM_VERDICT) | - (1 << NFT_EXPR_IMM_CHAIN); + /* NFTNL_GOTO and NFTNL_JUMP case */ + e->flags |= (1 << NFTNL_EXPR_IMM_VERDICT) | + (1 << NFTNL_EXPR_IMM_CHAIN); break; } } @@ -172,29 +172,29 @@ nft_rule_expr_immediate_parse(struct nft_rule_expr *e, struct nlattr *attr) } static int -nft_rule_expr_immediate_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_immediate_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING - struct nft_expr_immediate *imm = nft_expr_data(e); + struct nftnl_expr_immediate *imm = nftnl_expr_data(e); int datareg_type; uint32_t reg; - if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_IMM_DREG, reg); + if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_IMM_DREG, reg); - datareg_type = nft_jansson_data_reg_parse(root, "data", + datareg_type = nftnl_jansson_data_reg_parse(root, "data", &imm->data, err); if (datareg_type >= 0) { switch (datareg_type) { case DATA_VALUE: - e->flags |= (1 << NFT_EXPR_IMM_DATA); + e->flags |= (1 << NFTNL_EXPR_IMM_DATA); break; case DATA_VERDICT: - e->flags |= (1 << NFT_EXPR_IMM_VERDICT); + e->flags |= (1 << NFTNL_EXPR_IMM_VERDICT); break; case DATA_CHAIN: - e->flags |= (1 << NFT_EXPR_IMM_CHAIN); + e->flags |= (1 << NFTNL_EXPR_IMM_CHAIN); break; default: return -1; @@ -208,30 +208,30 @@ nft_rule_expr_immediate_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_immediate_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_immediate_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING - struct nft_expr_immediate *imm = nft_expr_data(e); + struct nftnl_expr_immediate *imm = nftnl_expr_data(e); int datareg_type; uint32_t reg; - if (nft_mxml_reg_parse(tree, "dreg", ®, MXML_DESCEND_FIRST, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_IMM_DREG, reg); + if (nftnl_mxml_reg_parse(tree, "dreg", ®, MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_IMM_DREG, reg); - datareg_type = nft_mxml_data_reg_parse(tree, "data", - &imm->data, NFT_XML_MAND, err); + datareg_type = nftnl_mxml_data_reg_parse(tree, "data", + &imm->data, NFTNL_XML_MAND, err); if (datareg_type >= 0) { switch (datareg_type) { case DATA_VALUE: - e->flags |= (1 << NFT_EXPR_IMM_DATA); + e->flags |= (1 << NFTNL_EXPR_IMM_DATA); break; case DATA_VERDICT: - e->flags |= (1 << NFT_EXPR_IMM_VERDICT); + e->flags |= (1 << NFTNL_EXPR_IMM_VERDICT); break; case DATA_CHAIN: - e->flags |= (1 << NFT_EXPR_IMM_CHAIN); + e->flags |= (1 << NFTNL_EXPR_IMM_CHAIN); break; default: return -1; @@ -246,47 +246,47 @@ nft_rule_expr_immediate_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, } static int -nft_rule_expr_immediate_export(char *buf, size_t size, struct nft_rule_expr *e, +nftnl_rule_expr_immediate_export(char *buf, size_t size, struct nftnl_rule_expr *e, int type) { - struct nft_expr_immediate *imm = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFT_EXPR_IMM_DREG)) - nft_buf_u32(&b, type, imm->dreg, DREG); - if (e->flags & (1 << NFT_EXPR_IMM_DATA)) - nft_buf_reg(&b, type, &imm->data, DATA_VALUE, DATA); - if (e->flags & (1 << NFT_EXPR_IMM_VERDICT)) - nft_buf_reg(&b, type, &imm->data, DATA_VERDICT, DATA); - if (e->flags & (1 << NFT_EXPR_IMM_CHAIN)) - nft_buf_reg(&b, type, &imm->data, DATA_CHAIN, DATA); - - return nft_buf_done(&b); + struct nftnl_expr_immediate *imm = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); + + if (e->flags & (1 << NFTNL_EXPR_IMM_DREG)) + nftnl_buf_u32(&b, type, imm->dreg, DREG); + if (e->flags & (1 << NFTNL_EXPR_IMM_DATA)) + nftnl_buf_reg(&b, type, &imm->data, DATA_VALUE, DATA); + if (e->flags & (1 << NFTNL_EXPR_IMM_VERDICT)) + nftnl_buf_reg(&b, type, &imm->data, DATA_VERDICT, DATA); + if (e->flags & (1 << NFTNL_EXPR_IMM_CHAIN)) + nftnl_buf_reg(&b, type, &imm->data, DATA_CHAIN, DATA); + + return nftnl_buf_done(&b); } static int -nft_rule_expr_immediate_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e, uint32_t flags) +nftnl_rule_expr_immediate_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e, uint32_t flags) { int size = len, offset = 0, ret; - struct nft_expr_immediate *imm = nft_expr_data(e); + struct nftnl_expr_immediate *imm = nftnl_expr_data(e); ret = snprintf(buf, len, "reg %u ", imm->dreg); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (e->flags & (1 << NFT_EXPR_IMM_DATA)) { - ret = nft_data_reg_snprintf(buf+offset, len, &imm->data, - NFT_OUTPUT_DEFAULT, flags, DATA_VALUE); + if (e->flags & (1 << NFTNL_EXPR_IMM_DATA)) { + ret = nftnl_data_reg_snprintf(buf+offset, len, &imm->data, + NFTNL_OUTPUT_DEFAULT, flags, DATA_VALUE); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - } else if (e->flags & (1 << NFT_EXPR_IMM_VERDICT)) { - ret = nft_data_reg_snprintf(buf+offset, len, &imm->data, - NFT_OUTPUT_DEFAULT, flags, DATA_VERDICT); + } else if (e->flags & (1 << NFTNL_EXPR_IMM_VERDICT)) { + ret = nftnl_data_reg_snprintf(buf+offset, len, &imm->data, + NFTNL_OUTPUT_DEFAULT, flags, DATA_VERDICT); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - } else if (e->flags & (1 << NFT_EXPR_IMM_CHAIN)) { - ret = nft_data_reg_snprintf(buf+offset, len, &imm->data, - NFT_OUTPUT_DEFAULT, flags, DATA_CHAIN); + } else if (e->flags & (1 << NFTNL_EXPR_IMM_CHAIN)) { + ret = nftnl_data_reg_snprintf(buf+offset, len, &imm->data, + NFTNL_OUTPUT_DEFAULT, flags, DATA_CHAIN); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } @@ -294,39 +294,39 @@ nft_rule_expr_immediate_snprintf_default(char *buf, size_t len, } static int -nft_rule_expr_immediate_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_immediate_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch(type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_immediate_snprintf_default(buf, len, e, flags); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_immediate_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_immediate_snprintf_default(buf, len, e, flags); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_immediate_export(buf, len, e, type); default: break; } return -1; } -static void nft_rule_expr_immediate_free(struct nft_rule_expr *e) +static void nftnl_rule_expr_immediate_free(struct nftnl_rule_expr *e) { - struct nft_expr_immediate *imm = nft_expr_data(e); + struct nftnl_expr_immediate *imm = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_IMM_VERDICT)) - nft_free_verdict(&imm->data); + if (e->flags & (1 << NFTNL_EXPR_IMM_VERDICT)) + nftnl_free_verdict(&imm->data); } struct expr_ops expr_ops_immediate = { .name = "immediate", - .alloc_len = sizeof(struct nft_expr_immediate), + .alloc_len = sizeof(struct nftnl_expr_immediate), .max_attr = NFTA_IMMEDIATE_MAX, - .free = nft_rule_expr_immediate_free, - .set = nft_rule_expr_immediate_set, - .get = nft_rule_expr_immediate_get, - .parse = nft_rule_expr_immediate_parse, - .build = nft_rule_expr_immediate_build, - .snprintf = nft_rule_expr_immediate_snprintf, - .xml_parse = nft_rule_expr_immediate_xml_parse, - .json_parse = nft_rule_expr_immediate_json_parse, + .free = nftnl_rule_expr_immediate_free, + .set = nftnl_rule_expr_immediate_set, + .get = nftnl_rule_expr_immediate_get, + .parse = nftnl_rule_expr_immediate_parse, + .build = nftnl_rule_expr_immediate_build, + .snprintf = nftnl_rule_expr_immediate_snprintf, + .xml_parse = nftnl_rule_expr_immediate_xml_parse, + .json_parse = nftnl_rule_expr_immediate_json_parse, }; diff --git a/src/expr/limit.c b/src/expr/limit.c index 3ad246e..b323c5c 100644 --- a/src/expr/limit.c +++ b/src/expr/limit.c @@ -22,22 +22,22 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_limit { +struct nftnl_expr_limit { uint64_t rate; uint64_t unit; }; static int -nft_rule_expr_limit_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_limit_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_LIMIT_RATE: + case NFTNL_EXPR_LIMIT_RATE: limit->rate = *((uint64_t *)data); break; - case NFT_EXPR_LIMIT_UNIT: + case NFTNL_EXPR_LIMIT_UNIT: limit->unit = *((uint64_t *)data); break; default: @@ -47,23 +47,23 @@ nft_rule_expr_limit_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_limit_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_limit_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_LIMIT_RATE: + case NFTNL_EXPR_LIMIT_RATE: *data_len = sizeof(uint64_t); return &limit->rate; - case NFT_EXPR_LIMIT_UNIT: + case NFTNL_EXPR_LIMIT_UNIT: *data_len = sizeof(uint64_t); return &limit->unit; } return NULL; } -static int nft_rule_expr_limit_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_limit_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -84,48 +84,48 @@ static int nft_rule_expr_limit_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_limit_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_limit_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_LIMIT_RATE)) + if (e->flags & (1 << NFTNL_EXPR_LIMIT_RATE)) mnl_attr_put_u64(nlh, NFTA_LIMIT_RATE, htobe64(limit->rate)); - if (e->flags & (1 << NFT_EXPR_LIMIT_UNIT)) + if (e->flags & (1 << NFTNL_EXPR_LIMIT_UNIT)) mnl_attr_put_u64(nlh, NFTA_LIMIT_UNIT, htobe64(limit->unit)); } static int -nft_rule_expr_limit_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_limit_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); struct nlattr *tb[NFTA_LIMIT_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_limit_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_limit_cb, tb) < 0) return -1; if (tb[NFTA_LIMIT_RATE]) { limit->rate = be64toh(mnl_attr_get_u64(tb[NFTA_LIMIT_RATE])); - e->flags |= (1 << NFT_EXPR_LIMIT_RATE); + e->flags |= (1 << NFTNL_EXPR_LIMIT_RATE); } if (tb[NFTA_LIMIT_UNIT]) { limit->unit = be64toh(mnl_attr_get_u64(tb[NFTA_LIMIT_UNIT])); - e->flags |= (1 << NFT_EXPR_LIMIT_UNIT); + e->flags |= (1 << NFTNL_EXPR_LIMIT_UNIT); } return 0; } -static int nft_rule_expr_limit_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +static int nftnl_rule_expr_limit_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING uint64_t uval64; - if (nft_jansson_parse_val(root, "rate", NFT_TYPE_U64, &uval64, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_RATE, uval64); + if (nftnl_jansson_parse_val(root, "rate", NFTNL_TYPE_U64, &uval64, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_LIMIT_RATE, uval64); - if (nft_jansson_parse_val(root, "unit", NFT_TYPE_U64, &uval64, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_UNIT, uval64); + if (nftnl_jansson_parse_val(root, "unit", NFTNL_TYPE_U64, &uval64, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_LIMIT_UNIT, uval64); return 0; #else @@ -134,20 +134,20 @@ static int nft_rule_expr_limit_json_parse(struct nft_rule_expr *e, json_t *root, #endif } -static int nft_rule_expr_limit_xml_parse(struct nft_rule_expr *e, +static int nftnl_rule_expr_limit_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { #ifdef XML_PARSING uint64_t rate, unit; - if (nft_mxml_num_parse(tree, "rate", MXML_DESCEND_FIRST, BASE_DEC, - &rate, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_RATE, rate); + if (nftnl_mxml_num_parse(tree, "rate", MXML_DESCEND_FIRST, BASE_DEC, + &rate, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_LIMIT_RATE, rate); - if (nft_mxml_num_parse(tree, "unit", MXML_DESCEND_FIRST, BASE_DEC, - &unit, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_UNIT, unit); + if (nftnl_mxml_num_parse(tree, "unit", MXML_DESCEND_FIRST, BASE_DEC, + &unit, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_LIMIT_UNIT, unit); return 0; #else @@ -168,40 +168,40 @@ static const char *get_unit(uint64_t u) return "error"; } -static int nft_rule_expr_limit_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_limit_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_limit *limit = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_LIMIT_RATE)) - nft_buf_u64(&b, type, limit->rate, RATE); - if (e->flags & (1 << NFT_EXPR_LIMIT_UNIT)) - nft_buf_u64(&b, type, limit->unit, UNIT); + if (e->flags & (1 << NFTNL_EXPR_LIMIT_RATE)) + nftnl_buf_u64(&b, type, limit->rate, RATE); + if (e->flags & (1 << NFTNL_EXPR_LIMIT_UNIT)) + nftnl_buf_u64(&b, type, limit->unit, UNIT); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } -static int nft_rule_expr_limit_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e) +static int nftnl_rule_expr_limit_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); return snprintf(buf, len, "rate %"PRIu64"/%s ", limit->rate, get_unit(limit->unit)); } static int -nft_rule_expr_limit_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_limit_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch(type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_limit_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_limit_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_limit_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_limit_export(buf, len, e, type); default: break; } @@ -210,13 +210,13 @@ nft_rule_expr_limit_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_limit = { .name = "limit", - .alloc_len = sizeof(struct nft_expr_limit), + .alloc_len = sizeof(struct nftnl_expr_limit), .max_attr = NFTA_LIMIT_MAX, - .set = nft_rule_expr_limit_set, - .get = nft_rule_expr_limit_get, - .parse = nft_rule_expr_limit_parse, - .build = nft_rule_expr_limit_build, - .snprintf = nft_rule_expr_limit_snprintf, - .xml_parse = nft_rule_expr_limit_xml_parse, - .json_parse = nft_rule_expr_limit_json_parse, + .set = nftnl_rule_expr_limit_set, + .get = nftnl_rule_expr_limit_get, + .parse = nftnl_rule_expr_limit_parse, + .build = nftnl_rule_expr_limit_build, + .snprintf = nftnl_rule_expr_limit_snprintf, + .xml_parse = nftnl_rule_expr_limit_xml_parse, + .json_parse = nftnl_rule_expr_limit_json_parse, }; diff --git a/src/expr/log.c b/src/expr/log.c index 19bef56..2f1f705 100644 --- a/src/expr/log.c +++ b/src/expr/log.c @@ -21,7 +21,7 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_log { +struct nftnl_expr_log { uint32_t snaplen; uint16_t group; uint16_t qthreshold; @@ -30,31 +30,31 @@ struct nft_expr_log { const char *prefix; }; -static int nft_rule_expr_log_set(struct nft_rule_expr *e, uint16_t type, +static int nftnl_rule_expr_log_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_log *log = nft_expr_data(e); + struct nftnl_expr_log *log = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_LOG_PREFIX: + case NFTNL_EXPR_LOG_PREFIX: if (log->prefix) xfree(log->prefix); log->prefix = strdup(data); break; - case NFT_EXPR_LOG_GROUP: + case NFTNL_EXPR_LOG_GROUP: log->group = *((uint16_t *)data); break; - case NFT_EXPR_LOG_SNAPLEN: + case NFTNL_EXPR_LOG_SNAPLEN: log->snaplen = *((uint32_t *)data); break; - case NFT_EXPR_LOG_QTHRESHOLD: + case NFTNL_EXPR_LOG_QTHRESHOLD: log->qthreshold = *((uint16_t *)data); break; - case NFT_EXPR_LOG_LEVEL: + case NFTNL_EXPR_LOG_LEVEL: log->level = *((uint32_t *)data); break; - case NFT_EXPR_LOG_FLAGS: + case NFTNL_EXPR_LOG_FLAGS: log->flags = *((uint32_t *)data); break; default: @@ -64,35 +64,35 @@ static int nft_rule_expr_log_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_log_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_log_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_log *log = nft_expr_data(e); + struct nftnl_expr_log *log = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_LOG_PREFIX: + case NFTNL_EXPR_LOG_PREFIX: *data_len = strlen(log->prefix)+1; return log->prefix; - case NFT_EXPR_LOG_GROUP: + case NFTNL_EXPR_LOG_GROUP: *data_len = sizeof(log->group); return &log->group; - case NFT_EXPR_LOG_SNAPLEN: + case NFTNL_EXPR_LOG_SNAPLEN: *data_len = sizeof(log->snaplen); return &log->snaplen; - case NFT_EXPR_LOG_QTHRESHOLD: + case NFTNL_EXPR_LOG_QTHRESHOLD: *data_len = sizeof(log->qthreshold); return &log->qthreshold; - case NFT_EXPR_LOG_LEVEL: + case NFTNL_EXPR_LOG_LEVEL: *data_len = sizeof(log->level); return &log->level; - case NFT_EXPR_LOG_FLAGS: + case NFTNL_EXPR_LOG_FLAGS: *data_len = sizeof(log->flags); return &log->flags; } return NULL; } -static int nft_rule_expr_log_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_log_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -123,31 +123,31 @@ static int nft_rule_expr_log_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_log_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_log_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_log *log = nft_expr_data(e); + struct nftnl_expr_log *log = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_LOG_PREFIX)) + if (e->flags & (1 << NFTNL_EXPR_LOG_PREFIX)) mnl_attr_put_strz(nlh, NFTA_LOG_PREFIX, log->prefix); - if (e->flags & (1 << NFT_EXPR_LOG_GROUP)) + if (e->flags & (1 << NFTNL_EXPR_LOG_GROUP)) mnl_attr_put_u16(nlh, NFTA_LOG_GROUP, htons(log->group)); - if (e->flags & (1 << NFT_EXPR_LOG_SNAPLEN)) + if (e->flags & (1 << NFTNL_EXPR_LOG_SNAPLEN)) mnl_attr_put_u32(nlh, NFTA_LOG_SNAPLEN, htonl(log->snaplen)); - if (e->flags & (1 << NFT_EXPR_LOG_QTHRESHOLD)) + if (e->flags & (1 << NFTNL_EXPR_LOG_QTHRESHOLD)) mnl_attr_put_u16(nlh, NFTA_LOG_QTHRESHOLD, htons(log->qthreshold)); - if (e->flags & (1 << NFT_EXPR_LOG_LEVEL)) + if (e->flags & (1 << NFTNL_EXPR_LOG_LEVEL)) mnl_attr_put_u32(nlh, NFTA_LOG_LEVEL, htonl(log->level)); - if (e->flags & (1 << NFT_EXPR_LOG_FLAGS)) + if (e->flags & (1 << NFTNL_EXPR_LOG_FLAGS)) mnl_attr_put_u32(nlh, NFTA_LOG_FLAGS, htonl(log->flags)); } static int -nft_rule_expr_log_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_log_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_log *log = nft_expr_data(e); + struct nftnl_expr_log *log = nftnl_expr_data(e); struct nlattr *tb[NFTA_LOG_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_log_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_log_cb, tb) < 0) return -1; if (tb[NFTA_LOG_PREFIX]) { @@ -155,63 +155,63 @@ nft_rule_expr_log_parse(struct nft_rule_expr *e, struct nlattr *attr) xfree(log->prefix); log->prefix = strdup(mnl_attr_get_str(tb[NFTA_LOG_PREFIX])); - e->flags |= (1 << NFT_EXPR_LOG_PREFIX); + e->flags |= (1 << NFTNL_EXPR_LOG_PREFIX); } if (tb[NFTA_LOG_GROUP]) { log->group = ntohs(mnl_attr_get_u16(tb[NFTA_LOG_GROUP])); - e->flags |= (1 << NFT_EXPR_LOG_GROUP); + e->flags |= (1 << NFTNL_EXPR_LOG_GROUP); } if (tb[NFTA_LOG_SNAPLEN]) { log->snaplen = ntohl(mnl_attr_get_u32(tb[NFTA_LOG_SNAPLEN])); - e->flags |= (1 << NFT_EXPR_LOG_SNAPLEN); + e->flags |= (1 << NFTNL_EXPR_LOG_SNAPLEN); } if (tb[NFTA_LOG_QTHRESHOLD]) { log->qthreshold = ntohs(mnl_attr_get_u16(tb[NFTA_LOG_QTHRESHOLD])); - e->flags |= (1 << NFT_EXPR_LOG_QTHRESHOLD); + e->flags |= (1 << NFTNL_EXPR_LOG_QTHRESHOLD); } if (tb[NFTA_LOG_LEVEL]) { log->level = ntohl(mnl_attr_get_u32(tb[NFTA_LOG_LEVEL])); - e->flags |= (1 << NFT_EXPR_LOG_LEVEL); + e->flags |= (1 << NFTNL_EXPR_LOG_LEVEL); } if (tb[NFTA_LOG_FLAGS]) { log->flags = ntohl(mnl_attr_get_u32(tb[NFTA_LOG_FLAGS])); - e->flags |= (1 << NFT_EXPR_LOG_FLAGS); + e->flags |= (1 << NFTNL_EXPR_LOG_FLAGS); } return 0; } -static int nft_rule_expr_log_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +static int nftnl_rule_expr_log_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *prefix; uint32_t snaplen, level, flags; uint16_t group, qthreshold; - prefix = nft_jansson_parse_str(root, "prefix", err); + prefix = nftnl_jansson_parse_str(root, "prefix", err); if (prefix != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_LOG_PREFIX, prefix); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_LOG_PREFIX, prefix); - if (nft_jansson_parse_val(root, "group", NFT_TYPE_U16, &group, + if (nftnl_jansson_parse_val(root, "group", NFTNL_TYPE_U16, &group, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_LOG_GROUP, group); + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_LOG_GROUP, group); - if (nft_jansson_parse_val(root, "snaplen", NFT_TYPE_U32, &snaplen, + if (nftnl_jansson_parse_val(root, "snaplen", NFTNL_TYPE_U32, &snaplen, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOG_SNAPLEN, snaplen); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOG_SNAPLEN, snaplen); - if (nft_jansson_parse_val(root, "qthreshold", NFT_TYPE_U16, + if (nftnl_jansson_parse_val(root, "qthreshold", NFTNL_TYPE_U16, &qthreshold, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_LOG_QTHRESHOLD, qthreshold); + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_LOG_QTHRESHOLD, qthreshold); - if (nft_jansson_parse_val(root, "level", NFT_TYPE_U32, &level, + if (nftnl_jansson_parse_val(root, "level", NFTNL_TYPE_U32, &level, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOG_LEVEL, level); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOG_LEVEL, level); - if (nft_jansson_parse_val(root, "flags", NFT_TYPE_U32, &flags, + if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOG_FLAGS, flags); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOG_FLAGS, flags); return 0; #else @@ -220,42 +220,42 @@ static int nft_rule_expr_log_json_parse(struct nft_rule_expr *e, json_t *root, #endif } -static int nft_rule_expr_log_xml_parse(struct nft_rule_expr *e, +static int nftnl_rule_expr_log_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *prefix; uint32_t snaplen, level, flags; uint16_t group, qthreshold; - prefix = nft_mxml_str_parse(tree, "prefix", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + prefix = nftnl_mxml_str_parse(tree, "prefix", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (prefix != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_LOG_PREFIX, prefix); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_LOG_PREFIX, prefix); - if (nft_mxml_num_parse(tree, "group", MXML_DESCEND_FIRST, BASE_DEC, - &group, NFT_TYPE_U16, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_LOG_GROUP, group); + if (nftnl_mxml_num_parse(tree, "group", MXML_DESCEND_FIRST, BASE_DEC, + &group, NFTNL_TYPE_U16, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_LOG_GROUP, group); - if (nft_mxml_num_parse(tree, "snaplen", MXML_DESCEND_FIRST, BASE_DEC, - &snaplen, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOG_SNAPLEN, snaplen); + if (nftnl_mxml_num_parse(tree, "snaplen", MXML_DESCEND_FIRST, BASE_DEC, + &snaplen, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOG_SNAPLEN, snaplen); - if (nft_mxml_num_parse(tree, "qthreshold", MXML_DESCEND_FIRST, BASE_DEC, - &qthreshold, NFT_TYPE_U16, NFT_XML_MAND, + if (nftnl_mxml_num_parse(tree, "qthreshold", MXML_DESCEND_FIRST, BASE_DEC, + &qthreshold, NFTNL_TYPE_U16, NFTNL_XML_MAND, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_LOG_QTHRESHOLD, qthreshold); + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_LOG_QTHRESHOLD, qthreshold); - if (nft_mxml_num_parse(tree, "level", MXML_DESCEND_FIRST, BASE_DEC, - &level, NFT_TYPE_U16, NFT_XML_MAND, + if (nftnl_mxml_num_parse(tree, "level", MXML_DESCEND_FIRST, BASE_DEC, + &level, NFTNL_TYPE_U16, NFTNL_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOG_LEVEL, level); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOG_LEVEL, level); - if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, - &flags, NFT_TYPE_U16, NFT_XML_MAND, + if (nftnl_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, + &flags, NFTNL_TYPE_U16, NFTNL_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOG_FLAGS, flags); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOG_FLAGS, flags); return 0; #else @@ -264,21 +264,21 @@ static int nft_rule_expr_log_xml_parse(struct nft_rule_expr *e, #endif } -static int nft_rule_expr_log_snprintf_default(char *buf, size_t size, - struct nft_rule_expr *e) +static int nftnl_rule_expr_log_snprintf_default(char *buf, size_t size, + struct nftnl_rule_expr *e) { - struct nft_expr_log *log = nft_expr_data(e); + struct nftnl_expr_log *log = nftnl_expr_data(e); int ret, offset = 0, len = size; ret = snprintf(buf, len, "prefix %s ", log->prefix); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (e->flags & (1 << NFT_EXPR_LOG_GROUP)) { + if (e->flags & (1 << NFTNL_EXPR_LOG_GROUP)) { ret = snprintf(buf + offset, len, "group %u snaplen %u qthreshold %u", log->group, log->snaplen, log->qthreshold); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - } else if (e->flags & (1 << NFT_EXPR_LOG_LEVEL)) { + } else if (e->flags & (1 << NFTNL_EXPR_LOG_LEVEL)) { ret = snprintf(buf + offset, len, "level %u flags %u", log->level, log->flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -287,61 +287,61 @@ static int nft_rule_expr_log_snprintf_default(char *buf, size_t size, return offset; } -static int nft_rule_expr_log_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_log_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_log *log = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFT_EXPR_LOG_PREFIX)) - nft_buf_str(&b, type, log->prefix, PREFIX); - if (e->flags & (1 << NFT_EXPR_LOG_GROUP)) - nft_buf_u32(&b, type, log->group, GROUP); - if (e->flags & (1 << NFT_EXPR_LOG_SNAPLEN)) - nft_buf_u32(&b, type, log->snaplen, SNAPLEN); - if (e->flags & (1 << NFT_EXPR_LOG_QTHRESHOLD)) - nft_buf_u32(&b, type, log->qthreshold, QTHRESH); - if (e->flags & (1 << NFT_EXPR_LOG_LEVEL)) - nft_buf_u32(&b, type, log->level, LEVEL); - if (e->flags & (1 << NFT_EXPR_LOG_FLAGS)) - nft_buf_u32(&b, type, log->level, FLAGS); - - return nft_buf_done(&b); + struct nftnl_expr_log *log = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); + + if (e->flags & (1 << NFTNL_EXPR_LOG_PREFIX)) + nftnl_buf_str(&b, type, log->prefix, PREFIX); + if (e->flags & (1 << NFTNL_EXPR_LOG_GROUP)) + nftnl_buf_u32(&b, type, log->group, GROUP); + if (e->flags & (1 << NFTNL_EXPR_LOG_SNAPLEN)) + nftnl_buf_u32(&b, type, log->snaplen, SNAPLEN); + if (e->flags & (1 << NFTNL_EXPR_LOG_QTHRESHOLD)) + nftnl_buf_u32(&b, type, log->qthreshold, QTHRESH); + if (e->flags & (1 << NFTNL_EXPR_LOG_LEVEL)) + nftnl_buf_u32(&b, type, log->level, LEVEL); + if (e->flags & (1 << NFTNL_EXPR_LOG_FLAGS)) + nftnl_buf_u32(&b, type, log->level, FLAGS); + + return nftnl_buf_done(&b); } static int -nft_rule_expr_log_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_log_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch(type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_log_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_log_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_log_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_log_export(buf, len, e, type); default: break; } return -1; } -static void nft_rule_expr_log_free(struct nft_rule_expr *e) +static void nftnl_rule_expr_log_free(struct nftnl_rule_expr *e) { - struct nft_expr_log *log = nft_expr_data(e); + struct nftnl_expr_log *log = nftnl_expr_data(e); xfree(log->prefix); } struct expr_ops expr_ops_log = { .name = "log", - .alloc_len = sizeof(struct nft_expr_log), + .alloc_len = sizeof(struct nftnl_expr_log), .max_attr = NFTA_LOG_MAX, - .free = nft_rule_expr_log_free, - .set = nft_rule_expr_log_set, - .get = nft_rule_expr_log_get, - .parse = nft_rule_expr_log_parse, - .build = nft_rule_expr_log_build, - .snprintf = nft_rule_expr_log_snprintf, - .xml_parse = nft_rule_expr_log_xml_parse, - .json_parse = nft_rule_expr_log_json_parse, + .free = nftnl_rule_expr_log_free, + .set = nftnl_rule_expr_log_set, + .get = nftnl_rule_expr_log_get, + .parse = nftnl_rule_expr_log_parse, + .build = nftnl_rule_expr_log_build, + .snprintf = nftnl_rule_expr_log_snprintf, + .xml_parse = nftnl_rule_expr_log_xml_parse, + .json_parse = nftnl_rule_expr_log_json_parse, }; diff --git a/src/expr/lookup.c b/src/expr/lookup.c index b2f0aa4..98ac1ad 100644 --- a/src/expr/lookup.c +++ b/src/expr/lookup.c @@ -25,7 +25,7 @@ #define IFNAMSIZ 16 #endif -struct nft_expr_lookup { +struct nftnl_expr_lookup { enum nft_registers sreg; enum nft_registers dreg; char set_name[IFNAMSIZ]; @@ -33,23 +33,23 @@ struct nft_expr_lookup { }; static int -nft_rule_expr_lookup_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_lookup_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_lookup *lookup = nft_expr_data(e); + struct nftnl_expr_lookup *lookup = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_LOOKUP_SREG: + case NFTNL_EXPR_LOOKUP_SREG: lookup->sreg = *((uint32_t *)data); break; - case NFT_EXPR_LOOKUP_DREG: + case NFTNL_EXPR_LOOKUP_DREG: lookup->dreg = *((uint32_t *)data); break; - case NFT_EXPR_LOOKUP_SET: + case NFTNL_EXPR_LOOKUP_SET: snprintf(lookup->set_name, sizeof(lookup->set_name), "%s", (const char *)data); break; - case NFT_EXPR_LOOKUP_SET_ID: + case NFTNL_EXPR_LOOKUP_SET_ID: lookup->set_id = *((uint32_t *)data); break; default: @@ -59,27 +59,27 @@ nft_rule_expr_lookup_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_lookup_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_lookup_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_lookup *lookup = nft_expr_data(e); + struct nftnl_expr_lookup *lookup = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_LOOKUP_SREG: + case NFTNL_EXPR_LOOKUP_SREG: *data_len = sizeof(lookup->sreg); return &lookup->sreg; - case NFT_EXPR_LOOKUP_DREG: + case NFTNL_EXPR_LOOKUP_DREG: *data_len = sizeof(lookup->dreg); return &lookup->dreg; - case NFT_EXPR_LOOKUP_SET: + case NFTNL_EXPR_LOOKUP_SET: return lookup->set_name; - case NFT_EXPR_LOOKUP_SET_ID: + case NFTNL_EXPR_LOOKUP_SET_ID: return &lookup->set_id; } return NULL; } -static int nft_rule_expr_lookup_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_lookup_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -105,70 +105,70 @@ static int nft_rule_expr_lookup_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_lookup_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_lookup_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_lookup *lookup = nft_expr_data(e); + struct nftnl_expr_lookup *lookup = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_LOOKUP_SREG)) + if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SREG)) mnl_attr_put_u32(nlh, NFTA_LOOKUP_SREG, htonl(lookup->sreg)); - if (e->flags & (1 << NFT_EXPR_LOOKUP_DREG)) + if (e->flags & (1 << NFTNL_EXPR_LOOKUP_DREG)) mnl_attr_put_u32(nlh, NFTA_LOOKUP_DREG, htonl(lookup->dreg)); - if (e->flags & (1 << NFT_EXPR_LOOKUP_SET)) + if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SET)) mnl_attr_put_strz(nlh, NFTA_LOOKUP_SET, lookup->set_name); - if (e->flags & (1 << NFT_EXPR_LOOKUP_SET_ID)) { + if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SET_ID)) { mnl_attr_put_u32(nlh, NFTA_LOOKUP_SET_ID, htonl(lookup->set_id)); } } static int -nft_rule_expr_lookup_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_lookup_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_lookup *lookup = nft_expr_data(e); + struct nftnl_expr_lookup *lookup = nftnl_expr_data(e); struct nlattr *tb[NFTA_LOOKUP_MAX+1] = {}; int ret = 0; - if (mnl_attr_parse_nested(attr, nft_rule_expr_lookup_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_lookup_cb, tb) < 0) return -1; if (tb[NFTA_LOOKUP_SREG]) { lookup->sreg = ntohl(mnl_attr_get_u32(tb[NFTA_LOOKUP_SREG])); - e->flags |= (1 << NFT_EXPR_LOOKUP_SREG); + e->flags |= (1 << NFTNL_EXPR_LOOKUP_SREG); } if (tb[NFTA_LOOKUP_DREG]) { lookup->dreg = ntohl(mnl_attr_get_u32(tb[NFTA_LOOKUP_DREG])); - e->flags |= (1 << NFT_EXPR_LOOKUP_DREG); + e->flags |= (1 << NFTNL_EXPR_LOOKUP_DREG); } if (tb[NFTA_LOOKUP_SET]) { strcpy(lookup->set_name, mnl_attr_get_str(tb[NFTA_LOOKUP_SET])); - e->flags |= (1 << NFT_EXPR_LOOKUP_SET); + e->flags |= (1 << NFTNL_EXPR_LOOKUP_SET); } if (tb[NFTA_LOOKUP_SET_ID]) { lookup->set_id = ntohl(mnl_attr_get_u32(tb[NFTA_LOOKUP_SET_ID])); - e->flags |= (1 << NFT_EXPR_LOOKUP_SET_ID); + e->flags |= (1 << NFTNL_EXPR_LOOKUP_SET_ID); } return ret; } static int -nft_rule_expr_lookup_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_lookup_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *set_name; uint32_t sreg, dreg; - set_name = nft_jansson_parse_str(root, "set", err); + set_name = nftnl_jansson_parse_str(root, "set", err); if (set_name != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_LOOKUP_SET, set_name); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_LOOKUP_SET, set_name); - if (nft_jansson_parse_reg(root, "sreg", NFT_TYPE_U32, &sreg, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_SREG, sreg); + if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &sreg, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOOKUP_SREG, sreg); - if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, &dreg, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_DREG, dreg); + if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &dreg, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOOKUP_DREG, dreg); return 0; #else @@ -178,25 +178,25 @@ nft_rule_expr_lookup_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_lookup_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_lookup_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *set_name; uint32_t sreg, dreg; - set_name = nft_mxml_str_parse(tree, "set", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + set_name = nftnl_mxml_str_parse(tree, "set", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (set_name != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_LOOKUP_SET, set_name); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_LOOKUP_SET, set_name); - if (nft_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND, NFT_XML_MAND, + if (nftnl_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND, NFTNL_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_SREG, sreg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOOKUP_SREG, sreg); - if (nft_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND, NFT_XML_OPT, + if (nftnl_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND, NFTNL_XML_OPT, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_DREG, dreg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOOKUP_DREG, dreg); return 0; #else @@ -206,34 +206,34 @@ nft_rule_expr_lookup_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, } static int -nft_rule_expr_lookup_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +nftnl_rule_expr_lookup_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_lookup *l = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_lookup *l = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_LOOKUP_SET)) - nft_buf_str(&b, type, l->set_name, SET); - if (e->flags & (1 << NFT_EXPR_LOOKUP_SREG)) - nft_buf_u32(&b, type, l->sreg, SREG); - if (e->flags & (1 << NFT_EXPR_LOOKUP_DREG)) - nft_buf_u32(&b, type, l->dreg, DREG); + if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SET)) + nftnl_buf_str(&b, type, l->set_name, SET); + if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SREG)) + nftnl_buf_u32(&b, type, l->sreg, SREG); + if (e->flags & (1 << NFTNL_EXPR_LOOKUP_DREG)) + nftnl_buf_u32(&b, type, l->dreg, DREG); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } static int -nft_rule_expr_lookup_snprintf_default(char *buf, size_t size, - struct nft_rule_expr *e) +nftnl_rule_expr_lookup_snprintf_default(char *buf, size_t size, + struct nftnl_rule_expr *e) { int len = size, offset = 0, ret; - struct nft_expr_lookup *l = nft_expr_data(e); + struct nftnl_expr_lookup *l = nftnl_expr_data(e); ret = snprintf(buf, len, "reg %u set %s ", l->sreg, l->set_name); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (e->flags & (1 << NFT_EXPR_LOOKUP_DREG)) { + if (e->flags & (1 << NFTNL_EXPR_LOOKUP_DREG)) { ret = snprintf(buf+offset, len, "dreg %u ", l->dreg); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } @@ -242,16 +242,16 @@ nft_rule_expr_lookup_snprintf_default(char *buf, size_t size, } static int -nft_rule_expr_lookup_snprintf(char *buf, size_t size, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_lookup_snprintf(char *buf, size_t size, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch(type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_lookup_snprintf_default(buf, size, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_lookup_export(buf, size, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_lookup_snprintf_default(buf, size, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_lookup_export(buf, size, e, type); default: break; } @@ -260,13 +260,13 @@ nft_rule_expr_lookup_snprintf(char *buf, size_t size, uint32_t type, struct expr_ops expr_ops_lookup = { .name = "lookup", - .alloc_len = sizeof(struct nft_expr_lookup), + .alloc_len = sizeof(struct nftnl_expr_lookup), .max_attr = NFTA_LOOKUP_MAX, - .set = nft_rule_expr_lookup_set, - .get = nft_rule_expr_lookup_get, - .parse = nft_rule_expr_lookup_parse, - .build = nft_rule_expr_lookup_build, - .snprintf = nft_rule_expr_lookup_snprintf, - .xml_parse = nft_rule_expr_lookup_xml_parse, - .json_parse = nft_rule_expr_lookup_json_parse, + .set = nftnl_rule_expr_lookup_set, + .get = nftnl_rule_expr_lookup_get, + .parse = nftnl_rule_expr_lookup_parse, + .build = nftnl_rule_expr_lookup_build, + .snprintf = nftnl_rule_expr_lookup_snprintf, + .xml_parse = nftnl_rule_expr_lookup_xml_parse, + .json_parse = nftnl_rule_expr_lookup_json_parse, }; diff --git a/src/expr/masq.c b/src/expr/masq.c index e25587f..ee49151 100644 --- a/src/expr/masq.c +++ b/src/expr/masq.c @@ -20,18 +20,18 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_masq { +struct nftnl_expr_masq { uint32_t flags; }; static int -nft_rule_expr_masq_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_masq_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_masq *masq = nft_expr_data(e); + struct nftnl_expr_masq *masq = nftnl_expr_data(e); switch (type) { - case NFT_EXPR_MASQ_FLAGS: + case NFTNL_EXPR_MASQ_FLAGS: masq->flags = *((uint32_t *)data); break; default: @@ -41,20 +41,20 @@ nft_rule_expr_masq_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_masq_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_masq_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_masq *masq = nft_expr_data(e); + struct nftnl_expr_masq *masq = nftnl_expr_data(e); switch (type) { - case NFT_EXPR_MASQ_FLAGS: + case NFTNL_EXPR_MASQ_FLAGS: *data_len = sizeof(masq->flags); return &masq->flags; } return NULL; } -static int nft_rule_expr_masq_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_masq_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -74,41 +74,41 @@ static int nft_rule_expr_masq_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_masq_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_masq_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_masq *masq = nft_expr_data(e); + struct nftnl_expr_masq *masq = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_MASQ_FLAGS)) + if (e->flags & (1 << NFTNL_EXPR_MASQ_FLAGS)) mnl_attr_put_u32(nlh, NFTA_MASQ_FLAGS, htobe32(masq->flags)); } static int -nft_rule_expr_masq_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_masq_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_masq *masq = nft_expr_data(e); + struct nftnl_expr_masq *masq = nftnl_expr_data(e); struct nlattr *tb[NFTA_MASQ_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_masq_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_masq_cb, tb) < 0) return -1; if (tb[NFTA_MASQ_FLAGS]) { masq->flags = be32toh(mnl_attr_get_u32(tb[NFTA_MASQ_FLAGS])); - e->flags |= (1 << NFT_EXPR_MASQ_FLAGS); + e->flags |= (1 << NFTNL_EXPR_MASQ_FLAGS); } return 0; } static int -nft_rule_expr_masq_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_masq_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING uint32_t flags; - if (nft_jansson_parse_val(root, "flags", NFT_TYPE_U32, &flags, + if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_MASQ_FLAGS, flags); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_MASQ_FLAGS, flags); return 0; #else @@ -118,15 +118,15 @@ nft_rule_expr_masq_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_masq_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_masq_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING uint32_t flags; - if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, - &flags, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_MASQ_FLAGS, flags); + if (nftnl_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, + &flags, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_MASQ_FLAGS, flags); return 0; #else @@ -134,38 +134,38 @@ nft_rule_expr_masq_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, return -1; #endif } -static int nft_rule_expr_masq_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_masq_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_masq *masq = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_masq *masq = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_MASQ_FLAGS)) - nft_buf_u32(&b, type, masq->flags, FLAGS); + if (e->flags & (1 << NFTNL_EXPR_MASQ_FLAGS)) + nftnl_buf_u32(&b, type, masq->flags, FLAGS); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } -static int nft_rule_expr_masq_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e) +static int nftnl_rule_expr_masq_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e) { - struct nft_expr_masq *masq = nft_expr_data(e); + struct nftnl_expr_masq *masq = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_MASQ_FLAGS)) + if (e->flags & (1 << NFTNL_EXPR_MASQ_FLAGS)) return snprintf(buf, len, "flags 0x%x ", masq->flags); return 0; } -static int nft_rule_expr_masq_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +static int nftnl_rule_expr_masq_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_masq_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_masq_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_masq_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_masq_export(buf, len, e, type); default: break; } @@ -174,13 +174,13 @@ static int nft_rule_expr_masq_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_masq = { .name = "masq", - .alloc_len = sizeof(struct nft_expr_masq), + .alloc_len = sizeof(struct nftnl_expr_masq), .max_attr = NFTA_MASQ_MAX, - .set = nft_rule_expr_masq_set, - .get = nft_rule_expr_masq_get, - .parse = nft_rule_expr_masq_parse, - .build = nft_rule_expr_masq_build, - .snprintf = nft_rule_expr_masq_snprintf, - .xml_parse = nft_rule_expr_masq_xml_parse, - .json_parse = nft_rule_expr_masq_json_parse, + .set = nftnl_rule_expr_masq_set, + .get = nftnl_rule_expr_masq_get, + .parse = nftnl_rule_expr_masq_parse, + .build = nftnl_rule_expr_masq_build, + .snprintf = nftnl_rule_expr_masq_snprintf, + .xml_parse = nftnl_rule_expr_masq_xml_parse, + .json_parse = nftnl_rule_expr_masq_json_parse, }; diff --git a/src/expr/match.c b/src/expr/match.c index e101c1f..1a550cc 100644 --- a/src/expr/match.c +++ b/src/expr/match.c @@ -27,7 +27,7 @@ /* From include/linux/netfilter/x_tables.h */ #define XT_EXTENSION_MAXNAMELEN 29 -struct nft_expr_match { +struct nftnl_expr_match { char name[XT_EXTENSION_MAXNAMELEN]; uint32_t rev; uint32_t data_len; @@ -35,20 +35,20 @@ struct nft_expr_match { }; static int -nft_rule_expr_match_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_match_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_match *mt = nft_expr_data(e); + struct nftnl_expr_match *mt = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_MT_NAME: + case NFTNL_EXPR_MT_NAME: snprintf(mt->name, sizeof(mt->name), "%.*s", data_len, (const char *)data); break; - case NFT_EXPR_MT_REV: + case NFTNL_EXPR_MT_REV: mt->rev = *((uint32_t *)data); break; - case NFT_EXPR_MT_INFO: + case NFTNL_EXPR_MT_INFO: if (mt->data) xfree(mt->data); @@ -62,26 +62,26 @@ nft_rule_expr_match_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_match_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_match_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_match *mt = nft_expr_data(e); + struct nftnl_expr_match *mt = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_MT_NAME: + case NFTNL_EXPR_MT_NAME: *data_len = sizeof(mt->name); return mt->name; - case NFT_EXPR_MT_REV: + case NFTNL_EXPR_MT_REV: *data_len = sizeof(mt->rev); return &mt->rev; - case NFT_EXPR_MT_INFO: + case NFTNL_EXPR_MT_INFO: *data_len = mt->data_len; return mt->data; } return NULL; } -static int nft_rule_expr_match_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_match_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -109,24 +109,24 @@ static int nft_rule_expr_match_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_match_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_match_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_match *mt = nft_expr_data(e); + struct nftnl_expr_match *mt = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_MT_NAME)) + if (e->flags & (1 << NFTNL_EXPR_MT_NAME)) mnl_attr_put_strz(nlh, NFTA_MATCH_NAME, mt->name); - if (e->flags & (1 << NFT_EXPR_MT_REV)) + if (e->flags & (1 << NFTNL_EXPR_MT_REV)) mnl_attr_put_u32(nlh, NFTA_MATCH_REV, htonl(mt->rev)); - if (e->flags & (1 << NFT_EXPR_MT_INFO)) + if (e->flags & (1 << NFTNL_EXPR_MT_INFO)) mnl_attr_put(nlh, NFTA_MATCH_INFO, mt->data_len, mt->data); } -static int nft_rule_expr_match_parse(struct nft_rule_expr *e, struct nlattr *attr) +static int nftnl_rule_expr_match_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_match *match = nft_expr_data(e); + struct nftnl_expr_match *match = nftnl_expr_data(e); struct nlattr *tb[NFTA_MATCH_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_match_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_match_cb, tb) < 0) return -1; if (tb[NFTA_MATCH_NAME]) { @@ -134,12 +134,12 @@ static int nft_rule_expr_match_parse(struct nft_rule_expr *e, struct nlattr *att mnl_attr_get_str(tb[NFTA_MATCH_NAME])); match->name[XT_EXTENSION_MAXNAMELEN-1] = '\0'; - e->flags |= (1 << NFT_EXPR_MT_NAME); + e->flags |= (1 << NFTNL_EXPR_MT_NAME); } if (tb[NFTA_MATCH_REV]) { match->rev = ntohl(mnl_attr_get_u32(tb[NFTA_MATCH_REV])); - e->flags |= (1 << NFT_EXPR_MT_REV); + e->flags |= (1 << NFTNL_EXPR_MT_REV); } if (tb[NFTA_MATCH_INFO]) { @@ -158,21 +158,21 @@ static int nft_rule_expr_match_parse(struct nft_rule_expr *e, struct nlattr *att match->data = match_data; match->data_len = len; - e->flags |= (1 << NFT_EXPR_MT_INFO); + e->flags |= (1 << NFTNL_EXPR_MT_INFO); } return 0; } -static int nft_rule_expr_match_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +static int nftnl_rule_expr_match_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *name; - name = nft_jansson_parse_str(root, "name", err); + name = nftnl_jansson_parse_str(root, "name", err); if (name != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_MT_NAME, name); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_MT_NAME, name); return 0; #else @@ -182,16 +182,16 @@ static int nft_rule_expr_match_json_parse(struct nft_rule_expr *e, json_t *root, } -static int nft_rule_expr_match_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +static int nftnl_rule_expr_match_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *name; - name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + name = nftnl_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (name != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_MT_NAME, name); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_MT_NAME, name); /* mt->info is ignored until other solution is reached */ @@ -202,54 +202,54 @@ static int nft_rule_expr_match_xml_parse(struct nft_rule_expr *e, mxml_node_t *t #endif } -static int nft_rule_expr_match_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_match_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_match *mt = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_match *mt = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_MT_NAME)) - nft_buf_str(&b, type, mt->name, NAME); + if (e->flags & (1 << NFTNL_EXPR_MT_NAME)) + nftnl_buf_str(&b, type, mt->name, NAME); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } static int -nft_rule_expr_match_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_match_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { - struct nft_expr_match *match = nft_expr_data(e); + struct nftnl_expr_match *match = nftnl_expr_data(e); switch (type) { - case NFT_OUTPUT_DEFAULT: + case NFTNL_OUTPUT_DEFAULT: return snprintf(buf, len, "name %s rev %u ", match->name, match->rev); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_match_export(buf, len, e, type); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_match_export(buf, len, e, type); default: break; } return -1; } -static void nft_rule_expr_match_free(struct nft_rule_expr *e) +static void nftnl_rule_expr_match_free(struct nftnl_rule_expr *e) { - struct nft_expr_match *match = nft_expr_data(e); + struct nftnl_expr_match *match = nftnl_expr_data(e); xfree(match->data); } struct expr_ops expr_ops_match = { .name = "match", - .alloc_len = sizeof(struct nft_expr_match), + .alloc_len = sizeof(struct nftnl_expr_match), .max_attr = NFTA_MATCH_MAX, - .free = nft_rule_expr_match_free, - .set = nft_rule_expr_match_set, - .get = nft_rule_expr_match_get, - .parse = nft_rule_expr_match_parse, - .build = nft_rule_expr_match_build, - .snprintf = nft_rule_expr_match_snprintf, - .xml_parse = nft_rule_expr_match_xml_parse, - .json_parse = nft_rule_expr_match_json_parse, + .free = nftnl_rule_expr_match_free, + .set = nftnl_rule_expr_match_set, + .get = nftnl_rule_expr_match_get, + .parse = nftnl_rule_expr_match_parse, + .build = nftnl_rule_expr_match_build, + .snprintf = nftnl_rule_expr_match_snprintf, + .xml_parse = nftnl_rule_expr_match_xml_parse, + .json_parse = nftnl_rule_expr_match_json_parse, }; diff --git a/src/expr/meta.c b/src/expr/meta.c index cee09dd..98f7588 100644 --- a/src/expr/meta.c +++ b/src/expr/meta.c @@ -25,26 +25,26 @@ #define NFT_META_MAX (NFT_META_CGROUP + 1) #endif -struct nft_expr_meta { +struct nftnl_expr_meta { enum nft_meta_keys key; enum nft_registers dreg; enum nft_registers sreg; }; static int -nft_rule_expr_meta_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_meta_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_meta *meta = nft_expr_data(e); + struct nftnl_expr_meta *meta = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_META_KEY: + case NFTNL_EXPR_META_KEY: meta->key = *((uint32_t *)data); break; - case NFT_EXPR_META_DREG: + case NFTNL_EXPR_META_DREG: meta->dreg = *((uint32_t *)data); break; - case NFT_EXPR_META_SREG: + case NFTNL_EXPR_META_SREG: meta->sreg = *((uint32_t *)data); break; default: @@ -54,26 +54,26 @@ nft_rule_expr_meta_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_meta_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_meta_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_meta *meta = nft_expr_data(e); + struct nftnl_expr_meta *meta = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_META_KEY: + case NFTNL_EXPR_META_KEY: *data_len = sizeof(meta->key); return &meta->key; - case NFT_EXPR_META_DREG: + case NFTNL_EXPR_META_DREG: *data_len = sizeof(meta->dreg); return &meta->dreg; - case NFT_EXPR_META_SREG: + case NFTNL_EXPR_META_SREG: *data_len = sizeof(meta->sreg); return &meta->sreg; } return NULL; } -static int nft_rule_expr_meta_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_meta_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -95,38 +95,38 @@ static int nft_rule_expr_meta_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_meta_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_meta_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_meta *meta = nft_expr_data(e); + struct nftnl_expr_meta *meta = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_META_KEY)) + if (e->flags & (1 << NFTNL_EXPR_META_KEY)) mnl_attr_put_u32(nlh, NFTA_META_KEY, htonl(meta->key)); - if (e->flags & (1 << NFT_EXPR_META_DREG)) + if (e->flags & (1 << NFTNL_EXPR_META_DREG)) mnl_attr_put_u32(nlh, NFTA_META_DREG, htonl(meta->dreg)); - if (e->flags & (1 << NFT_EXPR_META_SREG)) + if (e->flags & (1 << NFTNL_EXPR_META_SREG)) mnl_attr_put_u32(nlh, NFTA_META_SREG, htonl(meta->sreg)); } static int -nft_rule_expr_meta_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_meta_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_meta *meta = nft_expr_data(e); + struct nftnl_expr_meta *meta = nftnl_expr_data(e); struct nlattr *tb[NFTA_META_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_meta_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_meta_cb, tb) < 0) return -1; if (tb[NFTA_META_KEY]) { meta->key = ntohl(mnl_attr_get_u32(tb[NFTA_META_KEY])); - e->flags |= (1 << NFT_EXPR_META_KEY); + e->flags |= (1 << NFTNL_EXPR_META_KEY); } if (tb[NFTA_META_DREG]) { meta->dreg = ntohl(mnl_attr_get_u32(tb[NFTA_META_DREG])); - e->flags |= (1 << NFT_EXPR_META_DREG); + e->flags |= (1 << NFTNL_EXPR_META_DREG); } if (tb[NFTA_META_SREG]) { meta->sreg = ntohl(mnl_attr_get_u32(tb[NFTA_META_SREG])); - e->flags |= (1 << NFT_EXPR_META_SREG); + e->flags |= (1 << NFTNL_EXPR_META_SREG); } return 0; @@ -180,31 +180,31 @@ static inline int str2meta_key(const char *str) return -1; } -static int nft_rule_expr_meta_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +static int nftnl_rule_expr_meta_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *key_str; uint32_t reg; int key; - key_str = nft_jansson_parse_str(root, "key", err); + key_str = nftnl_jansson_parse_str(root, "key", err); if (key_str != NULL) { key = str2meta_key(key_str); if (key >= 0) - nft_rule_expr_set_u32(e, NFT_EXPR_META_KEY, key); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_META_KEY, key); } - if (nft_jansson_node_exist(root, "dreg")) { - if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, ®, + if (nftnl_jansson_node_exist(root, "dreg")) { + if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_META_DREG, reg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_META_DREG, reg); } - if (nft_jansson_node_exist(root, "sreg")) { - if (nft_jansson_parse_reg(root, "sreg", NFT_TYPE_U32, ®, + if (nftnl_jansson_node_exist(root, "sreg")) { + if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_META_SREG, reg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_META_SREG, reg); } return 0; @@ -215,29 +215,29 @@ static int nft_rule_expr_meta_json_parse(struct nft_rule_expr *e, json_t *root, } -static int nft_rule_expr_meta_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +static int nftnl_rule_expr_meta_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *key_str; int key; uint32_t dreg, sreg; - key_str = nft_mxml_str_parse(tree, "key", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + key_str = nftnl_mxml_str_parse(tree, "key", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (key_str != NULL) { key = str2meta_key(key_str); if (key >= 0) - nft_rule_expr_set_u32(e, NFT_EXPR_META_KEY, key); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_META_KEY, key); } - if (nft_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, - NFT_XML_OPT, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_META_DREG, dreg); + if (nftnl_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, + NFTNL_XML_OPT, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_META_DREG, dreg); - if (nft_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, - NFT_XML_OPT, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_META_SREG, sreg); + if (nftnl_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST, + NFTNL_XML_OPT, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_META_SREG, sreg); return 0; #else @@ -247,48 +247,48 @@ static int nft_rule_expr_meta_xml_parse(struct nft_rule_expr *e, mxml_node_t *tr } static int -nft_rule_expr_meta_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e) +nftnl_rule_expr_meta_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e) { - struct nft_expr_meta *meta = nft_expr_data(e); + struct nftnl_expr_meta *meta = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_META_SREG)) { + if (e->flags & (1 << NFTNL_EXPR_META_SREG)) { return snprintf(buf, len, "set %s with reg %u ", meta_key2str(meta->key), meta->sreg); } - if (e->flags & (1 << NFT_EXPR_META_DREG)) { + if (e->flags & (1 << NFTNL_EXPR_META_DREG)) { return snprintf(buf, len, "load %s => reg %u ", meta_key2str(meta->key), meta->dreg); } return 0; } -static int nft_rule_expr_meta_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_meta_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_meta *meta = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_meta *meta = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_META_DREG)) - nft_buf_u32(&b, type, meta->dreg, DREG); - if (e->flags & (1 << NFT_EXPR_META_KEY)) - nft_buf_str(&b, type, meta_key2str(meta->key), KEY); - if (e->flags & (1 << NFT_EXPR_META_SREG)) - nft_buf_u32(&b, type, meta->sreg, SREG); + if (e->flags & (1 << NFTNL_EXPR_META_DREG)) + nftnl_buf_u32(&b, type, meta->dreg, DREG); + if (e->flags & (1 << NFTNL_EXPR_META_KEY)) + nftnl_buf_str(&b, type, meta_key2str(meta->key), KEY); + if (e->flags & (1 << NFTNL_EXPR_META_SREG)) + nftnl_buf_u32(&b, type, meta->sreg, SREG); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } static int -nft_rule_expr_meta_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_meta_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_meta_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_meta_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_meta_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_meta_export(buf, len, e, type); default: break; } @@ -297,13 +297,13 @@ nft_rule_expr_meta_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_meta = { .name = "meta", - .alloc_len = sizeof(struct nft_expr_meta), + .alloc_len = sizeof(struct nftnl_expr_meta), .max_attr = NFTA_META_MAX, - .set = nft_rule_expr_meta_set, - .get = nft_rule_expr_meta_get, - .parse = nft_rule_expr_meta_parse, - .build = nft_rule_expr_meta_build, - .snprintf = nft_rule_expr_meta_snprintf, - .xml_parse = nft_rule_expr_meta_xml_parse, - .json_parse = nft_rule_expr_meta_json_parse, + .set = nftnl_rule_expr_meta_set, + .get = nftnl_rule_expr_meta_get, + .parse = nftnl_rule_expr_meta_parse, + .build = nftnl_rule_expr_meta_build, + .snprintf = nftnl_rule_expr_meta_snprintf, + .xml_parse = nftnl_rule_expr_meta_xml_parse, + .json_parse = nftnl_rule_expr_meta_json_parse, }; diff --git a/src/expr/nat.c b/src/expr/nat.c index f888dfa..3b61344 100644 --- a/src/expr/nat.c +++ b/src/expr/nat.c @@ -24,7 +24,7 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_nat { +struct nftnl_expr_nat { enum nft_registers sreg_addr_min; enum nft_registers sreg_addr_max; enum nft_registers sreg_proto_min; @@ -35,31 +35,31 @@ struct nft_expr_nat { }; static int -nft_rule_expr_nat_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_nat_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_nat *nat = nft_expr_data(e); + struct nftnl_expr_nat *nat = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_NAT_TYPE: + case NFTNL_EXPR_NAT_TYPE: nat->type = *((uint32_t *)data); break; - case NFT_EXPR_NAT_FAMILY: + case NFTNL_EXPR_NAT_FAMILY: nat->family = *((uint32_t *)data); break; - case NFT_EXPR_NAT_REG_ADDR_MIN: + case NFTNL_EXPR_NAT_REG_ADDR_MIN: nat->sreg_addr_min = *((uint32_t *)data); break; - case NFT_EXPR_NAT_REG_ADDR_MAX: + case NFTNL_EXPR_NAT_REG_ADDR_MAX: nat->sreg_addr_max = *((uint32_t *)data); break; - case NFT_EXPR_NAT_REG_PROTO_MIN: + case NFTNL_EXPR_NAT_REG_PROTO_MIN: nat->sreg_proto_min = *((uint32_t *)data); break; - case NFT_EXPR_NAT_REG_PROTO_MAX: + case NFTNL_EXPR_NAT_REG_PROTO_MAX: nat->sreg_proto_max = *((uint32_t *)data); break; - case NFT_EXPR_NAT_FLAGS: + case NFTNL_EXPR_NAT_FLAGS: nat->flags = *((uint32_t *)data); break; default: @@ -70,38 +70,38 @@ nft_rule_expr_nat_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_nat_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_nat_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_nat *nat = nft_expr_data(e); + struct nftnl_expr_nat *nat = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_NAT_TYPE: + case NFTNL_EXPR_NAT_TYPE: *data_len = sizeof(nat->type); return &nat->type; - case NFT_EXPR_NAT_FAMILY: + case NFTNL_EXPR_NAT_FAMILY: *data_len = sizeof(nat->family); return &nat->family; - case NFT_EXPR_NAT_REG_ADDR_MIN: + case NFTNL_EXPR_NAT_REG_ADDR_MIN: *data_len = sizeof(nat->sreg_addr_min); return &nat->sreg_addr_min; - case NFT_EXPR_NAT_REG_ADDR_MAX: + case NFTNL_EXPR_NAT_REG_ADDR_MAX: *data_len = sizeof(nat->sreg_addr_max); return &nat->sreg_addr_max; - case NFT_EXPR_NAT_REG_PROTO_MIN: + case NFTNL_EXPR_NAT_REG_PROTO_MIN: *data_len = sizeof(nat->sreg_proto_min); return &nat->sreg_proto_min; - case NFT_EXPR_NAT_REG_PROTO_MAX: + case NFTNL_EXPR_NAT_REG_PROTO_MAX: *data_len = sizeof(nat->sreg_proto_max); return &nat->sreg_proto_max; - case NFT_EXPR_NAT_FLAGS: + case NFTNL_EXPR_NAT_FLAGS: *data_len = sizeof(nat->flags); return &nat->flags; } return NULL; } -static int nft_rule_expr_nat_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_nat_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -127,72 +127,72 @@ static int nft_rule_expr_nat_cb(const struct nlattr *attr, void *data) } static int -nft_rule_expr_nat_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_nat_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_nat *nat = nft_expr_data(e); + struct nftnl_expr_nat *nat = nftnl_expr_data(e); struct nlattr *tb[NFTA_NAT_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_nat_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_nat_cb, tb) < 0) return -1; if (tb[NFTA_NAT_TYPE]) { nat->type = ntohl(mnl_attr_get_u32(tb[NFTA_NAT_TYPE])); - e->flags |= (1 << NFT_EXPR_NAT_TYPE); + e->flags |= (1 << NFTNL_EXPR_NAT_TYPE); } if (tb[NFTA_NAT_FAMILY]) { nat->family = ntohl(mnl_attr_get_u32(tb[NFTA_NAT_FAMILY])); - e->flags |= (1 << NFT_EXPR_NAT_FAMILY); + e->flags |= (1 << NFTNL_EXPR_NAT_FAMILY); } if (tb[NFTA_NAT_REG_ADDR_MIN]) { nat->sreg_addr_min = ntohl(mnl_attr_get_u32(tb[NFTA_NAT_REG_ADDR_MIN])); - e->flags |= (1 << NFT_EXPR_NAT_REG_ADDR_MIN); + e->flags |= (1 << NFTNL_EXPR_NAT_REG_ADDR_MIN); } if (tb[NFTA_NAT_REG_ADDR_MAX]) { nat->sreg_addr_max = ntohl(mnl_attr_get_u32(tb[NFTA_NAT_REG_ADDR_MAX])); - e->flags |= (1 << NFT_EXPR_NAT_REG_ADDR_MAX); + e->flags |= (1 << NFTNL_EXPR_NAT_REG_ADDR_MAX); } if (tb[NFTA_NAT_REG_PROTO_MIN]) { nat->sreg_proto_min = ntohl(mnl_attr_get_u32(tb[NFTA_NAT_REG_PROTO_MIN])); - e->flags |= (1 << NFT_EXPR_NAT_REG_PROTO_MIN); + e->flags |= (1 << NFTNL_EXPR_NAT_REG_PROTO_MIN); } if (tb[NFTA_NAT_REG_PROTO_MAX]) { nat->sreg_proto_max = ntohl(mnl_attr_get_u32(tb[NFTA_NAT_REG_PROTO_MAX])); - e->flags |= (1 << NFT_EXPR_NAT_REG_PROTO_MAX); + e->flags |= (1 << NFTNL_EXPR_NAT_REG_PROTO_MAX); } if (tb[NFTA_NAT_FLAGS]) { nat->flags = ntohl(mnl_attr_get_u32(tb[NFTA_NAT_FLAGS])); - e->flags |= (1 << NFT_EXPR_NAT_FLAGS); + e->flags |= (1 << NFTNL_EXPR_NAT_FLAGS); } return 0; } static void -nft_rule_expr_nat_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_nat_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_nat *nat = nft_expr_data(e); + struct nftnl_expr_nat *nat = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_NAT_TYPE)) + if (e->flags & (1 << NFTNL_EXPR_NAT_TYPE)) mnl_attr_put_u32(nlh, NFTA_NAT_TYPE, htonl(nat->type)); - if (e->flags & (1 << NFT_EXPR_NAT_FAMILY)) + if (e->flags & (1 << NFTNL_EXPR_NAT_FAMILY)) mnl_attr_put_u32(nlh, NFTA_NAT_FAMILY, htonl(nat->family)); - if (e->flags & (1 << NFT_EXPR_NAT_REG_ADDR_MIN)) + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MIN)) mnl_attr_put_u32(nlh, NFTA_NAT_REG_ADDR_MIN, htonl(nat->sreg_addr_min)); - if (e->flags & (1 << NFT_EXPR_NAT_REG_ADDR_MAX)) + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MAX)) mnl_attr_put_u32(nlh, NFTA_NAT_REG_ADDR_MAX, htonl(nat->sreg_addr_max)); - if (e->flags & (1 << NFT_EXPR_NAT_REG_PROTO_MIN)) + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MIN)) mnl_attr_put_u32(nlh, NFTA_NAT_REG_PROTO_MIN, htonl(nat->sreg_proto_min)); - if (e->flags & (1 << NFT_EXPR_NAT_REG_PROTO_MAX)) + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MAX)) mnl_attr_put_u32(nlh, NFTA_NAT_REG_PROTO_MAX, htonl(nat->sreg_proto_max)); - if (e->flags & (1 << NFT_EXPR_NAT_FLAGS)) + if (e->flags & (1 << NFTNL_EXPR_NAT_FLAGS)) mnl_attr_put_u32(nlh, NFTA_NAT_FLAGS, htonl(nat->flags)); } @@ -208,7 +208,7 @@ static inline const char *nat2str(uint16_t nat) } } -static inline int nft_str2nat(const char *nat) +static inline int nftnl_str2nat(const char *nat) { if (strcmp(nat, "snat") == 0) return NFT_NAT_SNAT; @@ -220,53 +220,53 @@ static inline int nft_str2nat(const char *nat) } } -static int nft_rule_expr_nat_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +static int nftnl_rule_expr_nat_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *nat_type, *family_str; uint32_t reg, flags; int val32; - nat_type = nft_jansson_parse_str(root, "nat_type", err); + nat_type = nftnl_jansson_parse_str(root, "nat_type", err); if (nat_type == NULL) return -1; - val32 = nft_str2nat(nat_type); + val32 = nftnl_str2nat(nat_type); if (val32 < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_TYPE, val32); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_TYPE, val32); - family_str = nft_jansson_parse_str(root, "family", err); + family_str = nftnl_jansson_parse_str(root, "family", err); if (family_str == NULL) return -1; - val32 = nft_str2family(family_str); + val32 = nftnl_str2family(family_str); if (val32 < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_FAMILY, val32); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_FAMILY, val32); - if (nft_jansson_parse_reg(root, "sreg_addr_min", NFT_TYPE_U32, + if (nftnl_jansson_parse_reg(root, "sreg_addr_min", NFTNL_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_REG_ADDR_MIN, reg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_REG_ADDR_MIN, reg); - if (nft_jansson_parse_reg(root, "sreg_addr_max", NFT_TYPE_U32, + if (nftnl_jansson_parse_reg(root, "sreg_addr_max", NFTNL_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_REG_ADDR_MAX, reg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_REG_ADDR_MAX, reg); - if (nft_jansson_parse_reg(root, "sreg_proto_min", NFT_TYPE_U32, + if (nftnl_jansson_parse_reg(root, "sreg_proto_min", NFTNL_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_REG_PROTO_MIN, reg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_REG_PROTO_MIN, reg); - if (nft_jansson_parse_reg(root, "sreg_proto_max", NFT_TYPE_U32, + if (nftnl_jansson_parse_reg(root, "sreg_proto_max", NFTNL_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_REG_PROTO_MAX, reg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_REG_PROTO_MAX, reg); - if (nft_jansson_parse_val(root, "flags", NFT_TYPE_U32, + if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_FLAGS, flags); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_FLAGS, flags); return 0; #else @@ -275,8 +275,8 @@ static int nft_rule_expr_nat_json_parse(struct nft_rule_expr *e, json_t *root, #endif } -static int nft_rule_expr_nat_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +static int nftnl_rule_expr_nat_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *nat_type; @@ -284,43 +284,43 @@ static int nft_rule_expr_nat_xml_parse(struct nft_rule_expr *e, mxml_node_t *tre uint32_t reg_addr_min, reg_addr_max; uint32_t reg_proto_min, reg_proto_max; - nat_type = nft_mxml_str_parse(tree, "nat_type", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + nat_type = nftnl_mxml_str_parse(tree, "nat_type", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (nat_type == NULL) return -1; - nat_type_value = nft_str2nat(nat_type); + nat_type_value = nftnl_str2nat(nat_type); if (nat_type_value < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_TYPE, nat_type_value); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_TYPE, nat_type_value); - family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + family = nftnl_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (family < 0) { mxmlDelete(tree); return -1; } - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_FAMILY, family); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_FAMILY, family); - if (nft_mxml_reg_parse(tree, "sreg_addr_min", ®_addr_min, - MXML_DESCEND, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_REG_ADDR_MIN, reg_addr_min); + if (nftnl_mxml_reg_parse(tree, "sreg_addr_min", ®_addr_min, + MXML_DESCEND, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_REG_ADDR_MIN, reg_addr_min); - if (nft_mxml_reg_parse(tree, "sreg_addr_max", ®_addr_max, - MXML_DESCEND, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_REG_ADDR_MAX, reg_addr_max); + if (nftnl_mxml_reg_parse(tree, "sreg_addr_max", ®_addr_max, + MXML_DESCEND, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_REG_ADDR_MAX, reg_addr_max); - if (nft_mxml_reg_parse(tree, "sreg_proto_min", ®_proto_min, - MXML_DESCEND, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_REG_PROTO_MIN, reg_proto_min); + if (nftnl_mxml_reg_parse(tree, "sreg_proto_min", ®_proto_min, + MXML_DESCEND, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_REG_PROTO_MIN, reg_proto_min); - if (nft_mxml_reg_parse(tree, "sreg_proto_max", ®_proto_max, - MXML_DESCEND, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_REG_PROTO_MAX, reg_proto_max); + if (nftnl_mxml_reg_parse(tree, "sreg_proto_max", ®_proto_max, + MXML_DESCEND, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_REG_PROTO_MAX, reg_proto_max); - if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND, BASE_DEC, &flags, - NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_NAT_FLAGS, flags); + if (nftnl_mxml_num_parse(tree, "flags", MXML_DESCEND, BASE_DEC, &flags, + NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_NAT_FLAGS, flags); return 0; #else @@ -329,58 +329,58 @@ static int nft_rule_expr_nat_xml_parse(struct nft_rule_expr *e, mxml_node_t *tre #endif } -static int nft_rule_expr_nat_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_nat_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_nat *nat = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFT_EXPR_NAT_TYPE)) - nft_buf_str(&b, type, nat2str(nat->type), NAT_TYPE); - if (e->flags & (1 << NFT_EXPR_NAT_FAMILY)) - nft_buf_str(&b, type, nft_family2str(nat->family), FAMILY); - if (e->flags & (1 << NFT_EXPR_NAT_REG_ADDR_MIN)) - nft_buf_u32(&b, type, nat->sreg_addr_min, SREG_ADDR_MIN); - if (e->flags & (1 << NFT_EXPR_NAT_REG_ADDR_MAX)) - nft_buf_u32(&b, type, nat->sreg_addr_max, SREG_ADDR_MAX); - if (e->flags & (1 << NFT_EXPR_NAT_REG_PROTO_MIN)) - nft_buf_u32(&b, type, nat->sreg_proto_min, SREG_PROTO_MIN); - if (e->flags & (1 << NFT_EXPR_NAT_REG_PROTO_MAX)) - nft_buf_u32(&b, type, nat->sreg_proto_max, SREG_PROTO_MAX); - if (e->flags & (1 << NFT_EXPR_NAT_FLAGS)) - nft_buf_u32(&b, type, nat->flags, FLAGS); - - return nft_buf_done(&b); + struct nftnl_expr_nat *nat = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); + + if (e->flags & (1 << NFTNL_EXPR_NAT_TYPE)) + nftnl_buf_str(&b, type, nat2str(nat->type), NAT_TYPE); + if (e->flags & (1 << NFTNL_EXPR_NAT_FAMILY)) + nftnl_buf_str(&b, type, nftnl_family2str(nat->family), FAMILY); + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MIN)) + nftnl_buf_u32(&b, type, nat->sreg_addr_min, SREG_ADDR_MIN); + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MAX)) + nftnl_buf_u32(&b, type, nat->sreg_addr_max, SREG_ADDR_MAX); + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MIN)) + nftnl_buf_u32(&b, type, nat->sreg_proto_min, SREG_PROTO_MIN); + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MAX)) + nftnl_buf_u32(&b, type, nat->sreg_proto_max, SREG_PROTO_MAX); + if (e->flags & (1 << NFTNL_EXPR_NAT_FLAGS)) + nftnl_buf_u32(&b, type, nat->flags, FLAGS); + + return nftnl_buf_done(&b); } static int -nft_rule_expr_nat_snprintf_default(char *buf, size_t size, - struct nft_rule_expr *e) +nftnl_rule_expr_nat_snprintf_default(char *buf, size_t size, + struct nftnl_rule_expr *e) { - struct nft_expr_nat *nat = nft_expr_data(e); + struct nftnl_expr_nat *nat = nftnl_expr_data(e); int len = size, offset = 0, ret = 0; ret = snprintf(buf, len, "%s ", nat2str(nat->type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = snprintf(buf+offset, len, "%s ", nft_family2str(nat->family)); + ret = snprintf(buf+offset, len, "%s ", nftnl_family2str(nat->family)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (e->flags & (1 << NFT_EXPR_NAT_REG_ADDR_MIN)) { + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MIN)) { ret = snprintf(buf+offset, len, "addr_min reg %u addr_max reg %u ", nat->sreg_addr_min, nat->sreg_addr_max); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (e->flags & (1 << NFT_EXPR_NAT_REG_PROTO_MIN)) { + if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MIN)) { ret = snprintf(buf+offset, len, "proto_min reg %u proto_max reg %u ", nat->sreg_proto_min, nat->sreg_proto_max); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (e->flags & (1 << NFT_EXPR_NAT_FLAGS)) { + if (e->flags & (1 << NFTNL_EXPR_NAT_FLAGS)) { ret = snprintf(buf+offset, len, "flags %u", nat->flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } @@ -389,15 +389,15 @@ nft_rule_expr_nat_snprintf_default(char *buf, size_t size, } static int -nft_rule_expr_nat_snprintf(char *buf, size_t size, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_nat_snprintf(char *buf, size_t size, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_nat_snprintf_default(buf, size, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_nat_export(buf, size, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_nat_snprintf_default(buf, size, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_nat_export(buf, size, e, type); default: break; } @@ -406,13 +406,13 @@ nft_rule_expr_nat_snprintf(char *buf, size_t size, uint32_t type, struct expr_ops expr_ops_nat = { .name = "nat", - .alloc_len = sizeof(struct nft_expr_nat), + .alloc_len = sizeof(struct nftnl_expr_nat), .max_attr = NFTA_NAT_MAX, - .set = nft_rule_expr_nat_set, - .get = nft_rule_expr_nat_get, - .parse = nft_rule_expr_nat_parse, - .build = nft_rule_expr_nat_build, - .snprintf = nft_rule_expr_nat_snprintf, - .xml_parse = nft_rule_expr_nat_xml_parse, - .json_parse = nft_rule_expr_nat_json_parse, + .set = nftnl_rule_expr_nat_set, + .get = nftnl_rule_expr_nat_get, + .parse = nftnl_rule_expr_nat_parse, + .build = nftnl_rule_expr_nat_build, + .snprintf = nftnl_rule_expr_nat_snprintf, + .xml_parse = nftnl_rule_expr_nat_xml_parse, + .json_parse = nftnl_rule_expr_nat_json_parse, }; diff --git a/src/expr/payload.c b/src/expr/payload.c index 52bea19..eda96f7 100644 --- a/src/expr/payload.c +++ b/src/expr/payload.c @@ -24,7 +24,7 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_payload { +struct nftnl_expr_payload { enum nft_registers dreg; enum nft_payload_bases base; uint32_t offset; @@ -32,22 +32,22 @@ struct nft_expr_payload { }; static int -nft_rule_expr_payload_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_payload_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_payload *payload = nft_expr_data(e); + struct nftnl_expr_payload *payload = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_PAYLOAD_DREG: + case NFTNL_EXPR_PAYLOAD_DREG: payload->dreg = *((uint32_t *)data); break; - case NFT_EXPR_PAYLOAD_BASE: + case NFTNL_EXPR_PAYLOAD_BASE: payload->base = *((uint32_t *)data); break; - case NFT_EXPR_PAYLOAD_OFFSET: + case NFTNL_EXPR_PAYLOAD_OFFSET: payload->offset = *((unsigned int *)data); break; - case NFT_EXPR_PAYLOAD_LEN: + case NFTNL_EXPR_PAYLOAD_LEN: payload->len = *((unsigned int *)data); break; default: @@ -57,29 +57,29 @@ nft_rule_expr_payload_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_payload_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_payload_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_payload *payload = nft_expr_data(e); + struct nftnl_expr_payload *payload = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_PAYLOAD_DREG: + case NFTNL_EXPR_PAYLOAD_DREG: *data_len = sizeof(payload->dreg); return &payload->dreg; - case NFT_EXPR_PAYLOAD_BASE: + case NFTNL_EXPR_PAYLOAD_BASE: *data_len = sizeof(payload->base); return &payload->base; - case NFT_EXPR_PAYLOAD_OFFSET: + case NFTNL_EXPR_PAYLOAD_OFFSET: *data_len = sizeof(payload->offset); return &payload->offset; - case NFT_EXPR_PAYLOAD_LEN: + case NFTNL_EXPR_PAYLOAD_LEN: *data_len = sizeof(payload->len); return &payload->len; } return NULL; } -static int nft_rule_expr_payload_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_payload_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -102,44 +102,44 @@ static int nft_rule_expr_payload_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_payload_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_payload_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_payload *payload = nft_expr_data(e); + struct nftnl_expr_payload *payload = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_PAYLOAD_DREG)) + if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_DREG)) mnl_attr_put_u32(nlh, NFTA_PAYLOAD_DREG, htonl(payload->dreg)); - if (e->flags & (1 << NFT_EXPR_PAYLOAD_BASE)) + if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_BASE)) mnl_attr_put_u32(nlh, NFTA_PAYLOAD_BASE, htonl(payload->base)); - if (e->flags & (1 << NFT_EXPR_PAYLOAD_OFFSET)) + if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_OFFSET)) mnl_attr_put_u32(nlh, NFTA_PAYLOAD_OFFSET, htonl(payload->offset)); - if (e->flags & (1 << NFT_EXPR_PAYLOAD_LEN)) + if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_LEN)) mnl_attr_put_u32(nlh, NFTA_PAYLOAD_LEN, htonl(payload->len)); } static int -nft_rule_expr_payload_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_payload_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_payload *payload = nft_expr_data(e); + struct nftnl_expr_payload *payload = nftnl_expr_data(e); struct nlattr *tb[NFTA_PAYLOAD_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_payload_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_payload_cb, tb) < 0) return -1; if (tb[NFTA_PAYLOAD_DREG]) { payload->dreg = ntohl(mnl_attr_get_u32(tb[NFTA_PAYLOAD_DREG])); - e->flags |= (1 << NFT_EXPR_PAYLOAD_DREG); + e->flags |= (1 << NFTNL_EXPR_PAYLOAD_DREG); } if (tb[NFTA_PAYLOAD_BASE]) { payload->base = ntohl(mnl_attr_get_u32(tb[NFTA_PAYLOAD_BASE])); - e->flags |= (1 << NFT_EXPR_PAYLOAD_BASE); + e->flags |= (1 << NFTNL_EXPR_PAYLOAD_BASE); } if (tb[NFTA_PAYLOAD_OFFSET]) { payload->offset = ntohl(mnl_attr_get_u32(tb[NFTA_PAYLOAD_OFFSET])); - e->flags |= (1 << NFT_EXPR_PAYLOAD_OFFSET); + e->flags |= (1 << NFTNL_EXPR_PAYLOAD_OFFSET); } if (tb[NFTA_PAYLOAD_LEN]) { payload->len = ntohl(mnl_attr_get_u32(tb[NFTA_PAYLOAD_LEN])); - e->flags |= (1 << NFT_EXPR_PAYLOAD_LEN); + e->flags |= (1 << NFTNL_EXPR_PAYLOAD_LEN); } return 0; @@ -159,7 +159,7 @@ static const char *base2str(enum nft_payload_bases base) return base2str_array[base]; } -static inline int nft_str2base(const char *base) +static inline int nftnl_str2base(const char *base) { if (strcmp(base, "link") == 0) return NFT_PAYLOAD_LL_HEADER; @@ -174,32 +174,32 @@ static inline int nft_str2base(const char *base) } static int -nft_rule_expr_payload_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_payload_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *base_str; uint32_t reg, uval32; int base; - if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_DREG, reg); + if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_DREG, reg); - base_str = nft_jansson_parse_str(root, "base", err); + base_str = nftnl_jansson_parse_str(root, "base", err); if (base_str != NULL) { - base = nft_str2base(base_str); + base = nftnl_str2base(base_str); if (base < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_BASE, base); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_BASE, base); } - if (nft_jansson_parse_val(root, "offset", NFT_TYPE_U32, &uval32, + if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32, &uval32, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_OFFSET, uval32); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_OFFSET, uval32); - if (nft_jansson_parse_val(root, "len", NFT_TYPE_U32, &uval32, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_LEN, uval32); + if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &uval32, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_LEN, uval32); return 0; #else @@ -209,36 +209,36 @@ nft_rule_expr_payload_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_payload_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_payload_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *base_str; int32_t base; uint32_t dreg, offset, len; - if (nft_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_DREG, dreg); + if (nftnl_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_DREG, dreg); - base_str = nft_mxml_str_parse(tree, "base", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + base_str = nftnl_mxml_str_parse(tree, "base", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (base_str != NULL) { - base = nft_str2base(base_str); + base = nftnl_str2base(base_str); if (base < 0) return -1; - nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_BASE, base); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_BASE, base); } - if (nft_mxml_num_parse(tree, "offset", MXML_DESCEND_FIRST, BASE_DEC, - &offset, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_OFFSET, offset); + if (nftnl_mxml_num_parse(tree, "offset", MXML_DESCEND_FIRST, BASE_DEC, + &offset, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_OFFSET, offset); - if (nft_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, - &len, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_LEN, len); + if (nftnl_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, + &len, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_LEN, len); return 0; #else @@ -247,38 +247,38 @@ nft_rule_expr_payload_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, #endif } -static int nft_rule_expr_payload_export(char *buf, size_t size, uint32_t flags, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_payload_export(char *buf, size_t size, uint32_t flags, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_payload *payload = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFT_EXPR_PAYLOAD_DREG)) - nft_buf_u32(&b, type, payload->dreg, DREG); - if (e->flags & (1 << NFT_EXPR_PAYLOAD_OFFSET)) - nft_buf_u32(&b, type, payload->offset, OFFSET); - if (e->flags & (1 << NFT_EXPR_PAYLOAD_LEN)) - nft_buf_u32(&b, type, payload->len, LEN); - if (e->flags & (1 << NFT_EXPR_PAYLOAD_BASE)) - nft_buf_str(&b, type, base2str(payload->base), BASE); - - return nft_buf_done(&b); + struct nftnl_expr_payload *payload = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); + + if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_DREG)) + nftnl_buf_u32(&b, type, payload->dreg, DREG); + if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_OFFSET)) + nftnl_buf_u32(&b, type, payload->offset, OFFSET); + if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_LEN)) + nftnl_buf_u32(&b, type, payload->len, LEN); + if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_BASE)) + nftnl_buf_str(&b, type, base2str(payload->base), BASE); + + return nftnl_buf_done(&b); } static int -nft_rule_expr_payload_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_payload_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { - struct nft_expr_payload *payload = nft_expr_data(e); + struct nftnl_expr_payload *payload = nftnl_expr_data(e); switch (type) { - case NFT_OUTPUT_DEFAULT: + case NFTNL_OUTPUT_DEFAULT: return snprintf(buf, len, "load %ub @ %s header + %u => reg %u ", payload->len, base2str(payload->base), payload->offset, payload->dreg); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_payload_export(buf, len, flags, e, type); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_payload_export(buf, len, flags, e, type); default: break; } @@ -287,13 +287,13 @@ nft_rule_expr_payload_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_payload = { .name = "payload", - .alloc_len = sizeof(struct nft_expr_payload), + .alloc_len = sizeof(struct nftnl_expr_payload), .max_attr = NFTA_PAYLOAD_MAX, - .set = nft_rule_expr_payload_set, - .get = nft_rule_expr_payload_get, - .parse = nft_rule_expr_payload_parse, - .build = nft_rule_expr_payload_build, - .snprintf = nft_rule_expr_payload_snprintf, - .xml_parse = nft_rule_expr_payload_xml_parse, - .json_parse = nft_rule_expr_payload_json_parse, + .set = nftnl_rule_expr_payload_set, + .get = nftnl_rule_expr_payload_get, + .parse = nftnl_rule_expr_payload_parse, + .build = nftnl_rule_expr_payload_build, + .snprintf = nftnl_rule_expr_payload_snprintf, + .xml_parse = nftnl_rule_expr_payload_xml_parse, + .json_parse = nftnl_rule_expr_payload_json_parse, }; diff --git a/src/expr/queue.c b/src/expr/queue.c index 5e2a49e..e388968 100644 --- a/src/expr/queue.c +++ b/src/expr/queue.c @@ -20,25 +20,25 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_queue { +struct nftnl_expr_queue { uint16_t queuenum; uint16_t queues_total; uint16_t flags; }; -static int nft_rule_expr_queue_set(struct nft_rule_expr *e, uint16_t type, +static int nftnl_rule_expr_queue_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_queue *queue = nft_expr_data(e); + struct nftnl_expr_queue *queue = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_QUEUE_NUM: + case NFTNL_EXPR_QUEUE_NUM: queue->queuenum = *((uint16_t *)data); break; - case NFT_EXPR_QUEUE_TOTAL: + case NFTNL_EXPR_QUEUE_TOTAL: queue->queues_total = *((uint16_t *)data); break; - case NFT_EXPR_QUEUE_FLAGS: + case NFTNL_EXPR_QUEUE_FLAGS: queue->flags = *((uint16_t *)data); break; default: @@ -48,26 +48,26 @@ static int nft_rule_expr_queue_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_queue_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_queue_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_queue *queue = nft_expr_data(e); + struct nftnl_expr_queue *queue = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_QUEUE_NUM: + case NFTNL_EXPR_QUEUE_NUM: *data_len = sizeof(queue->queuenum); return &queue->queuenum; - case NFT_EXPR_QUEUE_TOTAL: + case NFTNL_EXPR_QUEUE_TOTAL: *data_len = sizeof(queue->queues_total); return &queue->queues_total; - case NFT_EXPR_QUEUE_FLAGS: + case NFTNL_EXPR_QUEUE_FLAGS: *data_len = sizeof(queue->flags); return &queue->flags; } return NULL; } -static int nft_rule_expr_queue_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_queue_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -89,60 +89,60 @@ static int nft_rule_expr_queue_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_queue_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_queue_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_queue *queue = nft_expr_data(e); + struct nftnl_expr_queue *queue = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_QUEUE_NUM)) + if (e->flags & (1 << NFTNL_EXPR_QUEUE_NUM)) mnl_attr_put_u16(nlh, NFTA_QUEUE_NUM, htons(queue->queuenum)); - if (e->flags & (1 << NFT_EXPR_QUEUE_TOTAL)) + if (e->flags & (1 << NFTNL_EXPR_QUEUE_TOTAL)) mnl_attr_put_u16(nlh, NFTA_QUEUE_TOTAL, htons(queue->queues_total)); - if (e->flags & (1 << NFT_EXPR_QUEUE_FLAGS)) + if (e->flags & (1 << NFTNL_EXPR_QUEUE_FLAGS)) mnl_attr_put_u16(nlh, NFTA_QUEUE_FLAGS, htons(queue->flags)); } static int -nft_rule_expr_queue_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_queue_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_queue *queue = nft_expr_data(e); + struct nftnl_expr_queue *queue = nftnl_expr_data(e); struct nlattr *tb[NFTA_QUEUE_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_queue_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_queue_cb, tb) < 0) return -1; if (tb[NFTA_QUEUE_NUM]) { queue->queuenum = ntohs(mnl_attr_get_u16(tb[NFTA_QUEUE_NUM])); - e->flags |= (1 << NFT_EXPR_QUEUE_NUM); + e->flags |= (1 << NFTNL_EXPR_QUEUE_NUM); } if (tb[NFTA_QUEUE_TOTAL]) { queue->queues_total = ntohs(mnl_attr_get_u16(tb[NFTA_QUEUE_TOTAL])); - e->flags |= (1 << NFT_EXPR_QUEUE_TOTAL); + e->flags |= (1 << NFTNL_EXPR_QUEUE_TOTAL); } if (tb[NFTA_QUEUE_FLAGS]) { queue->flags = ntohs(mnl_attr_get_u16(tb[NFTA_QUEUE_FLAGS])); - e->flags |= (1 << NFT_EXPR_QUEUE_FLAGS); + e->flags |= (1 << NFTNL_EXPR_QUEUE_FLAGS); } return 0; } static int -nft_rule_expr_queue_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_queue_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING uint16_t type; uint16_t code; - if (nft_jansson_parse_val(root, "num", NFT_TYPE_U16, &type, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_NUM, type); - nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_NUM, type); + if (nftnl_jansson_parse_val(root, "num", NFTNL_TYPE_U16, &type, err) == 0) + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_QUEUE_NUM, type); + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_QUEUE_NUM, type); - if (nft_jansson_parse_val(root, "total", NFT_TYPE_U16, &code, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_TOTAL, code); + if (nftnl_jansson_parse_val(root, "total", NFTNL_TYPE_U16, &code, err) == 0) + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_QUEUE_TOTAL, code); - if (nft_jansson_parse_val(root, "flags", NFT_TYPE_U16, &code, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_FLAGS, code); + if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U16, &code, err) == 0) + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_QUEUE_FLAGS, code); return 0; #else @@ -152,26 +152,26 @@ nft_rule_expr_queue_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_queue_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_queue_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING uint16_t queue_num, queue_total, flags; - if (nft_mxml_num_parse(tree, "num", MXML_DESCEND_FIRST, BASE_DEC, - &queue_num, NFT_TYPE_U16, NFT_XML_MAND, + if (nftnl_mxml_num_parse(tree, "num", MXML_DESCEND_FIRST, BASE_DEC, + &queue_num, NFTNL_TYPE_U16, NFTNL_XML_MAND, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_NUM, queue_num); + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_QUEUE_NUM, queue_num); - if (nft_mxml_num_parse(tree, "total", MXML_DESCEND_FIRST, BASE_DEC, - &queue_total, NFT_TYPE_U16, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_TOTAL, queue_total); + if (nftnl_mxml_num_parse(tree, "total", MXML_DESCEND_FIRST, BASE_DEC, + &queue_total, NFTNL_TYPE_U16, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_QUEUE_TOTAL, queue_total); - if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, - &flags, NFT_TYPE_U16, - NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_FLAGS, flags); + if (nftnl_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, + &flags, NFTNL_TYPE_U16, + NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u16(e, NFTNL_EXPR_QUEUE_FLAGS, flags); return 0; #else @@ -180,10 +180,10 @@ nft_rule_expr_queue_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, #endif } -static int nft_rule_expr_queue_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e) +static int nftnl_rule_expr_queue_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e) { - struct nft_expr_queue *queue = nft_expr_data(e); + struct nftnl_expr_queue *queue = nftnl_expr_data(e); int ret, size = len, offset = 0; uint16_t total_queues; @@ -197,7 +197,7 @@ static int nft_rule_expr_queue_snprintf_default(char *buf, size_t len, SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (e->flags & (1 << NFT_EXPR_QUEUE_FLAGS)) { + if (e->flags & (1 << NFTNL_EXPR_QUEUE_FLAGS)) { if (queue->flags & (NFT_QUEUE_FLAG_BYPASS)) { ret = snprintf(buf + offset, len, " bypass"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -210,33 +210,33 @@ static int nft_rule_expr_queue_snprintf_default(char *buf, size_t len, return offset; } -static int nft_rule_expr_queue_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_queue_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_queue *queue = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_queue *queue = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_QUEUE_NUM)) - nft_buf_u32(&b, type, queue->queuenum, NUM); - if (e->flags & (1 << NFT_EXPR_QUEUE_TOTAL)) - nft_buf_u32(&b, type, queue->queues_total, TOTAL); - if (e->flags & (1 << NFT_EXPR_QUEUE_FLAGS)) - nft_buf_u32(&b, type, queue->flags, FLAGS); + if (e->flags & (1 << NFTNL_EXPR_QUEUE_NUM)) + nftnl_buf_u32(&b, type, queue->queuenum, NUM); + if (e->flags & (1 << NFTNL_EXPR_QUEUE_TOTAL)) + nftnl_buf_u32(&b, type, queue->queues_total, TOTAL); + if (e->flags & (1 << NFTNL_EXPR_QUEUE_FLAGS)) + nftnl_buf_u32(&b, type, queue->flags, FLAGS); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } static int -nft_rule_expr_queue_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_queue_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_queue_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_queue_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_queue_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_queue_export(buf, len, e, type); default: break; } @@ -245,13 +245,13 @@ nft_rule_expr_queue_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_queue = { .name = "queue", - .alloc_len = sizeof(struct nft_expr_queue), + .alloc_len = sizeof(struct nftnl_expr_queue), .max_attr = NFTA_QUEUE_MAX, - .set = nft_rule_expr_queue_set, - .get = nft_rule_expr_queue_get, - .parse = nft_rule_expr_queue_parse, - .build = nft_rule_expr_queue_build, - .snprintf = nft_rule_expr_queue_snprintf, - .xml_parse = nft_rule_expr_queue_xml_parse, - .json_parse = nft_rule_expr_queue_json_parse, + .set = nftnl_rule_expr_queue_set, + .get = nftnl_rule_expr_queue_get, + .parse = nftnl_rule_expr_queue_parse, + .build = nftnl_rule_expr_queue_build, + .snprintf = nftnl_rule_expr_queue_snprintf, + .xml_parse = nftnl_rule_expr_queue_xml_parse, + .json_parse = nftnl_rule_expr_queue_json_parse, }; diff --git a/src/expr/redir.c b/src/expr/redir.c index 69bd94f..d73730d 100644 --- a/src/expr/redir.c +++ b/src/expr/redir.c @@ -20,26 +20,26 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_redir { +struct nftnl_expr_redir { enum nft_registers sreg_proto_min; enum nft_registers sreg_proto_max; uint32_t flags; }; static int -nft_rule_expr_redir_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_redir_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_redir *redir = nft_expr_data(e); + struct nftnl_expr_redir *redir = nftnl_expr_data(e); switch (type) { - case NFT_EXPR_REDIR_REG_PROTO_MIN: + case NFTNL_EXPR_REDIR_REG_PROTO_MIN: redir->sreg_proto_min = *((uint32_t *)data); break; - case NFT_EXPR_REDIR_REG_PROTO_MAX: + case NFTNL_EXPR_REDIR_REG_PROTO_MAX: redir->sreg_proto_max = *((uint32_t *)data); break; - case NFT_EXPR_REDIR_FLAGS: + case NFTNL_EXPR_REDIR_FLAGS: redir->flags = *((uint32_t *)data); break; default: @@ -49,26 +49,26 @@ nft_rule_expr_redir_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_redir_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_redir_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_redir *redir = nft_expr_data(e); + struct nftnl_expr_redir *redir = nftnl_expr_data(e); switch (type) { - case NFT_EXPR_REDIR_REG_PROTO_MIN: + case NFTNL_EXPR_REDIR_REG_PROTO_MIN: *data_len = sizeof(redir->sreg_proto_min); return &redir->sreg_proto_min; - case NFT_EXPR_REDIR_REG_PROTO_MAX: + case NFTNL_EXPR_REDIR_REG_PROTO_MAX: *data_len = sizeof(redir->sreg_proto_max); return &redir->sreg_proto_max; - case NFT_EXPR_REDIR_FLAGS: + case NFTNL_EXPR_REDIR_FLAGS: *data_len = sizeof(redir->flags); return &redir->flags; } return NULL; } -static int nft_rule_expr_redir_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_redir_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -90,65 +90,65 @@ static int nft_rule_expr_redir_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_redir_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_redir_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_redir *redir = nft_expr_data(e); + struct nftnl_expr_redir *redir = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_REDIR_REG_PROTO_MIN)) + if (e->flags & (1 << NFTNL_EXPR_REDIR_REG_PROTO_MIN)) mnl_attr_put_u32(nlh, NFTA_REDIR_REG_PROTO_MIN, htobe32(redir->sreg_proto_min)); - if (e->flags & (1 << NFT_EXPR_REDIR_REG_PROTO_MAX)) + if (e->flags & (1 << NFTNL_EXPR_REDIR_REG_PROTO_MAX)) mnl_attr_put_u32(nlh, NFTA_REDIR_REG_PROTO_MAX, htobe32(redir->sreg_proto_max)); - if (e->flags & (1 << NFT_EXPR_REDIR_FLAGS)) + if (e->flags & (1 << NFTNL_EXPR_REDIR_FLAGS)) mnl_attr_put_u32(nlh, NFTA_REDIR_FLAGS, htobe32(redir->flags)); } static int -nft_rule_expr_redir_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_redir_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_redir *redir = nft_expr_data(e); + struct nftnl_expr_redir *redir = nftnl_expr_data(e); struct nlattr *tb[NFTA_REDIR_MAX + 1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_redir_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_redir_cb, tb) < 0) return -1; if (tb[NFTA_REDIR_REG_PROTO_MIN]) { redir->sreg_proto_min = ntohl(mnl_attr_get_u32(tb[NFTA_REDIR_REG_PROTO_MIN])); - e->flags |= (1 << NFT_EXPR_REDIR_REG_PROTO_MIN); + e->flags |= (1 << NFTNL_EXPR_REDIR_REG_PROTO_MIN); } if (tb[NFTA_REDIR_REG_PROTO_MAX]) { redir->sreg_proto_max = ntohl(mnl_attr_get_u32(tb[NFTA_REDIR_REG_PROTO_MAX])); - e->flags |= (1 << NFT_EXPR_REDIR_REG_PROTO_MAX); + e->flags |= (1 << NFTNL_EXPR_REDIR_REG_PROTO_MAX); } if (tb[NFTA_REDIR_FLAGS]) { redir->flags = be32toh(mnl_attr_get_u32(tb[NFTA_REDIR_FLAGS])); - e->flags |= (1 << NFT_EXPR_REDIR_FLAGS); + e->flags |= (1 << NFTNL_EXPR_REDIR_FLAGS); } return 0; } static int -nft_rule_expr_redir_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_redir_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING uint32_t reg, flags; - if (nft_jansson_parse_reg(root, "sreg_proto_min", NFT_TYPE_U32, + if (nftnl_jansson_parse_reg(root, "sreg_proto_min", NFTNL_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_REDIR_REG_PROTO_MIN, reg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_REDIR_REG_PROTO_MIN, reg); - if (nft_jansson_parse_reg(root, "sreg_proto_max", NFT_TYPE_U32, + if (nftnl_jansson_parse_reg(root, "sreg_proto_max", NFTNL_TYPE_U32, ®, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_REDIR_REG_PROTO_MAX, reg); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_REDIR_REG_PROTO_MAX, reg); - if (nft_jansson_parse_val(root, "flags", NFT_TYPE_U32, &flags, + if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_REDIR_FLAGS, flags); + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_REDIR_FLAGS, flags); return 0; #else @@ -158,23 +158,23 @@ nft_rule_expr_redir_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_redir_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_redir_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING uint32_t reg, flags; - if (nft_mxml_reg_parse(tree, "sreg_proto_min", ®, - MXML_DESCEND, NFT_XML_OPT, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_REDIR_REG_PROTO_MIN, reg); + if (nftnl_mxml_reg_parse(tree, "sreg_proto_min", ®, + MXML_DESCEND, NFTNL_XML_OPT, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_REDIR_REG_PROTO_MIN, reg); - if (nft_mxml_reg_parse(tree, "sreg_proto_max", ®, - MXML_DESCEND, NFT_XML_OPT, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_REDIR_REG_PROTO_MAX, reg); + if (nftnl_mxml_reg_parse(tree, "sreg_proto_max", ®, + MXML_DESCEND, NFTNL_XML_OPT, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_REDIR_REG_PROTO_MAX, reg); - if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, - &flags, NFT_TYPE_U32, NFT_XML_OPT, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_REDIR_FLAGS, flags); + if (nftnl_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, + &flags, NFTNL_TYPE_U32, NFTNL_XML_OPT, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_REDIR_FLAGS, flags); return 0; #else @@ -183,41 +183,41 @@ nft_rule_expr_redir_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, #endif } -static int nft_rule_expr_redir_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_redir_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_redir *redir = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_redir *redir = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_REDIR_REG_PROTO_MIN)) - nft_buf_u32(&b, type, redir->sreg_proto_min, SREG_PROTO_MIN); - if (e->flags & (1 << NFT_EXPR_REDIR_REG_PROTO_MAX)) - nft_buf_u32(&b, type, redir->sreg_proto_max, SREG_PROTO_MAX); - if (e->flags & (1 << NFT_EXPR_REDIR_FLAGS)) - nft_buf_u32(&b, type, redir->flags, FLAGS); + if (e->flags & (1 << NFTNL_EXPR_REDIR_REG_PROTO_MIN)) + nftnl_buf_u32(&b, type, redir->sreg_proto_min, SREG_PROTO_MIN); + if (e->flags & (1 << NFTNL_EXPR_REDIR_REG_PROTO_MAX)) + nftnl_buf_u32(&b, type, redir->sreg_proto_max, SREG_PROTO_MAX); + if (e->flags & (1 << NFTNL_EXPR_REDIR_FLAGS)) + nftnl_buf_u32(&b, type, redir->flags, FLAGS); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } -static int nft_rule_expr_redir_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e) +static int nftnl_rule_expr_redir_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e) { int ret, size = len, offset = 0; - struct nft_expr_redir *redir = nft_expr_data(e); + struct nftnl_expr_redir *redir = nftnl_expr_data(e); - if (nft_rule_expr_is_set(e, NFT_EXPR_REDIR_REG_PROTO_MIN)) { + if (nftnl_rule_expr_is_set(e, NFTNL_EXPR_REDIR_REG_PROTO_MIN)) { ret = snprintf(buf + offset, len, "proto_min reg %u ", redir->sreg_proto_min); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (nft_rule_expr_is_set(e, NFT_EXPR_REDIR_REG_PROTO_MAX)) { + if (nftnl_rule_expr_is_set(e, NFTNL_EXPR_REDIR_REG_PROTO_MAX)) { ret = snprintf(buf + offset, len, "proto_max reg %u ", redir->sreg_proto_max); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (nft_rule_expr_is_set(e, NFT_EXPR_REDIR_FLAGS)) { + if (nftnl_rule_expr_is_set(e, NFTNL_EXPR_REDIR_FLAGS)) { ret = snprintf(buf + offset , len, "flags 0x%x ", redir->flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -227,15 +227,15 @@ static int nft_rule_expr_redir_snprintf_default(char *buf, size_t len, } static int -nft_rule_expr_redir_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_redir_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_redir_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_redir_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_redir_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_redir_export(buf, len, e, type); default: break; } @@ -244,13 +244,13 @@ nft_rule_expr_redir_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_redir = { .name = "redir", - .alloc_len = sizeof(struct nft_expr_redir), + .alloc_len = sizeof(struct nftnl_expr_redir), .max_attr = NFTA_REDIR_MAX, - .set = nft_rule_expr_redir_set, - .get = nft_rule_expr_redir_get, - .parse = nft_rule_expr_redir_parse, - .build = nft_rule_expr_redir_build, - .snprintf = nft_rule_expr_redir_snprintf, - .xml_parse = nft_rule_expr_redir_xml_parse, - .json_parse = nft_rule_expr_redir_json_parse, + .set = nftnl_rule_expr_redir_set, + .get = nftnl_rule_expr_redir_get, + .parse = nftnl_rule_expr_redir_parse, + .build = nftnl_rule_expr_redir_build, + .snprintf = nftnl_rule_expr_redir_snprintf, + .xml_parse = nftnl_rule_expr_redir_xml_parse, + .json_parse = nftnl_rule_expr_redir_json_parse, }; diff --git a/src/expr/reject.c b/src/expr/reject.c index a9c13d5..e0bfc71 100644 --- a/src/expr/reject.c +++ b/src/expr/reject.c @@ -21,21 +21,21 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_reject { +struct nftnl_expr_reject { uint32_t type; uint8_t icmp_code; }; -static int nft_rule_expr_reject_set(struct nft_rule_expr *e, uint16_t type, +static int nftnl_rule_expr_reject_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_reject *reject = nft_expr_data(e); + struct nftnl_expr_reject *reject = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_REJECT_TYPE: + case NFTNL_EXPR_REJECT_TYPE: reject->type = *((uint32_t *)data); break; - case NFT_EXPR_REJECT_CODE: + case NFTNL_EXPR_REJECT_CODE: reject->icmp_code = *((uint8_t *)data); break; default: @@ -45,23 +45,23 @@ static int nft_rule_expr_reject_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_reject_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_reject_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_reject *reject = nft_expr_data(e); + struct nftnl_expr_reject *reject = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_REJECT_TYPE: + case NFTNL_EXPR_REJECT_TYPE: *data_len = sizeof(reject->type); return &reject->type; - case NFT_EXPR_REJECT_CODE: + case NFTNL_EXPR_REJECT_CODE: *data_len = sizeof(reject->icmp_code); return &reject->icmp_code; } return NULL; } -static int nft_rule_expr_reject_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_reject_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -85,50 +85,50 @@ static int nft_rule_expr_reject_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_reject_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_reject_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_reject *reject = nft_expr_data(e); + struct nftnl_expr_reject *reject = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_REJECT_TYPE)) + if (e->flags & (1 << NFTNL_EXPR_REJECT_TYPE)) mnl_attr_put_u32(nlh, NFTA_REJECT_TYPE, htonl(reject->type)); - if (e->flags & (1 << NFT_EXPR_REJECT_CODE)) + if (e->flags & (1 << NFTNL_EXPR_REJECT_CODE)) mnl_attr_put_u8(nlh, NFTA_REJECT_ICMP_CODE, reject->icmp_code); } static int -nft_rule_expr_reject_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_reject_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_reject *reject = nft_expr_data(e); + struct nftnl_expr_reject *reject = nftnl_expr_data(e); struct nlattr *tb[NFTA_REJECT_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_reject_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_reject_cb, tb) < 0) return -1; if (tb[NFTA_REJECT_TYPE]) { reject->type = ntohl(mnl_attr_get_u32(tb[NFTA_REJECT_TYPE])); - e->flags |= (1 << NFT_EXPR_REJECT_TYPE); + e->flags |= (1 << NFTNL_EXPR_REJECT_TYPE); } if (tb[NFTA_REJECT_ICMP_CODE]) { reject->icmp_code = mnl_attr_get_u8(tb[NFTA_REJECT_ICMP_CODE]); - e->flags |= (1 << NFT_EXPR_REJECT_CODE); + e->flags |= (1 << NFTNL_EXPR_REJECT_CODE); } return 0; } static int -nft_rule_expr_reject_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_reject_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING uint32_t type; uint8_t code; - if (nft_jansson_parse_val(root, "type", NFT_TYPE_U32, &type, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_REJECT_TYPE, type); + if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, &type, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_REJECT_TYPE, type); - if (nft_jansson_parse_val(root, "code", NFT_TYPE_U8, &code, err) == 0) - nft_rule_expr_set_u8(e, NFT_EXPR_REJECT_CODE, code); + if (nftnl_jansson_parse_val(root, "code", NFTNL_TYPE_U8, &code, err) == 0) + nftnl_rule_expr_set_u8(e, NFTNL_EXPR_REJECT_CODE, code); return 0; #else @@ -138,20 +138,20 @@ nft_rule_expr_reject_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_reject_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_reject_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING uint32_t type; uint8_t code; - if (nft_mxml_num_parse(tree, "type", MXML_DESCEND_FIRST, BASE_DEC, - &type, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u32(e, NFT_EXPR_REJECT_TYPE, type); + if (nftnl_mxml_num_parse(tree, "type", MXML_DESCEND_FIRST, BASE_DEC, + &type, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_REJECT_TYPE, type); - if (nft_mxml_num_parse(tree, "code", MXML_DESCEND_FIRST, BASE_DEC, - &code, NFT_TYPE_U8, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u8(e, NFT_EXPR_REJECT_CODE, code); + if (nftnl_mxml_num_parse(tree, "code", MXML_DESCEND_FIRST, BASE_DEC, + &code, NFTNL_TYPE_U8, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u8(e, NFTNL_EXPR_REJECT_CODE, code); return 0; #else @@ -160,39 +160,39 @@ nft_rule_expr_reject_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, #endif } -static int nft_rule_expr_reject_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e) +static int nftnl_rule_expr_reject_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e) { - struct nft_expr_reject *reject = nft_expr_data(e); + struct nftnl_expr_reject *reject = nftnl_expr_data(e); return snprintf(buf, len, "type %u code %u ", reject->type, reject->icmp_code); } -static int nft_rule_expr_reject_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_reject_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_reject *reject = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_reject *reject = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_REJECT_TYPE)) - nft_buf_u32(&b, type, reject->type, TYPE); - if (e->flags & (1 << NFT_EXPR_REJECT_CODE)) - nft_buf_u32(&b, type, reject->icmp_code, CODE); + if (e->flags & (1 << NFTNL_EXPR_REJECT_TYPE)) + nftnl_buf_u32(&b, type, reject->type, TYPE); + if (e->flags & (1 << NFTNL_EXPR_REJECT_CODE)) + nftnl_buf_u32(&b, type, reject->icmp_code, CODE); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } static int -nft_rule_expr_reject_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_reject_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch (type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_reject_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_reject_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_reject_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_reject_export(buf, len, e, type); default: break; } @@ -201,13 +201,13 @@ nft_rule_expr_reject_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_reject = { .name = "reject", - .alloc_len = sizeof(struct nft_expr_reject), + .alloc_len = sizeof(struct nftnl_expr_reject), .max_attr = NFTA_REJECT_MAX, - .set = nft_rule_expr_reject_set, - .get = nft_rule_expr_reject_get, - .parse = nft_rule_expr_reject_parse, - .build = nft_rule_expr_reject_build, - .snprintf = nft_rule_expr_reject_snprintf, - .xml_parse = nft_rule_expr_reject_xml_parse, - .json_parse = nft_rule_expr_reject_json_parse, + .set = nftnl_rule_expr_reject_set, + .get = nftnl_rule_expr_reject_get, + .parse = nftnl_rule_expr_reject_parse, + .build = nftnl_rule_expr_reject_build, + .snprintf = nftnl_rule_expr_reject_snprintf, + .xml_parse = nftnl_rule_expr_reject_xml_parse, + .json_parse = nftnl_rule_expr_reject_json_parse, }; diff --git a/src/expr/target.c b/src/expr/target.c index 65c1ce0..57d03ea 100644 --- a/src/expr/target.c +++ b/src/expr/target.c @@ -27,7 +27,7 @@ /* From include/linux/netfilter/x_tables.h */ #define XT_EXTENSION_MAXNAMELEN 29 -struct nft_expr_target { +struct nftnl_expr_target { char name[XT_EXTENSION_MAXNAMELEN]; uint32_t rev; uint32_t data_len; @@ -35,20 +35,20 @@ struct nft_expr_target { }; static int -nft_rule_expr_target_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_target_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_target *tg = nft_expr_data(e); + struct nftnl_expr_target *tg = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_TG_NAME: + case NFTNL_EXPR_TG_NAME: snprintf(tg->name, sizeof(tg->name), "%.*s", data_len, (const char *) data); break; - case NFT_EXPR_TG_REV: + case NFTNL_EXPR_TG_REV: tg->rev = *((uint32_t *)data); break; - case NFT_EXPR_TG_INFO: + case NFTNL_EXPR_TG_INFO: if (tg->data) xfree(tg->data); @@ -62,26 +62,26 @@ nft_rule_expr_target_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_target_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_target_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_target *tg = nft_expr_data(e); + struct nftnl_expr_target *tg = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_TG_NAME: + case NFTNL_EXPR_TG_NAME: *data_len = sizeof(tg->name); return tg->name; - case NFT_EXPR_TG_REV: + case NFTNL_EXPR_TG_REV: *data_len = sizeof(tg->rev); return &tg->rev; - case NFT_EXPR_TG_INFO: + case NFTNL_EXPR_TG_INFO: *data_len = tg->data_len; return tg->data; } return NULL; } -static int nft_rule_expr_target_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_target_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -109,24 +109,24 @@ static int nft_rule_expr_target_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_target_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_target_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_target *tg = nft_expr_data(e); + struct nftnl_expr_target *tg = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_TG_NAME)) + if (e->flags & (1 << NFTNL_EXPR_TG_NAME)) mnl_attr_put_strz(nlh, NFTA_TARGET_NAME, tg->name); - if (e->flags & (1 << NFT_EXPR_TG_REV)) + if (e->flags & (1 << NFTNL_EXPR_TG_REV)) mnl_attr_put_u32(nlh, NFTA_TARGET_REV, htonl(tg->rev)); - if (e->flags & (1 << NFT_EXPR_TG_INFO)) + if (e->flags & (1 << NFTNL_EXPR_TG_INFO)) mnl_attr_put(nlh, NFTA_TARGET_INFO, tg->data_len, tg->data); } -static int nft_rule_expr_target_parse(struct nft_rule_expr *e, struct nlattr *attr) +static int nftnl_rule_expr_target_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_target *target = nft_expr_data(e); + struct nftnl_expr_target *target = nftnl_expr_data(e); struct nlattr *tb[NFTA_TARGET_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_target_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_target_cb, tb) < 0) return -1; if (tb[NFTA_TARGET_NAME]) { @@ -134,12 +134,12 @@ static int nft_rule_expr_target_parse(struct nft_rule_expr *e, struct nlattr *at mnl_attr_get_str(tb[NFTA_TARGET_NAME])); target->name[XT_EXTENSION_MAXNAMELEN-1] = '\0'; - e->flags |= (1 << NFT_EXPR_TG_NAME); + e->flags |= (1 << NFTNL_EXPR_TG_NAME); } if (tb[NFTA_TARGET_REV]) { target->rev = ntohl(mnl_attr_get_u32(tb[NFTA_TARGET_REV])); - e->flags |= (1 << NFT_EXPR_TG_REV); + e->flags |= (1 << NFTNL_EXPR_TG_REV); } if (tb[NFTA_TARGET_INFO]) { @@ -158,22 +158,22 @@ static int nft_rule_expr_target_parse(struct nft_rule_expr *e, struct nlattr *at target->data = target_data; target->data_len = len; - e->flags |= (1 << NFT_EXPR_TG_INFO); + e->flags |= (1 << NFTNL_EXPR_TG_INFO); } return 0; } static int -nft_rule_expr_target_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +nftnl_rule_expr_target_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING const char *name; - name = nft_jansson_parse_str(root, "name", err); + name = nftnl_jansson_parse_str(root, "name", err); if (name != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_TG_NAME, name); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_TG_NAME, name); return 0; #else @@ -183,16 +183,16 @@ nft_rule_expr_target_json_parse(struct nft_rule_expr *e, json_t *root, } static int -nft_rule_expr_target_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) +nftnl_rule_expr_target_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, + struct nftnl_parse_err *err) { #ifdef XML_PARSING const char *name; - name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + name = nftnl_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (name != NULL) - nft_rule_expr_set_str(e, NFT_EXPR_TG_NAME, name); + nftnl_rule_expr_set_str(e, NFTNL_EXPR_TG_NAME, name); /* tg->info is ignored until other solution is reached */ @@ -203,54 +203,54 @@ nft_rule_expr_target_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree, #endif } -static int nft_rule_exp_target_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_exp_target_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_target *target = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_target *target = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_TG_NAME)) - nft_buf_str(&b, type, target->name, NAME); + if (e->flags & (1 << NFTNL_EXPR_TG_NAME)) + nftnl_buf_str(&b, type, target->name, NAME); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } static int -nft_rule_expr_target_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_target_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { - struct nft_expr_target *target = nft_expr_data(e); + struct nftnl_expr_target *target = nftnl_expr_data(e); switch (type) { - case NFT_OUTPUT_DEFAULT: + case NFTNL_OUTPUT_DEFAULT: return snprintf(buf, len, "name %s rev %u ", target->name, target->rev); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_exp_target_export(buf, len, e, type); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_exp_target_export(buf, len, e, type); default: break; } return -1; } -static void nft_rule_expr_target_free(struct nft_rule_expr *e) +static void nftnl_rule_expr_target_free(struct nftnl_rule_expr *e) { - struct nft_expr_target *target = nft_expr_data(e); + struct nftnl_expr_target *target = nftnl_expr_data(e); xfree(target->data); } struct expr_ops expr_ops_target = { .name = "target", - .alloc_len = sizeof(struct nft_expr_target), + .alloc_len = sizeof(struct nftnl_expr_target), .max_attr = NFTA_TARGET_MAX, - .free = nft_rule_expr_target_free, - .set = nft_rule_expr_target_set, - .get = nft_rule_expr_target_get, - .parse = nft_rule_expr_target_parse, - .build = nft_rule_expr_target_build, - .snprintf = nft_rule_expr_target_snprintf, - .xml_parse = nft_rule_expr_target_xml_parse, - .json_parse = nft_rule_expr_target_json_parse, + .free = nftnl_rule_expr_target_free, + .set = nftnl_rule_expr_target_set, + .get = nftnl_rule_expr_target_get, + .parse = nftnl_rule_expr_target_parse, + .build = nftnl_rule_expr_target_build, + .snprintf = nftnl_rule_expr_target_snprintf, + .xml_parse = nftnl_rule_expr_target_xml_parse, + .json_parse = nftnl_rule_expr_target_json_parse, }; diff --git a/src/expr_ops.c b/src/expr_ops.c index 2de5805..fcc128f 100644 --- a/src/expr_ops.c +++ b/src/expr_ops.c @@ -49,7 +49,7 @@ static struct expr_ops *expr_ops[] = { NULL, }; -struct expr_ops *nft_expr_ops_lookup(const char *name) +struct expr_ops *nftnl_expr_ops_lookup(const char *name) { int i = 0; @@ -23,57 +23,57 @@ #include <libnftnl/gen.h> -struct nft_gen { +struct nftnl_gen { uint32_t id; uint32_t flags; }; -struct nft_gen *nft_gen_alloc(void) +struct nftnl_gen *nftnl_gen_alloc(void) { - return calloc(1, sizeof(struct nft_gen)); + return calloc(1, sizeof(struct nftnl_gen)); } EXPORT_SYMBOL(nftnl_gen_alloc, nft_gen_alloc); -void nft_gen_free(struct nft_gen *gen) +void nftnl_gen_free(struct nftnl_gen *gen) { xfree(gen); } EXPORT_SYMBOL(nftnl_gen_free, nft_gen_free); -bool nft_gen_attr_is_set(const struct nft_gen *gen, uint16_t attr) +bool nftnl_gen_attr_is_set(const struct nftnl_gen *gen, uint16_t attr) { return gen->flags & (1 << attr); } EXPORT_SYMBOL(nftnl_gen_attr_is_set, nft_gen_attr_is_set); -void nft_gen_attr_unset(struct nft_gen *gen, uint16_t attr) +void nftnl_gen_attr_unset(struct nftnl_gen *gen, uint16_t attr) { if (!(gen->flags & (1 << attr))) return; switch (attr) { - case NFT_GEN_ID: + case NFTNL_GEN_ID: break; } gen->flags &= ~(1 << attr); } EXPORT_SYMBOL(nftnl_gen_attr_unset, nft_gen_attr_unset); -static uint32_t nft_gen_attr_validate[NFT_GEN_MAX + 1] = { - [NFT_GEN_ID] = sizeof(uint32_t), +static uint32_t nftnl_gen_attr_validate[NFTNL_GEN_MAX + 1] = { + [NFTNL_GEN_ID] = sizeof(uint32_t), }; -void nft_gen_attr_set_data(struct nft_gen *gen, uint16_t attr, +void nftnl_gen_attr_set_data(struct nftnl_gen *gen, uint16_t attr, const void *data, uint32_t data_len) { - if (attr > NFT_GEN_MAX) + if (attr > NFTNL_GEN_MAX) return; - nft_assert_validate(data, nft_gen_attr_validate, attr, data_len); + nftnl_assert_validate(data, nftnl_gen_attr_validate, attr, data_len); switch (attr) { - case NFT_GEN_ID: + case NFTNL_GEN_ID: gen->id = *((uint32_t *)data); break; } @@ -81,47 +81,47 @@ void nft_gen_attr_set_data(struct nft_gen *gen, uint16_t attr, } EXPORT_SYMBOL(nftnl_gen_attr_set_data, nft_gen_attr_set_data); -void nft_gen_attr_set(struct nft_gen *gen, uint16_t attr, const void *data) +void nftnl_gen_attr_set(struct nftnl_gen *gen, uint16_t attr, const void *data) { - nft_gen_attr_set_data(gen, attr, data, nft_gen_attr_validate[attr]); + nftnl_gen_attr_set_data(gen, attr, data, nftnl_gen_attr_validate[attr]); } EXPORT_SYMBOL(nftnl_gen_attr_set, nft_gen_attr_set); -void nft_gen_attr_set_u32(struct nft_gen *gen, uint16_t attr, uint32_t val) +void nftnl_gen_attr_set_u32(struct nftnl_gen *gen, uint16_t attr, uint32_t val) { - nft_gen_attr_set_data(gen, attr, &val, sizeof(uint32_t)); + nftnl_gen_attr_set_data(gen, attr, &val, sizeof(uint32_t)); } EXPORT_SYMBOL(nftnl_gen_attr_set_u32, nft_gen_attr_set_u32); -const void *nft_gen_attr_get_data(struct nft_gen *gen, uint16_t attr, +const void *nftnl_gen_attr_get_data(struct nftnl_gen *gen, uint16_t attr, uint32_t *data_len) { if (!(gen->flags & (1 << attr))) return NULL; switch(attr) { - case NFT_GEN_ID: + case NFTNL_GEN_ID: return &gen->id; } return NULL; } EXPORT_SYMBOL(nftnl_gen_attr_get_data, nft_gen_attr_get_data); -const void *nft_gen_attr_get(struct nft_gen *gen, uint16_t attr) +const void *nftnl_gen_attr_get(struct nftnl_gen *gen, uint16_t attr) { uint32_t data_len; - return nft_gen_attr_get_data(gen, attr, &data_len); + return nftnl_gen_attr_get_data(gen, attr, &data_len); } EXPORT_SYMBOL(nftnl_gen_attr_get, nft_gen_attr_get); -uint32_t nft_gen_attr_get_u32(struct nft_gen *gen, uint16_t attr) +uint32_t nftnl_gen_attr_get_u32(struct nftnl_gen *gen, uint16_t attr) { - const void *ret = nft_gen_attr_get(gen, attr); + const void *ret = nftnl_gen_attr_get(gen, attr); return ret == NULL ? 0 : *((uint32_t *)ret); } EXPORT_SYMBOL(nftnl_gen_attr_get_u32, nft_gen_attr_get_u32); -static int nft_gen_parse_attr_cb(const struct nlattr *attr, void *data) +static int nftnl_gen_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -140,69 +140,69 @@ static int nft_gen_parse_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -int nft_gen_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_gen *gen) +int nftnl_gen_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_gen *gen) { struct nlattr *tb[NFTA_GEN_MAX + 1] = {}; struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh); - if (mnl_attr_parse(nlh, sizeof(*nfg), nft_gen_parse_attr_cb, tb) < 0) + if (mnl_attr_parse(nlh, sizeof(*nfg), nftnl_gen_parse_attr_cb, tb) < 0) return -1; if (tb[NFTA_GEN_ID]) { gen->id = ntohl(mnl_attr_get_u32(tb[NFTA_GEN_ID])); - gen->flags |= (1 << NFT_GEN_ID); + gen->flags |= (1 << NFTNL_GEN_ID); } return 0; } EXPORT_SYMBOL(nftnl_gen_nlmsg_parse, nft_gen_nlmsg_parse); -static int nft_gen_snprintf_default(char *buf, size_t size, struct nft_gen *gen) +static int nftnl_gen_snprintf_default(char *buf, size_t size, struct nftnl_gen *gen) { return snprintf(buf, size, "ruleset generation ID %u", gen->id); } -static int nft_gen_cmd_snprintf(char *buf, size_t size, struct nft_gen *gen, +static int nftnl_gen_cmd_snprintf(char *buf, size_t size, struct nftnl_gen *gen, uint32_t cmd, uint32_t type, uint32_t flags) { int ret, len = size, offset = 0; - ret = nft_cmd_header_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_header_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); switch(type) { - case NFT_OUTPUT_DEFAULT: - ret = nft_gen_snprintf_default(buf + offset, len, gen); + case NFTNL_OUTPUT_DEFAULT: + ret = nftnl_gen_snprintf_default(buf + offset, len, gen); break; default: return -1; } SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); return offset; } -int nft_gen_snprintf(char *buf, size_t size, struct nft_gen *gen, uint32_t type, +int nftnl_gen_snprintf(char *buf, size_t size, struct nftnl_gen *gen, uint32_t type, uint32_t flags) {; - return nft_gen_cmd_snprintf(buf, size, gen, nft_flag2cmd(flags), type, + return nftnl_gen_cmd_snprintf(buf, size, gen, nftnl_flag2cmd(flags), type, flags); } EXPORT_SYMBOL(nftnl_gen_snprintf, nft_gen_snprintf); -static inline int nft_gen_do_snprintf(char *buf, size_t size, void *gen, +static inline int nftnl_gen_do_snprintf(char *buf, size_t size, void *gen, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_gen_snprintf(buf, size, gen, type, flags); + return nftnl_gen_snprintf(buf, size, gen, type, flags); } -int nft_gen_fprintf(FILE *fp, struct nft_gen *gen, uint32_t type, +int nftnl_gen_fprintf(FILE *fp, struct nftnl_gen *gen, uint32_t type, uint32_t flags) { - return nft_fprintf(fp, gen, NFT_CMD_UNSPEC, type, flags, - nft_gen_do_snprintf); + return nftnl_fprintf(fp, gen, NFTNL_CMD_UNSPEC, type, flags, + nftnl_gen_do_snprintf); } EXPORT_SYMBOL(nftnl_gen_fprintf, nft_gen_fprintf); diff --git a/src/jansson.c b/src/jansson.c index b17d8a9..5ba26d3 100644 --- a/src/jansson.c +++ b/src/jansson.c @@ -23,21 +23,21 @@ #ifdef JSON_PARSING -static int nft_jansson_load_int_node(json_t *root, const char *node_name, - json_int_t *val, struct nft_parse_err *err) +static int nftnl_jansson_load_int_node(json_t *root, const char *node_name, + json_int_t *val, struct nftnl_parse_err *err) { json_t *node; node = json_object_get(root, node_name); if (node == NULL) { - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; err->node_name = node_name; errno = EINVAL; return -1; } if (!json_is_integer(node)) { - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; err->node_name = node_name; errno = ERANGE; return -1; @@ -47,15 +47,15 @@ static int nft_jansson_load_int_node(json_t *root, const char *node_name, return 0; } -const char *nft_jansson_parse_str(json_t *root, const char *node_name, - struct nft_parse_err *err) +const char *nftnl_jansson_parse_str(json_t *root, const char *node_name, + struct nftnl_parse_err *err) { json_t *node; const char *val; node = json_object_get(root, node_name); if (node == NULL) { - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; err->node_name = node_name; errno = EINVAL; return NULL; @@ -63,42 +63,42 @@ const char *nft_jansson_parse_str(json_t *root, const char *node_name, val = json_string_value(node); if (val == NULL) { - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; err->node_name = node_name; } return val; } -int nft_jansson_parse_val(json_t *root, const char *node_name, int type, - void *out, struct nft_parse_err *err) +int nftnl_jansson_parse_val(json_t *root, const char *node_name, int type, + void *out, struct nftnl_parse_err *err) { json_int_t val; - if (nft_jansson_load_int_node(root, node_name, &val, err) == -1) + if (nftnl_jansson_load_int_node(root, node_name, &val, err) == -1) return -1; - if (nft_get_value(type, &val, out) == -1) + if (nftnl_get_value(type, &val, out) == -1) return -1; return 0; } -bool nft_jansson_node_exist(json_t *root, const char *node_name) +bool nftnl_jansson_node_exist(json_t *root, const char *node_name) { return json_object_get(root, node_name) != NULL; } -json_t *nft_jansson_create_root(const void *json, json_error_t *error, - struct nft_parse_err *err, enum nft_parse_input input) +json_t *nftnl_jansson_create_root(const void *json, json_error_t *error, + struct nftnl_parse_err *err, enum nftnl_parse_input input) { json_t *root; switch (input) { - case NFT_PARSE_BUFFER: + case NFTNL_PARSE_BUFFER: root = json_loadb(json, strlen(json), 0, error); break; - case NFT_PARSE_FILE: + case NFTNL_PARSE_FILE: root = json_loadf((FILE *)json, 0, error); break; default: @@ -106,7 +106,7 @@ json_t *nft_jansson_create_root(const void *json, json_error_t *error, } if (root == NULL) { - err->error = NFT_PARSE_EBADINPUT; + err->error = NFTNL_PARSE_EBADINPUT; err->line = error->line; err->column = error->column; err->node_name = error->source; @@ -119,14 +119,14 @@ err: return NULL; } -json_t *nft_jansson_get_node(json_t *root, const char *node_name, - struct nft_parse_err *err) +json_t *nftnl_jansson_get_node(json_t *root, const char *node_name, + struct nftnl_parse_err *err) { json_t *node; node = json_object_get(root, node_name); if (node == NULL) { - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; err->node_name = node_name; errno = EINVAL; return NULL; @@ -135,21 +135,21 @@ json_t *nft_jansson_get_node(json_t *root, const char *node_name, return node; } -void nft_jansson_free_root(json_t *root) +void nftnl_jansson_free_root(json_t *root) { json_decref(root); } -int nft_jansson_parse_family(json_t *root, void *out, struct nft_parse_err *err) +int nftnl_jansson_parse_family(json_t *root, void *out, struct nftnl_parse_err *err) { const char *str; int family; - str = nft_jansson_parse_str(root, "family", err); + str = nftnl_jansson_parse_str(root, "family", err); if (str == NULL) return -1; - family = nft_str2family(str); + family = nftnl_str2family(str); if (family < 0) { err->node_name = "family"; errno = EINVAL; @@ -160,10 +160,10 @@ int nft_jansson_parse_family(json_t *root, void *out, struct nft_parse_err *err) return 0; } -int nft_jansson_parse_reg(json_t *root, const char *node_name, int type, - void *out, struct nft_parse_err *err) +int nftnl_jansson_parse_reg(json_t *root, const char *node_name, int type, + void *out, struct nftnl_parse_err *err) { - if (nft_jansson_parse_val(root, node_name, type, out, err) < 0) + if (nftnl_jansson_parse_val(root, node_name, type, out, err) < 0) return -1; if (*((uint32_t *)out) > NFT_REG_MAX){ @@ -174,32 +174,32 @@ int nft_jansson_parse_reg(json_t *root, const char *node_name, int type, return 0; } -int nft_jansson_str2num(json_t *root, const char *node_name, int base, - void *out, enum nft_type type, struct nft_parse_err *err) +int nftnl_jansson_str2num(json_t *root, const char *node_name, int base, + void *out, enum nftnl_type type, struct nftnl_parse_err *err) { const char *str; - str = nft_jansson_parse_str(root, node_name, err); + str = nftnl_jansson_parse_str(root, node_name, err); if (str == NULL) return -1; - return nft_strtoi(str, base, out, type); + return nftnl_strtoi(str, base, out, type); } -struct nft_rule_expr *nft_jansson_expr_parse(json_t *root, - struct nft_parse_err *err, - struct nft_set_list *set_list) +struct nftnl_rule_expr *nftnl_jansson_expr_parse(json_t *root, + struct nftnl_parse_err *err, + struct nftnl_set_list *set_list) { - struct nft_rule_expr *e; + struct nftnl_rule_expr *e; const char *type; uint32_t set_id; int ret; - type = nft_jansson_parse_str(root, "type", err); + type = nftnl_jansson_parse_str(root, "type", err); if (type == NULL) return NULL; - e = nft_rule_expr_alloc(type); + e = nftnl_rule_expr_alloc(type); if (e == NULL) { err->node_name = "type"; return NULL; @@ -209,15 +209,15 @@ struct nft_rule_expr *nft_jansson_expr_parse(json_t *root, if (set_list != NULL && strcmp(type, "lookup") == 0 && - nft_set_lookup_id(e, set_list, &set_id)) - nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_SET_ID, set_id); + nftnl_set_lookup_id(e, set_list, &set_id)) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOOKUP_SET_ID, set_id); return ret < 0 ? NULL : e; } -int nft_jansson_data_reg_parse(json_t *root, const char *node_name, - union nft_data_reg *data_reg, - struct nft_parse_err *err) +int nftnl_jansson_data_reg_parse(json_t *root, const char *node_name, + union nftnl_data_reg *data_reg, + struct nftnl_parse_err *err) { json_t *data; int ret; @@ -229,13 +229,13 @@ int nft_jansson_data_reg_parse(json_t *root, const char *node_name, data = json_object_get(data, "reg"); if (data == NULL) { - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; err->node_name = "reg"; errno = EINVAL; return -1; } - ret = nft_data_reg_json_parse(data_reg, data, err); + ret = nftnl_data_reg_json_parse(data_reg, data, err); if (ret == DATA_NONE) { errno = EINVAL; return -1; @@ -244,29 +244,29 @@ int nft_jansson_data_reg_parse(json_t *root, const char *node_name, return ret; } -int nft_jansson_set_elem_parse(struct nft_set_elem *e, json_t *root, - struct nft_parse_err *err) +int nftnl_jansson_set_elem_parse(struct nftnl_set_elem *e, json_t *root, + struct nftnl_parse_err *err) { int set_elem_data; uint32_t flags; - if (nft_jansson_parse_val(root, "flags", NFT_TYPE_U32, &flags, err) == 0) - nft_set_elem_attr_set_u32(e, NFT_SET_ELEM_ATTR_FLAGS, flags); + if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, err) == 0) + nftnl_set_elem_attr_set_u32(e, NFTNL_SET_ELEM_ATTR_FLAGS, flags); - if (nft_jansson_data_reg_parse(root, "key", &e->key, err) == DATA_VALUE) - e->flags |= (1 << NFT_SET_ELEM_ATTR_KEY); + if (nftnl_jansson_data_reg_parse(root, "key", &e->key, err) == DATA_VALUE) + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_KEY); - if (nft_jansson_node_exist(root, "data")) { - set_elem_data = nft_jansson_data_reg_parse(root, "data", + if (nftnl_jansson_node_exist(root, "data")) { + set_elem_data = nftnl_jansson_data_reg_parse(root, "data", &e->data, err); switch (set_elem_data) { case DATA_VALUE: - e->flags |= (1 << NFT_SET_ELEM_ATTR_DATA); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_DATA); break; case DATA_VERDICT: - e->flags |= (1 << NFT_SET_ELEM_ATTR_VERDICT); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_VERDICT); if (e->data.chain != NULL) - e->flags |= (1 << NFT_SET_ELEM_ATTR_CHAIN); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_CHAIN); break; case DATA_NONE: default: @@ -22,16 +22,16 @@ #include <libnftnl/set.h> #ifdef XML_PARSING -mxml_node_t *nft_mxml_build_tree(const void *data, const char *treename, - struct nft_parse_err *err, enum nft_parse_input input) +mxml_node_t *nftnl_mxml_build_tree(const void *data, const char *treename, + struct nftnl_parse_err *err, enum nftnl_parse_input input) { mxml_node_t *tree; switch (input) { - case NFT_PARSE_BUFFER: + case NFTNL_PARSE_BUFFER: tree = mxmlLoadString(NULL, data, MXML_OPAQUE_CALLBACK); break; - case NFT_PARSE_FILE: + case NFTNL_PARSE_FILE: tree = mxmlLoadFile(NULL, (FILE *)data, MXML_OPAQUE_CALLBACK); break; default: @@ -39,7 +39,7 @@ mxml_node_t *nft_mxml_build_tree(const void *data, const char *treename, } if (tree == NULL) { - err->error = NFT_PARSE_EBADINPUT; + err->error = NFTNL_PARSE_EBADINPUT; goto err; } @@ -47,7 +47,7 @@ mxml_node_t *nft_mxml_build_tree(const void *data, const char *treename, strcmp(tree->value.opaque, treename) == 0) return tree; - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; err->node_name = treename; mxmlDelete(tree); @@ -58,12 +58,12 @@ err: return NULL; } -struct nft_rule_expr *nft_mxml_expr_parse(mxml_node_t *node, - struct nft_parse_err *err, - struct nft_set_list *set_list) +struct nftnl_rule_expr *nftnl_mxml_expr_parse(mxml_node_t *node, + struct nftnl_parse_err *err, + struct nftnl_set_list *set_list) { mxml_node_t *tree; - struct nft_rule_expr *e; + struct nftnl_rule_expr *e; const char *expr_name; char *xml_text; uint32_t set_id; @@ -72,11 +72,11 @@ struct nft_rule_expr *nft_mxml_expr_parse(mxml_node_t *node, expr_name = mxmlElementGetAttr(node, "type"); if (expr_name == NULL) { err->node_name = "type"; - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; goto err; } - e = nft_rule_expr_alloc(expr_name); + e = nftnl_rule_expr_alloc(expr_name); if (e == NULL) goto err; @@ -95,37 +95,37 @@ struct nft_rule_expr *nft_mxml_expr_parse(mxml_node_t *node, if (set_list != NULL && strcmp(expr_name, "lookup") == 0 && - nft_set_lookup_id(e, set_list, &set_id)) - nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_SET_ID, set_id); + nftnl_set_lookup_id(e, set_list, &set_id)) + nftnl_rule_expr_set_u32(e, NFTNL_EXPR_LOOKUP_SET_ID, set_id); return ret < 0 ? NULL : e; err_expr: - nft_rule_expr_free(e); + nftnl_rule_expr_free(e); err: mxmlDelete(tree); errno = EINVAL; return NULL; } -int nft_mxml_reg_parse(mxml_node_t *tree, const char *reg_name, uint32_t *reg, +int nftnl_mxml_reg_parse(mxml_node_t *tree, const char *reg_name, uint32_t *reg, uint32_t mxmlflags, uint32_t flags, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { mxml_node_t *node; node = mxmlFindElement(tree, tree, reg_name, NULL, NULL, mxmlflags); if (node == NULL) { - if (!(flags & NFT_XML_OPT)) { - err->error = NFT_PARSE_EMISSINGNODE; + if (!(flags & NFTNL_XML_OPT)) { + err->error = NFTNL_PARSE_EMISSINGNODE; errno = EINVAL; goto err; } return -1; } - if (nft_strtoi(node->child->value.opaque, BASE_DEC, reg, - NFT_TYPE_U32) != 0) { - err->error = NFT_PARSE_EBADTYPE; + if (nftnl_strtoi(node->child->value.opaque, BASE_DEC, reg, + NFTNL_TYPE_U32) != 0) { + err->error = NFTNL_PARSE_EBADTYPE; goto err; } @@ -140,9 +140,9 @@ err: return -1; } -int nft_mxml_data_reg_parse(mxml_node_t *tree, const char *node_name, - union nft_data_reg *data_reg, uint16_t flags, - struct nft_parse_err *err) +int nftnl_mxml_data_reg_parse(mxml_node_t *tree, const char *node_name, + union nftnl_data_reg *data_reg, uint16_t flags, + struct nftnl_parse_err *err) { mxml_node_t *node; @@ -153,50 +153,50 @@ int nft_mxml_data_reg_parse(mxml_node_t *tree, const char *node_name, if (node == NULL || node->child == NULL) node = tree; - return nft_data_reg_xml_parse(data_reg, node, err); + return nftnl_data_reg_xml_parse(data_reg, node, err); } int -nft_mxml_num_parse(mxml_node_t *tree, const char *node_name, +nftnl_mxml_num_parse(mxml_node_t *tree, const char *node_name, uint32_t mxml_flags, int base, void *number, - enum nft_type type, uint16_t flags, - struct nft_parse_err *err) + enum nftnl_type type, uint16_t flags, + struct nftnl_parse_err *err) { mxml_node_t *node = NULL; int ret; node = mxmlFindElement(tree, tree, node_name, NULL, NULL, mxml_flags); if (node == NULL || node->child == NULL) { - if (!(flags & NFT_XML_OPT)) { + if (!(flags & NFTNL_XML_OPT)) { errno = EINVAL; err->node_name = node_name; - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; } return -1; } - ret = nft_strtoi(node->child->value.opaque, base, number, type); + ret = nftnl_strtoi(node->child->value.opaque, base, number, type); if (ret != 0) { - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; err->node_name = node_name; } return ret; } -const char *nft_mxml_str_parse(mxml_node_t *tree, const char *node_name, +const char *nftnl_mxml_str_parse(mxml_node_t *tree, const char *node_name, uint32_t mxml_flags, uint16_t flags, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { mxml_node_t *node; const char *ret; node = mxmlFindElement(tree, tree, node_name, NULL, NULL, mxml_flags); if (node == NULL || node->child == NULL) { - if (!(flags & NFT_XML_OPT)) { + if (!(flags & NFTNL_XML_OPT)) { errno = EINVAL; err->node_name = node_name; - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; } return NULL; } @@ -204,24 +204,24 @@ const char *nft_mxml_str_parse(mxml_node_t *tree, const char *node_name, ret = node->child->value.opaque; if (ret == NULL) { err->node_name = node_name; - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; } return ret; } -int nft_mxml_family_parse(mxml_node_t *tree, const char *node_name, +int nftnl_mxml_family_parse(mxml_node_t *tree, const char *node_name, uint32_t mxml_flags, uint16_t flags, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { const char *family_str; int family; - family_str = nft_mxml_str_parse(tree, node_name, mxml_flags, + family_str = nftnl_mxml_str_parse(tree, node_name, mxml_flags, flags, err); if (family_str == NULL) return -1; - family = nft_str2family(family_str); + family = nftnl_str2family(family_str); if (family < 0) { err->node_name = node_name; errno = EAFNOSUPPORT; @@ -29,7 +29,7 @@ #include <libnftnl/set.h> #include <libnftnl/expr.h> -struct nft_rule { +struct nftnl_rule { struct list_head head; uint32_t flags; @@ -50,11 +50,11 @@ struct nft_rule { struct list_head expr_list; }; -struct nft_rule *nft_rule_alloc(void) +struct nftnl_rule *nftnl_rule_alloc(void) { - struct nft_rule *r; + struct nftnl_rule *r; - r = calloc(1, sizeof(struct nft_rule)); + r = calloc(1, sizeof(struct nftnl_rule)); if (r == NULL) return NULL; @@ -64,12 +64,12 @@ struct nft_rule *nft_rule_alloc(void) } EXPORT_SYMBOL(nftnl_rule_alloc, nft_rule_alloc); -void nft_rule_free(struct nft_rule *r) +void nftnl_rule_free(struct nftnl_rule *r) { - struct nft_rule_expr *e, *tmp; + struct nftnl_rule_expr *e, *tmp; list_for_each_entry_safe(e, tmp, &r->expr_list, head) - nft_rule_expr_free(e); + nftnl_rule_expr_free(e); if (r->table != NULL) xfree(r->table); @@ -80,36 +80,36 @@ void nft_rule_free(struct nft_rule *r) } EXPORT_SYMBOL(nftnl_rule_free, nft_rule_free); -bool nft_rule_attr_is_set(const struct nft_rule *r, uint16_t attr) +bool nftnl_rule_attr_is_set(const struct nftnl_rule *r, uint16_t attr) { return r->flags & (1 << attr); } EXPORT_SYMBOL(nftnl_rule_attr_is_set, nft_rule_attr_is_set); -void nft_rule_attr_unset(struct nft_rule *r, uint16_t attr) +void nftnl_rule_attr_unset(struct nftnl_rule *r, uint16_t attr) { if (!(r->flags & (1 << attr))) return; switch (attr) { - case NFT_RULE_ATTR_TABLE: + case NFTNL_RULE_ATTR_TABLE: if (r->table) { xfree(r->table); r->table = NULL; } break; - case NFT_RULE_ATTR_CHAIN: + case NFTNL_RULE_ATTR_CHAIN: if (r->chain) { xfree(r->chain); r->chain = NULL; } break; - case NFT_RULE_ATTR_HANDLE: - case NFT_RULE_ATTR_COMPAT_PROTO: - case NFT_RULE_ATTR_COMPAT_FLAGS: - case NFT_RULE_ATTR_POSITION: - case NFT_RULE_ATTR_FAMILY: - case NFT_RULE_ATTR_USERDATA: + case NFTNL_RULE_ATTR_HANDLE: + case NFTNL_RULE_ATTR_COMPAT_PROTO: + case NFTNL_RULE_ATTR_COMPAT_FLAGS: + case NFTNL_RULE_ATTR_POSITION: + case NFTNL_RULE_ATTR_FAMILY: + case NFTNL_RULE_ATTR_USERDATA: break; } @@ -117,51 +117,51 @@ void nft_rule_attr_unset(struct nft_rule *r, uint16_t attr) } EXPORT_SYMBOL(nftnl_rule_attr_unset, nft_rule_attr_unset); -static uint32_t nft_rule_attr_validate[NFT_RULE_ATTR_MAX + 1] = { - [NFT_RULE_ATTR_HANDLE] = sizeof(uint64_t), - [NFT_RULE_ATTR_COMPAT_PROTO] = sizeof(uint32_t), - [NFT_RULE_ATTR_COMPAT_FLAGS] = sizeof(uint32_t), - [NFT_RULE_ATTR_FAMILY] = sizeof(uint32_t), - [NFT_RULE_ATTR_POSITION] = sizeof(uint64_t), +static uint32_t nftnl_rule_attr_validate[NFTNL_RULE_ATTR_MAX + 1] = { + [NFTNL_RULE_ATTR_HANDLE] = sizeof(uint64_t), + [NFTNL_RULE_ATTR_COMPAT_PROTO] = sizeof(uint32_t), + [NFTNL_RULE_ATTR_COMPAT_FLAGS] = sizeof(uint32_t), + [NFTNL_RULE_ATTR_FAMILY] = sizeof(uint32_t), + [NFTNL_RULE_ATTR_POSITION] = sizeof(uint64_t), }; -void nft_rule_attr_set_data(struct nft_rule *r, uint16_t attr, +void nftnl_rule_attr_set_data(struct nftnl_rule *r, uint16_t attr, const void *data, uint32_t data_len) { - if (attr > NFT_RULE_ATTR_MAX) + if (attr > NFTNL_RULE_ATTR_MAX) return; - nft_assert_validate(data, nft_rule_attr_validate, attr, data_len); + nftnl_assert_validate(data, nftnl_rule_attr_validate, attr, data_len); switch(attr) { - case NFT_RULE_ATTR_TABLE: + case NFTNL_RULE_ATTR_TABLE: if (r->table) xfree(r->table); r->table = strdup(data); break; - case NFT_RULE_ATTR_CHAIN: + case NFTNL_RULE_ATTR_CHAIN: if (r->chain) xfree(r->chain); r->chain = strdup(data); break; - case NFT_RULE_ATTR_HANDLE: + case NFTNL_RULE_ATTR_HANDLE: r->handle = *((uint64_t *)data); break; - case NFT_RULE_ATTR_COMPAT_PROTO: + case NFTNL_RULE_ATTR_COMPAT_PROTO: r->compat.proto = *((uint32_t *)data); break; - case NFT_RULE_ATTR_COMPAT_FLAGS: + case NFTNL_RULE_ATTR_COMPAT_FLAGS: r->compat.flags = *((uint32_t *)data); break; - case NFT_RULE_ATTR_FAMILY: + case NFTNL_RULE_ATTR_FAMILY: r->family = *((uint32_t *)data); break; - case NFT_RULE_ATTR_POSITION: + case NFTNL_RULE_ATTR_POSITION: r->position = *((uint64_t *)data); break; - case NFT_RULE_ATTR_USERDATA: + case NFTNL_RULE_ATTR_USERDATA: r->user.data = (void *)data; r->user.len = data_len; break; @@ -170,57 +170,57 @@ void nft_rule_attr_set_data(struct nft_rule *r, uint16_t attr, } EXPORT_SYMBOL(nftnl_rule_attr_set_data, nft_rule_attr_set_data); -void nft_rule_attr_set(struct nft_rule *r, uint16_t attr, const void *data) +void nftnl_rule_attr_set(struct nftnl_rule *r, uint16_t attr, const void *data) { - nft_rule_attr_set_data(r, attr, data, nft_rule_attr_validate[attr]); + nftnl_rule_attr_set_data(r, attr, data, nftnl_rule_attr_validate[attr]); } EXPORT_SYMBOL(nftnl_rule_attr_set, nft_rule_attr_set); -void nft_rule_attr_set_u32(struct nft_rule *r, uint16_t attr, uint32_t val) +void nftnl_rule_attr_set_u32(struct nftnl_rule *r, uint16_t attr, uint32_t val) { - nft_rule_attr_set_data(r, attr, &val, sizeof(uint32_t)); + nftnl_rule_attr_set_data(r, attr, &val, sizeof(uint32_t)); } EXPORT_SYMBOL(nftnl_rule_attr_set_u32, nft_rule_attr_set_u32); -void nft_rule_attr_set_u64(struct nft_rule *r, uint16_t attr, uint64_t val) +void nftnl_rule_attr_set_u64(struct nftnl_rule *r, uint16_t attr, uint64_t val) { - nft_rule_attr_set_data(r, attr, &val, sizeof(uint64_t)); + nftnl_rule_attr_set_data(r, attr, &val, sizeof(uint64_t)); } EXPORT_SYMBOL(nftnl_rule_attr_set_u64, nft_rule_attr_set_u64); -void nft_rule_attr_set_str(struct nft_rule *r, uint16_t attr, const char *str) +void nftnl_rule_attr_set_str(struct nftnl_rule *r, uint16_t attr, const char *str) { - nft_rule_attr_set_data(r, attr, str, strlen(str)); + nftnl_rule_attr_set_data(r, attr, str, strlen(str)); } EXPORT_SYMBOL(nftnl_rule_attr_set_str, nft_rule_attr_set_str); -const void *nft_rule_attr_get_data(const struct nft_rule *r, uint16_t attr, +const void *nftnl_rule_attr_get_data(const struct nftnl_rule *r, uint16_t attr, uint32_t *data_len) { if (!(r->flags & (1 << attr))) return NULL; switch(attr) { - case NFT_RULE_ATTR_FAMILY: + case NFTNL_RULE_ATTR_FAMILY: *data_len = sizeof(uint32_t); return &r->family; - case NFT_RULE_ATTR_TABLE: + case NFTNL_RULE_ATTR_TABLE: return r->table; - case NFT_RULE_ATTR_CHAIN: + case NFTNL_RULE_ATTR_CHAIN: return r->chain; - case NFT_RULE_ATTR_HANDLE: + case NFTNL_RULE_ATTR_HANDLE: *data_len = sizeof(uint64_t); return &r->handle; - case NFT_RULE_ATTR_COMPAT_PROTO: + case NFTNL_RULE_ATTR_COMPAT_PROTO: *data_len = sizeof(uint32_t); return &r->compat.proto; - case NFT_RULE_ATTR_COMPAT_FLAGS: + case NFTNL_RULE_ATTR_COMPAT_FLAGS: *data_len = sizeof(uint32_t); return &r->compat.flags; - case NFT_RULE_ATTR_POSITION: + case NFTNL_RULE_ATTR_POSITION: *data_len = sizeof(uint64_t); return &r->position; - case NFT_RULE_ATTR_USERDATA: + case NFTNL_RULE_ATTR_USERDATA: *data_len = r->user.len; return r->user.data; } @@ -228,66 +228,66 @@ const void *nft_rule_attr_get_data(const struct nft_rule *r, uint16_t attr, } EXPORT_SYMBOL(nftnl_rule_attr_get_data, nft_rule_attr_get_data); -const void *nft_rule_attr_get(const struct nft_rule *r, uint16_t attr) +const void *nftnl_rule_attr_get(const struct nftnl_rule *r, uint16_t attr) { uint32_t data_len; - return nft_rule_attr_get_data(r, attr, &data_len); + return nftnl_rule_attr_get_data(r, attr, &data_len); } EXPORT_SYMBOL(nftnl_rule_attr_get, nft_rule_attr_get); -const char *nft_rule_attr_get_str(const struct nft_rule *r, uint16_t attr) +const char *nftnl_rule_attr_get_str(const struct nftnl_rule *r, uint16_t attr) { - return nft_rule_attr_get(r, attr); + return nftnl_rule_attr_get(r, attr); } EXPORT_SYMBOL(nftnl_rule_attr_get_str, nft_rule_attr_get_str); -uint32_t nft_rule_attr_get_u32(const struct nft_rule *r, uint16_t attr) +uint32_t nftnl_rule_attr_get_u32(const struct nftnl_rule *r, uint16_t attr) { uint32_t data_len; - const uint32_t *val = nft_rule_attr_get_data(r, attr, &data_len); + const uint32_t *val = nftnl_rule_attr_get_data(r, attr, &data_len); - nft_assert(val, attr, data_len == sizeof(uint32_t)); + nftnl_assert(val, attr, data_len == sizeof(uint32_t)); return val ? *val : 0; } EXPORT_SYMBOL(nftnl_rule_attr_get_u32, nft_rule_attr_get_u32); -uint64_t nft_rule_attr_get_u64(const struct nft_rule *r, uint16_t attr) +uint64_t nftnl_rule_attr_get_u64(const struct nftnl_rule *r, uint16_t attr) { uint32_t data_len; - const uint64_t *val = nft_rule_attr_get_data(r, attr, &data_len); + const uint64_t *val = nftnl_rule_attr_get_data(r, attr, &data_len); - nft_assert(val, attr, data_len == sizeof(uint64_t)); + nftnl_assert(val, attr, data_len == sizeof(uint64_t)); return val ? *val : 0; } EXPORT_SYMBOL(nftnl_rule_attr_get_u64, nft_rule_attr_get_u64); -uint8_t nft_rule_attr_get_u8(const struct nft_rule *r, uint16_t attr) +uint8_t nftnl_rule_attr_get_u8(const struct nftnl_rule *r, uint16_t attr) { uint32_t data_len; - const uint8_t *val = nft_rule_attr_get_data(r, attr, &data_len); + const uint8_t *val = nftnl_rule_attr_get_data(r, attr, &data_len); - nft_assert(val, attr, data_len == sizeof(uint8_t)); + nftnl_assert(val, attr, data_len == sizeof(uint8_t)); return val ? *val : 0; } EXPORT_SYMBOL(nftnl_rule_attr_get_u8, nft_rule_attr_get_u8); -void nft_rule_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_rule *r) +void nftnl_rule_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_rule *r) { - struct nft_rule_expr *expr; + struct nftnl_rule_expr *expr; struct nlattr *nest, *nest2; - if (r->flags & (1 << NFT_RULE_ATTR_TABLE)) + if (r->flags & (1 << NFTNL_RULE_ATTR_TABLE)) mnl_attr_put_strz(nlh, NFTA_RULE_TABLE, r->table); - if (r->flags & (1 << NFT_RULE_ATTR_CHAIN)) + if (r->flags & (1 << NFTNL_RULE_ATTR_CHAIN)) mnl_attr_put_strz(nlh, NFTA_RULE_CHAIN, r->chain); - if (r->flags & (1 << NFT_RULE_ATTR_HANDLE)) + if (r->flags & (1 << NFTNL_RULE_ATTR_HANDLE)) mnl_attr_put_u64(nlh, NFTA_RULE_HANDLE, htobe64(r->handle)); - if (r->flags & (1 << NFT_RULE_ATTR_POSITION)) + if (r->flags & (1 << NFTNL_RULE_ATTR_POSITION)) mnl_attr_put_u64(nlh, NFTA_RULE_POSITION, htobe64(r->position)); - if (r->flags & (1 << NFT_RULE_ATTR_USERDATA)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_USERDATA)) { mnl_attr_put(nlh, NFTA_RULE_USERDATA, r->user.len, r->user.data); } @@ -296,14 +296,14 @@ void nft_rule_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_rule *r) nest = mnl_attr_nest_start(nlh, NFTA_RULE_EXPRESSIONS); list_for_each_entry(expr, &r->expr_list, head) { nest2 = mnl_attr_nest_start(nlh, NFTA_LIST_ELEM); - nft_rule_expr_build_payload(nlh, expr); + nftnl_rule_expr_build_payload(nlh, expr); mnl_attr_nest_end(nlh, nest2); } mnl_attr_nest_end(nlh, nest); } - if (r->flags & (1 << NFT_RULE_ATTR_COMPAT_PROTO) && - r->flags & (1 << NFT_RULE_ATTR_COMPAT_FLAGS)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_COMPAT_PROTO) && + r->flags & (1 << NFTNL_RULE_ATTR_COMPAT_FLAGS)) { nest = mnl_attr_nest_start(nlh, NFTA_RULE_COMPAT); mnl_attr_put_u32(nlh, NFTA_RULE_COMPAT_PROTO, @@ -315,13 +315,13 @@ void nft_rule_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_rule *r) } EXPORT_SYMBOL(nftnl_rule_nlmsg_build_payload, nft_rule_nlmsg_build_payload); -void nft_rule_add_expr(struct nft_rule *r, struct nft_rule_expr *expr) +void nftnl_rule_add_expr(struct nftnl_rule *r, struct nftnl_rule_expr *expr) { list_add_tail(&expr->head, &r->expr_list); } EXPORT_SYMBOL(nftnl_rule_add_expr, nft_rule_add_expr); -static int nft_rule_parse_attr_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -357,16 +357,16 @@ static int nft_rule_parse_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_rule_parse_expr(struct nlattr *nest, struct nft_rule *r) +static int nftnl_rule_parse_expr(struct nlattr *nest, struct nftnl_rule *r) { - struct nft_rule_expr *expr; + struct nftnl_rule_expr *expr; struct nlattr *attr; mnl_attr_for_each_nested(attr, nest) { if (mnl_attr_get_type(attr) != NFTA_LIST_ELEM) return -1; - expr = nft_rule_expr_parse(attr); + expr = nftnl_rule_expr_parse(attr); if (expr == NULL) return -1; @@ -375,7 +375,7 @@ static int nft_rule_parse_expr(struct nlattr *nest, struct nft_rule *r) return 0; } -static int nft_rule_parse_compat_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_parse_compat_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -395,56 +395,56 @@ static int nft_rule_parse_compat_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_rule_parse_compat(struct nlattr *nest, struct nft_rule *r) +static int nftnl_rule_parse_compat(struct nlattr *nest, struct nftnl_rule *r) { struct nlattr *tb[NFTA_RULE_COMPAT_MAX+1] = {}; - if (mnl_attr_parse_nested(nest, nft_rule_parse_compat_cb, tb) < 0) + if (mnl_attr_parse_nested(nest, nftnl_rule_parse_compat_cb, tb) < 0) return -1; if (tb[NFTA_RULE_COMPAT_PROTO]) { r->compat.proto = ntohl(mnl_attr_get_u32(tb[NFTA_RULE_COMPAT_PROTO])); - r->flags |= (1 << NFT_RULE_ATTR_COMPAT_PROTO); + r->flags |= (1 << NFTNL_RULE_ATTR_COMPAT_PROTO); } if (tb[NFTA_RULE_COMPAT_FLAGS]) { r->compat.flags = ntohl(mnl_attr_get_u32(tb[NFTA_RULE_COMPAT_FLAGS])); - r->flags |= (1 << NFT_RULE_ATTR_COMPAT_FLAGS); + r->flags |= (1 << NFTNL_RULE_ATTR_COMPAT_FLAGS); } return 0; } -int nft_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_rule *r) +int nftnl_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_rule *r) { struct nlattr *tb[NFTA_RULE_MAX+1] = {}; struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh); int ret = 0; - if (mnl_attr_parse(nlh, sizeof(*nfg), nft_rule_parse_attr_cb, tb) < 0) + if (mnl_attr_parse(nlh, sizeof(*nfg), nftnl_rule_parse_attr_cb, tb) < 0) return -1; if (tb[NFTA_RULE_TABLE]) { xfree(r->table); r->table = strdup(mnl_attr_get_str(tb[NFTA_RULE_TABLE])); - r->flags |= (1 << NFT_RULE_ATTR_TABLE); + r->flags |= (1 << NFTNL_RULE_ATTR_TABLE); } if (tb[NFTA_RULE_CHAIN]) { xfree(r->chain); r->chain = strdup(mnl_attr_get_str(tb[NFTA_RULE_CHAIN])); - r->flags |= (1 << NFT_RULE_ATTR_CHAIN); + r->flags |= (1 << NFTNL_RULE_ATTR_CHAIN); } if (tb[NFTA_RULE_HANDLE]) { r->handle = be64toh(mnl_attr_get_u64(tb[NFTA_RULE_HANDLE])); - r->flags |= (1 << NFT_RULE_ATTR_HANDLE); + r->flags |= (1 << NFTNL_RULE_ATTR_HANDLE); } if (tb[NFTA_RULE_EXPRESSIONS]) - ret = nft_rule_parse_expr(tb[NFTA_RULE_EXPRESSIONS], r); + ret = nftnl_rule_parse_expr(tb[NFTA_RULE_EXPRESSIONS], r); if (tb[NFTA_RULE_COMPAT]) - ret = nft_rule_parse_compat(tb[NFTA_RULE_COMPAT], r); + ret = nftnl_rule_parse_compat(tb[NFTA_RULE_COMPAT], r); if (tb[NFTA_RULE_POSITION]) { r->position = be64toh(mnl_attr_get_u64(tb[NFTA_RULE_POSITION])); - r->flags |= (1 << NFT_RULE_ATTR_POSITION); + r->flags |= (1 << NFTNL_RULE_ATTR_POSITION); } if (tb[NFTA_RULE_USERDATA]) { const void *udata = @@ -460,101 +460,101 @@ int nft_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_rule *r) return -1; memcpy(r->user.data, udata, r->user.len); - r->flags |= (1 << NFT_RULE_ATTR_USERDATA); + r->flags |= (1 << NFTNL_RULE_ATTR_USERDATA); } r->family = nfg->nfgen_family; - r->flags |= (1 << NFT_RULE_ATTR_FAMILY); + r->flags |= (1 << NFTNL_RULE_ATTR_FAMILY); return ret; } EXPORT_SYMBOL(nftnl_rule_nlmsg_parse, nft_rule_nlmsg_parse); #ifdef JSON_PARSING -int nft_jansson_parse_rule(struct nft_rule *r, json_t *tree, - struct nft_parse_err *err, - struct nft_set_list *set_list) +int nftnl_jansson_parse_rule(struct nftnl_rule *r, json_t *tree, + struct nftnl_parse_err *err, + struct nftnl_set_list *set_list) { json_t *root, *array; - struct nft_rule_expr *e; + struct nftnl_rule_expr *e; const char *str = NULL; uint64_t uval64; uint32_t uval32; int i, family; - root = nft_jansson_get_node(tree, "rule", err); + root = nftnl_jansson_get_node(tree, "rule", err); if (root == NULL) return -1; - if (nft_jansson_node_exist(root, "family")) { - if (nft_jansson_parse_family(root, &family, err) != 0) + if (nftnl_jansson_node_exist(root, "family")) { + if (nftnl_jansson_parse_family(root, &family, err) != 0) goto err; - nft_rule_attr_set_u32(r, NFT_RULE_ATTR_FAMILY, family); + nftnl_rule_attr_set_u32(r, NFTNL_RULE_ATTR_FAMILY, family); } - if (nft_jansson_node_exist(root, "table")) { - str = nft_jansson_parse_str(root, "table", err); + if (nftnl_jansson_node_exist(root, "table")) { + str = nftnl_jansson_parse_str(root, "table", err); if (str == NULL) goto err; - nft_rule_attr_set_str(r, NFT_RULE_ATTR_TABLE, str); + nftnl_rule_attr_set_str(r, NFTNL_RULE_ATTR_TABLE, str); } - if (nft_jansson_node_exist(root, "chain")) { - str = nft_jansson_parse_str(root, "chain", err); + if (nftnl_jansson_node_exist(root, "chain")) { + str = nftnl_jansson_parse_str(root, "chain", err); if (str == NULL) goto err; - nft_rule_attr_set_str(r, NFT_RULE_ATTR_CHAIN, str); + nftnl_rule_attr_set_str(r, NFTNL_RULE_ATTR_CHAIN, str); } - if (nft_jansson_node_exist(root, "handle")) { - if (nft_jansson_parse_val(root, "handle", NFT_TYPE_U64, &uval64, + if (nftnl_jansson_node_exist(root, "handle")) { + if (nftnl_jansson_parse_val(root, "handle", NFTNL_TYPE_U64, &uval64, err) < 0) goto err; - nft_rule_attr_set_u64(r, NFT_RULE_ATTR_HANDLE, uval64); + nftnl_rule_attr_set_u64(r, NFTNL_RULE_ATTR_HANDLE, uval64); } - if (nft_jansson_node_exist(root, "compat_proto") || - nft_jansson_node_exist(root, "compat_flags")) { - if (nft_jansson_parse_val(root, "compat_proto", NFT_TYPE_U32, + if (nftnl_jansson_node_exist(root, "compat_proto") || + nftnl_jansson_node_exist(root, "compat_flags")) { + if (nftnl_jansson_parse_val(root, "compat_proto", NFTNL_TYPE_U32, &uval32, err) < 0) goto err; - nft_rule_attr_set_u32(r, NFT_RULE_ATTR_COMPAT_PROTO, uval32); + nftnl_rule_attr_set_u32(r, NFTNL_RULE_ATTR_COMPAT_PROTO, uval32); - if (nft_jansson_parse_val(root, "compat_flags", NFT_TYPE_U32, + if (nftnl_jansson_parse_val(root, "compat_flags", NFTNL_TYPE_U32, &uval32, err) < 0) goto err; - nft_rule_attr_set_u32(r, NFT_RULE_ATTR_COMPAT_FLAGS, uval32); + nftnl_rule_attr_set_u32(r, NFTNL_RULE_ATTR_COMPAT_FLAGS, uval32); } - if (nft_jansson_node_exist(root, "position")) { - if (nft_jansson_parse_val(root, "position", NFT_TYPE_U64, + if (nftnl_jansson_node_exist(root, "position")) { + if (nftnl_jansson_parse_val(root, "position", NFTNL_TYPE_U64, &uval64, err) < 0) goto err; - nft_rule_attr_set_u64(r, NFT_RULE_ATTR_POSITION, uval64); + nftnl_rule_attr_set_u64(r, NFTNL_RULE_ATTR_POSITION, uval64); } array = json_object_get(root, "expr"); if (array == NULL) { - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; err->node_name = "expr"; goto err; } for (i = 0; i < json_array_size(array); ++i) { - e = nft_jansson_expr_parse(json_array_get(array, i), err, + e = nftnl_jansson_expr_parse(json_array_get(array, i), err, set_list); if (e == NULL) goto err; - nft_rule_add_expr(r, e); + nftnl_rule_add_expr(r, e); } return 0; @@ -563,23 +563,23 @@ err: } #endif -static int nft_rule_json_parse(struct nft_rule *r, const void *json, - struct nft_parse_err *err, - enum nft_parse_input input, - struct nft_set_list *set_list) +static int nftnl_rule_json_parse(struct nftnl_rule *r, const void *json, + struct nftnl_parse_err *err, + enum nftnl_parse_input input, + struct nftnl_set_list *set_list) { #ifdef JSON_PARSING json_t *tree; json_error_t error; int ret; - tree = nft_jansson_create_root(json, &error, err, input); + tree = nftnl_jansson_create_root(json, &error, err, input); if (tree == NULL) return -1; - ret = nft_jansson_parse_rule(r, tree, err, set_list); + ret = nftnl_jansson_parse_rule(r, tree, err, set_list); - nft_jansson_free_root(tree); + nftnl_jansson_free_root(tree); return ret; #else errno = EOPNOTSUPP; @@ -588,53 +588,53 @@ static int nft_rule_json_parse(struct nft_rule *r, const void *json, } #ifdef XML_PARSING -int nft_mxml_rule_parse(mxml_node_t *tree, struct nft_rule *r, - struct nft_parse_err *err, - struct nft_set_list *set_list) +int nftnl_mxml_rule_parse(mxml_node_t *tree, struct nftnl_rule *r, + struct nftnl_parse_err *err, + struct nftnl_set_list *set_list) { mxml_node_t *node; - struct nft_rule_expr *e; + struct nftnl_rule_expr *e; const char *table, *chain; int family; - family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + family = nftnl_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (family >= 0) - nft_rule_attr_set_u32(r, NFT_RULE_ATTR_FAMILY, family); + nftnl_rule_attr_set_u32(r, NFTNL_RULE_ATTR_FAMILY, family); - table = nft_mxml_str_parse(tree, "table", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + table = nftnl_mxml_str_parse(tree, "table", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (table != NULL) - nft_rule_attr_set_str(r, NFT_RULE_ATTR_TABLE, table); + nftnl_rule_attr_set_str(r, NFTNL_RULE_ATTR_TABLE, table); - chain = nft_mxml_str_parse(tree, "chain", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + chain = nftnl_mxml_str_parse(tree, "chain", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (chain != NULL) - nft_rule_attr_set_str(r, NFT_RULE_ATTR_CHAIN, chain); + nftnl_rule_attr_set_str(r, NFTNL_RULE_ATTR_CHAIN, chain); - if (nft_mxml_num_parse(tree, "handle", MXML_DESCEND_FIRST, BASE_DEC, - &r->handle, NFT_TYPE_U64, NFT_XML_MAND, err) >= 0) - r->flags |= (1 << NFT_RULE_ATTR_HANDLE); + if (nftnl_mxml_num_parse(tree, "handle", MXML_DESCEND_FIRST, BASE_DEC, + &r->handle, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) >= 0) + r->flags |= (1 << NFTNL_RULE_ATTR_HANDLE); - if (nft_mxml_num_parse(tree, "compat_proto", MXML_DESCEND_FIRST, - BASE_DEC, &r->compat.proto, NFT_TYPE_U32, - NFT_XML_OPT, err) >= 0) - r->flags |= (1 << NFT_RULE_ATTR_COMPAT_PROTO); + if (nftnl_mxml_num_parse(tree, "compat_proto", MXML_DESCEND_FIRST, + BASE_DEC, &r->compat.proto, NFTNL_TYPE_U32, + NFTNL_XML_OPT, err) >= 0) + r->flags |= (1 << NFTNL_RULE_ATTR_COMPAT_PROTO); - if (nft_mxml_num_parse(tree, "compat_flags", MXML_DESCEND_FIRST, - BASE_DEC, &r->compat.flags, NFT_TYPE_U32, - NFT_XML_OPT, err) >= 0) - r->flags |= (1 << NFT_RULE_ATTR_COMPAT_FLAGS); + if (nftnl_mxml_num_parse(tree, "compat_flags", MXML_DESCEND_FIRST, + BASE_DEC, &r->compat.flags, NFTNL_TYPE_U32, + NFTNL_XML_OPT, err) >= 0) + r->flags |= (1 << NFTNL_RULE_ATTR_COMPAT_FLAGS); - if (nft_rule_attr_is_set(r, NFT_RULE_ATTR_COMPAT_PROTO) != - nft_rule_attr_is_set(r, NFT_RULE_ATTR_COMPAT_FLAGS)) { + if (nftnl_rule_attr_is_set(r, NFTNL_RULE_ATTR_COMPAT_PROTO) != + nftnl_rule_attr_is_set(r, NFTNL_RULE_ATTR_COMPAT_FLAGS)) { errno = EINVAL; } - if (nft_mxml_num_parse(tree, "position", MXML_DESCEND_FIRST, - BASE_DEC, &r->position, NFT_TYPE_U64, - NFT_XML_OPT, err) >= 0) - r->flags |= (1 << NFT_RULE_ATTR_POSITION); + if (nftnl_mxml_num_parse(tree, "position", MXML_DESCEND_FIRST, + BASE_DEC, &r->position, NFTNL_TYPE_U64, + NFTNL_XML_OPT, err) >= 0) + r->flags |= (1 << NFTNL_RULE_ATTR_POSITION); /* Iterating over <expr> */ for (node = mxmlFindElement(tree, tree, "expr", "type", @@ -642,29 +642,29 @@ int nft_mxml_rule_parse(mxml_node_t *tree, struct nft_rule *r, node != NULL; node = mxmlFindElement(node, tree, "expr", "type", NULL, MXML_DESCEND)) { - e = nft_mxml_expr_parse(node, err, set_list); + e = nftnl_mxml_expr_parse(node, err, set_list); if (e == NULL) return -1; - nft_rule_add_expr(r, e); + nftnl_rule_add_expr(r, e); } return 0; } #endif -static int nft_rule_xml_parse(struct nft_rule *r, const void *xml, - struct nft_parse_err *err, - enum nft_parse_input input, - struct nft_set_list *set_list) +static int nftnl_rule_xml_parse(struct nftnl_rule *r, const void *xml, + struct nftnl_parse_err *err, + enum nftnl_parse_input input, + struct nftnl_set_list *set_list) { #ifdef XML_PARSING int ret; - mxml_node_t *tree = nft_mxml_build_tree(xml, "rule", err, input); + mxml_node_t *tree = nftnl_mxml_build_tree(xml, "rule", err, input); if (tree == NULL) return -1; - ret = nft_mxml_rule_parse(tree, r, err, set_list); + ret = nftnl_mxml_rule_parse(tree, r, err, set_list); mxmlDelete(tree); return ret; #else @@ -673,19 +673,19 @@ static int nft_rule_xml_parse(struct nft_rule *r, const void *xml, #endif } -static int nft_rule_do_parse(struct nft_rule *r, enum nft_parse_type type, - const void *data, struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_rule_do_parse(struct nftnl_rule *r, enum nftnl_parse_type type, + const void *data, struct nftnl_parse_err *err, + enum nftnl_parse_input input) { int ret; - struct nft_parse_err perr; + struct nftnl_parse_err perr; switch (type) { - case NFT_PARSE_XML: - ret = nft_rule_xml_parse(r, data, &perr, input, NULL); + case NFTNL_PARSE_XML: + ret = nftnl_rule_xml_parse(r, data, &perr, input, NULL); break; - case NFT_PARSE_JSON: - ret = nft_rule_json_parse(r, data, &perr, input, NULL); + case NFTNL_PARSE_JSON: + ret = nftnl_rule_json_parse(r, data, &perr, input, NULL); break; default: ret = -1; @@ -697,61 +697,61 @@ static int nft_rule_do_parse(struct nft_rule *r, enum nft_parse_type type, return ret; } -int nft_rule_parse(struct nft_rule *r, enum nft_parse_type type, - const char *data, struct nft_parse_err *err) +int nftnl_rule_parse(struct nftnl_rule *r, enum nftnl_parse_type type, + const char *data, struct nftnl_parse_err *err) { - return nft_rule_do_parse(r, type, data, err, NFT_PARSE_BUFFER); + return nftnl_rule_do_parse(r, type, data, err, NFTNL_PARSE_BUFFER); } EXPORT_SYMBOL(nftnl_rule_parse, nft_rule_parse); -int nft_rule_parse_file(struct nft_rule *r, enum nft_parse_type type, - FILE *fp, struct nft_parse_err *err) +int nftnl_rule_parse_file(struct nftnl_rule *r, enum nftnl_parse_type type, + FILE *fp, struct nftnl_parse_err *err) { - return nft_rule_do_parse(r, type, fp, err, NFT_PARSE_FILE); + return nftnl_rule_do_parse(r, type, fp, err, NFTNL_PARSE_FILE); } EXPORT_SYMBOL(nftnl_rule_parse_file, nft_rule_parse_file); -static int nft_rule_snprintf_json(char *buf, size_t size, struct nft_rule *r, +static int nftnl_rule_snprintf_json(char *buf, size_t size, struct nftnl_rule *r, uint32_t type, uint32_t flags) { int ret, len = size, offset = 0; - struct nft_rule_expr *expr; + struct nftnl_rule_expr *expr; ret = snprintf(buf, len, "{\"rule\":{"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (r->flags & (1 << NFT_RULE_ATTR_FAMILY)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_FAMILY)) { ret = snprintf(buf+offset, len, "\"family\":\"%s\",", - nft_family2str(r->family)); + nftnl_family2str(r->family)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_TABLE)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_TABLE)) { ret = snprintf(buf+offset, len, "\"table\":\"%s\",", r->table); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_CHAIN)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_CHAIN)) { ret = snprintf(buf+offset, len, "\"chain\":\"%s\",", r->chain); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_HANDLE)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_HANDLE)) { ret = snprintf(buf+offset, len, "\"handle\":%llu,", (unsigned long long)r->handle); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_COMPAT_PROTO) || - r->flags & (1 << NFT_RULE_ATTR_COMPAT_FLAGS)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_COMPAT_PROTO) || + r->flags & (1 << NFTNL_RULE_ATTR_COMPAT_FLAGS)) { ret = snprintf(buf+offset, len, "\"compat_flags\":%u," "\"compat_proto\":%u,", r->compat.flags, r->compat.proto); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_POSITION)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_POSITION)) { ret = snprintf(buf+offset, len, "\"position\":%"PRIu64",", r->position); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -789,33 +789,33 @@ static int nft_rule_snprintf_json(char *buf, size_t size, struct nft_rule *r, return offset; } -static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r, +static int nftnl_rule_snprintf_xml(char *buf, size_t size, struct nftnl_rule *r, uint32_t type, uint32_t flags) { int ret, len = size, offset = 0; - struct nft_rule_expr *expr; + struct nftnl_rule_expr *expr; ret = snprintf(buf, len, "<rule>"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (r->flags & (1 << NFT_RULE_ATTR_FAMILY)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_FAMILY)) { ret = snprintf(buf+offset, len, "<family>%s</family>", - nft_family2str(r->family)); + nftnl_family2str(r->family)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_TABLE)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_TABLE)) { ret = snprintf(buf+offset, len, "<table>%s</table>", r->table); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_CHAIN)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_CHAIN)) { ret = snprintf(buf+offset, len, "<chain>%s</chain>", r->chain); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_HANDLE)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_HANDLE)) { ret = snprintf(buf+offset, len, "<handle>%llu</handle>", (unsigned long long)r->handle); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -829,7 +829,7 @@ static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r, SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_POSITION)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_POSITION)) { ret = snprintf(buf+offset, len, "<position>%"PRIu64"</position>", r->position); @@ -841,7 +841,7 @@ static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r, "<expr type=\"%s\">", expr->ops->name); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_rule_expr_snprintf(buf+offset, len, expr, + ret = nftnl_rule_expr_snprintf(buf+offset, len, expr, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -855,36 +855,36 @@ static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r, return offset; } -static int nft_rule_snprintf_default(char *buf, size_t size, struct nft_rule *r, +static int nftnl_rule_snprintf_default(char *buf, size_t size, struct nftnl_rule *r, uint32_t type, uint32_t flags) { - struct nft_rule_expr *expr; + struct nftnl_rule_expr *expr; int ret, len = size, offset = 0, i; - if (r->flags & (1 << NFT_RULE_ATTR_FAMILY)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_FAMILY)) { ret = snprintf(buf+offset, len, "%s ", - nft_family2str(r->family)); + nftnl_family2str(r->family)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_TABLE)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_TABLE)) { ret = snprintf(buf+offset, len, "%s ", r->table); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_CHAIN)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_CHAIN)) { ret = snprintf(buf+offset, len, "%s ", r->chain); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_HANDLE)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_HANDLE)) { ret = snprintf(buf+offset, len, "%llu ", (unsigned long long)r->handle); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (r->flags & (1 << NFT_RULE_ATTR_POSITION)) { + if (r->flags & (1 << NFTNL_RULE_ATTR_POSITION)) { ret = snprintf(buf+offset, len, "%llu ", (unsigned long long)r->position); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -897,7 +897,7 @@ static int nft_rule_snprintf_default(char *buf, size_t size, struct nft_rule *r, ret = snprintf(buf+offset, len, " [ %s ", expr->ops->name); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_rule_expr_snprintf(buf+offset, len, expr, + ret = nftnl_rule_expr_snprintf(buf+offset, len, expr, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -925,28 +925,28 @@ static int nft_rule_snprintf_default(char *buf, size_t size, struct nft_rule *r, return offset; } -static int nft_rule_cmd_snprintf(char *buf, size_t size, struct nft_rule *r, +static int nftnl_rule_cmd_snprintf(char *buf, size_t size, struct nftnl_rule *r, uint32_t cmd, uint32_t type, uint32_t flags) { int ret, len = size, offset = 0; uint32_t inner_flags = flags; - inner_flags &= ~NFT_OF_EVENT_ANY; + inner_flags &= ~NFTNL_OF_EVENT_ANY; - ret = nft_cmd_header_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_header_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); switch(type) { - case NFT_OUTPUT_DEFAULT: - ret = nft_rule_snprintf_default(buf+offset, len, r, type, + case NFTNL_OUTPUT_DEFAULT: + ret = nftnl_rule_snprintf_default(buf+offset, len, r, type, inner_flags); break; - case NFT_OUTPUT_XML: - ret = nft_rule_snprintf_xml(buf+offset, len, r, type, + case NFTNL_OUTPUT_XML: + ret = nftnl_rule_snprintf_xml(buf+offset, len, r, type, inner_flags); break; - case NFT_OUTPUT_JSON: - ret = nft_rule_snprintf_json(buf+offset, len, r, type, + case NFTNL_OUTPUT_JSON: + ret = nftnl_rule_snprintf_json(buf+offset, len, r, type, inner_flags); break; default: @@ -955,40 +955,40 @@ static int nft_rule_cmd_snprintf(char *buf, size_t size, struct nft_rule *r, SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); return offset; } -int nft_rule_snprintf(char *buf, size_t size, struct nft_rule *r, +int nftnl_rule_snprintf(char *buf, size_t size, struct nftnl_rule *r, uint32_t type, uint32_t flags) { - return nft_rule_cmd_snprintf(buf, size, r, nft_flag2cmd(flags), type, + return nftnl_rule_cmd_snprintf(buf, size, r, nftnl_flag2cmd(flags), type, flags); } EXPORT_SYMBOL(nftnl_rule_snprintf, nft_rule_snprintf); -static inline int nft_rule_do_snprintf(char *buf, size_t size, void *r, +static inline int nftnl_rule_do_snprintf(char *buf, size_t size, void *r, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_rule_snprintf(buf, size, r, type, flags); + return nftnl_rule_snprintf(buf, size, r, type, flags); } -int nft_rule_fprintf(FILE *fp, struct nft_rule *r, uint32_t type, +int nftnl_rule_fprintf(FILE *fp, struct nftnl_rule *r, uint32_t type, uint32_t flags) { - return nft_fprintf(fp, r, NFT_CMD_UNSPEC, type, flags, - nft_rule_do_snprintf); + return nftnl_fprintf(fp, r, NFTNL_CMD_UNSPEC, type, flags, + nftnl_rule_do_snprintf); } EXPORT_SYMBOL(nftnl_rule_fprintf, nft_rule_fprintf); -int nft_rule_expr_foreach(struct nft_rule *r, - int (*cb)(struct nft_rule_expr *e, void *data), +int nftnl_rule_expr_foreach(struct nftnl_rule *r, + int (*cb)(struct nftnl_rule_expr *e, void *data), void *data) { - struct nft_rule_expr *cur, *tmp; + struct nftnl_rule_expr *cur, *tmp; int ret; list_for_each_entry_safe(cur, tmp, &r->expr_list, head) { @@ -1000,16 +1000,16 @@ int nft_rule_expr_foreach(struct nft_rule *r, } EXPORT_SYMBOL(nftnl_rule_expr_foreach, nft_rule_expr_foreach); -struct nft_rule_expr_iter { - struct nft_rule *r; - struct nft_rule_expr *cur; +struct nftnl_rule_expr_iter { + struct nftnl_rule *r; + struct nftnl_rule_expr *cur; }; -struct nft_rule_expr_iter *nft_rule_expr_iter_create(struct nft_rule *r) +struct nftnl_rule_expr_iter *nftnl_rule_expr_iter_create(struct nftnl_rule *r) { - struct nft_rule_expr_iter *iter; + struct nftnl_rule_expr_iter *iter; - iter = calloc(1, sizeof(struct nft_rule_expr_iter)); + iter = calloc(1, sizeof(struct nftnl_rule_expr_iter)); if (iter == NULL) return NULL; @@ -1017,22 +1017,22 @@ struct nft_rule_expr_iter *nft_rule_expr_iter_create(struct nft_rule *r) if (list_empty(&r->expr_list)) iter->cur = NULL; else - iter->cur = list_entry(r->expr_list.next, struct nft_rule_expr, + iter->cur = list_entry(r->expr_list.next, struct nftnl_rule_expr, head); return iter; } EXPORT_SYMBOL(nftnl_rule_expr_iter_create, nft_rule_expr_iter_create); -struct nft_rule_expr *nft_rule_expr_iter_next(struct nft_rule_expr_iter *iter) +struct nftnl_rule_expr *nftnl_rule_expr_iter_next(struct nftnl_rule_expr_iter *iter) { - struct nft_rule_expr *expr = iter->cur; + struct nftnl_rule_expr *expr = iter->cur; if (expr == NULL) return NULL; /* get next expression, if any */ - iter->cur = list_entry(iter->cur->head.next, struct nft_rule_expr, head); + iter->cur = list_entry(iter->cur->head.next, struct nftnl_rule_expr, head); if (&iter->cur->head == iter->r->expr_list.next) return NULL; @@ -1040,21 +1040,21 @@ struct nft_rule_expr *nft_rule_expr_iter_next(struct nft_rule_expr_iter *iter) } EXPORT_SYMBOL(nftnl_rule_expr_iter_next, nft_rule_expr_iter_next); -void nft_rule_expr_iter_destroy(struct nft_rule_expr_iter *iter) +void nftnl_rule_expr_iter_destroy(struct nftnl_rule_expr_iter *iter) { xfree(iter); } EXPORT_SYMBOL(nftnl_rule_expr_iter_destroy, nft_rule_expr_iter_destroy); -struct nft_rule_list { +struct nftnl_rule_list { struct list_head list; }; -struct nft_rule_list *nft_rule_list_alloc(void) +struct nftnl_rule_list *nftnl_rule_list_alloc(void) { - struct nft_rule_list *list; + struct nftnl_rule_list *list; - list = calloc(1, sizeof(struct nft_rule_list)); + list = calloc(1, sizeof(struct nftnl_rule_list)); if (list == NULL) return NULL; @@ -1064,47 +1064,47 @@ struct nft_rule_list *nft_rule_list_alloc(void) } EXPORT_SYMBOL(nftnl_rule_list_alloc, nft_rule_list_alloc); -void nft_rule_list_free(struct nft_rule_list *list) +void nftnl_rule_list_free(struct nftnl_rule_list *list) { - struct nft_rule *r, *tmp; + struct nftnl_rule *r, *tmp; list_for_each_entry_safe(r, tmp, &list->list, head) { list_del(&r->head); - nft_rule_free(r); + nftnl_rule_free(r); } xfree(list); } EXPORT_SYMBOL(nftnl_rule_list_free, nft_rule_list_free); -int nft_rule_list_is_empty(struct nft_rule_list *list) +int nftnl_rule_list_is_empty(struct nftnl_rule_list *list) { return list_empty(&list->list); } EXPORT_SYMBOL(nftnl_rule_list_is_empty, nft_rule_list_is_empty); -void nft_rule_list_add(struct nft_rule *r, struct nft_rule_list *list) +void nftnl_rule_list_add(struct nftnl_rule *r, struct nftnl_rule_list *list) { list_add(&r->head, &list->list); } EXPORT_SYMBOL(nftnl_rule_list_add, nft_rule_list_add); -void nft_rule_list_add_tail(struct nft_rule *r, struct nft_rule_list *list) +void nftnl_rule_list_add_tail(struct nftnl_rule *r, struct nftnl_rule_list *list) { list_add_tail(&r->head, &list->list); } EXPORT_SYMBOL(nftnl_rule_list_add_tail, nft_rule_list_add_tail); -void nft_rule_list_del(struct nft_rule *r) +void nftnl_rule_list_del(struct nftnl_rule *r) { list_del(&r->head); } EXPORT_SYMBOL(nftnl_rule_list_del, nft_rule_list_del); -int nft_rule_list_foreach(struct nft_rule_list *rule_list, - int (*cb)(struct nft_rule *r, void *data), +int nftnl_rule_list_foreach(struct nftnl_rule_list *rule_list, + int (*cb)(struct nftnl_rule *r, void *data), void *data) { - struct nft_rule *cur, *tmp; + struct nftnl_rule *cur, *tmp; int ret; list_for_each_entry_safe(cur, tmp, &rule_list->list, head) { @@ -1116,44 +1116,44 @@ int nft_rule_list_foreach(struct nft_rule_list *rule_list, } EXPORT_SYMBOL(nftnl_rule_list_foreach, nft_rule_list_foreach); -struct nft_rule_list_iter { - struct nft_rule_list *list; - struct nft_rule *cur; +struct nftnl_rule_list_iter { + struct nftnl_rule_list *list; + struct nftnl_rule *cur; }; -struct nft_rule_list_iter *nft_rule_list_iter_create(struct nft_rule_list *l) +struct nftnl_rule_list_iter *nftnl_rule_list_iter_create(struct nftnl_rule_list *l) { - struct nft_rule_list_iter *iter; + struct nftnl_rule_list_iter *iter; - iter = calloc(1, sizeof(struct nft_rule_list_iter)); + iter = calloc(1, sizeof(struct nftnl_rule_list_iter)); if (iter == NULL) return NULL; iter->list = l; - if (nft_rule_list_is_empty(l)) + if (nftnl_rule_list_is_empty(l)) iter->cur = NULL; else - iter->cur = list_entry(l->list.next, struct nft_rule, head); + iter->cur = list_entry(l->list.next, struct nftnl_rule, head); return iter; } EXPORT_SYMBOL(nftnl_rule_list_iter_create, nft_rule_list_iter_create); -struct nft_rule *nft_rule_list_iter_cur(struct nft_rule_list_iter *iter) +struct nftnl_rule *nftnl_rule_list_iter_cur(struct nftnl_rule_list_iter *iter) { return iter->cur; } EXPORT_SYMBOL(nftnl_rule_list_iter_cur, nft_rule_list_iter_cur); -struct nft_rule *nft_rule_list_iter_next(struct nft_rule_list_iter *iter) +struct nftnl_rule *nftnl_rule_list_iter_next(struct nftnl_rule_list_iter *iter) { - struct nft_rule *r = iter->cur; + struct nftnl_rule *r = iter->cur; if (r == NULL) return NULL; /* get next rule, if any */ - iter->cur = list_entry(iter->cur->head.next, struct nft_rule, head); + iter->cur = list_entry(iter->cur->head.next, struct nftnl_rule, head); if (&iter->cur->head == iter->list->list.next) return NULL; @@ -1161,7 +1161,7 @@ struct nft_rule *nft_rule_list_iter_next(struct nft_rule_list_iter *iter) } EXPORT_SYMBOL(nftnl_rule_list_iter_next, nft_rule_list_iter_next); -void nft_rule_list_iter_destroy(struct nft_rule_list_iter *iter) +void nftnl_rule_list_iter_destroy(struct nftnl_rule_list_iter *iter) { xfree(iter); } diff --git a/src/ruleset.c b/src/ruleset.c index 42fe9e6..969b862 100644 --- a/src/ruleset.c +++ b/src/ruleset.c @@ -23,24 +23,24 @@ #include <libnftnl/set.h> #include <libnftnl/rule.h> -struct nft_ruleset { - struct nft_table_list *table_list; - struct nft_chain_list *chain_list; - struct nft_set_list *set_list; - struct nft_rule_list *rule_list; +struct nftnl_ruleset { + struct nftnl_table_list *table_list; + struct nftnl_chain_list *chain_list; + struct nftnl_set_list *set_list; + struct nftnl_rule_list *rule_list; uint16_t flags; }; -struct nft_parse_ctx { - enum nft_cmd_type cmd; - enum nft_ruleset_type type; +struct nftnl_parse_ctx { + enum nftnl_cmd_type cmd; + enum nftnl_ruleset_type type; union { - struct nft_table *table; - struct nft_chain *chain; - struct nft_rule *rule; - struct nft_set *set; - struct nft_set_elem *set_elem; + struct nftnl_table *table; + struct nftnl_chain *chain; + struct nftnl_rule *rule; + struct nftnl_set *set; + struct nftnl_set_elem *set_elem; }; void *data; @@ -52,58 +52,58 @@ struct nft_parse_ctx { uint32_t format; uint32_t set_id; - struct nft_set_list *set_list; + struct nftnl_set_list *set_list; - int (*cb)(const struct nft_parse_ctx *ctx); + int (*cb)(const struct nftnl_parse_ctx *ctx); uint16_t flags; }; -struct nft_ruleset *nft_ruleset_alloc(void) +struct nftnl_ruleset *nftnl_ruleset_alloc(void) { - return calloc(1, sizeof(struct nft_ruleset)); + return calloc(1, sizeof(struct nftnl_ruleset)); } EXPORT_SYMBOL(nftnl_ruleset_alloc, nft_ruleset_alloc); -void nft_ruleset_free(struct nft_ruleset *r) +void nftnl_ruleset_free(struct nftnl_ruleset *r) { - if (r->flags & (1 << NFT_RULESET_ATTR_TABLELIST)) - nft_table_list_free(r->table_list); - if (r->flags & (1 << NFT_RULESET_ATTR_CHAINLIST)) - nft_chain_list_free(r->chain_list); - if (r->flags & (1 << NFT_RULESET_ATTR_SETLIST)) - nft_set_list_free(r->set_list); - if (r->flags & (1 << NFT_RULESET_ATTR_RULELIST)) - nft_rule_list_free(r->rule_list); + if (r->flags & (1 << NFTNL_RULESET_ATTR_TABLELIST)) + nftnl_table_list_free(r->table_list); + if (r->flags & (1 << NFTNL_RULESET_ATTR_CHAINLIST)) + nftnl_chain_list_free(r->chain_list); + if (r->flags & (1 << NFTNL_RULESET_ATTR_SETLIST)) + nftnl_set_list_free(r->set_list); + if (r->flags & (1 << NFTNL_RULESET_ATTR_RULELIST)) + nftnl_rule_list_free(r->rule_list); xfree(r); } EXPORT_SYMBOL(nftnl_ruleset_free, nft_ruleset_free); -bool nft_ruleset_attr_is_set(const struct nft_ruleset *r, uint16_t attr) +bool nftnl_ruleset_attr_is_set(const struct nftnl_ruleset *r, uint16_t attr) { return r->flags & (1 << attr); } EXPORT_SYMBOL(nftnl_ruleset_attr_is_set, nft_ruleset_attr_is_set); -void nft_ruleset_attr_unset(struct nft_ruleset *r, uint16_t attr) +void nftnl_ruleset_attr_unset(struct nftnl_ruleset *r, uint16_t attr) { if (!(r->flags & (1 << attr))) return; switch (attr) { - case NFT_RULESET_ATTR_TABLELIST: - nft_table_list_free(r->table_list); + case NFTNL_RULESET_ATTR_TABLELIST: + nftnl_table_list_free(r->table_list); r->table_list = NULL; break; - case NFT_RULESET_ATTR_CHAINLIST: - nft_chain_list_free(r->chain_list); + case NFTNL_RULESET_ATTR_CHAINLIST: + nftnl_chain_list_free(r->chain_list); r->chain_list = NULL; break; - case NFT_RULESET_ATTR_SETLIST: - nft_set_list_free(r->set_list); + case NFTNL_RULESET_ATTR_SETLIST: + nftnl_set_list_free(r->set_list); r->set_list = NULL; break; - case NFT_RULESET_ATTR_RULELIST: - nft_rule_list_free(r->rule_list); + case NFTNL_RULESET_ATTR_RULELIST: + nftnl_rule_list_free(r->rule_list); r->rule_list = NULL; break; } @@ -111,23 +111,23 @@ void nft_ruleset_attr_unset(struct nft_ruleset *r, uint16_t attr) } EXPORT_SYMBOL(nftnl_ruleset_attr_unset, nft_ruleset_attr_unset); -void nft_ruleset_attr_set(struct nft_ruleset *r, uint16_t attr, void *data) +void nftnl_ruleset_attr_set(struct nftnl_ruleset *r, uint16_t attr, void *data) { switch (attr) { - case NFT_RULESET_ATTR_TABLELIST: - nft_ruleset_attr_unset(r, NFT_RULESET_ATTR_TABLELIST); + case NFTNL_RULESET_ATTR_TABLELIST: + nftnl_ruleset_attr_unset(r, NFTNL_RULESET_ATTR_TABLELIST); r->table_list = data; break; - case NFT_RULESET_ATTR_CHAINLIST: - nft_ruleset_attr_unset(r, NFT_RULESET_ATTR_CHAINLIST); + case NFTNL_RULESET_ATTR_CHAINLIST: + nftnl_ruleset_attr_unset(r, NFTNL_RULESET_ATTR_CHAINLIST); r->chain_list = data; break; - case NFT_RULESET_ATTR_SETLIST: - nft_ruleset_attr_unset(r, NFT_RULESET_ATTR_SETLIST); + case NFTNL_RULESET_ATTR_SETLIST: + nftnl_ruleset_attr_unset(r, NFTNL_RULESET_ATTR_SETLIST); r->set_list = data; break; - case NFT_RULESET_ATTR_RULELIST: - nft_ruleset_attr_unset(r, NFT_RULESET_ATTR_RULELIST); + case NFTNL_RULESET_ATTR_RULELIST: + nftnl_ruleset_attr_unset(r, NFTNL_RULESET_ATTR_RULELIST); r->rule_list = data; break; default: @@ -137,19 +137,19 @@ void nft_ruleset_attr_set(struct nft_ruleset *r, uint16_t attr, void *data) } EXPORT_SYMBOL(nftnl_ruleset_attr_set, nft_ruleset_attr_set); -void *nft_ruleset_attr_get(const struct nft_ruleset *r, uint16_t attr) +void *nftnl_ruleset_attr_get(const struct nftnl_ruleset *r, uint16_t attr) { if (!(r->flags & (1 << attr))) return NULL; switch (attr) { - case NFT_RULESET_ATTR_TABLELIST: + case NFTNL_RULESET_ATTR_TABLELIST: return r->table_list; - case NFT_RULESET_ATTR_CHAINLIST: + case NFTNL_RULESET_ATTR_CHAINLIST: return r->chain_list; - case NFT_RULESET_ATTR_SETLIST: + case NFTNL_RULESET_ATTR_SETLIST: return r->set_list; - case NFT_RULESET_ATTR_RULELIST: + case NFTNL_RULESET_ATTR_RULELIST: return r->rule_list; default: return NULL; @@ -157,54 +157,54 @@ void *nft_ruleset_attr_get(const struct nft_ruleset *r, uint16_t attr) } EXPORT_SYMBOL(nftnl_ruleset_attr_get, nft_ruleset_attr_get); -void nft_ruleset_ctx_free(const struct nft_parse_ctx *ctx) +void nftnl_ruleset_ctx_free(const struct nftnl_parse_ctx *ctx) { switch (ctx->type) { - case NFT_RULESET_TABLE: - nft_table_free(ctx->table); + case NFTNL_RULESET_TABLE: + nftnl_table_free(ctx->table); break; - case NFT_RULESET_CHAIN: - nft_chain_free(ctx->chain); + case NFTNL_RULESET_CHAIN: + nftnl_chain_free(ctx->chain); break; - case NFT_RULESET_RULE: - nft_rule_free(ctx->rule); + case NFTNL_RULESET_RULE: + nftnl_rule_free(ctx->rule); break; - case NFT_RULESET_SET: - case NFT_RULESET_SET_ELEMS: - nft_set_free(ctx->set); + case NFTNL_RULESET_SET: + case NFTNL_RULESET_SET_ELEMS: + nftnl_set_free(ctx->set); break; - case NFT_RULESET_RULESET: - case NFT_RULESET_UNSPEC: + case NFTNL_RULESET_RULESET: + case NFTNL_RULESET_UNSPEC: break; } } EXPORT_SYMBOL(nftnl_ruleset_ctx_free, nft_ruleset_ctx_free); -bool nft_ruleset_ctx_is_set(const struct nft_parse_ctx *ctx, uint16_t attr) +bool nftnl_ruleset_ctx_is_set(const struct nftnl_parse_ctx *ctx, uint16_t attr) { return ctx->flags & (1 << attr); } EXPORT_SYMBOL(nftnl_ruleset_ctx_is_set, nft_ruleset_ctx_is_set); -void *nft_ruleset_ctx_get(const struct nft_parse_ctx *ctx, uint16_t attr) +void *nftnl_ruleset_ctx_get(const struct nftnl_parse_ctx *ctx, uint16_t attr) { if (!(ctx->flags & (1 << attr))) return NULL; switch (attr) { - case NFT_RULESET_CTX_CMD: + case NFTNL_RULESET_CTX_CMD: return (void *)&ctx->cmd; - case NFT_RULESET_CTX_TYPE: + case NFTNL_RULESET_CTX_TYPE: return (void *)&ctx->type; - case NFT_RULESET_CTX_TABLE: + case NFTNL_RULESET_CTX_TABLE: return ctx->table; - case NFT_RULESET_CTX_CHAIN: + case NFTNL_RULESET_CTX_CHAIN: return ctx->chain; - case NFT_RULESET_CTX_RULE: + case NFTNL_RULESET_CTX_RULE: return ctx->rule; - case NFT_RULESET_CTX_SET: + case NFTNL_RULESET_CTX_SET: return ctx->set; - case NFT_RULESET_CTX_DATA: + case NFTNL_RULESET_CTX_DATA: return ctx->data; default: return NULL; @@ -212,68 +212,68 @@ void *nft_ruleset_ctx_get(const struct nft_parse_ctx *ctx, uint16_t attr) } EXPORT_SYMBOL(nftnl_ruleset_ctx_get, nft_ruleset_ctx_get); -uint32_t nft_ruleset_ctx_get_u32(const struct nft_parse_ctx *ctx, uint16_t attr) +uint32_t nftnl_ruleset_ctx_get_u32(const struct nftnl_parse_ctx *ctx, uint16_t attr) { - const void *ret = nft_ruleset_ctx_get(ctx, attr); + const void *ret = nftnl_ruleset_ctx_get(ctx, attr); return ret == NULL ? 0 : *((uint32_t *)ret); } EXPORT_SYMBOL(nftnl_ruleset_ctx_get_u32, nft_ruleset_ctx_get_u32); #if defined(JSON_PARSING) || defined(XML_PARSING) -static void nft_ruleset_ctx_set(struct nft_parse_ctx *ctx, uint16_t attr, +static void nftnl_ruleset_ctx_set(struct nftnl_parse_ctx *ctx, uint16_t attr, void *data) { switch (attr) { - case NFT_RULESET_CTX_CMD: + case NFTNL_RULESET_CTX_CMD: ctx->cmd = *((uint32_t *)data); break; - case NFT_RULESET_CTX_TYPE: + case NFTNL_RULESET_CTX_TYPE: ctx->type = *((uint32_t *)data); break; - case NFT_RULESET_CTX_TABLE: + case NFTNL_RULESET_CTX_TABLE: ctx->table = data; break; - case NFT_RULESET_CTX_CHAIN: + case NFTNL_RULESET_CTX_CHAIN: ctx->chain = data; break; - case NFT_RULESET_CTX_RULE: + case NFTNL_RULESET_CTX_RULE: ctx->rule = data; break; - case NFT_RULESET_CTX_SET: + case NFTNL_RULESET_CTX_SET: ctx->set = data; break; - case NFT_RULESET_CTX_DATA: + case NFTNL_RULESET_CTX_DATA: ctx->data = data; break; } ctx->flags |= (1 << attr); } -static void nft_ruleset_ctx_set_u32(struct nft_parse_ctx *ctx, uint16_t attr, +static void nftnl_ruleset_ctx_set_u32(struct nftnl_parse_ctx *ctx, uint16_t attr, uint32_t val) { - nft_ruleset_ctx_set(ctx, attr, &val); + nftnl_ruleset_ctx_set(ctx, attr, &val); } -static int nft_ruleset_parse_tables(struct nft_parse_ctx *ctx, - struct nft_parse_err *err) +static int nftnl_ruleset_parse_tables(struct nftnl_parse_ctx *ctx, + struct nftnl_parse_err *err) { - struct nft_table *table; + struct nftnl_table *table; - table = nft_table_alloc(); + table = nftnl_table_alloc(); if (table == NULL) return -1; switch (ctx->format) { - case NFT_OUTPUT_JSON: + case NFTNL_OUTPUT_JSON: #ifdef JSON_PARSING - if (nft_jansson_parse_table(table, ctx->json, err) < 0) + if (nftnl_jansson_parse_table(table, ctx->json, err) < 0) goto err; #endif break; - case NFT_OUTPUT_XML: + case NFTNL_OUTPUT_XML: #ifdef XML_PARSING - if (nft_mxml_table_parse(ctx->xml, table, err) < 0) + if (nftnl_mxml_table_parse(ctx->xml, table, err) < 0) goto err; #endif break; @@ -282,36 +282,36 @@ static int nft_ruleset_parse_tables(struct nft_parse_ctx *ctx, goto err; } - nft_ruleset_ctx_set_u32(ctx, NFT_RULESET_CTX_TYPE, NFT_RULESET_TABLE); - nft_ruleset_ctx_set(ctx, NFT_RULESET_CTX_TABLE, table); + nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, NFTNL_RULESET_TABLE); + nftnl_ruleset_ctx_set(ctx, NFTNL_RULESET_CTX_TABLE, table); if (ctx->cb(ctx) < 0) goto err; return 0; err: - nft_table_free(table); + nftnl_table_free(table); return -1; } -static int nft_ruleset_parse_chains(struct nft_parse_ctx *ctx, - struct nft_parse_err *err) +static int nftnl_ruleset_parse_chains(struct nftnl_parse_ctx *ctx, + struct nftnl_parse_err *err) { - struct nft_chain *chain; + struct nftnl_chain *chain; - chain = nft_chain_alloc(); + chain = nftnl_chain_alloc(); if (chain == NULL) return -1; switch (ctx->format) { - case NFT_OUTPUT_JSON: + case NFTNL_OUTPUT_JSON: #ifdef JSON_PARSING - if (nft_jansson_parse_chain(chain, ctx->json, err) < 0) + if (nftnl_jansson_parse_chain(chain, ctx->json, err) < 0) goto err; #endif break; - case NFT_OUTPUT_XML: + case NFTNL_OUTPUT_XML: #ifdef XML_PARSING - if (nft_mxml_chain_parse(ctx->xml, chain, err) < 0) + if (nftnl_mxml_chain_parse(ctx->xml, chain, err) < 0) goto err; #endif break; @@ -320,33 +320,33 @@ static int nft_ruleset_parse_chains(struct nft_parse_ctx *ctx, goto err; } - nft_ruleset_ctx_set_u32(ctx, NFT_RULESET_CTX_TYPE, NFT_RULESET_CHAIN); - nft_ruleset_ctx_set(ctx, NFT_RULESET_CTX_CHAIN, chain); + nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, NFTNL_RULESET_CHAIN); + nftnl_ruleset_ctx_set(ctx, NFTNL_RULESET_CTX_CHAIN, chain); if (ctx->cb(ctx) < 0) goto err; return 0; err: - nft_chain_free(chain); + nftnl_chain_free(chain); return -1; } -static int nft_ruleset_parse_set(struct nft_parse_ctx *ctx, - struct nft_set *set, uint32_t type, - struct nft_parse_err *err) +static int nftnl_ruleset_parse_set(struct nftnl_parse_ctx *ctx, + struct nftnl_set *set, uint32_t type, + struct nftnl_parse_err *err) { - struct nft_set *newset; + struct nftnl_set *newset; - nft_set_attr_set_u32(set, NFT_SET_ATTR_ID, ctx->set_id++); + nftnl_set_attr_set_u32(set, NFTNL_SET_ATTR_ID, ctx->set_id++); - newset = nft_set_clone(set); + newset = nftnl_set_clone(set); if (newset == NULL) goto err; - nft_set_list_add_tail(newset, ctx->set_list); + nftnl_set_list_add_tail(newset, ctx->set_list); - nft_ruleset_ctx_set_u32(ctx, NFT_RULESET_CTX_TYPE, type); - nft_ruleset_ctx_set(ctx, NFT_RULESET_CTX_SET, set); + nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, type); + nftnl_ruleset_ctx_set(ctx, NFTNL_RULESET_CTX_SET, set); if (ctx->cb(ctx) < 0) goto err; @@ -355,25 +355,25 @@ err: return -1; } -static int nft_ruleset_parse_set_elems(struct nft_parse_ctx *ctx, - struct nft_parse_err *err) +static int nftnl_ruleset_parse_set_elems(struct nftnl_parse_ctx *ctx, + struct nftnl_parse_err *err) { - struct nft_set *set; + struct nftnl_set *set; - set = nft_set_alloc(); + set = nftnl_set_alloc(); if (set == NULL) return -1; switch (ctx->format) { - case NFT_OUTPUT_JSON: + case NFTNL_OUTPUT_JSON: #ifdef JSON_PARSING - if (nft_jansson_parse_elem(set, ctx->json, err) < 0) + if (nftnl_jansson_parse_elem(set, ctx->json, err) < 0) goto err; #endif break; - case NFT_OUTPUT_XML: + case NFTNL_OUTPUT_XML: #ifdef XML_PARSING - if (nft_mxml_set_parse(ctx->xml, set, err) < 0) + if (nftnl_mxml_set_parse(ctx->xml, set, err) < 0) goto err; #endif break; @@ -382,34 +382,34 @@ static int nft_ruleset_parse_set_elems(struct nft_parse_ctx *ctx, goto err; } - if (nft_ruleset_parse_set(ctx, set, NFT_RULESET_SET_ELEMS, err) < 0) + if (nftnl_ruleset_parse_set(ctx, set, NFTNL_RULESET_SET_ELEMS, err) < 0) goto err; return 0; err: - nft_set_free(set); + nftnl_set_free(set); return -1; } -static int nft_ruleset_parse_sets(struct nft_parse_ctx *ctx, - struct nft_parse_err *err) +static int nftnl_ruleset_parse_sets(struct nftnl_parse_ctx *ctx, + struct nftnl_parse_err *err) { - struct nft_set *set; + struct nftnl_set *set; - set = nft_set_alloc(); + set = nftnl_set_alloc(); if (set == NULL) return -1; switch (ctx->format) { - case NFT_OUTPUT_JSON: + case NFTNL_OUTPUT_JSON: #ifdef JSON_PARSING - if (nft_jansson_parse_set(set, ctx->json, err) < 0) + if (nftnl_jansson_parse_set(set, ctx->json, err) < 0) goto err; #endif break; - case NFT_OUTPUT_XML: + case NFTNL_OUTPUT_XML: #ifdef XML_PARSING - if (nft_mxml_set_parse(ctx->xml, set, err) < 0) + if (nftnl_mxml_set_parse(ctx->xml, set, err) < 0) goto err; #endif break; @@ -418,35 +418,35 @@ static int nft_ruleset_parse_sets(struct nft_parse_ctx *ctx, goto err; } - if (nft_ruleset_parse_set(ctx, set, NFT_RULESET_SET, err) < 0) + if (nftnl_ruleset_parse_set(ctx, set, NFTNL_RULESET_SET, err) < 0) goto err; return 0; err: - nft_set_free(set); + nftnl_set_free(set); return -1; } -static int nft_ruleset_parse_rules(struct nft_parse_ctx *ctx, - struct nft_parse_err *err) +static int nftnl_ruleset_parse_rules(struct nftnl_parse_ctx *ctx, + struct nftnl_parse_err *err) { - struct nft_rule *rule; + struct nftnl_rule *rule; - rule = nft_rule_alloc(); + rule = nftnl_rule_alloc(); if (rule == NULL) return -1; switch (ctx->format) { - case NFT_OUTPUT_JSON: + case NFTNL_OUTPUT_JSON: #ifdef JSON_PARSING - if (nft_jansson_parse_rule(rule, ctx->json, err, + if (nftnl_jansson_parse_rule(rule, ctx->json, err, ctx->set_list) < 0) goto err; #endif break; - case NFT_OUTPUT_XML: + case NFTNL_OUTPUT_XML: #ifdef XML_PARSING - if (nft_mxml_rule_parse(ctx->xml, rule, err, ctx->set_list) < 0) + if (nftnl_mxml_rule_parse(ctx->xml, rule, err, ctx->set_list) < 0) goto err; #endif break; @@ -455,21 +455,21 @@ static int nft_ruleset_parse_rules(struct nft_parse_ctx *ctx, goto err; } - nft_ruleset_ctx_set_u32(ctx, NFT_RULESET_CTX_TYPE, NFT_RULESET_RULE); - nft_ruleset_ctx_set(ctx, NFT_RULESET_CTX_RULE, rule); + nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, NFTNL_RULESET_RULE); + nftnl_ruleset_ctx_set(ctx, NFTNL_RULESET_CTX_RULE, rule); if (ctx->cb(ctx) < 0) goto err; return 0; err: - nft_rule_free(rule); + nftnl_rule_free(rule); return -1; } #endif #ifdef JSON_PARSING -static int nft_ruleset_json_parse_ruleset(struct nft_parse_ctx *ctx, - struct nft_parse_err *err) +static int nftnl_ruleset_json_parse_ruleset(struct nftnl_parse_ctx *ctx, + struct nftnl_parse_err *err) { json_t *node, *array = ctx->json; int len, i, ret; @@ -483,16 +483,16 @@ static int nft_ruleset_json_parse_ruleset(struct nft_parse_ctx *ctx, } ctx->json = node; - if (nft_jansson_node_exist(node, "table")) - ret = nft_ruleset_parse_tables(ctx, err); - else if (nft_jansson_node_exist(node, "chain")) - ret = nft_ruleset_parse_chains(ctx, err); - else if (nft_jansson_node_exist(node, "set")) - ret = nft_ruleset_parse_sets(ctx, err); - else if (nft_jansson_node_exist(node, "rule")) - ret = nft_ruleset_parse_rules(ctx, err); - else if (nft_jansson_node_exist(node, "element")) - ret = nft_ruleset_parse_set_elems(ctx, err); + if (nftnl_jansson_node_exist(node, "table")) + ret = nftnl_ruleset_parse_tables(ctx, err); + else if (nftnl_jansson_node_exist(node, "chain")) + ret = nftnl_ruleset_parse_chains(ctx, err); + else if (nftnl_jansson_node_exist(node, "set")) + ret = nftnl_ruleset_parse_sets(ctx, err); + else if (nftnl_jansson_node_exist(node, "rule")) + ret = nftnl_ruleset_parse_rules(ctx, err); + else if (nftnl_jansson_node_exist(node, "element")) + ret = nftnl_ruleset_parse_set_elems(ctx, err); else return -1; @@ -500,9 +500,9 @@ static int nft_ruleset_json_parse_ruleset(struct nft_parse_ctx *ctx, return ret; } - if (len == 0 && ctx->cmd == NFT_CMD_FLUSH) { - nft_ruleset_ctx_set_u32(ctx, NFT_RULESET_CTX_TYPE, - NFT_RULESET_RULESET); + if (len == 0 && ctx->cmd == NFTNL_CMD_FLUSH) { + nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, + NFTNL_RULESET_RULESET); if (ctx->cb(ctx) < 0) return -1; } @@ -510,28 +510,28 @@ static int nft_ruleset_json_parse_ruleset(struct nft_parse_ctx *ctx, return 0; } -static int nft_ruleset_json_parse_cmd(const char *cmd, - struct nft_parse_err *err, - struct nft_parse_ctx *ctx) +static int nftnl_ruleset_json_parse_cmd(const char *cmd, + struct nftnl_parse_err *err, + struct nftnl_parse_ctx *ctx) { uint32_t cmdnum; json_t *nodecmd; - cmdnum = nft_str2cmd(cmd); - if (cmdnum == NFT_CMD_UNSPEC) { - err->error = NFT_PARSE_EMISSINGNODE; + cmdnum = nftnl_str2cmd(cmd); + if (cmdnum == NFTNL_CMD_UNSPEC) { + err->error = NFTNL_PARSE_EMISSINGNODE; err->node_name = strdup(cmd); return -1; } - nft_ruleset_ctx_set_u32(ctx, NFT_RULESET_CTX_CMD, cmdnum); + nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_CMD, cmdnum); nodecmd = json_object_get(ctx->json, cmd); if (nodecmd == NULL) return 0; ctx->json = nodecmd; - if (nft_ruleset_json_parse_ruleset(ctx, err) != 0) + if (nftnl_ruleset_json_parse_ruleset(ctx, err) != 0) goto err; return 0; @@ -540,30 +540,30 @@ err: } #endif -static int nft_ruleset_json_parse(const void *json, - struct nft_parse_err *err, - enum nft_parse_input input, - enum nft_parse_type type, void *arg, - int (*cb)(const struct nft_parse_ctx *ctx)) +static int nftnl_ruleset_json_parse(const void *json, + struct nftnl_parse_err *err, + enum nftnl_parse_input input, + enum nftnl_parse_type type, void *arg, + int (*cb)(const struct nftnl_parse_ctx *ctx)) { #ifdef JSON_PARSING json_t *root, *array, *node; json_error_t error; int i, len; const char *key; - struct nft_parse_ctx ctx; + struct nftnl_parse_ctx ctx; ctx.cb = cb; ctx.format = type; - ctx.set_list = nft_set_list_alloc(); + ctx.set_list = nftnl_set_list_alloc(); if (ctx.set_list == NULL) return -1; if (arg != NULL) - nft_ruleset_ctx_set(&ctx, NFT_RULESET_CTX_DATA, arg); + nftnl_ruleset_ctx_set(&ctx, NFTNL_RULESET_CTX_DATA, arg); - root = nft_jansson_create_root(json, &error, err, input); + root = nftnl_jansson_create_root(json, &error, err, input); if (root == NULL) goto err1; @@ -585,17 +585,17 @@ static int nft_ruleset_json_parse(const void *json, if (key == NULL) goto err2; - if (nft_ruleset_json_parse_cmd(key, err, &ctx) < 0) + if (nftnl_ruleset_json_parse_cmd(key, err, &ctx) < 0) goto err2; } - nft_set_list_free(ctx.set_list); - nft_jansson_free_root(root); + nftnl_set_list_free(ctx.set_list); + nftnl_jansson_free_root(root); return 0; err2: - nft_jansson_free_root(root); + nftnl_jansson_free_root(root); err1: - nft_set_list_free(ctx.set_list); + nftnl_set_list_free(ctx.set_list); return -1; #else errno = EOPNOTSUPP; @@ -604,8 +604,8 @@ err1: } #ifdef XML_PARSING -static int nft_ruleset_xml_parse_ruleset(struct nft_parse_ctx *ctx, - struct nft_parse_err *err) +static int nftnl_ruleset_xml_parse_ruleset(struct nftnl_parse_ctx *ctx, + struct nftnl_parse_err *err) { const char *node_type; mxml_node_t *node, *array = ctx->xml; @@ -620,15 +620,15 @@ static int nft_ruleset_xml_parse_ruleset(struct nft_parse_ctx *ctx, node_type = node->value.opaque; ctx->xml = node; if (strcmp(node_type, "table") == 0) - ret = nft_ruleset_parse_tables(ctx, err); + ret = nftnl_ruleset_parse_tables(ctx, err); else if (strcmp(node_type, "chain") == 0) - ret = nft_ruleset_parse_chains(ctx, err); + ret = nftnl_ruleset_parse_chains(ctx, err); else if (strcmp(node_type, "set") == 0) - ret = nft_ruleset_parse_sets(ctx, err); + ret = nftnl_ruleset_parse_sets(ctx, err); else if (strcmp(node_type, "rule") == 0) - ret = nft_ruleset_parse_rules(ctx, err); + ret = nftnl_ruleset_parse_rules(ctx, err); else if (strcmp(node_type, "element") == 0) - ret = nft_ruleset_parse_set_elems(ctx, err); + ret = nftnl_ruleset_parse_set_elems(ctx, err); else return -1; @@ -636,9 +636,9 @@ static int nft_ruleset_xml_parse_ruleset(struct nft_parse_ctx *ctx, return ret; } - if (len == 0 && ctx->cmd == NFT_CMD_FLUSH) { - nft_ruleset_ctx_set_u32(ctx, NFT_RULESET_CTX_TYPE, - NFT_RULESET_RULESET); + if (len == 0 && ctx->cmd == NFTNL_CMD_FLUSH) { + nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, + NFTNL_RULESET_RULESET); if (ctx->cb(ctx) < 0) return -1; } @@ -646,15 +646,15 @@ static int nft_ruleset_xml_parse_ruleset(struct nft_parse_ctx *ctx, return 0; } -static int nft_ruleset_xml_parse_cmd(const char *cmd, struct nft_parse_err *err, - struct nft_parse_ctx *ctx) +static int nftnl_ruleset_xml_parse_cmd(const char *cmd, struct nftnl_parse_err *err, + struct nftnl_parse_ctx *ctx) { uint32_t cmdnum; mxml_node_t *nodecmd; - cmdnum = nft_str2cmd(cmd); - if (cmdnum == NFT_CMD_UNSPEC) { - err->error = NFT_PARSE_EMISSINGNODE; + cmdnum = nftnl_str2cmd(cmd); + if (cmdnum == NFTNL_CMD_UNSPEC) { + err->error = NFTNL_PARSE_EMISSINGNODE; err->node_name = strdup(cmd); return -1; } @@ -663,9 +663,9 @@ static int nft_ruleset_xml_parse_cmd(const char *cmd, struct nft_parse_err *err, MXML_DESCEND_FIRST); ctx->xml = nodecmd; - nft_ruleset_ctx_set_u32(ctx, NFT_RULESET_CTX_CMD, cmdnum); + nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_CMD, cmdnum); - if (nft_ruleset_xml_parse_ruleset(ctx, err) != 0) + if (nftnl_ruleset_xml_parse_ruleset(ctx, err) != 0) goto err; return 0; @@ -674,27 +674,27 @@ err: } #endif -static int nft_ruleset_xml_parse(const void *xml, struct nft_parse_err *err, - enum nft_parse_input input, - enum nft_parse_type type, void *arg, - int (*cb)(const struct nft_parse_ctx *ctx)) +static int nftnl_ruleset_xml_parse(const void *xml, struct nftnl_parse_err *err, + enum nftnl_parse_input input, + enum nftnl_parse_type type, void *arg, + int (*cb)(const struct nftnl_parse_ctx *ctx)) { #ifdef XML_PARSING mxml_node_t *tree, *nodecmd = NULL; char *cmd; - struct nft_parse_ctx ctx; + struct nftnl_parse_ctx ctx; ctx.cb = cb; ctx.format = type; - ctx.set_list = nft_set_list_alloc(); + ctx.set_list = nftnl_set_list_alloc(); if (ctx.set_list == NULL) return -1; if (arg != NULL) - nft_ruleset_ctx_set(&ctx, NFT_RULESET_CTX_DATA, arg); + nftnl_ruleset_ctx_set(&ctx, NFTNL_RULESET_CTX_DATA, arg); - tree = nft_mxml_build_tree(xml, "nftables", err, input); + tree = nftnl_mxml_build_tree(xml, "nftables", err, input); if (tree == NULL) goto err1; @@ -703,18 +703,18 @@ static int nft_ruleset_xml_parse(const void *xml, struct nft_parse_err *err, nodecmd = mxmlWalkNext(tree, tree, MXML_DESCEND_FIRST); while (nodecmd != NULL) { cmd = nodecmd->value.opaque; - if (nft_ruleset_xml_parse_cmd(cmd, err, &ctx) < 0) + if (nftnl_ruleset_xml_parse_cmd(cmd, err, &ctx) < 0) goto err2; nodecmd = mxmlWalkNext(tree, tree, MXML_NO_DESCEND); } - nft_set_list_free(ctx.set_list); + nftnl_set_list_free(ctx.set_list); mxmlDelete(tree); return 0; err2: mxmlDelete(tree); err1: - nft_set_list_free(ctx.set_list); + nftnl_set_list_free(ctx.set_list); return -1; #else errno = EOPNOTSUPP; @@ -723,18 +723,18 @@ err1: } static int -nft_ruleset_do_parse(enum nft_parse_type type, const void *data, - struct nft_parse_err *err, enum nft_parse_input input, - void *arg, int (*cb)(const struct nft_parse_ctx *ctx)) +nftnl_ruleset_do_parse(enum nftnl_parse_type type, const void *data, + struct nftnl_parse_err *err, enum nftnl_parse_input input, + void *arg, int (*cb)(const struct nftnl_parse_ctx *ctx)) { int ret; switch (type) { - case NFT_PARSE_XML: - ret = nft_ruleset_xml_parse(data, err, input, type, arg, cb); + case NFTNL_PARSE_XML: + ret = nftnl_ruleset_xml_parse(data, err, input, type, arg, cb); break; - case NFT_PARSE_JSON: - ret = nft_ruleset_json_parse(data, err, input, type, arg, cb); + case NFTNL_PARSE_JSON: + ret = nftnl_ruleset_json_parse(data, err, input, type, arg, cb); break; default: ret = -1; @@ -745,76 +745,76 @@ nft_ruleset_do_parse(enum nft_parse_type type, const void *data, return ret; } -int nft_ruleset_parse_file_cb(enum nft_parse_type type, FILE *fp, - struct nft_parse_err *err, void *data, - int (*cb)(const struct nft_parse_ctx *ctx)) +int nftnl_ruleset_parse_file_cb(enum nftnl_parse_type type, FILE *fp, + struct nftnl_parse_err *err, void *data, + int (*cb)(const struct nftnl_parse_ctx *ctx)) { - return nft_ruleset_do_parse(type, fp, err, NFT_PARSE_FILE, data, cb); + return nftnl_ruleset_do_parse(type, fp, err, NFTNL_PARSE_FILE, data, cb); } EXPORT_SYMBOL(nftnl_ruleset_parse_file_cb, nft_ruleset_parse_file_cb); -int nft_ruleset_parse_buffer_cb(enum nft_parse_type type, const char *buffer, - struct nft_parse_err *err, void *data, - int (*cb)(const struct nft_parse_ctx *ctx)) +int nftnl_ruleset_parse_buffer_cb(enum nftnl_parse_type type, const char *buffer, + struct nftnl_parse_err *err, void *data, + int (*cb)(const struct nftnl_parse_ctx *ctx)) { - return nft_ruleset_do_parse(type, buffer, err, NFT_PARSE_BUFFER, data, + return nftnl_ruleset_do_parse(type, buffer, err, NFTNL_PARSE_BUFFER, data, cb); } EXPORT_SYMBOL(nftnl_ruleset_parse_buffer_cb, nft_ruleset_parse_buffer_cb); -static int nft_ruleset_cb(const struct nft_parse_ctx *ctx) +static int nftnl_ruleset_cb(const struct nftnl_parse_ctx *ctx) { - struct nft_ruleset *r = ctx->data; + struct nftnl_ruleset *r = ctx->data; - if (ctx->cmd != NFT_CMD_ADD) + if (ctx->cmd != NFTNL_CMD_ADD) return -1; switch (ctx->type) { - case NFT_RULESET_TABLE: + case NFTNL_RULESET_TABLE: if (r->table_list == NULL) { - r->table_list = nft_table_list_alloc(); + r->table_list = nftnl_table_list_alloc(); if (r->table_list == NULL) return -1; - nft_ruleset_attr_set(r, NFT_RULESET_ATTR_TABLELIST, + nftnl_ruleset_attr_set(r, NFTNL_RULESET_ATTR_TABLELIST, r->table_list); } - nft_table_list_add_tail(ctx->table, r->table_list); + nftnl_table_list_add_tail(ctx->table, r->table_list); break; - case NFT_RULESET_CHAIN: + case NFTNL_RULESET_CHAIN: if (r->chain_list == NULL) { - r->chain_list = nft_chain_list_alloc(); + r->chain_list = nftnl_chain_list_alloc(); if (r->chain_list == NULL) return -1; - nft_ruleset_attr_set(r, NFT_RULESET_ATTR_CHAINLIST, + nftnl_ruleset_attr_set(r, NFTNL_RULESET_ATTR_CHAINLIST, r->chain_list); } - nft_chain_list_add_tail(ctx->chain, r->chain_list); + nftnl_chain_list_add_tail(ctx->chain, r->chain_list); break; - case NFT_RULESET_SET: + case NFTNL_RULESET_SET: if (r->set_list == NULL) { - r->set_list = nft_set_list_alloc(); + r->set_list = nftnl_set_list_alloc(); if (r->set_list == NULL) return -1; - nft_ruleset_attr_set(r, NFT_RULESET_ATTR_SETLIST, + nftnl_ruleset_attr_set(r, NFTNL_RULESET_ATTR_SETLIST, r->set_list); } - nft_set_list_add_tail(ctx->set, r->set_list); + nftnl_set_list_add_tail(ctx->set, r->set_list); break; - case NFT_RULESET_RULE: + case NFTNL_RULESET_RULE: if (r->rule_list == NULL) { - r->rule_list = nft_rule_list_alloc(); + r->rule_list = nftnl_rule_list_alloc(); if (r->rule_list == NULL) return -1; - nft_ruleset_attr_set(r, NFT_RULESET_ATTR_RULELIST, + nftnl_ruleset_attr_set(r, NFTNL_RULESET_ATTR_RULELIST, r->rule_list); } - nft_rule_list_add_tail(ctx->rule, r->rule_list); + nftnl_rule_list_add_tail(ctx->rule, r->rule_list); break; - case NFT_RULESET_RULESET: + case NFTNL_RULESET_RULESET: break; default: return -1; @@ -823,53 +823,53 @@ static int nft_ruleset_cb(const struct nft_parse_ctx *ctx) return 0; } -int nft_ruleset_parse(struct nft_ruleset *r, enum nft_parse_type type, - const char *data, struct nft_parse_err *err) +int nftnl_ruleset_parse(struct nftnl_ruleset *r, enum nftnl_parse_type type, + const char *data, struct nftnl_parse_err *err) { - return nft_ruleset_parse_buffer_cb(type, data, err, r, nft_ruleset_cb); + return nftnl_ruleset_parse_buffer_cb(type, data, err, r, nftnl_ruleset_cb); } EXPORT_SYMBOL(nftnl_ruleset_parse, nft_ruleset_parse); -int nft_ruleset_parse_file(struct nft_ruleset *rs, enum nft_parse_type type, - FILE *fp, struct nft_parse_err *err) +int nftnl_ruleset_parse_file(struct nftnl_ruleset *rs, enum nftnl_parse_type type, + FILE *fp, struct nftnl_parse_err *err) { - return nft_ruleset_parse_file_cb(type, fp, err, rs, nft_ruleset_cb); + return nftnl_ruleset_parse_file_cb(type, fp, err, rs, nftnl_ruleset_cb); } EXPORT_SYMBOL(nftnl_ruleset_parse_file, nft_ruleset_parse_file); -static const char *nft_ruleset_o_opentag(uint32_t type) +static const char *nftnl_ruleset_o_opentag(uint32_t type) { switch (type) { - case NFT_OUTPUT_XML: + case NFTNL_OUTPUT_XML: return "<nftables>"; - case NFT_OUTPUT_JSON: + case NFTNL_OUTPUT_JSON: return "{\"nftables\":["; default: return ""; } } -static const char *nft_ruleset_o_separator(void *obj, uint32_t type) +static const char *nftnl_ruleset_o_separator(void *obj, uint32_t type) { if (obj == NULL) return ""; switch (type) { - case NFT_OUTPUT_JSON: + case NFTNL_OUTPUT_JSON: return ","; - case NFT_OUTPUT_DEFAULT: + case NFTNL_OUTPUT_DEFAULT: return "\n"; default: return ""; } } -static const char *nft_ruleset_o_closetag(uint32_t type) +static const char *nftnl_ruleset_o_closetag(uint32_t type) { switch (type) { - case NFT_OUTPUT_XML: + case NFTNL_OUTPUT_XML: return "</nftables>"; - case NFT_OUTPUT_JSON: + case NFTNL_OUTPUT_JSON: return "]}"; default: return ""; @@ -877,123 +877,123 @@ static const char *nft_ruleset_o_closetag(uint32_t type) } static int -nft_ruleset_snprintf_table(char *buf, size_t size, - const struct nft_ruleset *rs, uint32_t type, +nftnl_ruleset_snprintf_table(char *buf, size_t size, + const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags) { - struct nft_table *t; - struct nft_table_list_iter *ti; + struct nftnl_table *t; + struct nftnl_table_list_iter *ti; int ret, len = size, offset = 0; - ti = nft_table_list_iter_create(rs->table_list); + ti = nftnl_table_list_iter_create(rs->table_list); if (ti == NULL) return 0; - t = nft_table_list_iter_next(ti); + t = nftnl_table_list_iter_next(ti); while (t != NULL) { - ret = nft_table_snprintf(buf+offset, len, t, type, flags); + ret = nftnl_table_snprintf(buf+offset, len, t, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - t = nft_table_list_iter_next(ti); + t = nftnl_table_list_iter_next(ti); ret = snprintf(buf+offset, len, "%s", - nft_ruleset_o_separator(t, type)); + nftnl_ruleset_o_separator(t, type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - nft_table_list_iter_destroy(ti); + nftnl_table_list_iter_destroy(ti); return offset; } static int -nft_ruleset_snprintf_chain(char *buf, size_t size, - const struct nft_ruleset *rs, uint32_t type, +nftnl_ruleset_snprintf_chain(char *buf, size_t size, + const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags) { - struct nft_chain *c; - struct nft_chain_list_iter *ci; + struct nftnl_chain *c; + struct nftnl_chain_list_iter *ci; int ret, len = size, offset = 0; - ci = nft_chain_list_iter_create(rs->chain_list); + ci = nftnl_chain_list_iter_create(rs->chain_list); if (ci == NULL) return 0; - c = nft_chain_list_iter_next(ci); + c = nftnl_chain_list_iter_next(ci); while (c != NULL) { - ret = nft_chain_snprintf(buf+offset, len, c, type, flags); + ret = nftnl_chain_snprintf(buf+offset, len, c, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - c = nft_chain_list_iter_next(ci); + c = nftnl_chain_list_iter_next(ci); ret = snprintf(buf+offset, len, "%s", - nft_ruleset_o_separator(c, type)); + nftnl_ruleset_o_separator(c, type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - nft_chain_list_iter_destroy(ci); + nftnl_chain_list_iter_destroy(ci); return offset; } static int -nft_ruleset_snprintf_set(char *buf, size_t size, - const struct nft_ruleset *rs, uint32_t type, +nftnl_ruleset_snprintf_set(char *buf, size_t size, + const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags) { - struct nft_set *s; - struct nft_set_list_iter *si; + struct nftnl_set *s; + struct nftnl_set_list_iter *si; int ret, len = size, offset = 0; - si = nft_set_list_iter_create(rs->set_list); + si = nftnl_set_list_iter_create(rs->set_list); if (si == NULL) return 0; - s = nft_set_list_iter_next(si); + s = nftnl_set_list_iter_next(si); while (s != NULL) { - ret = nft_set_snprintf(buf+offset, len, s, type, flags); + ret = nftnl_set_snprintf(buf+offset, len, s, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - s = nft_set_list_iter_next(si); + s = nftnl_set_list_iter_next(si); ret = snprintf(buf+offset, len, "%s", - nft_ruleset_o_separator(s, type)); + nftnl_ruleset_o_separator(s, type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - nft_set_list_iter_destroy(si); + nftnl_set_list_iter_destroy(si); return offset; } static int -nft_ruleset_snprintf_rule(char *buf, size_t size, - const struct nft_ruleset *rs, uint32_t type, +nftnl_ruleset_snprintf_rule(char *buf, size_t size, + const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags) { - struct nft_rule *r; - struct nft_rule_list_iter *ri; + struct nftnl_rule *r; + struct nftnl_rule_list_iter *ri; int ret, len = size, offset = 0; - ri = nft_rule_list_iter_create(rs->rule_list); + ri = nftnl_rule_list_iter_create(rs->rule_list); if (ri == NULL) return 0; - r = nft_rule_list_iter_next(ri); + r = nftnl_rule_list_iter_next(ri); while (r != NULL) { - ret = nft_rule_snprintf(buf+offset, len, r, type, flags); + ret = nftnl_rule_snprintf(buf+offset, len, r, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - r = nft_rule_list_iter_next(ri); + r = nftnl_rule_list_iter_next(ri); ret = snprintf(buf+offset, len, "%s", - nft_ruleset_o_separator(r, type)); + nftnl_ruleset_o_separator(r, type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - nft_rule_list_iter_destroy(ri); + nftnl_rule_list_iter_destroy(ri); return offset; } static int -nft_ruleset_do_snprintf(char *buf, size_t size, const struct nft_ruleset *rs, +nftnl_ruleset_do_snprintf(char *buf, size_t size, const struct nftnl_ruleset *rs, uint32_t cmd, uint32_t type, uint32_t flags) { int ret, len = size, offset = 0; @@ -1001,17 +1001,17 @@ nft_ruleset_do_snprintf(char *buf, size_t size, const struct nft_ruleset *rs, uint32_t inner_flags = flags; /* dont pass events flags to child calls of _snprintf() */ - inner_flags &= ~NFT_OF_EVENT_ANY; + inner_flags &= ~NFTNL_OF_EVENT_ANY; - ret = snprintf(buf + offset, len, "%s", nft_ruleset_o_opentag(type)); + ret = snprintf(buf + offset, len, "%s", nftnl_ruleset_o_opentag(type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_cmd_header_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_header_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (nft_ruleset_attr_is_set(rs, NFT_RULESET_ATTR_TABLELIST) && - (!nft_table_list_is_empty(rs->table_list))) { - ret = nft_ruleset_snprintf_table(buf+offset, len, rs, + if (nftnl_ruleset_attr_is_set(rs, NFTNL_RULESET_ATTR_TABLELIST) && + (!nftnl_table_list_is_empty(rs->table_list))) { + ret = nftnl_ruleset_snprintf_table(buf+offset, len, rs, type, inner_flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -1019,13 +1019,13 @@ nft_ruleset_do_snprintf(char *buf, size_t size, const struct nft_ruleset *rs, prev = rs->table_list; } - if (nft_ruleset_attr_is_set(rs, NFT_RULESET_ATTR_CHAINLIST) && - (!nft_chain_list_is_empty(rs->chain_list))) { + if (nftnl_ruleset_attr_is_set(rs, NFTNL_RULESET_ATTR_CHAINLIST) && + (!nftnl_chain_list_is_empty(rs->chain_list))) { ret = snprintf(buf+offset, len, "%s", - nft_ruleset_o_separator(prev, type)); + nftnl_ruleset_o_separator(prev, type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_ruleset_snprintf_chain(buf+offset, len, rs, + ret = nftnl_ruleset_snprintf_chain(buf+offset, len, rs, type, inner_flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -1033,13 +1033,13 @@ nft_ruleset_do_snprintf(char *buf, size_t size, const struct nft_ruleset *rs, prev = rs->chain_list; } - if (nft_ruleset_attr_is_set(rs, NFT_RULESET_ATTR_SETLIST) && - (!nft_set_list_is_empty(rs->set_list))) { + if (nftnl_ruleset_attr_is_set(rs, NFTNL_RULESET_ATTR_SETLIST) && + (!nftnl_set_list_is_empty(rs->set_list))) { ret = snprintf(buf+offset, len, "%s", - nft_ruleset_o_separator(prev, type)); + nftnl_ruleset_o_separator(prev, type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_ruleset_snprintf_set(buf+offset, len, rs, + ret = nftnl_ruleset_snprintf_set(buf+offset, len, rs, type, inner_flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -1047,50 +1047,50 @@ nft_ruleset_do_snprintf(char *buf, size_t size, const struct nft_ruleset *rs, prev = rs->set_list; } - if (nft_ruleset_attr_is_set(rs, NFT_RULESET_ATTR_RULELIST) && - (!nft_rule_list_is_empty(rs->rule_list))) { + if (nftnl_ruleset_attr_is_set(rs, NFTNL_RULESET_ATTR_RULELIST) && + (!nftnl_rule_list_is_empty(rs->rule_list))) { ret = snprintf(buf+offset, len, "%s", - nft_ruleset_o_separator(prev, type)); + nftnl_ruleset_o_separator(prev, type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_ruleset_snprintf_rule(buf+offset, len, rs, + ret = nftnl_ruleset_snprintf_rule(buf+offset, len, rs, type, inner_flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - ret = nft_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = snprintf(buf + offset, len, "%s", nft_ruleset_o_closetag(type)); + ret = snprintf(buf + offset, len, "%s", nftnl_ruleset_o_closetag(type)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); return offset; } -static int nft_ruleset_cmd_snprintf(char *buf, size_t size, - const struct nft_ruleset *r, uint32_t cmd, +static int nftnl_ruleset_cmd_snprintf(char *buf, size_t size, + const struct nftnl_ruleset *r, uint32_t cmd, uint32_t type, uint32_t flags) { switch (type) { - case NFT_OUTPUT_DEFAULT: - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_ruleset_do_snprintf(buf, size, r, cmd, type, flags); + case NFTNL_OUTPUT_DEFAULT: + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_ruleset_do_snprintf(buf, size, r, cmd, type, flags); default: errno = EOPNOTSUPP; return -1; } } -int nft_ruleset_snprintf(char *buf, size_t size, const struct nft_ruleset *r, +int nftnl_ruleset_snprintf(char *buf, size_t size, const struct nftnl_ruleset *r, uint32_t type, uint32_t flags) { switch (type) { - case NFT_OUTPUT_DEFAULT: - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_ruleset_cmd_snprintf(buf, size, r, - nft_flag2cmd(flags), type, + case NFTNL_OUTPUT_DEFAULT: + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_ruleset_cmd_snprintf(buf, size, r, + nftnl_flag2cmd(flags), type, flags); default: errno = EOPNOTSUPP; @@ -1099,152 +1099,152 @@ int nft_ruleset_snprintf(char *buf, size_t size, const struct nft_ruleset *r, } EXPORT_SYMBOL(nftnl_ruleset_snprintf, nft_ruleset_snprintf); -static int nft_ruleset_fprintf_tables(FILE *fp, const struct nft_ruleset *rs, +static int nftnl_ruleset_fprintf_tables(FILE *fp, const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags) { int len = 0, ret = 0; - struct nft_table *t; - struct nft_table_list_iter *ti; + struct nftnl_table *t; + struct nftnl_table_list_iter *ti; - ti = nft_table_list_iter_create(rs->table_list); + ti = nftnl_table_list_iter_create(rs->table_list); if (ti == NULL) return -1; - t = nft_table_list_iter_next(ti); + t = nftnl_table_list_iter_next(ti); while (t != NULL) { - ret = nft_table_fprintf(fp, t, type, flags); + ret = nftnl_table_fprintf(fp, t, type, flags); if (ret < 0) goto err; len += ret; - t = nft_table_list_iter_next(ti); + t = nftnl_table_list_iter_next(ti); - ret = fprintf(fp, "%s", nft_ruleset_o_separator(t, type)); + ret = fprintf(fp, "%s", nftnl_ruleset_o_separator(t, type)); if (ret < 0) goto err; len += ret; } - nft_table_list_iter_destroy(ti); + nftnl_table_list_iter_destroy(ti); return len; err: - nft_table_list_iter_destroy(ti); + nftnl_table_list_iter_destroy(ti); return -1; } -static int nft_ruleset_fprintf_chains(FILE *fp, const struct nft_ruleset *rs, +static int nftnl_ruleset_fprintf_chains(FILE *fp, const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags) { int len = 0, ret = 0; - struct nft_chain *o; - struct nft_chain_list_iter *i; + struct nftnl_chain *o; + struct nftnl_chain_list_iter *i; - i = nft_chain_list_iter_create(rs->chain_list); + i = nftnl_chain_list_iter_create(rs->chain_list); if (i == NULL) return -1; - o = nft_chain_list_iter_next(i); + o = nftnl_chain_list_iter_next(i); while (o != NULL) { - ret = nft_chain_fprintf(fp, o, type, flags); + ret = nftnl_chain_fprintf(fp, o, type, flags); if (ret < 0) goto err; len += ret; - o = nft_chain_list_iter_next(i); + o = nftnl_chain_list_iter_next(i); - ret = fprintf(fp, "%s", nft_ruleset_o_separator(o, type)); + ret = fprintf(fp, "%s", nftnl_ruleset_o_separator(o, type)); if (ret < 0) goto err; len += ret; } - nft_chain_list_iter_destroy(i); + nftnl_chain_list_iter_destroy(i); return len; err: - nft_chain_list_iter_destroy(i); + nftnl_chain_list_iter_destroy(i); return -1; } -static int nft_ruleset_fprintf_sets(FILE *fp, const struct nft_ruleset *rs, +static int nftnl_ruleset_fprintf_sets(FILE *fp, const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags) { int len = 0, ret = 0; - struct nft_set *o; - struct nft_set_list_iter *i; + struct nftnl_set *o; + struct nftnl_set_list_iter *i; - i = nft_set_list_iter_create(rs->set_list); + i = nftnl_set_list_iter_create(rs->set_list); if (i == NULL) return -1; - o = nft_set_list_iter_next(i); + o = nftnl_set_list_iter_next(i); while (o != NULL) { - ret = nft_set_fprintf(fp, o, type, flags); + ret = nftnl_set_fprintf(fp, o, type, flags); if (ret < 0) goto err; len += ret; - o = nft_set_list_iter_next(i); + o = nftnl_set_list_iter_next(i); - ret = fprintf(fp, "%s", nft_ruleset_o_separator(o, type)); + ret = fprintf(fp, "%s", nftnl_ruleset_o_separator(o, type)); if (ret < 0) goto err; len += ret; } - nft_set_list_iter_destroy(i); + nftnl_set_list_iter_destroy(i); return len; err: - nft_set_list_iter_destroy(i); + nftnl_set_list_iter_destroy(i); return -1; } -static int nft_ruleset_fprintf_rules(FILE *fp, const struct nft_ruleset *rs, +static int nftnl_ruleset_fprintf_rules(FILE *fp, const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags) { int len = 0, ret = 0; - struct nft_rule *o; - struct nft_rule_list_iter *i; + struct nftnl_rule *o; + struct nftnl_rule_list_iter *i; - i = nft_rule_list_iter_create(rs->rule_list); + i = nftnl_rule_list_iter_create(rs->rule_list); if (i == NULL) return -1; - o = nft_rule_list_iter_next(i); + o = nftnl_rule_list_iter_next(i); while (o != NULL) { - ret = nft_rule_fprintf(fp, o, type, flags); + ret = nftnl_rule_fprintf(fp, o, type, flags); if (ret < 0) goto err; len += ret; - o = nft_rule_list_iter_next(i); + o = nftnl_rule_list_iter_next(i); - ret = fprintf(fp, "%s", nft_ruleset_o_separator(o, type)); + ret = fprintf(fp, "%s", nftnl_ruleset_o_separator(o, type)); if (ret < 0) goto err; len += ret; } - nft_rule_list_iter_destroy(i); + nftnl_rule_list_iter_destroy(i); return len; err: - nft_rule_list_iter_destroy(i); + nftnl_rule_list_iter_destroy(i); return -1; } -#define NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len) \ +#define NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len) \ if (ret < 0) \ return -1; \ len += ret; -static int nft_ruleset_cmd_fprintf(FILE *fp, const struct nft_ruleset *rs, +static int nftnl_ruleset_cmd_fprintf(FILE *fp, const struct nftnl_ruleset *rs, uint32_t cmd, uint32_t type, uint32_t flags) { int len = 0, ret = 0; @@ -1252,69 +1252,69 @@ static int nft_ruleset_cmd_fprintf(FILE *fp, const struct nft_ruleset *rs, uint32_t inner_flags = flags; /* dont pass events flags to child calls of _snprintf() */ - inner_flags &= ~NFT_OF_EVENT_ANY; + inner_flags &= ~NFTNL_OF_EVENT_ANY; - ret = fprintf(fp, "%s", nft_ruleset_o_opentag(type)); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + ret = fprintf(fp, "%s", nftnl_ruleset_o_opentag(type)); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); - ret = nft_cmd_header_fprintf(fp, cmd, type, flags); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + ret = nftnl_cmd_header_fprintf(fp, cmd, type, flags); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); - if ((nft_ruleset_attr_is_set(rs, NFT_RULESET_ATTR_TABLELIST)) && - (!nft_table_list_is_empty(rs->table_list))) { - ret = nft_ruleset_fprintf_tables(fp, rs, type, inner_flags); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + if ((nftnl_ruleset_attr_is_set(rs, NFTNL_RULESET_ATTR_TABLELIST)) && + (!nftnl_table_list_is_empty(rs->table_list))) { + ret = nftnl_ruleset_fprintf_tables(fp, rs, type, inner_flags); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); if (ret > 0) prev = rs->table_list; } - if ((nft_ruleset_attr_is_set(rs, NFT_RULESET_ATTR_CHAINLIST)) && - (!nft_chain_list_is_empty(rs->chain_list))) { - ret = fprintf(fp, "%s", nft_ruleset_o_separator(prev, type)); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + if ((nftnl_ruleset_attr_is_set(rs, NFTNL_RULESET_ATTR_CHAINLIST)) && + (!nftnl_chain_list_is_empty(rs->chain_list))) { + ret = fprintf(fp, "%s", nftnl_ruleset_o_separator(prev, type)); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); - ret = nft_ruleset_fprintf_chains(fp, rs, type, inner_flags); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + ret = nftnl_ruleset_fprintf_chains(fp, rs, type, inner_flags); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); if (ret > 0) prev = rs->chain_list; } - if ((nft_ruleset_attr_is_set(rs, NFT_RULESET_ATTR_SETLIST)) && - (!nft_set_list_is_empty(rs->set_list))) { - ret = fprintf(fp, "%s", nft_ruleset_o_separator(prev, type)); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + if ((nftnl_ruleset_attr_is_set(rs, NFTNL_RULESET_ATTR_SETLIST)) && + (!nftnl_set_list_is_empty(rs->set_list))) { + ret = fprintf(fp, "%s", nftnl_ruleset_o_separator(prev, type)); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); - ret = nft_ruleset_fprintf_sets(fp, rs, type, inner_flags); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + ret = nftnl_ruleset_fprintf_sets(fp, rs, type, inner_flags); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); if (ret > 0) prev = rs->set_list; } - if ((nft_ruleset_attr_is_set(rs, NFT_RULESET_ATTR_RULELIST)) && - (!nft_rule_list_is_empty(rs->rule_list))) { - ret = fprintf(fp, "%s", nft_ruleset_o_separator(prev, type)); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + if ((nftnl_ruleset_attr_is_set(rs, NFTNL_RULESET_ATTR_RULELIST)) && + (!nftnl_rule_list_is_empty(rs->rule_list))) { + ret = fprintf(fp, "%s", nftnl_ruleset_o_separator(prev, type)); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); - ret = nft_ruleset_fprintf_rules(fp, rs, type, inner_flags); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + ret = nftnl_ruleset_fprintf_rules(fp, rs, type, inner_flags); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); } - ret = nft_cmd_footer_fprintf(fp, cmd, type, flags); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + ret = nftnl_cmd_footer_fprintf(fp, cmd, type, flags); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); - ret = fprintf(fp, "%s", nft_ruleset_o_closetag(type)); - NFT_FPRINTF_RETURN_OR_FIXLEN(ret, len); + ret = fprintf(fp, "%s", nftnl_ruleset_o_closetag(type)); + NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len); return len; } -int nft_ruleset_fprintf(FILE *fp, const struct nft_ruleset *rs, uint32_t type, +int nftnl_ruleset_fprintf(FILE *fp, const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags) { - return nft_ruleset_cmd_fprintf(fp, rs, nft_flag2cmd(flags), type, + return nftnl_ruleset_cmd_fprintf(fp, rs, nftnl_flag2cmd(flags), type, flags); } EXPORT_SYMBOL(nftnl_ruleset_fprintf, nft_ruleset_fprintf); @@ -27,11 +27,11 @@ #include <libnftnl/set.h> #include <libnftnl/expr.h> -struct nft_set *nft_set_alloc(void) +struct nftnl_set *nftnl_set_alloc(void) { - struct nft_set *s; + struct nftnl_set *s; - s = calloc(1, sizeof(struct nft_set)); + s = calloc(1, sizeof(struct nftnl_set)); if (s == NULL) return NULL; @@ -40,9 +40,9 @@ struct nft_set *nft_set_alloc(void) } EXPORT_SYMBOL(nftnl_set_alloc, nft_set_alloc); -void nft_set_free(struct nft_set *s) +void nftnl_set_free(struct nftnl_set *s) { - struct nft_set_elem *elem, *tmp; + struct nftnl_set_elem *elem, *tmp; if (s->table != NULL) xfree(s->table); @@ -51,46 +51,46 @@ void nft_set_free(struct nft_set *s) list_for_each_entry_safe(elem, tmp, &s->element_list, head) { list_del(&elem->head); - nft_set_elem_free(elem); + nftnl_set_elem_free(elem); } xfree(s); } EXPORT_SYMBOL(nftnl_set_free, nft_set_free); -bool nft_set_attr_is_set(const struct nft_set *s, uint16_t attr) +bool nftnl_set_attr_is_set(const struct nftnl_set *s, uint16_t attr) { return s->flags & (1 << attr); } EXPORT_SYMBOL(nftnl_set_attr_is_set, nft_set_attr_is_set); -void nft_set_attr_unset(struct nft_set *s, uint16_t attr) +void nftnl_set_attr_unset(struct nftnl_set *s, uint16_t attr) { switch (attr) { - case NFT_SET_ATTR_TABLE: - if (s->flags & (1 << NFT_SET_ATTR_TABLE)) + case NFTNL_SET_ATTR_TABLE: + if (s->flags & (1 << NFTNL_SET_ATTR_TABLE)) if (s->table) { xfree(s->table); s->table = NULL; } break; - case NFT_SET_ATTR_NAME: - if (s->flags & (1 << NFT_SET_ATTR_NAME)) + case NFTNL_SET_ATTR_NAME: + if (s->flags & (1 << NFTNL_SET_ATTR_NAME)) if (s->name) { xfree(s->name); s->name = NULL; } break; - case NFT_SET_ATTR_FLAGS: - case NFT_SET_ATTR_KEY_TYPE: - case NFT_SET_ATTR_KEY_LEN: - case NFT_SET_ATTR_DATA_TYPE: - case NFT_SET_ATTR_DATA_LEN: - case NFT_SET_ATTR_FAMILY: - case NFT_SET_ATTR_ID: - case NFT_SET_ATTR_POLICY: - case NFT_SET_ATTR_DESC_SIZE: - case NFT_SET_ATTR_TIMEOUT: - case NFT_SET_ATTR_GC_INTERVAL: + case NFTNL_SET_ATTR_FLAGS: + case NFTNL_SET_ATTR_KEY_TYPE: + case NFTNL_SET_ATTR_KEY_LEN: + case NFTNL_SET_ATTR_DATA_TYPE: + case NFTNL_SET_ATTR_DATA_LEN: + case NFTNL_SET_ATTR_FAMILY: + case NFTNL_SET_ATTR_ID: + case NFTNL_SET_ATTR_POLICY: + case NFTNL_SET_ATTR_DESC_SIZE: + case NFTNL_SET_ATTR_TIMEOUT: + case NFTNL_SET_ATTR_GC_INTERVAL: break; default: return; @@ -100,71 +100,71 @@ void nft_set_attr_unset(struct nft_set *s, uint16_t attr) } EXPORT_SYMBOL(nftnl_set_attr_unset, nft_set_attr_unset); -static uint32_t nft_set_attr_validate[NFT_SET_ATTR_MAX + 1] = { - [NFT_SET_ATTR_FLAGS] = sizeof(uint32_t), - [NFT_SET_ATTR_KEY_TYPE] = sizeof(uint32_t), - [NFT_SET_ATTR_KEY_LEN] = sizeof(uint32_t), - [NFT_SET_ATTR_DATA_TYPE] = sizeof(uint32_t), - [NFT_SET_ATTR_DATA_LEN] = sizeof(uint32_t), - [NFT_SET_ATTR_FAMILY] = sizeof(uint32_t), - [NFT_SET_ATTR_POLICY] = sizeof(uint32_t), - [NFT_SET_ATTR_DESC_SIZE] = sizeof(uint32_t), - [NFT_SET_ATTR_TIMEOUT] = sizeof(uint64_t), - [NFT_SET_ATTR_GC_INTERVAL] = sizeof(uint32_t), +static uint32_t nftnl_set_attr_validate[NFTNL_SET_ATTR_MAX + 1] = { + [NFTNL_SET_ATTR_FLAGS] = sizeof(uint32_t), + [NFTNL_SET_ATTR_KEY_TYPE] = sizeof(uint32_t), + [NFTNL_SET_ATTR_KEY_LEN] = sizeof(uint32_t), + [NFTNL_SET_ATTR_DATA_TYPE] = sizeof(uint32_t), + [NFTNL_SET_ATTR_DATA_LEN] = sizeof(uint32_t), + [NFTNL_SET_ATTR_FAMILY] = sizeof(uint32_t), + [NFTNL_SET_ATTR_POLICY] = sizeof(uint32_t), + [NFTNL_SET_ATTR_DESC_SIZE] = sizeof(uint32_t), + [NFTNL_SET_ATTR_TIMEOUT] = sizeof(uint64_t), + [NFTNL_SET_ATTR_GC_INTERVAL] = sizeof(uint32_t), }; -void nft_set_attr_set_data(struct nft_set *s, uint16_t attr, const void *data, +void nftnl_set_attr_set_data(struct nftnl_set *s, uint16_t attr, const void *data, uint32_t data_len) { - if (attr > NFT_SET_ATTR_MAX) + if (attr > NFTNL_SET_ATTR_MAX) return; - nft_assert_validate(data, nft_set_attr_validate, attr, data_len); + nftnl_assert_validate(data, nftnl_set_attr_validate, attr, data_len); switch(attr) { - case NFT_SET_ATTR_TABLE: + case NFTNL_SET_ATTR_TABLE: if (s->table) xfree(s->table); s->table = strdup(data); break; - case NFT_SET_ATTR_NAME: + case NFTNL_SET_ATTR_NAME: if (s->name) xfree(s->name); s->name = strdup(data); break; - case NFT_SET_ATTR_FLAGS: + case NFTNL_SET_ATTR_FLAGS: s->set_flags = *((uint32_t *)data); break; - case NFT_SET_ATTR_KEY_TYPE: + case NFTNL_SET_ATTR_KEY_TYPE: s->key_type = *((uint32_t *)data); break; - case NFT_SET_ATTR_KEY_LEN: + case NFTNL_SET_ATTR_KEY_LEN: s->key_len = *((uint32_t *)data); break; - case NFT_SET_ATTR_DATA_TYPE: + case NFTNL_SET_ATTR_DATA_TYPE: s->data_type = *((uint32_t *)data); break; - case NFT_SET_ATTR_DATA_LEN: + case NFTNL_SET_ATTR_DATA_LEN: s->data_len = *((uint32_t *)data); break; - case NFT_SET_ATTR_FAMILY: + case NFTNL_SET_ATTR_FAMILY: s->family = *((uint32_t *)data); break; - case NFT_SET_ATTR_ID: + case NFTNL_SET_ATTR_ID: s->id = *((uint32_t *)data); break; - case NFT_SET_ATTR_POLICY: + case NFTNL_SET_ATTR_POLICY: s->policy = *((uint32_t *)data); break; - case NFT_SET_ATTR_DESC_SIZE: + case NFTNL_SET_ATTR_DESC_SIZE: s->desc.size = *((uint32_t *)data); break; - case NFT_SET_ATTR_TIMEOUT: + case NFTNL_SET_ATTR_TIMEOUT: s->timeout = *((uint64_t *)data); break; - case NFT_SET_ATTR_GC_INTERVAL: + case NFTNL_SET_ATTR_GC_INTERVAL: s->gc_interval = *((uint32_t *)data); break; } @@ -172,72 +172,72 @@ void nft_set_attr_set_data(struct nft_set *s, uint16_t attr, const void *data, } EXPORT_SYMBOL(nftnl_set_attr_set_data, nft_set_attr_set_data); -void nft_set_attr_set(struct nft_set *s, uint16_t attr, const void *data) +void nftnl_set_attr_set(struct nftnl_set *s, uint16_t attr, const void *data) { - nft_set_attr_set_data(s, attr, data, nft_set_attr_validate[attr]); + nftnl_set_attr_set_data(s, attr, data, nftnl_set_attr_validate[attr]); } EXPORT_SYMBOL(nftnl_set_attr_set, nft_set_attr_set); -void nft_set_attr_set_u32(struct nft_set *s, uint16_t attr, uint32_t val) +void nftnl_set_attr_set_u32(struct nftnl_set *s, uint16_t attr, uint32_t val) { - nft_set_attr_set(s, attr, &val); + nftnl_set_attr_set(s, attr, &val); } EXPORT_SYMBOL(nftnl_set_attr_set_u32, nft_set_attr_set_u32); -void nft_set_attr_set_u64(struct nft_set *s, uint16_t attr, uint64_t val) +void nftnl_set_attr_set_u64(struct nftnl_set *s, uint16_t attr, uint64_t val) { - nft_set_attr_set(s, attr, &val); + nftnl_set_attr_set(s, attr, &val); } EXPORT_SYMBOL(nftnl_set_attr_set_u64, nft_set_attr_set_u64); -void nft_set_attr_set_str(struct nft_set *s, uint16_t attr, const char *str) +void nftnl_set_attr_set_str(struct nftnl_set *s, uint16_t attr, const char *str) { - nft_set_attr_set(s, attr, str); + nftnl_set_attr_set(s, attr, str); } EXPORT_SYMBOL(nftnl_set_attr_set_str, nft_set_attr_set_str); -const void *nft_set_attr_get_data(struct nft_set *s, uint16_t attr, +const void *nftnl_set_attr_get_data(struct nftnl_set *s, uint16_t attr, uint32_t *data_len) { if (!(s->flags & (1 << attr))) return NULL; switch(attr) { - case NFT_SET_ATTR_TABLE: + case NFTNL_SET_ATTR_TABLE: return s->table; - case NFT_SET_ATTR_NAME: + case NFTNL_SET_ATTR_NAME: return s->name; - case NFT_SET_ATTR_FLAGS: + case NFTNL_SET_ATTR_FLAGS: *data_len = sizeof(uint32_t); return &s->set_flags; - case NFT_SET_ATTR_KEY_TYPE: + case NFTNL_SET_ATTR_KEY_TYPE: *data_len = sizeof(uint32_t); return &s->key_type; - case NFT_SET_ATTR_KEY_LEN: + case NFTNL_SET_ATTR_KEY_LEN: *data_len = sizeof(uint32_t); return &s->key_len; - case NFT_SET_ATTR_DATA_TYPE: + case NFTNL_SET_ATTR_DATA_TYPE: *data_len = sizeof(uint32_t); return &s->data_type; - case NFT_SET_ATTR_DATA_LEN: + case NFTNL_SET_ATTR_DATA_LEN: *data_len = sizeof(uint32_t); return &s->data_len; - case NFT_SET_ATTR_FAMILY: + case NFTNL_SET_ATTR_FAMILY: *data_len = sizeof(uint32_t); return &s->family; - case NFT_SET_ATTR_ID: + case NFTNL_SET_ATTR_ID: *data_len = sizeof(uint32_t); return &s->id; - case NFT_SET_ATTR_POLICY: + case NFTNL_SET_ATTR_POLICY: *data_len = sizeof(uint32_t); return &s->policy; - case NFT_SET_ATTR_DESC_SIZE: + case NFTNL_SET_ATTR_DESC_SIZE: *data_len = sizeof(uint32_t); return &s->desc.size; - case NFT_SET_ATTR_TIMEOUT: + case NFTNL_SET_ATTR_TIMEOUT: *data_len = sizeof(uint64_t); return &s->timeout; - case NFT_SET_ATTR_GC_INTERVAL: + case NFTNL_SET_ATTR_GC_INTERVAL: *data_len = sizeof(uint32_t); return &s->gc_interval; } @@ -245,60 +245,60 @@ const void *nft_set_attr_get_data(struct nft_set *s, uint16_t attr, } EXPORT_SYMBOL(nftnl_set_attr_get_data, nft_set_attr_get_data); -const void *nft_set_attr_get(struct nft_set *s, uint16_t attr) +const void *nftnl_set_attr_get(struct nftnl_set *s, uint16_t attr) { uint32_t data_len; - return nft_set_attr_get_data(s, attr, &data_len); + return nftnl_set_attr_get_data(s, attr, &data_len); } EXPORT_SYMBOL(nftnl_set_attr_get, nft_set_attr_get); -const char *nft_set_attr_get_str(struct nft_set *s, uint16_t attr) +const char *nftnl_set_attr_get_str(struct nftnl_set *s, uint16_t attr) { - return nft_set_attr_get(s, attr); + return nftnl_set_attr_get(s, attr); } EXPORT_SYMBOL(nftnl_set_attr_get_str, nft_set_attr_get_str); -uint32_t nft_set_attr_get_u32(struct nft_set *s, uint16_t attr) +uint32_t nftnl_set_attr_get_u32(struct nftnl_set *s, uint16_t attr) { uint32_t data_len; - const uint32_t *val = nft_set_attr_get_data(s, attr, &data_len); + const uint32_t *val = nftnl_set_attr_get_data(s, attr, &data_len); - nft_assert(val, attr, data_len == sizeof(uint32_t)); + nftnl_assert(val, attr, data_len == sizeof(uint32_t)); return val ? *val : 0; } EXPORT_SYMBOL(nftnl_set_attr_get_u32, nft_set_attr_get_u32); -uint64_t nft_set_attr_get_u64(struct nft_set *s, uint16_t attr) +uint64_t nftnl_set_attr_get_u64(struct nftnl_set *s, uint16_t attr) { uint32_t data_len; - const uint64_t *val = nft_set_attr_get_data(s, attr, &data_len); + const uint64_t *val = nftnl_set_attr_get_data(s, attr, &data_len); - nft_assert(val, attr, data_len == sizeof(uint64_t)); + nftnl_assert(val, attr, data_len == sizeof(uint64_t)); return val ? *val : 0; } EXPORT_SYMBOL(nftnl_set_attr_get_u64, nft_set_attr_get_u64); -struct nft_set *nft_set_clone(const struct nft_set *set) +struct nftnl_set *nftnl_set_clone(const struct nftnl_set *set) { - struct nft_set *newset; - struct nft_set_elem *elem, *newelem; + struct nftnl_set *newset; + struct nftnl_set_elem *elem, *newelem; - newset = nft_set_alloc(); + newset = nftnl_set_alloc(); if (newset == NULL) return NULL; memcpy(newset, set, sizeof(*set)); - if (set->flags & (1 << NFT_SET_ATTR_TABLE)) + if (set->flags & (1 << NFTNL_SET_ATTR_TABLE)) newset->table = strdup(set->table); - if (set->flags & (1 << NFT_SET_ATTR_NAME)) + if (set->flags & (1 << NFTNL_SET_ATTR_NAME)) newset->name = strdup(set->name); INIT_LIST_HEAD(&newset->element_list); list_for_each_entry(elem, &set->element_list, head) { - newelem = nft_set_elem_clone(elem); + newelem = nftnl_set_elem_clone(elem); if (newelem == NULL) goto err; @@ -307,12 +307,12 @@ struct nft_set *nft_set_clone(const struct nft_set *set) return newset; err: - nft_set_free(newset); + nftnl_set_free(newset); return NULL; } static void -nft_set_nlmsg_build_desc_payload(struct nlmsghdr *nlh, struct nft_set *s) +nftnl_set_nlmsg_build_desc_payload(struct nlmsghdr *nlh, struct nftnl_set *s) { struct nlattr *nest; @@ -321,37 +321,37 @@ nft_set_nlmsg_build_desc_payload(struct nlmsghdr *nlh, struct nft_set *s) mnl_attr_nest_end(nlh, nest); } -void nft_set_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set *s) +void nftnl_set_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_set *s) { - if (s->flags & (1 << NFT_SET_ATTR_TABLE)) + if (s->flags & (1 << NFTNL_SET_ATTR_TABLE)) mnl_attr_put_strz(nlh, NFTA_SET_TABLE, s->table); - if (s->flags & (1 << NFT_SET_ATTR_NAME)) + if (s->flags & (1 << NFTNL_SET_ATTR_NAME)) mnl_attr_put_strz(nlh, NFTA_SET_NAME, s->name); - if (s->flags & (1 << NFT_SET_ATTR_FLAGS)) + if (s->flags & (1 << NFTNL_SET_ATTR_FLAGS)) mnl_attr_put_u32(nlh, NFTA_SET_FLAGS, htonl(s->set_flags)); - if (s->flags & (1 << NFT_SET_ATTR_KEY_TYPE)) + if (s->flags & (1 << NFTNL_SET_ATTR_KEY_TYPE)) mnl_attr_put_u32(nlh, NFTA_SET_KEY_TYPE, htonl(s->key_type)); - if (s->flags & (1 << NFT_SET_ATTR_KEY_LEN)) + if (s->flags & (1 << NFTNL_SET_ATTR_KEY_LEN)) mnl_attr_put_u32(nlh, NFTA_SET_KEY_LEN, htonl(s->key_len)); /* These are only used to map matching -> action (1:1) */ - if (s->flags & (1 << NFT_SET_ATTR_DATA_TYPE)) + if (s->flags & (1 << NFTNL_SET_ATTR_DATA_TYPE)) mnl_attr_put_u32(nlh, NFTA_SET_DATA_TYPE, htonl(s->data_type)); - if (s->flags & (1 << NFT_SET_ATTR_DATA_LEN)) + if (s->flags & (1 << NFTNL_SET_ATTR_DATA_LEN)) mnl_attr_put_u32(nlh, NFTA_SET_DATA_LEN, htonl(s->data_len)); - if (s->flags & (1 << NFT_SET_ATTR_ID)) + if (s->flags & (1 << NFTNL_SET_ATTR_ID)) mnl_attr_put_u32(nlh, NFTA_SET_ID, htonl(s->id)); - if (s->flags & (1 << NFT_SET_ATTR_POLICY)) + if (s->flags & (1 << NFTNL_SET_ATTR_POLICY)) mnl_attr_put_u32(nlh, NFTA_SET_POLICY, htonl(s->policy)); - if (s->flags & (1 << NFT_SET_ATTR_DESC_SIZE)) - nft_set_nlmsg_build_desc_payload(nlh, s); - if (s->flags & (1 << NFT_SET_ATTR_TIMEOUT)) + if (s->flags & (1 << NFTNL_SET_ATTR_DESC_SIZE)) + nftnl_set_nlmsg_build_desc_payload(nlh, s); + if (s->flags & (1 << NFTNL_SET_ATTR_TIMEOUT)) mnl_attr_put_u64(nlh, NFTA_SET_TIMEOUT, htobe64(s->timeout)); - if (s->flags & (1 << NFT_SET_ATTR_GC_INTERVAL)) + if (s->flags & (1 << NFTNL_SET_ATTR_GC_INTERVAL)) mnl_attr_put_u32(nlh, NFTA_SET_GC_INTERVAL, htonl(s->gc_interval)); } EXPORT_SYMBOL(nftnl_set_nlmsg_build_payload, nft_set_nlmsg_build_payload); -static int nft_set_parse_attr_cb(const struct nlattr *attr, void *data) +static int nftnl_set_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -390,7 +390,7 @@ static int nft_set_parse_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_set_desc_parse_attr_cb(const struct nlattr *attr, void *data) +static int nftnl_set_desc_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -409,159 +409,159 @@ static int nft_set_desc_parse_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_set_desc_parse(struct nft_set *s, +static int nftnl_set_desc_parse(struct nftnl_set *s, const struct nlattr *attr) { struct nlattr *tb[NFTA_SET_DESC_MAX + 1] = {}; - if (mnl_attr_parse_nested(attr, nft_set_desc_parse_attr_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_set_desc_parse_attr_cb, tb) < 0) return -1; if (tb[NFTA_SET_DESC_SIZE]) { s->desc.size = ntohl(mnl_attr_get_u32(tb[NFTA_SET_DESC_SIZE])); - s->flags |= (1 << NFT_SET_ATTR_DESC_SIZE); + s->flags |= (1 << NFTNL_SET_ATTR_DESC_SIZE); } return 0; } -int nft_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s) +int nftnl_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s) { struct nlattr *tb[NFTA_SET_MAX+1] = {}; struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh); int ret = 0; - if (mnl_attr_parse(nlh, sizeof(*nfg), nft_set_parse_attr_cb, tb) < 0) + if (mnl_attr_parse(nlh, sizeof(*nfg), nftnl_set_parse_attr_cb, tb) < 0) return -1; if (tb[NFTA_SET_TABLE]) { xfree(s->table); s->table = strdup(mnl_attr_get_str(tb[NFTA_SET_TABLE])); - s->flags |= (1 << NFT_SET_ATTR_TABLE); + s->flags |= (1 << NFTNL_SET_ATTR_TABLE); } if (tb[NFTA_SET_NAME]) { xfree(s->name); s->name = strdup(mnl_attr_get_str(tb[NFTA_SET_NAME])); - s->flags |= (1 << NFT_SET_ATTR_NAME); + s->flags |= (1 << NFTNL_SET_ATTR_NAME); } if (tb[NFTA_SET_FLAGS]) { s->set_flags = ntohl(mnl_attr_get_u32(tb[NFTA_SET_FLAGS])); - s->flags |= (1 << NFT_SET_ATTR_FLAGS); + s->flags |= (1 << NFTNL_SET_ATTR_FLAGS); } if (tb[NFTA_SET_KEY_TYPE]) { s->key_type = ntohl(mnl_attr_get_u32(tb[NFTA_SET_KEY_TYPE])); - s->flags |= (1 << NFT_SET_ATTR_KEY_TYPE); + s->flags |= (1 << NFTNL_SET_ATTR_KEY_TYPE); } if (tb[NFTA_SET_KEY_LEN]) { s->key_len = ntohl(mnl_attr_get_u32(tb[NFTA_SET_KEY_LEN])); - s->flags |= (1 << NFT_SET_ATTR_KEY_LEN); + s->flags |= (1 << NFTNL_SET_ATTR_KEY_LEN); } if (tb[NFTA_SET_DATA_TYPE]) { s->data_type = ntohl(mnl_attr_get_u32(tb[NFTA_SET_DATA_TYPE])); - s->flags |= (1 << NFT_SET_ATTR_DATA_TYPE); + s->flags |= (1 << NFTNL_SET_ATTR_DATA_TYPE); } if (tb[NFTA_SET_DATA_LEN]) { s->data_len = ntohl(mnl_attr_get_u32(tb[NFTA_SET_DATA_LEN])); - s->flags |= (1 << NFT_SET_ATTR_DATA_LEN); + s->flags |= (1 << NFTNL_SET_ATTR_DATA_LEN); } if (tb[NFTA_SET_ID]) { s->id = ntohl(mnl_attr_get_u32(tb[NFTA_SET_ID])); - s->flags |= (1 << NFT_SET_ATTR_ID); + s->flags |= (1 << NFTNL_SET_ATTR_ID); } if (tb[NFTA_SET_POLICY]) { s->policy = ntohl(mnl_attr_get_u32(tb[NFTA_SET_POLICY])); - s->flags |= (1 << NFT_SET_ATTR_POLICY); + s->flags |= (1 << NFTNL_SET_ATTR_POLICY); } if (tb[NFTA_SET_TIMEOUT]) { s->timeout = be64toh(mnl_attr_get_u64(tb[NFTA_SET_TIMEOUT])); - s->flags |= (1 << NFT_SET_ATTR_TIMEOUT); + s->flags |= (1 << NFTNL_SET_ATTR_TIMEOUT); } if (tb[NFTA_SET_GC_INTERVAL]) { s->gc_interval = ntohl(mnl_attr_get_u32(tb[NFTA_SET_GC_INTERVAL])); - s->flags |= (1 << NFT_SET_ATTR_GC_INTERVAL); + s->flags |= (1 << NFTNL_SET_ATTR_GC_INTERVAL); } if (tb[NFTA_SET_DESC]) - ret = nft_set_desc_parse(s, tb[NFTA_SET_DESC]); + ret = nftnl_set_desc_parse(s, tb[NFTA_SET_DESC]); s->family = nfg->nfgen_family; - s->flags |= (1 << NFT_SET_ATTR_FAMILY); + s->flags |= (1 << NFTNL_SET_ATTR_FAMILY); return ret; } EXPORT_SYMBOL(nftnl_set_nlmsg_parse, nft_set_nlmsg_parse); #ifdef JSON_PARSING -static int nft_jansson_parse_set_info(struct nft_set *s, json_t *tree, - struct nft_parse_err *err) +static int nftnl_jansson_parse_set_info(struct nftnl_set *s, json_t *tree, + struct nftnl_parse_err *err) { json_t *root = tree, *array, *json_elem; uint32_t flags, key_type, key_len, data_type, data_len, policy, size; int family, i; const char *name, *table; - struct nft_set_elem *elem; + struct nftnl_set_elem *elem; - name = nft_jansson_parse_str(root, "name", err); + name = nftnl_jansson_parse_str(root, "name", err); if (name == NULL) return -1; - nft_set_attr_set_str(s, NFT_SET_ATTR_NAME, name); + nftnl_set_attr_set_str(s, NFTNL_SET_ATTR_NAME, name); - table = nft_jansson_parse_str(root, "table", err); + table = nftnl_jansson_parse_str(root, "table", err); if (table == NULL) return -1; - nft_set_attr_set_str(s, NFT_SET_ATTR_TABLE, table); + nftnl_set_attr_set_str(s, NFTNL_SET_ATTR_TABLE, table); - if (nft_jansson_parse_family(root, &family, err) == 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_FAMILY, family); + if (nftnl_jansson_parse_family(root, &family, err) == 0) + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_FAMILY, family); - if (nft_jansson_parse_val(root, "flags", NFT_TYPE_U32, &flags, err) == 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_FLAGS, flags); + if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, err) == 0) + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_FLAGS, flags); - if (nft_jansson_parse_val(root, "key_type", NFT_TYPE_U32, &key_type, + if (nftnl_jansson_parse_val(root, "key_type", NFTNL_TYPE_U32, &key_type, err) == 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_KEY_TYPE, key_type); + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_KEY_TYPE, key_type); - if (nft_jansson_parse_val(root, "key_len", NFT_TYPE_U32, &key_len, + if (nftnl_jansson_parse_val(root, "key_len", NFTNL_TYPE_U32, &key_len, err) == 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_KEY_LEN, key_len); + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_KEY_LEN, key_len); - if (nft_jansson_node_exist(root, "data_type")) { - if (nft_jansson_parse_val(root, "data_type", NFT_TYPE_U32, + if (nftnl_jansson_node_exist(root, "data_type")) { + if (nftnl_jansson_parse_val(root, "data_type", NFTNL_TYPE_U32, &data_type, err) < 0) return -1; - nft_set_attr_set_u32(s, NFT_SET_ATTR_DATA_TYPE, data_type); + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_DATA_TYPE, data_type); } - if (nft_jansson_node_exist(root, "data_len")) { - if (nft_jansson_parse_val(root, "data_len", NFT_TYPE_U32, + if (nftnl_jansson_node_exist(root, "data_len")) { + if (nftnl_jansson_parse_val(root, "data_len", NFTNL_TYPE_U32, &data_len, err) < 0) return -1; - nft_set_attr_set_u32(s, NFT_SET_ATTR_DATA_LEN, data_len); + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_DATA_LEN, data_len); } - if (nft_jansson_node_exist(root, "policy")) { - if (nft_jansson_parse_val(root, "policy", NFT_TYPE_U32, + if (nftnl_jansson_node_exist(root, "policy")) { + if (nftnl_jansson_parse_val(root, "policy", NFTNL_TYPE_U32, &policy, err) < 0) return -1; - nft_set_attr_set_u32(s, NFT_SET_ATTR_POLICY, policy); + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_POLICY, policy); } - if (nft_jansson_node_exist(root, "desc_size")) { - if (nft_jansson_parse_val(root, "desc_size", NFT_TYPE_U32, + if (nftnl_jansson_node_exist(root, "desc_size")) { + if (nftnl_jansson_parse_val(root, "desc_size", NFTNL_TYPE_U32, &size, err) < 0) return -1; - nft_set_attr_set_u32(s, NFT_SET_ATTR_DESC_SIZE, size); + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_DESC_SIZE, size); } - if (nft_jansson_node_exist(root, "set_elem")) { + if (nftnl_jansson_node_exist(root, "set_elem")) { array = json_object_get(root, "set_elem"); for (i = 0; i < json_array_size(array); i++) { - elem = nft_set_elem_alloc(); + elem = nftnl_set_elem_alloc(); if (elem == NULL) return -1; @@ -569,7 +569,7 @@ static int nft_jansson_parse_set_info(struct nft_set *s, json_t *tree, if (json_elem == NULL) return -1; - if (nft_jansson_set_elem_parse(elem, + if (nftnl_jansson_set_elem_parse(elem, json_elem, err) < 0) return -1; @@ -581,46 +581,46 @@ static int nft_jansson_parse_set_info(struct nft_set *s, json_t *tree, return 0; } -int nft_jansson_parse_set(struct nft_set *s, json_t *tree, - struct nft_parse_err *err) +int nftnl_jansson_parse_set(struct nftnl_set *s, json_t *tree, + struct nftnl_parse_err *err) { json_t *root; - root = nft_jansson_get_node(tree, "set", err); + root = nftnl_jansson_get_node(tree, "set", err); if (root == NULL) return -1; - return nft_jansson_parse_set_info(s, root, err); + return nftnl_jansson_parse_set_info(s, root, err); } -int nft_jansson_parse_elem(struct nft_set *s, json_t *tree, - struct nft_parse_err *err) +int nftnl_jansson_parse_elem(struct nftnl_set *s, json_t *tree, + struct nftnl_parse_err *err) { json_t *root; - root = nft_jansson_get_node(tree, "element", err); + root = nftnl_jansson_get_node(tree, "element", err); if (root == NULL) return -1; - return nft_jansson_parse_set_info(s, root, err); + return nftnl_jansson_parse_set_info(s, root, err); } #endif -static int nft_set_json_parse(struct nft_set *s, const void *json, - struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_set_json_parse(struct nftnl_set *s, const void *json, + struct nftnl_parse_err *err, + enum nftnl_parse_input input) { #ifdef JSON_PARSING json_t *tree; json_error_t error; int ret; - tree = nft_jansson_create_root(json, &error, err, input); + tree = nftnl_jansson_create_root(json, &error, err, input); if (tree == NULL) return -1; - ret = nft_jansson_parse_set(s, tree, err); - nft_jansson_free_root(tree); + ret = nftnl_jansson_parse_set(s, tree, err); + nftnl_jansson_free_root(tree); return ret; #else @@ -630,68 +630,68 @@ static int nft_set_json_parse(struct nft_set *s, const void *json, } #ifdef XML_PARSING -int nft_mxml_set_parse(mxml_node_t *tree, struct nft_set *s, - struct nft_parse_err *err) +int nftnl_mxml_set_parse(mxml_node_t *tree, struct nftnl_set *s, + struct nftnl_parse_err *err) { mxml_node_t *node = NULL; - struct nft_set_elem *elem; + struct nftnl_set_elem *elem; const char *name, *table; int family; uint32_t set_flags, key_type, key_len; uint32_t data_type, data_len, policy, size; - name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + name = nftnl_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (name == NULL) return -1; - nft_set_attr_set_str(s, NFT_SET_ATTR_NAME, name); + nftnl_set_attr_set_str(s, NFTNL_SET_ATTR_NAME, name); - table = nft_mxml_str_parse(tree, "table", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + table = nftnl_mxml_str_parse(tree, "table", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (table == NULL) return -1; - nft_set_attr_set_str(s, NFT_SET_ATTR_TABLE, table); + nftnl_set_attr_set_str(s, NFTNL_SET_ATTR_TABLE, table); - family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + family = nftnl_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (family >= 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_FAMILY, family); + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_FAMILY, family); - if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, - &set_flags, NFT_TYPE_U32, NFT_XML_MAND, + if (nftnl_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, + &set_flags, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_FLAGS, set_flags); + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_FLAGS, set_flags); - if (nft_mxml_num_parse(tree, "key_type", MXML_DESCEND_FIRST, BASE_DEC, - &key_type, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_KEY_TYPE, key_type); + if (nftnl_mxml_num_parse(tree, "key_type", MXML_DESCEND_FIRST, BASE_DEC, + &key_type, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_KEY_TYPE, key_type); - if (nft_mxml_num_parse(tree, "key_len", MXML_DESCEND_FIRST, BASE_DEC, - &key_len, NFT_TYPE_U32, NFT_XML_MAND, err) < 0) + if (nftnl_mxml_num_parse(tree, "key_len", MXML_DESCEND_FIRST, BASE_DEC, + &key_len, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) < 0) return -1; - nft_set_attr_set_u32(s, NFT_SET_ATTR_KEY_LEN, key_len); + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_KEY_LEN, key_len); - if (nft_mxml_num_parse(tree, "data_type", MXML_DESCEND_FIRST, BASE_DEC, - &data_type, NFT_TYPE_U32, - NFT_XML_OPT, err) == 0) { - nft_set_attr_set_u32(s, NFT_SET_ATTR_DATA_TYPE, data_type); + if (nftnl_mxml_num_parse(tree, "data_type", MXML_DESCEND_FIRST, BASE_DEC, + &data_type, NFTNL_TYPE_U32, + NFTNL_XML_OPT, err) == 0) { + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_DATA_TYPE, data_type); - if (nft_mxml_num_parse(tree, "data_len", MXML_DESCEND_FIRST, - BASE_DEC, &data_len, NFT_TYPE_U32, - NFT_XML_MAND, err) == 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_DATA_LEN, data_len); + if (nftnl_mxml_num_parse(tree, "data_len", MXML_DESCEND_FIRST, + BASE_DEC, &data_len, NFTNL_TYPE_U32, + NFTNL_XML_MAND, err) == 0) + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_DATA_LEN, data_len); } - if (nft_mxml_num_parse(tree, "policy", MXML_DESCEND_FIRST, - BASE_DEC, &policy, NFT_TYPE_U32, - NFT_XML_OPT, err) == 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_POLICY, policy); + if (nftnl_mxml_num_parse(tree, "policy", MXML_DESCEND_FIRST, + BASE_DEC, &policy, NFTNL_TYPE_U32, + NFTNL_XML_OPT, err) == 0) + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_POLICY, policy); - if (nft_mxml_num_parse(tree, "desc_size", MXML_DESCEND_FIRST, - BASE_DEC, &size, NFT_TYPE_U32, - NFT_XML_OPT, err) == 0) - nft_set_attr_set_u32(s, NFT_SET_ATTR_DESC_SIZE, policy); + if (nftnl_mxml_num_parse(tree, "desc_size", MXML_DESCEND_FIRST, + BASE_DEC, &size, NFTNL_TYPE_U32, + NFTNL_XML_OPT, err) == 0) + nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_DESC_SIZE, policy); for (node = mxmlFindElement(tree, tree, "set_elem", NULL, NULL, MXML_DESCEND); @@ -699,11 +699,11 @@ int nft_mxml_set_parse(mxml_node_t *tree, struct nft_set *s, node = mxmlFindElement(node, tree, "set_elem", NULL, NULL, MXML_DESCEND)) { - elem = nft_set_elem_alloc(); + elem = nftnl_set_elem_alloc(); if (elem == NULL) return -1; - if (nft_mxml_set_elem_parse(node, elem, err) < 0) + if (nftnl_mxml_set_elem_parse(node, elem, err) < 0) return -1; list_add_tail(&elem->head, &s->element_list); @@ -713,17 +713,17 @@ int nft_mxml_set_parse(mxml_node_t *tree, struct nft_set *s, } #endif -static int nft_set_xml_parse(struct nft_set *s, const void *xml, - struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_set_xml_parse(struct nftnl_set *s, const void *xml, + struct nftnl_parse_err *err, + enum nftnl_parse_input input) { #ifdef XML_PARSING int ret; - mxml_node_t *tree = nft_mxml_build_tree(xml, "set", err, input); + mxml_node_t *tree = nftnl_mxml_build_tree(xml, "set", err, input); if (tree == NULL) return -1; - ret = nft_mxml_set_parse(tree, s, err); + ret = nftnl_mxml_set_parse(tree, s, err); mxmlDelete(tree); return ret; #else @@ -732,19 +732,19 @@ static int nft_set_xml_parse(struct nft_set *s, const void *xml, #endif } -static int nft_set_do_parse(struct nft_set *s, enum nft_parse_type type, - const void *data, struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_set_do_parse(struct nftnl_set *s, enum nftnl_parse_type type, + const void *data, struct nftnl_parse_err *err, + enum nftnl_parse_input input) { int ret; - struct nft_parse_err perr; + struct nftnl_parse_err perr; switch (type) { - case NFT_PARSE_XML: - ret = nft_set_xml_parse(s, data, &perr, input); + case NFTNL_PARSE_XML: + ret = nftnl_set_xml_parse(s, data, &perr, input); break; - case NFT_PARSE_JSON: - ret = nft_set_json_parse(s, data, &perr, input); + case NFTNL_PARSE_JSON: + ret = nftnl_set_json_parse(s, data, &perr, input); break; default: ret = -1; @@ -757,76 +757,76 @@ static int nft_set_do_parse(struct nft_set *s, enum nft_parse_type type, return ret; } -int nft_set_parse(struct nft_set *s, enum nft_parse_type type, - const char *data, struct nft_parse_err *err) +int nftnl_set_parse(struct nftnl_set *s, enum nftnl_parse_type type, + const char *data, struct nftnl_parse_err *err) { - return nft_set_do_parse(s, type, data, err, NFT_PARSE_BUFFER); + return nftnl_set_do_parse(s, type, data, err, NFTNL_PARSE_BUFFER); } EXPORT_SYMBOL(nftnl_set_parse, nft_set_parse); -int nft_set_parse_file(struct nft_set *s, enum nft_parse_type type, - FILE *fp, struct nft_parse_err *err) +int nftnl_set_parse_file(struct nftnl_set *s, enum nftnl_parse_type type, + FILE *fp, struct nftnl_parse_err *err) { - return nft_set_do_parse(s, type, fp, err, NFT_PARSE_FILE); + return nftnl_set_do_parse(s, type, fp, err, NFTNL_PARSE_FILE); } EXPORT_SYMBOL(nftnl_set_parse_file, nft_set_parse_file); -static int nft_set_snprintf_json(char *buf, size_t size, struct nft_set *s, +static int nftnl_set_snprintf_json(char *buf, size_t size, struct nftnl_set *s, uint32_t type, uint32_t flags) { int len = size, offset = 0, ret; - struct nft_set_elem *elem; + struct nftnl_set_elem *elem; ret = snprintf(buf, len, "{\"set\":{"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (s->flags & (1 << NFT_SET_ATTR_NAME)) { + if (s->flags & (1 << NFTNL_SET_ATTR_NAME)) { ret = snprintf(buf + offset, len, "\"name\":\"%s\"", s->name); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_TABLE)) { + if (s->flags & (1 << NFTNL_SET_ATTR_TABLE)) { ret = snprintf(buf + offset, len, ",\"table\":\"%s\"", s->table); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_FLAGS)) { + if (s->flags & (1 << NFTNL_SET_ATTR_FLAGS)) { ret = snprintf(buf + offset, len, ",\"flags\":%u", s->set_flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_FAMILY)) { + if (s->flags & (1 << NFTNL_SET_ATTR_FAMILY)) { ret = snprintf(buf + offset, len, ",\"family\":\"%s\"", - nft_family2str(s->family)); + nftnl_family2str(s->family)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_KEY_TYPE)) { + if (s->flags & (1 << NFTNL_SET_ATTR_KEY_TYPE)) { ret = snprintf(buf + offset, len, ",\"key_type\":%u", s->key_type); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_KEY_LEN)) { + if (s->flags & (1 << NFTNL_SET_ATTR_KEY_LEN)) { ret = snprintf(buf + offset, len, ",\"key_len\":%u", s->key_len); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if(s->flags & (1 << NFT_SET_ATTR_DATA_TYPE)) { + if(s->flags & (1 << NFTNL_SET_ATTR_DATA_TYPE)) { ret = snprintf(buf + offset, len, ",\"data_type\":%u", s->data_type); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if(s->flags & (1 << NFT_SET_ATTR_DATA_LEN)) { + if(s->flags & (1 << NFTNL_SET_ATTR_DATA_LEN)) { ret = snprintf(buf + offset, len, ",\"data_len\":%u", s->data_len); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_POLICY)) { + if (s->flags & (1 << NFTNL_SET_ATTR_POLICY)) { ret = snprintf(buf + offset, len, ",\"policy\":%u", s->policy); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_DESC_SIZE)) { + if (s->flags & (1 << NFTNL_SET_ATTR_DESC_SIZE)) { ret = snprintf(buf + offset, len, ",\"desc_size\":%u", s->desc.size); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -846,7 +846,7 @@ static int nft_set_snprintf_json(char *buf, size_t size, struct nft_set *s, ret = snprintf(buf + offset, len, "{"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_set_elem_snprintf(buf + offset, len, elem, type, + ret = nftnl_set_elem_snprintf(buf + offset, len, elem, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -862,35 +862,35 @@ static int nft_set_snprintf_json(char *buf, size_t size, struct nft_set *s, return offset; } -static int nft_set_snprintf_default(char *buf, size_t size, struct nft_set *s, +static int nftnl_set_snprintf_default(char *buf, size_t size, struct nftnl_set *s, uint32_t type, uint32_t flags) { int ret; int len = size, offset = 0; - struct nft_set_elem *elem; + struct nftnl_set_elem *elem; ret = snprintf(buf, len, "%s %s %x", s->name, s->table, s->set_flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (s->flags & (1 << NFT_SET_ATTR_TIMEOUT)) { + if (s->flags & (1 << NFTNL_SET_ATTR_TIMEOUT)) { ret = snprintf(buf + offset, len, " timeout %"PRIu64"ms", s->timeout); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_GC_INTERVAL)) { + if (s->flags & (1 << NFTNL_SET_ATTR_GC_INTERVAL)) { ret = snprintf(buf + offset, len, " gc_interval %ums", s->gc_interval); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_POLICY)) { + if (s->flags & (1 << NFTNL_SET_ATTR_POLICY)) { ret = snprintf(buf + offset, len, " policy %u", s->policy); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_DESC_SIZE)) { + if (s->flags & (1 << NFTNL_SET_ATTR_DESC_SIZE)) { ret = snprintf(buf + offset, len, " size %u", s->desc.size); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } @@ -906,75 +906,75 @@ static int nft_set_snprintf_default(char *buf, size_t size, struct nft_set *s, ret = snprintf(buf+offset, len, "\t"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_set_elem_snprintf(buf+offset, len, elem, type, flags); + ret = nftnl_set_elem_snprintf(buf+offset, len, elem, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } return offset; } -static int nft_set_snprintf_xml(char *buf, size_t size, struct nft_set *s, +static int nftnl_set_snprintf_xml(char *buf, size_t size, struct nftnl_set *s, uint32_t flags) { int ret; int len = size, offset = 0; - struct nft_set_elem *elem; + struct nftnl_set_elem *elem; ret = snprintf(buf, len, "<set>"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (s->flags & (1 << NFT_SET_ATTR_FAMILY)) { + if (s->flags & (1 << NFTNL_SET_ATTR_FAMILY)) { ret = snprintf(buf + offset, len, "<family>%s</family>", - nft_family2str(s->family)); + nftnl_family2str(s->family)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_TABLE)) { + if (s->flags & (1 << NFTNL_SET_ATTR_TABLE)) { ret = snprintf(buf + offset, len, "<table>%s</table>", s->table); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_NAME)) { + if (s->flags & (1 << NFTNL_SET_ATTR_NAME)) { ret = snprintf(buf + offset, len, "<name>%s</name>", s->name); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_FLAGS)) { + if (s->flags & (1 << NFTNL_SET_ATTR_FLAGS)) { ret = snprintf(buf + offset, len, "<flags>%u</flags>", s->set_flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_KEY_TYPE)) { + if (s->flags & (1 << NFTNL_SET_ATTR_KEY_TYPE)) { ret = snprintf(buf + offset, len, "<key_type>%u</key_type>", s->key_type); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_KEY_LEN)) { + if (s->flags & (1 << NFTNL_SET_ATTR_KEY_LEN)) { ret = snprintf(buf + offset, len, "<key_len>%u</key_len>", s->key_len); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_DATA_TYPE)) { + if (s->flags & (1 << NFTNL_SET_ATTR_DATA_TYPE)) { ret = snprintf(buf + offset, len, "<data_type>%u</data_type>", s->data_type); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_DATA_LEN)) { + if (s->flags & (1 << NFTNL_SET_ATTR_DATA_LEN)) { ret = snprintf(buf + offset, len, "<data_len>%u</data_len>", s->data_len); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_POLICY)) { + if (s->flags & (1 << NFTNL_SET_ATTR_POLICY)) { ret = snprintf(buf + offset, len, "<policy>%u</policy>", s->policy); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (s->flags & (1 << NFT_SET_ATTR_DESC_SIZE)) { + if (s->flags & (1 << NFTNL_SET_ATTR_DESC_SIZE)) { ret = snprintf(buf + offset, len, "<desc_size>%u</desc_size>", s->desc.size); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -982,8 +982,8 @@ static int nft_set_snprintf_xml(char *buf, size_t size, struct nft_set *s, if (!list_empty(&s->element_list)) { list_for_each_entry(elem, &s->element_list, head) { - ret = nft_set_elem_snprintf(buf + offset, len, elem, - NFT_OUTPUT_XML, flags); + ret = nftnl_set_elem_snprintf(buf + offset, len, elem, + NFTNL_OUTPUT_XML, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } } @@ -994,28 +994,28 @@ static int nft_set_snprintf_xml(char *buf, size_t size, struct nft_set *s, return offset; } -static int nft_set_cmd_snprintf(char *buf, size_t size, struct nft_set *s, +static int nftnl_set_cmd_snprintf(char *buf, size_t size, struct nftnl_set *s, uint32_t cmd, uint32_t type, uint32_t flags) { int ret, len = size, offset = 0; uint32_t inner_flags = flags; /* prevent set_elems to print as events */ - inner_flags &= ~NFT_OF_EVENT_ANY; + inner_flags &= ~NFTNL_OF_EVENT_ANY; - ret = nft_cmd_header_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_header_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); switch(type) { - case NFT_OUTPUT_DEFAULT: - ret = nft_set_snprintf_default(buf+offset, len, s, type, + case NFTNL_OUTPUT_DEFAULT: + ret = nftnl_set_snprintf_default(buf+offset, len, s, type, inner_flags); break; - case NFT_OUTPUT_XML: - ret = nft_set_snprintf_xml(buf+offset, len, s, inner_flags); + case NFTNL_OUTPUT_XML: + ret = nftnl_set_snprintf_xml(buf+offset, len, s, inner_flags); break; - case NFT_OUTPUT_JSON: - ret = nft_set_snprintf_json(buf+offset, len, s, type, + case NFTNL_OUTPUT_JSON: + ret = nftnl_set_snprintf_json(buf+offset, len, s, type, inner_flags); break; default: @@ -1024,50 +1024,50 @@ static int nft_set_cmd_snprintf(char *buf, size_t size, struct nft_set *s, SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); return offset; } -int nft_set_snprintf(char *buf, size_t size, struct nft_set *s, +int nftnl_set_snprintf(char *buf, size_t size, struct nftnl_set *s, uint32_t type, uint32_t flags) { - return nft_set_cmd_snprintf(buf, size, s, nft_flag2cmd(flags), type, + return nftnl_set_cmd_snprintf(buf, size, s, nftnl_flag2cmd(flags), type, flags); } EXPORT_SYMBOL(nftnl_set_snprintf, nft_set_snprintf); -static inline int nft_set_do_snprintf(char *buf, size_t size, void *s, +static inline int nftnl_set_do_snprintf(char *buf, size_t size, void *s, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_set_snprintf(buf, size, s, type, flags); + return nftnl_set_snprintf(buf, size, s, type, flags); } -int nft_set_fprintf(FILE *fp, struct nft_set *s, uint32_t type, +int nftnl_set_fprintf(FILE *fp, struct nftnl_set *s, uint32_t type, uint32_t flags) { - return nft_fprintf(fp, s, NFT_CMD_UNSPEC, type, flags, - nft_set_do_snprintf); + return nftnl_fprintf(fp, s, NFTNL_CMD_UNSPEC, type, flags, + nftnl_set_do_snprintf); } EXPORT_SYMBOL(nftnl_set_fprintf, nft_set_fprintf); -void nft_set_elem_add(struct nft_set *s, struct nft_set_elem *elem) +void nftnl_set_elem_add(struct nftnl_set *s, struct nftnl_set_elem *elem) { list_add_tail(&elem->head, &s->element_list); } EXPORT_SYMBOL(nftnl_set_elem_add, nft_set_elem_add); -struct nft_set_list { +struct nftnl_set_list { struct list_head list; }; -struct nft_set_list *nft_set_list_alloc(void) +struct nftnl_set_list *nftnl_set_list_alloc(void) { - struct nft_set_list *list; + struct nftnl_set_list *list; - list = calloc(1, sizeof(struct nft_set_list)); + list = calloc(1, sizeof(struct nftnl_set_list)); if (list == NULL) return NULL; @@ -1077,46 +1077,46 @@ struct nft_set_list *nft_set_list_alloc(void) } EXPORT_SYMBOL(nftnl_set_list_alloc, nft_set_list_alloc); -void nft_set_list_free(struct nft_set_list *list) +void nftnl_set_list_free(struct nftnl_set_list *list) { - struct nft_set *s, *tmp; + struct nftnl_set *s, *tmp; list_for_each_entry_safe(s, tmp, &list->list, head) { list_del(&s->head); - nft_set_free(s); + nftnl_set_free(s); } xfree(list); } EXPORT_SYMBOL(nftnl_set_list_free, nft_set_list_free); -int nft_set_list_is_empty(struct nft_set_list *list) +int nftnl_set_list_is_empty(struct nftnl_set_list *list) { return list_empty(&list->list); } EXPORT_SYMBOL(nftnl_set_list_is_empty, nft_set_list_is_empty); -void nft_set_list_add(struct nft_set *s, struct nft_set_list *list) +void nftnl_set_list_add(struct nftnl_set *s, struct nftnl_set_list *list) { list_add(&s->head, &list->list); } EXPORT_SYMBOL(nftnl_set_list_add, nft_set_list_add); -void nft_set_list_add_tail(struct nft_set *s, struct nft_set_list *list) +void nftnl_set_list_add_tail(struct nftnl_set *s, struct nftnl_set_list *list) { list_add_tail(&s->head, &list->list); } EXPORT_SYMBOL(nftnl_set_list_add_tail, nft_set_list_add_tail); -void nft_set_list_del(struct nft_set *s) +void nftnl_set_list_del(struct nftnl_set *s) { list_del(&s->head); } EXPORT_SYMBOL(nftnl_set_list_del, nft_set_list_del); -int nft_set_list_foreach(struct nft_set_list *set_list, - int (*cb)(struct nft_set *t, void *data), void *data) +int nftnl_set_list_foreach(struct nftnl_set_list *set_list, + int (*cb)(struct nftnl_set *t, void *data), void *data) { - struct nft_set *cur, *tmp; + struct nftnl_set *cur, *tmp; int ret; list_for_each_entry_safe(cur, tmp, &set_list->list, head) { @@ -1128,44 +1128,44 @@ int nft_set_list_foreach(struct nft_set_list *set_list, } EXPORT_SYMBOL(nftnl_set_list_foreach, nft_set_list_foreach); -struct nft_set_list_iter { - struct nft_set_list *list; - struct nft_set *cur; +struct nftnl_set_list_iter { + struct nftnl_set_list *list; + struct nftnl_set *cur; }; -struct nft_set_list_iter *nft_set_list_iter_create(struct nft_set_list *l) +struct nftnl_set_list_iter *nftnl_set_list_iter_create(struct nftnl_set_list *l) { - struct nft_set_list_iter *iter; + struct nftnl_set_list_iter *iter; - iter = calloc(1, sizeof(struct nft_set_list_iter)); + iter = calloc(1, sizeof(struct nftnl_set_list_iter)); if (iter == NULL) return NULL; iter->list = l; - if (nft_set_list_is_empty(l)) + if (nftnl_set_list_is_empty(l)) iter->cur = NULL; else - iter->cur = list_entry(l->list.next, struct nft_set, head); + iter->cur = list_entry(l->list.next, struct nftnl_set, head); return iter; } EXPORT_SYMBOL(nftnl_set_list_iter_create, nft_set_list_iter_create); -struct nft_set *nft_set_list_iter_cur(struct nft_set_list_iter *iter) +struct nftnl_set *nftnl_set_list_iter_cur(struct nftnl_set_list_iter *iter) { return iter->cur; } EXPORT_SYMBOL(nftnl_set_list_iter_cur, nft_set_list_iter_cur); -struct nft_set *nft_set_list_iter_next(struct nft_set_list_iter *iter) +struct nftnl_set *nftnl_set_list_iter_next(struct nftnl_set_list_iter *iter) { - struct nft_set *s = iter->cur; + struct nftnl_set *s = iter->cur; if (s == NULL) return NULL; /* get next rule, if any */ - iter->cur = list_entry(iter->cur->head.next, struct nft_set, head); + iter->cur = list_entry(iter->cur->head.next, struct nftnl_set, head); if (&iter->cur->head == iter->list->list.next) return NULL; @@ -1173,50 +1173,50 @@ struct nft_set *nft_set_list_iter_next(struct nft_set_list_iter *iter) } EXPORT_SYMBOL(nftnl_set_list_iter_next, nft_set_list_iter_next); -void nft_set_list_iter_destroy(struct nft_set_list_iter *iter) +void nftnl_set_list_iter_destroy(struct nftnl_set_list_iter *iter) { xfree(iter); } EXPORT_SYMBOL(nftnl_set_list_iter_destroy, nft_set_list_iter_destroy); -static struct nft_set *nft_set_lookup(const char *this_set_name, - struct nft_set_list *set_list) +static struct nftnl_set *nftnl_set_lookup(const char *this_set_name, + struct nftnl_set_list *set_list) { - struct nft_set_list_iter *iter; - struct nft_set *s; + struct nftnl_set_list_iter *iter; + struct nftnl_set *s; const char *set_name; - iter = nft_set_list_iter_create(set_list); + iter = nftnl_set_list_iter_create(set_list); if (iter == NULL) return NULL; - s = nft_set_list_iter_cur(iter); + s = nftnl_set_list_iter_cur(iter); while (s != NULL) { - set_name = nft_set_attr_get_str(s, NFT_SET_ATTR_NAME); + set_name = nftnl_set_attr_get_str(s, NFTNL_SET_ATTR_NAME); if (strcmp(this_set_name, set_name) == 0) break; - s = nft_set_list_iter_next(iter); + s = nftnl_set_list_iter_next(iter); } - nft_set_list_iter_destroy(iter); + nftnl_set_list_iter_destroy(iter); return s; } -int nft_set_lookup_id(struct nft_rule_expr *e, - struct nft_set_list *set_list, uint32_t *set_id) +int nftnl_set_lookup_id(struct nftnl_rule_expr *e, + struct nftnl_set_list *set_list, uint32_t *set_id) { const char *set_name; - struct nft_set *s; + struct nftnl_set *s; - set_name = nft_rule_expr_get_str(e, NFT_EXPR_LOOKUP_SET); + set_name = nftnl_rule_expr_get_str(e, NFTNL_EXPR_LOOKUP_SET); if (set_name == NULL) return 0; - s = nft_set_lookup(set_name, set_list); + s = nftnl_set_lookup(set_name, set_list); if (s == NULL) return 0; - *set_id = nft_set_attr_get_u32(s, NFT_SET_ATTR_ID); + *set_id = nftnl_set_attr_get_u32(s, NFTNL_SET_ATTR_ID); return 1; } diff --git a/src/set_elem.c b/src/set_elem.c index a130cc3..4f68787 100644 --- a/src/set_elem.c +++ b/src/set_elem.c @@ -27,11 +27,11 @@ #include <libnftnl/rule.h> #include <libnftnl/expr.h> -struct nft_set_elem *nft_set_elem_alloc(void) +struct nftnl_set_elem *nftnl_set_elem_alloc(void) { - struct nft_set_elem *s; + struct nftnl_set_elem *s; - s = calloc(1, sizeof(struct nft_set_elem)); + s = calloc(1, sizeof(struct nftnl_set_elem)); if (s == NULL) return NULL; @@ -39,50 +39,50 @@ struct nft_set_elem *nft_set_elem_alloc(void) } EXPORT_SYMBOL(nftnl_set_elem_alloc, nft_set_elem_alloc); -void nft_set_elem_free(struct nft_set_elem *s) +void nftnl_set_elem_free(struct nftnl_set_elem *s) { - if (s->flags & (1 << NFT_SET_ELEM_ATTR_CHAIN)) { + if (s->flags & (1 << NFTNL_SET_ELEM_ATTR_CHAIN)) { if (s->data.chain) { xfree(s->data.chain); s->data.chain = NULL; } } - if (s->flags & (1 << NFT_SET_ELEM_ATTR_EXPR)) - nft_rule_expr_free(s->expr); + if (s->flags & (1 << NFTNL_SET_ELEM_ATTR_EXPR)) + nftnl_rule_expr_free(s->expr); xfree(s); } EXPORT_SYMBOL(nftnl_set_elem_free, nft_set_elem_free); -bool nft_set_elem_attr_is_set(const struct nft_set_elem *s, uint16_t attr) +bool nftnl_set_elem_attr_is_set(const struct nftnl_set_elem *s, uint16_t attr) { return s->flags & (1 << attr); } EXPORT_SYMBOL(nftnl_set_elem_attr_is_set, nft_set_elem_attr_is_set); -void nft_set_elem_attr_unset(struct nft_set_elem *s, uint16_t attr) +void nftnl_set_elem_attr_unset(struct nftnl_set_elem *s, uint16_t attr) { switch (attr) { - case NFT_SET_ELEM_ATTR_CHAIN: - if (s->flags & (1 << NFT_SET_ELEM_ATTR_CHAIN)) { + case NFTNL_SET_ELEM_ATTR_CHAIN: + if (s->flags & (1 << NFTNL_SET_ELEM_ATTR_CHAIN)) { if (s->data.chain) { xfree(s->data.chain); s->data.chain = NULL; } } break; - case NFT_SET_ELEM_ATTR_FLAGS: - case NFT_SET_ELEM_ATTR_KEY: /* NFTA_SET_ELEM_KEY */ - case NFT_SET_ELEM_ATTR_VERDICT: /* NFTA_SET_ELEM_DATA */ - case NFT_SET_ELEM_ATTR_DATA: /* NFTA_SET_ELEM_DATA */ - case NFT_SET_ELEM_ATTR_TIMEOUT: /* NFTA_SET_ELEM_TIMEOUT */ - case NFT_SET_ELEM_ATTR_EXPIRATION: /* NFTA_SET_ELEM_EXPIRATION */ - case NFT_SET_ELEM_ATTR_USERDATA: /* NFTA_SET_ELEM_USERDATA */ + case NFTNL_SET_ELEM_ATTR_FLAGS: + case NFTNL_SET_ELEM_ATTR_KEY: /* NFTA_SET_ELEM_KEY */ + case NFTNL_SET_ELEM_ATTR_VERDICT: /* NFTA_SET_ELEM_DATA */ + case NFTNL_SET_ELEM_ATTR_DATA: /* NFTA_SET_ELEM_DATA */ + case NFTNL_SET_ELEM_ATTR_TIMEOUT: /* NFTA_SET_ELEM_TIMEOUT */ + case NFTNL_SET_ELEM_ATTR_EXPIRATION: /* NFTA_SET_ELEM_EXPIRATION */ + case NFTNL_SET_ELEM_ATTR_USERDATA: /* NFTA_SET_ELEM_USERDATA */ break; - case NFT_SET_ELEM_ATTR_EXPR: - if (s->flags & (1 << NFT_SET_ELEM_ATTR_EXPR)) { - nft_rule_expr_free(s->expr); + case NFTNL_SET_ELEM_ATTR_EXPR: + if (s->flags & (1 << NFTNL_SET_ELEM_ATTR_EXPR)) { + nftnl_rule_expr_free(s->expr); s->expr = NULL; } break; @@ -94,34 +94,34 @@ void nft_set_elem_attr_unset(struct nft_set_elem *s, uint16_t attr) } EXPORT_SYMBOL(nftnl_set_elem_attr_unset, nft_set_elem_attr_unset); -void nft_set_elem_attr_set(struct nft_set_elem *s, uint16_t attr, +void nftnl_set_elem_attr_set(struct nftnl_set_elem *s, uint16_t attr, const void *data, uint32_t data_len) { switch(attr) { - case NFT_SET_ELEM_ATTR_FLAGS: + case NFTNL_SET_ELEM_ATTR_FLAGS: s->set_elem_flags = *((uint32_t *)data); break; - case NFT_SET_ELEM_ATTR_KEY: /* NFTA_SET_ELEM_KEY */ + case NFTNL_SET_ELEM_ATTR_KEY: /* NFTA_SET_ELEM_KEY */ memcpy(&s->key.val, data, data_len); s->key.len = data_len; break; - case NFT_SET_ELEM_ATTR_VERDICT: /* NFTA_SET_ELEM_DATA */ + case NFTNL_SET_ELEM_ATTR_VERDICT: /* NFTA_SET_ELEM_DATA */ s->data.verdict = *((uint32_t *)data); break; - case NFT_SET_ELEM_ATTR_CHAIN: /* NFTA_SET_ELEM_DATA */ + case NFTNL_SET_ELEM_ATTR_CHAIN: /* NFTA_SET_ELEM_DATA */ if (s->data.chain) xfree(s->data.chain); s->data.chain = strdup(data); break; - case NFT_SET_ELEM_ATTR_DATA: /* NFTA_SET_ELEM_DATA */ + case NFTNL_SET_ELEM_ATTR_DATA: /* NFTA_SET_ELEM_DATA */ memcpy(s->data.val, data, data_len); s->data.len = data_len; break; - case NFT_SET_ELEM_ATTR_TIMEOUT: /* NFTA_SET_ELEM_TIMEOUT */ + case NFTNL_SET_ELEM_ATTR_TIMEOUT: /* NFTA_SET_ELEM_TIMEOUT */ s->timeout = *((uint64_t *)data); break; - case NFT_SET_ELEM_ATTR_USERDATA: /* NFTA_SET_ELEM_USERDATA */ + case NFTNL_SET_ELEM_ATTR_USERDATA: /* NFTA_SET_ELEM_USERDATA */ s->user.data = (void *)data; s->user.len = data_len; break; @@ -132,173 +132,173 @@ void nft_set_elem_attr_set(struct nft_set_elem *s, uint16_t attr, } EXPORT_SYMBOL(nftnl_set_elem_attr_set, nft_set_elem_attr_set); -void nft_set_elem_attr_set_u32(struct nft_set_elem *s, uint16_t attr, uint32_t val) +void nftnl_set_elem_attr_set_u32(struct nftnl_set_elem *s, uint16_t attr, uint32_t val) { - nft_set_elem_attr_set(s, attr, &val, sizeof(uint32_t)); + nftnl_set_elem_attr_set(s, attr, &val, sizeof(uint32_t)); } EXPORT_SYMBOL(nftnl_set_elem_attr_set_u32, nft_set_elem_attr_set_u32); -void nft_set_elem_attr_set_u64(struct nft_set_elem *s, uint16_t attr, uint64_t val) +void nftnl_set_elem_attr_set_u64(struct nftnl_set_elem *s, uint16_t attr, uint64_t val) { - nft_set_elem_attr_set(s, attr, &val, sizeof(uint64_t)); + nftnl_set_elem_attr_set(s, attr, &val, sizeof(uint64_t)); } EXPORT_SYMBOL(nftnl_set_elem_attr_set_u64, nft_set_elem_attr_set_u64); -void nft_set_elem_attr_set_str(struct nft_set_elem *s, uint16_t attr, const char *str) +void nftnl_set_elem_attr_set_str(struct nftnl_set_elem *s, uint16_t attr, const char *str) { - nft_set_elem_attr_set(s, attr, str, strlen(str)); + nftnl_set_elem_attr_set(s, attr, str, strlen(str)); } EXPORT_SYMBOL(nftnl_set_elem_attr_set_str, nft_set_elem_attr_set_str); -const void *nft_set_elem_attr_get(struct nft_set_elem *s, uint16_t attr, uint32_t *data_len) +const void *nftnl_set_elem_attr_get(struct nftnl_set_elem *s, uint16_t attr, uint32_t *data_len) { if (!(s->flags & (1 << attr))) return NULL; switch(attr) { - case NFT_SET_ELEM_ATTR_FLAGS: + case NFTNL_SET_ELEM_ATTR_FLAGS: return &s->set_elem_flags; - case NFT_SET_ELEM_ATTR_KEY: /* NFTA_SET_ELEM_KEY */ + case NFTNL_SET_ELEM_ATTR_KEY: /* NFTA_SET_ELEM_KEY */ *data_len = s->key.len; return &s->key.val; - case NFT_SET_ELEM_ATTR_VERDICT: /* NFTA_SET_ELEM_DATA */ + case NFTNL_SET_ELEM_ATTR_VERDICT: /* NFTA_SET_ELEM_DATA */ return &s->data.verdict; - case NFT_SET_ELEM_ATTR_CHAIN: /* NFTA_SET_ELEM_DATA */ + case NFTNL_SET_ELEM_ATTR_CHAIN: /* NFTA_SET_ELEM_DATA */ return s->data.chain; - case NFT_SET_ELEM_ATTR_DATA: /* NFTA_SET_ELEM_DATA */ + case NFTNL_SET_ELEM_ATTR_DATA: /* NFTA_SET_ELEM_DATA */ *data_len = s->data.len; return &s->data.val; - case NFT_SET_ELEM_ATTR_TIMEOUT: /* NFTA_SET_ELEM_TIMEOUT */ + case NFTNL_SET_ELEM_ATTR_TIMEOUT: /* NFTA_SET_ELEM_TIMEOUT */ return &s->timeout; - case NFT_SET_ELEM_ATTR_EXPIRATION: /* NFTA_SET_ELEM_EXPIRATION */ + case NFTNL_SET_ELEM_ATTR_EXPIRATION: /* NFTA_SET_ELEM_EXPIRATION */ return &s->expiration; - case NFT_SET_ELEM_ATTR_USERDATA: + case NFTNL_SET_ELEM_ATTR_USERDATA: *data_len = s->user.len; return s->user.data; - case NFT_SET_ELEM_ATTR_EXPR: + case NFTNL_SET_ELEM_ATTR_EXPR: return s->expr; } return NULL; } EXPORT_SYMBOL(nftnl_set_elem_attr_get, nft_set_elem_attr_get); -const char *nft_set_elem_attr_get_str(struct nft_set_elem *s, uint16_t attr) +const char *nftnl_set_elem_attr_get_str(struct nftnl_set_elem *s, uint16_t attr) { uint32_t size; - return nft_set_elem_attr_get(s, attr, &size); + return nftnl_set_elem_attr_get(s, attr, &size); } EXPORT_SYMBOL(nftnl_set_elem_attr_get_str, nft_set_elem_attr_get_str); -uint32_t nft_set_elem_attr_get_u32(struct nft_set_elem *s, uint16_t attr) +uint32_t nftnl_set_elem_attr_get_u32(struct nftnl_set_elem *s, uint16_t attr) { uint32_t size; - uint32_t val = *((uint32_t *)nft_set_elem_attr_get(s, attr, &size)); + uint32_t val = *((uint32_t *)nftnl_set_elem_attr_get(s, attr, &size)); return val; } EXPORT_SYMBOL(nftnl_set_elem_attr_get_u32, nft_set_elem_attr_get_u32); -uint64_t nft_set_elem_attr_get_u64(struct nft_set_elem *s, uint16_t attr) +uint64_t nftnl_set_elem_attr_get_u64(struct nftnl_set_elem *s, uint16_t attr) { uint32_t size; - uint64_t val = *((uint64_t *)nft_set_elem_attr_get(s, attr, &size)); + uint64_t val = *((uint64_t *)nftnl_set_elem_attr_get(s, attr, &size)); return val; } EXPORT_SYMBOL(nftnl_set_elem_attr_get_u64, nft_set_elem_attr_get_u64); -struct nft_set_elem *nft_set_elem_clone(struct nft_set_elem *elem) +struct nftnl_set_elem *nftnl_set_elem_clone(struct nftnl_set_elem *elem) { - struct nft_set_elem *newelem; + struct nftnl_set_elem *newelem; - newelem = nft_set_elem_alloc(); + newelem = nftnl_set_elem_alloc(); if (newelem == NULL) return NULL; memcpy(newelem, elem, sizeof(*elem)); - if (elem->flags & (1 << NFT_SET_ELEM_ATTR_CHAIN)) + if (elem->flags & (1 << NFTNL_SET_ELEM_ATTR_CHAIN)) newelem->data.chain = strdup(elem->data.chain); return newelem; } -void nft_set_elem_nlmsg_build_payload(struct nlmsghdr *nlh, - struct nft_set_elem *e) +void nftnl_set_elem_nlmsg_build_payload(struct nlmsghdr *nlh, + struct nftnl_set_elem *e) { - if (e->flags & (1 << NFT_SET_ELEM_ATTR_FLAGS)) + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_FLAGS)) mnl_attr_put_u32(nlh, NFTA_SET_ELEM_FLAGS, htonl(e->set_elem_flags)); - if (e->flags & (1 << NFT_SET_ELEM_ATTR_TIMEOUT)) + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_TIMEOUT)) mnl_attr_put_u64(nlh, NFTA_SET_ELEM_TIMEOUT, htobe64(e->timeout)); - if (e->flags & (1 << NFT_SET_ELEM_ATTR_KEY)) { + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_KEY)) { struct nlattr *nest1; nest1 = mnl_attr_nest_start(nlh, NFTA_SET_ELEM_KEY); mnl_attr_put(nlh, NFTA_DATA_VALUE, e->key.len, e->key.val); mnl_attr_nest_end(nlh, nest1); } - if (e->flags & (1 << NFT_SET_ELEM_ATTR_VERDICT)) { + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_VERDICT)) { struct nlattr *nest1, *nest2; nest1 = mnl_attr_nest_start(nlh, NFTA_SET_ELEM_DATA); nest2 = mnl_attr_nest_start(nlh, NFTA_DATA_VERDICT); mnl_attr_put_u32(nlh, NFTA_VERDICT_CODE, htonl(e->data.verdict)); - if (e->flags & (1 << NFT_SET_ELEM_ATTR_CHAIN)) + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_CHAIN)) mnl_attr_put_strz(nlh, NFTA_VERDICT_CHAIN, e->data.chain); mnl_attr_nest_end(nlh, nest1); mnl_attr_nest_end(nlh, nest2); } - if (e->flags & (1 << NFT_SET_ELEM_ATTR_DATA)) { + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_DATA)) { struct nlattr *nest1; nest1 = mnl_attr_nest_start(nlh, NFTA_SET_ELEM_DATA); mnl_attr_put(nlh, NFTA_DATA_VALUE, e->data.len, e->data.val); mnl_attr_nest_end(nlh, nest1); } - if (e->flags & (1 << NFT_SET_ELEM_ATTR_USERDATA)) + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_USERDATA)) mnl_attr_put(nlh, NFTA_SET_ELEM_USERDATA, e->user.len, e->user.data); } -static void nft_set_elem_nlmsg_build_def(struct nlmsghdr *nlh, - struct nft_set *s) +static void nftnl_set_elem_nlmsg_build_def(struct nlmsghdr *nlh, + struct nftnl_set *s) { - if (s->flags & (1 << NFT_SET_ATTR_NAME)) + if (s->flags & (1 << NFTNL_SET_ATTR_NAME)) mnl_attr_put_strz(nlh, NFTA_SET_ELEM_LIST_SET, s->name); - if (s->flags & (1 << NFT_SET_ATTR_ID)) + if (s->flags & (1 << NFTNL_SET_ATTR_ID)) mnl_attr_put_u32(nlh, NFTA_SET_ELEM_LIST_SET_ID, htonl(s->id)); - if (s->flags & (1 << NFT_SET_ATTR_TABLE)) + if (s->flags & (1 << NFTNL_SET_ATTR_TABLE)) mnl_attr_put_strz(nlh, NFTA_SET_ELEM_LIST_TABLE, s->table); } -static struct nlattr *nft_set_elem_attr_build(struct nlmsghdr *nlh, - struct nft_set_elem *elem, int i) +static struct nlattr *nftnl_set_elem_attr_build(struct nlmsghdr *nlh, + struct nftnl_set_elem *elem, int i) { struct nlattr *nest2; nest2 = mnl_attr_nest_start(nlh, i); - nft_set_elem_nlmsg_build_payload(nlh, elem); + nftnl_set_elem_nlmsg_build_payload(nlh, elem); mnl_attr_nest_end(nlh, nest2); return nest2; } -void nft_set_elems_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set *s) +void nftnl_set_elems_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_set *s) { - struct nft_set_elem *elem; + struct nftnl_set_elem *elem; struct nlattr *nest1; int i = 0; - nft_set_elem_nlmsg_build_def(nlh, s); + nftnl_set_elem_nlmsg_build_def(nlh, s); nest1 = mnl_attr_nest_start(nlh, NFTA_SET_ELEM_LIST_ELEMENTS); list_for_each_entry(elem, &s->element_list, head) - nft_set_elem_attr_build(nlh, elem, ++i); + nftnl_set_elem_attr_build(nlh, elem, ++i); mnl_attr_nest_end(nlh, nest1); } EXPORT_SYMBOL(nftnl_set_elems_nlmsg_build_payload, nft_set_elems_nlmsg_build_payload); -static int nft_set_elem_parse_attr_cb(const struct nlattr *attr, void *data) +static int nftnl_set_elem_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -332,58 +332,58 @@ static int nft_set_elem_parse_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_set_elems_parse2(struct nft_set *s, const struct nlattr *nest) +static int nftnl_set_elems_parse2(struct nftnl_set *s, const struct nlattr *nest) { struct nlattr *tb[NFTA_SET_ELEM_MAX+1] = {}; - struct nft_set_elem *e; + struct nftnl_set_elem *e; int ret = 0, type; - e = nft_set_elem_alloc(); + e = nftnl_set_elem_alloc(); if (e == NULL) return -1; - if (mnl_attr_parse_nested(nest, nft_set_elem_parse_attr_cb, tb) < 0) { - nft_set_elem_free(e); + if (mnl_attr_parse_nested(nest, nftnl_set_elem_parse_attr_cb, tb) < 0) { + nftnl_set_elem_free(e); return -1; } if (tb[NFTA_SET_ELEM_FLAGS]) { e->set_elem_flags = ntohl(mnl_attr_get_u32(tb[NFTA_SET_ELEM_FLAGS])); - e->flags |= (1 << NFT_SET_ELEM_ATTR_FLAGS); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_FLAGS); } if (tb[NFTA_SET_ELEM_TIMEOUT]) { e->timeout = be64toh(mnl_attr_get_u64(tb[NFTA_SET_ELEM_TIMEOUT])); - e->flags |= (1 << NFT_SET_ELEM_ATTR_TIMEOUT); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_TIMEOUT); } if (tb[NFTA_SET_ELEM_EXPIRATION]) { e->expiration = be64toh(mnl_attr_get_u64(tb[NFTA_SET_ELEM_EXPIRATION])); - e->flags |= (1 << NFT_SET_ELEM_ATTR_EXPIRATION); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_EXPIRATION); } if (tb[NFTA_SET_ELEM_KEY]) { - ret = nft_parse_data(&e->key, tb[NFTA_SET_ELEM_KEY], &type); - e->flags |= (1 << NFT_SET_ELEM_ATTR_KEY); + ret = nftnl_parse_data(&e->key, tb[NFTA_SET_ELEM_KEY], &type); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_KEY); } if (tb[NFTA_SET_ELEM_DATA]) { - ret = nft_parse_data(&e->data, tb[NFTA_SET_ELEM_DATA], &type); + ret = nftnl_parse_data(&e->data, tb[NFTA_SET_ELEM_DATA], &type); switch(type) { case DATA_VERDICT: - e->flags |= (1 << NFT_SET_ELEM_ATTR_VERDICT); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_VERDICT); break; case DATA_CHAIN: - e->flags |= (1 << NFT_SET_ELEM_ATTR_VERDICT) | - (1 << NFT_SET_ELEM_ATTR_CHAIN); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_VERDICT) | + (1 << NFTNL_SET_ELEM_ATTR_CHAIN); break; case DATA_VALUE: - e->flags |= (1 << NFT_SET_ELEM_ATTR_DATA); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_DATA); break; } } if (tb[NFTA_SET_ELEM_EXPR]) { - e->expr = nft_rule_expr_parse(tb[NFTA_SET_ELEM_EXPR]); + e->expr = nftnl_rule_expr_parse(tb[NFTA_SET_ELEM_EXPR]); if (e->expr == NULL) goto err; - e->flags |= (1 << NFT_SET_ELEM_ATTR_EXPR); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_EXPR); } if (tb[NFTA_SET_ELEM_USERDATA]) { const void *udata = @@ -397,12 +397,12 @@ static int nft_set_elems_parse2(struct nft_set *s, const struct nlattr *nest) if (e->user.data == NULL) goto err; memcpy(e->user.data, udata, e->user.len); - e->flags |= (1 << NFT_RULE_ATTR_USERDATA); + e->flags |= (1 << NFTNL_RULE_ATTR_USERDATA); } if (ret < 0) { err: - nft_set_elem_free(e); + nftnl_set_elem_free(e); return -1; } @@ -413,7 +413,7 @@ err: } static int -nft_set_elem_list_parse_attr_cb(const struct nlattr *attr, void *data) +nftnl_set_elem_list_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -437,7 +437,7 @@ nft_set_elem_list_parse_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_set_elems_parse(struct nft_set *s, const struct nlattr *nest) +static int nftnl_set_elems_parse(struct nftnl_set *s, const struct nlattr *nest) { struct nlattr *attr; int ret = 0; @@ -446,74 +446,74 @@ static int nft_set_elems_parse(struct nft_set *s, const struct nlattr *nest) if (mnl_attr_get_type(attr) != NFTA_LIST_ELEM) return -1; - ret = nft_set_elems_parse2(s, attr); + ret = nftnl_set_elems_parse2(s, attr); } return ret; } -int nft_set_elems_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s) +int nftnl_set_elems_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s) { struct nlattr *tb[NFTA_SET_ELEM_LIST_MAX+1] = {}; struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh); int ret = 0; if (mnl_attr_parse(nlh, sizeof(*nfg), - nft_set_elem_list_parse_attr_cb, tb) < 0) + nftnl_set_elem_list_parse_attr_cb, tb) < 0) return -1; if (tb[NFTA_SET_ELEM_LIST_TABLE]) { xfree(s->table); s->table = strdup(mnl_attr_get_str(tb[NFTA_SET_ELEM_LIST_TABLE])); - s->flags |= (1 << NFT_SET_ATTR_TABLE); + s->flags |= (1 << NFTNL_SET_ATTR_TABLE); } if (tb[NFTA_SET_ELEM_LIST_SET]) { xfree(s->name); s->name = strdup(mnl_attr_get_str(tb[NFTA_SET_ELEM_LIST_SET])); - s->flags |= (1 << NFT_SET_ATTR_NAME); + s->flags |= (1 << NFTNL_SET_ATTR_NAME); } if (tb[NFTA_SET_ELEM_LIST_SET_ID]) { s->id = ntohl(mnl_attr_get_u32(tb[NFTA_SET_ELEM_LIST_SET_ID])); - s->flags |= (1 << NFT_SET_ATTR_ID); + s->flags |= (1 << NFTNL_SET_ATTR_ID); } if (tb[NFTA_SET_ELEM_LIST_ELEMENTS]) - ret = nft_set_elems_parse(s, tb[NFTA_SET_ELEM_LIST_ELEMENTS]); + ret = nftnl_set_elems_parse(s, tb[NFTA_SET_ELEM_LIST_ELEMENTS]); s->family = nfg->nfgen_family; - s->flags |= (1 << NFT_SET_ATTR_FAMILY); + s->flags |= (1 << NFTNL_SET_ATTR_FAMILY); return ret; } EXPORT_SYMBOL(nftnl_set_elems_nlmsg_parse, nft_set_elems_nlmsg_parse); #ifdef XML_PARSING -int nft_mxml_set_elem_parse(mxml_node_t *tree, struct nft_set_elem *e, - struct nft_parse_err *err) +int nftnl_mxml_set_elem_parse(mxml_node_t *tree, struct nftnl_set_elem *e, + struct nftnl_parse_err *err) { int set_elem_data; uint32_t set_elem_flags; - if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, - &set_elem_flags, NFT_TYPE_U32, NFT_XML_MAND, + if (nftnl_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC, + &set_elem_flags, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) - nft_set_elem_attr_set_u32(e, NFT_SET_ELEM_ATTR_FLAGS, set_elem_flags); + nftnl_set_elem_attr_set_u32(e, NFTNL_SET_ELEM_ATTR_FLAGS, set_elem_flags); - if (nft_mxml_data_reg_parse(tree, "key", &e->key, - NFT_XML_MAND, err) == DATA_VALUE) - e->flags |= (1 << NFT_SET_ELEM_ATTR_KEY); + if (nftnl_mxml_data_reg_parse(tree, "key", &e->key, + NFTNL_XML_MAND, err) == DATA_VALUE) + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_KEY); /* <set_elem_data> is not mandatory */ - set_elem_data = nft_mxml_data_reg_parse(tree, "data", - &e->data, NFT_XML_OPT, err); + set_elem_data = nftnl_mxml_data_reg_parse(tree, "data", + &e->data, NFTNL_XML_OPT, err); switch (set_elem_data) { case DATA_VALUE: - e->flags |= (1 << NFT_SET_ELEM_ATTR_DATA); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_DATA); break; case DATA_VERDICT: - e->flags |= (1 << NFT_SET_ELEM_ATTR_VERDICT); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_VERDICT); if (e->data.chain != NULL) - e->flags |= (1 << NFT_SET_ELEM_ATTR_CHAIN); + e->flags |= (1 << NFTNL_SET_ELEM_ATTR_CHAIN); break; } @@ -522,19 +522,19 @@ int nft_mxml_set_elem_parse(mxml_node_t *tree, struct nft_set_elem *e, } #endif -static int nft_set_elem_xml_parse(struct nft_set_elem *e, const void *xml, - struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_set_elem_xml_parse(struct nftnl_set_elem *e, const void *xml, + struct nftnl_parse_err *err, + enum nftnl_parse_input input) { #ifdef XML_PARSING mxml_node_t *tree; int ret; - tree = nft_mxml_build_tree(xml, "set_elem", err, input); + tree = nftnl_mxml_build_tree(xml, "set_elem", err, input); if (tree == NULL) return -1; - ret = nft_mxml_set_elem_parse(tree, e, err); + ret = nftnl_mxml_set_elem_parse(tree, e, err); mxmlDelete(tree); return ret; #else @@ -543,19 +543,19 @@ static int nft_set_elem_xml_parse(struct nft_set_elem *e, const void *xml, #endif } -static int nft_set_elem_json_parse(struct nft_set_elem *e, const void *json, - struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_set_elem_json_parse(struct nftnl_set_elem *e, const void *json, + struct nftnl_parse_err *err, + enum nftnl_parse_input input) { #ifdef JSON_PARSING json_t *tree; json_error_t error; - tree = nft_jansson_create_root(json, &error, err, input); + tree = nftnl_jansson_create_root(json, &error, err, input); if (tree == NULL) return -1; - return nft_jansson_set_elem_parse(e, tree, err); + return nftnl_jansson_set_elem_parse(e, tree, err); #else errno = EOPNOTSUPP; return -1; @@ -563,18 +563,18 @@ static int nft_set_elem_json_parse(struct nft_set_elem *e, const void *json, } static int -nft_set_elem_do_parse(struct nft_set_elem *e, enum nft_parse_type type, - const void *data, struct nft_parse_err *err, - enum nft_parse_input input) +nftnl_set_elem_do_parse(struct nftnl_set_elem *e, enum nftnl_parse_type type, + const void *data, struct nftnl_parse_err *err, + enum nftnl_parse_input input) { int ret; switch (type) { - case NFT_PARSE_XML: - ret = nft_set_elem_xml_parse(e, data, err, input); + case NFTNL_PARSE_XML: + ret = nftnl_set_elem_xml_parse(e, data, err, input); break; - case NFT_PARSE_JSON: - ret = nft_set_elem_json_parse(e, data, err, input); + case NFTNL_PARSE_JSON: + ret = nftnl_set_elem_json_parse(e, data, err, input); break; default: errno = EOPNOTSUPP; @@ -584,26 +584,26 @@ nft_set_elem_do_parse(struct nft_set_elem *e, enum nft_parse_type type, return ret; } -int nft_set_elem_parse(struct nft_set_elem *e, enum nft_parse_type type, - const char *data, struct nft_parse_err *err) +int nftnl_set_elem_parse(struct nftnl_set_elem *e, enum nftnl_parse_type type, + const char *data, struct nftnl_parse_err *err) { - return nft_set_elem_do_parse(e, type, data, err, NFT_PARSE_BUFFER); + return nftnl_set_elem_do_parse(e, type, data, err, NFTNL_PARSE_BUFFER); } EXPORT_SYMBOL(nftnl_set_elem_parse, nft_set_elem_parse); -int nft_set_elem_parse_file(struct nft_set_elem *e, enum nft_parse_type type, - FILE *fp, struct nft_parse_err *err) +int nftnl_set_elem_parse_file(struct nftnl_set_elem *e, enum nftnl_parse_type type, + FILE *fp, struct nftnl_parse_err *err) { - return nft_set_elem_do_parse(e, type, fp, err, NFT_PARSE_FILE); + return nftnl_set_elem_do_parse(e, type, fp, err, NFTNL_PARSE_FILE); } EXPORT_SYMBOL(nftnl_set_elem_parse_file, nft_set_elem_parse_file); -static int nft_set_elem_snprintf_json(char *buf, size_t size, - struct nft_set_elem *e, uint32_t flags) +static int nftnl_set_elem_snprintf_json(char *buf, size_t size, + struct nftnl_set_elem *e, uint32_t flags) { int ret, len = size, offset = 0, type = -1; - if (e->flags & (1 << NFT_SET_ELEM_ATTR_FLAGS)) { + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_FLAGS)) { ret = snprintf(buf, len, "\"flags\":%u,", e->set_elem_flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } @@ -611,26 +611,26 @@ static int nft_set_elem_snprintf_json(char *buf, size_t size, ret = snprintf(buf + offset, len, "\"key\":{"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_data_reg_snprintf(buf + offset, len, &e->key, - NFT_OUTPUT_JSON, flags, DATA_VALUE); + ret = nftnl_data_reg_snprintf(buf + offset, len, &e->key, + NFTNL_OUTPUT_JSON, flags, DATA_VALUE); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); ret = snprintf(buf + offset, len, "}"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (e->flags & (1 << NFT_SET_ELEM_ATTR_DATA)) + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_DATA)) type = DATA_VALUE; - else if (e->flags & (1 << NFT_SET_ELEM_ATTR_CHAIN)) + else if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_CHAIN)) type = DATA_CHAIN; - else if (e->flags & (1 << NFT_SET_ELEM_ATTR_VERDICT)) + else if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_VERDICT)) type = DATA_VERDICT; if (type != -1) { ret = snprintf(buf + offset, len, ",\"data\":{"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_data_reg_snprintf(buf + offset, len, &e->data, - NFT_OUTPUT_JSON, flags, type); + ret = nftnl_data_reg_snprintf(buf + offset, len, &e->data, + NFTNL_OUTPUT_JSON, flags, type); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); ret = snprintf(buf + offset, len, "}"); @@ -640,8 +640,8 @@ static int nft_set_elem_snprintf_json(char *buf, size_t size, return offset; } -static int nft_set_elem_snprintf_default(char *buf, size_t size, - struct nft_set_elem *e) +static int nftnl_set_elem_snprintf_default(char *buf, size_t size, + struct nftnl_set_elem *e) { int ret, len = size, offset = 0, i; @@ -683,45 +683,45 @@ static int nft_set_elem_snprintf_default(char *buf, size_t size, return offset; } -static int nft_set_elem_snprintf_xml(char *buf, size_t size, - struct nft_set_elem *e, uint32_t flags) +static int nftnl_set_elem_snprintf_xml(char *buf, size_t size, + struct nftnl_set_elem *e, uint32_t flags) { int ret, len = size, offset = 0, type = DATA_NONE; ret = snprintf(buf, size, "<set_elem>"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (e->flags & (1 << NFT_SET_ELEM_ATTR_FLAGS)) { + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_FLAGS)) { ret = snprintf(buf + offset, size, "<flags>%u</flags>", e->set_elem_flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (e->flags & (1 << NFT_SET_ELEM_ATTR_KEY)) { + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_KEY)) { ret = snprintf(buf + offset, len, "<key>"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_data_reg_snprintf(buf + offset, len, &e->key, - NFT_OUTPUT_XML, flags, DATA_VALUE); + ret = nftnl_data_reg_snprintf(buf + offset, len, &e->key, + NFTNL_OUTPUT_XML, flags, DATA_VALUE); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); ret = snprintf(buf + offset, len, "</key>"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); } - if (e->flags & (1 << NFT_SET_ELEM_ATTR_DATA)) + if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_DATA)) type = DATA_VALUE; - else if (e->flags & (1 << NFT_SET_ELEM_ATTR_CHAIN)) + else if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_CHAIN)) type = DATA_CHAIN; - else if (e->flags & (1 << NFT_SET_ELEM_ATTR_VERDICT)) + else if (e->flags & (1 << NFTNL_SET_ELEM_ATTR_VERDICT)) type = DATA_VERDICT; if (type != DATA_NONE) { ret = snprintf(buf + offset, len, "<data>"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_data_reg_snprintf(buf + offset, len, &e->data, - NFT_OUTPUT_XML, flags, type); + ret = nftnl_data_reg_snprintf(buf + offset, len, &e->data, + NFTNL_OUTPUT_XML, flags, type); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); ret = snprintf(buf + offset, len, "</data>"); @@ -734,24 +734,24 @@ static int nft_set_elem_snprintf_xml(char *buf, size_t size, return offset; } -static int nft_set_elem_cmd_snprintf(char *buf, size_t size, - struct nft_set_elem *e, uint32_t cmd, +static int nftnl_set_elem_cmd_snprintf(char *buf, size_t size, + struct nftnl_set_elem *e, uint32_t cmd, uint32_t type, uint32_t flags) { int ret, len = size, offset = 0; - ret = nft_cmd_header_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_header_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); switch(type) { - case NFT_OUTPUT_DEFAULT: - ret = nft_set_elem_snprintf_default(buf+offset, len, e); + case NFTNL_OUTPUT_DEFAULT: + ret = nftnl_set_elem_snprintf_default(buf+offset, len, e); break; - case NFT_OUTPUT_XML: - ret = nft_set_elem_snprintf_xml(buf+offset, len, e, flags); + case NFTNL_OUTPUT_XML: + ret = nftnl_set_elem_snprintf_xml(buf+offset, len, e, flags); break; - case NFT_OUTPUT_JSON: - ret = nft_set_elem_snprintf_json(buf+offset, len, e, flags); + case NFTNL_OUTPUT_JSON: + ret = nftnl_set_elem_snprintf_json(buf+offset, len, e, flags); break; default: return -1; @@ -759,40 +759,40 @@ static int nft_set_elem_cmd_snprintf(char *buf, size_t size, SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); return offset; } -int nft_set_elem_snprintf(char *buf, size_t size, struct nft_set_elem *e, +int nftnl_set_elem_snprintf(char *buf, size_t size, struct nftnl_set_elem *e, uint32_t type, uint32_t flags) { - return nft_set_elem_cmd_snprintf(buf, size, e, nft_flag2cmd(flags), + return nftnl_set_elem_cmd_snprintf(buf, size, e, nftnl_flag2cmd(flags), type, flags); } EXPORT_SYMBOL(nftnl_set_elem_snprintf, nft_set_elem_snprintf); -static inline int nft_set_elem_do_snprintf(char *buf, size_t size, void *e, +static inline int nftnl_set_elem_do_snprintf(char *buf, size_t size, void *e, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_set_elem_snprintf(buf, size, e, type, flags); + return nftnl_set_elem_snprintf(buf, size, e, type, flags); } -int nft_set_elem_fprintf(FILE *fp, struct nft_set_elem *se, uint32_t type, +int nftnl_set_elem_fprintf(FILE *fp, struct nftnl_set_elem *se, uint32_t type, uint32_t flags) { - return nft_fprintf(fp, se, NFT_CMD_UNSPEC, type, flags, - nft_set_elem_do_snprintf); + return nftnl_fprintf(fp, se, NFTNL_CMD_UNSPEC, type, flags, + nftnl_set_elem_do_snprintf); } EXPORT_SYMBOL(nftnl_set_elem_fprintf, nft_set_elem_fprintf); -int nft_set_elem_foreach(struct nft_set *s, - int (*cb)(struct nft_set_elem *e, void *data), +int nftnl_set_elem_foreach(struct nftnl_set *s, + int (*cb)(struct nftnl_set_elem *e, void *data), void *data) { - struct nft_set_elem *elem; + struct nftnl_set_elem *elem; int ret; list_for_each_entry(elem, &s->element_list, head) { @@ -804,17 +804,17 @@ int nft_set_elem_foreach(struct nft_set *s, } EXPORT_SYMBOL(nftnl_set_elem_foreach, nft_set_elem_foreach); -struct nft_set_elems_iter { - struct nft_set *set; +struct nftnl_set_elems_iter { + struct nftnl_set *set; struct list_head *list; - struct nft_set_elem *cur; + struct nftnl_set_elem *cur; }; -struct nft_set_elems_iter *nft_set_elems_iter_create(struct nft_set *s) +struct nftnl_set_elems_iter *nftnl_set_elems_iter_create(struct nftnl_set *s) { - struct nft_set_elems_iter *iter; + struct nftnl_set_elems_iter *iter; - iter = calloc(1, sizeof(struct nft_set_elems_iter)); + iter = calloc(1, sizeof(struct nftnl_set_elems_iter)); if (iter == NULL) return NULL; @@ -824,26 +824,26 @@ struct nft_set_elems_iter *nft_set_elems_iter_create(struct nft_set *s) iter->cur = NULL; else iter->cur = list_entry(s->element_list.next, - struct nft_set_elem, head); + struct nftnl_set_elem, head); return iter; } EXPORT_SYMBOL(nftnl_set_elems_iter_create, nft_set_elems_iter_create); -struct nft_set_elem *nft_set_elems_iter_cur(struct nft_set_elems_iter *iter) +struct nftnl_set_elem *nftnl_set_elems_iter_cur(struct nftnl_set_elems_iter *iter) { return iter->cur; } EXPORT_SYMBOL(nftnl_set_elems_iter_cur, nft_set_elems_iter_cur); -struct nft_set_elem *nft_set_elems_iter_next(struct nft_set_elems_iter *iter) +struct nftnl_set_elem *nftnl_set_elems_iter_next(struct nftnl_set_elems_iter *iter) { - struct nft_set_elem *s = iter->cur; + struct nftnl_set_elem *s = iter->cur; if (s == NULL) return NULL; - iter->cur = list_entry(iter->cur->head.next, struct nft_set_elem, head); + iter->cur = list_entry(iter->cur->head.next, struct nftnl_set_elem, head); if (&iter->cur->head == iter->list->next) return NULL; @@ -851,13 +851,13 @@ struct nft_set_elem *nft_set_elems_iter_next(struct nft_set_elems_iter *iter) } EXPORT_SYMBOL(nftnl_set_elems_iter_next, nft_set_elems_iter_next); -void nft_set_elems_iter_destroy(struct nft_set_elems_iter *iter) +void nftnl_set_elems_iter_destroy(struct nftnl_set_elems_iter *iter) { xfree(iter); } EXPORT_SYMBOL(nftnl_set_elems_iter_destroy, nft_set_elems_iter_destroy); -static bool nft_attr_nest_overflow(struct nlmsghdr *nlh, +static bool nftnl_attr_nest_overflow(struct nlmsghdr *nlh, const struct nlattr *from, const struct nlattr *to) { @@ -874,27 +874,27 @@ static bool nft_attr_nest_overflow(struct nlmsghdr *nlh, return false; } -int nft_set_elems_nlmsg_build_payload_iter(struct nlmsghdr *nlh, - struct nft_set_elems_iter *iter) +int nftnl_set_elems_nlmsg_build_payload_iter(struct nlmsghdr *nlh, + struct nftnl_set_elems_iter *iter) { - struct nft_set_elem *elem; + struct nftnl_set_elem *elem; struct nlattr *nest1, *nest2; int i = 0, ret = 0; - nft_set_elem_nlmsg_build_def(nlh, iter->set); + nftnl_set_elem_nlmsg_build_def(nlh, iter->set); nest1 = mnl_attr_nest_start(nlh, NFTA_SET_ELEM_LIST_ELEMENTS); - elem = nft_set_elems_iter_next(iter); + elem = nftnl_set_elems_iter_next(iter); while (elem != NULL) { - nest2 = nft_set_elem_attr_build(nlh, elem, ++i); - if (nft_attr_nest_overflow(nlh, nest1, nest2)) { + nest2 = nftnl_set_elem_attr_build(nlh, elem, ++i); + if (nftnl_attr_nest_overflow(nlh, nest1, nest2)) { /* Go back to previous not to miss this element */ iter->cur = list_entry(iter->cur->head.prev, - struct nft_set_elem, head); + struct nftnl_set_elem, head); ret = 1; break; } - elem = nft_set_elems_iter_next(iter); + elem = nftnl_set_elems_iter_next(iter); } mnl_attr_nest_end(nlh, nest1); diff --git a/src/table.c b/src/table.c index 543ea8d..4adfba8 100644 --- a/src/table.c +++ b/src/table.c @@ -26,7 +26,7 @@ #include <libnftnl/table.h> #include <buffer.h> -struct nft_table { +struct nftnl_table { struct list_head head; const char *name; @@ -36,76 +36,76 @@ struct nft_table { uint32_t flags; }; -struct nft_table *nft_table_alloc(void) +struct nftnl_table *nftnl_table_alloc(void) { - return calloc(1, sizeof(struct nft_table)); + return calloc(1, sizeof(struct nftnl_table)); } EXPORT_SYMBOL(nftnl_table_alloc, nft_table_alloc); -void nft_table_free(struct nft_table *t) +void nftnl_table_free(struct nftnl_table *t) { - if (t->flags & (1 << NFT_TABLE_ATTR_NAME)) + if (t->flags & (1 << NFTNL_TABLE_ATTR_NAME)) xfree(t->name); xfree(t); } EXPORT_SYMBOL(nftnl_table_free, nft_table_free); -bool nft_table_attr_is_set(const struct nft_table *t, uint16_t attr) +bool nftnl_table_attr_is_set(const struct nftnl_table *t, uint16_t attr) { return t->flags & (1 << attr); } EXPORT_SYMBOL(nftnl_table_attr_is_set, nft_table_attr_is_set); -void nft_table_attr_unset(struct nft_table *t, uint16_t attr) +void nftnl_table_attr_unset(struct nftnl_table *t, uint16_t attr) { if (!(t->flags & (1 << attr))) return; switch (attr) { - case NFT_TABLE_ATTR_NAME: + case NFTNL_TABLE_ATTR_NAME: if (t->name) { xfree(t->name); t->name = NULL; } break; - case NFT_TABLE_ATTR_FLAGS: - case NFT_TABLE_ATTR_FAMILY: + case NFTNL_TABLE_ATTR_FLAGS: + case NFTNL_TABLE_ATTR_FAMILY: break; - case NFT_TABLE_ATTR_USE: + case NFTNL_TABLE_ATTR_USE: break; } t->flags &= ~(1 << attr); } EXPORT_SYMBOL(nftnl_table_attr_unset, nft_table_attr_unset); -static uint32_t nft_table_attr_validate[NFT_TABLE_ATTR_MAX + 1] = { - [NFT_TABLE_ATTR_FLAGS] = sizeof(uint32_t), - [NFT_TABLE_ATTR_FAMILY] = sizeof(uint32_t), +static uint32_t nftnl_table_attr_validate[NFTNL_TABLE_ATTR_MAX + 1] = { + [NFTNL_TABLE_ATTR_FLAGS] = sizeof(uint32_t), + [NFTNL_TABLE_ATTR_FAMILY] = sizeof(uint32_t), }; -void nft_table_attr_set_data(struct nft_table *t, uint16_t attr, +void nftnl_table_attr_set_data(struct nftnl_table *t, uint16_t attr, const void *data, uint32_t data_len) { - if (attr > NFT_TABLE_ATTR_MAX) + if (attr > NFTNL_TABLE_ATTR_MAX) return; - nft_assert_validate(data, nft_table_attr_validate, attr, data_len); + nftnl_assert_validate(data, nftnl_table_attr_validate, attr, data_len); switch (attr) { - case NFT_TABLE_ATTR_NAME: + case NFTNL_TABLE_ATTR_NAME: if (t->name) xfree(t->name); t->name = strdup(data); break; - case NFT_TABLE_ATTR_FLAGS: + case NFTNL_TABLE_ATTR_FLAGS: t->table_flags = *((uint32_t *)data); break; - case NFT_TABLE_ATTR_FAMILY: + case NFTNL_TABLE_ATTR_FAMILY: t->family = *((uint32_t *)data); break; - case NFT_TABLE_ATTR_USE: + case NFTNL_TABLE_ATTR_USE: t->use = *((uint32_t *)data); break; } @@ -113,46 +113,46 @@ void nft_table_attr_set_data(struct nft_table *t, uint16_t attr, } EXPORT_SYMBOL(nftnl_table_attr_set_data, nft_table_attr_set_data); -void nft_table_attr_set(struct nft_table *t, uint16_t attr, const void *data) +void nftnl_table_attr_set(struct nftnl_table *t, uint16_t attr, const void *data) { - nft_table_attr_set_data(t, attr, data, nft_table_attr_validate[attr]); + nftnl_table_attr_set_data(t, attr, data, nftnl_table_attr_validate[attr]); } EXPORT_SYMBOL(nftnl_table_attr_set, nft_table_attr_set); -void nft_table_attr_set_u32(struct nft_table *t, uint16_t attr, uint32_t val) +void nftnl_table_attr_set_u32(struct nftnl_table *t, uint16_t attr, uint32_t val) { - nft_table_attr_set_data(t, attr, &val, sizeof(uint32_t)); + nftnl_table_attr_set_data(t, attr, &val, sizeof(uint32_t)); } EXPORT_SYMBOL(nftnl_table_attr_set_u32, nft_table_attr_set_u32); -void nft_table_attr_set_u8(struct nft_table *t, uint16_t attr, uint8_t val) +void nftnl_table_attr_set_u8(struct nftnl_table *t, uint16_t attr, uint8_t val) { - nft_table_attr_set_data(t, attr, &val, sizeof(uint8_t)); + nftnl_table_attr_set_data(t, attr, &val, sizeof(uint8_t)); } EXPORT_SYMBOL(nftnl_table_attr_set_u8, nft_table_attr_set_u8); -void nft_table_attr_set_str(struct nft_table *t, uint16_t attr, const char *str) +void nftnl_table_attr_set_str(struct nftnl_table *t, uint16_t attr, const char *str) { - nft_table_attr_set_data(t, attr, str, 0); + nftnl_table_attr_set_data(t, attr, str, 0); } EXPORT_SYMBOL(nftnl_table_attr_set_str, nft_table_attr_set_str); -const void *nft_table_attr_get_data(struct nft_table *t, uint16_t attr, +const void *nftnl_table_attr_get_data(struct nftnl_table *t, uint16_t attr, uint32_t *data_len) { if (!(t->flags & (1 << attr))) return NULL; switch(attr) { - case NFT_TABLE_ATTR_NAME: + case NFTNL_TABLE_ATTR_NAME: return t->name; - case NFT_TABLE_ATTR_FLAGS: + case NFTNL_TABLE_ATTR_FLAGS: *data_len = sizeof(uint32_t); return &t->table_flags; - case NFT_TABLE_ATTR_FAMILY: + case NFTNL_TABLE_ATTR_FAMILY: *data_len = sizeof(uint32_t); return &t->family; - case NFT_TABLE_ATTR_USE: + case NFTNL_TABLE_ATTR_USE: *data_len = sizeof(uint32_t); return &t->use; } @@ -160,43 +160,43 @@ const void *nft_table_attr_get_data(struct nft_table *t, uint16_t attr, } EXPORT_SYMBOL(nftnl_table_attr_get_data, nft_table_attr_get_data); -const void *nft_table_attr_get(struct nft_table *t, uint16_t attr) +const void *nftnl_table_attr_get(struct nftnl_table *t, uint16_t attr) { uint32_t data_len; - return nft_table_attr_get_data(t, attr, &data_len); + return nftnl_table_attr_get_data(t, attr, &data_len); } EXPORT_SYMBOL(nftnl_table_attr_get, nft_table_attr_get); -uint32_t nft_table_attr_get_u32(struct nft_table *t, uint16_t attr) +uint32_t nftnl_table_attr_get_u32(struct nftnl_table *t, uint16_t attr) { - const void *ret = nft_table_attr_get(t, attr); + const void *ret = nftnl_table_attr_get(t, attr); return ret == NULL ? 0 : *((uint32_t *)ret); } EXPORT_SYMBOL(nftnl_table_attr_get_u32, nft_table_attr_get_u32); -uint8_t nft_table_attr_get_u8(struct nft_table *t, uint16_t attr) +uint8_t nftnl_table_attr_get_u8(struct nftnl_table *t, uint16_t attr) { - const void *ret = nft_table_attr_get(t, attr); + const void *ret = nftnl_table_attr_get(t, attr); return ret == NULL ? 0 : *((uint8_t *)ret); } EXPORT_SYMBOL(nftnl_table_attr_get_u8, nft_table_attr_get_u8); -const char *nft_table_attr_get_str(struct nft_table *t, uint16_t attr) +const char *nftnl_table_attr_get_str(struct nftnl_table *t, uint16_t attr) { - return nft_table_attr_get(t, attr); + return nftnl_table_attr_get(t, attr); } EXPORT_SYMBOL(nftnl_table_attr_get_str, nft_table_attr_get_str); -void nft_table_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_table *t) +void nftnl_table_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nftnl_table *t) { - if (t->flags & (1 << NFT_TABLE_ATTR_NAME)) + if (t->flags & (1 << NFTNL_TABLE_ATTR_NAME)) mnl_attr_put_strz(nlh, NFTA_TABLE_NAME, t->name); - if (t->flags & (1 << NFT_TABLE_ATTR_FLAGS)) + if (t->flags & (1 << NFTNL_TABLE_ATTR_FLAGS)) mnl_attr_put_u32(nlh, NFTA_TABLE_FLAGS, htonl(t->table_flags)); } EXPORT_SYMBOL(nftnl_table_nlmsg_build_payload, nft_table_nlmsg_build_payload); -static int nft_table_parse_attr_cb(const struct nlattr *attr, void *data) +static int nftnl_table_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -220,76 +220,76 @@ static int nft_table_parse_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -int nft_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_table *t) +int nftnl_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_table *t) { struct nlattr *tb[NFTA_TABLE_MAX+1] = {}; struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh); - if (mnl_attr_parse(nlh, sizeof(*nfg), nft_table_parse_attr_cb, tb) < 0) + if (mnl_attr_parse(nlh, sizeof(*nfg), nftnl_table_parse_attr_cb, tb) < 0) return -1; if (tb[NFTA_TABLE_NAME]) { xfree(t->name); t->name = strdup(mnl_attr_get_str(tb[NFTA_TABLE_NAME])); - t->flags |= (1 << NFT_TABLE_ATTR_NAME); + t->flags |= (1 << NFTNL_TABLE_ATTR_NAME); } if (tb[NFTA_TABLE_FLAGS]) { t->table_flags = ntohl(mnl_attr_get_u32(tb[NFTA_TABLE_FLAGS])); - t->flags |= (1 << NFT_TABLE_ATTR_FLAGS); + t->flags |= (1 << NFTNL_TABLE_ATTR_FLAGS); } if (tb[NFTA_TABLE_USE]) { t->use = ntohl(mnl_attr_get_u32(tb[NFTA_TABLE_USE])); - t->flags |= (1 << NFT_TABLE_ATTR_USE); + t->flags |= (1 << NFTNL_TABLE_ATTR_USE); } t->family = nfg->nfgen_family; - t->flags |= (1 << NFT_TABLE_ATTR_FAMILY); + t->flags |= (1 << NFTNL_TABLE_ATTR_FAMILY); return 0; } EXPORT_SYMBOL(nftnl_table_nlmsg_parse, nft_table_nlmsg_parse); #ifdef XML_PARSING -int nft_mxml_table_parse(mxml_node_t *tree, struct nft_table *t, - struct nft_parse_err *err) +int nftnl_mxml_table_parse(mxml_node_t *tree, struct nftnl_table *t, + struct nftnl_parse_err *err) { const char *name; int family; uint32_t flags, use; - name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + name = nftnl_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (name != NULL) - nft_table_attr_set_str(t, NFT_TABLE_ATTR_NAME, name); + nftnl_table_attr_set_str(t, NFTNL_TABLE_ATTR_NAME, name); - family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + family = nftnl_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (family >= 0) - nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FAMILY, family); + nftnl_table_attr_set_u32(t, NFTNL_TABLE_ATTR_FAMILY, family); - if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND, BASE_DEC, - &flags, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FLAGS, flags); + if (nftnl_mxml_num_parse(tree, "flags", MXML_DESCEND, BASE_DEC, + &flags, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_table_attr_set_u32(t, NFTNL_TABLE_ATTR_FLAGS, flags); - if (nft_mxml_num_parse(tree, "use", MXML_DESCEND, BASE_DEC, - &use, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) - nft_table_attr_set_u32(t, NFT_TABLE_ATTR_USE, use); + if (nftnl_mxml_num_parse(tree, "use", MXML_DESCEND, BASE_DEC, + &use, NFTNL_TYPE_U32, NFTNL_XML_MAND, err) == 0) + nftnl_table_attr_set_u32(t, NFTNL_TABLE_ATTR_USE, use); return 0; } #endif -static int nft_table_xml_parse(struct nft_table *t, const void *data, - struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_table_xml_parse(struct nftnl_table *t, const void *data, + struct nftnl_parse_err *err, + enum nftnl_parse_input input) { #ifdef XML_PARSING int ret; - mxml_node_t *tree = nft_mxml_build_tree(data, "table", err, input); + mxml_node_t *tree = nftnl_mxml_build_tree(data, "table", err, input); if (tree == NULL) return -1; - ret = nft_mxml_table_parse(tree, t, err); + ret = nftnl_mxml_table_parse(tree, t, err); mxmlDelete(tree); return ret; #else @@ -299,52 +299,52 @@ static int nft_table_xml_parse(struct nft_table *t, const void *data, } #ifdef JSON_PARSING -int nft_jansson_parse_table(struct nft_table *t, json_t *tree, - struct nft_parse_err *err) +int nftnl_jansson_parse_table(struct nftnl_table *t, json_t *tree, + struct nftnl_parse_err *err) { json_t *root; uint32_t flags, use; const char *str; int family; - root = nft_jansson_get_node(tree, "table", err); + root = nftnl_jansson_get_node(tree, "table", err); if (root == NULL) return -1; - str = nft_jansson_parse_str(root, "name", err); + str = nftnl_jansson_parse_str(root, "name", err); if (str != NULL) - nft_table_attr_set_str(t, NFT_TABLE_ATTR_NAME, str); + nftnl_table_attr_set_str(t, NFTNL_TABLE_ATTR_NAME, str); - if (nft_jansson_parse_family(root, &family, err) == 0) - nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FAMILY, family); + if (nftnl_jansson_parse_family(root, &family, err) == 0) + nftnl_table_attr_set_u32(t, NFTNL_TABLE_ATTR_FAMILY, family); - if (nft_jansson_parse_val(root, "flags", NFT_TYPE_U32, &flags, + if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, err) == 0) - nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FLAGS, flags); + nftnl_table_attr_set_u32(t, NFTNL_TABLE_ATTR_FLAGS, flags); - if (nft_jansson_parse_val(root, "use", NFT_TYPE_U32, &use, err) == 0) - nft_table_attr_set_u32(t, NFT_TABLE_ATTR_USE, use); + if (nftnl_jansson_parse_val(root, "use", NFTNL_TYPE_U32, &use, err) == 0) + nftnl_table_attr_set_u32(t, NFTNL_TABLE_ATTR_USE, use); return 0; } #endif -static int nft_table_json_parse(struct nft_table *t, const void *json, - struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_table_json_parse(struct nftnl_table *t, const void *json, + struct nftnl_parse_err *err, + enum nftnl_parse_input input) { #ifdef JSON_PARSING json_t *tree; json_error_t error; int ret; - tree = nft_jansson_create_root(json, &error, err, input); + tree = nftnl_jansson_create_root(json, &error, err, input); if (tree == NULL) return -1; - ret = nft_jansson_parse_table(t, tree, err); + ret = nftnl_jansson_parse_table(t, tree, err); - nft_jansson_free_root(tree); + nftnl_jansson_free_root(tree); return ret; #else @@ -353,19 +353,19 @@ static int nft_table_json_parse(struct nft_table *t, const void *json, #endif } -static int nft_table_do_parse(struct nft_table *t, enum nft_parse_type type, - const void *data, struct nft_parse_err *err, - enum nft_parse_input input) +static int nftnl_table_do_parse(struct nftnl_table *t, enum nftnl_parse_type type, + const void *data, struct nftnl_parse_err *err, + enum nftnl_parse_input input) { int ret; - struct nft_parse_err perr; + struct nftnl_parse_err perr; switch (type) { - case NFT_PARSE_XML: - ret = nft_table_xml_parse(t, data, &perr, input); + case NFTNL_PARSE_XML: + ret = nftnl_table_xml_parse(t, data, &perr, input); break; - case NFT_PARSE_JSON: - ret = nft_table_json_parse(t, data, &perr, input); + case NFTNL_PARSE_JSON: + ret = nftnl_table_json_parse(t, data, &perr, input); break; default: ret = -1; @@ -379,106 +379,106 @@ static int nft_table_do_parse(struct nft_table *t, enum nft_parse_type type, return ret; } -int nft_table_parse(struct nft_table *t, enum nft_parse_type type, - const char *data, struct nft_parse_err *err) +int nftnl_table_parse(struct nftnl_table *t, enum nftnl_parse_type type, + const char *data, struct nftnl_parse_err *err) { - return nft_table_do_parse(t, type, data, err, NFT_PARSE_BUFFER); + return nftnl_table_do_parse(t, type, data, err, NFTNL_PARSE_BUFFER); } EXPORT_SYMBOL(nftnl_table_parse, nft_table_parse); -int nft_table_parse_file(struct nft_table *t, enum nft_parse_type type, - FILE *fp, struct nft_parse_err *err) +int nftnl_table_parse_file(struct nftnl_table *t, enum nftnl_parse_type type, + FILE *fp, struct nftnl_parse_err *err) { - return nft_table_do_parse(t, type, fp, err, NFT_PARSE_FILE); + return nftnl_table_do_parse(t, type, fp, err, NFTNL_PARSE_FILE); } EXPORT_SYMBOL(nftnl_table_parse_file, nft_table_parse_file); -static int nft_table_export(char *buf, size_t size, struct nft_table *t, +static int nftnl_table_export(char *buf, size_t size, struct nftnl_table *t, int type) { - NFT_BUF_INIT(b, buf, size); + NFTNL_BUF_INIT(b, buf, size); - nft_buf_open(&b, type, TABLE); - if (t->flags & (1 << NFT_TABLE_ATTR_NAME)) - nft_buf_str(&b, type, t->name, NAME); - if (t->flags & (1 << NFT_TABLE_ATTR_FAMILY)) - nft_buf_str(&b, type, nft_family2str(t->family), FAMILY); - if (t->flags & (1 << NFT_TABLE_ATTR_FLAGS)) - nft_buf_u32(&b, type, t->table_flags, FLAGS); - if (t->flags & (1 << NFT_TABLE_ATTR_USE)) - nft_buf_u32(&b, type, t->use, USE); + nftnl_buf_open(&b, type, TABLE); + if (t->flags & (1 << NFTNL_TABLE_ATTR_NAME)) + nftnl_buf_str(&b, type, t->name, NAME); + if (t->flags & (1 << NFTNL_TABLE_ATTR_FAMILY)) + nftnl_buf_str(&b, type, nftnl_family2str(t->family), FAMILY); + if (t->flags & (1 << NFTNL_TABLE_ATTR_FLAGS)) + nftnl_buf_u32(&b, type, t->table_flags, FLAGS); + if (t->flags & (1 << NFTNL_TABLE_ATTR_USE)) + nftnl_buf_u32(&b, type, t->use, USE); - nft_buf_close(&b, type, TABLE); + nftnl_buf_close(&b, type, TABLE); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } -static int nft_table_snprintf_default(char *buf, size_t size, struct nft_table *t) +static int nftnl_table_snprintf_default(char *buf, size_t size, struct nftnl_table *t) { return snprintf(buf, size, "table %s %s flags %x use %d", - t->name, nft_family2str(t->family), + t->name, nftnl_family2str(t->family), t->table_flags, t->use); } -static int nft_table_cmd_snprintf(char *buf, size_t size, struct nft_table *t, +static int nftnl_table_cmd_snprintf(char *buf, size_t size, struct nftnl_table *t, uint32_t cmd, uint32_t type, uint32_t flags) { int ret, len = size, offset = 0; - ret = nft_cmd_header_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_header_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); switch (type) { - case NFT_OUTPUT_DEFAULT: - ret = nft_table_snprintf_default(buf+offset, len, t); + case NFTNL_OUTPUT_DEFAULT: + ret = nftnl_table_snprintf_default(buf+offset, len, t); break; - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - ret = nft_table_export(buf+offset, len, t, type); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + ret = nftnl_table_export(buf+offset, len, t, type); break; default: return -1; } SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = nft_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); + ret = nftnl_cmd_footer_snprintf(buf + offset, len, cmd, type, flags); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); return offset; } -int nft_table_snprintf(char *buf, size_t size, struct nft_table *t, +int nftnl_table_snprintf(char *buf, size_t size, struct nftnl_table *t, uint32_t type, uint32_t flags) { - return nft_table_cmd_snprintf(buf, size, t, nft_flag2cmd(flags), type, + return nftnl_table_cmd_snprintf(buf, size, t, nftnl_flag2cmd(flags), type, flags); } EXPORT_SYMBOL(nftnl_table_snprintf, nft_table_snprintf); -static inline int nft_table_do_snprintf(char *buf, size_t size, void *t, +static inline int nftnl_table_do_snprintf(char *buf, size_t size, void *t, uint32_t cmd, uint32_t type, uint32_t flags) { - return nft_table_snprintf(buf, size, t, type, flags); + return nftnl_table_snprintf(buf, size, t, type, flags); } -int nft_table_fprintf(FILE *fp, struct nft_table *t, uint32_t type, +int nftnl_table_fprintf(FILE *fp, struct nftnl_table *t, uint32_t type, uint32_t flags) { - return nft_fprintf(fp, t, NFT_CMD_UNSPEC, type, flags, - nft_table_do_snprintf); + return nftnl_fprintf(fp, t, NFTNL_CMD_UNSPEC, type, flags, + nftnl_table_do_snprintf); } EXPORT_SYMBOL(nftnl_table_fprintf, nft_table_fprintf); -struct nft_table_list { +struct nftnl_table_list { struct list_head list; }; -struct nft_table_list *nft_table_list_alloc(void) +struct nftnl_table_list *nftnl_table_list_alloc(void) { - struct nft_table_list *list; + struct nftnl_table_list *list; - list = calloc(1, sizeof(struct nft_table_list)); + list = calloc(1, sizeof(struct nftnl_table_list)); if (list == NULL) return NULL; @@ -488,47 +488,47 @@ struct nft_table_list *nft_table_list_alloc(void) } EXPORT_SYMBOL(nftnl_table_list_alloc, nft_table_list_alloc); -void nft_table_list_free(struct nft_table_list *list) +void nftnl_table_list_free(struct nftnl_table_list *list) { - struct nft_table *r, *tmp; + struct nftnl_table *r, *tmp; list_for_each_entry_safe(r, tmp, &list->list, head) { list_del(&r->head); - nft_table_free(r); + nftnl_table_free(r); } xfree(list); } EXPORT_SYMBOL(nftnl_table_list_free, nft_table_list_free); -int nft_table_list_is_empty(struct nft_table_list *list) +int nftnl_table_list_is_empty(struct nftnl_table_list *list) { return list_empty(&list->list); } EXPORT_SYMBOL(nftnl_table_list_is_empty, nft_table_list_is_empty); -void nft_table_list_add(struct nft_table *r, struct nft_table_list *list) +void nftnl_table_list_add(struct nftnl_table *r, struct nftnl_table_list *list) { list_add(&r->head, &list->list); } EXPORT_SYMBOL(nftnl_table_list_add, nft_table_list_add); -void nft_table_list_add_tail(struct nft_table *r, struct nft_table_list *list) +void nftnl_table_list_add_tail(struct nftnl_table *r, struct nftnl_table_list *list) { list_add_tail(&r->head, &list->list); } EXPORT_SYMBOL(nftnl_table_list_add_tail, nft_table_list_add_tail); -void nft_table_list_del(struct nft_table *t) +void nftnl_table_list_del(struct nftnl_table *t) { list_del(&t->head); } EXPORT_SYMBOL(nftnl_table_list_del, nft_table_list_del); -int nft_table_list_foreach(struct nft_table_list *table_list, - int (*cb)(struct nft_table *t, void *data), +int nftnl_table_list_foreach(struct nftnl_table_list *table_list, + int (*cb)(struct nftnl_table *t, void *data), void *data) { - struct nft_table *cur, *tmp; + struct nftnl_table *cur, *tmp; int ret; list_for_each_entry_safe(cur, tmp, &table_list->list, head) { @@ -540,38 +540,38 @@ int nft_table_list_foreach(struct nft_table_list *table_list, } EXPORT_SYMBOL(nftnl_table_list_foreach, nft_table_list_foreach); -struct nft_table_list_iter { - struct nft_table_list *list; - struct nft_table *cur; +struct nftnl_table_list_iter { + struct nftnl_table_list *list; + struct nftnl_table *cur; }; -struct nft_table_list_iter *nft_table_list_iter_create(struct nft_table_list *l) +struct nftnl_table_list_iter *nftnl_table_list_iter_create(struct nftnl_table_list *l) { - struct nft_table_list_iter *iter; + struct nftnl_table_list_iter *iter; - iter = calloc(1, sizeof(struct nft_table_list_iter)); + iter = calloc(1, sizeof(struct nftnl_table_list_iter)); if (iter == NULL) return NULL; iter->list = l; - if (nft_table_list_is_empty(l)) + if (nftnl_table_list_is_empty(l)) iter->cur = NULL; else - iter->cur = list_entry(l->list.next, struct nft_table, head); + iter->cur = list_entry(l->list.next, struct nftnl_table, head); return iter; } EXPORT_SYMBOL(nftnl_table_list_iter_create, nft_table_list_iter_create); -struct nft_table *nft_table_list_iter_next(struct nft_table_list_iter *iter) +struct nftnl_table *nftnl_table_list_iter_next(struct nftnl_table_list_iter *iter) { - struct nft_table *r = iter->cur; + struct nftnl_table *r = iter->cur; if (r == NULL) return NULL; /* get next table, if any */ - iter->cur = list_entry(iter->cur->head.next, struct nft_table, head); + iter->cur = list_entry(iter->cur->head.next, struct nftnl_table, head); if (&iter->cur->head == iter->list->list.next) return NULL; @@ -579,7 +579,7 @@ struct nft_table *nft_table_list_iter_next(struct nft_table_list_iter *iter) } EXPORT_SYMBOL(nftnl_table_list_iter_next, nft_table_list_iter_next); -void nft_table_list_iter_destroy(struct nft_table_list_iter *iter) +void nftnl_table_list_iter_destroy(struct nftnl_table_list_iter *iter) { xfree(iter); } diff --git a/src/utils.c b/src/utils.c index 728ae30..c241e5f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -22,7 +22,7 @@ #include <linux/netfilter.h> #include <linux/netfilter/nf_tables.h> -static const char *const nft_family_str[NFPROTO_NUMPROTO] = { +static const char *const nftnl_family_str[NFPROTO_NUMPROTO] = { [NFPROTO_INET] = "inet", [NFPROTO_IPV4] = "ip", [NFPROTO_ARP] = "arp", @@ -30,23 +30,23 @@ static const char *const nft_family_str[NFPROTO_NUMPROTO] = { [NFPROTO_IPV6] = "ip6", }; -const char *nft_family2str(uint32_t family) +const char *nftnl_family2str(uint32_t family) { - if (nft_family_str[family] == NULL) + if (nftnl_family_str[family] == NULL) return "unknown"; - return nft_family_str[family]; + return nftnl_family_str[family]; } -int nft_str2family(const char *family) +int nftnl_str2family(const char *family) { int i; for (i = 0; i < NFPROTO_NUMPROTO; i++) { - if (nft_family_str[i] == NULL) + if (nftnl_family_str[i] == NULL) continue; - if (strcmp(nft_family_str[i], family) == 0) + if (strcmp(nftnl_family_str[i], family) == 0) return i; } @@ -59,27 +59,26 @@ static struct { int64_t min; uint64_t max; } basetype[] = { - [NFT_TYPE_U8] = { .len = sizeof(uint8_t), .max = UINT8_MAX }, - [NFT_TYPE_U16] = { .len = sizeof(uint16_t), .max = UINT16_MAX }, - [NFT_TYPE_U32] = { .len = sizeof(uint32_t), .max = UINT32_MAX }, - [NFT_TYPE_U64] = { .len = sizeof(uint64_t), .max = UINT64_MAX }, - [NFT_TYPE_S8] = { .len = sizeof(int8_t), .min = INT8_MIN, .max = INT8_MAX }, - [NFT_TYPE_S16] = { .len = sizeof(int16_t), .min = INT16_MIN, .max = INT16_MAX }, - [NFT_TYPE_S32] = { .len = sizeof(int32_t), .min = INT32_MIN, .max = INT32_MAX }, - [NFT_TYPE_S64] = { .len = sizeof(int64_t), .min = INT64_MIN, .max = INT64_MAX }, + [NFTNL_TYPE_U8] = { .len = sizeof(uint8_t), .max = UINT8_MAX }, + [NFTNL_TYPE_U16] = { .len = sizeof(uint16_t), .max = UINT16_MAX }, + [NFTNL_TYPE_U32] = { .len = sizeof(uint32_t), .max = UINT32_MAX }, + [NFTNL_TYPE_U64] = { .len = sizeof(uint64_t), .max = UINT64_MAX }, + [NFTNL_TYPE_S8] = { .len = sizeof(int8_t), .min = INT8_MIN, .max = INT8_MAX }, + [NFTNL_TYPE_S16] = { .len = sizeof(int16_t), .min = INT16_MIN, .max = INT16_MAX }, + [NFTNL_TYPE_S32] = { .len = sizeof(int32_t), .min = INT32_MIN, .max = INT32_MAX }, + [NFTNL_TYPE_S64] = { .len = sizeof(int64_t), .min = INT64_MIN, .max = INT64_MAX }, }; - -int nft_get_value(enum nft_type type, void *val, void *out) +int nftnl_get_value(enum nftnl_type type, void *val, void *out) { int64_t sval; uint64_t uval; switch (type) { - case NFT_TYPE_U8: - case NFT_TYPE_U16: - case NFT_TYPE_U32: - case NFT_TYPE_U64: + case NFTNL_TYPE_U8: + case NFTNL_TYPE_U16: + case NFTNL_TYPE_U32: + case NFTNL_TYPE_U64: uval = *((uint64_t *)val); if (uval > basetype[type].max) { errno = ERANGE; @@ -87,10 +86,10 @@ int nft_get_value(enum nft_type type, void *val, void *out) } memcpy(out, &uval, basetype[type].len); break; - case NFT_TYPE_S8: - case NFT_TYPE_S16: - case NFT_TYPE_S32: - case NFT_TYPE_S64: + case NFTNL_TYPE_S8: + case NFTNL_TYPE_S16: + case NFTNL_TYPE_S32: + case NFTNL_TYPE_S64: sval = *((int64_t *)val); if (sval < basetype[type].min || sval > (int64_t)basetype[type].max) { @@ -104,7 +103,7 @@ int nft_get_value(enum nft_type type, void *val, void *out) return 0; } -int nft_strtoi(const char *string, int base, void *out, enum nft_type type) +int nftnl_strtoi(const char *string, int base, void *out, enum nftnl_type type) { int ret; int64_t sval = 0; @@ -112,19 +111,19 @@ int nft_strtoi(const char *string, int base, void *out, enum nft_type type) char *endptr; switch (type) { - case NFT_TYPE_U8: - case NFT_TYPE_U16: - case NFT_TYPE_U32: - case NFT_TYPE_U64: + case NFTNL_TYPE_U8: + case NFTNL_TYPE_U16: + case NFTNL_TYPE_U32: + case NFTNL_TYPE_U64: uval = strtoll(string, &endptr, base); - ret = nft_get_value(type, &uval, out); + ret = nftnl_get_value(type, &uval, out); break; - case NFT_TYPE_S8: - case NFT_TYPE_S16: - case NFT_TYPE_S32: - case NFT_TYPE_S64: + case NFTNL_TYPE_S8: + case NFTNL_TYPE_S16: + case NFTNL_TYPE_S32: + case NFTNL_TYPE_S64: sval = strtoull(string, &endptr, base); - ret = nft_get_value(type, &sval, out); + ret = nftnl_get_value(type, &sval, out); break; default: errno = EINVAL; @@ -139,7 +138,7 @@ int nft_strtoi(const char *string, int base, void *out, enum nft_type type) return ret; } -const char *nft_verdict2str(uint32_t verdict) +const char *nftnl_verdict2str(uint32_t verdict) { switch (verdict) { case NF_ACCEPT: @@ -157,7 +156,7 @@ const char *nft_verdict2str(uint32_t verdict) } } -int nft_str2verdict(const char *verdict, int *verdict_num) +int nftnl_str2verdict(const char *verdict, int *verdict_num) { if (strcmp(verdict, "accept") == 0) { *verdict_num = NF_ACCEPT; @@ -179,53 +178,53 @@ int nft_str2verdict(const char *verdict, int *verdict_num) return -1; } -enum nft_cmd_type nft_flag2cmd(uint32_t flags) +enum nftnl_cmd_type nftnl_flag2cmd(uint32_t flags) { - if (flags & NFT_OF_EVENT_NEW) - return NFT_CMD_ADD; - else if (flags & NFT_OF_EVENT_DEL) - return NFT_CMD_DELETE; + if (flags & NFTNL_OF_EVENT_NEW) + return NFTNL_CMD_ADD; + else if (flags & NFTNL_OF_EVENT_DEL) + return NFTNL_CMD_DELETE; - return NFT_CMD_UNSPEC; + return NFTNL_CMD_UNSPEC; } -const char *cmd2tag[NFT_CMD_MAX] = { - [NFT_CMD_ADD] = ADD, - [NFT_CMD_INSERT] = INSERT, - [NFT_CMD_DELETE] = DELETE, - [NFT_CMD_REPLACE] = REPLACE, - [NFT_CMD_FLUSH] = FLUSH, +const char *cmd2tag[NFTNL_CMD_MAX] = { + [NFTNL_CMD_ADD] = ADD, + [NFTNL_CMD_INSERT] = INSERT, + [NFTNL_CMD_DELETE] = DELETE, + [NFTNL_CMD_REPLACE] = REPLACE, + [NFTNL_CMD_FLUSH] = FLUSH, }; -const char *nft_cmd2tag(enum nft_cmd_type cmd) +const char *nftnl_cmd2tag(enum nftnl_cmd_type cmd) { - if (cmd >= NFT_CMD_MAX) + if (cmd >= NFTNL_CMD_MAX) return "unknown"; return cmd2tag[cmd]; } -uint32_t nft_str2cmd(const char *cmd) +uint32_t nftnl_str2cmd(const char *cmd) { if (strcmp(cmd, ADD) == 0) - return NFT_CMD_ADD; + return NFTNL_CMD_ADD; else if (strcmp(cmd, INSERT) == 0) - return NFT_CMD_INSERT; + return NFTNL_CMD_INSERT; else if (strcmp(cmd, DELETE) == 0) - return NFT_CMD_DELETE; + return NFTNL_CMD_DELETE; else if (strcmp(cmd, REPLACE) == 0) - return NFT_CMD_REPLACE; + return NFTNL_CMD_REPLACE; else if (strcmp(cmd, FLUSH) == 0) - return NFT_CMD_FLUSH; + return NFTNL_CMD_FLUSH; - return NFT_CMD_UNSPEC; + return NFTNL_CMD_UNSPEC; } -int nft_fprintf(FILE *fp, void *obj, uint32_t cmd, uint32_t type, uint32_t flags, +int nftnl_fprintf(FILE *fp, void *obj, uint32_t cmd, uint32_t type, uint32_t flags, int (*snprintf_cb)(char *buf, size_t bufsiz, void *obj, uint32_t cmd, uint32_t type, uint32_t flags)) { - char _buf[NFT_SNPRINTF_BUFSIZ]; + char _buf[NFTNL_SNPRINTF_BUFSIZ]; char *buf = _buf; size_t bufsiz = sizeof(_buf); int ret; @@ -234,7 +233,7 @@ int nft_fprintf(FILE *fp, void *obj, uint32_t cmd, uint32_t type, uint32_t flags if (ret <= 0) goto out; - if (ret >= NFT_SNPRINTF_BUFSIZ) { + if (ret >= NFTNL_SNPRINTF_BUFSIZ) { bufsiz = ret + 1; buf = malloc(bufsiz); @@ -255,7 +254,7 @@ out: return ret; } -void __nft_assert_fail(uint16_t attr, const char *filename, int line) +void __nftnl_assert_fail(uint16_t attr, const char *filename, int line) { fprintf(stderr, "libnftnl: attribute %d assertion failed in %s:%d\n", attr, filename, line); |