summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* datatype: Initialize rt_symbol_tables' base fieldPhil Sutter2024-01-021-4/+8
| | | | | | | | | It is unconditionally accessed in symbol_table_print() so make sure it is initialized to either BASE_DECIMAL (arbitrary) for empty or non-existent source files or a proper value depending on entry number format. Signed-off-by: Phil Sutter <phil@nwl.cc>
* datatype: rt_symbol_table_init() to search for iproute2 configsPhil Sutter2024-01-023-6/+36
| | | | | | | | | | | | | | | | | | | There is an ongoing effort among various distributions to tidy up in /etc. The idea is to reduce contents to just what the admin manually inserted to customize the system, anything else shall move out to /usr (or so). The various files in /etc/iproute2 fall in that category as they are seldomly modified. The crux is though that iproute2 project seems not quite sure yet where the files should go. While v6.6.0 installs them into /usr/lib/iproute2, current mast^Wmain branch uses /usr/share/iproute2. Assume this is going to stay as /(usr/)lib does not seem right for such files. Note that rt_symbol_table_init() is not just used for iproute2-maintained configs but also for connlabel.conf - so retain the old behaviour when passed an absolute path. Signed-off-by: Phil Sutter <phil@nwl.cc>
* parser_bison: ensure all timeout policy names are releasedFlorian Westphal2023-12-221-5/+27
| | | | | | | | | | | | | | | | | | | We need to add a custom destructor for this structure, it contains the dynamically allocated names. a:5:55-55: Error: syntax error, unexpected '}', expecting string policy = { estabQisheestablished : 2m3s, cd : 2m3s, } ==562373==ERROR: LeakSanitizer: detected memory leaks Indirect leak of 160 byte(s) in 2 object(s) allocated from: #1 0x5a565b in xmalloc src/utils.c:31:8 #2 0x5a565b in xzalloc src/utils.c:70:8 #3 0x3d9352 in nft_parse_bison_filename src/libnftables.c:520:8 [..] Fixes: c7c94802679c ("src: add ct timeout support") Signed-off-by: Florian Westphal <fw@strlen.de>
* src: do not allow to chain more than 16 binopsFlorian Westphal2023-12-222-4/+42
| | | | | | | | | | | | | | | | | | | | | netlink_linearize.c has never supported more than 16 chained binops. Adding more is possible but overwrites the stack in netlink_gen_bitwise(). Add a recursion counter to catch this at eval stage. Its not enough to just abort once the counter hits NFT_MAX_EXPR_RECURSION. This is because there are valid test cases that exceed this. For example, evaluation of 1 | 2 will merge the constans, so even if there are a dozen recursive eval calls this will not end up with large binop chain post-evaluation. v2: allow more than 16 binops iff the evaluation function did constant-merging. Signed-off-by: Florian Westphal <fw@strlen.de>
* netlink: fix stack overflow due to erroneous roundingFlorian Westphal2023-12-201-3/+8
| | | | | | | Byteorder switch in this function may undersize the conversion buffer by one byte, this needs to use div_round_up(). Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: don't crash if object map does not refer to a valueFlorian Westphal2023-12-201-0/+5
| | | | | | | | | | | Before: BUG: Value export of 512 bytes would overflownft: src/netlink.c:474: netlink_gen_prefix: Assertion `0' failed. After: 66: Error: Object mapping data should be a value, not prefix synproxy name ip saddr map { 192.168.1.0/24 : "v*" } Signed-off-by: Florian Westphal <fw@strlen.de>
* parser_bison: error out on duplicated type/typeof/element keywordsFlorian Westphal2023-12-191-2/+36
| | | | | | | | | | | Otherwise nft will leak the previous definition (expressions). Also remove the nonsensical datatype_set($1->key, $3->dtype); This is a no-op, at this point: $1->key and $3 are identical. Signed-off-by: Florian Westphal <fw@strlen.de>
* intervals: BUG on prefix expressions without valueFlorian Westphal2023-12-191-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Its possible to end up with prefix expressions that have a symbolic expression, e.g.: table t { set s { type inet_service flags interval elements = { 172.16.0.0/16 } } set s { type inet_service flags interval elements = { 0-1024, 8080-8082, 10000-40000 } } } Without this change, nft will crash. We end up in setelem_expr_to_range() with prefix "/16" for the symbolic expression "172.16.0.0". We than pass invalid mpz_t pointer into libgmp. This isn't a real fix, but instead of blindly assuming that the attached expression has a gmp value die with at least some info. Signed-off-by: Florian Westphal <fw@strlen.de>
* tcpopt: don't create exthdr expression without datatypeFlorian Westphal2023-12-191-1/+1
| | | | | | | | | | | | | The reproducer crashes during concat evaluation, as the exthdr expression lacks a datatype. This should never happen, i->dtype must be set. In this case the culprit is tcp option parsing, it will wire up a non-existent template, because the "nop" option has no length field (1 byte only). Signed-off-by: Florian Westphal <fw@strlen.de>
* intervals: set_to_range can be staticFlorian Westphal2023-12-161-1/+3
| | | | Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: fix stack overflow with huge priority stringFlorian Westphal2023-12-151-1/+1
| | | | | | | | Alternative would be to refactor this and move this into the parsers (bison, json) instead of this hidden re-parsing. Fixes: 627c451b2351 ("src: allow variables in the chain priority specification") Signed-off-by: Florian Westphal <fw@strlen.de>
* netlink: fix stack buffer overflow with sub-reg sized prefixesFlorian Westphal2023-12-151-2/+5
| | | | | | | | | | | | | | | | | | | | | | | The calculation of the dynamic on-stack array is incorrect, the scratch space can be too low which gives stack corruption: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffdb454f064.. #1 0x7fabe92aaac4 in __mpz_export_data src/gmputil.c:108 #2 0x7fabe92d71b1 in netlink_export_pad src/netlink.c:251 #3 0x7fabe92d91d8 in netlink_gen_prefix src/netlink.c:476 div_round_up() cannot be used here, it fails to account for register padding. A 16 bit prefix will need 2 registers (start, end -- 8 bytes in total). Remove the dynamic sizing and add an assertion in case upperlayer ever passes invalid expr sizes down to us. After this fix, the combination is rejected by the kernel because of the maps' wrong data size, before the fix userspace may crash before. Signed-off-by: Florian Westphal <fw@strlen.de>
* src: reject large raw payload and concat expressionsFlorian Westphal2023-12-152-0/+15
| | | | | | | | | | | | | | | | | | The kernel will reject this too, but unfortunately nft may try to cram the data into the underlying libnftnl expr. This causes heap corruption or BUG: nld buffer overflow: want to copy 132, max 64 After: Error: Concatenation of size 544 exceeds maximum size of 512 udp length . @th,0,512 . @th,512,512 { 47-63 . 0xe373135363130 . 0x33131303735353203 } ^^^^^^^^^ resp. same warning for an over-sized raw expression. Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: exthdr: statement arg must be not be a rangeFlorian Westphal2023-12-141-3/+16
| | | | | | | | Else we get: BUG: unknown expression type range nft: src/netlink_linearize.c:909: netlink_gen_expr: Assertion `0' failed. Signed-off-by: Florian Westphal <fw@strlen.de>
* netlink: don't crash if prefix for < byte is requestedFlorian Westphal2023-12-141-1/+2
| | | | | | | | | | | | | | If prefix is used with a datatype that has less than 8 bits an assertion is triggered: src/netlink.c:243: netlink_gen_raw_data: Assertion `len > 0' failed. This is esoteric, the alternative would be to restrict prefixes to ipv4/ipv6 addresses. Simpler fix is to use round_up instead of divide. Signed-off-by: Florian Westphal <fw@strlen.de>
* Revert "evaluate: error out when existing set has incompatible key"Florian Westphal2023-12-141-3/+0
| | | | | | | | | | This breaks existing behaviour, add a test case so this is caught in the future. The reverted test case will be brought back once a better fix is available. Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: fix gmp assertion with too-large reject codeFlorian Westphal2023-12-141-0/+7
| | | | | | | | Before: nft: gmputil.c:77: mpz_get_uint8: Assertion `cnt <= 1' failed. After: Error: reject code must be integer in range 0-255 Signed-off-by: Florian Westphal <fw@strlen.de>
* meta: fix tc classid parsing out-of-bounds accessFlorian Westphal2023-12-131-20/+9
| | | | | | | | | | | | | | | | | AddressSanitizer: heap-buffer-overflow on address 0x6020000003af ... #0 0x7f9a83cbb402 in tchandle_type_parse src/meta.c:89 #1 0x7f9a83c6753f in symbol_parse src/datatype.c:138 strlen() - 1 can underflow if length was 0. Simplify the function, there is no need to duplicate the string while scanning it. Expect the first strtol to stop at ':', scan for the minor number next. The second scan is required to stop at '\0'. Fixes: 6f2eb8548e0d ("src: meta priority support using tc classid") Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: error out when existing set has incompatible keyFlorian Westphal2023-12-131-0/+3
| | | | | | | | | | | | | | Before: BUG: invalid range expression type symbol nft: expression.c:1494: range_expr_value_high: Assertion `0' failed. After: range_expr_value_high_assert:5:20-27: Error: Could not resolve protocol name elements = { 100-11.0.0.0, } ^^^^^^^^ range_expr_value_high_assert:7:6-7: Error: set definition has conflicting key (ipv4_addr vs inet_proto) Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: stmt_nat: set reference must point to a mapFlorian Westphal2023-12-131-0/+9
| | | | | | | | | | nat_concat_map() requires a datamap, else we crash: set->data is dereferenced. Also update expr_evaluate_map() so that EXPR_SET_REF is checked there too. Signed-off-by: Florian Westphal <fw@strlen.de>
* parser_bison: fix memory leaks on hookspec error processingFlorian Westphal2023-12-131-0/+7
| | | | | | | prio_spec may contain an embedded expression, release it. We also need to release the device expr and the hook string. Signed-off-by: Florian Westphal <fw@strlen.de>
* parser_bison: close chain scope before chain releaseFlorian Westphal2023-12-131-0/+1
| | | | | | | | | | | | | | | | cmd_alloc() will free the chain, so we must close the scope opened in chain_block_alloc beforehand. The included test file will cause a use-after-free because nft attempts to search for an identifier in a scope that has been freed: AddressSanitizer: heap-use-after-free on address 0x618000000368 at pc 0x7f1cbc0e6959 bp 0x7ffd3ccb7850 sp 0x7ffd3ccb7840 #0 0x7f1cbc0e6958 in symbol_lookup src/rule.c:629 #1 0x7f1cbc0e66a1 in symbol_get src/rule.c:588 #2 0x7f1cbc120d67 in nft_parse src/parser_bison.y:4325 Fixes: a66b5ad9540d ("src: allow for updating devices on existing netdev chain") Signed-off-by: Florian Westphal <fw@strlen.de>
* parser_bison: fix ct scope underflow if ct helper section is duplicatedFlorian Westphal2023-12-121-4/+11
| | | | | | | | | | | | | | | | | | | | | table inet filter { ct helper sip-5060u { type "sip" protocol udp l3proto ip }5060t { type "sip" protocol tcp l3pownerip } Will close the 'ct' scope twice, it has to be closed AFTER the separator has been parsed. While not strictly needed, also error out if the protocol is already given, this provides a better error description. Also make sure we release the string in all error branches. Signed-off-by: Florian Westphal <fw@strlen.de>
* parser_bison: make sure obj_free releases timeout policiesFlorian Westphal2023-12-121-0/+1
| | | | | | | | | obj_free() won't release them because ->type is still 0 at this point. Init this to CT_TIMEOUT. Signed-off-by: Florian Westphal <fw@strlen.de>
* netlink_linearize: avoid strict-overflow warning in netlink_gen_bitwise()Thomas Haller2023-12-121-4/+3
| | | | | | | | | | | | | | | | | | With gcc-13.2.1-1.fc38.x86_64: $ gcc -Iinclude -c -o tmp.o src/netlink_linearize.c -Werror -Wstrict-overflow=5 -O3 src/netlink_linearize.c: In function ‘netlink_gen_bitwise’: src/netlink_linearize.c:1790:1: error: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C2 -+ C1 [-Werror=strict-overflow] 1790 | } | ^ cc1: all warnings being treated as errors It also makes more sense this way, where "n" is the hight of the "binops" stack, and we check for a non-empty stack with "n > 0" and pop the last element with "binops[--n]". Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: fix bogus assertion failure with boolean datatypeFlorian Westphal2023-12-121-3/+4
| | | | | | | | | | | | The assertion is too strict, as found by afl++: typeof iifname . ip saddr . meta ipsec elements = { "eth0" . 10.1.1.2 . 1 } meta ipsec is boolean (1 bit), but datasize of 1 is set at 8 bit. Fixes: 22b750aa6dc9 ("src: allow use of base integer types as set keys in concatenations") Signed-off-by: Florian Westphal <fw@strlen.de>
* netlink: add and use nft_data_memcpy helperFlorian Westphal2023-12-121-10/+15
| | | | | | | | | | | | | | | | | | | | | | | There is a stack overflow somewhere in this code, we end up memcpy'ing a way too large expr into a fixed-size on-stack buffer. This is hard to diagnose, most of this code gets inlined so the crash happens later on return from alloc_nftnl_setelem. Condense the mempy into a helper and add a BUG so we can catch the overflow before it occurs. ->value is too small (4, should be 16), but for normal cases (well-formed data must fit into max reg space, i.e. 64 byte) the chain buffer that comes after value in the structure provides a cushion. In order to have the new BUG() not trigger on valid data, bump value to the correct size, this is userspace so the additional 60 bytes of stack usage is no concern. Signed-off-by: Florian Westphal <fw@strlen.de>
* parser_bison: fix memleak in meta set error handlingFlorian Westphal2023-12-111-0/+1
| | | | | | | We must release the expression here, found via afl++ and -fsanitize-address build. Signed-off-by: Florian Westphal <fw@strlen.de>
* parser_bison: fix objref statement corruptionFlorian Westphal2023-12-111-37/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider this: counter_stmt : counter_stmt_alloc | counter_stmt_alloc counter_args counter_stmt_alloc : COUNTER { $$ = counter_stmt_alloc(&@$); } | COUNTER NAME stmt_expr { $$ = objref_stmt_alloc(&@$); $$->objref.type = NFT_OBJECT_COUNTER; $$->objref.expr = $3; } ; counter_args : counter_arg { $<stmt>$ = $<stmt>0; } | counter_args counter_arg ; counter_arg : PACKETS NUM { $<stmt>0->counter.packets = $2; } [..] This has 'counter_stmt_alloc' EITHER return counter or objref statement. Both are the same structure but with different (union'd) trailer content. counter_stmt permits the 'packet' and 'byte' argument. But the 'counter_arg' directive only works with a statement coming from counter_stmt_alloc(). afl++ came up with following input: table inet x { chain y { counter name ip saddr bytes 1.1.1. 1024 } } This clobbers $<stmt>->objref.expr pointer, we then crash when calling expr_evaluate() on it. Split the objref related statements into their own directive. After this, the input will fail with: "syntax error, unexpected bytes, expecting newline or semicolon". Also split most of the other objref statements into their own blocks. synproxy seems to have same problem, limit and quota appeared to be ok. v1 added objref_stmt to stateful_stmt list, this is wrong, we will assert when generating the 'counter' statement. Place it in the normal statement list so netlink_gen_stmt_stateful_assert throws the expected parser error. Fixes: dccab4f646b4 ("parser_bison: consolidate stmt_expr rule") Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: validate chain max lengthFlorian Westphal2023-12-111-1/+33
| | | | | | | | | The includes test files cause: BUG: chain is too large (257, 256 max)nft: netlink.c:418: netlink_gen_chain: Assertion `0' failed. Error out in evaluation step instead. Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: reset statement length context before evaluating statementPablo Neira Ayuso2023-12-082-30/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch consolidates ctx->stmt_len reset in stmt_evaluate() to avoid this problem. Note that stmt_evaluate_meta() and stmt_evaluate_ct() already reset it after the statement evaluation. Moreover, statement dependency can be generated while evaluating a meta and ct statement. Payload statement dependency already manually stashes this before calling stmt_evaluate(). Add a new stmt_dependency_evaluate() function to stash statement length context when evaluating a new statement dependency and use it for all of the existing statement dependencies. Florian also says: 'meta mark set vlan id map { 1 : 0x00000001, 4095 : 0x00004095 }' will crash. Reason is that the l2 dependency generated here is errounously expanded to a 32bit-one, so the evaluation path won't recognize this as a L2 dependency. Therefore, pctx->stacked_ll_count is 0 and __expr_evaluate_payload() crashes with a null deref when dereferencing pctx->stacked_ll[0]. nft-test.py gains a fugly hack to tolerate '!map typeof vlan id : meta mark'. For more generic support we should find something more acceptable, e.g. !map typeof( everything here is a key or data ) timeout ... tests/py update and assert(pctx->stacked_ll_count) by Florian Westphal. Fixes: edecd58755a8 ("evaluate: support shifts larger than the width of the left operand") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Florian Westphal <fw@strlen.de>
* parser: tcpopt: fix tcp option parsing with NUM + length fieldFlorian Westphal2023-12-062-10/+38
| | | | | | | | | | | | | | | | | | | | | | tcp option 254 length ge 4 ... will segfault. The crash bug is that tcpopt_expr_alloc() can return NULL if we cannot find a suitable template for the requested kind + field combination, so add the needed error handling in the bison parser. However, we can handle this. NOP and EOL have templates, all other options (known or unknown) must also have a length field. So also add a fallback template to handle both kind and length, even if only a numeric option is given that nft doesn't recognize. Don't bother with output, above will be printed via raw syntax, i.e. tcp option @254,8,8 >= 4. Fixes: 24d8da308342 ("tcpopt: allow to check for presence of any tcp option") Reported-by: Maciej Żenczykowski <zenczykowski@gmail.com> Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: reject set definition with no keyPablo Neira Ayuso2023-12-061-2/+6
| | | | | | | | | | | | tests/shell/testcases/bogons/nft-f/set_definition_with_no_key_assert BUG: unhandled key type 2 nft: src/intervals.c:59: setelem_expr_to_range: Assertion `0' failed. This patch adds a new unit tests/shell courtesy of Florian Westphal. Fixes: 3975430b12d9 ("src: expand table command before evaluation") Reported-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* monitor: add support for concatenated set rangesPablo Neira Ayuso2023-12-061-2/+9
| | | | | | | monitor is missing concatenated set ranges support. Fixes: 8ac2f3b2fca3 ("src: Add support for concatenated set ranges") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* evaluate: fix double free on dtype releaseFlorian Westphal2023-12-051-1/+1
| | | | | | | We release ->dtype twice, will either segfault or assert on dtype->refcount != 0 check in datatype_free(). Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: catch implicit map expressions without known datatypeFlorian Westphal2023-12-051-0/+4
| | | | | | | | mapping_With_invalid_datatype_crash:1:8-65: Error: Implicit map expression without known datatype bla to tcp dport map { 80 : 1.1.1.1 . 8001, 81 : 2.2.2.2 . 9001 } bla ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: reject attempt to update a setFlorian Westphal2023-12-051-0/+4
| | | | | | | | | | | This will crash as set->data is NULL, so check that SET_REF is pointing to a map: Error: candidates_ipv4 is not a map tcp dport 10003 ip saddr . tcp dport @candidates_ipv4 add @candidates_ipv4 { ip saddr . 10 :0004 timeout 1s } ~~~~~~~~~~~~~~~~ Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: disable meta set with rangesFlorian Westphal2023-12-051-0/+13
| | | | | | | | | | | | | | | | ... this will cause an assertion in netlink linearization, catch this at eval stage instead. before: BUG: unknown expression type range nft: netlink_linearize.c:908: netlink_gen_expr: Assertion `0' failed. after: /unknown_expr_type_range_assert:3:31-40: Error: Meta expression cannot be a range meta mark set 0x001-3434 ^^^^^^^^^^ Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: error out if basetypes are differentFlorian Westphal2023-12-051-2/+5
| | | | | | | | | | prefer binop_with_different_basetype_assert:3:29-35: Error: Binary operation (<<) with different base types (string vs integer) is not supported oifname set ip9dscp << 26 | 0x10 ^^^^^^^~~~~~~ to assertion failure. Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: guard against NULL basetypeFlorian Westphal2023-12-051-1/+1
| | | | | | i->dtype->basetype can be NULL. Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: handle invalid mapping expressions gracefullyFlorian Westphal2023-12-051-2/+2
| | | | | | | | | | | | Before: BUG: invalid mapping expression binop nft: src/evaluate.c:2027: expr_evaluate_map: Assertion `0' failed. After: tests/shell/testcases/bogons/nft-f/invalid_mapping_expr_binop_assert:1:22-25: Error: invalid mapping expression binop xy mame ip saddr map h& p p ~~~~~~~~ ^^^^ Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: turn assert into real error checkFlorian Westphal2023-12-051-6/+19
| | | | | | | | | large '& VAL' results in: src/evaluate.c:531: expr_evaluate_bits: Assertion `masklen <= NFT_REG_SIZE * BITS_PER_BYTE' failed. Turn this into expr_error(). Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: prevent assert when evaluating very large shift valuesFlorian Westphal2023-12-031-2/+7
| | | | | | | Error out instead of 'nft: gmputil.c:67: mpz_get_uint32: Assertion `cnt <= 1' failed.'. Fixes: edecd58755a8 ("evaluate: support shifts larger than the width of the left operand") Signed-off-by: Florian Westphal <fw@strlen.de>
* main: Refer to nft_options in nft_options_check()Phil Sutter2023-12-031-10/+9
| | | | | | | | | Consult the array when determining whether a given option is followed by an argument or not instead of hard-coding those that do. The array holds both short and long option name, so one extra pitfall removed. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Florian Westphal <fw@strlen.de>
* main: Reduce indenting in nft_options_check()Phil Sutter2023-12-031-15/+16
| | | | | | | No functional change intended. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: reject sets with no keyFlorian Westphal2023-12-011-0/+3
| | | | | | | | nft --check -f tests/shell/testcases/bogons/nft-f/set_without_key Segmentation fault (core dumped) Fixes: 56c90a2dd2eb ("evaluate: expand sets and maps before evaluation") Signed-off-by: Florian Westphal <fw@strlen.de>
* json: deal appropriately with multidevice in chainPablo Neira Ayuso2023-11-232-58/+58
| | | | | | | | | | | | | | | | Chain device support is broken in JSON: listing does not include devices and parser only deals with one single device. Use existing json_parse_flowtable_devs() function, rename it to json_parse_devs() to parse the device array. Use the dev_array that contains the device names (as string) for the listing. Update incorrect .json-nft files in tests/shell. Fixes: 3fdc7541fba0 ("src: add multidevice support for netdev chain") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* evaluate: clone unary expression datatype to deal with dynamic datatypePablo Neira Ayuso2023-11-221-1/+1
| | | | | | | | When allocating a unary expression, clone the datatype to deal with dynamic datatypes. Fixes: 6b01bb9ff798 ("datatype: concat expression only releases dynamically allocated datatype") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* evaluate: bogus error when adding devices to flowtablePablo Neira Ayuso2023-11-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | Bail out if flowtable declaration is missing and no devices are specified. Otherwise, this reports a bogus error when adding new devices to an existing flowtable. # nft -v nftables v1.0.9 (Old Doc Yak #3) # ip link add dummy1 type dummy # ip link set dummy1 up # nft 'create flowtable inet filter f1 { hook ingress priority 0; counter }' # nft 'add flowtable inet filter f1 { devices = { dummy1 } ; }' Error: missing hook and priority in flowtable declaration add flowtable inet filter f1 { devices = { dummy1 } ; } ^^^^^^^^^^^^^^^^^^^^^^^^ Fixes: 5ad475fce5a1 ("evaluate: bail out if new flowtable does not specify hook and priority") Reported-by: Martin Gignac <martin.gignac@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* evaluate: fix rule replacement with anon setsFlorian Westphal2023-11-201-0/+1
| | | | | | | | | | nft replace rule t c handle 3 'jhash ip protocol . ip saddr mod 170 vmap { 0-94 : goto wan1, 95-169 : goto wan2, 170-269 }"' BUG: unhandled op 2 nft: src/evaluate.c:1748: interval_set_eval: Assertion `0' failed. Fixes: 81e36530fcac ("src: replace interval segment tree overlap and automerge") Reported-by: Tino Reichardt <milky-netfilter@mcmilk.de> Signed-off-by: Florian Westphal <fw@strlen.de>