diff options
Diffstat (limited to 'tests')
32 files changed, 275 insertions, 313 deletions
diff --git a/tests/nft-chain-test.c b/tests/nft-chain-test.c index d678d46..0d0544a 100644 --- a/tests/nft-chain-test.c +++ b/tests/nft-chain-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -23,9 +18,25 @@ static void print_err(const char *msg) printf("\033[31mERROR:\e[0m %s\n", msg); } -static void cmp_nftnl_chain(struct nftnl_chain *a, struct nftnl_chain *b) +static void cmp_devices(const char * const *adevs, + const char * const *bdevs) { + int i; + + if (!adevs && !bdevs) + return; + if (!!adevs ^ !!bdevs) + print_err("Chain devices mismatches"); + for (i = 0; adevs[i] && bdevs[i]; i++) { + if (strcmp(adevs[i], bdevs[i])) + break; + } + if (adevs[i] || bdevs[i]) + print_err("Chain devices mismatches"); +} +static void cmp_nftnl_chain(struct nftnl_chain *a, struct nftnl_chain *b) +{ if (strcmp(nftnl_chain_get_str(a, NFTNL_CHAIN_NAME), nftnl_chain_get_str(b, NFTNL_CHAIN_NAME)) != 0) print_err("Chain name mismatches"); @@ -59,13 +70,17 @@ static void cmp_nftnl_chain(struct nftnl_chain *a, struct nftnl_chain *b) if (strcmp(nftnl_chain_get_str(a, NFTNL_CHAIN_TYPE), nftnl_chain_get_str(b, NFTNL_CHAIN_TYPE)) != 0) print_err("Chain type mismatches"); - if (strcmp(nftnl_chain_get_str(a, NFTNL_CHAIN_DEV), + if (nftnl_chain_is_set(a, NFTNL_CHAIN_DEV) && + strcmp(nftnl_chain_get_str(a, NFTNL_CHAIN_DEV), nftnl_chain_get_str(b, NFTNL_CHAIN_DEV)) != 0) print_err("Chain device mismatches"); + cmp_devices(nftnl_chain_get_array(a, NFTNL_CHAIN_DEVICES), + nftnl_chain_get_array(b, NFTNL_CHAIN_DEVICES)); } int main(int argc, char *argv[]) { + const char *devs[] = { "eth0", "eth1", "eth2", NULL }; struct nftnl_chain *a, *b; char buf[4096]; struct nlmsghdr *nlh; @@ -89,8 +104,20 @@ int main(int argc, char *argv[]) nftnl_chain_set_str(a, NFTNL_CHAIN_DEV, "eth0"); /* cmd extracted from include/linux/netfilter/nf_tables.h */ - nlh = nftnl_chain_nlmsg_build_hdr(buf, NFT_MSG_NEWCHAIN, AF_INET, - 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWCHAIN, AF_INET, 0, 1234); + nftnl_chain_nlmsg_build_payload(nlh, a); + + if (nftnl_chain_nlmsg_parse(nlh, b) < 0) + print_err("parsing problems"); + + cmp_nftnl_chain(a, b); + + /* repeat test with multiple devices */ + + nftnl_chain_unset(a, NFTNL_CHAIN_DEV); + nftnl_chain_set_array(a, NFTNL_CHAIN_DEVICES, devs); + + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWCHAIN, AF_INET, 0, 1234); nftnl_chain_nlmsg_build_payload(nlh, a); if (nftnl_chain_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_bitwise-test.c b/tests/nft-expr_bitwise-test.c index f134728..784619e 100644 --- a/tests/nft-expr_bitwise-test.c +++ b/tests/nft-expr_bitwise-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -27,81 +22,35 @@ static void print_err(const char *test, const char *msg) printf("\033[31mERROR:\e[0m [%s] %s\n", test, msg); } -static void cmp_nftnl_expr_bool(struct nftnl_expr *rule_a, - struct nftnl_expr *rule_b) +static void cmp_nftnl_expr_mask_xor(struct nftnl_expr *rule_a, + struct nftnl_expr *rule_b) { uint32_t maska, maskb; uint32_t xora, xorb; if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_DREG) != nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_DREG)) - print_err("bool", "Expr BITWISE_DREG mismatches"); + print_err("mask & xor", "Expr BITWISE_DREG mismatches"); if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_SREG) != nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_SREG)) - print_err("bool", "Expr BITWISE_SREG mismatches"); + print_err("mask & xor", "Expr BITWISE_SREG mismatches"); if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_OP) != nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_OP)) - print_err("bool", "Expr BITWISE_OP mismatches"); + print_err("mask & xor", "Expr BITWISE_OP mismatches"); if (nftnl_expr_get_u16(rule_a, NFTNL_EXPR_BITWISE_LEN) != nftnl_expr_get_u16(rule_b, NFTNL_EXPR_BITWISE_LEN)) - print_err("bool", "Expr BITWISE_LEN mismatches"); + print_err("mask & xor", "Expr BITWISE_LEN mismatches"); nftnl_expr_get(rule_a, NFTNL_EXPR_BITWISE_MASK, &maska); nftnl_expr_get(rule_b, NFTNL_EXPR_BITWISE_MASK, &maskb); if (maska != maskb) - print_err("bool", "Size of BITWISE_MASK mismatches"); + print_err("mask & xor", "Size of BITWISE_MASK mismatches"); nftnl_expr_get(rule_a, NFTNL_EXPR_BITWISE_XOR, &xora); nftnl_expr_get(rule_b, NFTNL_EXPR_BITWISE_XOR, &xorb); if (xora != xorb) - print_err("bool", "Size of BITWISE_XOR mismatches"); + print_err("mask & xor", "Size of BITWISE_XOR mismatches"); } -static void cmp_nftnl_expr_lshift(struct nftnl_expr *rule_a, - struct nftnl_expr *rule_b) -{ - uint32_t data_a, data_b; - - if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_DREG) != - nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_DREG)) - print_err("lshift", "Expr BITWISE_DREG mismatches"); - if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_SREG) != - nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_SREG)) - print_err("lshift", "Expr BITWISE_SREG mismatches"); - if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_OP) != - nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_OP)) - print_err("lshift", "Expr BITWISE_OP mismatches"); - if (nftnl_expr_get_u16(rule_a, NFTNL_EXPR_BITWISE_LEN) != - nftnl_expr_get_u16(rule_b, NFTNL_EXPR_BITWISE_LEN)) - print_err("lshift", "Expr BITWISE_LEN mismatches"); - nftnl_expr_get(rule_a, NFTNL_EXPR_BITWISE_DATA, &data_a); - nftnl_expr_get(rule_b, NFTNL_EXPR_BITWISE_DATA, &data_b); - if (data_a != data_b) - print_err("lshift", "Expr BITWISE_DATA mismatches"); -} - -static void cmp_nftnl_expr_rshift(struct nftnl_expr *rule_a, - struct nftnl_expr *rule_b) -{ - uint32_t data_a, data_b; - - if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_DREG) != - nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_DREG)) - print_err("rshift", "Expr BITWISE_DREG mismatches"); - if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_SREG) != - nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_SREG)) - print_err("rshift", "Expr BITWISE_SREG mismatches"); - if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_OP) != - nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_OP)) - print_err("rshift", "Expr BITWISE_OP mismatches"); - if (nftnl_expr_get_u16(rule_a, NFTNL_EXPR_BITWISE_LEN) != - nftnl_expr_get_u16(rule_b, NFTNL_EXPR_BITWISE_LEN)) - print_err("rshift", "Expr BITWISE_LEN mismatches"); - nftnl_expr_get(rule_a, NFTNL_EXPR_BITWISE_DATA, &data_a); - nftnl_expr_get(rule_b, NFTNL_EXPR_BITWISE_DATA, &data_b); - if (data_a != data_b) - print_err("rshift", "Expr BITWISE_DATA mismatches"); -} - -static void test_bool(void) +static void test_mask_xor(void) { struct nftnl_rule *a, *b = NULL; struct nftnl_expr *ex = NULL; @@ -115,10 +64,10 @@ static void test_bool(void) a = nftnl_rule_alloc(); b = nftnl_rule_alloc(); if (a == NULL || b == NULL) - print_err("bool", "OOM"); + print_err("mask & xor", "OOM"); ex = nftnl_expr_alloc("bitwise"); if (ex == NULL) - print_err("bool", "OOM"); + print_err("mask & xor", "OOM"); nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_SREG, 0x12345678); nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_DREG, 0x78123456); @@ -129,111 +78,170 @@ static void test_bool(void) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) - print_err("bool", "parsing problems"); + print_err("mask & xor", "parsing problems"); iter_a = nftnl_expr_iter_create(a); iter_b = nftnl_expr_iter_create(b); if (iter_a == NULL || iter_b == NULL) - print_err("bool", "OOM"); + print_err("mask & xor", "OOM"); rule_a = nftnl_expr_iter_next(iter_a); rule_b = nftnl_expr_iter_next(iter_b); if (rule_a == NULL || rule_b == NULL) - print_err("bool", "OOM"); + print_err("mask & xor", "OOM"); if (nftnl_expr_iter_next(iter_a) != NULL || nftnl_expr_iter_next(iter_b) != NULL) - print_err("bool", "More 1 expr."); + print_err("mask & xor", "More 1 expr."); nftnl_expr_iter_destroy(iter_a); nftnl_expr_iter_destroy(iter_b); - cmp_nftnl_expr_bool(rule_a,rule_b); + cmp_nftnl_expr_mask_xor(rule_a,rule_b); nftnl_rule_free(a); nftnl_rule_free(b); } -static void test_lshift(void) +static void cmp_nftnl_expr_shift(const char *opname, + const struct nftnl_expr *rule_a, + const struct nftnl_expr *rule_b) { - struct nftnl_rule *a, *b = NULL; - struct nftnl_expr *ex = NULL; + uint32_t data_a, data_b; + + if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_DREG) != + nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_DREG)) + print_err(opname, "Expr BITWISE_DREG mismatches"); + if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_SREG) != + nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_SREG)) + print_err(opname, "Expr BITWISE_SREG mismatches"); + if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_OP) != + nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_OP)) + print_err(opname, "Expr BITWISE_OP mismatches"); + if (nftnl_expr_get_u16(rule_a, NFTNL_EXPR_BITWISE_LEN) != + nftnl_expr_get_u16(rule_b, NFTNL_EXPR_BITWISE_LEN)) + print_err(opname, "Expr BITWISE_LEN mismatches"); + nftnl_expr_get(rule_a, NFTNL_EXPR_BITWISE_DATA, &data_a); + nftnl_expr_get(rule_b, NFTNL_EXPR_BITWISE_DATA, &data_b); + if (data_a != data_b) + print_err(opname, "Expr BITWISE_DATA mismatches"); +} + +static void test_shift(enum nft_bitwise_ops op) +{ + struct nftnl_rule *a, *b; + struct nftnl_expr *ex; struct nlmsghdr *nlh; char buf[4096]; - struct nftnl_expr_iter *iter_a, *iter_b = NULL; - struct nftnl_expr *rule_a, *rule_b = NULL; + struct nftnl_expr_iter *iter_a, *iter_b; + struct nftnl_expr *rule_a, *rule_b; + const char *opname = op == NFT_BITWISE_LSHIFT ? "lshift" : "rshift"; a = nftnl_rule_alloc(); b = nftnl_rule_alloc(); if (a == NULL || b == NULL) - print_err("lshift", "OOM"); + print_err(opname, "OOM"); ex = nftnl_expr_alloc("bitwise"); if (ex == NULL) - print_err("lshift", "OOM"); + print_err(opname, "OOM"); nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_SREG, 0x12345678); nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_DREG, 0x78123456); - nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_OP, NFT_BITWISE_LSHIFT); + nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_OP, op); nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_LEN, 0x56781234); nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_DATA, 13); nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) - print_err("lshift", "parsing problems"); + print_err(opname, "parsing problems"); iter_a = nftnl_expr_iter_create(a); iter_b = nftnl_expr_iter_create(b); if (iter_a == NULL || iter_b == NULL) - print_err("lshift", "OOM"); + print_err(opname, "OOM"); rule_a = nftnl_expr_iter_next(iter_a); rule_b = nftnl_expr_iter_next(iter_b); if (rule_a == NULL || rule_b == NULL) - print_err("lshift", "OOM"); + print_err(opname, "OOM"); if (nftnl_expr_iter_next(iter_a) != NULL || nftnl_expr_iter_next(iter_b) != NULL) - print_err("lshift", "More 1 expr."); + print_err(opname, "More 1 expr."); nftnl_expr_iter_destroy(iter_a); nftnl_expr_iter_destroy(iter_b); - cmp_nftnl_expr_lshift(rule_a,rule_b); + cmp_nftnl_expr_shift(opname, rule_a, rule_b); nftnl_rule_free(a); nftnl_rule_free(b); } +static void test_lshift(void) +{ + test_shift(NFT_BITWISE_LSHIFT); +} + static void test_rshift(void) { - struct nftnl_rule *a, *b = NULL; - struct nftnl_expr *ex = NULL; + test_shift(NFT_BITWISE_RSHIFT); +} + +static void cmp_nftnl_expr_bool(const char *opname, + const struct nftnl_expr *rule_a, + const struct nftnl_expr *rule_b) +{ + if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_DREG) != + nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_DREG)) + print_err(opname, "Expr BITWISE_DREG mismatches"); + if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_SREG) != + nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_SREG)) + print_err(opname, "Expr BITWISE_SREG mismatches"); + if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_SREG2) != + nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_SREG2)) + print_err(opname, "Expr BITWISE_SREG2 mismatches"); + if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_BITWISE_OP) != + nftnl_expr_get_u32(rule_b, NFTNL_EXPR_BITWISE_OP)) + print_err(opname, "Expr BITWISE_OP mismatches"); + if (nftnl_expr_get_u16(rule_a, NFTNL_EXPR_BITWISE_LEN) != + nftnl_expr_get_u16(rule_b, NFTNL_EXPR_BITWISE_LEN)) + print_err(opname, "Expr BITWISE_LEN mismatches"); +} + +static void test_bool(enum nft_bitwise_ops op) +{ + struct nftnl_rule *a, *b; + struct nftnl_expr *ex; struct nlmsghdr *nlh; char buf[4096]; - struct nftnl_expr_iter *iter_a, *iter_b = NULL; - struct nftnl_expr *rule_a, *rule_b = NULL; + struct nftnl_expr_iter *iter_a, *iter_b; + struct nftnl_expr *rule_a, *rule_b; + const char *opname = + op == NFT_BITWISE_AND ? "and" : + op == NFT_BITWISE_OR ? "or" : "xor"; a = nftnl_rule_alloc(); b = nftnl_rule_alloc(); if (a == NULL || b == NULL) - print_err("rshift", "OOM"); + print_err(opname, "OOM"); ex = nftnl_expr_alloc("bitwise"); if (ex == NULL) - print_err("rshift", "OOM"); + print_err(opname, "OOM"); nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_SREG, 0x12345678); + nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_SREG2, 0x90abcdef); nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_DREG, 0x78123456); - nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_OP, NFT_BITWISE_RSHIFT); + nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_OP, op); nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_LEN, 0x56781234); - nftnl_expr_set_u32(ex, NFTNL_EXPR_BITWISE_DATA, 17); nftnl_rule_add_expr(a, ex); @@ -241,34 +249,49 @@ static void test_rshift(void) nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) - print_err("rshift", "parsing problems"); + print_err(opname, "parsing problems"); iter_a = nftnl_expr_iter_create(a); iter_b = nftnl_expr_iter_create(b); if (iter_a == NULL || iter_b == NULL) - print_err("rshift", "OOM"); + print_err(opname, "OOM"); rule_a = nftnl_expr_iter_next(iter_a); rule_b = nftnl_expr_iter_next(iter_b); if (rule_a == NULL || rule_b == NULL) - print_err("rshift", "OOM"); + print_err(opname, "OOM"); if (nftnl_expr_iter_next(iter_a) != NULL || nftnl_expr_iter_next(iter_b) != NULL) - print_err("rshift", "More 1 expr."); + print_err(opname, "More 1 expr."); nftnl_expr_iter_destroy(iter_a); nftnl_expr_iter_destroy(iter_b); - cmp_nftnl_expr_rshift(rule_a,rule_b); + cmp_nftnl_expr_bool(opname, rule_a, rule_b); nftnl_rule_free(a); nftnl_rule_free(b); } +static void test_and(void) +{ + test_bool(NFT_BITWISE_AND); +} + +static void test_or(void) +{ + test_bool(NFT_BITWISE_OR); +} + +static void test_xor(void) +{ + test_bool(NFT_BITWISE_XOR); +} + int main(int argc, char *argv[]) { - test_bool(); + test_mask_xor(); if (!test_ok) exit(EXIT_FAILURE); @@ -280,6 +303,18 @@ int main(int argc, char *argv[]) if (!test_ok) exit(EXIT_FAILURE); + test_and(); + if (!test_ok) + exit(EXIT_FAILURE); + + test_or(); + if (!test_ok) + exit(EXIT_FAILURE); + + test_xor(); + if (!test_ok) + exit(EXIT_FAILURE); + printf("%s: \033[32mOK\e[0m\n", argv[0]); return EXIT_SUCCESS; } diff --git a/tests/nft-expr_byteorder-test.c b/tests/nft-expr_byteorder-test.c index 5994e5b..dfd6973 100644 --- a/tests/nft-expr_byteorder-test.c +++ b/tests/nft-expr_byteorder-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -72,7 +67,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_cmp-test.c b/tests/nft-expr_cmp-test.c index ec00bb9..e5f5c9b 100644 --- a/tests/nft-expr_cmp-test.c +++ b/tests/nft-expr_cmp-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -68,7 +63,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_counter-test.c b/tests/nft-expr_counter-test.c index 519bc1f..b9b5501 100644 --- a/tests/nft-expr_counter-test.c +++ b/tests/nft-expr_counter-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -60,7 +55,7 @@ int main(int argc, char *argv[]) nftnl_expr_set_u64(ex, NFTNL_EXPR_CTR_PACKETS, 0xf0123456789abcde); nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_ct-test.c b/tests/nft-expr_ct-test.c index e98fbab..b6b192e 100644 --- a/tests/nft-expr_ct-test.c +++ b/tests/nft-expr_ct-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -62,7 +57,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_dup-test.c b/tests/nft-expr_dup-test.c index 3c37d4a..1865d49 100644 --- a/tests/nft-expr_dup-test.c +++ b/tests/nft-expr_dup-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -59,7 +54,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_exthdr-test.c b/tests/nft-expr_exthdr-test.c index fef2dd0..514eebe 100644 --- a/tests/nft-expr_exthdr-test.c +++ b/tests/nft-expr_exthdr-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -68,7 +63,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) print_err("parsing problems"); diff --git a/tests/nft-expr_fwd-test.c b/tests/nft-expr_fwd-test.c index 4fdf53d..a52caa9 100644 --- a/tests/nft-expr_fwd-test.c +++ b/tests/nft-expr_fwd-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -55,7 +50,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_hash-test.c b/tests/nft-expr_hash-test.c index 7be6e9e..e2e59e9 100644 --- a/tests/nft-expr_hash-test.c +++ b/tests/nft-expr_hash-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2016 by Laura Garcia <nevola@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -76,7 +71,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) print_err("parsing problems"); diff --git a/tests/nft-expr_immediate-test.c b/tests/nft-expr_immediate-test.c index c25eedb..e054c23 100644 --- a/tests/nft-expr_immediate-test.c +++ b/tests/nft-expr_immediate-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -93,7 +88,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex_val); nftnl_rule_add_expr(a, ex_ver); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_limit-test.c b/tests/nft-expr_limit-test.c index 2838941..4347f9c 100644 --- a/tests/nft-expr_limit-test.c +++ b/tests/nft-expr_limit-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -73,7 +68,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_log-test.c b/tests/nft-expr_log-test.c index b7aa302..2fc5ad6 100644 --- a/tests/nft-expr_log-test.c +++ b/tests/nft-expr_log-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -68,7 +63,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) print_err("parsing problems"); diff --git a/tests/nft-expr_lookup-test.c b/tests/nft-expr_lookup-test.c index 9e6e051..de84ea8 100644 --- a/tests/nft-expr_lookup-test.c +++ b/tests/nft-expr_lookup-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -76,7 +71,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_masq-test.c b/tests/nft-expr_masq-test.c index 3f9903d..1705dc0 100644 --- a/tests/nft-expr_masq-test.c +++ b/tests/nft-expr_masq-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -62,7 +57,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_match-test.c b/tests/nft-expr_match-test.c index 39a49d8..bc9f6ac 100644 --- a/tests/nft-expr_match-test.c +++ b/tests/nft-expr_match-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -59,7 +54,7 @@ int main(int argc, char *argv[]) char buf[4096]; struct nftnl_expr_iter *iter_a, *iter_b; struct nftnl_expr *rule_a, *rule_b; - char data[16] = "0123456789abcdef"; + char data[] = "0123456789abcdef"; a = nftnl_rule_alloc(); b = nftnl_rule_alloc(); @@ -74,7 +69,7 @@ int main(int argc, char *argv[]) nftnl_expr_set(ex, NFTNL_EXPR_MT_INFO, strdup(data), sizeof(data)); nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_meta-test.c b/tests/nft-expr_meta-test.c index 8fb7873..43c665f 100644 --- a/tests/nft-expr_meta-test.c +++ b/tests/nft-expr_meta-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -60,7 +55,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) print_err("parsing problems"); diff --git a/tests/nft-expr_nat-test.c b/tests/nft-expr_nat-test.c index fd3a488..983e1af 100644 --- a/tests/nft-expr_nat-test.c +++ b/tests/nft-expr_nat-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -81,7 +76,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_numgen-test.c b/tests/nft-expr_numgen-test.c index 0d0a3bb..666043e 100644 --- a/tests/nft-expr_numgen-test.c +++ b/tests/nft-expr_numgen-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2016 by Laura Garcia <nevola@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -68,7 +63,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) print_err("parsing problems"); diff --git a/tests/nft-expr_objref-test.c b/tests/nft-expr_objref-test.c index 08e27ce..36c869e 100644 --- a/tests/nft-expr_objref-test.c +++ b/tests/nft-expr_objref-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -52,7 +47,7 @@ int main(int argc, char *argv[]) b = nftnl_rule_alloc(); if (a == NULL || b == NULL) print_err("OOM"); - ex = nftnl_expr_alloc("lookup"); + ex = nftnl_expr_alloc("objref"); if (ex == NULL) print_err("OOM"); diff --git a/tests/nft-expr_payload-test.c b/tests/nft-expr_payload-test.c index 371372c..8c41bab 100644 --- a/tests/nft-expr_payload-test.c +++ b/tests/nft-expr_payload-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -69,7 +64,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) print_err("parsing problems"); diff --git a/tests/nft-expr_queue-test.c b/tests/nft-expr_queue-test.c index 81d7dd2..b114cea 100644 --- a/tests/nft-expr_queue-test.c +++ b/tests/nft-expr_queue-test.c @@ -1,13 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Eric Leblond <eric@regit.org> * * Based on test framework by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -67,7 +62,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_quota-test.c b/tests/nft-expr_quota-test.c index 2320551..193afc8 100644 --- a/tests/nft-expr_quota-test.c +++ b/tests/nft-expr_quota-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2016 by Pablo Neira Ayuso <pablo@netfilter.org> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -59,7 +54,7 @@ int main(int argc, char *argv[]) nftnl_expr_set_u32(ex, NFTNL_EXPR_QUOTA_FLAGS, 0x12345678); nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_range-test.c b/tests/nft-expr_range-test.c index b92dfc0..c441a2e 100644 --- a/tests/nft-expr_range-test.c +++ b/tests/nft-expr_range-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -75,7 +70,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_redir-test.c b/tests/nft-expr_redir-test.c index 6c8caec..d2de222 100644 --- a/tests/nft-expr_redir-test.c +++ b/tests/nft-expr_redir-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -62,7 +57,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_reject-test.c b/tests/nft-expr_reject-test.c index d8189ea..cadd322 100644 --- a/tests/nft-expr_reject-test.c +++ b/tests/nft-expr_reject-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -61,7 +56,7 @@ int main(int argc, char *argv[]) nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-expr_target-test.c b/tests/nft-expr_target-test.c index ba56b27..a483e7a 100644 --- a/tests/nft-expr_target-test.c +++ b/tests/nft-expr_target-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -58,7 +53,7 @@ int main(int argc, char *argv[]) char buf[4096]; struct nftnl_expr_iter *iter_a, *iter_b; struct nftnl_expr *rule_a, *rule_b; - char data[16] = "0123456789abcdef"; + char data[] = "0123456789abcdef"; a = nftnl_rule_alloc(); b = nftnl_rule_alloc(); @@ -74,7 +69,7 @@ int main(int argc, char *argv[]) nftnl_expr_set(ex, NFTNL_EXPR_TG_INFO, strdup(data), sizeof(data)); nftnl_rule_add_expr(a, ex); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-flowtable-test.c b/tests/nft-flowtable-test.c index 8ab8d4c..49bc0a1 100644 --- a/tests/nft-flowtable-test.c +++ b/tests/nft-flowtable-test.c @@ -13,6 +13,23 @@ static void print_err(const char *msg) printf("\033[31mERROR:\e[0m %s\n", msg); } +static void cmp_devices(const char * const *adevs, + const char * const *bdevs) +{ + int i; + + if (!adevs && !bdevs) + return; + if (!!adevs ^ !!bdevs) + print_err("Flowtable devices mismatches"); + for (i = 0; adevs[i] && bdevs[i]; i++) { + if (strcmp(adevs[i], bdevs[i])) + break; + } + if (adevs[i] || bdevs[i]) + print_err("Flowtable devices mismatches"); +} + static void cmp_nftnl_flowtable(struct nftnl_flowtable *a, struct nftnl_flowtable *b) { if (strcmp(nftnl_flowtable_get_str(a, NFTNL_FLOWTABLE_NAME), @@ -44,10 +61,13 @@ static void cmp_nftnl_flowtable(struct nftnl_flowtable *a, struct nftnl_flowtabl if (nftnl_flowtable_get_u64(a, NFTNL_FLOWTABLE_HANDLE) != nftnl_flowtable_get_u64(b, NFTNL_FLOWTABLE_HANDLE)) print_err("Flowtable handle mismatches"); + cmp_devices(nftnl_flowtable_get_array(a, NFTNL_FLOWTABLE_DEVICES), + nftnl_flowtable_get_array(b, NFTNL_FLOWTABLE_DEVICES)); } int main(int argc, char *argv[]) { + const char *devs[] = { "eth0", "eth1", "eth2", NULL }; struct nftnl_flowtable *a, *b; char buf[4096]; struct nlmsghdr *nlh; @@ -66,6 +86,7 @@ int main(int argc, char *argv[]) nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_SIZE, 0x89016745); nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_FLAGS, 0x45016723); nftnl_flowtable_set_u64(a, NFTNL_FLOWTABLE_HANDLE, 0x2345016789); + nftnl_flowtable_set_array(a, NFTNL_FLOWTABLE_DEVICES, devs); nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWFLOWTABLE, AF_INET, 0, 1234); diff --git a/tests/nft-object-test.c b/tests/nft-object-test.c index d2ca444..77300e6 100644 --- a/tests/nft-object-test.c +++ b/tests/nft-object-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> diff --git a/tests/nft-rule-test.c b/tests/nft-rule-test.c index dee3530..d865d26 100644 --- a/tests/nft-rule-test.c +++ b/tests/nft-rule-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -48,6 +43,12 @@ static void cmp_nftnl_rule(struct nftnl_rule *a, struct nftnl_rule *b) if (nftnl_rule_get_u32(a, NFTNL_RULE_COMPAT_FLAGS) != nftnl_rule_get_u32(b, NFTNL_RULE_COMPAT_FLAGS)) print_err("Rule compat_flags mismatches"); + if (nftnl_rule_get_u32(a, NFTNL_RULE_ID) != + nftnl_rule_get_u32(b, NFTNL_RULE_ID)) + print_err("Rule id mismatches"); + if (nftnl_rule_get_u32(a, NFTNL_RULE_POSITION_ID) != + nftnl_rule_get_u32(b, NFTNL_RULE_POSITION_ID)) + print_err("Rule position_id mismatches"); if (nftnl_rule_get_u64(a, NFTNL_RULE_POSITION) != nftnl_rule_get_u64(b, NFTNL_RULE_POSITION)) print_err("Rule compat_position mismatches"); @@ -84,13 +85,15 @@ int main(int argc, char *argv[]) nftnl_rule_set_u64(a, NFTNL_RULE_HANDLE, 0x1234567812345678); nftnl_rule_set_u32(a, NFTNL_RULE_COMPAT_PROTO, 0x12345678); nftnl_rule_set_u32(a, NFTNL_RULE_COMPAT_FLAGS, 0x12345678); + nftnl_rule_set_u32(a, NFTNL_RULE_ID, 0x12345678); + nftnl_rule_set_u32(a, NFTNL_RULE_POSITION_ID, 0x12345678); nftnl_rule_set_u64(a, NFTNL_RULE_POSITION, 0x1234567812345678); nftnl_rule_set_data(a, NFTNL_RULE_USERDATA, nftnl_udata_buf_data(udata), nftnl_udata_buf_len(udata)); nftnl_udata_buf_free(udata); - nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234); nftnl_rule_nlmsg_build_payload(nlh, a); if (nftnl_rule_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-set-test.c b/tests/nft-set-test.c index 173c17f..1cb66e4 100644 --- a/tests/nft-set-test.c +++ b/tests/nft-set-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -26,6 +21,9 @@ static void print_err(const char *msg) static void cmp_nftnl_set(struct nftnl_set *a, struct nftnl_set *b) { + const uint8_t *data_a, *data_b; + uint32_t datalen_a, datalen_b; + if (strcmp(nftnl_set_get_str(a, NFTNL_SET_TABLE), nftnl_set_get_str(b, NFTNL_SET_TABLE)) != 0) print_err("Set table mismatches"); @@ -50,11 +48,18 @@ static void cmp_nftnl_set(struct nftnl_set *a, struct nftnl_set *b) if (strcmp(nftnl_set_get_str(a, NFTNL_SET_USERDATA), nftnl_set_get_str(b, NFTNL_SET_USERDATA)) != 0) print_err("Set userdata mismatches"); + + data_a = nftnl_set_get_data(a, NFTNL_SET_DESC_CONCAT, &datalen_a); + data_b = nftnl_set_get_data(b, NFTNL_SET_DESC_CONCAT, &datalen_b); + if (datalen_a != datalen_b || + memcmp(data_a, data_b, datalen_a)) + print_err("Set desc concat mismatches"); } int main(int argc, char *argv[]) { struct nftnl_set *a, *b = NULL; + uint8_t field_lengths[16]; char buf[4096]; struct nlmsghdr *nlh; @@ -73,8 +78,15 @@ int main(int argc, char *argv[]) nftnl_set_set_u32(a, NFTNL_SET_FAMILY, 0x12345678); nftnl_set_set_str(a, NFTNL_SET_USERDATA, "testing user data"); + memset(field_lengths, 0xff, sizeof(field_lengths)); + if (!nftnl_set_set_data(a, NFTNL_SET_DESC_CONCAT, field_lengths, 17)) + print_err("oversized NFTNL_SET_DESC_CONCAT data accepted"); + if (nftnl_set_set_data(a, NFTNL_SET_DESC_CONCAT, field_lengths, 16)) + print_err("setting NFTNL_SET_DESC_CONCAT failed"); + + /* cmd extracted from include/linux/netfilter/nf_tables.h */ - nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_NEWSET, AF_INET, 0, 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWSET, AF_INET, 0, 1234); nftnl_set_nlmsg_build_payload(nlh, a); if (nftnl_set_nlmsg_parse(nlh, b) < 0) diff --git a/tests/nft-table-test.c b/tests/nft-table-test.c index 1031ffe..79e10ef 100644 --- a/tests/nft-table-test.c +++ b/tests/nft-table-test.c @@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2013 by Ana Rey Botello <anarey@gmail.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * */ #include <stdio.h> @@ -34,7 +29,7 @@ static void cmp_nftnl_table(struct nftnl_table *a, struct nftnl_table *b) print_err("table flags mismatches"); if (nftnl_table_get_u32(a, NFTNL_TABLE_FAMILY) != nftnl_table_get_u32(b, NFTNL_TABLE_FAMILY)) - print_err("tabke family mismatches"); + print_err("table family mismatches"); } int main(int argc, char *argv[]) @@ -55,8 +50,7 @@ int main(int argc, char *argv[]) nftnl_table_set_u32(a, NFTNL_TABLE_FLAGS, 0); /* cmd extracted from include/linux/netfilter/nf_tables.h */ - nlh = nftnl_table_nlmsg_build_hdr(buf, NFT_MSG_NEWTABLE, AF_INET, 0, - 1234); + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWTABLE, AF_INET, 0, 1234); nftnl_table_nlmsg_build_payload(nlh, a); if (nftnl_table_nlmsg_parse(nlh, b) < 0) |