feat(libsinsp): support list modifiers for string operators (oneof/anyof/allof)#2984
Conversation
96327f0 to
b132c91
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2984 +/- ##
==========================================
+ Coverage 75.21% 75.77% +0.56%
==========================================
Files 297 299 +2
Lines 32330 33096 +766
Branches 5116 5148 +32
==========================================
+ Hits 24316 25080 +764
- Misses 8014 8016 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3ab9a7c to
b7b1139
Compare
Perf diff from master - unit testsHeap diff from master - unit testsHeap diff from master - scap fileBenchmarks diff from master |
469f636 to
2163952
Compare
Add StrOperatorModifier production to the BNF grammar and update parser.h with the full StrOperator list. Add lex_str_op_modifier() and wire the modifier token into parse_condition() so that proc.name startswith oneof (a, b, c) parses as a StrOperator + modifier + ListValue. Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
Adds make_terms_last / make_regex_terms_last helpers that produce an N-element list where only the final term matches proc.name = "svc-last". Both modifier and chained variants must iterate every term before the hit — O(N) comparisons with a successful result — which is the true worst-case for a matching event, distinct from no_match (returns false) and first_match (short-circuits on the first term). Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
Certain types (PT_IPV4NET, PT_IPV6NET, PT_IPNET, PT_SOCKADDR, PT_SOCKTUPLE, PT_FDLIST, PT_SIGSET) only support equality-based comparison in flt_compare. compare_rhs already handles this for CO_IN and CO_INTERSECTS by forcing CO_EQ; apply the same logic in compare_rhs_with_mod via a dedicated elem_cmp selector so modifier evaluation uses the correct comparison operator for these types. Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
… types IP address and network filter fields only support equality-based comparison (CO_EQ / CO_NE). Extend flt_is_comparable to reject modifier + non-equality operator combinations for PT_IPV4ADDR, PT_IPV4NET, PT_IPV6ADDR, PT_IPV6NET, PT_IPADDR, and PT_IPNET at filter compilation time, so invalid expressions like `fd.ip contains anyof (...)` are caught early with a clear error. The check is gated on cmp.mod != none, so existing filter expressions without a modifier are not affected. Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
Extract a rhs_elem_matches primitive that centralises the per-element dispatch (CO_REGEX vs flt_compare, CO_NE always uses CO_EQ). in_rhs and all_rhs then become straightforward loops over n_rhs elements with a single early-return pattern, eliminating duplicated operator checks and the scattered CO_NE inversion logic. Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
Extract try_parse_list_expr() from the identical ( ... ) blocks in parse_list_value() and parse_list_value_or_transformer(). Both callers now delegate to the shared helper and only differ in their fallback paths. Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
Rename none/oneof/anyof/allof to CMPOP_MOD_NONE/ONEOF/ANYOF/ALLOF to follow the same naming convention as cmpop (CO_EQ, CO_NE, etc.) and avoid polluting the enclosing namespace with bare lowercase names. Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
…e methods Replace the three local lambdas with named private member functions: matches_rhs_elem, matches_any_rhs, matches_all_rhs. Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
…r RE2 Include <re2/re2.h> directly in sinsp_filtercheck.h instead of forward- declaring, which allows using std::unique_ptr<re2::RE2> without a custom deleter. Replace the manual new + unique_ptr constructor with make_unique. Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
pmatch is a list operator and cannot be combined with oneof/anyof/allof modifiers; add it alongside the existing in/intersects rejection cases. Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
2163952 to
43b3251
Compare
…icates Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
a15239a to
1897b64
Compare
…ier rejection tests Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
…hing Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
05fcaa6 to
36b96f5
Compare
|
LGTM label has been added. DetailsGit tree hash: 79596dd2c35b6f2cc2f083a4359922a2636f854d |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ekoops, leogr, therealbobo The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind test
/kind feature
Any specific area of the project related to this PR?
/area libsinsp
Does this PR require a change in the driver versions?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #2983
Special notes for your reviewer:
Does this PR introduce a user-facing change?: