From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: Elise Lennion <elise.lennion@gmail.com>, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft v3 2/2] datatype: Implement binary search in symbolic_constant_print()
Date: Tue, 29 Nov 2016 09:35:48 +0100 [thread overview]
Message-ID: <20161129083548.GA973@salvia> (raw)
In-Reply-To: <20161128221223.GB9858@breakpoint.cc>
On Mon, Nov 28, 2016 at 11:12:23PM +0100, Florian Westphal wrote:
> Elise Lennion <elise.lennion@gmail.com> wrote:
> > Because a linear search is used, which is slower.
> >
> > This approach demands that the symbol_table have a variable with its
> > size, also, it must be sorted by value.
>
> Did Pablo put you up to this? Bad Pablo, bad! :-P
Yep, Elise don't feel bad, that's my fault ;-)
> because:
>
> > static const struct symbol_table ethertype_tbl = {
> > + .size = 4,
> > .symbols = {
> > SYMBOL("ip", __constant_htons(ETH_P_IP)),
> > + SYMBOL("vlan", __constant_htons(ETH_P_8021Q)),
> > SYMBOL("arp", __constant_htons(ETH_P_ARP)),
> > SYMBOL("ip6", __constant_htons(ETH_P_IPV6)),
> > - SYMBOL("vlan", __constant_htons(ETH_P_8021Q)),
> > SYMBOL_LIST_END
> > },
>
> This is unmaintanable. I have no clue what value ETH_P_8021Q is, and that
> this has to be placed at spot #2 to not break things.
OK, let's try to make this a bit more maintainable, another proposal
in steps:
1) Update symbol_table definition to:
struct symbol_table {
unsignd int size;
const struct symbolic_constant *symbols; <---
};
so we don't have a flexible array anymore. Then, split this array of
symbols from struct symbol_table so this looks like:
static cont struct symbolic_constant ethertype_symbols[] = {
SYMBOL("ip", __constant_htons(ETH_P_IP)),
SYMBOL("vlan", __constant_htons(ETH_P_8021Q)),
SYMBOL("arp", __constant_htons(ETH_P_ARP)),
SYMBOL("ip6", __constant_htons(ETH_P_IPV6)),
SYMBOL_LIST_END
};
static const struct symbol_table ethertype_tbl = {
.size = SYMTBL_SIZE(ethertype_symbols),
.symbolic_constant = ethertype_symbols,
};
I can see 19 symbol_tables from here at quick glace, so this would be
an initial patch to update this. SYMTBL_SIZE needs to be define too, yes.
2) Then, second patch would look like:
struct symbol_table {
unsignd int size;
bool qsort; <---
const struct symbolic_constant *symbols;
};
If qsort field if true, then we can just validate when calling
datatype_register() that the array is not sorted and spot a BUG().
Moreover, the new qsort field would restrict this qsort to the large
inet_service symbol table.
Florian, are you OK if Elise follows this approach? If this is overly
complicated and not worth, rise your hand.
next prev parent reply other threads:[~2016-11-29 8:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-28 20:23 [PATCH nft v3 2/2] datatype: Implement binary search in symbolic_constant_print() Elise Lennion
2016-11-28 22:12 ` Florian Westphal
2016-11-29 8:35 ` Pablo Neira Ayuso [this message]
2016-11-29 10:04 ` Florian Westphal
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=20161129083548.GA973@salvia \
--to=pablo@netfilter.org \
--cc=elise.lennion@gmail.com \
--cc=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.