aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ftypes/ftype-ipv4.c
AgeCommit message (Collapse)AuthorFilesLines
2023-10-31wsutil: Rename inet_netw.[ch]João Valverde1-1/+1
inet_netw.c -> inet_cidr.c inet_netw.h -> inet_cidr.h
2023-10-31epan: Move tvbuff functions to tvbuff.cJoão Valverde1-1/+0
2023-10-31wsutil: Move and consolidate CIDR codeJoão Valverde1-3/+3
Consolidate code to handle CIDR network addresses in inet_netw.[ch].
2023-10-29wsutil/to_str: Deprecate ip_to_str() for endian-explicit versionsJoão Valverde1-2/+1
ip_to_str() forces the caller to cast the argument and it's not obvious at all that the input should be in network-byte order for IPv4 addresses. Deprecated the function and add endian-explicit substitutes (number vs address).
2023-10-27ftypes: Add IPv4 setter/getterJoão Valverde1-8/+7
Do not allow "fvalue_set_uinteger" and "fvalue_get_uinteger" with FT_IPv4. Use "fvalue_set_ipv4" and "fvalue_get_ipv4" intead. Fix incorrect usage of fvalue_*_uinteger with FT_IPv4, hopefully I caught all of them.
2023-10-22dfilter: Use better assertions for invalid enumsJoão Valverde1-2/+0
Remove name static storage and use a switch to map enums to names. This allows mapping names all names, even those that are not instantiated as objects. Rewrite some assertions using ws_error() for detailed error messages.
2023-10-22dfilter: Add number lexical typeJoão Valverde1-8/+11
Add a lexical type for numbers, consisting of integers and floats. Because the float is represented internally as an IEEE 754 double and that is a lossy representation, we still need to parse numbers from strings sometimes. One sematic change instroduced is that integers on the RHS of a relation with bytes are interpreted as decimals instead of hexadecimals without a 0x prefix in the representation. This is a net win, in line with the goal of being explicit writing literal values in display filter expressions.
2023-09-22Convert epan/ftypes to C99 typesGerald Combs1-23/+23
Ping #19116
2023-06-26dfilter: Make string slices a return an FT_STRINGJoão Valverde1-1/+1
Allow string slices (indexing) to work with internationalized strings. The old behavior of indexing on byte boundaries can be obtained using raw slices.
2023-06-26dflter: Fix semantics of fvalue lengthJoão Valverde1-1/+7
Do not mix wire size, a protocol property, with fvalue length, a property of certain types of objects (sequences). Rename ftype_length() to ftype_wire_size(). Do not return wire_size with fvalue_length() (use ftype_wire_size() instead). Make the semantic check reject taking the len() of objects that are not arrays or lists. If the (fixed) len() of a number is somehow useful we can add a different function for that.
2023-04-19ftypes: Add a hash/equal methodJoão Valverde1-0/+9
Add methods to make fvalues hashable with GHashTable.
2023-01-06dfilter: Print CIDR mask for IPv4/IPv6 field types.João Valverde1-1/+12
2022-07-14dfilter: Improve compatibility of integer typesJoão Valverde1-4/+9
Before: $ dftest '_ws.ftypes.int64 == _ws.ftypes.int8' Filter: _ws.ftypes.int64 == _ws.ftypes.int8 dftest: _ws.ftypes.int64 and _ws.ftypes.int8 are not of compatible types. _ws.ftypes.int64 == _ws.ftypes.int8 ^~~~~~~~~~~~~~~ After: $ dftest '_ws.ftypes.int64 == _ws.ftypes.int8' Filter: _ws.ftypes.int64 == _ws.ftypes.int8 Syntax tree: 0 TEST_ANY_EQ: 1 FIELD(_ws.ftypes.int64 <FT_INT64>) 1 FIELD(_ws.ftypes.int8 <FT_INT8>) Instructions: 00000 READ_TREE _ws.ftypes.int64 <FT_INT64> -> reg#0 00001 IF_FALSE_GOTO 5 00002 READ_TREE _ws.ftypes.int8 <FT_INT8> -> reg#1 00003 IF_FALSE_GOTO 5 00004 ANY_EQ reg#0 === reg#1 00005 RETURN
2022-04-18dfilter: Add abs() functionJoão Valverde1-0/+1
Add an absolute value function for ftypes.
2022-03-31dfilter: Add remaining arithmetic integer opsJoão Valverde1-0/+3
2022-03-31dfilter: Add binary arithmetic (add/subtract)João Valverde1-0/+2
Add support for display filter binary addition and subtraction. The grammar is intentionally kept simple for now. The use case is to add a constant to a protocol field, or (maybe) add two fields in an expression. We use signed arithmetic with unsigned numbers, checking for overflow and casting where necessary to do the conversion. We could legitimately opt to use traditional modular arithmetic instead (like C) and if it turns out that that is more useful for some reason we may want to in the future. Fixes #15504.
2022-03-30dfilter: Add fvalue duplicate methodJoão Valverde1-0/+1
2022-03-28dfilter: Add ftypes pseudofieldsJoão Valverde1-0/+16
This adds a _ws.ftypes namespace with protocol fields with all the existing field types. Currently this is only useful to debug the display filter compiler, without having to find a real protocol field with the desired type. Later it may find other uses.
2022-03-28dfilter: Add support for unary arithmeticJoão Valverde1-0/+1
This change implements a unary minus operator. Filter: tcp.window_size_scalefactor == -tcp.dstport Instructions: 00000 READ_TREE tcp.window_size_scalefactor -> reg#0 00001 IF_FALSE_GOTO 6 00002 READ_TREE tcp.dstport -> reg#1 00003 IF_FALSE_GOTO 6 00004 MK_MINUS -reg#1 -> reg#2 00005 ANY_EQ reg#0 == reg#2 00006 RETURN It is supported for integer types, floats and relative time values. The unsigned integer types are promoted to a 32 bit signed integer. Unary plus is implemented as a no-op. The plus sign is simply ignored. Constant arithmetic expressions are computed during compilation. Overflow with constants is a compile time error. Overflow with variables is a run time error and silently ignored. Only a debug message will be printed to the console. Related to #15504.
2022-03-23dfilter: ftype_is_true -> ftype_is_zeroJoão Valverde1-3/+3
2022-03-22dfilter: Add bitwise masking of bitsJoão Valverde1-9/+13
Add support for masking of bits. Before the bitwise operator could only test bits, it did not support clearing bits. This allows testing if any combination of bits are set/unset more naturally with a single test. Previously this was only possible by combining several bitwise predicates. Bitwise is implemented as a test node, even though it is not. Maybe the test node should be renamed to something else. Fixes #17246.
2022-03-05dfilter: Rename "unparsed" to "literal"João Valverde1-3/+3
A literal value is a value that cannot be interpreted as a registered protocol. An unparsed value can be a literal or an identifier (protocol/field) according to context and the current disambiguation rules. Strictly literal here is to be understood to mean "numeric literal, including numeric arrays, but not strings or character constants".
2021-12-19epan: Convert to use stdio.h from GLibJoão Valverde1-2/+2
Replace: g_snprintf() -> snprintf() g_vsnprintf() -> vsnprintf() g_strdup_printf() -> ws_strdup_printf() g_strdup_vprintf() -> ws_strdup_vprintf() This is more portable, user-friendly and faster on platforms where GLib does not like the native I/O. Adjust the format string to use macros from intypes.h.
2021-11-24dfilter: Parse character constants in lexerJoão Valverde1-0/+1
Invalid character constants should be handled in the lexical scanner. Todo: See if some code could be shared to parse double quoted strings. It also fixes some unintuitive type coercions to string. Character constants should be treated as characters, or maybe integers, or maybe even throw an invalid comparison error, but coverting to a literal string or byte array is surprising and not particularly useful: '\xFF' -> "'\xFF'" (equals) '\xFF' -> "FF" (contains) Before: Filter: http.request.method contains "\x63" Constants: 00000 PUT_FVALUE "c" <FT_STRING> -> reg#1 (...) Filter: http.request.method contains '\x63' Constants: 00000 PUT_FVALUE "63" <FT_STRING> -> reg#1 (...) Filter: http.request.method == "\x63" Constants: 00000 PUT_FVALUE "c" <FT_STRING> -> reg#1 (...) Filter: http.request.method == '\x63' Constants: 00000 PUT_FVALUE "'\\x63'" <FT_STRING> -> reg#1 (...) After: Filter: http.request.method contains '\x63' Constants: 00000 PUT_FVALUE "c" <FT_STRING> -> reg#1 (...) Filter: http.request.method == '\x63' Constants: 00000 PUT_FVALUE "c" <FT_STRING> -> reg#1 (...)
2021-11-11ftypes: Internal headers need to be internalJoão Valverde1-1/+1
The header ftypes-int.h should not be used outside of epan/ftypes because it is a private header. The functions fvalue_free() and fvalue_cleanup() need not and should not be macros either.
2021-11-10ftypes: Remove fvalue_string_repr_len()João Valverde1-14/+3
The implementation is pre-computing the length and using that to allocate a buffer. This doesn't have any practical advantage and is inefficient because the code is mostly doing the same work twice. Remove the unnecessary length pre-computation step.
2021-10-27Remove some unnecessary casts.João Valverde1-2/+2
Casts are best avoided unless they are truly required. Fix some constness mismatches this revealed.
2021-10-10ftypes: Use an order function to compare ftypesJoão Valverde1-64/+6
All the order operators can be defined in terms of 'lt' and 'eq' so use that to reduce the number of required methods from 6 to 2. Further reduce to one by combining those two into a single function that has memcmp semantics: negative return is "less than", positive is "greater than" and zero is equal.
2019-07-26HTTPS (almost) everywhere.Guy Harris1-1/+1
Change all wireshark.org URLs to use https. Fix some broken links while we're at it. Change-Id: I161bf8eeca43b8027605acea666032da86f5ea1c Reviewed-on: https://code.wireshark.org/review/34089 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-08epan: use SPDX indentifiers.Dario Lombardo1-13/+1
Skipping dissectors dir for now. Change-Id: I717b66bfbc7cc81b83f8c2cbc011fcad643796aa Reviewed-on: https://code.wireshark.org/review/25694 Petri-Dish: Dario Lombardo <lomato@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-10-30Make FT_IPv4 a bit more like FT_IPv6.Guy Harris1-3/+3
FT_IPv6 doesn't expose the prefix, which is used only for values in filter expressions, not values in protocol fields; do the same for FT_IPv4, hiding the netmask, and using fvalue_get_integer() to get the value, having it return a network-byte-order value for the address. (This also makes it opaque whether the address and netmask are stored in host or network byte order.) Change-Id: I4285a87f6ccef2c0ccec040490ddcd15d787326e Reviewed-on: https://code.wireshark.org/review/24177 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-10-30Get rid of ipv4_get_net_order_addr() and ipv4_get_host_order_addr().Guy Harris1-1/+1
Just directly use the addr field, converting from host to network byte order if necessary. Change-Id: Ie1cd9ea5527b7824014dc315225ad2a6adb61c38 Reviewed-on: https://code.wireshark.org/review/24176 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-10-29Get rid of MAX_IP_STR_LEN and MAX_IP6_STR_LEN.Guy Harris1-2/+2
We have WS_INET_ADDRSTRLEN and WS_INET6_ADDRSTRLEN; use them. Change-Id: Idade0da9fae70d891901acd787b06d21e2ddbc5f Reviewed-on: https://code.wireshark.org/review/24156 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-10-26Swallow up the stuff from epan/ipv4.c into epan/ftypes/ftype-ipv4.c and ↵Guy Harris1-19/+58
epan/ipv4.h. Most of it doesn't need to be public; pull it into epan/ipv4.c. Pull the two routines that *are* used outside epan/ftypes/ftype-ipv4.c into epan/ipv4.h as static inline functions. This allows some optimization, and makes epan/ipv4.h more like epan/ipv6.h. Change-Id: I80229acde559d810aecec2acd5c995076440c181 Reviewed-on: https://code.wireshark.org/review/24071 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-20IPv4/IPv6 display filter fixes and testingSilvio Gissi1-7/+1
Removed 'len' from IPv4, not needed Added more test coverage for IPv6 in dftestlib Change-Id: I1ca80e2525f32f6095ad73352baba733f4694ced Reviewed-on: https://code.wireshark.org/review/22260 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-06-19Added IPv4 byte slicingSilvio Gissi1-2/+17
Change-Id: I3bdca418801305d71b33fa07396497d82ad06e33 Reviewed-on: https://code.wireshark.org/review/22212 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-20ftypes: move get_value_ptr into the unionMartin Kaiser1-3/+1
Delete get_value_ptr from struct _ftype_t, make it part of the get_value union. Change-Id: I947331069662a7043bd838e622d286629cc7be9a Reviewed-on: https://code.wireshark.org/review/20647 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-20ftypes: move get_value_uinteger into the unionMartin Kaiser1-1/+0
Delete get_value_uinteger from struct _ftype_t, make it part of the get_value union. Change-Id: I4a6c8341676c442e2bf8ae3b8f771b72161d133c Reviewed-on: https://code.wireshark.org/review/20640 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-19ftypes: move get_value_sinteger into the unionMartin Kaiser1-1/+0
Delete get_value_sinteger from struct _ftype_t, make it part of the get_value union. Change-Id: I3127252cafc62389ce426639992f1d59f7ac9731 Reviewed-on: https://code.wireshark.org/review/20637 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-19ftypes: move get_value_uinteger64 into the unionMartin Kaiser1-1/+0
Delete get_value_uinteger64 from struct _ftype_t, make it part of the get_value union. Change-Id: I2b06efb7691c1bd4089994849373ab8b5ff0bcc7 Reviewed-on: https://code.wireshark.org/review/20618 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-19ftypes: move get_value_sinteger64 into the unionMartin Kaiser1-1/+0
Delete get_value_sinteger64 from struct _ftype_t, make it part of the get_value union. Change-Id: I0113f70ab0aadd1aa655466e896e3acce6c8faeb Reviewed-on: https://code.wireshark.org/review/20617 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-19ftypes: create a get_value union, move get_value_floating into the unionMartin Kaiser1-2/+1
Change-Id: I6bbaf6a7c8a3124e5eab7a7b97c6be082fe8beff Reviewed-on: https://code.wireshark.org/review/20611 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-18ftypes: rename get_value to get_value_ptrMartin Kaiser1-1/+1
This is in preparation for introducing a get_value union, similar to set_value. Change-Id: Id0cf913a616e0314638f1531836c3136ed02631d Reviewed-on: https://code.wireshark.org/review/20610 Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
2017-03-15ftypes: move set_value_floating into the unionMartin Kaiser1-1/+0
Delete set_value_floating from struct _ftype_t, make it part of the set_value union. Change-Id: Ic00e1c70488ddc4422c34657c62af7dc07db02d9 Reviewed-on: https://code.wireshark.org/review/20556 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Reviewed-by: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-14ftypes: move set_value_sinteger64 into the unionMartin Kaiser1-1/+0
Delete set_value_sinteger64 from struct _ftype_t, make it part of the set_value union. Change-Id: I76668f0a6455c5d75c703cd4f440757601246bdb Reviewed-on: https://code.wireshark.org/review/20551 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-14ftypes: move set_value_uinteger64 into the unionMartin Kaiser1-1/+0
Delete set_value_uinteger64 from struct _ftype_t, make it part of the set_value union. Change-Id: I12407b7336282daa60fe6e0e742d65e205dc84fd Reviewed-on: https://code.wireshark.org/review/20539 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-13ftypes: move set_value_sinteger into the unionMartin Kaiser1-1/+0
Delete set_value_sinteger from struct _ftype_t, make it part of the set_value union. Change-Id: I084c4c9beba9978b538d359ebaac21391ebd7f82 Reviewed-on: https://code.wireshark.org/review/20523 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-13ftypes: move set_value_uinteger into the unionMartin Kaiser1-2/+1
Delete set_value_uinteger from struct _ftype_t, make it part of the set_value union. Change-Id: I26de15be8ea0ede76236a8f8a4958bfd97ad9d52 Reviewed-on: https://code.wireshark.org/review/20521 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-10ftypes: move set_value_protocol into the unionMartin Kaiser1-1/+0
Delete set_value_protocol from struct _ftype_t, make it part of the set_value union. Change-Id: Iae55388b8a2c965944028499619282c3232c31f3 Reviewed-on: https://code.wireshark.org/review/20475 Reviewed-by: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-03-10ftypes: move set_value_string into the unionMartin Kaiser1-1/+0
Delete set_value_string from struct _ftype_t, make it part of the set_value union. Change-Id: Ia3a57245330ed0d158c8c3e4552ec5d80752fe0f Reviewed-on: https://code.wireshark.org/review/20474 Reviewed-by: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>