statement: avoid huge rodata array
Florian Westphal
maintainerPATCH 1/1 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.
--- src/statement.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
src/statement.c +14 -9
@@ -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 = {
Signature · 1 line
1.8.1.5
Quoted 4 lines · Florian Westphal
commit b259d1a ('src: operational limit match') creates huge array, increasing nft binary size from ~240k to ~5m on
x86_64.Use switch statement instead.
Applied,
src/statement.c struct stmt *log_stmt_alloc(const struct location *loc) · line 148
Quoted 4 lines
src/statement.c +4
-0+static const char *get_unit (uint64_t u) +{ +switch (u) { +case 1 :return "seconds" ;
... after changing this to 'second', spotted by Phil Oester.
Pablo Neira Ayuso
maintainerQuoted 6 lines · Florian Westphal
Quoted 4 lines · Florian Westphal
commit b259d1a ('src: operational limit match') creates huge array, increasing nft binary size from ~240k to ~5m on
x86_64.Use switch statement instead.
Quoted 8 lines
Applied,
src/statement.c struct stmt *log_stmt_alloc(const struct location *loc) · line 148
Quoted 4 lines
src/statement.c +4
-0+static const char *get_unit (uint64_t u) +{ +switch (u) { +case 1 :return "seconds" ;... after changing this to 'second', spotted by Phil Oester.
Please, push a patch to change libnftables to 'second'. Thanks!
Pablo Neira Ayuso
maintainerQuoted 4 lines · Florian Westphal
commit b259d1a ('src: operational limit match') creates huge array, increasing nft binary size from ~240k to ~5m on
x86_64.Use switch statement instead.
Thanks Florian.
Applied a similar patch for libnftables:
http://git.netfilter.org/libnftables/commit/?id=cc9d2851135901d11e21b1a0332e83119124d083