* [PATCH nft] statement: avoid huge rodata array
@ 2013-10-22 12:35 Florian Westphal
2013-10-22 13:12 ` Florian Westphal
2013-10-22 13:15 ` Pablo Neira Ayuso
0 siblings, 2 replies; 4+ messages in thread
From: Florian Westphal @ 2013-10-22 12:35 UTC (permalink / raw)
To: netfilter-devel; +Cc: 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.
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH nft] statement: avoid huge rodata array
2013-10-22 12:35 [PATCH nft] statement: avoid huge rodata array Florian Westphal
@ 2013-10-22 13:12 ` Florian Westphal
2013-10-22 13:18 ` Pablo Neira Ayuso
2013-10-22 13:15 ` Pablo Neira Ayuso
1 sibling, 1 reply; 4+ messages in thread
From: Florian Westphal @ 2013-10-22 13:12 UTC (permalink / raw)
To: netfilter-devel
Florian Westphal <fw@strlen.de> wrote:
> 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,
> +static const char *get_unit(uint64_t u)
> +{
> + switch (u) {
> + case 1: return "seconds";
... after changing this to 'second', spotted by Phil Oester.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH nft] statement: avoid huge rodata array
2013-10-22 12:35 [PATCH nft] statement: avoid huge rodata array Florian Westphal
2013-10-22 13:12 ` Florian Westphal
@ 2013-10-22 13:15 ` Pablo Neira Ayuso
1 sibling, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2013-10-22 13:15 UTC (permalink / raw)
To: Florian Westphal; +Cc: netfilter-devel
On Tue, Oct 22, 2013 at 02:35:02PM +0200, Florian Westphal wrote:
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH nft] statement: avoid huge rodata array
2013-10-22 13:12 ` Florian Westphal
@ 2013-10-22 13:18 ` Pablo Neira Ayuso
0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2013-10-22 13:18 UTC (permalink / raw)
To: Florian Westphal; +Cc: netfilter-devel
On Tue, Oct 22, 2013 at 03:12:41PM +0200, Florian Westphal wrote:
> Florian Westphal <fw@strlen.de> wrote:
> > 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,
>
> > +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!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-10-22 13:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-22 12:35 [PATCH nft] statement: avoid huge rodata array Florian Westphal
2013-10-22 13:12 ` Florian Westphal
2013-10-22 13:18 ` Pablo Neira Ayuso
2013-10-22 13:15 ` Pablo Neira Ayuso
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).