summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2015-09-01 20:19:56 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2015-09-07 19:24:19 +0200
commit760768890e60617acfd144dce875a4a3be14513c (patch)
tree14a3a4f53e81fd9b44c8481e123f2c0ceb6f2bff
parentb7154e52fc417e927bef0bbfa5db6e7a71f28602 (diff)
src: rename existing functions to use the nftnl_ prefix
So we can use the nft_* prefix anytime soon for our upcoming higher level library. After this patch, the nft_* symbols become an alias of the nftnl_* symbols. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--examples/nft-chain-add.c28
-rw-r--r--examples/nft-chain-del.c24
-rw-r--r--examples/nft-chain-get.c34
-rw-r--r--examples/nft-chain-parse-add.c46
-rw-r--r--examples/nft-events.c84
-rw-r--r--examples/nft-rule-add.c68
-rw-r--r--examples/nft-rule-del.c22
-rw-r--r--examples/nft-rule-get.c24
-rw-r--r--examples/nft-rule-parse-add.c48
-rw-r--r--examples/nft-ruleset-get.c152
-rw-r--r--examples/nft-ruleset-parse-file.c244
-rw-r--r--examples/nft-set-add.c32
-rw-r--r--examples/nft-set-del.c14
-rw-r--r--examples/nft-set-elem-add.c28
-rw-r--r--examples/nft-set-elem-del.c28
-rw-r--r--examples/nft-set-elem-get.c32
-rw-r--r--examples/nft-set-get.c30
-rw-r--r--examples/nft-set-parse-add.c46
-rw-r--r--examples/nft-table-add.c26
-rw-r--r--examples/nft-table-del.c26
-rw-r--r--examples/nft-table-get.c32
-rw-r--r--examples/nft-table-parse-add.c44
-rw-r--r--examples/nft-table-upd.c14
-rw-r--r--include/buffer.h34
-rw-r--r--include/common.h18
-rw-r--r--include/data_reg.h8
-rw-r--r--include/expr.h6
-rw-r--r--include/expr_ops.h26
-rw-r--r--include/json.h86
-rw-r--r--include/libnftnl/batch.h16
-rw-r--r--include/libnftnl/chain.h110
-rw-r--r--include/libnftnl/common.h66
-rw-r--r--include/libnftnl/expr.h192
-rw-r--r--include/libnftnl/gen.h38
-rw-r--r--include/libnftnl/rule.h112
-rw-r--r--include/libnftnl/ruleset.h86
-rw-r--r--include/libnftnl/set.h190
-rw-r--r--include/libnftnl/table.h84
-rw-r--r--include/set.h8
-rw-r--r--include/set_elem.h8
-rw-r--r--include/utils.h54
-rw-r--r--include/xml.h78
-rw-r--r--src/batch.c55
-rw-r--r--src/buffer.c114
-rw-r--r--src/chain.c593
-rw-r--r--src/common.c94
-rw-r--r--src/expr.c76
-rw-r--r--src/expr/bitwise.c202
-rw-r--r--src/expr/byteorder.c192
-rw-r--r--src/expr/cmp.c152
-rw-r--r--src/expr/counter.c120
-rw-r--r--src/expr/ct.c174
-rw-r--r--src/expr/data_reg.c150
-rw-r--r--src/expr/dynset.c218
-rw-r--r--src/expr/exthdr.c168
-rw-r--r--src/expr/immediate.c196
-rw-r--r--src/expr/limit.c120
-rw-r--r--src/expr/log.c222
-rw-r--r--src/expr/lookup.c148
-rw-r--r--src/expr/masq.c100
-rw-r--r--src/expr/match.c114
-rw-r--r--src/expr/meta.c150
-rw-r--r--src/expr/nat.c250
-rw-r--r--src/expr/payload.c168
-rw-r--r--src/expr/queue.c150
-rw-r--r--src/expr/redir.c148
-rw-r--r--src/expr/reject.c120
-rw-r--r--src/expr/target.c114
-rw-r--r--src/expr_ops.c2
-rw-r--r--src/gen.c80
-rw-r--r--src/jansson.c112
-rw-r--r--src/mxml.c84
-rw-r--r--src/rule.c536
-rw-r--r--src/ruleset.c816
-rw-r--r--src/set.c646
-rw-r--r--src/set_elem.c414
-rw-r--r--src/table.c316
-rw-r--r--src/utils.c125
-rw-r--r--tests/nft-chain-test.c92
-rw-r--r--tests/nft-expr_bitwise-test.c78
-rw-r--r--tests/nft-expr_byteorder-test.c88
-rw-r--r--tests/nft-expr_cmp-test.c72
-rw-r--r--tests/nft-expr_counter-test.c64
-rw-r--r--tests/nft-expr_ct-test.c66
-rw-r--r--tests/nft-expr_exthdr-test.c80
-rw-r--r--tests/nft-expr_immediate-test.c80
-rw-r--r--tests/nft-expr_limit-test.c60
-rw-r--r--tests/nft-expr_log-test.c80
-rw-r--r--tests/nft-expr_lookup-test.c72
-rw-r--r--tests/nft-expr_masq-test.c56
-rw-r--r--tests/nft-expr_match-test.c72
-rw-r--r--tests/nft-expr_meta-test.c64
-rw-r--r--tests/nft-expr_nat-test.c104
-rw-r--r--tests/nft-expr_payload-test.c80
-rw-r--r--tests/nft-expr_queue-test.c66
-rw-r--r--tests/nft-expr_redir-test.c72
-rw-r--r--tests/nft-expr_reject-test.c64
-rw-r--r--tests/nft-expr_target-test.c72
-rw-r--r--tests/nft-parsing-test.c54
-rw-r--r--tests/nft-rule-test.c62
-rw-r--r--tests/nft-set-test.c62
-rw-r--r--tests/nft-table-test.c40
102 files changed, 5742 insertions, 5743 deletions
diff --git a/examples/nft-chain-add.c b/examples/nft-chain-add.c
index f7f640a..c50369e 100644
--- a/examples/nft-chain-add.c
+++ b/examples/nft-chain-add.c
@@ -20,9 +20,9 @@
#include <libmnl/libmnl.h>
#include <libnftnl/chain.h>
-static struct nft_chain *chain_add_parse(int argc, char *argv[])
+static struct nftnl_chain *chain_add_parse(int argc, char *argv[])
{
- struct nft_chain *t;
+ struct nftnl_chain *t;
int hooknum = 0;
if (argc == 6) {
@@ -43,16 +43,16 @@ static struct nft_chain *chain_add_parse(int argc, char *argv[])
}
}
- t = nft_chain_alloc();
+ t = nftnl_chain_alloc();
if (t == NULL) {
perror("OOM");
return NULL;
}
- nft_chain_attr_set(t, NFT_CHAIN_ATTR_TABLE, argv[2]);
- nft_chain_attr_set(t, NFT_CHAIN_ATTR_NAME, argv[3]);
+ nftnl_chain_attr_set(t, NFTNL_CHAIN_ATTR_TABLE, argv[2]);
+ nftnl_chain_attr_set(t, NFTNL_CHAIN_ATTR_NAME, argv[3]);
if (argc == 6) {
- nft_chain_attr_set_u32(t, NFT_CHAIN_ATTR_HOOKNUM, hooknum);
- nft_chain_attr_set_u32(t, NFT_CHAIN_ATTR_PRIO, atoi(argv[5]));
+ nftnl_chain_attr_set_u32(t, NFTNL_CHAIN_ATTR_HOOKNUM, hooknum);
+ nftnl_chain_attr_set_u32(t, NFTNL_CHAIN_ATTR_PRIO, atoi(argv[5]));
}
return t;
@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
struct nlmsghdr *nlh;
uint32_t portid, seq, chain_seq;
int ret, family;
- struct nft_chain *t;
+ struct nftnl_chain *t;
struct mnl_nlmsg_batch *batch;
int batching;
@@ -93,7 +93,7 @@ int main(int argc, char *argv[])
if (t == NULL)
exit(EXIT_FAILURE);
- batching = nft_batch_is_supported();
+ batching = nftnl_batch_is_supported();
if (batching < 0) {
perror("cannot talk to nfnetlink");
exit(EXIT_FAILURE);
@@ -103,20 +103,20 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
if (batching) {
- nft_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
chain_seq = seq;
- nlh = nft_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_NEWCHAIN, family,
NLM_F_ACK, seq++);
- nft_chain_nlmsg_build_payload(nlh, t);
- nft_chain_free(t);
+ nftnl_chain_nlmsg_build_payload(nlh, t);
+ nftnl_chain_free(t);
mnl_nlmsg_batch_next(batch);
if (batching) {
- nft_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
diff --git a/examples/nft-chain-del.c b/examples/nft-chain-del.c
index 2a52a01..0b04daa 100644
--- a/examples/nft-chain-del.c
+++ b/examples/nft-chain-del.c
@@ -20,18 +20,18 @@
#include <libmnl/libmnl.h>
#include <libnftnl/chain.h>
-static struct nft_chain *chain_del_parse(int argc, char *argv[])
+static struct nftnl_chain *chain_del_parse(int argc, char *argv[])
{
- struct nft_chain *t;
+ struct nftnl_chain *t;
- t = nft_chain_alloc();
+ t = nftnl_chain_alloc();
if (t == NULL) {
perror("OOM");
return NULL;
}
- nft_chain_attr_set(t, NFT_CHAIN_ATTR_TABLE, argv[2]);
- nft_chain_attr_set(t, NFT_CHAIN_ATTR_NAME, argv[3]);
+ nftnl_chain_attr_set(t, NFTNL_CHAIN_ATTR_TABLE, argv[2]);
+ nftnl_chain_attr_set(t, NFTNL_CHAIN_ATTR_NAME, argv[3]);
return t;
}
@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, chain_seq;
- struct nft_chain *t;
+ struct nftnl_chain *t;
int ret, family, batching;
if (argc != 4) {
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
if (t == NULL)
exit(EXIT_FAILURE);
- batching = nft_batch_is_supported();
+ batching = nftnl_batch_is_supported();
if (batching < 0) {
perror("cannot talk to nfnetlink");
exit(EXIT_FAILURE);
@@ -79,20 +79,20 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
if (batching) {
- nft_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
chain_seq = seq;
- nlh = nft_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_DELCHAIN, family,
NLM_F_ACK, seq++);
- nft_chain_nlmsg_build_payload(nlh, t);
- nft_chain_free(t);
+ nftnl_chain_nlmsg_build_payload(nlh, t);
+ nftnl_chain_free(t);
mnl_nlmsg_batch_next(batch);
if (batching) {
- nft_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
diff --git a/examples/nft-chain-get.c b/examples/nft-chain-get.c
index 76fa5d9..f743ee3 100644
--- a/examples/nft-chain-get.c
+++ b/examples/nft-chain-get.c
@@ -22,26 +22,26 @@
static int table_cb(const struct nlmsghdr *nlh, void *data)
{
- struct nft_chain *t;
+ struct nftnl_chain *t;
char buf[4096];
uint32_t *type = data;
- t = nft_chain_alloc();
+ t = nftnl_chain_alloc();
if (t == NULL) {
perror("OOM");
goto err;
}
- if (nft_chain_nlmsg_parse(nlh, t) < 0) {
- perror("nft_chain_nlmsg_parse");
+ if (nftnl_chain_nlmsg_parse(nlh, t) < 0) {
+ perror("nftnl_chain_nlmsg_parse");
goto err_free;
}
- nft_chain_snprintf(buf, sizeof(buf), t, *type, 0);
+ nftnl_chain_snprintf(buf, sizeof(buf), t, *type, 0);
printf("%s\n", buf);
err_free:
- nft_chain_free(t);
+ nftnl_chain_free(t);
err:
return MNL_CB_OK;
}
@@ -51,8 +51,8 @@ int main(int argc, char *argv[])
struct mnl_socket *nl;
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
- uint32_t portid, seq, type = NFT_OUTPUT_DEFAULT;
- struct nft_chain *t = NULL;
+ uint32_t portid, seq, type = NFTNL_OUTPUT_DEFAULT;
+ struct nftnl_chain *t = NULL;
int ret, family;
seq = time(NULL);
@@ -79,26 +79,26 @@ int main(int argc, char *argv[])
}
if (argc >= 4) {
- t = nft_chain_alloc();
+ t = nftnl_chain_alloc();
if (t == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
}
- nlh = nft_chain_nlmsg_build_hdr(buf, NFT_MSG_GETCHAIN, family,
+ nlh = nftnl_chain_nlmsg_build_hdr(buf, NFT_MSG_GETCHAIN, family,
NLM_F_ACK, seq);
- nft_chain_attr_set(t, NFT_CHAIN_ATTR_TABLE, argv[2]);
- nft_chain_attr_set(t, NFT_CHAIN_ATTR_NAME, argv[3]);
- nft_chain_nlmsg_build_payload(nlh, t);
- nft_chain_free(t);
+ nftnl_chain_attr_set(t, NFTNL_CHAIN_ATTR_TABLE, argv[2]);
+ nftnl_chain_attr_set(t, NFTNL_CHAIN_ATTR_NAME, argv[3]);
+ nftnl_chain_nlmsg_build_payload(nlh, t);
+ nftnl_chain_free(t);
} else if (argc >= 2) {
- nlh = nft_chain_nlmsg_build_hdr(buf, NFT_MSG_GETCHAIN, family,
+ nlh = nftnl_chain_nlmsg_build_hdr(buf, NFT_MSG_GETCHAIN, family,
NLM_F_DUMP, seq);
}
if (strcmp(argv[argc-1], "xml") == 0){
- type = NFT_OUTPUT_XML;
+ type = NFTNL_OUTPUT_XML;
}else if (strcmp(argv[argc-1], "json") == 0){
- type = NFT_OUTPUT_JSON;
+ type = NFTNL_OUTPUT_JSON;
}
nl = mnl_socket_open(NETLINK_NETFILTER);
diff --git a/examples/nft-chain-parse-add.c b/examples/nft-chain-parse-add.c
index c4e4b88..57accad 100644
--- a/examples/nft-chain-parse-add.c
+++ b/examples/nft-chain-parse-add.c
@@ -26,14 +26,14 @@
#include <libnftnl/chain.h>
#include <libnftnl/rule.h>
-static struct nft_chain *chain_parse_file(const char *file, uint16_t format)
+static struct nftnl_chain *chain_parse_file(const char *file, uint16_t format)
{
int fd;
- struct nft_chain *c;
- struct nft_parse_err *err;
+ struct nftnl_chain *c;
+ struct nftnl_parse_err *err;
char data[4096];
- c = nft_chain_alloc();
+ c = nftnl_chain_alloc();
if (c == NULL) {
perror("OOM");
return NULL;
@@ -53,19 +53,19 @@ static struct nft_chain *chain_parse_file(const char *file, uint16_t format)
close(fd);
- err = nft_parse_err_alloc();
+ err = nftnl_parse_err_alloc();
if (err == NULL) {
perror("OOM");
return NULL;
}
- if (nft_chain_parse(c, format, data, err) < 0) {
- nft_parse_perror("Unable to parse file", err);
- nft_parse_err_free(err);
+ if (nftnl_chain_parse(c, format, data, err) < 0) {
+ nftnl_parse_perror("Unable to parse file", err);
+ nftnl_parse_err_free(err);
return NULL;
}
- nft_parse_err_free(err);
+ nftnl_parse_err_free(err);
return c;
}
@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, chain_seq;
- struct nft_chain *c;
+ struct nftnl_chain *c;
uint16_t family, format, outformat;
int ret, batching;
struct mnl_nlmsg_batch *batch;
@@ -86,11 +86,11 @@ int main(int argc, char *argv[])
}
if (strcmp(argv[1], "xml") == 0) {
- format = NFT_PARSE_XML;
- outformat = NFT_OUTPUT_XML;
+ format = NFTNL_PARSE_XML;
+ outformat = NFTNL_OUTPUT_XML;
} else if (strcmp(argv[1], "json") == 0) {
- format = NFT_PARSE_JSON;
- outformat = NFT_OUTPUT_JSON;
+ format = NFTNL_PARSE_JSON;
+ outformat = NFTNL_OUTPUT_JSON;
} else {
printf("Unknown format: xml, json\n");
exit(EXIT_FAILURE);
@@ -100,14 +100,14 @@ int main(int argc, char *argv[])
if (c == NULL)
exit(EXIT_FAILURE);
- nft_chain_fprintf(stdout, c, outformat, 0);
+ nftnl_chain_fprintf(stdout, c, outformat, 0);
fprintf(stdout, "\n");
- nft_chain_attr_unset(c, NFT_CHAIN_ATTR_HANDLE);
- family = nft_chain_attr_get_u32(c, NFT_CHAIN_ATTR_FAMILY);
+ nftnl_chain_attr_unset(c, NFTNL_CHAIN_ATTR_HANDLE);
+ family = nftnl_chain_attr_get_u32(c, NFTNL_CHAIN_ATTR_FAMILY);
seq = time(NULL);
- batching = nft_batch_is_supported();
+ batching = nftnl_batch_is_supported();
if (batching < 0) {
perror("cannot talk to nfnetlink");
exit(EXIT_FAILURE);
@@ -116,20 +116,20 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
if (batching) {
- nft_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
chain_seq = seq;
- nlh = nft_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_NEWCHAIN, family,
NLM_F_ACK, seq++);
- nft_chain_nlmsg_build_payload(nlh, c);
- nft_chain_free(c);
+ nftnl_chain_nlmsg_build_payload(nlh, c);
+ nftnl_chain_free(c);
mnl_nlmsg_batch_next(batch);
if (batching) {
- nft_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
diff --git a/examples/nft-events.c b/examples/nft-events.c
index ef860d3..885af45 100644
--- a/examples/nft-events.c
+++ b/examples/nft-events.c
@@ -34,13 +34,13 @@ static uint32_t event2flag(uint32_t event)
case NFT_MSG_NEWSET:
case NFT_MSG_NEWSETELEM:
case NFT_MSG_NEWGEN:
- return NFT_OF_EVENT_NEW;
+ return NFTNL_OF_EVENT_NEW;
case NFT_MSG_DELTABLE:
case NFT_MSG_DELCHAIN:
case NFT_MSG_DELRULE:
case NFT_MSG_DELSET:
case NFT_MSG_DELSETELEM:
- return NFT_OF_EVENT_DEL;
+ return NFTNL_OF_EVENT_DEL;
}
return 0;
@@ -48,96 +48,96 @@ static uint32_t event2flag(uint32_t event)
static int table_cb(const struct nlmsghdr *nlh, int event, int type)
{
- struct nft_table *t;
+ struct nftnl_table *t;
- t = nft_table_alloc();
+ t = nftnl_table_alloc();
if (t == NULL) {
perror("OOM");
goto err;
}
- if (nft_table_nlmsg_parse(nlh, t) < 0) {
- perror("nft_table_nlmsg_parse");
+ if (nftnl_table_nlmsg_parse(nlh, t) < 0) {
+ perror("nftnl_table_nlmsg_parse");
goto err_free;
}
- nft_table_fprintf(stdout, t, type, event2flag(event));
+ nftnl_table_fprintf(stdout, t, type, event2flag(event));
fprintf(stdout, "\n");
err_free:
- nft_table_free(t);
+ nftnl_table_free(t);
err:
return MNL_CB_OK;
}
static int rule_cb(const struct nlmsghdr *nlh, int event, int type)
{
- struct nft_rule *t;
+ struct nftnl_rule *t;
- t = nft_rule_alloc();
+ t = nftnl_rule_alloc();
if (t == NULL) {
perror("OOM");
goto err;
}
- if (nft_rule_nlmsg_parse(nlh, t) < 0) {
- perror("nft_rule_nlmsg_parse");
+ if (nftnl_rule_nlmsg_parse(nlh, t) < 0) {
+ perror("nftnl_rule_nlmsg_parse");
goto err_free;
}
- nft_rule_fprintf(stdout, t, type, event2flag(event));
+ nftnl_rule_fprintf(stdout, t, type, event2flag(event));
fprintf(stdout, "\n");
err_free:
- nft_rule_free(t);
+ nftnl_rule_free(t);
err:
return MNL_CB_OK;
}
static int chain_cb(const struct nlmsghdr *nlh, int event, int type)
{
- struct nft_chain *t;
+ struct nftnl_chain *t;
- t = nft_chain_alloc();
+ t = nftnl_chain_alloc();
if (t == NULL) {
perror("OOM");
goto err;
}
- if (nft_chain_nlmsg_parse(nlh, t) < 0) {
- perror("nft_chain_nlmsg_parse");
+ if (nftnl_chain_nlmsg_parse(nlh, t) < 0) {
+ perror("nftnl_chain_nlmsg_parse");
goto err_free;
}
- nft_chain_fprintf(stdout, t, type, event2flag(event));
+ nftnl_chain_fprintf(stdout, t, type, event2flag(event));
fprintf(stdout, "\n");
err_free:
- nft_chain_free(t);
+ nftnl_chain_free(t);
err:
return MNL_CB_OK;
}
static int set_cb(const struct nlmsghdr *nlh, int event, int type)
{
- struct nft_set *t;
+ struct nftnl_set *t;
- t = nft_set_alloc();
+ t = nftnl_set_alloc();
if (t == NULL) {
perror("OOM");
goto err;
}
- if (nft_set_nlmsg_parse(nlh, t) < 0) {
- perror("nft_set_nlmsg_parse");
+ if (nftnl_set_nlmsg_parse(nlh, t) < 0) {
+ perror("nftnl_set_nlmsg_parse");
goto err_free;
}
- nft_set_fprintf(stdout, t, type, event2flag(event));
+ nftnl_set_fprintf(stdout, t, type, event2flag(event));
fprintf(stdout, "\n");
err_free:
- nft_set_free(t);
+ nftnl_set_free(t);
err:
return MNL_CB_OK;
}
@@ -145,47 +145,47 @@ err:
static int setelem_cb(const struct nlmsghdr *nlh, int event, int type)
{
- struct nft_set *s;
+ struct nftnl_set *s;
- s = nft_set_alloc();
+ s = nftnl_set_alloc();
if (s == NULL) {
perror("OOM");
goto err;
}
- if (nft_set_elems_nlmsg_parse(nlh, s) < 0) {
- perror("nft_set_nlmsg_parse");
+ if (nftnl_set_elems_nlmsg_parse(nlh, s) < 0) {
+ perror("nftnl_set_nlmsg_parse");
goto err_free;
}
- nft_set_fprintf(stdout, s, type, event2flag(event));
+ nftnl_set_fprintf(stdout, s, type, event2flag(event));
fprintf(stdout, "\n");
err_free:
- nft_set_free(s);
+ nftnl_set_free(s);
err:
return MNL_CB_OK;
}
static int gen_cb(const struct nlmsghdr *nlh, int event, int type)
{
- struct nft_gen *gen;
+ struct nftnl_gen *gen;
- gen = nft_gen_alloc();
+ gen = nftnl_gen_alloc();
if (gen == NULL) {
perror("OOM");
goto err;
}
- if (nft_gen_nlmsg_parse(nlh, gen) < 0) {
- perror("nft_gen_parse");
+ if (nftnl_gen_nlmsg_parse(nlh, gen) < 0) {
+ perror("nftnl_gen_parse");
goto err_free;
}
- nft_gen_fprintf(stdout, gen, type, event2flag(event));
+ nftnl_gen_fprintf(stdout, gen, type, event2flag(event));
fprintf(stdout, "\n");
err_free:
- nft_gen_free(gen);
+ nftnl_gen_free(gen);
err:
return MNL_CB_OK;
}
@@ -233,15 +233,15 @@ int main(int argc, char *argv[])
switch (argc) {
case 1:
- type = NFT_OUTPUT_DEFAULT;
+ type = NFTNL_OUTPUT_DEFAULT;
break;
case 2:
if (strcmp(argv[1], "xml") == 0) {
- type = NFT_OUTPUT_XML;
+ type = NFTNL_OUTPUT_XML;
} else if (strcmp(argv[1], "json") == 0) {
- type = NFT_OUTPUT_JSON;
+ type = NFTNL_OUTPUT_JSON;
} else if (strcmp(argv[1], "default") == 0) {
- type = NFT_OUTPUT_DEFAULT;
+ type = NFTNL_OUTPUT_DEFAULT;
} else {
fprintf(stderr, "unknown format type `%s'\n", argv[1]);
return EXIT_FAILURE;
diff --git a/examples/nft-rule-add.c b/examples/nft-rule-add.c
index 6961d0d..a111bc5 100644
--- a/examples/nft-rule-add.c
+++ b/examples/nft-rule-add.c
@@ -29,77 +29,77 @@
#include <libnftnl/rule.h>
#include <libnftnl/expr.h>
-static void add_payload(struct nft_rule *r, uint32_t base, uint32_t dreg,
+static void add_payload(struct nftnl_rule *r, uint32_t base, uint32_t dreg,
uint32_t offset, uint32_t len)
{
- struct nft_rule_expr *e;
+ struct nftnl_rule_expr *e;
- e = nft_rule_expr_alloc("payload");
+ e = nftnl_rule_expr_alloc("payload");
if (e == NULL) {
perror("expr payload oom");
exit(EXIT_FAILURE);
}
- nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_BASE, base);
- nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_DREG, dreg);
- nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_OFFSET, offset);
- nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_LEN, len);
+ nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_BASE, base);
+ nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_DREG, dreg);
+ nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_OFFSET, offset);
+ nftnl_rule_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_LEN, len);
- nft_rule_add_expr(r, e);
+ nftnl_rule_add_expr(r, e);
}
-static void add_cmp(struct nft_rule *r, uint32_t sreg, uint32_t op,
+static void add_cmp(struct nftnl_rule *r, uint32_t sreg, uint32_t op,
const void *data, uint32_t data_len)
{
- struct nft_rule_expr *e;
+ struct nftnl_rule_expr *e;
- e = nft_rule_expr_alloc("cmp");
+ e = nftnl_rule_expr_alloc("cmp");
if (e == NULL) {
perror("expr cmp oom");
exit(EXIT_FAILURE);
}
- nft_rule_expr_set_u32(e, NFT_EXPR_CMP_SREG, sreg);
- nft_rule_expr_set_u32(e, NFT_EXPR_CMP_OP, op);
- nft_rule_expr_set(e, NFT_EXPR_CMP_DATA, data, data_len);
+ nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CMP_SREG, sreg);
+ nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CMP_OP, op);
+ nftnl_rule_expr_set(e, NFTNL_EXPR_CMP_DATA, data, data_len);
- nft_rule_add_expr(r, e);
+ nftnl_rule_add_expr(r, e);
}
-static void add_counter(struct nft_rule *r)
+static void add_counter(struct nftnl_rule *r)
{
- struct nft_rule_expr *e;
+ struct nftnl_rule_expr *e;
- e = nft_rule_expr_alloc("counter");
+ e = nftnl_rule_expr_alloc("counter");
if (e == NULL) {
perror("expr counter oom");
exit(EXIT_FAILURE);
}
- nft_rule_add_expr(r, e);
+ nftnl_rule_add_expr(r, e);
}
-static struct nft_rule *setup_rule(uint8_t family, const char *table,
+static struct nftnl_rule *setup_rule(uint8_t family, const char *table,
const char *chain, const char *handle)
{
- struct nft_rule *r = NULL;
+ struct nftnl_rule *r = NULL;
uint8_t proto;
uint16_t dport;
uint64_t handle_num;
- r = nft_rule_alloc();
+ r = nftnl_rule_alloc();
if (r == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
}
- nft_rule_attr_set(r, NFT_RULE_ATTR_TABLE, table);
- nft_rule_attr_set(r, NFT_RULE_ATTR_CHAIN, chain);
- nft_rule_attr_set_u32(r, NFT_RULE_ATTR_FAMILY, family);
+ nftnl_rule_attr_set(r, NFTNL_RULE_ATTR_TABLE, table);
+ nftnl_rule_attr_set(r, NFTNL_RULE_ATTR_CHAIN, chain);
+ nftnl_rule_attr_set_u32(r, NFTNL_RULE_ATTR_FAMILY, family);
if (handle != NULL) {
handle_num = atoll(handle);
- nft_rule_attr_set_u64(r, NFT_RULE_ATTR_POSITION, handle_num);
+ nftnl_rule_attr_set_u64(r, NFTNL_RULE_ATTR_POSITION, handle_num);
}
proto = IPPROTO_TCP;
@@ -117,7 +117,7 @@ static struct nft_rule *setup_rule(uint8_t family, const char *table,
return r;
}
-static void nft_mnl_batch_put(char *buf, uint16_t type, uint32_t seq)
+static void nftnl_mnl_batch_put(char *buf, uint16_t type, uint32_t seq)
{
struct nlmsghdr *nlh;
struct nfgenmsg *nfg;
@@ -136,7 +136,7 @@ static void nft_mnl_batch_put(char *buf, uint16_t type, uint32_t seq)
int main(int argc, char *argv[])
{
struct mnl_socket *nl;
- struct nft_rule *r;
+ struct nftnl_rule *r;
struct nlmsghdr *nlh;
struct mnl_nlmsg_batch *batch;
uint8_t family;
@@ -176,20 +176,20 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
- nft_mnl_batch_put(mnl_nlmsg_batch_current(batch),
+ nftnl_mnl_batch_put(mnl_nlmsg_batch_current(batch),
NFNL_MSG_BATCH_BEGIN, seq++);
mnl_nlmsg_batch_next(batch);
- nlh = nft_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_NEWRULE,
- nft_rule_attr_get_u32(r, NFT_RULE_ATTR_FAMILY),
+ nftnl_rule_attr_get_u32(r, NFTNL_RULE_ATTR_FAMILY),
NLM_F_APPEND|NLM_F_CREATE|NLM_F_ACK, seq++);
- nft_rule_nlmsg_build_payload(nlh, r);
- nft_rule_free(r);
+ nftnl_rule_nlmsg_build_payload(nlh, r);
+ nftnl_rule_free(r);
mnl_nlmsg_batch_next(batch);
- nft_mnl_batch_put(mnl_nlmsg_batch_current(batch), NFNL_MSG_BATCH_END,
+ nftnl_mnl_batch_put(mnl_nlmsg_batch_current(batch), NFNL_MSG_BATCH_END,
seq++);
mnl_nlmsg_batch_next(batch);
diff --git a/examples/nft-rule-del.c b/examples/nft-rule-del.c
index cec9440..5927c61 100644
--- a/examples/nft-rule-del.c
+++ b/examples/nft-rule-del.c
@@ -22,7 +22,7 @@
#include <libmnl/libmnl.h>
#include <libnftnl/rule.h>
-static void nft_mnl_batch_put(char *buf, uint16_t type, uint32_t seq)
+static void nftnl_mnl_batch_put(char *buf, uint16_t type, uint32_t seq)
{
struct nlmsghdr *nlh;
struct nfgenmsg *nfg;
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
struct nlmsghdr *nlh;
struct mnl_nlmsg_batch *batch;
uint32_t portid, seq;
- struct nft_rule *r = NULL;
+ struct nftnl_rule *r = NULL;
int ret, family;
if (argc < 4 || argc > 5) {
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- r = nft_rule_alloc();
+ r = nftnl_rule_alloc();
if (r == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
@@ -74,29 +74,29 @@ int main(int argc, char *argv[])
}
seq = time(NULL);
- nft_rule_attr_set(r, NFT_RULE_ATTR_TABLE, argv[2]);
- nft_rule_attr_set(r, NFT_RULE_ATTR_CHAIN, argv[3]);
+ nftnl_rule_attr_set(r, NFTNL_RULE_ATTR_TABLE, argv[2]);
+ nftnl_rule_attr_set(r, NFTNL_RULE_ATTR_CHAIN, argv[3]);
/* If no handle is specified, delete all rules in the chain */
if (argc == 5)
- nft_rule_attr_set_u64(r, NFT_RULE_ATTR_HANDLE, atoi(argv[4]));
+ nftnl_rule_attr_set_u64(r, NFTNL_RULE_ATTR_HANDLE, atoi(argv[4]));
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
- nft_mnl_batch_put(mnl_nlmsg_batch_current(batch),
+ nftnl_mnl_batch_put(mnl_nlmsg_batch_current(batch),
NFNL_MSG_BATCH_BEGIN, seq++);
mnl_nlmsg_batch_next(batch);
- nlh = nft_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_DELRULE,
family,
NLM_F_ACK, seq++);
- nft_rule_nlmsg_build_payload(nlh, r);
- nft_rule_free(r);
+ nftnl_rule_nlmsg_build_payload(nlh, r);
+ nftnl_rule_free(r);
mnl_nlmsg_batch_next(batch);
- nft_mnl_batch_put(mnl_nlmsg_batch_current(batch), NFNL_MSG_BATCH_END,
+ nftnl_mnl_batch_put(mnl_nlmsg_batch_current(batch), NFNL_MSG_BATCH_END,
seq++);
mnl_nlmsg_batch_next(batch);
diff --git a/examples/nft-rule-get.c b/examples/nft-rule-get.c
index 5803143..54bee73 100644
--- a/examples/nft-rule-get.c
+++ b/examples/nft-rule-get.c
@@ -22,26 +22,26 @@
static int table_cb(const struct nlmsghdr *nlh, void *data)
{
- struct nft_rule *t;
+ struct nftnl_rule *t;
char buf[4096];
uint32_t *type = data;
- t = nft_rule_alloc();
+ t = nftnl_rule_alloc();
if (t == NULL) {
perror("OOM");
goto err;
}
- if (nft_rule_nlmsg_parse(nlh, t) < 0) {
- perror("nft_rule_nlmsg_parse");
+ if (nftnl_rule_nlmsg_parse(nlh, t) < 0) {
+ perror("nftnl_rule_nlmsg_parse");
goto err_free;
}
- nft_rule_snprintf(buf, sizeof(buf), t, *type, 0);
+ nftnl_rule_snprintf(buf, sizeof(buf), t, *type, 0);
printf("%s\n", buf);
err_free:
- nft_rule_free(t);
+ nftnl_rule_free(t);
err:
return MNL_CB_OK;
}
@@ -51,8 +51,8 @@ int main(int argc, char *argv[])
struct mnl_socket *nl;
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
- uint32_t portid, seq, type = NFT_OUTPUT_DEFAULT;
- struct nft_rule *t = NULL;
+ uint32_t portid, seq, type = NFTNL_OUTPUT_DEFAULT;
+ struct nftnl_rule *t = NULL;
int ret, family;
if (argc < 2 || argc > 3) {
@@ -78,21 +78,21 @@ int main(int argc, char *argv[])
if (argc == 3) {
if (strcmp(argv[2], "xml") == 0)
- type = NFT_OUTPUT_XML;
+ type = NFTNL_OUTPUT_XML;
else if (strcmp(argv[2], "json") == 0)
- type = NFT_OUTPUT_JSON;
+ type = NFTNL_OUTPUT_JSON;
}
/* XXX requires table, chain and handle attributes for selective get */
- t = nft_rule_alloc();
+ t = nftnl_rule_alloc();
if (t == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
}
seq = time(NULL);
- nlh = nft_rule_nlmsg_build_hdr(buf, NFT_MSG_GETRULE, family,
+ nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_GETRULE, family,
NLM_F_DUMP, seq);
nl = mnl_socket_open(NETLINK_NETFILTER);
diff --git a/examples/nft-rule-parse-add.c b/examples/nft-rule-parse-add.c
index 75f5268..3413070 100644
--- a/examples/nft-rule-parse-add.c
+++ b/examples/nft-rule-parse-add.c
@@ -27,11 +27,11 @@
#include <libmnl/libmnl.h>
#include <libnftnl/rule.h>
-static struct nft_rule *rule_parse_file(const char *file, uint16_t format)
+static struct nftnl_rule *rule_parse_file(const char *file, uint16_t format)
{
int fd;
- struct nft_rule *r;
- struct nft_parse_err *err;
+ struct nftnl_rule *r;
+ struct nftnl_parse_err *err;
char data[4096];
fd = open(file, O_RDONLY);
@@ -47,28 +47,28 @@ static struct nft_rule *rule_parse_file(const char *file, uint16_t format)
}
close(fd);
- r = nft_rule_alloc();
+ r = nftnl_rule_alloc();
if (r == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
}
- err = nft_parse_err_alloc();
+ err = nftnl_parse_err_alloc();
if (err == NULL) {
perror("error");
exit(EXIT_FAILURE);
}
- if (nft_rule_parse(r, format, data, err) < 0) {
- nft_parse_perror("Unable to parse file", err);
- nft_parse_err_free(err);
- nft_rule_free(r);
+ if (nftnl_rule_parse(r, format, data, err) < 0) {
+ nftnl_parse_perror("Unable to parse file", err);
+ nftnl_parse_err_free(err);
+ nftnl_rule_free(r);
return NULL;
}
- nft_rule_attr_unset(r, NFT_RULE_ATTR_HANDLE);
+ nftnl_rule_attr_unset(r, NFTNL_RULE_ATTR_HANDLE);
- nft_parse_err_free(err);
+ nftnl_parse_err_free(err);
return r;
}
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, rule_seq;
- struct nft_rule *r;
+ struct nftnl_rule *r;
int ret, batching;
uint16_t family, format, outformat;
@@ -89,11 +89,11 @@ int main(int argc, char *argv[])
}
if (strcmp(argv[1], "xml") == 0) {
- format = NFT_PARSE_XML;
- outformat = NFT_OUTPUT_XML;
+ format = NFTNL_PARSE_XML;
+ outformat = NFTNL_OUTPUT_XML;
} else if (strcmp(argv[1], "json") == 0) {
- format = NFT_PARSE_JSON;
- outformat = NFT_OUTPUT_JSON;
+ format = NFTNL_PARSE_JSON;
+ outformat = NFTNL_OUTPUT_JSON;
} else {
printf("Unknown format: xml, json\n");
exit(EXIT_FAILURE);
@@ -103,10 +103,10 @@ int main(int argc, char *argv[])
if (r == NULL)
exit(EXIT_FAILURE);
- nft_rule_fprintf(stdout, r, outformat, 0);
+ nftnl_rule_fprintf(stdout, r, outformat, 0);
fprintf(stdout, "\n");
- batching = nft_batch_is_supported();
+ batching = nftnl_batch_is_supported();
if (batching < 0) {
perror("Cannot talk to nfnetlink");
exit(EXIT_FAILURE);
@@ -116,22 +116,22 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
if (batching) {
- nft_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
rule_seq = seq;
- family = nft_rule_attr_get_u32(r, NFT_RULE_ATTR_FAMILY);
- nlh = nft_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ family = nftnl_rule_attr_get_u32(r, NFTNL_RULE_ATTR_FAMILY);
+ nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_NEWRULE, family,
NLM_F_CREATE|NLM_F_APPEND|NLM_F_ACK,
seq++);
- nft_rule_nlmsg_build_payload(nlh, r);
- nft_rule_free(r);
+ nftnl_rule_nlmsg_build_payload(nlh, r);
+ nftnl_rule_free(r);
mnl_nlmsg_batch_next(batch);
if (batching) {
- nft_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
diff --git a/examples/nft-ruleset-get.c b/examples/nft-ruleset-get.c
index 18de2a9..014a9e7 100644
--- a/examples/nft-ruleset-get.c
+++ b/examples/nft-ruleset-get.c
@@ -67,37 +67,37 @@ out:
*/
static int rule_cb(const struct nlmsghdr *nlh, void *data)
{
- struct nft_rule_list *nlr_list = data;
- struct nft_rule *r;
+ struct nftnl_rule_list *nlr_list = data;
+ struct nftnl_rule *r;
- r = nft_rule_alloc();
+ r = nftnl_rule_alloc();
if (r == NULL)
memory_allocation_error();
- if (nft_rule_nlmsg_parse(nlh, r) < 0)
+ if (nftnl_rule_nlmsg_parse(nlh, r) < 0)
goto err_free;
- nft_rule_list_add_tail(r, nlr_list);
+ nftnl_rule_list_add_tail(r, nlr_list);
return MNL_CB_OK;
err_free:
- nft_rule_free(r);
+ nftnl_rule_free(r);
return MNL_CB_OK;
}
-static struct nft_rule_list *mnl_rule_dump(struct mnl_socket *nf_sock,
+static struct nftnl_rule_list *mnl_rule_dump(struct mnl_socket *nf_sock,
int family)
{
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
- struct nft_rule_list *nlr_list;
+ struct nftnl_rule_list *nlr_list;
int ret;
- nlr_list = nft_rule_list_alloc();
+ nlr_list = nftnl_rule_list_alloc();
if (nlr_list == NULL)
memory_allocation_error();
- nlh = nft_rule_nlmsg_build_hdr(buf, NFT_MSG_GETRULE, family,
+ nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_GETRULE, family,
NLM_F_DUMP, seq);
ret = mnl_talk(nf_sock, nlh, nlh->nlmsg_len, rule_cb, nlr_list);
@@ -106,7 +106,7 @@ static struct nft_rule_list *mnl_rule_dump(struct mnl_socket *nf_sock,
return nlr_list;
err:
- nft_rule_list_free(nlr_list);
+ nftnl_rule_list_free(nlr_list);
return NULL;
}
@@ -115,37 +115,37 @@ err:
*/
static int chain_cb(const struct nlmsghdr *nlh, void *data)
{
- struct nft_chain_list *nlc_list = data;
- struct nft_chain *c;
+ struct nftnl_chain_list *nlc_list = data;
+ struct nftnl_chain *c;
- c = nft_chain_alloc();
+ c = nftnl_chain_alloc();
if (c == NULL)
memory_allocation_error();
- if (nft_chain_nlmsg_parse(nlh, c) < 0)
+ if (nftnl_chain_nlmsg_parse(nlh, c) < 0)
goto err_free;
- nft_chain_list_add_tail(c, nlc_list);
+ nftnl_chain_list_add_tail(c, nlc_list);
return MNL_CB_OK;
err_free:
- nft_chain_free(c);
+ nftnl_chain_free(c);
return MNL_CB_OK;
}
-static struct nft_chain_list *mnl_chain_dump(struct mnl_socket *nf_sock,
+static struct nftnl_chain_list *mnl_chain_dump(struct mnl_socket *nf_sock,
int family)
{
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
- struct nft_chain_list *nlc_list;
+ struct nftnl_chain_list *nlc_list;
int ret;
- nlc_list = nft_chain_list_alloc();
+ nlc_list = nftnl_chain_list_alloc();
if (nlc_list == NULL)
memory_allocation_error();
- nlh = nft_chain_nlmsg_build_hdr(buf, NFT_MSG_GETCHAIN, family,
+ nlh = nftnl_chain_nlmsg_build_hdr(buf, NFT_MSG_GETCHAIN, family,
NLM_F_DUMP, seq);
ret = mnl_talk(nf_sock, nlh, nlh->nlmsg_len, chain_cb, nlc_list);
@@ -154,7 +154,7 @@ static struct nft_chain_list *mnl_chain_dump(struct mnl_socket *nf_sock,
return nlc_list;
err:
- nft_chain_list_free(nlc_list);
+ nftnl_chain_list_free(nlc_list);
return NULL;
}
@@ -163,37 +163,37 @@ err:
*/
static int table_cb(const struct nlmsghdr *nlh, void *data)
{
- struct nft_table_list *nlt_list = data;
- struct nft_table *t;
+ struct nftnl_table_list *nlt_list = data;
+ struct nftnl_table *t;
- t = nft_table_alloc();
+ t = nftnl_table_alloc();
if (t == NULL)
memory_allocation_error();
- if (nft_table_nlmsg_parse(nlh, t) < 0)
+ if (nftnl_table_nlmsg_parse(nlh, t) < 0)
goto err_free;
- nft_table_list_add_tail(t, nlt_list);
+ nftnl_table_list_add_tail(t, nlt_list);
return MNL_CB_OK;
err_free:
- nft_table_free(t);
+ nftnl_table_free(t);
return MNL_CB_OK;
}
-static struct nft_table_list *mnl_table_dump(struct mnl_socket *nf_sock,
+static struct nftnl_table_list *mnl_table_dump(struct mnl_socket *nf_sock,
int family)
{
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
- struct nft_table_list *nlt_list;
+ struct nftnl_table_list *nlt_list;
int ret;
- nlt_list = nft_table_list_alloc();
+ nlt_list = nftnl_table_list_alloc();
if (nlt_list == NULL)
memory_allocation_error();
- nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
+ nlh = nftnl_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
NLM_F_DUMP, seq);
ret = mnl_talk(nf_sock, nlh, nlh->nlmsg_len, table_cb, nlt_list);
@@ -202,7 +202,7 @@ static struct nft_table_list *mnl_table_dump(struct mnl_socket *nf_sock,
return nlt_list;
err:
- nft_table_list_free(nlt_list);
+ nftnl_table_list_free(nlt_list);
return NULL;
}
@@ -211,19 +211,19 @@ err:
*/
static int set_elem_cb(const struct nlmsghdr *nlh, void *data)
{
- nft_set_elems_nlmsg_parse(nlh, data);
+ nftnl_set_elems_nlmsg_parse(nlh, data);
return MNL_CB_OK;
}
-static int mnl_setelem_get(struct mnl_socket *nf_sock, struct nft_set *nls)
+static int mnl_setelem_get(struct mnl_socket *nf_sock, struct nftnl_set *nls)
{
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
- uint32_t family = nft_set_attr_get_u32(nls, NFT_SET_ATTR_FAMILY);
+ uint32_t family = nftnl_set_attr_get_u32(nls, NFTNL_SET_ATTR_FAMILY);
- nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_GETSETELEM, family,
+ nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_GETSETELEM, family,
NLM_F_DUMP|NLM_F_ACK, seq);
- nft_set_nlmsg_build_payload(nlh, nls);
+ nftnl_set_nlmsg_build_payload(nlh, nls);
return mnl_talk(nf_sock, nlh, nlh->nlmsg_len, set_elem_cb, nls);
}
@@ -233,45 +233,45 @@ static int mnl_setelem_get(struct mnl_socket *nf_sock, struct nft_set *nls)
*/
static int set_cb(const struct nlmsghdr *nlh, void *data)
{
- struct nft_set_list *nls_list = data;
- struct nft_set *s;
+ struct nftnl_set_list *nls_list = data;
+ struct nftnl_set *s;
- s = nft_set_alloc();
+ s = nftnl_set_alloc();
if (s == NULL)
memory_allocation_error();
- if (nft_set_nlmsg_parse(nlh, s) < 0)
+ if (nftnl_set_nlmsg_parse(nlh, s) < 0)
goto err_free;
- nft_set_list_add_tail(s, nls_list);
+ nftnl_set_list_add_tail(s, nls_list);
return MNL_CB_OK;
err_free:
- nft_set_free(s);
+ nftnl_set_free(s);
return MNL_CB_OK;
}
-static struct nft_set_list *
+static struct nftnl_set_list *
mnl_set_dump(struct mnl_socket *nf_sock, int family)
{
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
- struct nft_set *s;
- struct nft_set_list *nls_list;
- struct nft_set *si;
- struct nft_set_list_iter *i;
+ struct nftnl_set *s;
+ struct nftnl_set_list *nls_list;
+ struct nftnl_set *si;
+ struct nftnl_set_list_iter *i;
int ret;
- s = nft_set_alloc();
+ s = nftnl_set_alloc();
if (s == NULL)
memory_allocation_error();
- nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_GETSET, family,
+ nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_GETSET, family,
NLM_F_DUMP|NLM_F_ACK, seq);
- nft_set_nlmsg_build_payload(nlh, s);
- nft_set_free(s);
+ nftnl_set_nlmsg_build_payload(nlh, s);
+ nftnl_set_free(s);
- nls_list = nft_set_list_alloc();
+ nls_list = nftnl_set_list_alloc();
if (nls_list == NULL)
memory_allocation_error();
@@ -279,25 +279,25 @@ mnl_set_dump(struct mnl_socket *nf_sock, int family)
if (ret < 0)
goto err;
- i = nft_set_list_iter_create(nls_list);
+ i = nftnl_set_list_iter_create(nls_list);
if (i == NULL)
memory_allocation_error();
- si = nft_set_list_iter_next(i);
+ si = nftnl_set_list_iter_next(i);
while (si != NULL) {
if (mnl_setelem_get(nf_sock, si) != 0) {
perror("E: Unable to get set elements");
- nft_set_list_iter_destroy(i);
+ nftnl_set_list_iter_destroy(i);
goto err;
}
- si = nft_set_list_iter_next(i);
+ si = nftnl_set_list_iter_next(i);
}
- nft_set_list_iter_destroy(i);
+ nftnl_set_list_iter_destroy(i);
return nls_list;
err:
- nft_set_list_free(nls_list);
+ nftnl_set_list_free(nls_list);
return NULL;
}
@@ -305,33 +305,33 @@ err:
* ruleset
*/
-static struct nft_ruleset *mnl_ruleset_dump(struct mnl_socket *nf_sock)
+static struct nftnl_ruleset *mnl_ruleset_dump(struct mnl_socket *nf_sock)
{
- struct nft_ruleset *rs;
- struct nft_table_list *t;
- struct nft_chain_list *c;
- struct nft_set_list *s;
- struct nft_rule_list *r;
+ struct nftnl_ruleset *rs;
+ struct nftnl_table_list *t;
+ struct nftnl_chain_list *c;
+ struct nftnl_set_list *s;
+ struct nftnl_rule_list *r;
- rs = nft_ruleset_alloc();
+ rs = nftnl_ruleset_alloc();
if (rs == NULL)
memory_allocation_error();
t = mnl_table_dump(nf_sock, NFPROTO_UNSPEC);
if (t != NULL)
- nft_ruleset_attr_set(rs, NFT_RULESET_ATTR_TABLELIST, t);
+ nftnl_ruleset_attr_set(rs, NFTNL_RULESET_ATTR_TABLELIST, t);
c = mnl_chain_dump(nf_sock, NFPROTO_UNSPEC);
if (c != NULL)
- nft_ruleset_attr_set(rs, NFT_RULESET_ATTR_CHAINLIST, c);
+ nftnl_ruleset_attr_set(rs, NFTNL_RULESET_ATTR_CHAINLIST, c);
s = mnl_set_dump(nf_sock, NFPROTO_UNSPEC);
if (s != NULL)
- nft_ruleset_attr_set(rs, NFT_RULESET_ATTR_SETLIST, s);
+ nftnl_ruleset_attr_set(rs, NFTNL_RULESET_ATTR_SETLIST, s);
r = mnl_rule_dump(nf_sock, NFPROTO_UNSPEC);
if (r != NULL)
- nft_ruleset_attr_set(rs, NFT_RULESET_ATTR_RULELIST, r);
+ nftnl_ruleset_attr_set(rs, NFTNL_RULESET_ATTR_RULELIST, r);
return rs;
}
@@ -339,8 +339,8 @@ static struct nft_ruleset *mnl_ruleset_dump(struct mnl_socket *nf_sock)
int main(int argc, char *argv[])
{
struct mnl_socket *nl;
- uint32_t type = NFT_OUTPUT_DEFAULT;
- struct nft_ruleset *rs;
+ uint32_t type = NFTNL_OUTPUT_DEFAULT;
+ struct nftnl_ruleset *rs;
int ret;
if (argc > 2) {
@@ -351,9 +351,9 @@ int main(int argc, char *argv[])
if (argc == 2) {
if (strcmp(argv[1], "xml") == 0)
- type = NFT_OUTPUT_XML;
+ type = NFTNL_OUTPUT_XML;
else if (strcmp(argv[1], "json") == 0)
- type = NFT_OUTPUT_JSON;
+ type = NFTNL_OUTPUT_JSON;
else {
fprintf(stderr, "Unknown type: {xml|json}\n");
exit(EXIT_FAILURE);
@@ -379,7 +379,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- ret = nft_ruleset_fprintf(stdout, rs, type, 0);
+ ret = nftnl_ruleset_fprintf(stdout, rs, type, 0);
fprintf(stdout, "\n");
if (ret == -1)
diff --git a/examples/nft-ruleset-parse-file.c b/examples/nft-ruleset-parse-file.c
index cac7d0d..2113cd7 100644
--- a/examples/nft-ruleset-parse-file.c
+++ b/examples/nft-ruleset-parse-file.c
@@ -33,26 +33,26 @@
struct mnl_nlmsg_batch *batch;
uint32_t seq;
-static int nft_ruleset_set_elems(const struct nft_parse_ctx *ctx)
+static int nftnl_ruleset_set_elems(const struct nftnl_parse_ctx *ctx)
{
- struct nft_set_elems_iter *iter_elems;
+ struct nftnl_set_elems_iter *iter_elems;
uint16_t nl_type, nl_flags;
uint32_t cmd;
struct nlmsghdr *nlh;
- struct nft_set *set;
+ struct nftnl_set *set;
- cmd = nft_ruleset_ctx_get_u32(ctx, NFT_RULESET_CTX_CMD);
+ cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
- set = nft_ruleset_ctx_get(ctx, NFT_RULESET_CTX_SET);
+ set = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_SET);
if (set == NULL)
return -1;
switch (cmd) {
- case NFT_CMD_ADD:
+ case NFTNL_CMD_ADD:
nl_type = NFT_MSG_NEWSETELEM;
nl_flags = NLM_F_CREATE|NLM_F_EXCL|NLM_F_ACK;
break;
- case NFT_CMD_DELETE:
+ case NFTNL_CMD_DELETE:
nl_type = NFT_MSG_DELSETELEM;
/* This will generate an ACK message for each request. When
* removing NLM_F_ACK, the kernel will only report when things
@@ -64,45 +64,45 @@ static int nft_ruleset_set_elems(const struct nft_parse_ctx *ctx)
goto err;
}
- iter_elems = nft_set_elems_iter_create(set);
+ iter_elems = nftnl_set_elems_iter_create(set);
if (iter_elems == NULL)
goto err;
- nlh = nft_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), nl_type,
- nft_set_attr_get_u32(set,
- NFT_SET_ATTR_FAMILY),
+ nlh = nftnl_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), nl_type,
+ nftnl_set_attr_get_u32(set,
+ NFTNL_SET_ATTR_FAMILY),
nl_flags, seq++);
- nft_set_elems_nlmsg_build_payload_iter(nlh, iter_elems);
+ nftnl_set_elems_nlmsg_build_payload_iter(nlh, iter_elems);
mnl_nlmsg_batch_next(batch);
- nft_set_elems_iter_destroy(iter_elems);
+ nftnl_set_elems_iter_destroy(iter_elems);
return 0;
err:
return -1;
}
-static int nft_ruleset_set(const struct nft_parse_ctx *ctx)
+static int nftnl_ruleset_set(const struct nftnl_parse_ctx *ctx)
{
struct nlmsghdr *nlh;
uint16_t nl_type, nl_flags;
- struct nft_set *set;
+ struct nftnl_set *set;
uint32_t cmd;
int ret;
- cmd = nft_ruleset_ctx_get_u32(ctx, NFT_RULESET_CTX_CMD);
+ cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
- set = nft_ruleset_ctx_get(ctx, NFT_RULESET_CTX_SET);
+ set = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_SET);
if (set == NULL)
return -1;
switch (cmd) {
- case NFT_CMD_ADD:
+ case NFTNL_CMD_ADD:
nl_type = NFT_MSG_NEWSET;
nl_flags = NLM_F_CREATE|NLM_F_ACK;
break;
- case NFT_CMD_DELETE:
+ case NFTNL_CMD_DELETE:
nl_type = NFT_MSG_DELSET;
nl_flags = NLM_F_ACK;
break;
@@ -110,163 +110,163 @@ static int nft_ruleset_set(const struct nft_parse_ctx *ctx)
goto err;
}
- nlh = nft_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
nl_type,
- nft_set_attr_get_u32(set,
- NFT_SET_ATTR_FAMILY),
+ nftnl_set_attr_get_u32(set,
+ NFTNL_SET_ATTR_FAMILY),
nl_flags,
seq++);
- nft_set_nlmsg_build_payload(nlh, set);
+ nftnl_set_nlmsg_build_payload(nlh, set);
mnl_nlmsg_batch_next(batch);
- ret = nft_ruleset_set_elems(ctx);
+ ret = nftnl_ruleset_set_elems(ctx);
return ret;
err:
return -1;
}
-static int nft_ruleset_rule_build_msg(const struct nft_parse_ctx *ctx,
- uint32_t cmd, struct nft_rule *rule)
+static int nftnl_ruleset_rule_build_msg(const struct nftnl_parse_ctx *ctx,
+ uint32_t cmd, struct nftnl_rule *rule)
{
struct nlmsghdr *nlh;
uint16_t nl_type, nl_flags;
switch (cmd) {
- case NFT_CMD_ADD:
+ case NFTNL_CMD_ADD:
nl_type = NFT_MSG_NEWRULE;
nl_flags = NLM_F_APPEND|NLM_F_CREATE|NLM_F_ACK;
- nft_rule_attr_unset(rule, NFT_RULE_ATTR_HANDLE);
+ nftnl_rule_attr_unset(rule, NFTNL_RULE_ATTR_HANDLE);
break;
- case NFT_CMD_DELETE:
+ case NFTNL_CMD_DELETE:
nl_type = NFT_MSG_DELRULE;
nl_flags = NLM_F_ACK;
break;
- case NFT_CMD_REPLACE:
+ case NFTNL_CMD_REPLACE:
nl_type = NFT_MSG_NEWRULE;
nl_flags = NLM_F_REPLACE|NLM_F_ACK;
break;
- case NFT_CMD_INSERT:
+ case NFTNL_CMD_INSERT:
nl_type = NFT_MSG_NEWRULE;
nl_flags = NLM_F_CREATE|NLM_F_ACK;
- nft_rule_attr_unset(rule, NFT_RULE_ATTR_HANDLE);
+ nftnl_rule_attr_unset(rule, NFTNL_RULE_ATTR_HANDLE);
break;
default:
return -1;
}
- nlh = nft_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
nl_type,
- nft_rule_attr_get_u32(rule,
- NFT_RULE_ATTR_FAMILY),
+ nftnl_rule_attr_get_u32(rule,
+ NFTNL_RULE_ATTR_FAMILY),
nl_flags,
seq++);
- nft_rule_nlmsg_build_payload(nlh, rule);
+ nftnl_rule_nlmsg_build_payload(nlh, rule);
mnl_nlmsg_batch_next(batch);
return 0;
}
-static int nft_ruleset_rule(const struct nft_parse_ctx *ctx)
+static int nftnl_ruleset_rule(const struct nftnl_parse_ctx *ctx)
{
- struct nft_rule *rule;
+ struct nftnl_rule *rule;
int ret;
uint32_t cmd;
- cmd = nft_ruleset_ctx_get_u32(ctx, NFT_RULESET_CTX_CMD);
+ cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
- rule = nft_ruleset_ctx_get(ctx, NFT_RULESET_CTX_RULE);
+ rule = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_RULE);
if (rule == NULL)
return -1;
- ret = nft_ruleset_rule_build_msg(ctx, cmd, rule);
+ ret = nftnl_ruleset_rule_build_msg(ctx, cmd, rule);
return ret;
}
-static int nft_ruleset_flush_rules(const struct nft_parse_ctx *ctx)
+static int nftnl_ruleset_flush_rules(const struct nftnl_parse_ctx *ctx)
{
- struct nft_rule *nlr;
- struct nft_table *nlt;
- struct nft_chain *nlc;
+ struct nftnl_rule *nlr;
+ struct nftnl_table *nlt;
+ struct nftnl_chain *nlc;
uint32_t type;
int ret;
- nlr = nft_rule_alloc();
+ nlr = nftnl_rule_alloc();
if (nlr == NULL)
return -1;
- type = nft_ruleset_ctx_get_u32(ctx, NFT_RULESET_CTX_TYPE);
+ type = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_TYPE);
switch (type) {
- case NFT_RULESET_TABLE:
- nlt = nft_ruleset_ctx_get(ctx, NFT_RULESET_CTX_TABLE);
- nft_rule_attr_set(nlr, NFT_RULE_ATTR_TABLE,
- nft_table_attr_get(nlt, NFT_TABLE_ATTR_NAME));
- nft_rule_attr_set(nlr, NFT_RULE_ATTR_FAMILY,
- nft_table_attr_get(nlt, NFT_TABLE_ATTR_FAMILY));
+ case NFTNL_RULESET_TABLE:
+ nlt = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_TABLE);
+ nftnl_rule_attr_set(nlr, NFTNL_RULE_ATTR_TABLE,
+ nftnl_table_attr_get(nlt, NFTNL_TABLE_ATTR_NAME));
+ nftnl_rule_attr_set(nlr, NFTNL_RULE_ATTR_FAMILY,
+ nftnl_table_attr_get(nlt, NFTNL_TABLE_ATTR_FAMILY));
break;
- case NFT_RULESET_CHAIN:
- nlc = nft_ruleset_ctx_get(ctx, NFT_RULESET_CTX_CHAIN);
- nft_rule_attr_set(nlr, NFT_RULE_ATTR_TABLE,
- nft_chain_attr_get(nlc,
- NFT_CHAIN_ATTR_TABLE));
- nft_rule_attr_set(nlr, NFT_RULE_ATTR_CHAIN,
- nft_chain_attr_get(nlc,
- NFT_CHAIN_ATTR_NAME));
- nft_rule_attr_set(nlr, NFT_RULE_ATTR_FAMILY,
- nft_chain_attr_get(nlc, NFT_TABLE_ATTR_FAMILY));
+ case NFTNL_RULESET_CHAIN:
+ nlc = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_CHAIN);
+ nftnl_rule_attr_set(nlr, NFTNL_RULE_ATTR_TABLE,
+ nftnl_chain_attr_get(nlc,
+ NFTNL_CHAIN_ATTR_TABLE));
+ nftnl_rule_attr_set(nlr, NFTNL_RULE_ATTR_CHAIN,
+ nftnl_chain_attr_get(nlc,
+ NFTNL_CHAIN_ATTR_NAME));
+ nftnl_rule_attr_set(nlr, NFTNL_RULE_ATTR_FAMILY,
+ nftnl_chain_attr_get(nlc, NFTNL_TABLE_ATTR_FAMILY));
break;
default:
goto err;
}
- ret = nft_ruleset_rule_build_msg(ctx, NFT_CMD_DELETE, nlr);
- nft_rule_free(nlr);
+ ret = nftnl_ruleset_rule_build_msg(ctx, NFTNL_CMD_DELETE, nlr);
+ nftnl_rule_free(nlr);
return ret;
err:
- nft_rule_free(nlr);
+ nftnl_rule_free(nlr);
return -1;
}
-static int nft_ruleset_chain(const struct nft_parse_ctx *ctx)
+static int nftnl_ruleset_chain(const struct nftnl_parse_ctx *ctx)
{
struct nlmsghdr *nlh;
uint16_t nl_type, nl_flags;
uint32_t cmd;
- struct nft_chain *chain;
+ struct nftnl_chain *chain;
- cmd = nft_ruleset_ctx_get_u32(ctx, NFT_RULESET_CTX_CMD);
+ cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
- chain = nft_ruleset_ctx_get(ctx, NFT_RULESET_CTX_CHAIN);
+ chain = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_CHAIN);
if (chain == NULL)
return -1;
switch (cmd) {
- case NFT_CMD_ADD:
+ case NFTNL_CMD_ADD:
nl_type = NFT_MSG_NEWCHAIN;
nl_flags = NLM_F_CREATE|NLM_F_ACK;
break;
- case NFT_CMD_DELETE:
+ case NFTNL_CMD_DELETE:
nl_type = NFT_MSG_DELCHAIN;
nl_flags = NLM_F_ACK;
break;
- case NFT_CMD_FLUSH:
- return nft_ruleset_flush_rules(ctx);
+ case NFTNL_CMD_FLUSH:
+ return nftnl_ruleset_flush_rules(ctx);
default:
goto err;
}
- nft_chain_attr_unset(chain, NFT_CHAIN_ATTR_HANDLE);
- nlh = nft_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nftnl_chain_attr_unset(chain, NFTNL_CHAIN_ATTR_HANDLE);
+ nlh = nftnl_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
nl_type,
- nft_chain_attr_get_u32(chain,
- NFT_CHAIN_ATTR_FAMILY),
+ nftnl_chain_attr_get_u32(chain,
+ NFTNL_CHAIN_ATTR_FAMILY),
nl_flags,
seq++);
- nft_chain_nlmsg_build_payload(nlh, chain);
+ nftnl_chain_nlmsg_build_payload(nlh, chain);
mnl_nlmsg_batch_next(batch);
return 0;
@@ -274,109 +274,109 @@ err:
return -1;
}
-static int nft_ruleset_table_build_msg(const struct nft_parse_ctx *ctx,
- uint32_t cmd, struct nft_table *table)
+static int nftnl_ruleset_table_build_msg(const struct nftnl_parse_ctx *ctx,
+ uint32_t cmd, struct nftnl_table *table)
{
struct nlmsghdr *nlh;
uint16_t nl_type, nl_flags;
switch (cmd) {
- case NFT_CMD_ADD:
+ case NFTNL_CMD_ADD:
nl_type = NFT_MSG_NEWTABLE;
nl_flags = NLM_F_CREATE|NLM_F_ACK;
break;
- case NFT_CMD_DELETE:
+ case NFTNL_CMD_DELETE:
nl_type = NFT_MSG_DELTABLE;
nl_flags = NLM_F_ACK;
break;
- case NFT_CMD_FLUSH:
- return nft_ruleset_flush_rules(ctx);
+ case NFTNL_CMD_FLUSH:
+ return nftnl_ruleset_flush_rules(ctx);
default:
return -1;
}
- nlh = nft_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
nl_type,
- nft_table_attr_get_u32(table,
- NFT_TABLE_ATTR_FAMILY),
+ nftnl_table_attr_get_u32(table,
+ NFTNL_TABLE_ATTR_FAMILY),
nl_flags,
seq++);
- nft_table_nlmsg_build_payload(nlh, table);
+ nftnl_table_nlmsg_build_payload(nlh, table);
mnl_nlmsg_batch_next(batch);
return 0;
}
-static int nft_ruleset_table(const struct nft_parse_ctx *ctx)
+static int nftnl_ruleset_table(const struct nftnl_parse_ctx *ctx)
{
- struct nft_table *table;
+ struct nftnl_table *table;
uint32_t cmd;
int ret;
- cmd = nft_ruleset_ctx_get_u32(ctx, NFT_RULESET_CTX_CMD);
+ cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
- table = nft_ruleset_ctx_get(ctx, NFT_RULESET_CTX_TABLE);
+ table = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_TABLE);
if (table == NULL)
return -1;
- ret = nft_ruleset_table_build_msg(ctx, cmd, table);
+ ret = nftnl_ruleset_table_build_msg(ctx, cmd, table);
return ret;
}
-static int nft_ruleset_flush_ruleset(const struct nft_parse_ctx *ctx)
+static int nftnl_ruleset_flush_ruleset(const struct nftnl_parse_ctx *ctx)
{
- struct nft_table *table;
+ struct nftnl_table *table;
int ret;
- table = nft_table_alloc();
+ table = nftnl_table_alloc();
if (table == NULL)
return -1;
- ret = nft_ruleset_table_build_msg(ctx, NFT_CMD_DELETE, table);
- nft_table_free(table);
+ ret = nftnl_ruleset_table_build_msg(ctx, NFTNL_CMD_DELETE, table);
+ nftnl_table_free(table);
return ret;
}
-static int ruleset_elems_cb(const struct nft_parse_ctx *ctx)
+static int ruleset_elems_cb(const struct nftnl_parse_ctx *ctx)
{
uint32_t type;
int ret;
- type = nft_ruleset_ctx_get_u32(ctx, NFT_RULESET_CTX_TYPE);
+ type = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_TYPE);
switch (type) {
- case NFT_RULESET_TABLE:
- ret = nft_ruleset_table(ctx);
+ case NFTNL_RULESET_TABLE:
+ ret = nftnl_ruleset_table(ctx);
break;
- case NFT_RULESET_CHAIN:
- ret = nft_ruleset_chain(ctx);
+ case NFTNL_RULESET_CHAIN:
+ ret = nftnl_ruleset_chain(ctx);
break;
- case NFT_RULESET_RULE:
- ret = nft_ruleset_rule(ctx);
+ case NFTNL_RULESET_RULE:
+ ret = nftnl_ruleset_rule(ctx);
break;
- case NFT_RULESET_SET:
- ret = nft_ruleset_set(ctx);
+ case NFTNL_RULESET_SET:
+ ret = nftnl_ruleset_set(ctx);
break;
- case NFT_RULESET_SET_ELEMS:
- ret = nft_ruleset_set_elems(ctx);
+ case NFTNL_RULESET_SET_ELEMS:
+ ret = nftnl_ruleset_set_elems(ctx);
break;
- case NFT_RULESET_RULESET:
- ret = nft_ruleset_flush_ruleset(ctx);
+ case NFTNL_RULESET_RULESET:
+ ret = nftnl_ruleset_flush_ruleset(ctx);
break;
default:
return -1;
}
- nft_ruleset_ctx_free(ctx);
+ nftnl_ruleset_ctx_free(ctx);
return ret;
}
int main(int argc, char *argv[])
{
- struct nft_parse_err *err;
+ struct nftnl_parse_err *err;
const char *filename;
FILE *fp;
int ret = -1, len, batching, portid;
@@ -396,13 +396,13 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- err = nft_parse_err_alloc();
+ err = nftnl_parse_err_alloc();
if (err == NULL) {
perror("error");
exit(EXIT_FAILURE);
}
- batching = nft_batch_is_supported();
+ batching = nftnl_batch_is_supported();
if (batching < 0) {
perror("Cannot talk to nfnetlink");
exit(EXIT_FAILURE);
@@ -412,7 +412,7 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
if (batching) {
- nft_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
ruleset_seq = seq;
@@ -420,10 +420,10 @@ int main(int argc, char *argv[])
filename = argv[1];
len = strlen(filename);
if (len >= 5 && strcmp(&filename[len - 5], ".json") == 0)
- ret = nft_ruleset_parse_file_cb(NFT_PARSE_JSON, fp, err, NULL,
+ ret = nftnl_ruleset_parse_file_cb(NFTNL_PARSE_JSON, fp, err, NULL,
&ruleset_elems_cb);
else if (len >= 4 && strcmp(&filename[len - 4], ".xml") == 0)
- ret = nft_ruleset_parse_file_cb(NFT_PARSE_XML, fp, err, NULL,
+ ret = nftnl_ruleset_parse_file_cb(NFTNL_PARSE_XML, fp, err, NULL,
&ruleset_elems_cb);
else {
printf("the filename %s must to end in .xml or .json\n",
@@ -432,14 +432,14 @@ int main(int argc, char *argv[])
}
if (ret < 0) {
- nft_parse_perror("fail", err);
+ nftnl_parse_perror("fail", err);
exit(EXIT_FAILURE);
}
fclose(fp);
if (batching) {
- nft_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
diff --git a/examples/nft-set-add.c b/examples/nft-set-add.c
index 530aa0a..593627b 100644
--- a/examples/nft-set-add.c
+++ b/examples/nft-set-add.c
@@ -28,28 +28,28 @@
#include <libmnl/libmnl.h>
#include <libnftnl/set.h>
-static struct nft_set *setup_set(uint8_t family, const char *table,
+static struct nftnl_set *setup_set(uint8_t family, const char *table,
const char *name)
{
- struct nft_set *s = NULL;
+ struct nftnl_set *s = NULL;
- s = nft_set_alloc();
+ s = nftnl_set_alloc();
if (s == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
}
- nft_set_attr_set_str(s, NFT_SET_ATTR_TABLE, table);
- nft_set_attr_set_str(s, NFT_SET_ATTR_NAME, name);
- nft_set_attr_set_u32(s, NFT_SET_ATTR_FAMILY, family);
- nft_set_attr_set_u32(s, NFT_SET_ATTR_KEY_LEN, 2);
- nft_set_attr_set_u32(s, NFT_SET_ATTR_ID, 1);
- nft_set_attr_set_u32(s, NFT_SET_ATTR_FLAGS, NFT_SET_CONSTANT);
+ nftnl_set_attr_set_str(s, NFTNL_SET_ATTR_TABLE, table);
+ nftnl_set_attr_set_str(s, NFTNL_SET_ATTR_NAME, name);
+ nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_FAMILY, family);
+ nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_KEY_LEN, 2);
+ nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_ID, 1);
+ nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_FLAGS, NFT_SET_CONSTANT);
return s;
}
-static void nft_mnl_batch_put(char *buf, uint16_t type, uint32_t seq)
+static void nftnl_mnl_batch_put(char *buf, uint16_t type, uint32_t seq)
{
struct nlmsghdr *nlh;
struct nfgenmsg *nfg;
@@ -68,7 +68,7 @@ static void nft_mnl_batch_put(char *buf, uint16_t type, uint32_t seq)
int main(int argc, char *argv[])
{
struct mnl_socket *nl;
- struct nft_set *s;
+ struct nftnl_set *s;
struct nlmsghdr *nlh;
struct mnl_nlmsg_batch *batch;
uint8_t family;
@@ -109,19 +109,19 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
- nft_mnl_batch_put(mnl_nlmsg_batch_current(batch),
+ nftnl_mnl_batch_put(mnl_nlmsg_batch_current(batch),
NFNL_MSG_BATCH_BEGIN, seq++);
mnl_nlmsg_batch_next(batch);
- nlh = nft_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_NEWSET, family,
NLM_F_CREATE|NLM_F_ACK, seq++);
- nft_set_nlmsg_build_payload(nlh, s);
- nft_set_free(s);
+ nftnl_set_nlmsg_build_payload(nlh, s);
+ nftnl_set_free(s);
mnl_nlmsg_batch_next(batch);
- nft_mnl_batch_put(mnl_nlmsg_batch_current(batch), NFNL_MSG_BATCH_END,
+ nftnl_mnl_batch_put(mnl_nlmsg_batch_current(batch), NFNL_MSG_BATCH_END,
seq++);
mnl_nlmsg_batch_next(batch);
diff --git a/examples/nft-set-del.c b/examples/nft-set-del.c
index 5abd3b1..897793a 100644
--- a/examples/nft-set-del.c
+++ b/examples/nft-set-del.c
@@ -26,7 +26,7 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, family;
- struct nft_set *t = NULL;
+ struct nftnl_set *t = NULL;
int ret;
if (argc != 4) {
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- t = nft_set_alloc();
+ t = nftnl_set_alloc();
if (t == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
@@ -54,13 +54,13 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_DELSET, family,
+ nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_DELSET, family,
NLM_F_ACK, seq);
- nft_set_attr_set(t, NFT_SET_ATTR_TABLE, argv[2]);
- nft_set_attr_set(t, NFT_SET_ATTR_NAME, argv[3]);
+ nftnl_set_attr_set(t, NFTNL_SET_ATTR_TABLE, argv[2]);
+ nftnl_set_attr_set(t, NFTNL_SET_ATTR_NAME, argv[3]);
- nft_set_nlmsg_build_payload(nlh, t);
- nft_set_free(t);
+ nftnl_set_nlmsg_build_payload(nlh, t);
+ nftnl_set_free(t);
nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
diff --git a/examples/nft-set-elem-add.c b/examples/nft-set-elem-add.c
index ffc025c..ef155b3 100644
--- a/examples/nft-set-elem-add.c
+++ b/examples/nft-set-elem-add.c
@@ -26,8 +26,8 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, family, data;
- struct nft_set *s;
- struct nft_set_elem *e;
+ struct nftnl_set *s;
+ struct nftnl_set_elem *e;
int ret;
if (argc != 4) {
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- s = nft_set_alloc();
+ s = nftnl_set_alloc();
if (s == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
@@ -55,33 +55,33 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- nft_set_attr_set(s, NFT_SET_ATTR_TABLE, argv[2]);
- nft_set_attr_set(s, NFT_SET_ATTR_NAME, argv[3]);
+ nftnl_set_attr_set(s, NFTNL_SET_ATTR_TABLE, argv[2]);
+ nftnl_set_attr_set(s, NFTNL_SET_ATTR_NAME, argv[3]);
/* Add to dummy elements to set */
- e = nft_set_elem_alloc();
+ e = nftnl_set_elem_alloc();
if (e == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
}
data = 0x1;
- nft_set_elem_attr_set(e, NFT_SET_ELEM_ATTR_KEY, &data, sizeof(data));
- nft_set_elem_add(s, e);
+ nftnl_set_elem_attr_set(e, NFTNL_SET_ELEM_ATTR_KEY, &data, sizeof(data));
+ nftnl_set_elem_add(s, e);
- e = nft_set_elem_alloc();
+ e = nftnl_set_elem_alloc();
if (e == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
}
data = 0x2;
- nft_set_elem_attr_set(e, NFT_SET_ELEM_ATTR_KEY, &data, sizeof(data));
- nft_set_elem_add(s, e);
+ nftnl_set_elem_attr_set(e, NFTNL_SET_ELEM_ATTR_KEY, &data, sizeof(data));
+ nftnl_set_elem_add(s, e);
- nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_NEWSETELEM, family,
+ nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_NEWSETELEM, family,
NLM_F_CREATE|NLM_F_EXCL|NLM_F_ACK, seq);
- nft_set_elems_nlmsg_build_payload(nlh, s);
- nft_set_free(s);
+ nftnl_set_elems_nlmsg_build_payload(nlh, s);
+ nftnl_set_free(s);
nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
diff --git a/examples/nft-set-elem-del.c b/examples/nft-set-elem-del.c
index af70cde..e770224 100644
--- a/examples/nft-set-elem-del.c
+++ b/examples/nft-set-elem-del.c
@@ -26,8 +26,8 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, family, data;
- struct nft_set *s;
- struct nft_set_elem *e;
+ struct nftnl_set *s;
+ struct nftnl_set_elem *e;
int ret;
if (argc != 4) {
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- s = nft_set_alloc();
+ s = nftnl_set_alloc();
if (s == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
@@ -55,33 +55,33 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- nft_set_attr_set(s, NFT_SET_ATTR_TABLE, argv[2]);
- nft_set_attr_set(s, NFT_SET_ATTR_NAME, argv[3]);
+ nftnl_set_attr_set(s, NFTNL_SET_ATTR_TABLE, argv[2]);
+ nftnl_set_attr_set(s, NFTNL_SET_ATTR_NAME, argv[3]);
/* Add to dummy elements to set */
- e = nft_set_elem_alloc();
+ e = nftnl_set_elem_alloc();
if (e == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
}
data = 0x1;
- nft_set_elem_attr_set(e, NFT_SET_ELEM_ATTR_KEY, &data, sizeof(data));
- nft_set_elem_add(s, e);
+ nftnl_set_elem_attr_set(e, NFTNL_SET_ELEM_ATTR_KEY, &data, sizeof(data));
+ nftnl_set_elem_add(s, e);
- e = nft_set_elem_alloc();
+ e = nftnl_set_elem_alloc();
if (e == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
}
data = 0x2;
- nft_set_elem_attr_set(e, NFT_SET_ELEM_ATTR_KEY, &data, sizeof(data));
- nft_set_elem_add(s, e);
+ nftnl_set_elem_attr_set(e, NFTNL_SET_ELEM_ATTR_KEY, &data, sizeof(data));
+ nftnl_set_elem_add(s, e);
- nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_DELSETELEM, family,
+ nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_DELSETELEM, family,
NLM_F_ACK, seq);
- nft_set_elems_nlmsg_build_payload(nlh, s);
- nft_set_free(s);
+ nftnl_set_elems_nlmsg_build_payload(nlh, s);
+ nftnl_set_free(s);
nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
diff --git a/examples/nft-set-elem-get.c b/examples/nft-set-elem-get.c
index 6908c2a..66b5524 100644
--- a/examples/nft-set-elem-get.c
+++ b/examples/nft-set-elem-get.c
@@ -22,26 +22,26 @@
static int set_cb(const struct nlmsghdr *nlh, void *data)
{
- struct nft_set *t;
+ struct nftnl_set *t;
char buf[4096];
uint32_t *type = data;
- t = nft_set_alloc();
+ t = nftnl_set_alloc();
if (t == NULL) {
perror("OOM");
goto err;
}
- if (nft_set_elems_nlmsg_parse(nlh, t) < 0) {
- perror("nft_set_nlmsg_parse");
+ if (nftnl_set_elems_nlmsg_parse(nlh, t) < 0) {
+ perror("nftnl_set_nlmsg_parse");
goto err_free;
}
- nft_set_snprintf(buf, sizeof(buf), t, *type, 0);
+ nftnl_set_snprintf(buf, sizeof(buf), t, *type, 0);
printf("%s\n", buf);
err_free:
- nft_set_free(t);
+ nftnl_set_free(t);
err:
return MNL_CB_OK;
}
@@ -52,8 +52,8 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, family;
- uint32_t type = NFT_OUTPUT_DEFAULT;
- struct nft_set *t = NULL;
+ uint32_t type = NFTNL_OUTPUT_DEFAULT;
+ struct nftnl_set *t = NULL;
int ret;
if (argc < 4 || argc > 5) {
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
argv[0]);
return EXIT_FAILURE;
}
- t = nft_set_alloc();
+ t = nftnl_set_alloc();
if (t == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
@@ -81,16 +81,16 @@ int main(int argc, char *argv[])
}
if (argc == 5 && strcmp(argv[4], "json") == 0 )
- type = NFT_OUTPUT_JSON;
+ type = NFTNL_OUTPUT_JSON;
else if (argc == 5 && strcmp(argv[4], "xml") == 0)
- type = NFT_OUTPUT_XML;
+ type = NFTNL_OUTPUT_XML;
- nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_GETSETELEM, family,
+ nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_GETSETELEM, family,
NLM_F_DUMP|NLM_F_ACK, seq);
- nft_set_attr_set(t, NFT_SET_ATTR_NAME, argv[3]);
- nft_set_attr_set(t, NFT_SET_ATTR_TABLE, argv[2]);
- nft_set_elems_nlmsg_build_payload(nlh, t);
- nft_set_free(t);
+ nftnl_set_attr_set(t, NFTNL_SET_ATTR_NAME, argv[3]);
+ nftnl_set_attr_set(t, NFTNL_SET_ATTR_TABLE, argv[2]);
+ nftnl_set_elems_nlmsg_build_payload(nlh, t);
+ nftnl_set_free(t);
nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
diff --git a/examples/nft-set-get.c b/examples/nft-set-get.c
index 2822025..aec76e8 100644
--- a/examples/nft-set-get.c
+++ b/examples/nft-set-get.c
@@ -22,26 +22,26 @@
static int set_cb(const struct nlmsghdr *nlh, void *data)
{
- struct nft_set *t;
+ struct nftnl_set *t;
char buf[4096];
uint32_t *type = data;
- t = nft_set_alloc();
+ t = nftnl_set_alloc();
if (t == NULL) {
perror("OOM");
goto err;
}
- if (nft_set_nlmsg_parse(nlh, t) < 0) {
- perror("nft_set_nlmsg_parse");
+ if (nftnl_set_nlmsg_parse(nlh, t) < 0) {
+ perror("nftnl_set_nlmsg_parse");
goto err_free;
}
- nft_set_snprintf(buf, sizeof(buf), t, *type, 0);
+ nftnl_set_snprintf(buf, sizeof(buf), t, *type, 0);
printf("%s\n", buf);
err_free:
- nft_set_free(t);
+ nftnl_set_free(t);
err:
return MNL_CB_OK;
}
@@ -52,15 +52,15 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, family;
- uint32_t type = NFT_OUTPUT_DEFAULT;
- struct nft_set *t = NULL;
+ uint32_t type = NFTNL_OUTPUT_DEFAULT;
+ struct nftnl_set *t = NULL;
int ret;
if (argc < 2 || argc > 3) {
fprintf(stderr, "%s <family> [<json|xml>]\n", argv[0]);
return EXIT_FAILURE;
}
- t = nft_set_alloc();
+ t = nftnl_set_alloc();
if (t == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
@@ -82,16 +82,16 @@ int main(int argc, char *argv[])
}
if (argc == 3 && strcmp(argv[2], "json") == 0)
- type = NFT_OUTPUT_JSON;
+ type = NFTNL_OUTPUT_JSON;
else if (argc == 3 && strcmp(argv[2], "xml") == 0)
- type = NFT_OUTPUT_XML;
+ type = NFTNL_OUTPUT_XML;
- nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_GETSET, family,
+ nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_GETSET, family,
NLM_F_DUMP|NLM_F_ACK, seq);
/* Use this below if you want to obtain sets per table */
-/* nft_set_attr_set(t, NFT_SET_ATTR_TABLE, argv[2]); */
- nft_set_nlmsg_build_payload(nlh, t);
- nft_set_free(t);
+/* nftnl_set_attr_set(t, NFT_SET_ATTR_TABLE, argv[2]); */
+ nftnl_set_nlmsg_build_payload(nlh, t);
+ nftnl_set_free(t);
nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
diff --git a/examples/nft-set-parse-add.c b/examples/nft-set-parse-add.c
index f21385f..57326ee 100644
--- a/examples/nft-set-parse-add.c
+++ b/examples/nft-set-parse-add.c
@@ -28,14 +28,14 @@
#include <libmnl/libmnl.h>
#include <libnftnl/set.h>
-static struct nft_set *set_parse_file(const char *file, uint16_t format)
+static struct nftnl_set *set_parse_file(const char *file, uint16_t format)
{
int fd;
- struct nft_set *s;
- struct nft_parse_err *err;
+ struct nftnl_set *s;
+ struct nftnl_parse_err *err;
char data[4096];
- s = nft_set_alloc();
+ s = nftnl_set_alloc();
if (s == NULL) {
perror("OOM");
return NULL;
@@ -54,21 +54,21 @@ static struct nft_set *set_parse_file(const char *file, uint16_t format)
}
close(fd);
- err = nft_parse_err_alloc();
+ err = nftnl_parse_err_alloc();
if (err == NULL) {
perror("error");
return NULL;
}
- if (nft_set_parse(s, format, data, err) < 0) {
- nft_parse_perror("Unable to parse file", err);
- nft_parse_err_free(err);
+ if (nftnl_set_parse(s, format, data, err) < 0) {
+ nftnl_parse_perror("Unable to parse file", err);
+ nftnl_parse_err_free(err);
return NULL;
}
- nft_parse_err_free(err);
+ nftnl_parse_err_free(err);
- nft_set_attr_set_u32(s, NFT_SET_ATTR_ID, 1);
+ nftnl_set_attr_set_u32(s, NFTNL_SET_ATTR_ID, 1);
return s;
}
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, set_seq;
- struct nft_set *s;
+ struct nftnl_set *s;
int ret, batching;
uint16_t family, format, outformat;
struct mnl_nlmsg_batch *batch;
@@ -90,11 +90,11 @@ int main(int argc, char *argv[])
}
if (strcmp(argv[1], "xml") == 0) {
- format = NFT_PARSE_XML;
- outformat = NFT_OUTPUT_XML;
+ format = NFTNL_PARSE_XML;
+ outformat = NFTNL_OUTPUT_XML;
} else if (strcmp(argv[1], "json") == 0) {
- format = NFT_PARSE_JSON;
- outformat = NFT_OUTPUT_JSON;
+ format = NFTNL_PARSE_JSON;
+ outformat = NFTNL_OUTPUT_JSON;
} else {
printf("Unknown format: xml, json\n");
exit(EXIT_FAILURE);
@@ -104,11 +104,11 @@ int main(int argc, char *argv[])
if (s == NULL)
exit(EXIT_FAILURE);
- nft_set_fprintf(stdout, s, outformat, 0);
+ nftnl_set_fprintf(stdout, s, outformat, 0);
fprintf(stdout, "\n");
seq = time(NULL);
- batching = nft_batch_is_supported();
+ batching = nftnl_batch_is_supported();
if (batching < 0) {
perror("cannot talk to nfnetlink");
exit(EXIT_FAILURE);
@@ -117,22 +117,22 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
if (batching) {
- nft_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
- family = nft_set_attr_get_u32(s, NFT_SET_ATTR_FAMILY);
+ family = nftnl_set_attr_get_u32(s, NFTNL_SET_ATTR_FAMILY);
set_seq = seq;
- nlh = nft_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_NEWSET, family,
NLM_F_CREATE|NLM_F_ACK, seq++);
- nft_set_nlmsg_build_payload(nlh, s);
- nft_set_free(s);
+ nftnl_set_nlmsg_build_payload(nlh, s);
+ nftnl_set_free(s);
mnl_nlmsg_batch_next(batch);
if (batching) {
- nft_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
diff --git a/examples/nft-table-add.c b/examples/nft-table-add.c
index 9340128..f8ae46f 100644
--- a/examples/nft-table-add.c
+++ b/examples/nft-table-add.c
@@ -20,9 +20,9 @@
#include <libmnl/libmnl.h>
#include <libnftnl/table.h>
-static struct nft_table *table_add_parse(int argc, char *argv[])
+static struct nftnl_table *table_add_parse(int argc, char *argv[])
{
- struct nft_table *t;
+ struct nftnl_table *t;
uint16_t family;
if (strcmp(argv[1], "ip") == 0)
@@ -38,14 +38,14 @@ static struct nft_table *table_add_parse(int argc, char *argv[])
return NULL;
}
- t = nft_table_alloc();
+ t = nftnl_table_alloc();
if (t == NULL) {
perror("OOM");
return NULL;
}
- nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FAMILY, family);
- nft_table_attr_set_str(t, NFT_TABLE_ATTR_NAME, argv[2]);
+ nftnl_table_attr_set_u32(t, NFTNL_TABLE_ATTR_FAMILY, family);
+ nftnl_table_attr_set_str(t, NFTNL_TABLE_ATTR_NAME, argv[2]);
return t;
}
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, table_seq, family;
- struct nft_table *t;
+ struct nftnl_table *t;
struct mnl_nlmsg_batch *batch;
int ret, batching;
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
if (t == NULL)
exit(EXIT_FAILURE);
- batching = nft_batch_is_supported();
+ batching = nftnl_batch_is_supported();
if (batching < 0) {
perror("cannot talk to nfnetlink");
exit(EXIT_FAILURE);
@@ -79,21 +79,21 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
if (batching) {
- nft_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
table_seq = seq;
- family = nft_table_attr_get_u32(t, NFT_TABLE_ATTR_FAMILY);
- nlh = nft_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ family = nftnl_table_attr_get_u32(t, NFTNL_TABLE_ATTR_FAMILY);
+ nlh = nftnl_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_NEWTABLE, family,
NLM_F_ACK, seq++);
- nft_table_nlmsg_build_payload(nlh, t);
- nft_table_free(t);
+ nftnl_table_nlmsg_build_payload(nlh, t);
+ nftnl_table_free(t);
mnl_nlmsg_batch_next(batch);
if (batching) {
- nft_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
diff --git a/examples/nft-table-del.c b/examples/nft-table-del.c
index 334d20b..a321bca 100644
--- a/examples/nft-table-del.c
+++ b/examples/nft-table-del.c
@@ -20,9 +20,9 @@
#include <libmnl/libmnl.h>
#include <libnftnl/table.h>
-static struct nft_table *table_del_parse(int argc, char *argv[])
+static struct nftnl_table *table_del_parse(int argc, char *argv[])
{
- struct nft_table *t;
+ struct nftnl_table *t;
uint16_t family;
if (strcmp(argv[1], "ip") == 0)
@@ -38,14 +38,14 @@ static struct nft_table *table_del_parse(int argc, char *argv[])
return NULL;
}
- t = nft_table_alloc();
+ t = nftnl_table_alloc();
if (t == NULL) {
perror("OOM");
return NULL;
}
- nft_table_attr_set_str(t, NFT_TABLE_ATTR_NAME, argv[2]);
- nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FAMILY, family);
+ nftnl_table_attr_set_str(t, NFTNL_TABLE_ATTR_NAME, argv[2]);
+ nftnl_table_attr_set_u32(t, NFTNL_TABLE_ATTR_FAMILY, family);
return t;
}
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, table_seq, family;
- struct nft_table *t;
+ struct nftnl_table *t;
struct mnl_nlmsg_batch *batch;
int ret, batching;
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
if (t == NULL)
exit(EXIT_FAILURE);
- batching = nft_batch_is_supported();
+ batching = nftnl_batch_is_supported();
if (batching < 0) {
perror("cannot talk to nfnetlink");
exit(EXIT_FAILURE);
@@ -79,21 +79,21 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
if (batching) {
- nft_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
table_seq = seq;
- family = nft_table_attr_get_u32(t, NFT_TABLE_ATTR_FAMILY);
- nlh = nft_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ family = nftnl_table_attr_get_u32(t, NFTNL_TABLE_ATTR_FAMILY);
+ nlh = nftnl_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_DELTABLE, family,
NLM_F_ACK, seq++);
- nft_table_nlmsg_build_payload(nlh, t);
+ nftnl_table_nlmsg_build_payload(nlh, t);
mnl_nlmsg_batch_next(batch);
- nft_table_free(t);
+ nftnl_table_free(t);
if (batching) {
- nft_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
diff --git a/examples/nft-table-get.c b/examples/nft-table-get.c
index 6ac56d6..8e37556 100644
--- a/examples/nft-table-get.c
+++ b/examples/nft-table-get.c
@@ -22,26 +22,26 @@
static int table_cb(const struct nlmsghdr *nlh, void *data)
{
- struct nft_table *t;
+ struct nftnl_table *t;
char buf[4096];
uint32_t *type = data;
- t = nft_table_alloc();
+ t = nftnl_table_alloc();
if (t == NULL) {
perror("OOM");
goto err;
}
- if (nft_table_nlmsg_parse(nlh, t) < 0) {
- perror("nft_table_nlmsg_parse");
+ if (nftnl_table_nlmsg_parse(nlh, t) < 0) {
+ perror("nftnl_table_nlmsg_parse");
goto err_free;
}
- nft_table_snprintf(buf, sizeof(buf), t, *type, 0);
+ nftnl_table_snprintf(buf, sizeof(buf), t, *type, 0);
printf("%s\n", buf);
err_free:
- nft_table_free(t);
+ nftnl_table_free(t);
err:
return MNL_CB_OK;
}
@@ -52,9 +52,9 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, family;
- struct nft_table *t = NULL;
+ struct nftnl_table *t = NULL;
int ret;
- uint32_t type = NFT_OUTPUT_DEFAULT;
+ uint32_t type = NFTNL_OUTPUT_DEFAULT;
if (argc < 2 || argc > 4) {
fprintf(stderr, "%s <family> [<table>] [<default|xml|json>]\n",
@@ -78,11 +78,11 @@ int main(int argc, char *argv[])
}
if (strcmp(argv[argc-1], "xml") == 0) {
- type = NFT_OUTPUT_XML;
+ type = NFTNL_OUTPUT_XML;
argv[argc-1] = NULL;
argc--;
}else if (strcmp(argv[argc-1], "json") == 0) {
- type = NFT_OUTPUT_JSON;
+ type = NFTNL_OUTPUT_JSON;
argv[argc-1] = NULL;
argc--;
} else if (strcmp(argv[argc - 1], "default") == 0) {
@@ -90,7 +90,7 @@ int main(int argc, char *argv[])
}
if (argc == 3) {
- t = nft_table_alloc();
+ t = nftnl_table_alloc();
if (t == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
@@ -99,14 +99,14 @@ int main(int argc, char *argv[])
seq = time(NULL);
if (t == NULL) {
- nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
+ nlh = nftnl_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
NLM_F_DUMP, seq);
} else {
- nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
+ nlh = nftnl_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
NLM_F_ACK, seq);
- nft_table_attr_set(t, NFT_TABLE_ATTR_NAME, argv[2]);
- nft_table_nlmsg_build_payload(nlh, t);
- nft_table_free(t);
+ nftnl_table_attr_set(t, NFTNL_TABLE_ATTR_NAME, argv[2]);
+ nftnl_table_nlmsg_build_payload(nlh, t);
+ nftnl_table_free(t);
}
nl = mnl_socket_open(NETLINK_NETFILTER);
diff --git a/examples/nft-table-parse-add.c b/examples/nft-table-parse-add.c
index c21b6ba..794db97 100644
--- a/examples/nft-table-parse-add.c
+++ b/examples/nft-table-parse-add.c
@@ -25,14 +25,14 @@
#include <libnftnl/table.h>
#include <libnftnl/common.h>
-static struct nft_table *table_parse_file(const char *file, uint16_t format)
+static struct nftnl_table *table_parse_file(const char *file, uint16_t format)
{
int fd;
- struct nft_table *t;
- struct nft_parse_err *err;
+ struct nftnl_table *t;
+ struct nftnl_parse_err *err;
char data[4096];
- t = nft_table_alloc();
+ t = nftnl_table_alloc();
if (t == NULL) {
perror("OOM");
return NULL;
@@ -51,19 +51,19 @@ static struct nft_table *table_parse_file(const char *file, uint16_t format)
}
close(fd);
- err = nft_parse_err_alloc();
+ err = nftnl_parse_err_alloc();
if (err == NULL) {
perror("error");
return NULL;
}
- if (nft_table_parse(t, format, data, err) < 0) {
- nft_parse_perror("Unable to parse file", err);
- nft_parse_err_free(err);
+ if (nftnl_table_parse(t, format, data, err) < 0) {
+ nftnl_parse_perror("Unable to parse file", err);
+ nftnl_parse_err_free(err);
return NULL;
}
- nft_parse_err_free(err);
+ nftnl_parse_err_free(err);
return t;
}
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, table_seq;
- struct nft_table *t = NULL;
+ struct nftnl_table *t = NULL;
int ret, batching;
uint16_t family, format, outformat;
struct mnl_nlmsg_batch *batch;
@@ -85,11 +85,11 @@ int main(int argc, char *argv[])
}
if (strcmp(argv[1], "xml") == 0) {
- format = NFT_PARSE_XML;
- outformat = NFT_OUTPUT_XML;
+ format = NFTNL_PARSE_XML;
+ outformat = NFTNL_OUTPUT_XML;
} else if (strcmp(argv[1], "json") == 0) {
- format = NFT_PARSE_JSON;
- outformat = NFT_OUTPUT_JSON;
+ format = NFTNL_PARSE_JSON;
+ outformat = NFTNL_OUTPUT_JSON;
} else {
printf("Unknown format: xml, json\n");
exit(EXIT_FAILURE);
@@ -99,11 +99,11 @@ int main(int argc, char *argv[])
if (t == NULL)
exit(EXIT_FAILURE);
- nft_table_fprintf(stdout, t, outformat, 0);
+ nftnl_table_fprintf(stdout, t, outformat, 0);
fprintf(stdout, "\n");
seq = time(NULL);
- batching = nft_batch_is_supported();
+ batching = nftnl_batch_is_supported();
if (batching < 0) {
perror("cannot talk to nfnetlink");
exit(EXIT_FAILURE);
@@ -112,22 +112,22 @@ int main(int argc, char *argv[])
batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
if (batching) {
- nft_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
- family = nft_table_attr_get_u32(t, NFT_TABLE_ATTR_FAMILY);
+ family = nftnl_table_attr_get_u32(t, NFTNL_TABLE_ATTR_FAMILY);
table_seq = seq;
- nlh = nft_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ nlh = nftnl_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
NFT_MSG_NEWTABLE, family,
NLM_F_CREATE|NLM_F_ACK, seq++);
- nft_table_nlmsg_build_payload(nlh, t);
- nft_table_free(t);
+ nftnl_table_nlmsg_build_payload(nlh, t);
+ nftnl_table_free(t);
mnl_nlmsg_batch_next(batch);
if (batching) {
- nft_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
mnl_nlmsg_batch_next(batch);
}
diff --git a/examples/nft-table-upd.c b/examples/nft-table-upd.c
index 9f0e809..7deb8fd 100644
--- a/examples/nft-table-upd.c
+++ b/examples/nft-table-upd.c
@@ -26,7 +26,7 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq, family, flags;
- struct nft_table *t = NULL;
+ struct nftnl_table *t = NULL;
int ret;
if (argc != 4) {
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- t = nft_table_alloc();
+ t = nftnl_table_alloc();
if (t == NULL) {
perror("OOM");
exit(EXIT_FAILURE);
@@ -63,13 +63,13 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- nft_table_attr_set(t, NFT_TABLE_ATTR_NAME, argv[2]);
- nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FLAGS, flags);
+ nftnl_table_attr_set(t, NFTNL_TABLE_ATTR_NAME, argv[2]);
+ nftnl_table_attr_set_u32(t, NFTNL_TABLE_ATTR_FLAGS, flags);
- nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_NEWTABLE, family,
+ nlh = nftnl_table_nlmsg_build_hdr(buf, NFT_MSG_NEWTABLE, family,
NLM_F_ACK, seq);
- nft_table_nlmsg_build_payload(nlh, t);
- nft_table_free(t);
+ nftnl_table_nlmsg_build_payload(nlh, t);
+ nftnl_table_free(t);
nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
diff --git a/include/buffer.h b/include/buffer.h
index 38b6136..a5bd039 100644
--- a/include/buffer.h
+++ b/include/buffer.h
@@ -1,10 +1,10 @@
-#ifndef _NFT_BUFFER_H_
-#define _NFT_BUFFER_H_
+#ifndef _NFTNL_BUFFER_H_
+#define _NFTNL_BUFFER_H_
#include <stdint.h>
#include <stdbool.h>
-struct nft_buf {
+struct nftnl_buf {
char *buf;
size_t size;
size_t len;
@@ -12,28 +12,28 @@ struct nft_buf {
bool fail;
};
-#define NFT_BUF_INIT(__b, __buf, __len) \
- struct nft_buf __b = { \
+#define NFTNL_BUF_INIT(__b, __buf, __len) \
+ struct nftnl_buf __b = { \
.buf = __buf, \
.len = __len, \
};
-int nft_buf_update(struct nft_buf *b, int ret);
-int nft_buf_done(struct nft_buf *b);
+int nftnl_buf_update(struct nftnl_buf *b, int ret);
+int nftnl_buf_done(struct nftnl_buf *b);
-union nft_data_reg;
+union nftnl_data_reg;
-int nft_buf_open(struct nft_buf *b, int type, const char *tag);
-int nft_buf_close(struct nft_buf *b, int type, const char *tag);
+int nftnl_buf_open(struct nftnl_buf *b, int type, const char *tag);
+int nftnl_buf_close(struct nftnl_buf *b, int type, const char *tag);
-int nft_buf_open_array(struct nft_buf *b, int type, const char *tag);
-int nft_buf_close_array(struct nft_buf *b, int type, const char *tag);
+int nftnl_buf_open_array(struct nftnl_buf *b, int type, const char *tag);
+int nftnl_buf_close_array(struct nftnl_buf *b, int type, const char *tag);
-int nft_buf_u32(struct nft_buf *b, int type, uint32_t value, const char *tag);
-int nft_buf_s32(struct nft_buf *b, int type, uint32_t value, const char *tag);
-int nft_buf_u64(struct nft_buf *b, int type, uint64_t value, const char *tag);
-int nft_buf_str(struct nft_buf *b, int type, const char *str, const char *tag);
-int nft_buf_reg(struct nft_buf *b, int type, union nft_data_reg *reg,
+int nftnl_buf_u32(struct nftnl_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);
+int nftnl_buf_u64(struct nftnl_buf *b, int type, uint64_t value, const char *tag);
+int nftnl_buf_str(struct nftnl_buf *b, int type, const char *str, const char *tag);
+int nftnl_buf_reg(struct nftnl_buf *b, int type, union nftnl_data_reg *reg,
int reg_type, const char *tag);
#define BASE "base"
diff --git a/include/common.h b/include/common.h
index 4b9e2c5..425bbf5 100644
--- a/include/common.h
+++ b/include/common.h
@@ -4,29 +4,29 @@
#define BASE_DEC 10
#define BASE_HEX 16
-#define NFT_SNPRINTF_BUFSIZ 4096
+#define NFTNL_SNPRINTF_BUFSIZ 4096
-struct nft_parse_err {
+struct nftnl_parse_err {
int line;
int column;
int error;
const char *node_name;
};
-enum nft_parse_input {
- NFT_PARSE_BUFFER,
- NFT_PARSE_FILE,
+enum nftnl_parse_input {
+ NFTNL_PARSE_BUFFER,
+ NFTNL_PARSE_FILE,
};
#include <stdio.h>
-int nft_cmd_header_snprintf(char *buf, size_t bufsize, uint32_t cmd,
+int nftnl_cmd_header_snprintf(char *buf, size_t bufsize, uint32_t cmd,
uint32_t format, uint32_t flags);
-int nft_cmd_header_fprintf(FILE *fp, uint32_t cmd, uint32_t format,
+int nftnl_cmd_header_fprintf(FILE *fp, uint32_t cmd, uint32_t format,
uint32_t flags);
-int nft_cmd_footer_snprintf(char *buf, size_t bufsize, uint32_t cmd,
+int nftnl_cmd_footer_snprintf(char *buf, size_t bufsize, uint32_t cmd,
uint32_t format, uint32_t flags);
-int nft_cmd_footer_fprintf(FILE *fp, uint32_t cmd, uint32_t format,
+int nftnl_cmd_footer_fprintf(FILE *fp, uint32_t cmd, uint32_t format,
uint32_t flags);
#endif
diff --git a/include/data_reg.h b/include/data_reg.h
index e0fdd10..0f2ae9a 100644
--- a/include/data_reg.h
+++ b/include/data_reg.h
@@ -12,7 +12,7 @@ enum {
DATA_CHAIN,
};
-union nft_data_reg {
+union nftnl_data_reg {
struct {
uint32_t val[NFT_DATA_VALUE_MAXLEN / sizeof(uint32_t)];
uint32_t len;
@@ -23,11 +23,11 @@ union nft_data_reg {
};
};
-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);
struct nlattr;
-int nft_parse_data(union nft_data_reg *data, struct nlattr *attr, int *type);
-void nft_free_verdict(union nft_data_reg *data);
+int nftnl_parse_data(union nftnl_data_reg *data, struct nlattr *attr, int *type);
+void nftnl_free_verdict(union nftnl_data_reg *data);
#endif
diff --git a/include/expr.h b/include/expr.h
index a4333c6..26b4a95 100644
--- a/include/expr.h
+++ b/include/expr.h
@@ -3,7 +3,7 @@
struct expr_ops;
-struct nft_rule_expr {
+struct nftnl_rule_expr {
struct list_head head;
uint32_t flags;
struct expr_ops *ops;
@@ -12,8 +12,8 @@ struct nft_rule_expr {
struct nlmsghdr;
-void nft_rule_expr_build_payload(struct nlmsghdr *nlh, struct nft_rule_expr *expr);
-struct nft_rule_expr *nft_rule_expr_parse(struct nlattr *attr);
+void nftnl_rule_expr_build_payload(struct nlmsghdr *nlh, struct nftnl_rule_expr *expr);
+struct nftnl_rule_expr *nftnl_rule_expr_parse(struct nlattr *attr);
#endif
diff --git a/include/expr_ops.h b/include/expr_ops.h
index 08cf57f..caf9218 100644
--- a/include/expr_ops.h
+++ b/include/expr_ops.h
@@ -6,26 +6,26 @@
struct nlattr;
struct nlmsghdr;
-struct nft_rule_expr;
+struct nftnl_rule_expr;
struct expr_ops {
const char *name;
uint32_t alloc_len;
int max_attr;
- void (*free)(struct nft_rule_expr *e);
- int (*set)(struct nft_rule_expr *e, uint16_t type, const void *data, uint32_t data_len);
- const void *(*get)(const struct nft_rule_expr *e, uint16_t type, uint32_t *data_len);
- int (*parse)(struct nft_rule_expr *e, struct nlattr *attr);
- void (*build)(struct nlmsghdr *nlh, struct nft_rule_expr *e);
- int (*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, struct nft_rule_expr *e);
- int (*xml_parse)(struct nft_rule_expr *e, mxml_node_t *tree,
- struct nft_parse_err *err);
- int (*json_parse)(struct nft_rule_expr *e, json_t *data,
- struct nft_parse_err *err);
+ void (*free)(struct nftnl_rule_expr *e);
+ int (*set)(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len);
+ const void *(*get)(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len);
+ int (*parse)(struct nftnl_rule_expr *e, struct nlattr *attr);
+ void (*build)(struct nlmsghdr *nlh, struct nftnl_rule_expr *e);
+ int (*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, struct nftnl_rule_expr *e);
+ int (*xml_parse)(struct nftnl_rule_expr *e, mxml_node_t *tree,
+ struct nftnl_parse_err *err);
+ int (*json_parse)(struct nftnl_rule_expr *e, json_t *data,
+ struct nftnl_parse_err *err);
};
-struct expr_ops *nft_expr_ops_lookup(const char *name);
+struct expr_ops *nftnl_expr_ops_lookup(const char *name);
-#define nft_expr_data(ops) (void *)ops->data
+#define nftnl_expr_data(ops) (void *)ops->data
#endif
diff --git a/include/json.h b/include/json.h
index 821c15f..a15a65b 100644
--- a/include/json.h
+++ b/include/json.h
@@ -6,51 +6,51 @@
#include <stdbool.h>
#include "common.h"
-struct nft_table;
-struct nft_chain;
-struct nft_rule;
-struct nft_set;
-struct nft_set_elem;
-struct nft_set_list;
-union nft_data_reg;
+struct nftnl_table;
+struct nftnl_chain;
+struct nftnl_rule;
+struct nftnl_set;
+struct nftnl_set_elem;
+struct nftnl_set_list;
+union nftnl_data_reg;
-int nft_jansson_parse_val(json_t *root, const char *node_name, int type,
- void *out, struct nft_parse_err *err);
-const char *nft_jansson_parse_str(json_t *root, const char *node_name,
- struct nft_parse_err *err);
-bool nft_jansson_node_exist(json_t *root, const char *node_name);
-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 *nft_jansson_get_node(json_t *root, const char *node_name,
- struct nft_parse_err *err);
-void nft_jansson_free_root(json_t *root);
-int nft_jansson_parse_family(json_t *root, void *out, struct nft_parse_err *err);
-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 nft_jansson_parse_reg(json_t *root, const char *node_name, int type,
- void *out, struct nft_parse_err *err);
-struct nft_rule_expr *nft_jansson_expr_parse(json_t *root,
- struct nft_parse_err *err,
- struct nft_set_list *set_list);
-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 nft_jansson_set_elem_parse(struct nft_set_elem *e, json_t *root,
- struct nft_parse_err *err);
-int nft_jansson_parse_table(struct nft_table *t, json_t *tree,
- struct nft_parse_err *err);
-int nft_jansson_parse_chain(struct nft_chain *c, json_t *tree,
- struct nft_parse_err *err);
-int nft_jansson_parse_rule(struct nft_rule *r, json_t *tree,
- struct nft_parse_err *err,
- struct nft_set_list *set_list);
-int nft_jansson_parse_set(struct nft_set *s, json_t *tree,
- struct nft_parse_err *err);
-int nft_jansson_parse_elem(struct nft_set *s, json_t *tree,
- 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);
+const char *nftnl_jansson_parse_str(json_t *root, const char *node_name,
+ struct nftnl_parse_err *err);
+bool nftnl_jansson_node_exist(json_t *root, const char *node_name);
+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 *nftnl_jansson_get_node(json_t *root, const char *node_name,
+ struct nftnl_parse_err *err);
+void nftnl_jansson_free_root(json_t *root);
+int nftnl_jansson_parse_family(json_t *root, void *out, struct nftnl_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);
+int nftnl_jansson_parse_reg(json_t *root, const char *node_name, int type,
+ void *out, struct nftnl_parse_err *err);
+struct nftnl_rule_expr *nftnl_jansson_expr_parse(json_t *root,
+ struct nftnl_parse_err *err,
+ struct nftnl_set_list *set_list);
+int nftnl_jansson_data_reg_parse(json_t *root, const char *node_name,
+ union nftnl_data_reg *data_reg,
+ struct nftnl_parse_err *err);
+int nftnl_jansson_set_elem_parse(struct nftnl_set_elem *e, json_t *root,
+ struct nftnl_parse_err *err);
+int nftnl_jansson_parse_table(struct nftnl_table *t, json_t *tree,
+ struct nftnl_parse_err *err);
+int nftnl_jansson_parse_chain(struct nftnl_chain *c, json_t *tree,
+ struct nftnl_parse_err *err);
+int nftnl_jansson_parse_rule(struct nftnl_rule *r, json_t *tree,
+ struct nftnl_parse_err *err,
+ struct nftnl_set_list *set_list);
+int nftnl_jansson_parse_set(struct nftnl_set *s, json_t *tree,
+ struct nftnl_parse_err *err);
+int nftnl_jansson_parse_elem(struct nftnl_set *s, json_t *tree,
+ struct nftnl_parse_err *err);
-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);
#else
#define json_t void
#endif
diff --git a/include/libnftnl/batch.h b/include/libnftnl/batch.h
index 40416e6..ea1ea66 100644
--- a/include/libnftnl/batch.h
+++ b/include/libnftnl/batch.h
@@ -3,16 +3,16 @@
#include <stdint.h>
-struct nft_batch;
+struct nftnl_batch;
-struct nft_batch *nft_batch_alloc(uint32_t pg_size, uint32_t pg_overrun_size);
-int nft_batch_update(struct nft_batch *batch);
-void nft_batch_free(struct nft_batch *batch);
+struct nftnl_batch *nftnl_batch_alloc(uint32_t pg_size, uint32_t pg_overrun_size);
+int nftnl_batch_update(struct nftnl_batch *batch);
+void nftnl_batch_free(struct nftnl_batch *batch);
-void *nft_batch_buffer(struct nft_batch *batch);
-uint32_t nft_batch_buffer_len(struct nft_batch *batch);
+void *nftnl_batch_buffer(struct nftnl_batch *batch);
+uint32_t nftnl_batch_buffer_len(struct nftnl_batch *batch);
-int nft_batch_iovec_len(struct nft_batch *batch);
-void nft_batch_iovec(struct nft_batch *batch, struct iovec *iov, uint32_t iovlen);
+int nftnl_batch_iovec_len(struct nftnl_batch *batch);
+void nftnl_batch_iovec(struct nftnl_batch *batch, struct iovec *iov, uint32_t iovlen);
#endif
diff --git a/include/libnftnl/chain.h b/include/libnftnl/chain.h
index 3968e6b..1f426f7 100644
--- a/include/libnftnl/chain.h
+++ b/include/libnftnl/chain.h
@@ -12,78 +12,78 @@
extern "C" {
#endif
-struct nft_chain;
+struct nftnl_chain;
-struct nft_chain *nft_chain_alloc(void);
-void nft_chain_free(struct nft_chain *);
+struct nftnl_chain *nftnl_chain_alloc(void);
+void nftnl_chain_free(struct nftnl_chain *);
enum {
- NFT_CHAIN_ATTR_NAME = 0,
- NFT_CHAIN_ATTR_FAMILY,
- NFT_CHAIN_ATTR_TABLE,
- NFT_CHAIN_ATTR_HOOKNUM,
- NFT_CHAIN_ATTR_PRIO = 4,
- NFT_CHAIN_ATTR_POLICY,
- NFT_CHAIN_ATTR_USE,
- NFT_CHAIN_ATTR_BYTES,
- NFT_CHAIN_ATTR_PACKETS = 8,
- NFT_CHAIN_ATTR_HANDLE,
- NFT_CHAIN_ATTR_TYPE,
- NFT_CHAIN_ATTR_DEV,
- __NFT_CHAIN_ATTR_MAX
+ NFTNL_CHAIN_ATTR_NAME = 0,
+ NFTNL_CHAIN_ATTR_FAMILY,
+ NFTNL_CHAIN_ATTR_TABLE,
+ NFTNL_CHAIN_ATTR_HOOKNUM,
+ NFTNL_CHAIN_ATTR_PRIO = 4,
+ NFTNL_CHAIN_ATTR_POLICY,
+ NFTNL_CHAIN_ATTR_USE,
+ NFTNL_CHAIN_ATTR_BYTES,
+ NFTNL_CHAIN_ATTR_PACKETS = 8,
+ NFTNL_CHAIN_ATTR_HANDLE,
+ NFTNL_CHAIN_ATTR_TYPE,
+ NFTNL_CHAIN_ATTR_DEV,
+ __NFTNL_CHAIN_ATTR_MAX
};
-#define NFT_CHAIN_ATTR_MAX (__NFT_CHAIN_ATTR_MAX - 1)
+#define NFTNL_CHAIN_ATTR_MAX (__NFTNL_CHAIN_ATTR_MAX - 1)
-bool nft_chain_attr_is_set(const struct nft_chain *c, uint16_t attr);
-void nft_chain_attr_unset(struct nft_chain *c, uint16_t attr);
-void nft_chain_attr_set(struct nft_chain *t, uint16_t attr, const void *data);
-void nft_chain_attr_set_data(struct nft_chain *t, uint16_t attr,
+bool nftnl_chain_attr_is_set(const struct nftnl_chain *c, uint16_t attr);
+void nftnl_chain_attr_unset(struct nftnl_chain *c, uint16_t attr);
+void nftnl_chain_attr_set(struct nftnl_chain *t, uint16_t attr, const void *data);
+void nftnl_chain_attr_set_data(struct nftnl_chain *t, uint16_t attr,
const void *data, uint32_t data_len);
-void nft_chain_attr_set_u8(struct nft_chain *t, uint16_t attr, uint8_t data);
-void nft_chain_attr_set_u32(struct nft_chain *t, uint16_t attr, uint32_t data);
-void nft_chain_attr_set_s32(struct nft_chain *t, uint16_t attr, int32_t data);
-void nft_chain_attr_set_u64(struct nft_chain *t, uint16_t attr, uint64_t data);
-void nft_chain_attr_set_str(struct nft_chain *t, uint16_t attr, const char *str);
-
-const void *nft_chain_attr_get(struct nft_chain *c, uint16_t attr);
-const void *nft_chain_attr_get_data(struct nft_chain *c, uint16_t attr,
+void nftnl_chain_attr_set_u8(struct nftnl_chain *t, uint16_t attr, uint8_t data);
+void nftnl_chain_attr_set_u32(struct nftnl_chain *t, uint16_t attr, uint32_t data);
+void nftnl_chain_attr_set_s32(struct nftnl_chain *t, uint16_t attr, int32_t data);
+void nftnl_chain_attr_set_u64(struct nftnl_chain *t, uint16_t attr, uint64_t data);
+void nftnl_chain_attr_set_str(struct nftnl_chain *t, uint16_t attr, const char *str);
+
+const void *nftnl_chain_attr_get(struct nftnl_chain *c, uint16_t attr);
+const void *nftnl_chain_attr_get_data(struct nftnl_chain *c, uint16_t attr,
uint32_t *data_len);
-const char *nft_chain_attr_get_str(struct nft_chain *c, uint16_t attr);
-uint8_t nft_chain_attr_get_u8(struct nft_chain *c, uint16_t attr);
-uint32_t nft_chain_attr_get_u32(struct nft_chain *c, uint16_t attr);
-int32_t nft_chain_attr_get_s32(struct nft_chain *c, uint16_t attr);
-uint64_t nft_chain_attr_get_u64(struct nft_chain *c, uint16_t attr);
+const char *nftnl_chain_attr_get_str(struct nftnl_chain *c, uint16_t attr);
+uint8_t nftnl_chain_attr_get_u8(struct nftnl_chain *c, uint16_t attr);
+uint32_t nftnl_chain_attr_get_u32(struct nftnl_chain *c, uint16_t attr);
+int32_t nftnl_chain_attr_get_s32(struct nftnl_chain *c, uint16_t attr);
+uint64_t nftnl_chain_attr_get_u64(struct nftnl_chain *c, uint16_t attr);
struct nlmsghdr;
-void nft_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_chain *t);
+void nftnl_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nftnl_chain *t);
-int nft_chain_parse(struct nft_chain *c, enum nft_parse_type type,
- const char *data, struct nft_parse_err *err);
-int nft_chain_parse_file(struct nft_chain *c, enum nft_parse_type type,
- FILE *fp, struct nft_parse_err *err);
-int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *t, uint32_t type, uint32_t flags);
-int nft_chain_fprintf(FILE *fp, struct nft_chain *c, uint32_t type, uint32_t flags);
+int nftnl_chain_parse(struct nftnl_chain *c, enum nftnl_parse_type type,
+ const char *data, struct nftnl_parse_err *err);
+int nftnl_chain_parse_file(struct nftnl_chain *c, enum nftnl_parse_type type,
+ FILE *fp, struct nftnl_parse_err *err);
+int nftnl_chain_snprintf(char *buf, size_t size, struct nftnl_chain *t, uint32_t type, uint32_t flags);
+int nftnl_chain_fprintf(FILE *fp, struct nftnl_chain *c, uint32_t type, uint32_t flags);
-#define nft_chain_nlmsg_build_hdr nft_nlmsg_build_hdr
-int nft_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_chain *t);
+#define nftnl_chain_nlmsg_build_hdr nftnl_nlmsg_build_hdr
+int nftnl_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_chain *t);
-struct nft_chain_list;
+struct nftnl_chain_list;
-struct nft_chain_list *nft_chain_list_alloc(void);
-void nft_chain_list_free(struct nft_chain_list *list);
-int nft_chain_list_is_empty(struct nft_chain_list *list);
-int nft_chain_list_foreach(struct nft_chain_list *chain_list, int (*cb)(struct nft_chain *t, void *data), void *data);
+struct nftnl_chain_list *nftnl_chain_list_alloc(void);
+void nftnl_chain_list_free(struct nftnl_chain_list *list);
+int nftnl_chain_list_is_empty(struct nftnl_chain_list *list);
+int nftnl_chain_list_foreach(struct nftnl_chain_list *chain_list, int (*cb)(struct nftnl_chain *t, void *data), void *data);
-void nft_chain_list_add(struct nft_chain *r, struct nft_chain_list *list);
-void nft_chain_list_add_tail(struct nft_chain *r, struct nft_chain_list *list);
-void nft_chain_list_del(struct nft_chain *c);
+void nftnl_chain_list_add(struct nftnl_chain *r, struct nftnl_chain_list *list);
+void nftnl_chain_list_add_tail(struct nftnl_chain *r, struct nftnl_chain_list *list);
+void nftnl_chain_list_del(struct nftnl_chain *c);
-struct nft_chain_list_iter;
+struct nftnl_chain_list_iter;
-struct nft_chain_list_iter *nft_chain_list_iter_create(struct nft_chain_list *l);
-struct nft_chain *nft_chain_list_iter_next(struct nft_chain_list_iter *iter);
-void nft_chain_list_iter_destroy(struct nft_chain_list_iter *iter);
+struct nftnl_chain_list_iter *nftnl_chain_list_iter_create(struct nftnl_chain_list *l);
+struct nftnl_chain *nftnl_chain_list_iter_next(struct nftnl_chain_list_iter *iter);
+void nftnl_chain_list_iter_destroy(struct nftnl_chain_list_iter *iter);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/include/libnftnl/common.h b/include/libnftnl/common.h
index 14db823..b9c6ff3 100644
--- a/include/libnftnl/common.h
+++ b/include/libnftnl/common.h
@@ -4,52 +4,52 @@
#include <stdint.h>
enum {
- NFT_PARSE_EBADINPUT = 0,
- NFT_PARSE_EMISSINGNODE,
- NFT_PARSE_EBADTYPE,
- NFT_PARSE_EOPNOTSUPP,
+ NFTNL_PARSE_EBADINPUT = 0,
+ NFTNL_PARSE_EMISSINGNODE,
+ NFTNL_PARSE_EBADTYPE,
+ NFTNL_PARSE_EOPNOTSUPP,
};
-enum nft_output_type {
- NFT_OUTPUT_DEFAULT = 0,
- NFT_OUTPUT_XML,
- NFT_OUTPUT_JSON,
+enum nftnl_output_type {
+ NFTNL_OUTPUT_DEFAULT = 0,
+ NFTNL_OUTPUT_XML,
+ NFTNL_OUTPUT_JSON,
};
-enum nft_output_flags {
- NFT_OF_EVENT_NEW = (1 << 0),
- NFT_OF_EVENT_DEL = (1 << 1),
- NFT_OF_EVENT_ANY = (NFT_OF_EVENT_NEW | NFT_OF_EVENT_DEL),
+enum nftnl_output_flags {
+ NFTNL_OF_EVENT_NEW = (1 << 0),
+ NFTNL_OF_EVENT_DEL = (1 << 1),
+ NFTNL_OF_EVENT_ANY = (NFTNL_OF_EVENT_NEW | NFTNL_OF_EVENT_DEL),
};
-enum nft_cmd_type {
- NFT_CMD_UNSPEC = 0,
- NFT_CMD_ADD,
- NFT_CMD_INSERT,
- NFT_CMD_DELETE,
- NFT_CMD_REPLACE,
- NFT_CMD_FLUSH,
- NFT_CMD_MAX,
+enum nftnl_cmd_type {
+ NFTNL_CMD_UNSPEC = 0,
+ NFTNL_CMD_ADD,
+ NFTNL_CMD_INSERT,
+ NFTNL_CMD_DELETE,
+ NFTNL_CMD_REPLACE,
+ NFTNL_CMD_FLUSH,
+ NFTNL_CMD_MAX,
};
-enum nft_parse_type {
- NFT_PARSE_NONE = 0,
- NFT_PARSE_XML,
- NFT_PARSE_JSON,
- NFT_PARSE_MAX,
+enum nftnl_parse_type {
+ NFTNL_PARSE_NONE = 0,
+ NFTNL_PARSE_XML,
+ NFTNL_PARSE_JSON,
+ NFTNL_PARSE_MAX,
};
-struct nft_parse_err;
+struct nftnl_parse_err;
-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 nft_parse_err *nft_parse_err_alloc(void);
-void nft_parse_err_free(struct nft_parse_err *);
-int nft_parse_perror(const char *str, struct nft_parse_err *err);
+struct nftnl_parse_err *nftnl_parse_err_alloc(void);
+void nftnl_parse_err_free(struct nftnl_parse_err *);
+int nftnl_parse_perror(const char *str, struct nftnl_parse_err *err);
-int nft_batch_is_supported(void);
-void nft_batch_begin(char *buf, uint32_t seq);
-void nft_batch_end(char *buf, uint32_t seq);
+int nftnl_batch_is_supported(void);
+void nftnl_batch_begin(char *buf, uint32_t seq);
+void nftnl_batch_end(char *buf, uint32_t seq);
#endif
diff --git a/include/libnftnl/expr.h b/include/libnftnl/expr.h
index 59ae2d7..1ca1d8b 100644
--- a/include/libnftnl/expr.h
+++ b/include/libnftnl/expr.h
@@ -9,168 +9,168 @@
extern "C" {
#endif
-struct nft_rule_expr;
+struct nftnl_rule_expr;
enum {
- NFT_RULE_EXPR_ATTR_NAME = 0,
- NFT_RULE_EXPR_ATTR_BASE,
+ NFTNL_RULE_EXPR_ATTR_NAME = 0,
+ NFTNL_RULE_EXPR_ATTR_BASE,
};
-struct nft_rule_expr *nft_rule_expr_alloc(const char *name);
-void nft_rule_expr_free(struct nft_rule_expr *expr);
+struct nftnl_rule_expr *nftnl_rule_expr_alloc(const char *name);
+void nftnl_rule_expr_free(struct nftnl_rule_expr *expr);
-bool nft_rule_expr_is_set(const struct nft_rule_expr *expr, uint16_t type);
-void nft_rule_expr_set(struct nft_rule_expr *expr, uint16_t type, const void *data, uint32_t data_len);
-#define nft_rule_expr_set_data nft_rule_expr_set
-void nft_rule_expr_set_u8(struct nft_rule_expr *expr, uint16_t type, uint8_t data);
-void nft_rule_expr_set_u16(struct nft_rule_expr *expr, uint16_t type, uint16_t data);
-void nft_rule_expr_set_u32(struct nft_rule_expr *expr, uint16_t type, uint32_t data);
-void nft_rule_expr_set_u64(struct nft_rule_expr *expr, uint16_t type, uint64_t data);
-void nft_rule_expr_set_str(struct nft_rule_expr *expr, uint16_t type, const char *str);
+bool nftnl_rule_expr_is_set(const struct nftnl_rule_expr *expr, uint16_t type);
+void nftnl_rule_expr_set(struct nftnl_rule_expr *expr, uint16_t type, const void *data, uint32_t data_len);
+#define nftnl_rule_expr_set_data nftnl_rule_expr_set
+void nftnl_rule_expr_set_u8(struct nftnl_rule_expr *expr, uint16_t type, uint8_t data);
+void nftnl_rule_expr_set_u16(struct nftnl_rule_expr *expr, uint16_t type, uint16_t data);
+void nftnl_rule_expr_set_u32(struct nftnl_rule_expr *expr, uint16_t type, uint32_t data);
+void nftnl_rule_expr_set_u64(struct nftnl_rule_expr *expr, uint16_t type, uint64_t data);
+void nftnl_rule_expr_set_str(struct nftnl_rule_expr *expr, uint16_t type, const char *str);
-const void *nft_rule_expr_get(const struct nft_rule_expr *expr, uint16_t type, uint32_t *data_len);
-#define nft_rule_expr_get_data nft_rule_expr_get
-uint8_t nft_rule_expr_get_u8(const struct nft_rule_expr *expr, uint16_t type);
-uint16_t nft_rule_expr_get_u16(const struct nft_rule_expr *expr, uint16_t type);
-uint32_t nft_rule_expr_get_u32(const struct nft_rule_expr *expr, uint16_t type);
-uint64_t nft_rule_expr_get_u64(const struct nft_rule_expr *expr, uint16_t type);
-const char *nft_rule_expr_get_str(const struct nft_rule_expr *expr, uint16_t type);
+const void *nftnl_rule_expr_get(const struct nftnl_rule_expr *expr, uint16_t type, uint32_t *data_len);
+#define nftnl_rule_expr_get_data nftnl_rule_expr_get
+uint8_t nftnl_rule_expr_get_u8(const struct nftnl_rule_expr *expr, uint16_t type);
+uint16_t nftnl_rule_expr_get_u16(const struct nftnl_rule_expr *expr, uint16_t type);
+uint32_t nftnl_rule_expr_get_u32(const struct nftnl_rule_expr *expr, uint16_t type);
+uint64_t nftnl_rule_expr_get_u64(const struct nftnl_rule_expr *expr, uint16_t type);
+const char *nftnl_rule_expr_get_str(const struct nftnl_rule_expr *expr, uint16_t type);
-int nft_rule_expr_snprintf(char *buf, size_t buflen, struct nft_rule_expr *expr, uint32_t type, uint32_t flags);
+int nftnl_rule_expr_snprintf(char *buf, size_t buflen, struct nftnl_rule_expr *expr, uint32_t type, uint32_t flags);
enum {
- NFT_EXPR_PAYLOAD_DREG = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_PAYLOAD_BASE,
- NFT_EXPR_PAYLOAD_OFFSET,
- NFT_EXPR_PAYLOAD_LEN,
+ NFTNL_EXPR_PAYLOAD_DREG = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_PAYLOAD_BASE,
+ NFTNL_EXPR_PAYLOAD_OFFSET,
+ NFTNL_EXPR_PAYLOAD_LEN,
};
enum {
- NFT_EXPR_META_KEY = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_META_DREG,
- NFT_EXPR_META_SREG,
+ NFTNL_EXPR_META_KEY = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_META_DREG,
+ NFTNL_EXPR_META_SREG,
};
enum {
- NFT_EXPR_CMP_SREG = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_CMP_OP,
- NFT_EXPR_CMP_DATA,
+ NFTNL_EXPR_CMP_SREG = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_CMP_OP,
+ NFTNL_EXPR_CMP_DATA,
};
enum {
- NFT_EXPR_IMM_DREG = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_IMM_DATA,
- NFT_EXPR_IMM_VERDICT,
- NFT_EXPR_IMM_CHAIN,
+ NFTNL_EXPR_IMM_DREG = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_IMM_DATA,
+ NFTNL_EXPR_IMM_VERDICT,
+ NFTNL_EXPR_IMM_CHAIN,
};
enum {
- NFT_EXPR_CTR_PACKETS = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_CTR_BYTES,
+ NFTNL_EXPR_CTR_PACKETS = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_CTR_BYTES,
};
enum {
- NFT_EXPR_BITWISE_SREG = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_BITWISE_DREG,
- NFT_EXPR_BITWISE_LEN,
- NFT_EXPR_BITWISE_MASK,
- NFT_EXPR_BITWISE_XOR,
+ NFTNL_EXPR_BITWISE_SREG = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_BITWISE_DREG,
+ NFTNL_EXPR_BITWISE_LEN,
+ NFTNL_EXPR_BITWISE_MASK,
+ NFTNL_EXPR_BITWISE_XOR,
};
enum {
- NFT_EXPR_TG_NAME = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_TG_REV,
- NFT_EXPR_TG_INFO,
+ NFTNL_EXPR_TG_NAME = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_TG_REV,
+ NFTNL_EXPR_TG_INFO,
};
enum {
- NFT_EXPR_MT_NAME = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_MT_REV,
- NFT_EXPR_MT_INFO,
+ NFTNL_EXPR_MT_NAME = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_MT_REV,
+ NFTNL_EXPR_MT_INFO,
};
enum {
- NFT_EXPR_NAT_TYPE = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_NAT_FAMILY,
- NFT_EXPR_NAT_REG_ADDR_MIN,
- NFT_EXPR_NAT_REG_ADDR_MAX,
- NFT_EXPR_NAT_REG_PROTO_MIN,
- NFT_EXPR_NAT_REG_PROTO_MAX,
- NFT_EXPR_NAT_FLAGS,
+ NFTNL_EXPR_NAT_TYPE = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_NAT_FAMILY,
+ NFTNL_EXPR_NAT_REG_ADDR_MIN,
+ NFTNL_EXPR_NAT_REG_ADDR_MAX,
+ NFTNL_EXPR_NAT_REG_PROTO_MIN,
+ NFTNL_EXPR_NAT_REG_PROTO_MAX,
+ NFTNL_EXPR_NAT_FLAGS,
};
enum {
- NFT_EXPR_LOOKUP_SREG = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_LOOKUP_DREG,
- NFT_EXPR_LOOKUP_SET,
- NFT_EXPR_LOOKUP_SET_ID,
+ NFTNL_EXPR_LOOKUP_SREG = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_LOOKUP_DREG,
+ NFTNL_EXPR_LOOKUP_SET,
+ NFTNL_EXPR_LOOKUP_SET_ID,
};
enum {
- NFT_EXPR_DYNSET_SREG_KEY = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_DYNSET_SREG_DATA,
- NFT_EXPR_DYNSET_OP,
- NFT_EXPR_DYNSET_TIMEOUT,
- NFT_EXPR_DYNSET_SET_NAME,
- NFT_EXPR_DYNSET_SET_ID,
- NFT_EXPR_DYNSET_EXPR,
+ NFTNL_EXPR_DYNSET_SREG_KEY = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_DYNSET_SREG_DATA,
+ NFTNL_EXPR_DYNSET_OP,
+ NFTNL_EXPR_DYNSET_TIMEOUT,
+ NFTNL_EXPR_DYNSET_SET_NAME,
+ NFTNL_EXPR_DYNSET_SET_ID,
+ NFTNL_EXPR_DYNSET_EXPR,
};
enum {
- NFT_EXPR_LOG_PREFIX = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_LOG_GROUP,
- NFT_EXPR_LOG_SNAPLEN,
- NFT_EXPR_LOG_QTHRESHOLD,
- NFT_EXPR_LOG_LEVEL,
- NFT_EXPR_LOG_FLAGS,
+ NFTNL_EXPR_LOG_PREFIX = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_LOG_GROUP,
+ NFTNL_EXPR_LOG_SNAPLEN,
+ NFTNL_EXPR_LOG_QTHRESHOLD,
+ NFTNL_EXPR_LOG_LEVEL,
+ NFTNL_EXPR_LOG_FLAGS,
};
enum {
- NFT_EXPR_EXTHDR_DREG = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_EXTHDR_TYPE,
- NFT_EXPR_EXTHDR_OFFSET,
- NFT_EXPR_EXTHDR_LEN,
+ NFTNL_EXPR_EXTHDR_DREG = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_EXTHDR_TYPE,
+ NFTNL_EXPR_EXTHDR_OFFSET,
+ NFTNL_EXPR_EXTHDR_LEN,
};
enum {
- NFT_EXPR_CT_DREG = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_CT_KEY,
- NFT_EXPR_CT_DIR,
- NFT_EXPR_CT_SREG,
+ NFTNL_EXPR_CT_DREG = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_CT_KEY,
+ NFTNL_EXPR_CT_DIR,
+ NFTNL_EXPR_CT_SREG,
};
enum {
- NFT_EXPR_BYTEORDER_DREG = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_BYTEORDER_SREG,
- NFT_EXPR_BYTEORDER_OP,
- NFT_EXPR_BYTEORDER_LEN,
- NFT_EXPR_BYTEORDER_SIZE,
+ NFTNL_EXPR_BYTEORDER_DREG = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_BYTEORDER_SREG,
+ NFTNL_EXPR_BYTEORDER_OP,
+ NFTNL_EXPR_BYTEORDER_LEN,
+ NFTNL_EXPR_BYTEORDER_SIZE,
};
enum {
- NFT_EXPR_LIMIT_RATE = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_LIMIT_UNIT,
+ NFTNL_EXPR_LIMIT_RATE = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_LIMIT_UNIT,
};
enum {
- NFT_EXPR_REJECT_TYPE = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_REJECT_CODE,
+ NFTNL_EXPR_REJECT_TYPE = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_REJECT_CODE,
};
enum {
- NFT_EXPR_QUEUE_NUM = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_QUEUE_TOTAL,
- NFT_EXPR_QUEUE_FLAGS,
+ NFTNL_EXPR_QUEUE_NUM = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_QUEUE_TOTAL,
+ NFTNL_EXPR_QUEUE_FLAGS,
};
enum {
- NFT_EXPR_MASQ_FLAGS = NFT_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_MASQ_FLAGS = NFTNL_RULE_EXPR_ATTR_BASE,
};
enum {
- NFT_EXPR_REDIR_REG_PROTO_MIN = NFT_RULE_EXPR_ATTR_BASE,
- NFT_EXPR_REDIR_REG_PROTO_MAX,
- NFT_EXPR_REDIR_FLAGS,
+ NFTNL_EXPR_REDIR_REG_PROTO_MIN = NFTNL_RULE_EXPR_ATTR_BASE,
+ NFTNL_EXPR_REDIR_REG_PROTO_MAX,
+ NFTNL_EXPR_REDIR_FLAGS,
};
#ifdef __cplusplus
diff --git a/include/libnftnl/gen.h b/include/libnftnl/gen.h
index 00753b0..eb72d56 100644
--- a/include/libnftnl/gen.h
+++ b/include/libnftnl/gen.h
@@ -12,37 +12,37 @@
extern "C" {
#endif
-struct nft_gen;
+struct nftnl_gen;
-struct nft_gen *nft_gen_alloc(void);
-void nft_gen_free(struct nft_gen *);
+struct nftnl_gen *nftnl_gen_alloc(void);
+void nftnl_gen_free(struct nftnl_gen *);
enum {
- NFT_GEN_ID = 0,
- __NFT_GEN_MAX
+ NFTNL_GEN_ID = 0,
+ __NFTNL_GEN_MAX
};
-#define NFT_GEN_MAX (__NFT_GEN_MAX - 1)
+#define NFTNL_GEN_MAX (__NFTNL_GEN_MAX - 1)
-bool nft_gen_attr_is_set(const struct nft_gen *gen, uint16_t attr);
-void nft_gen_attr_unset(struct nft_gen *gen, uint16_t attr);
-void nft_gen_attr_set(struct nft_gen *gen, uint16_t attr, const void *data);
-void nft_gen_attr_set_data(struct nft_gen *gen, uint16_t attr,
+bool nftnl_gen_attr_is_set(const struct nftnl_gen *gen, uint16_t attr);
+void nftnl_gen_attr_unset(struct nftnl_gen *gen, uint16_t attr);
+void nftnl_gen_attr_set(struct nftnl_gen *gen, uint16_t attr, const void *data);
+void nftnl_gen_attr_set_data(struct nftnl_gen *gen, uint16_t attr,
const void *data, uint32_t data_len);
-const void *nft_gen_attr_get(struct nft_gen *gen, uint16_t attr);
-const void *nft_gen_attr_get_data(struct nft_gen *gen, uint16_t attr,
+const void *nftnl_gen_attr_get(struct nftnl_gen *gen, uint16_t attr);
+const void *nftnl_gen_attr_get_data(struct nftnl_gen *gen, uint16_t attr,
uint32_t *data_len);
-void nft_gen_attr_set_u32(struct nft_gen *gen, uint16_t attr, uint32_t data);
-uint32_t nft_gen_attr_get_u32(struct nft_gen *gen, uint16_t attr);
+void nftnl_gen_attr_set_u32(struct nftnl_gen *gen, uint16_t attr, uint32_t data);
+uint32_t nftnl_gen_attr_get_u32(struct nftnl_gen *gen, uint16_t attr);
struct nlmsghdr;
-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);
-int nft_gen_snprintf(char *buf, size_t size, struct nft_gen *gen, uint32_t type, uint32_t flags);
-int nft_gen_fprintf(FILE *fp, struct nft_gen *gen, uint32_t type, uint32_t flags);
+int nftnl_gen_snprintf(char *buf, size_t size, struct nftnl_gen *gen, uint32_t type, uint32_t flags);
+int nftnl_gen_fprintf(FILE *fp, struct nftnl_gen *gen, uint32_t type, uint32_t flags);
-#define nft_gen_nlmsg_build_hdr nft_nlmsg_build_hdr
-int nft_gen_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_gen *gen);
+#define nftnl_gen_nlmsg_build_hdr nftnl_nlmsg_build_hdr
+int nftnl_gen_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_gen *gen);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/include/libnftnl/rule.h b/include/libnftnl/rule.h
index 62dba59..8aa47ea 100644
--- a/include/libnftnl/rule.h
+++ b/include/libnftnl/rule.h
@@ -12,84 +12,84 @@
extern "C" {
#endif
-struct nft_rule;
-struct nft_rule_expr;
+struct nftnl_rule;
+struct nftnl_rule_expr;
-struct nft_rule *nft_rule_alloc(void);
-void nft_rule_free(struct nft_rule *);
+struct nftnl_rule *nftnl_rule_alloc(void);
+void nftnl_rule_free(struct nftnl_rule *);
enum {
- NFT_RULE_ATTR_FAMILY = 0,
- NFT_RULE_ATTR_TABLE,
- NFT_RULE_ATTR_CHAIN,
- NFT_RULE_ATTR_HANDLE,
- NFT_RULE_ATTR_COMPAT_PROTO,
- NFT_RULE_ATTR_COMPAT_FLAGS,
- NFT_RULE_ATTR_POSITION,
- NFT_RULE_ATTR_USERDATA,
- __NFT_RULE_ATTR_MAX
+ NFTNL_RULE_ATTR_FAMILY = 0,
+ NFTNL_RULE_ATTR_TABLE,
+ NFTNL_RULE_ATTR_CHAIN,
+ NFTNL_RULE_ATTR_HANDLE,
+ NFTNL_RULE_ATTR_COMPAT_PROTO,
+ NFTNL_RULE_ATTR_COMPAT_FLAGS,
+ NFTNL_RULE_ATTR_POSITION,
+ NFTNL_RULE_ATTR_USERDATA,
+ __NFTNL_RULE_ATTR_MAX
};
-#define NFT_RULE_ATTR_MAX (__NFT_RULE_ATTR_MAX - 1)
+#define NFTNL_RULE_ATTR_MAX (__NFTNL_RULE_ATTR_MAX - 1)
-void nft_rule_attr_unset(struct nft_rule *r, uint16_t attr);
-bool nft_rule_attr_is_set(const struct nft_rule *r, uint16_t attr);
-void nft_rule_attr_set(struct nft_rule *r, uint16_t attr, const void *data);
-void nft_rule_attr_set_data(struct nft_rule *r, uint16_t attr,
+void nftnl_rule_attr_unset(struct nftnl_rule *r, uint16_t attr);
+bool nftnl_rule_attr_is_set(const struct nftnl_rule *r, uint16_t attr);
+void nftnl_rule_attr_set(struct nftnl_rule *r, uint16_t attr, const void *data);
+void nftnl_rule_attr_set_data(struct nftnl_rule *r, uint16_t attr,
const void *data, uint32_t data_len);
-void nft_rule_attr_set_u32(struct nft_rule *r, uint16_t attr, uint32_t val);
-void nft_rule_attr_set_u64(struct nft_rule *r, uint16_t attr, uint64_t val);
-void nft_rule_attr_set_str(struct nft_rule *r, uint16_t attr, const char *str);
+void nftnl_rule_attr_set_u32(struct nftnl_rule *r, uint16_t attr, uint32_t val);
+void nftnl_rule_attr_set_u64(struct nftnl_rule *r, uint16_t attr, uint64_t val);
+void nftnl_rule_attr_set_str(struct nftnl_rule *r, uint16_t attr, const char *str);
-const void *nft_rule_attr_get(const struct nft_rule *r, uint16_t attr);
-const void *nft_rule_attr_get_data(const struct nft_rule *r, uint16_t attr,
+const void *nftnl_rule_attr_get(const struct nftnl_rule *r, uint16_t attr);
+const void *nftnl_rule_attr_get_data(const struct nftnl_rule *r, uint16_t attr,
uint32_t *data_len);
-const char *nft_rule_attr_get_str(const struct nft_rule *r, uint16_t attr);
-uint8_t nft_rule_attr_get_u8(const struct nft_rule *r, uint16_t attr);
-uint32_t nft_rule_attr_get_u32(const struct nft_rule *r, uint16_t attr);
-uint64_t nft_rule_attr_get_u64(const struct nft_rule *r, uint16_t attr);
+const char *nftnl_rule_attr_get_str(const struct nftnl_rule *r, uint16_t attr);
+uint8_t nftnl_rule_attr_get_u8(const struct nftnl_rule *r, uint16_t attr);
+uint32_t nftnl_rule_attr_get_u32(const struct nftnl_rule *r, uint16_t attr);
+uint64_t nftnl_rule_attr_get_u64(const struct nftnl_rule *r, uint16_t attr);
-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);
struct nlmsghdr;
-void nft_rule_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_rule *t);
+void nftnl_rule_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_rule *t);
-int nft_rule_parse(struct nft_rule *r, enum nft_parse_type type,
- const char *data, struct nft_parse_err *err);
-int nft_rule_parse_file(struct nft_rule *r, enum nft_parse_type type,
- FILE *fp, struct nft_parse_err *err);
-int nft_rule_snprintf(char *buf, size_t size, struct nft_rule *t, uint32_t type, uint32_t flags);
-int nft_rule_fprintf(FILE *fp, struct nft_rule *r, uint32_t type, uint32_t flags);
+int nftnl_rule_parse(struct nftnl_rule *r, enum nftnl_parse_type type,
+ const char *data, struct nftnl_parse_err *err);
+int nftnl_rule_parse_file(struct nftnl_rule *r, enum nftnl_parse_type type,
+ FILE *fp, struct nftnl_parse_err *err);
+int nftnl_rule_snprintf(char *buf, size_t size, struct nftnl_rule *t, uint32_t type, uint32_t flags);
+int nftnl_rule_fprintf(FILE *fp, struct nftnl_rule *r, uint32_t type, uint32_t flags);
-#define nft_rule_nlmsg_build_hdr nft_nlmsg_build_hdr
-int nft_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_rule *t);
+#define nftnl_rule_nlmsg_build_hdr nftnl_nlmsg_build_hdr
+int nftnl_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_rule *t);
-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_iter;
+struct nftnl_rule_expr_iter;
-struct nft_rule_expr_iter *nft_rule_expr_iter_create(struct nft_rule *r);
-struct nft_rule_expr *nft_rule_expr_iter_next(struct nft_rule_expr_iter *iter);
-void nft_rule_expr_iter_destroy(struct nft_rule_expr_iter *iter);
+struct nftnl_rule_expr_iter *nftnl_rule_expr_iter_create(struct nftnl_rule *r);
+struct nftnl_rule_expr *nftnl_rule_expr_iter_next(struct nftnl_rule_expr_iter *iter);
+void nftnl_rule_expr_iter_destroy(struct nftnl_rule_expr_iter *iter);
-struct nft_rule_list;
+struct nftnl_rule_list;
-struct nft_rule_list *nft_rule_list_alloc(void);
-void nft_rule_list_free(struct nft_rule_list *list);
-int nft_rule_list_is_empty(struct nft_rule_list *list);
-void nft_rule_list_add(struct nft_rule *r, struct nft_rule_list *list);
-void nft_rule_list_add_tail(struct nft_rule *r, struct nft_rule_list *list);
-void nft_rule_list_del(struct nft_rule *r);
-int nft_rule_list_foreach(struct nft_rule_list *rule_list, int (*cb)(struct nft_rule *t, void *data), void *data);
+struct nftnl_rule_list *nftnl_rule_list_alloc(void);
+void nftnl_rule_list_free(struct nftnl_rule_list *list);
+int nftnl_rule_list_is_empty(struct nftnl_rule_list *list);
+void nftnl_rule_list_add(struct nftnl_rule *r, struct nftnl_rule_list *list);
+void nftnl_rule_list_add_tail(struct nftnl_rule *r, struct nftnl_rule_list *list);
+void nftnl_rule_list_del(struct nftnl_rule *r);
+int nftnl_rule_list_foreach(struct nftnl_rule_list *rule_list, int (*cb)(struct nftnl_rule *t, void *data), void *data);
-struct nft_rule_list_iter;
+struct nftnl_rule_list_iter;
-struct nft_rule_list_iter *nft_rule_list_iter_create(struct nft_rule_list *l);
-struct nft_rule *nft_rule_list_iter_cur(struct nft_rule_list_iter *iter);
-struct nft_rule *nft_rule_list_iter_next(struct nft_rule_list_iter *iter);
-void nft_rule_list_iter_destroy(struct nft_rule_list_iter *iter);
+struct nftnl_rule_list_iter *nftnl_rule_list_iter_create(struct nftnl_rule_list *l);
+struct nftnl_rule *nftnl_rule_list_iter_cur(struct nftnl_rule_list_iter *iter);
+struct nftnl_rule *nftnl_rule_list_iter_next(struct nftnl_rule_list_iter *iter);
+void nftnl_rule_list_iter_destroy(struct nftnl_rule_list_iter *iter);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/include/libnftnl/ruleset.h b/include/libnftnl/ruleset.h
index fe5e44f..12e2495 100644
--- a/include/libnftnl/ruleset.h
+++ b/include/libnftnl/ruleset.h
@@ -13,62 +13,62 @@
extern "C" {
#endif
-struct nft_ruleset;
+struct nftnl_ruleset;
-struct nft_ruleset *nft_ruleset_alloc(void);
-void nft_ruleset_free(struct nft_ruleset *r);
+struct nftnl_ruleset *nftnl_ruleset_alloc(void);
+void nftnl_ruleset_free(struct nftnl_ruleset *r);
enum {
- NFT_RULESET_ATTR_TABLELIST = 0,
- NFT_RULESET_ATTR_CHAINLIST,
- NFT_RULESET_ATTR_SETLIST,
- NFT_RULESET_ATTR_RULELIST,
+ NFTNL_RULESET_ATTR_TABLELIST = 0,
+ NFTNL_RULESET_ATTR_CHAINLIST,
+ NFTNL_RULESET_ATTR_SETLIST,
+ NFTNL_RULESET_ATTR_RULELIST,
};
-enum nft_ruleset_type {
- NFT_RULESET_UNSPEC = 0,
- NFT_RULESET_RULESET,
- NFT_RULESET_TABLE,
- NFT_RULESET_CHAIN,
- NFT_RULESET_RULE,
- NFT_RULESET_SET,
- NFT_RULESET_SET_ELEMS,
+enum nftnl_ruleset_type {
+ NFTNL_RULESET_UNSPEC = 0,
+ NFTNL_RULESET_RULESET,
+ NFTNL_RULESET_TABLE,
+ NFTNL_RULESET_CHAIN,
+ NFTNL_RULESET_RULE,
+ NFTNL_RULESET_SET,
+ NFTNL_RULESET_SET_ELEMS,
};
-bool nft_ruleset_attr_is_set(const struct nft_ruleset *r, uint16_t attr);
-void nft_ruleset_attr_unset(struct nft_ruleset *r, uint16_t attr);
-void nft_ruleset_attr_set(struct nft_ruleset *r, uint16_t attr, void *data);
-void *nft_ruleset_attr_get(const struct nft_ruleset *r, uint16_t attr);
+bool nftnl_ruleset_attr_is_set(const struct nftnl_ruleset *r, uint16_t attr);
+void nftnl_ruleset_attr_unset(struct nftnl_ruleset *r, uint16_t attr);
+void nftnl_ruleset_attr_set(struct nftnl_ruleset *r, uint16_t attr, void *data);
+void *nftnl_ruleset_attr_get(const struct nftnl_ruleset *r, uint16_t attr);
enum {
- NFT_RULESET_CTX_CMD = 0,
- NFT_RULESET_CTX_TYPE,
- NFT_RULESET_CTX_TABLE,
- NFT_RULESET_CTX_CHAIN,
- NFT_RULESET_CTX_RULE,
- NFT_RULESET_CTX_SET,
- NFT_RULESET_CTX_DATA,
+ NFTNL_RULESET_CTX_CMD = 0,
+ NFTNL_RULESET_CTX_TYPE,
+ NFTNL_RULESET_CTX_TABLE,
+ NFTNL_RULESET_CTX_CHAIN,
+ NFTNL_RULESET_CTX_RULE,
+ NFTNL_RULESET_CTX_SET,
+ NFTNL_RULESET_CTX_DATA,
};
-struct nft_parse_ctx;
-void nft_ruleset_ctx_free(const struct nft_parse_ctx *ctx);
-bool nft_ruleset_ctx_is_set(const struct nft_parse_ctx *ctx, uint16_t attr);
-void *nft_ruleset_ctx_get(const struct nft_parse_ctx *ctx, uint16_t attr);
-uint32_t nft_ruleset_ctx_get_u32(const struct nft_parse_ctx *ctx,
+struct nftnl_parse_ctx;
+void nftnl_ruleset_ctx_free(const struct nftnl_parse_ctx *ctx);
+bool nftnl_ruleset_ctx_is_set(const struct nftnl_parse_ctx *ctx, uint16_t attr);
+void *nftnl_ruleset_ctx_get(const struct nftnl_parse_ctx *ctx, uint16_t attr);
+uint32_t nftnl_ruleset_ctx_get_u32(const struct nftnl_parse_ctx *ctx,
uint16_t attr);
-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 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 nft_ruleset_parse(struct nft_ruleset *rs, enum nft_parse_type type,
- const char *data, struct nft_parse_err *err);
-int nft_ruleset_parse_file(struct nft_ruleset *rs, enum nft_parse_type type,
- FILE *fp, struct nft_parse_err *err);
-int nft_ruleset_snprintf(char *buf, size_t size, const struct nft_ruleset *rs, uint32_t type, uint32_t flags);
-int nft_ruleset_fprintf(FILE *fp, const struct nft_ruleset *rs, uint32_t type, uint32_t flags);
+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));
+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));
+int nftnl_ruleset_parse(struct nftnl_ruleset *rs, enum nftnl_parse_type type,
+ const char *data, struct nftnl_parse_err *err);
+int nftnl_ruleset_parse_file(struct nftnl_ruleset *rs, enum nftnl_parse_type type,
+ FILE *fp, struct nftnl_parse_err *err);
+int nftnl_ruleset_snprintf(char *buf, size_t size, const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags);
+int nftnl_ruleset_fprintf(FILE *fp, const struct nftnl_ruleset *rs, uint32_t type, uint32_t flags);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/include/libnftnl/set.h b/include/libnftnl/set.h
index 4efc7d4..d3958f6 100644
--- a/include/libnftnl/set.h
+++ b/include/libnftnl/set.h
@@ -9,135 +9,135 @@
#include <libnftnl/common.h>
enum {
- NFT_SET_ATTR_TABLE,
- NFT_SET_ATTR_NAME,
- NFT_SET_ATTR_FLAGS,
- NFT_SET_ATTR_KEY_TYPE,
- NFT_SET_ATTR_KEY_LEN,
- NFT_SET_ATTR_DATA_TYPE,
- NFT_SET_ATTR_DATA_LEN,
- NFT_SET_ATTR_FAMILY,
- NFT_SET_ATTR_ID,
- NFT_SET_ATTR_POLICY,
- NFT_SET_ATTR_DESC_SIZE,
- NFT_SET_ATTR_TIMEOUT,
- NFT_SET_ATTR_GC_INTERVAL,
- __NFT_SET_ATTR_MAX
+ NFTNL_SET_ATTR_TABLE,
+ NFTNL_SET_ATTR_NAME,
+ NFTNL_SET_ATTR_FLAGS,
+ NFTNL_SET_ATTR_KEY_TYPE,
+ NFTNL_SET_ATTR_KEY_LEN,
+ NFTNL_SET_ATTR_DATA_TYPE,
+ NFTNL_SET_ATTR_DATA_LEN,
+ NFTNL_SET_ATTR_FAMILY,
+ NFTNL_SET_ATTR_ID,
+ NFTNL_SET_ATTR_POLICY,
+ NFTNL_SET_ATTR_DESC_SIZE,
+ NFTNL_SET_ATTR_TIMEOUT,
+ NFTNL_SET_ATTR_GC_INTERVAL,
+ __NFTNL_SET_ATTR_MAX
};
-#define NFT_SET_ATTR_MAX (__NFT_SET_ATTR_MAX - 1)
+#define NFTNL_SET_ATTR_MAX (__NFTNL_SET_ATTR_MAX - 1)
-struct nft_set;
+struct nftnl_set;
-struct nft_set *nft_set_alloc(void);
-void nft_set_free(struct nft_set *s);
+struct nftnl_set *nftnl_set_alloc(void);
+void nftnl_set_free(struct nftnl_set *s);
-struct nft_set *nft_set_clone(const struct nft_set *set);
+struct nftnl_set *nftnl_set_clone(const struct nftnl_set *set);
-bool nft_set_attr_is_set(const struct nft_set *s, uint16_t attr);
-void nft_set_attr_unset(struct nft_set *s, uint16_t attr);
-void nft_set_attr_set(struct nft_set *s, uint16_t attr, const void *data);
-void nft_set_attr_set_data(struct nft_set *s, uint16_t attr, const void *data,
+bool nftnl_set_attr_is_set(const struct nftnl_set *s, uint16_t attr);
+void nftnl_set_attr_unset(struct nftnl_set *s, uint16_t attr);
+void nftnl_set_attr_set(struct nftnl_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);
-void nft_set_attr_set_u32(struct nft_set *s, uint16_t attr, uint32_t val);
-void nft_set_attr_set_u64(struct nft_set *s, uint16_t attr, uint64_t val);
-void nft_set_attr_set_str(struct nft_set *s, uint16_t attr, const char *str);
+void nftnl_set_attr_set_u32(struct nftnl_set *s, uint16_t attr, uint32_t val);
+void nftnl_set_attr_set_u64(struct nftnl_set *s, uint16_t attr, uint64_t val);
+void nftnl_set_attr_set_str(struct nftnl_set *s, uint16_t attr, const char *str);
-const void *nft_set_attr_get(struct nft_set *s, uint16_t attr);
-const void *nft_set_attr_get_data(struct nft_set *s, uint16_t attr,
+const void *nftnl_set_attr_get(struct nftnl_set *s, uint16_t attr);
+const void *nftnl_set_attr_get_data(struct nftnl_set *s, uint16_t attr,
uint32_t *data_len);
-const char *nft_set_attr_get_str(struct nft_set *s, uint16_t attr);
-uint32_t nft_set_attr_get_u32(struct nft_set *s, uint16_t attr);
-uint64_t nft_set_attr_get_u64(struct nft_set *s, uint16_t attr);
+const char *nftnl_set_attr_get_str(struct nftnl_set *s, uint16_t attr);
+uint32_t nftnl_set_attr_get_u32(struct nftnl_set *s, uint16_t attr);
+uint64_t nftnl_set_attr_get_u64(struct nftnl_set *s, uint16_t attr);
struct nlmsghdr;
-#define nft_set_nlmsg_build_hdr nft_nlmsg_build_hdr
-void nft_set_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set *s);
-int nft_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s);
-int nft_set_elems_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s);
+#define nftnl_set_nlmsg_build_hdr nftnl_nlmsg_build_hdr
+void nftnl_set_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_set *s);
+int nftnl_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s);
+int nftnl_set_elems_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s);
-int nft_set_snprintf(char *buf, size_t size, struct nft_set *s, uint32_t type, uint32_t flags);
-int nft_set_fprintf(FILE *fp, struct nft_set *s, uint32_t type, uint32_t flags);
+int nftnl_set_snprintf(char *buf, size_t size, struct nftnl_set *s, uint32_t type, uint32_t flags);
+int nftnl_set_fprintf(FILE *fp, struct nftnl_set *s, uint32_t type, uint32_t flags);
-struct nft_set_list;
+struct nftnl_set_list;
-struct nft_set_list *nft_set_list_alloc(void);
-void nft_set_list_free(struct nft_set_list *list);
-int nft_set_list_is_empty(struct nft_set_list *list);
-void nft_set_list_add(struct nft_set *s, struct nft_set_list *list);
-void nft_set_list_add_tail(struct nft_set *s, struct nft_set_list *list);
-void nft_set_list_del(struct nft_set *s);
-int nft_set_list_foreach(struct nft_set_list *set_list, int (*cb)(struct nft_set *t, void *data), void *data);
+struct nftnl_set_list *nftnl_set_list_alloc(void);
+void nftnl_set_list_free(struct nftnl_set_list *list);
+int nftnl_set_list_is_empty(struct nftnl_set_list *list);
+void nftnl_set_list_add(struct nftnl_set *s, struct nftnl_set_list *list);
+void nftnl_set_list_add_tail(struct nftnl_set *s, struct nftnl_set_list *list);
+void nftnl_set_list_del(struct nftnl_set *s);
+int nftnl_set_list_foreach(struct nftnl_set_list *set_list, int (*cb)(struct nftnl_set *t, void *data), void *data);
-struct nft_set_list_iter;
-struct nft_set_list_iter *nft_set_list_iter_create(struct nft_set_list *l);
-struct nft_set *nft_set_list_iter_cur(struct nft_set_list_iter *iter);
-struct nft_set *nft_set_list_iter_next(struct nft_set_list_iter *iter);
-void nft_set_list_iter_destroy(struct nft_set_list_iter *iter);
+struct nftnl_set_list_iter;
+struct nftnl_set_list_iter *nftnl_set_list_iter_create(struct nftnl_set_list *l);
+struct nftnl_set *nftnl_set_list_iter_cur(struct nftnl_set_list_iter *iter);
+struct nftnl_set *nftnl_set_list_iter_next(struct nftnl_set_list_iter *iter);
+void nftnl_set_list_iter_destroy(struct nftnl_set_list_iter *iter);
-int nft_set_parse(struct nft_set *s, enum nft_parse_type type,
- const char *data, struct nft_parse_err *err);
-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(struct nftnl_set *s, enum nftnl_parse_type type,
+ const char *data, struct nftnl_parse_err *err);
+int nftnl_set_parse_file(struct nftnl_set *s, enum nftnl_parse_type type,
+ FILE *fp, struct nftnl_parse_err *err);
/*
* Set elements
*/
enum {
- NFT_SET_ELEM_ATTR_FLAGS,
- NFT_SET_ELEM_ATTR_KEY,
- NFT_SET_ELEM_ATTR_VERDICT,
- NFT_SET_ELEM_ATTR_CHAIN,
- NFT_SET_ELEM_ATTR_DATA,
- NFT_SET_ELEM_ATTR_TIMEOUT,
- NFT_SET_ELEM_ATTR_EXPIRATION,
- NFT_SET_ELEM_ATTR_USERDATA,
- NFT_SET_ELEM_ATTR_EXPR,
+ NFTNL_SET_ELEM_ATTR_FLAGS,
+ NFTNL_SET_ELEM_ATTR_KEY,
+ NFTNL_SET_ELEM_ATTR_VERDICT,
+ NFTNL_SET_ELEM_ATTR_CHAIN,
+ NFTNL_SET_ELEM_ATTR_DATA,
+ NFTNL_SET_ELEM_ATTR_TIMEOUT,
+ NFTNL_SET_ELEM_ATTR_EXPIRATION,
+ NFTNL_SET_ELEM_ATTR_USERDATA,
+ NFTNL_SET_ELEM_ATTR_EXPR,
};
-struct nft_set_elem;
+struct nftnl_set_elem;
-struct nft_set_elem *nft_set_elem_alloc(void);
-void nft_set_elem_free(struct nft_set_elem *s);
+struct nftnl_set_elem *nftnl_set_elem_alloc(void);
+void nftnl_set_elem_free(struct nftnl_set_elem *s);
-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);
-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);
-void nft_set_elem_attr_unset(struct nft_set_elem *s, uint16_t attr);
-void nft_set_elem_attr_set(struct nft_set_elem *s, uint16_t attr, const void *data, uint32_t data_len);
-void nft_set_elem_attr_set_u32(struct nft_set_elem *s, uint16_t attr, uint32_t val);
-void nft_set_elem_attr_set_u64(struct nft_set_elem *s, uint16_t attr, uint64_t val);
-void nft_set_elem_attr_set_str(struct nft_set_elem *s, uint16_t attr, const char *str);
+void nftnl_set_elem_attr_unset(struct nftnl_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);
+void nftnl_set_elem_attr_set_u32(struct nftnl_set_elem *s, uint16_t attr, uint32_t val);
+void nftnl_set_elem_attr_set_u64(struct nftnl_set_elem *s, uint16_t attr, uint64_t val);
+void nftnl_set_elem_attr_set_str(struct nftnl_set_elem *s, uint16_t attr, const char *str);
-const void *nft_set_elem_attr_get(struct nft_set_elem *s, uint16_t attr, uint32_t *data_len);
-const char *nft_set_elem_attr_get_str(struct nft_set_elem *s, uint16_t attr);
-uint32_t nft_set_elem_attr_get_u32(struct nft_set_elem *s, uint16_t attr);
-uint64_t nft_set_elem_attr_get_u64(struct nft_set_elem *s, uint16_t attr);
+const void *nftnl_set_elem_attr_get(struct nftnl_set_elem *s, uint16_t attr, uint32_t *data_len);
+const char *nftnl_set_elem_attr_get_str(struct nftnl_set_elem *s, uint16_t attr);
+uint32_t nftnl_set_elem_attr_get_u32(struct nftnl_set_elem *s, uint16_t attr);
+uint64_t nftnl_set_elem_attr_get_u64(struct nftnl_set_elem *s, uint16_t attr);
-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);
-#define nft_set_elem_nlmsg_build_hdr nft_nlmsg_build_hdr
-void nft_set_elems_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set *s);
-void nft_set_elem_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set_elem *e);
+#define nftnl_set_elem_nlmsg_build_hdr nftnl_nlmsg_build_hdr
+void nftnl_set_elems_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_set *s);
+void nftnl_set_elem_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_set_elem *e);
-int nft_set_elem_parse(struct nft_set_elem *e, enum nft_parse_type type,
- const char *data, struct nft_parse_err *err);
-int nft_set_elem_parse_file(struct nft_set_elem *e, enum nft_parse_type type,
- FILE *fp, struct nft_parse_err *err);
-int nft_set_elem_snprintf(char *buf, size_t size, struct nft_set_elem *s, uint32_t type, uint32_t flags);
-int nft_set_elem_fprintf(FILE *fp, struct nft_set_elem *se, uint32_t type, uint32_t flags);
+int nftnl_set_elem_parse(struct nftnl_set_elem *e, enum nftnl_parse_type type,
+ const char *data, struct nftnl_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);
+int nftnl_set_elem_snprintf(char *buf, size_t size, struct nftnl_set_elem *s, uint32_t type, uint32_t flags);
+int nftnl_set_elem_fprintf(FILE *fp, struct nftnl_set_elem *se, uint32_t type, uint32_t flags);
-int nft_set_elem_foreach(struct nft_set *s, int (*cb)(struct nft_set_elem *e, void *data), 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_elems_iter;
-struct nft_set_elems_iter *nft_set_elems_iter_create(struct nft_set *s);
-struct nft_set_elem *nft_set_elems_iter_cur(struct nft_set_elems_iter *iter);
-struct nft_set_elem *nft_set_elems_iter_next(struct nft_set_elems_iter *iter);
-void nft_set_elems_iter_destroy(struct nft_set_elems_iter *iter);
+struct nftnl_set_elems_iter;
+struct nftnl_set_elems_iter *nftnl_set_elems_iter_create(struct nftnl_set *s);
+struct nftnl_set_elem *nftnl_set_elems_iter_cur(struct nftnl_set_elems_iter *iter);
+struct nftnl_set_elem *nftnl_set_elems_iter_next(struct nftnl_set_elems_iter *iter);
+void nftnl_set_elems_iter_destroy(struct nftnl_set_elems_iter *iter);
-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);
#endif /* _LIBNFTNL_SET_H_ */
diff --git a/include/libnftnl/table.h b/include/libnftnl/table.h
index fac79e7..0f0589b 100644
--- a/include/libnftnl/table.h
+++ b/include/libnftnl/table.h
@@ -12,66 +12,66 @@
extern "C" {
#endif
-struct nft_table;
+struct nftnl_table;
-struct nft_table *nft_table_alloc(void);
-void nft_table_free(struct nft_table *);
+struct nftnl_table *nftnl_table_alloc(void);
+void nftnl_table_free(struct nftnl_table *);
enum {
- NFT_TABLE_ATTR_NAME = 0,
- NFT_TABLE_ATTR_FAMILY,
- NFT_TABLE_ATTR_FLAGS,
- NFT_TABLE_ATTR_USE,
- __NFT_TABLE_ATTR_MAX
+ NFTNL_TABLE_ATTR_NAME = 0,
+ NFTNL_TABLE_ATTR_FAMILY,
+ NFTNL_TABLE_ATTR_FLAGS,
+ NFTNL_TABLE_ATTR_USE,
+ __NFTNL_TABLE_ATTR_MAX
};
-#define NFT_TABLE_ATTR_MAX (__NFT_TABLE_ATTR_MAX - 1)
+#define NFTNL_TABLE_ATTR_MAX (__NFTNL_TABLE_ATTR_MAX - 1)
-bool nft_table_attr_is_set(const struct nft_table *t, uint16_t attr);
-void nft_table_attr_unset(struct nft_table *t, uint16_t attr);
-void nft_table_attr_set(struct nft_table *t, uint16_t attr, const void *data);
-void nft_table_attr_set_data(struct nft_table *t, uint16_t attr,
+bool nftnl_table_attr_is_set(const struct nftnl_table *t, uint16_t attr);
+void nftnl_table_attr_unset(struct nftnl_table *t, uint16_t attr);
+void nftnl_table_attr_set(struct nftnl_table *t, uint16_t attr, const void *data);
+void nftnl_table_attr_set_data(struct nftnl_table *t, uint16_t attr,
const void *data, uint32_t data_len);
-const void *nft_table_attr_get(struct nft_table *t, uint16_t attr);
-const void *nft_table_attr_get_data(struct nft_table *t, uint16_t attr,
+const void *nftnl_table_attr_get(struct nftnl_table *t, uint16_t attr);
+const void *nftnl_table_attr_get_data(struct nftnl_table *t, uint16_t attr,
uint32_t *data_len);
-void nft_table_attr_set_u8(struct nft_table *t, uint16_t attr, uint8_t data);
-void nft_table_attr_set_u32(struct nft_table *t, uint16_t attr, uint32_t data);
-void nft_table_attr_set_str(struct nft_table *t, uint16_t attr, const char *str);
-uint8_t nft_table_attr_get_u8(struct nft_table *t, uint16_t attr);
-uint32_t nft_table_attr_get_u32(struct nft_table *t, uint16_t attr);
-const char *nft_table_attr_get_str(struct nft_table *t, uint16_t attr);
+void nftnl_table_attr_set_u8(struct nftnl_table *t, uint16_t attr, uint8_t data);
+void nftnl_table_attr_set_u32(struct nftnl_table *t, uint16_t attr, uint32_t data);
+void nftnl_table_attr_set_str(struct nftnl_table *t, uint16_t attr, const char *str);
+uint8_t nftnl_table_attr_get_u8(struct nftnl_table *t, uint16_t attr);
+uint32_t nftnl_table_attr_get_u32(struct nftnl_table *t, uint16_t attr);
+const char *nftnl_table_attr_get_str(struct nftnl_table *t, uint16_t attr);
struct nlmsghdr;
-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);
-int nft_table_parse(struct nft_table *t, enum nft_parse_type type,
- const char *data, struct nft_parse_err *err);
-int nft_table_parse_file(struct nft_table *t, enum nft_parse_type type,
- FILE *fp, struct nft_parse_err *err);
-int nft_table_snprintf(char *buf, size_t size, struct nft_table *t, uint32_t type, uint32_t flags);
-int nft_table_fprintf(FILE *fp, struct nft_table *t, uint32_t type, uint32_t flags);
+int nftnl_table_parse(struct nftnl_table *t, enum nftnl_parse_type type,
+ const char *data, struct nftnl_parse_err *err);
+int nftnl_table_parse_file(struct nftnl_table *t, enum nftnl_parse_type type,
+ FILE *fp, struct nftnl_parse_err *err);
+int nftnl_table_snprintf(char *buf, size_t size, struct nftnl_table *t, uint32_t type, uint32_t flags);
+int nftnl_table_fprintf(FILE *fp, struct nftnl_table *t, uint32_t type, uint32_t flags);
-#define nft_table_nlmsg_build_hdr nft_nlmsg_build_hdr
-int nft_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_table *t);
+#define nftnl_table_nlmsg_build_hdr nftnl_nlmsg_build_hdr
+int nftnl_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_table *t);
-struct nft_table_list;
+struct nftnl_table_list;
-struct nft_table_list *nft_table_list_alloc(void);
-void nft_table_list_free(struct nft_table_list *list);
-int nft_table_list_is_empty(struct nft_table_list *list);
-int nft_table_list_foreach(struct nft_table_list *table_list, int (*cb)(struct nft_table *t, void *data), void *data);
+struct nftnl_table_list *nftnl_table_list_alloc(void);
+void nftnl_table_list_free(struct nftnl_table_list *list);
+int nftnl_table_list_is_empty(struct nftnl_table_list *list);
+int nftnl_table_list_foreach(struct nftnl_table_list *table_list, int (*cb)(struct nftnl_table *t, void *data), void *data);
-void nft_table_list_add(struct nft_table *r, struct nft_table_list *list);
-void nft_table_list_add_tail(struct nft_table *r, struct nft_table_list *list);
-void nft_table_list_del(struct nft_table *r);
+void nftnl_table_list_add(struct nftnl_table *r, struct nftnl_table_list *list);
+void nftnl_table_list_add_tail(struct nftnl_table *r, struct nftnl_table_list *list);
+void nftnl_table_list_del(struct nftnl_table *r);
-struct nft_table_list_iter;
+struct nftnl_table_list_iter;
-struct nft_table_list_iter *nft_table_list_iter_create(struct nft_table_list *l);
-struct nft_table *nft_table_list_iter_next(struct nft_table_list_iter *iter);
-void nft_table_list_iter_destroy(struct nft_table_list_iter *iter);
+struct nftnl_table_list_iter *nftnl_table_list_iter_create(struct nftnl_table_list *l);
+struct nftnl_table *nftnl_table_list_iter_next(struct nftnl_table_list_iter *iter);
+void nftnl_table_list_iter_destroy(struct nftnl_table_list_iter *iter);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/include/set.h b/include/set.h
index 008ed6e..1addd0f 100644
--- a/include/set.h
+++ b/include/set.h
@@ -3,7 +3,7 @@
#include <linux/netfilter/nf_tables.h>
-struct nft_set {
+struct nftnl_set {
struct list_head head;
uint32_t family;
@@ -26,9 +26,9 @@ struct nft_set {
uint64_t timeout;
};
-struct nft_set_list;
-struct nft_rule_expr;
-int nft_set_lookup_id(struct nft_rule_expr *e, struct nft_set_list *set_list,
+struct nftnl_set_list;
+struct nftnl_rule_expr;
+int nftnl_set_lookup_id(struct nftnl_rule_expr *e, struct nftnl_set_list *set_list,
uint32_t *set_id);
#endif
diff --git a/include/set_elem.h b/include/set_elem.h
index bdefe4b..13e096c 100644
--- a/include/set_elem.h
+++ b/include/set_elem.h
@@ -3,12 +3,12 @@
#include <data_reg.h>
-struct nft_set_elem {
+struct nftnl_set_elem {
struct list_head head;
uint32_t set_elem_flags;
- union nft_data_reg key;
- union nft_data_reg data;
- struct nft_rule_expr *expr;
+ union nftnl_data_reg key;
+ union nftnl_data_reg data;
+ struct nftnl_rule_expr *expr;
uint32_t flags;
uint64_t timeout;
uint64_t expiration;
diff --git a/include/utils.h b/include/utils.h
index fad64e8..7a46725 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -10,7 +10,7 @@
#include "config.h"
#ifdef HAVE_VISIBILITY_HIDDEN
# define __visible __attribute__((visibility("default")))
-# define EXPORT_SYMBOL(y, x) typeof(x) (x) __visible; __typeof (x) y __attribute ((alias (#x), visibility ("default")))
+# define EXPORT_SYMBOL(x, y) typeof(x) (x) __visible; __typeof (x) y __attribute ((alias (#x), visibility ("default")))
#else
# define EXPORT_SYMBOL
#endif
@@ -26,19 +26,19 @@ void __noreturn __abi_breakage(const char *file, int line, const char *reason);
#define abi_breakage() \
__abi_breakage(__FILE__, __LINE__, strerror(errno));
-void __nft_assert_fail(uint16_t attr, const char *filename, int line);
+void __nftnl_assert_fail(uint16_t attr, const char *filename, int line);
-#define nft_assert(val, attr, expr) \
+#define nftnl_assert(val, attr, expr) \
((!val || expr) \
? (void)0 \
- : __nft_assert_fail(attr, __FILE__, __LINE__))
+ : __nftnl_assert_fail(attr, __FILE__, __LINE__))
-#define nft_assert_validate(data, _validate_array, _attr, _data_len) \
+#define nftnl_assert_validate(data, _validate_array, _attr, _data_len) \
({ \
if (!data) \
- __nft_assert_fail(attr, __FILE__, __LINE__); \
+ __nftnl_assert_fail(attr, __FILE__, __LINE__); \
if (_validate_array[_attr]) \
- nft_assert(data, attr, _validate_array[_attr] == _data_len); \
+ nftnl_assert(data, attr, _validate_array[_attr] == _data_len); \
})
#define SNPRINTF_BUFFER_SIZE(ret, size, len, offset) \
@@ -50,32 +50,32 @@ void __nft_assert_fail(uint16_t attr, const char *filename, int line);
size += ret; \
len -= ret;
-const char *nft_family2str(uint32_t family);
-int nft_str2family(const char *family);
-
-enum nft_type {
- NFT_TYPE_U8,
- NFT_TYPE_U16,
- NFT_TYPE_U32,
- NFT_TYPE_U64,
- NFT_TYPE_S8,
- NFT_TYPE_S16,
- NFT_TYPE_S32,
- NFT_TYPE_S64,
+const char *nftnl_family2str(uint32_t family);
+int nftnl_str2family(const char *family);
+
+enum nftnl_type {
+ NFTNL_TYPE_U8,
+ NFTNL_TYPE_U16,
+ NFTNL_TYPE_U32,
+ NFTNL_TYPE_U64,
+ NFTNL_TYPE_S8,
+ NFTNL_TYPE_S16,
+ NFTNL_TYPE_S32,
+ NFTNL_TYPE_S64,
};
-int nft_strtoi(const char *string, int base, void *number, enum nft_type type);
-int nft_get_value(enum nft_type type, void *val, void *out);
+int nftnl_strtoi(const char *string, int base, void *number, enum nftnl_type type);
+int nftnl_get_value(enum nftnl_type type, void *val, void *out);
-const char *nft_verdict2str(uint32_t verdict);
-int nft_str2verdict(const char *verdict, int *verdict_num);
+const char *nftnl_verdict2str(uint32_t verdict);
+int nftnl_str2verdict(const char *verdict, int *verdict_num);
-const char *nft_cmd2tag(enum nft_cmd_type cmd);
-uint32_t nft_str2cmd(const char *cmd);
+const char *nftnl_cmd2tag(enum nftnl_cmd_type cmd);
+uint32_t nftnl_str2cmd(const char *cmd);
-enum nft_cmd_type nft_flag2cmd(uint32_t flags);
+enum nftnl_cmd_type nftnl_flag2cmd(uint32_t flags);
-int nft_fprintf(FILE *fp, void *obj, uint32_t cmd, uint32_t type,
+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));
diff --git a/include/xml.h b/include/xml.h
index 5137034..454de44 100644
--- a/include/xml.h
+++ b/include/xml.h
@@ -5,52 +5,52 @@
#include <mxml.h>
#include "common.h"
-#define NFT_XML_MAND 0
-#define NFT_XML_OPT (1 << 0)
+#define NFTNL_XML_MAND 0
+#define NFTNL_XML_OPT (1 << 0)
-struct nft_table;
-struct nft_chain;
-struct nft_rule;
-struct nft_set;
-struct nft_set_elem;
-struct nft_set_list;
-union nft_data_reg;
+struct nftnl_table;
+struct nftnl_chain;
+struct nftnl_rule;
+struct nftnl_set;
+struct nftnl_set_elem;
+struct nftnl_set_list;
+union nftnl_data_reg;
-mxml_node_t *nft_mxml_build_tree(const void *data, const char *treename,
- struct nft_parse_err *err, enum nft_parse_input input);
-struct nft_rule_expr *nft_mxml_expr_parse(mxml_node_t *node,
- struct nft_parse_err *err,
- struct nft_set_list *set_list);
-int nft_mxml_reg_parse(mxml_node_t *tree, const char *reg_name, uint32_t *reg,
+mxml_node_t *nftnl_mxml_build_tree(const void *data, const char *treename,
+ struct nftnl_parse_err *err, enum nftnl_parse_input input);
+struct nftnl_rule_expr *nftnl_mxml_expr_parse(mxml_node_t *node,
+ struct nftnl_parse_err *err,
+ struct nftnl_set_list *set_list);
+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);
-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 nft_mxml_num_parse(mxml_node_t *tree, const char *node_name,
+ struct nftnl_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);
+int 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);
-const char *nft_mxml_str_parse(mxml_node_t *tree, const char *node_name,
+ enum nftnl_type type, uint16_t flags,
+ struct nftnl_parse_err *err);
+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);
-int nft_mxml_family_parse(mxml_node_t *tree, const char *node_name,
+ struct nftnl_parse_err *err);
+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);
-int nft_mxml_set_elem_parse(mxml_node_t *node, struct nft_set_elem *e,
- struct nft_parse_err *err);
-int nft_mxml_table_parse(mxml_node_t *tree, struct nft_table *t,
- struct nft_parse_err *err);
-int nft_mxml_chain_parse(mxml_node_t *tree, struct nft_chain *c,
- struct nft_parse_err *err);
-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 nft_mxml_set_parse(mxml_node_t *tree, struct nft_set *s,
- struct nft_parse_err *err);
+ struct nftnl_parse_err *err);
+int nftnl_mxml_set_elem_parse(mxml_node_t *node, struct nftnl_set_elem *e,
+ struct nftnl_parse_err *err);
+int nftnl_mxml_table_parse(mxml_node_t *tree, struct nftnl_table *t,
+ struct nftnl_parse_err *err);
+int nftnl_mxml_chain_parse(mxml_node_t *tree, struct nftnl_chain *c,
+ struct nftnl_parse_err *err);
+int nftnl_mxml_rule_parse(mxml_node_t *tree, struct nftnl_rule *r,
+ struct nftnl_parse_err *err,
+ struct nftnl_set_list *set_list);
+int nftnl_mxml_set_parse(mxml_node_t *tree, struct nftnl_set *s,
+ struct nftnl_parse_err *err);
-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);
#else
#define mxml_node_t void
#endif
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),
diff --git a/src/expr.c b/src/expr.c
index 7731a85..115203e 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -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, &reg, err) == 0)
- nft_rule_expr_set_u32(e, NFT_EXPR_BITWISE_SREG, reg);
+ if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &reg, err) == 0)
+ nftnl_rule_expr_set_u32(e, NFTNL_EXPR_BITWISE_SREG, reg);
- if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, &reg, err) == 0)
- nft_rule_expr_set_u32(e, NFT_EXPR_BITWISE_DREG, reg);
+ if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg, 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, &reg, err) == 0)
- nft_rule_expr_set_u32(e, NFT_EXPR_CT_DREG, reg);
+ if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg, err) == 0)
+ nftnl_rule_expr_set_u32(e, NFTNL_EXPR_CT_DREG, reg);
- if (nft_jansson_parse_reg(root, "sreg", NFT_TYPE_U32, &reg, err) == 0)
- nft_rule_expr_set_u32(e, NFT_EXPR_CT_SREG, reg);
+ if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &reg, 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, &reg->len, err) < 0)
+ if (nftnl_jansson_parse_val(data, "len", NFTNL_TYPE_U8, &reg->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,
- &reg->val[i], NFT_TYPE_U32, err) != 0)
+ if (nftnl_jansson_str2num(data, node_name, BASE_HEX,
+ &reg->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,
- &reg->len, NFT_TYPE_U8, NFT_XML_MAND, err) != 0)
+ if (nftnl_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC,
+ &reg->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, &reg->val[i], NFT_TYPE_U32,
- NFT_XML_MAND, err) != 0)
+ if (nftnl_mxml_num_parse(tree, node_name, MXML_DESCEND_FIRST,
+ BASE_HEX, &reg->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, &reg, err) == 0)
- nft_rule_expr_set_u32(e, NFT_EXPR_IMM_DREG, reg);
+ if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg, 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", &reg, 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", &reg, 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, &reg,
+ if (nftnl_jansson_node_exist(root, "dreg")) {
+ if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg,
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, &reg,
+ if (nftnl_jansson_node_exist(root, "sreg")) {
+ if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &reg,
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,
&reg, 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,
&reg, 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,
&reg, 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,
&reg, 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", &reg_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", &reg_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", &reg_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", &reg_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", &reg_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", &reg_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", &reg_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", &reg_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, &reg, err) == 0)
- nft_rule_expr_set_u32(e, NFT_EXPR_PAYLOAD_DREG, reg);
+ if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg, 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,
&reg, 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,
&reg, 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", &reg,
- 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", &reg,
+ 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", &reg,
- 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", &reg,
+ 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;
diff --git a/src/gen.c b/src/gen.c
index 2c9e561..bb66295 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -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:
diff --git a/src/mxml.c b/src/mxml.c
index b68f86f..de43f73 100644
--- a/src/mxml.c
+++ b/src/mxml.c
@@ -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;
diff --git a/src/rule.c b/src/rule.c
index d47bc2c..0668311 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -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);
diff --git a/src/set.c b/src/set.c
index 2df6b93..293341a 100644
--- a/src/set.c
+++ b/src/set.c
@@ -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