From: Florian Westphal <fw@strlen.de>
To: netfilter-devel@vger.kernel.org
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft] statement: avoid huge rodata array
Date: Tue, 22 Oct 2013 14:35:02 +0200 [thread overview]
Message-ID: <1382445302-8050-1-git-send-email-fw@strlen.de> (raw)
commit b259d1a ('src: operational limit match') creates huge
array, increasing nft binary size from ~240k to ~5m on x86_64.
Use switch statement instead.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/statement.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/statement.c b/src/statement.c
index 658dc5f..f201919 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -142,18 +142,23 @@ struct stmt *log_stmt_alloc(const struct location *loc)
return stmt_alloc(loc, &log_stmt_ops);
}
+static const char *get_unit(uint64_t u)
+{
+ switch (u) {
+ case 1: return "seconds";
+ case 60: return "minute";
+ case 60 * 60: return "hour";
+ case 60 * 60 * 24: return "day";
+ case 60 * 60 * 24 * 7: return "week";
+ }
+
+ return "error";
+}
+
static void limit_stmt_print(const struct stmt *stmt)
{
- static const char *units[] = {
- [1] = "second",
- [1 * 60] = "minute",
- [1 * 60 * 60] = "hour",
- [1 * 60 * 60 * 24] = "day",
- [1 * 60 * 60 * 24 * 7] = "week",
- };
-
printf("limit rate %" PRIu64 "/%s",
- stmt->limit.rate, units[stmt->limit.unit]);
+ stmt->limit.rate, get_unit(stmt->limit.unit));
}
static const struct stmt_ops limit_stmt_ops = {
--
1.8.1.5
next reply other threads:[~2013-10-22 12:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-22 12:35 Florian Westphal [this message]
2013-10-22 13:12 ` [PATCH nft] statement: avoid huge rodata array Florian Westphal
2013-10-22 13:18 ` Pablo Neira Ayuso
2013-10-22 13:15 ` 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=1382445302-8050-1-git-send-email-fw@strlen.de \
--to=fw@strlen.de \
--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 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.