scanner: fix reading of really long line

Current code is causing a failure in adding a set containing
a really long list of elements. The failure occurs as soon as
the line is longer than flex read buffer.

When a line is longer than scanner buffer size, the code in YY_INPUT
forces a rewind to the beginning of the string because it does not
find a end of line. The result is that the string is never parsed.

This patch updates the code by rewinding till we found a space.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
netlink_delinearize: clone on netlink_get_register(), release previous on _set()

If we add this rule:

  nft add rule filter input meta length 33-55

the listing shows:

  meta length >= 33 meta length <= 754974720

The two meta statements share the same left-hand side, thus, only the
first one is converted from network byte order to host byte order.

Update netlink_get_register() to return a clone so each left-hand side
has its own left-hand side.

Moreover, release the existing register before overriding it with fresh
expressions in netlink_set_register().

Thefore, if you manipulate a register from any of the existing parse
functions, you have to re-set it again to place fresh modified clone.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
meta: set base field on clones

Set missing field on meta expression clone.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests: regression: fix "Listing is broken" instead of output mismatch

If the output string doesn't match the input, indicate that the output
mismatches instead of the misleading "Listing is broken".

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests: regression: any/ct: remove wrong output

ct mark 0x32-0x45

displays:

ct mark >= 0x00000032 ct mark <= 0x00000045
                                 ^^^^^^^^^^
instead of ct mark <= 0x45000000
                      ^^^^^^^^^^

Remove the custom output so this displays a warning. nft should
(at some point) merge the two statements into one single to express
the range from the netlink_delinearize step.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
scanner: don't bug on too large values

Add a new ERROR symbol to handle scanning of too large values.

 <cmdline>:1:36-99: Error: bad value '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
 add rule ip test-ip4 input ct mark 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
instead of:

 BUG: nft: scanner.l:470: nft_lex: Assertion `0' failed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
datatype: fix name of icmp* code

The name of datatypes can be used in set definition so they should
follow the same logic (and maybe not contain space to avoid problem
with parsing).

This patch adds an underscore to the name of the icmp* code
datatype.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>