Commit Graph

789 Commits

Author SHA1 Message Date
João Valverde ad21615973 dfilter: Fix an error message
Before:

    $ dftest 'ip.port == 5'
    Filter:
     ip.port == 5

    Error: Constant expression is invalid.
      ip.port == 5
      ^~~~~~~~~~~~

After:

    $ dftest 'ip.port == 5'
    Filter:
     ip.port == 5

    Error: "ip.port" is not a valid protocol or protocol field.
      ip.port == 5
      ^~~~~~~
2023-06-22 05:46:45 +01:00
João Valverde a3ffd742fe dfilter: Fix second stage compilation flags
Pass the dfs->flags instead of flags to dfwork_new(),
because the flags might have been modified in the first stage
by the parser.
2023-06-20 12:10:45 +00:00
João Valverde d456cc761a ftypes: Rename IS_FT_* macros
Rename IS_FT_*() to FT_IS_*(). I find it to be more natural and
a better namespace for a public interface.
2023-06-20 00:22:57 +01:00
John Thacker a3806fc69b Qt: Fix crash when changing dfilter macro
The comments claim that UAT_AFFECTS_FIELDS also triggers a redissection,
but it does not. Fortunately, all UATs whose flags have UAT_AFFECTS_FIELDS
also have UAT_AFFECTS_DISSECTION.

dfilter macro expressions are a rare case of a UAT that should trigger
FieldsChanged but not PacketDissectionChanged. (It's slightly
unnecessary to invalidate the custom columns, but perhaps in the
future macros will be possible in custom columns.)

So resolve things by changing the comments to reflect current reality
and making the dfilter macro UAT flags UAT_AFFECTS_FIELDS.

This prevents a crash when removing a dfilter macro thus invalidating
the current filter, and then opening a file (including reloading the
current one.)

Fix #13753
2023-06-09 15:34:44 +00:00
João Valverde 62b427c611 Initialize some variables [-Wmaybe-uninitialized] 2023-05-21 13:57:32 +00:00
John Thacker f69e0ca6bc dfilter+taps: Load field references for taps
When rescanning or retapping, if there is a currently selected packet
in the GUI, load any field references in any filters for any tap
listeners.

Note that Lua plugins can register some filtering tap listeners later
after we reset the dissection tree, but those are for field extraction
in the new tree and can't contain field references.

Fix #18912
2023-05-06 23:28:40 -04:00
João Valverde 0d1a60a911 dfilter: Restore handling of empty/invalid filters
Restore behavior before 435a2186ab.
Handling of empty expressions should be handled by the parser
and that commit was faulty.
2023-04-22 04:55:29 +00:00
João Valverde dfffd13892 dfilter: Remove assertion on empty filter expression
Because existing code is dependant on the behavior that a null/empty
filter is a sort of valid input (presumably to avoid having to check
for that condition explicitly) add back that behavior to avoid a lot
of potential hidden cascading failures.
2023-04-21 19:11:26 +01:00
João Valverde 0d0d468b64 dfilter: Add separate state for first and second stages
This will allow resetting the code generation state if we
want to do multiple code generation passes.
2023-04-21 18:15:18 +01:00
João Valverde d73387c245 dfilter: Minor refactoring 2023-04-21 18:06:07 +01:00
João Valverde b7bdbf0eb0 dfilter: Add dfwork_build()
Add a separate function to structure the code better.
2023-04-21 18:05:48 +01:00
João Valverde c053b96f08 dfilter: Assert on invalid dfilter_compile input 2023-04-21 18:04:33 +01:00
João Valverde 435a2186ab dfilter: Cleanup handling of null/empty expressions 2023-04-21 18:04:33 +01:00
João Valverde 43117dd40f dfilter: Rename dfilter_compile_real() -> dfilter_compile_full()
The function is part of the public interface. The new name is better
and more descriptive.
2023-04-21 17:02:29 +00:00
João Valverde 9e98b13524 dfilter: Move flags to dfwork_t
Replace booleans with a flags field.
2023-04-21 17:02:29 +00:00
João Valverde 61bfa918f1 dfilter: Add a dfwork_parse() function
Split the scanning/parsing stage into a separate function to
improve the structure of the code.
2023-04-21 17:02:29 +00:00
João Valverde e1871ba81c dfilter: Normalize error handling
Fail compilation if error pointer is set. Remove other redundant
failure flags.

Remove lemon %parse_failure block. This should be unnecessary.
I think this is only useful if we are doing error recovery,
which we aren't.
2023-04-21 17:02:29 +00:00
João Valverde d92846969c dfilter: Rename struct member
Members inside a structure do not need a namespace
prefix.

Remove stale declaration.
2023-04-21 17:02:29 +00:00
João Valverde 00fe9bc3d5 dfilter: Remove a default case statement
Let a (good) compiler warn if there is a missing case
in the switch.
2023-04-21 17:02:29 +00:00
João Valverde 297375df19 dfilter: Fix a memory leak
Don't leak error message string after creating a new dfilter
error object.
2023-04-20 15:29:33 +01:00
João Valverde 81a8777b9f dfilter: Make error a pointer
Make it easier and more natural to test for errors and hand-over
error results.
2023-04-20 14:12:39 +00:00
João Valverde 7595af96a0 ftypes: Hide fvalue implementation
Exposing the fvalue_t implementation is exposing internal
details of the implementation. Fix that by making the fvalue_t
internal to the ftypes implementation and using setters/getters
where necessary.
2023-04-19 15:12:25 +00:00
João Valverde a3547d0e8d dfilter: Improve previous fix
Refactor previous fix to cover the case where the pointer
array is empty.
2023-04-18 22:05:13 +00:00
João Valverde ba59ed9ae8 dfilter: Fix memory leak in load_references()
The 'finfos' pointer array is a temporary data structure that must
be freed at the end.
2023-04-18 18:23:16 +01:00
João Valverde a9fc552161 dfilter: Fix memory leak in sttype_slice_set1()
The GSList pointer is a temporary data structure that must be
freed at the end.
2023-04-18 18:23:16 +01:00
João Valverde 8ce3bac131 dftest: Add --refs option
Add option to dump runtime data structures in a compiled display
filter. As the comment notes:

    /* NOTE: References are loaded during runtime and dftest only does compilation.
     * Unless some static reference data is hard-coded at compile time during
     * development the --refs option to dftest is useless because it will just
     * print empty reference vectors. */
2023-04-17 01:31:49 +00:00
João Valverde 36c5741558 dfilter: Replace local variable 2023-04-17 01:08:35 +00:00
João Valverde 1ec61b22c7 dfilter: Remove dead variable 2023-04-17 01:08:35 +00:00
João Valverde 39f3587b98 dfilter: Add some missing headers 2023-04-17 01:08:15 +00:00
John Thacker 4196076418 dfilter: Use ws_debug
Use ws_debug instead of ws_log(WS_LOG_DOMAIN, LOG_LEVEL_DEBUG)
in dfilter_compile_real, so that the logging is optimized away in a
Release build.
2023-02-28 02:36:38 +00:00
John Thacker 8834c8e9de epan: Determine if an active color filter has a hfid/proto
Add functions to test if a compiled dfilter considers an hfid
or a protocol id interesting. Use those to define functions to
test if any enabled color filter considers an hfid or a protocol
interesting.
2023-02-26 02:41:19 +00:00
João Valverde fe7bfdf6ca CMake: Require explicit installation of development headers
Develpment headers are a sizeable part of the binary installation
and most users won't ever require them. It's recommended to package
them separately in a devel package or SDK.

Create a CMake installation component for development headers
and add the EXCLUDE_FROM_ALL property.

Headers can be installed using the invocation:

    cmake --install <dir> --component Development
2023-01-18 03:35:13 +00:00
João Valverde edd4295166 MinGW: Fix -Wunknown-pragma 2023-01-13 22:41:04 +00:00
João Valverde 4c9b0d846c CMake: Reverse debug macros
Originally WS_DISABLE_DEBUG was chosen to be
similar to G_DISABLE_ASSERT and NDEBUG.

However generator expressions are essential for modern CMake
but the syntax is weird and having to use negations makes it
ten-fold worse.

Remove the negation. Instead of changing the CMake variable
reverse the macro definition for WS_DISABLE_DEBUG.

