From 760768890e60617acfd144dce875a4a3be14513c Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Tue, 1 Sep 2015 20:19:56 +0200 Subject: 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 --- examples/nft-chain-add.c | 28 ++--- examples/nft-chain-del.c | 24 ++-- examples/nft-chain-get.c | 34 +++--- examples/nft-chain-parse-add.c | 46 +++---- examples/nft-events.c | 84 ++++++------- examples/nft-rule-add.c | 68 +++++------ examples/nft-rule-del.c | 22 ++-- examples/nft-rule-get.c | 24 ++-- examples/nft-rule-parse-add.c | 48 ++++---- examples/nft-ruleset-get.c | 152 ++++++++++++------------ examples/nft-ruleset-parse-file.c | 244 +++++++++++++++++++------------------- examples/nft-set-add.c | 32 ++--- examples/nft-set-del.c | 14 +-- examples/nft-set-elem-add.c | 28 ++--- examples/nft-set-elem-del.c | 28 ++--- examples/nft-set-elem-get.c | 32 ++--- examples/nft-set-get.c | 30 ++--- examples/nft-set-parse-add.c | 46 +++---- examples/nft-table-add.c | 26 ++-- examples/nft-table-del.c | 26 ++-- examples/nft-table-get.c | 32 ++--- examples/nft-table-parse-add.c | 44 +++---- examples/nft-table-upd.c | 14 +-- 23 files changed, 563 insertions(+), 563 deletions(-) (limited to 'examples') 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 #include -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 #include -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 #include -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 #include -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 #include -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 #include -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 #include -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 []\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 #include -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 #include -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 #include -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 [] []\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 #include -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) { -- cgit v1.2.3