diff options
author | João Valverde <j@v6e.pt> | 2021-10-18 21:07:06 +0100 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-10-24 06:55:54 +0000 |
commit | 0abe10e040080491063848545b8bf9f8ebb3374b (patch) | |
tree | ce2c29b9c9f1540963f8b5f204c1496f3aa30137 /epan/dfilter/dfvm.h | |
parent | d2b249a445e7c1d69a558b6209a2ec9dd7634cca (diff) |
dfilter: Fix "!=" relation to be free of contradictions
Wireshark defines the relation of equality A == B as
A any_eq B <=> An == Bn for at least one An, Bn.
More accurately I think this is (formally) an equivalence
relation, not true equality.
Whichever definition for "==" we choose we must keep the
definition of "!=" as !(A == B), otherwise it will
lead to logical contradictions like (A == B) AND (A != B)
being true.
Fix the '!=' relation to match the definition of equality:
A != B <=> !(A == B) <=> A all_ne B <=> An != Bn, for
every n.
This has been the recomended way to write "not equal" for a
long time in the documentation, even to the point where != was
deprecated, but it just wasn't implemented consistently in the
language, which has understandably been a persistent source
of confusion. Even a field that is normally well-behaved
with "!=" like "ip.src" or "ip.dst" will produce unexpected
results with encapsulations like IP-over-IP.
The opcode ALL_NE could have been implemented in the compiler
instead using NOT and ANY_EQ but I chose to implement it in
bytecode. It just seemed more elegant and efficient
but the difference was not very significant.
Keep around "~=" for any_ne relation, in case someone depends
on that, and because we don't have an operator for true equality:
A strict_equal B <=> A all_eq B <=> !(A any_ne B).
If there is only one value then any_ne and all_ne are the same
comparison operation.
Implementing this change did not require fixing any tests so it
is unlikely the relation "~=" (any_ne) will be very useful.
Note that the behaviour of the '<' (less than) comparison relation
is a separate, more subtle issue. In the general case the definition
of '<' that is used is only a partial order.
Diffstat (limited to 'epan/dfilter/dfvm.h')
-rw-r--r-- | epan/dfilter/dfvm.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/epan/dfilter/dfvm.h b/epan/dfilter/dfvm.h index a57333c707..2cdc85b189 100644 --- a/epan/dfilter/dfvm.h +++ b/epan/dfilter/dfvm.h @@ -53,6 +53,7 @@ typedef enum { PUT_FVALUE, PUT_PCRE, ANY_EQ, + ALL_NE, ANY_NE, ANY_GT, ANY_GE, |