summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* doc: nft.8: Highlight "hook" in flowtable descriptionHEADmasterPhil Sutter13 hours1-2/+2
| | | | | | | | Lacking an explicit description of possible hook values, emphasising the word in the description text should draw readers' attention in the right direction. Signed-off-by: Phil Sutter <phil@nwl.cc>
* doc: nft.8: Fix markup in ct expectation synopsisPhil Sutter13 hours1-1/+1
| | | | | | | Just a missing asterisk somewhere. Fixes: 1dd08fcfa07a4 ("src: add ct expectations support") Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: shell: Fix for maps/typeof_maps_add_delete with ASANPhil Sutter13 hours3-4/+4
| | | | | | | | With both KASAN and ASAN enabled, my VM is too slow so the ping-induced set entry times out before the test checks its existence. Increase its timeout to 2s, seems to do the trick. Signed-off-by: Phil Sutter <phil@nwl.cc>
* json: Fix for memleak in __binop_expr_jsonPhil Sutter13 hours1-8/+16
| | | | | | | | | | | | | When merging the JSON arrays generated for LHS and RHS of nested binop expressions, the emptied array objects leak if their reference is not decremented. Fix this and tidy up other spots which did it right already by introducing a json_array_extend wrapper. Reported-by: Pablo Neira Ayuso <pablo@netfilter.org> Fixes: 0ac39384fd9e4 ("json: Accept more than two operands in binary expressions") Signed-off-by: Phil Sutter <phil@nwl.cc>
* Add support for table's persist flagPhil Sutter6 days8-17/+142
| | | | | | | | | Bison parser lacked support for passing multiple flags, JSON parser did not support table flags at all. Document also 'owner' flag (and describe their relationship in nft.8. Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: shell: Avoid escape chars when printing to non-terminalsPhil Sutter13 days1-2/+2
| | | | | | | | Print the 'EXECUTING' status line only if stdout is a terminal, the mandatory following escape sequence to delete it messes up log file contents. Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: py: Drop needless recorded JSON outputsPhil Sutter13 days5-512/+0
| | | | | | These match the input already, no need to track them. Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: py: Warn if recorded JSON output matches the inputPhil Sutter13 days1-0/+2
| | | | | | Actively support spring-cleaning by nagging callers. Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: py: Fix some JSON equivalentsPhil Sutter13 days3-55/+75
| | | | | | | | | | | | Make sure they match the standard syntax input as much as possible. For some reason inet/tcp.t.json was using plain arrays in place of binary OR expressions in many cases. These arrays are interpreted as list expressions, which seems to be semantically identical but the goal here is to present an accurate equivalent to the rule in standard syntax. Signed-off-by: Phil Sutter <phil@nwl.cc>
* mergesort: Avoid accidental set element reorderingPhil Sutter13 days4-22/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In corner cases, expr_msort_cmp() may return 0 for two non-identical elements. An example are ORed tcp flags: 'syn' and 'syn | ack' are considered the same value since expr_msort_value() reduces the latter to its LHS. Keeping the above in mind and looking at how list_expr_sort() works: The list in 'head' is cut in half, the first half put into the temporary list 'list' and finally 'list' is merged back into 'head' considering each element's position. Shall expr_msort_cmp() return 0 for two elements, the one from 'list' ends up after the one in 'head', thus reverting their previous ordering. The practical implication is that output never matches input for the sample set '{ syn, syn | ack }' as the sorting after delinearization in netlink_list_setelems() keeps swapping the elements. Out of coincidence, the commit this fixes itself illustrates the use-case this breaks, namely tracking a ruleset in git: Each ruleset reload will trigger an update to the stored dump. This change breaks interval set element deletion because __set_delete() implicitly relies upon this reordering of duplicate entries by inserting a clone of the one to delete into the start (via list_move()) and after sorting assumes the clone will end up right behind the original. Fix this by calling list_move_tail() instead. Fixes: 14ee0a979b622 ("src: sort set elements in netlink_get_setelems()") Signed-off-by: Phil Sutter <phil@nwl.cc>
* json: Accept more than two operands in binary expressionsPhil Sutter13 days7-235/+91
| | | | | | | | | | | | | | The most common use case is ORing flags like | syn | ack | rst but nft seems to be fine with less intuitive stuff like | meta mark set ip dscp << 2 << 3 so support all of them. Signed-off-by: Phil Sutter <phil@nwl.cc>
* doc: nft.8: Two minor synopsis fixupsPhil Sutter2024-04-111-2/+2
| | | | | | | | | | | | The curly braces in 'add table' are to be put literally, so need to be bold. Also, they are optional unless either one (or both) of 'comment' and 'flags' are specified. The 'add chain' synopsis contained a stray tick, messing up the following markup. Fixes: 7fd67ce121f86 ("doc: fix synopsis of named counter, quota and ct {helper,timeout,expect}") Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: shell: check for reset tcp options supportPablo Neira Ayuso2024-04-082-0/+7
| | | | | Fixes: 59a33d08ab3a ("parser: tcpopt: fix tcp option parsing with NUM + length field") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: shell: maps/{vmap_unary,named_limits} require pipapo set backendPablo Neira Ayuso2024-04-084-0/+8
| | | | | | ... sets/typeof_sets_concat needs it too. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: shell: chains/{netdev_netns_gone,netdev_chain_dev_gone} require ↵Pablo Neira Ayuso2024-04-082-0/+4
| | | | | | | inet/ingress support Fixes: 6847a7ce0fc9 ("tests: shell: cover netns removal for netdev and inet/ingress basechains") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: shell: payload matching requires egress supportPablo Neira Ayuso2024-04-081-0/+2
| | | | | | | Older kernels do not support for egress hook. Fixes: 84da729e067a ("tests: shell: add test to cover payload transport match and mangle") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: py: complete icmp and icmpv6 updatePablo Neira Ayuso2024-04-045-14/+14
| | | | | | | Update json update and leftover payload update to complete 5fecd2a6ef61 ("src: disentangle ICMP code types"). Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: disentangle ICMP code typesPablo Neira Ayuso2024-04-049-113/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, ICMP{v4,v6,inet} code datatypes only describe those that are supported by the reject statement, but they can also be used for icmp code matching. Moreover, ICMP code types go hand-to-hand with ICMP types, that is, ICMP code symbols depend on the ICMP type. Thus, the output of: nft describe icmp_code look confusing because that only displays the values that are supported by the reject statement. Disentangle this by adding internal datatypes for the reject statement to handle the ICMP code symbol conversion to value as well as ruleset listing. The existing icmp_code, icmpv6_code and icmpx_code remain in place. For backward compatibility, a parser function is defined in case an existing ruleset relies on these symbols. As for the manpage, move existing ICMP code tables from the DATA TYPES section to the REJECT STATEMENT section, where this really belongs to. But the icmp_code and icmpv6_code table stubs remain in the DATA TYPES section because that describe that this is an 8-bit integer field. After this patch: # nft describe icmp_code datatype icmp_code (icmp code) (basetype integer), 8 bits # nft describe icmpv6_code datatype icmpv6_code (icmpv6 code) (basetype integer), 8 bits # nft describe icmpx_code datatype icmpx_code (icmpx code) (basetype integer), 8 bits do not display the symbol table of the reject statement anymore. icmpx_code_type is not used anymore, but keep it in place for backward compatibility reasons. And update tests/shell accordingly. Fixes: 5fdd0b6a0600 ("nft: complete reject support") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* netlink_delinearize: unused code in reverse cross-day meta hour rangePablo Neira Ayuso2024-04-022-8/+12
| | | | | | | | | | | | | | | | | | | | | f8f32deda31d ("meta: Introduce new conditions 'time', 'day' and 'hour'") reverses a cross-day range expressed as "22:00"-"02:00" UTC time into != "02:00"-"22:00" so meta hour ranges works. Listing is however confusing, hence, 44d144cd593e ("netlink_delinearize: reverse cross-day meta hour range") introduces code to reverse a cross-day. However, it also adds code to reverse a range in == to-from form (assuming OP_IMPLICIT) which is never exercised from the listing path because the range expression is not currently used, instead two instructions (cmp gte and cmp lte) are used to represent the range. Remove this branch otherwise a reversed notation will be used to display meta hour ranges once the range instruction is to represent this. Add test for cross-day scenario in EADT timezone. Fixes: 44d144cd593e ("netlink_delinearize: reverse cross-day meta hour range") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: shell: packetpath/flowtables: open all temporary files in /tmpJeremy Sowden2024-04-021-1/+1
| | | | | | | | | | The test used to do I/O over a named pipe in $PWD, until Phil changed it to create the pipe in /tmp. However, he missed one `socat` command. Update that too. Fixes: 3a9f29e21726 ("tests: shell: packetpath/flowtables: Avoid spurious EPERM") Signed-off-by: Jeremy Sowden <jeremy@azazel.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: meta_time: fix dump validation failureFlorian Westphal2024-04-022-32/+0
| | | | | | | | | | | | [DUMP FAIL] 1/1 tests/shell/testcases/listing/meta_time This dump file validates only correctly for TZ=UTC-1 (i.e., CET). Time dumps cannot be validated in a portable way, the dump depends on TZ. As the test already does dump valiation with different TZ values, remove the dump file again. Signed-off-by: Florian Westphal <fw@strlen.de>
* tests: shell: add regression test for double-free crash bugFlorian Westphal2024-04-023-0/+83
| | | | | | | | | | | | | | | | BUG: KASAN: slab-use-after-free in nf_tables_set_elem_destroy+0x55/0x160 Call Trace: nf_tables_set_elem_destroy+0x55/0x160 nf_tables_set_elem_destroy+0x55/0x160 nft_pipapo_destroy+0x3b4/0x5a0 nft_set_destroy+0x118/0x3a0 nf_tables_trans_destroy_work+0x4f2/0xa80 This is a test case for the bug fiex with kernel commit b0e256f3dd2b ("netfilter: nft_set_pipapo: release elements in clone only from destroy path"). Reported-by: lonial con <kongln9170@gmail.com> Signed-off-by: Florian Westphal <fw@strlen.de>
* datatype: use DTYPE_F_PREFIX only for IP address datatypePablo Neira Ayuso2024-03-215-13/+10
| | | | | | | | | | | | | | | | | DTYPE_F_PREFIX flag provides a hint to the netlink delinearize path to use prefix notation. It seems use of prefix notation in meta mark causes confusion, users expect to see prefix in the listing only in IP address datatypes. Untoggle this flag so (more lengthy) binop output such as: meta mark & 0xffffff00 == 0xffffff00 is used instead. Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1739 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* evaluate: display "Range negative size" errorPablo Neira Ayuso2024-03-201-2/+2
| | | | | | | | zero length ranges now allowed, therefore, update error message to refer to negative ranges which are not possible. Fixes: 7a6e16040d65 ("evaluate: allow for zero length ranges") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* netlink_delinearize: reverse cross-day meta hour rangePablo Neira Ayuso2024-03-208-7/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | f8f32deda31d ("meta: Introduce new conditions 'time', 'day' and 'hour'") reverses the hour range in case that a cross-day range is used, eg. meta hour "03:00"-"14:00" counter accept which results in (Sidney, Australia AEDT time): meta hour != "14:00"-"03:00" counter accept kernel handles time in UTC, therefore, cross-day range may not be obvious according to local time. The ruleset listing above is not very intuitive to the reader depending on their timezone, therefore, complete netlink delinearize path to reverse the cross-day meta range. Update manpage to recommend to use a range expression when matching meta hour range. Recommend range expression for meta time and meta day too. Extend testcases/listing/meta_time to cover for this scenario. Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1737 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* netlink_delinearize: restore binop syntax when listing ruleset for flagsPablo Neira Ayuso2024-03-207-82/+346
| | | | | | | | | | | c3d57114f119 ("parser_bison: add shortcut syntax for matching flags without binary operations") provides a similar syntax to iptables using a prefix representation for flag matching. Restore original representation using binop when listing the ruleset. The parser still accepts the prefix notation for backward compatibility. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: do not merge a set with a erroneous oneFlorian Westphal2024-03-204-2/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The included sample causes a crash because we attempt to range-merge a prefix expression with a symbolic expression. The first set is evaluated, the symbol expression evaluation fails and nft queues an error message ("Could not resolve hostname"). However, nft continues evaluation. nft then encounters the same set definition again and merges the new content with the preceeding one. But the first set structure is dodgy, it still contains the unresolved symbolic expression. That then makes nft crash (assert) in the set internals. There are various different incarnations of this issue, but the low level set processing code does not allow for any partially transformed expressions to still remain. Before: nft --check -f tests/shell/testcases/bogons/nft-f/invalid_range_expr_type_binop BUG: invalid range expression type binop nft: src/expression.c:1479: range_expr_value_low: Assertion `0' failed. After: nft --check -f tests/shell/testcases/bogons/nft-f/invalid_range_expr_type_binop invalid_range_expr_type_binop:4:18-25: Error: Could not resolve hostname: Name or service not known elements = { 1&.141.0.1 - 192.168.0.2} ^^^^^^^^ Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* doc: libnftables-json: Drop invalid ops from match expressionPhil Sutter2024-03-201-5/+0
| | | | | | | These make no sense there and are listed again in BINARY OPERATION. Fixes: 872f373dc50f7 ("doc: Add JSON schema documentation") Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: shell: Fix one json-nft dump for reordered outputPhil Sutter2024-03-201-16/+16
| | | | | | | Missed this one when regenerating all dumps. Fixes: 2a0fe52eca32a ("tests: shell: Regenerate all json-nft dumps") Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: shell: Add missing json-nft dumpsPhil Sutter2024-03-1913-0/+1808
| | | | | | | | | Given that a bunch of issues got fixed, add some more dumps. Also add tests/shell/testcases/owner/dumps/0002-persist.nft while at it, even though it's really small. Signed-off-by: Phil Sutter <phil@nwl.cc>
* parser: json: Support for synproxy objectsPhil Sutter2024-03-191-6/+11
| | | | | | | | | | Parsing code was there already, merely the entry in json_parse_cmd_add() missing. To support maps with synproxy target, an entry in string_to_nft_object() is required. While being at it, add other missing entries as well. Signed-off-by: Phil Sutter <phil@nwl.cc>
* json: Support maps with concatenated dataPhil Sutter2024-03-192-14/+14
| | | | | | | Dump such maps with an array of types in "map" property, make the parser aware of this. Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: shell: Regenerate all json-nft dumpsPhil Sutter2024-03-1960-647/+647
| | | | | | | | Ordering of 'nft -j list ruleset' output has changed, Regenerate existing json-nft dumps. No functional change intended, merely the position of chain objects should have moved up in the "nftables" array. Signed-off-by: Phil Sutter <phil@nwl.cc>
* json: Order output like nft_cmd_expand()Phil Sutter2024-03-191-3/+5
| | | | | | | | Print empty chain add commands early in list so following verdict maps and rules referring to them won't cause spurious errors when loading the resulting ruleset dump. Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: shell: packetpath/flowtables: Avoid spurious EPERMPhil Sutter2024-03-191-3/+3
| | | | | | | | | On my system for testing, called socat is not allowed to create the pipe file in local directory (probably due to sshfs). Specify a likely unique path in /tmp to avoid such problems. Fixes: 419c0199774c6 ("tests: shell: add test to cover ct offload by using nft flowtables") Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: py: move meter tests to tests/shellPablo Neira Ayuso2024-03-1310-182/+250
| | | | | | | | | Userspace performs an translation to dynamic set which does not fit well into tests/py, move them to tests/shell. Fixes: b8f8ddfff733 ("evaluate: translate meter into dynamic set") Acked-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: remove utf-8 character in printf linesFlorian Westphal2024-03-132-13/+13
| | | | | | replace "‘" (UTF-8, 0xe280 0x98) with "'" (ASCII 0x27). Signed-off-by: Florian Westphal <fw@strlen.de>
* tests: py: add payload merging test casesFlorian Westphal2024-03-133-0/+291
| | | | | | Add a test case that would fail without preceeding fix. Signed-off-by: Florian Westphal <fw@strlen.de>
* nftables: do mot merge payloads on negationSriram Rajagopalan2024-03-131-1/+0
| | | | | | | | | | | else, a rule like tcp sport != 22 tcp dport != 23 will match even if the destination is 23 as long as sport is != 22. (or vice versa). Signed-off-by: Sriram Rajagopalan <sriramr@arista.com> Signed-off-by: Florian Westphal <fw@strlen.de>
* evaluate: translate meter into dynamic setPablo Neira Ayuso2024-03-129-34/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 129f9d153279 ("nft: migrate man page examples with `meter` directive to sets") already replaced meters by dynamic sets. This patch removes NFT_SET_ANONYMOUS flag from the implicit set that is instantiated via meter, so the listing shows a dynamic set instead which is the recommended approach these days. Therefore, a batch like this: add table t add chain t c add rule t c tcp dport 80 meter m size 128 { ip saddr timeout 1s limit rate 10/second } gets translated to a dynamic set: table ip t { set m { type ipv4_addr size 128 flags dynamic,timeout } chain c { tcp dport 80 update @m { ip saddr timeout 1s limit rate 10/second burst 5 packets } } } Check for NFT_SET_ANONYMOUS flag is also relaxed for list and flush meter commands: # nft list meter ip t m table ip t { set m { type ipv4_addr size 128 flags dynamic,timeout } } # nft flush meter ip t m As a side effect the legacy 'list meter' and 'flush meter' commands allow to flush a dynamic set to retain backward compatibility. This patch updates testcases/sets/0022type_selective_flush_0 and testcases/sets/0038meter_list_0 as well as the json output which now uses the dynamic set representation. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* Makefile: mkdir $(builddir}/docNeels Hofmeyr2024-03-081-0/+1
| | | | | | | | | When building separately from the source tree (as in ../src/configure), the 'doc' dir is not present from just the source tree. Create the dir before calling a2x. Signed-off-by: Neels Hofmeyr <nhofmeyr@sysmocom.de> Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: add test case for named ct objectsFlorian Westphal2024-03-052-0/+165
| | | | | | | | | | Add a dedicated test for named conntrack objects: timeouts, helpers and expectations. A json dump file is not added because the json input code does not support "typeof" declarations for sets/maps. Signed-off-by: Florian Westphal <fw@strlen.de>
* parser: allow to define maps that contain ct helpersFlorian Westphal2024-03-051-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Its currently not possible to use ct helpers in objref maps. Simply adding "CT HELPER" to "map_block_obj_type" does not work due to a conflict with the "ct helper" ct_expr block. map m { type ipv4_addr : ct helper .. ... declares a map storing ip addresses and conntrack helper names (string type). This does not make sense, there is no way to use the associated value (the names) in any sensible way: ct helper "ftp" - this matches if the packet has a conntrack entry that was accepted via the "ftp" conntrack helper. In nft vm terms, this is translated to: [ ct load helper => reg 1 ] [ cmp eq reg 1 0x00707466 0x00000000 0x00000000 0x00000000 ] Or one can query a set, e.g. 'ct helper { "ftp", "sip" }'. "ftp" and "sip" are the kernel-defined names of these connection tracking helpers. ct helper set "ftp" is something else, however: This is used to assign a *userspace defined helper objrect reference*. Nftables will translate this to: [ objref type 3 name ftp ] .. where "ftp" is a arbitrary user-chosen name. ct helper "ftp" { type "ftp" protocol tcp l3proto ip } IOW, "ct helper" is ambiguous. Without the "set" keyword (first case), it places the kernel-defined name of the active connection tracking helper in the chosen register (or it will cancel rule evaluation if no helper was active). With the set keyword (second case), the expected argument is a user-defined object reference which will then tell the connection tracking engine to monitor all further packets of the new flow with the given helper template. This change makes it so that map m { type ipv4_addr : ct helper .. declares a map storing ct helper object references suitable for 'ct helper set'. The better alternative would be to resolve the ambiguity by adding an additional postfix keyword, for example ct helper name (case one) ct helper object (case two). But this needs a kernel change that adds NFT_CT_HELPER_NAME and NFT_CT_HELPER_OBJECT to enum nft_ct_keys. While a new kernel could handle old nftables binaries that still use NFT_CT_HELPER key, new nftables would need to probe support first. Furthermore, ct helper name set "foo" ... would make no sense, as the kernel-defined helper names are readonly. ct helper object "foo" ... would make no sense, unless we extend the kernel to store the nftables userspace-defined name in a well-known location in the kernel. Userdata area cannot work for this, because the nft conntrack expression in the kernel would need to know how to retrieve this info again. Also, I cannot think of a sensible use case for this. So the only remaining, useful commands are: ct helper name "ftp" ct helper object set "foo" ... which is identical to what we already support, just with extra keyword. So a much simpler solution that does not need any kernel changes is make "ct helper" have different meaning depending on wheter it is placed on the key side, i.e.: "typeof ct helper", "typeof ct helper : $value" versus when its on placed on the data (value) side of maps: "typeof $key : ct helper". Signed-off-by: Florian Westphal <fw@strlen.de>
* parser: allow to define maps that contain timeouts and expectationsFlorian Westphal2024-03-051-3/+11
| | | | | | | | | | | | | | Its currently not possible to use ct timeouts/expectations/helpers in objref maps, bison parser lacks the relevant keywords. This change adds support for timeouts and expectations. Ct helpers are more problematic, this will come in a different change. Support is only added for the "typeof" keyword, otherwise we'd need to add pseudo-datatypes as well, but making "ct expectation" available as "type" as well might be confusing. Signed-off-by: Florian Westphal <fw@strlen.de>
* rule: fix ASAN errors in chain priority to textual namesPablo Neira Ayuso2024-03-051-6/+9
| | | | | | | | | | | | | | | | | | | | | ASAN reports several errors when listing this ruleset: table ip x { chain y { type filter hook input priority -2147483648; policy accept; } } src/rule.c:1002:8: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself src/rule.c:1001:11: runtime error: signed integer overflow: -2147483648 - 50 cannot be represented in type 'int' Use int64_t for the offset to avoid an underflow when calculating closest existing priority definition. Use llabs() because abs() is undefined with INT32_MIN. Fixes: c8a0e8c90e2d ("src: Set/print standard chain prios with textual names") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: move test case to "maps" directoryFlorian Westphal2024-03-012-0/+0
| | | | | | | This tests named object maps, so this should reside in maps/ not sets/ directory. Signed-off-by: Florian Westphal <fw@strlen.de>
* tests: maps: add a test case for "limit" objref mapFlorian Westphal2024-03-013-0/+442
| | | | | | | | | check add, delete and removal operations for objref maps. Also check type vs. typeof declarations and use both interval and interval+concatenation (rbtree, pipapo). Signed-off-by: Florian Westphal <fw@strlen.de>
* netlink: allow typeof keywords with objref maps during listingFlorian Westphal2024-03-011-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without this, typeof meta l4proto . ip saddr . tcp sport : limit ... is shown as type inet_proto . ipv4_addr . inet_service : limit The "data" element is a value (the object type number). It doesn't support userinfo data. There is no reason to add it, the value is the object type number that the object-reference map stores. So, if we have an objref map, DO NOT discard the key part, as we do for normal maps. For normal maps, we support either typeof notation, i.e.: typeof meta l4proto . ip saddr . tcp sport : ip saddr or the data type version: type inet_proto . ipv4_addr . inet_service : ipv4_addr ... but not a mix, a hyptothetical typeof meta l4proto . ip saddr . tcp sport : ipv4_addr ... does not work. If nft finds no udata attached to the data element, for normal map case, it has to fall back to the "type" form. But for objref maps this is expected, udata for key but not for data. Hence, for objref case, keep the typeof part if its valid. Signed-off-by: Florian Westphal <fw@strlen.de>
* parser: allow typeof in objref mapsFlorian Westphal2024-03-011-0/+9
| | | | | | | | | | | | | | | | | | Its currently not possible to declare a map that stores object references with the "typeof" keyword, e.g. map m { type ipv4_addr : limit will work, but map m { typeof ip saddr : limit will give a syntax error ("unexpected limit"). Followup pach will add support for listing side too. Signed-off-by: Florian Westphal <fw@strlen.de>
* parser: compact type/typeof set rulesFlorian Westphal2024-03-011-15/+9
| | | | | | | | | | | Set/maps keys can be declared either by 'type' or 'typeof' keyword. Compact this to use a common block for both cases. The datatype_set call is redundant, remove it: at this point $3 == $1->key, so this is a no-op. Signed-off-by: Florian Westphal <fw@strlen.de>