Skip to contentSkip to conversation

statement: avoid huge rodata array

PATCH Applied Florian Westphal 2 participants 4 messages Oct 22, 2013 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 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
index 658dc5f..f201919 100644
@@ -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
author maintainer Applied
#1 lore raw
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.

#2 lore raw
Quoted 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!