From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: kaber@trash.net
Subject: [PATCH 2/7] src: add assertion infrastructure to validate attribute types
Date: Wed, 26 Feb 2014 02:51:54 +0100 [thread overview]
Message-ID: <1393379519-16189-3-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1393379519-16189-1-git-send-email-pablo@netfilter.org>
This will be used to validate that the size is correct according
to the expected attribute size.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/internal.h | 13 +++++++++++++
src/utils.c | 7 +++++++
2 files changed, 20 insertions(+)
diff --git a/src/internal.h b/src/internal.h
index a3fc46f..3216bc6 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -187,4 +187,17 @@ struct nft_set_elem {
#define __init __attribute__((constructor))
+void __nft_assert_fail(uint16_t attr, const char *filename, int line);
+
+#define nft_assert(attr, expr) \
+ ((expr) \
+ ? (void)0 \
+ : __nft_assert_fail(attr, __FILE__, __LINE__))
+
+#define nft_assert_validate(_validate_array, _attr, _data_len) \
+({ \
+ if (_validate_array[_attr]) \
+ nft_assert(attr, _validate_array[_attr] == _data_len); \
+})
+
#endif
diff --git a/src/utils.c b/src/utils.c
index 9691c4c..18917f5 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -211,3 +211,10 @@ int nft_fprintf(FILE *fp, void *obj, uint32_t type, uint32_t flags,
return ret;
}
+
+void __nft_assert_fail(uint16_t attr, const char *filename, int line)
+{
+ fprintf(stderr, "libnftnl: attribute %d assertion failed in %s:%d\n",
+ attr, filename, line);
+ exit(EXIT_FAILURE);
+}
--
1.7.10.4
next prev parent reply other threads:[~2014-02-26 1:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-26 1:51 [PATCH 0/7] libnftnl updates Pablo Neira Ayuso
2014-02-26 1:51 ` [PATCH 1/7] src: early attribute type validation in nft_*_attr_set Pablo Neira Ayuso
2014-02-26 1:51 ` Pablo Neira Ayuso [this message]
2014-02-26 1:51 ` [PATCH 3/7] src: add nft_*_attr_{set|get}_data interface Pablo Neira Ayuso
2014-02-26 1:51 ` [PATCH 4/7] src: fix wrong type in NFT_ATTR_*_FAMILY Pablo Neira Ayuso
2014-02-26 1:51 ` [PATCH 5/7] include: get linux/netfilter/nf_tables.h in sync with kernel header Pablo Neira Ayuso
2014-02-26 1:51 ` [PATCH 6/7] example: nft-rule-add: simplify example Pablo Neira Ayuso
2014-02-26 1:51 ` [PATCH 7/7] rule: add NFT_RULE_ATTR_USERDATA support Pablo Neira Ayuso
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=1393379519-16189-3-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).