The $<CONFIG:cgs> generator expression with multiple config arguments
requires CMake >= 3.19 so we can't use that yet for a further
syntactical simplification.
2023-01-12 00:59:15 +00:00
Philipp Dittmann 9c68879a27 Windows: Fix Release (unused variables)
- ws_assert does not work, because _ASSERT_ENABLED is false and gets optimized
- add _U_ to unused variables because of compile flag /W3
- local variables need suppression of warning 4189
2023-01-11 17:50:42 +00:00
João Valverde 313fed6db0 dftest: Add --types option 2023-01-11 01:00:41 +00:00
João Valverde 70e006fc42 dftest: Revert to using "->"
">>" looks like a bit shift. Revert back to "->".
2023-01-11 00:37:44 +00:00
João Valverde 613331f07b dfilter: Disable flex debug trace for release builds
This omits the flex debug code in the binary if the build type is
RelMinSize or Release.

It replaces the "%option debug" stanza with the -d command line
option, to be able to configure the flex behaviour.
2023-01-09 04:03:19 +00:00
João Valverde 840a0d3025 dfilter: Display layer in DFVM dump string 2023-01-08 15:10:43 +00:00
João Valverde fcf97be1e9 dftest: Move a newline insertion
We want the string to not end with a new line for logging purposes
but add the final new line when printing to a file stream.
2023-01-07 22:28:01 +00:00
João Valverde 1861679e81 dfilter: Optimize some scanner patterns
Cleanup flex code. Optimize some patterns to avoid lookups
for field matches for values that are not legal field names.

Improve warning and add some comments.
2023-01-07 21:15:25 +00:00
João Valverde 7641ba7416 dftest: More code cleanups and enhancements 2023-01-07 19:16:16 +00:00
João Valverde a2b23f5a09 dfilter: Fix DFVM function debug output
Add a NULL check. Add missing newlines.

Remove explicit display of number of input arguments.
2023-01-06 02:52:04 +00:00
João Valverde df30299aff dftest: Add -h and improve output format
Experiment with removing the type from the instruction output.

This information is also available with the -s option flag.

Rename -t to -s.
2023-01-06 01:43:42 +00:00
João Valverde 522c74b734 dftest: More CLI options and improve output format 2023-01-05 20:26:42 +00:00
João Valverde fd709a6af3 dfilter: Indent DFVM program using spaces 2023-01-05 20:26:42 +00:00
João Valverde e990b25ea2 dfilter: Remove semcheck arithmetic commute argument
No one is using this so I'd like to explore other
options first to handle constants in arithmetic
expressions that lack type information.

Reverts 3ddb017a88.
2023-01-03 12:46:13 +00:00
João Valverde f37c7c4062 dfilter: Tweak representation for length-1 byte array
Make dfilter byte representation always use ':' for consistency.

Make 1 byte be represented as "XX:" with the colon suffix to
make it nonambiguous that is is a byte and not other type,
like a protocol.

The difference is can be seen in the following programs. In the
before representation it is not obvious at all that the second
"fc" value is a literal bytes value and not the value of the
protocol "fc", although it can be inferred from the lack of
a READ_TREE instruction. In the After we know that "fc:" must
be bytes and not a protocol.

Note that a leading colon is a syntactical expedient to say
"this value with any type is a literal value and not a protocol
field." A terminating colon is just a part of the dfilter
literal bytes syntax.

Before:

Filter: fc == :fc

Syntax tree:
 0 TEST_ANY_EQ:
   1 FIELD(fc <FT_PROTOCOL>)
   1 FVALUE(fc <FT_PROTOCOL>)

Instructions:
00000 READ_TREE		fc <FT_PROTOCOL> -> reg#0
00001 IF_FALSE_GOTO	3
00002 ANY_EQ		reg#0 == fc <FT_PROTOCOL>

After:

Filter: fc == :fc

Syntax tree:
 0 TEST_ANY_EQ:
   1 FIELD(fc <FT_PROTOCOL>)
   1 FVALUE(fc: <FT_PROTOCOL>)

Instructions:
00000 READ_TREE		fc <FT_PROTOCOL> -> reg#0
00001 IF_FALSE_GOTO	3
00002 ANY_EQ		reg#0 == fc: <FT_PROTOCOL>
2023-01-02 02:54:38 +00:00
João Valverde c762d8492b dfilter: Improve debug format 2023-01-02 02:53:21 +00:00
João Valverde f5bfe89785 dfilter: Replace global variable 2023-01-02 01:19:51 +00:00