From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [libnftnl PATCH 2/3] tests: Extend set test by NFTNL_SET_DESC_CONCAT
Date: Wed, 27 Nov 2024 19:01:02 +0100 [thread overview]
Message-ID: <20241127180103.15076-2-phil@nwl.cc> (raw)
In-Reply-To: <20241127180103.15076-1-phil@nwl.cc>
Just to cover setter and getter code for that attribute.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
tests/nft-set-test.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tests/nft-set-test.c b/tests/nft-set-test.c
index e264c735a2de6..1cb66e4a3ea64 100644
--- a/tests/nft-set-test.c
+++ b/tests/nft-set-test.c
@@ -21,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");
@@ -45,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;
@@ -68,6 +78,13 @@ 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_nlmsg_build_hdr(buf, NFT_MSG_NEWSET, AF_INET, 0, 1234);
nftnl_set_nlmsg_build_payload(nlh, a);
--
2.47.0
next prev parent reply other threads:[~2024-11-27 18:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-27 18:01 [libnftnl PATCH 1/3] set: Fix for array overrun when setting NFTNL_SET_DESC_CONCAT Phil Sutter
2024-11-27 18:01 ` Phil Sutter [this message]
2024-11-27 18:01 ` [libnftnl PATCH 3/3] tests: Fix for ASAN Phil Sutter
2024-12-04 14:30 ` [libnftnl PATCH 1/3] set: Fix for array overrun when setting NFTNL_SET_DESC_CONCAT Pablo Neira Ayuso
2024-12-04 14:45 ` Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241127180103.15076-2-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.