summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2013-10-22 14:35:02 +0200
committerFlorian Westphal <fw@strlen.de>2013-10-22 15:06:08 +0200
commita57def11266077a3354d4edff8e6b8a0b7b499b3 (patch)
tree1e03e025c7712a569b4eed5129cf3eea51c5b52f
parentb259d1aca0db1bed5af3e4fe378f8aeb4d3ce645 (diff)
statement: avoid huge rodata array
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>
-rw-r--r--src/statement.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/statement.c b/src/statement.c
index 658dc5ff..d18e0340 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 "second";
+ 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 = {