Commit Graph

179 Commits

Author SHA1 Message Date
Niels Widger 4b9d0d5c10 sharkd: Add "capture_types" and "encap_types" to "info" method
Add two new fields `capture_types` and `encap_types` to the output of
`sharkd`'s `info` method which replicate the info displayed by
`editcap -F` and `editcap -T`, respectively.
2023-08-23 11:58:21 +00:00
Niels Widger 09ebddaa7f sharkd: Enable synchronous name resolution, including MaxMind GeoIP
Enable synchronous name resolution in `sharkd` via a call to
`set_resolution_synchrony` in `sharkd_session_main`.  Work for
supporting synchronous calls to `mmdb_resolve` for MaxMind GeoIP seems
to have been done and is also enabled by the
`set_resolution_synchrony` call.

Fix a bug that was using `uat_clear` in `sharkd`'s `main` function to
stop an existing `mmdb_resolve` process.  Using `uat_clear` also wipes
out any custom configuration set by the `maxmind_db_paths` UAT, which
we don't want.  By instead calling the UAT's `reset_cb` callback, we
can stop the old `mmdb_resolve` process without erasing the UAT in the
child `sharkd` process.

See 0542c5b7 for an explanation as to why performing synchronous name
resolution in `tshark` is important.  The same reasoning applies for
`sharkd` as well.
2023-08-22 23:49:26 +00:00
Niels Widger 77f0516b07 sharkd: Fix incorrect "stop_time" field in "voip-calls" tap
Commit a4c6a2f1 added a `voip-calls` tap to `sharkd`, but a copy-paste
bug in `sharkd_session_process_tap_voip_calls_cb` caused each call's
`stop_time` field to actually be the call's start time.  This commit
fixes this bug and updates the `test_sharkd_req_tap_voip_calls` unit
test accordingly.
2023-08-22 09:47:17 -04:00
John Thacker 01af473feb sharkd: Fix some leaks
address_to_display(NULL, addr) allocates a string that must be freed
Coverity CIDs 1532327, 1541107, 1541111
2023-08-21 23:20:15 +00:00
João Valverde 3f841e8553 sharkd: Fix a name collision with MinGW headers 2023-08-19 11:43:10 +01:00
Niels Widger 2904e8c3e5 sharkd: Generate "eo:<name>" object list in "download" method when needed
Previously, a `download` method request for an `eo:<name>_<row>`
export object (for example, `eo:http_0` to download the HTTP export
object with row 0) would fail unless a `tap` method for `eo:<name>`
had already been run.  This behavior is surprising as the other
resources downloadable via the `download` method do not work this way.
This commit addresses this issue by updating the `download` method to,
when a `eo:<name>_<row>` export object is requested, see if an
`eo:<name>` object list already exists in `sharkd_eo_list`.  If it
does not exist, the `download` method first generates the object list
for `eo:<name>` and adds it to `sharkd_eo_list` using `sharkd_retap`
in the same manner that the `tap` method does.  After that, the
`download` method looks for the exported object in `sharkd_eo_list`
just as it did before.

This commit also adds a `sha1` field to the list of exported objects
returned by the `tap` method for `eo` objects in
`sharkd_session_process_tap_eo_cb`.
2023-08-19 07:33:38 +00:00
Niels Widger bdc78d3a63 sharkd: Add optional "filter" parameter to "tap" method
Add new optional `filter` parameter to `sharkd`'s `tap` method which
sets the `fstring` filter parameter which should be used for all
`register_tap_listener` calls made when creating taps requested in the
method's `tap0`-`tap15` parameters.  The value of the new `filter`
parameter is used to set a `tap_filter` local variable in
`sharkd_session_process_tap`.  This local variable existed previously
and was already passed into most calls to `register_tap_listener`, but
was always set to an empty string.
2023-08-16 21:06:41 +00:00
Niels Widger dc29ae7ba3 sharkd: Add "fn" field to "frame" output
The `fn` attribute indicates the "field name" of the current tree item.
This is useful to have outside of having to parse the `f` attribute.
2023-08-16 10:25:49 -04:00
Niels Widger a4c6a2f14b sharkd: add voip-calls and voip-convs taps
Add `voip-calls` and `voip-convs` taps to `sharkd`, which provide the
same information as the `Telephony -> VoIP Calls` GUI menu item.  The
`voip-convs` tap accepts an optional comma-separated list of call ID's
allowing the caller to limit which conversations are returned.  Both a
single call ID or a `<start>-<end>` call ID range is accepted.  For
example, `voip-convs:` returns all conversations, `voip-convs:123`
returns only the conversation with call ID 123 and
`voip-convs:1,5-7,9` returns conversations with call ID's 1, 5, 6, 7
and 9.  The call ID for a conversation is returned in the `call`
field.  The set of call ID's requested by the caller is stored in a
bit-array which, on a standard Linux amd64 machine, supports storing a
maximum of 65536 call ID's.

Because many of the taps initialized by `voip_calls_init_all_taps` are
not able to be built without it, a basic CLI-based implementation of
`simple_dialog` which prints to `stderr` has been added in
`ui/cli/simple_dialog.c`.
2023-08-16 08:48:38 -04:00
Niels Widger 92c5fb9ad3 sharkd: Use PRIu32/PRIu64 when outputing guint32/guint64 JSON values
Update `sharkd_session_process_tap_phs_cb_aux` to use the
`PRIu32`/`PRIu64` format specifiers from `<inttypes.h>` when outputing
`guint32`/`guint64` JSON values since difference targets require
different specifiers to compile.
2023-08-15 14:32:21 +00:00
Niels Widger 1bdbea4ae1 sharkd: Remove unneeded sharkd_phs_req struct 2023-08-15 14:32:21 +00:00
Niels Widger c96b79f105 sharkd: Add phs tap to sharkd
Add `phs` tap to `sharkd`, providing the same information as
`tshark`'s `-z io,phs` option.

Additionally, modify how `tshark -z io,phs` (and therefore `sharkd`'s
new `phs` tap) handles packet comments (aka `pkt_comment` protocol
frames).  Previously, `pkt_comment` protocol frames were handled no
differently from any other protocol in `io,phs`'s `tap_packet`
callback `protohierstat_packet` but were skipped in its `tap_draw`
callback `protohierstat_draw`.  This behavior seems to have been first
introduced in 80ae3708.  For captures containing packet comments, this
lead to surprising `tshark -z io,phs` output with multiple root-level
`eth` trees.  Below is example output of the old behavior for the
`test/captures/protohier-with-comments.pcapng` capture in this
repository with two packet comments, one on an ICMPv6 packet and
another on an SSDP packet:

    # tshark -qz io,phs -r ./test/captures/protohier-with-comments.pcapng
    ===================================================================
    Protocol Hierarchy Statistics
    Filter:

    eth                                      frames:113 bytes:21809
      ipv6                                   frames:38 bytes:7456
        icmpv6                               frames:35 bytes:3574
        udp                                  frames:3 bytes:3882
          data                               frames:3 bytes:3882
      ip                                     frames:69 bytes:13993
        udp                                  frames:59 bytes:13391
          mdns                               frames:1 bytes:138
          ssdp                               frames:29 bytes:8561
          nbns                               frames:20 bytes:2200
          nbdgm                              frames:1 bytes:248
            smb                              frames:1 bytes:248
              mailslot                       frames:1 bytes:248
                browser                      frames:1 bytes:248
          dhcp                               frames:4 bytes:1864
          dns                                frames:4 bytes:380
        igmp                                 frames:10 bytes:602
      arp                                    frames:6 bytes:360
    eth                                      frames:2 bytes:377
      ipv6                                   frames:1 bytes:110
        icmpv6                               frames:1 bytes:110
      ip                                     frames:1 bytes:267
        udp                                  frames:1 bytes:267
          ssdp                               frames:1 bytes:267
    ===================================================================

Despite the comment in `phs_draw` in `ui/cli/tap-protohierstat.c`,
this does not seem to match the behavior for PHS as shown in the GUI.
The GUI seems to ignore the `pkt_comment` protocol frames and merges
their children up a level.  This commit tries to reproduce this
behavior in the `tshark -z io,phs` output by ignoring `pkt_comment`
protocol frames in `protohierstat_packet` instead of
`protohierstat_draw`.  The result is output like the following:

    # tshark -qz io,phs -r ./test/captures/protohier-with-comments.pcapng
    ===================================================================
    Protocol Hierarchy Statistics
    Filter:

    eth                                      frames:115 bytes:22186
      ipv6                                   frames:39 bytes:7566
        icmpv6                               frames:36 bytes:3684
        udp                                  frames:3 bytes:3882
          data                               frames:3 bytes:3882
      ip                                     frames:70 bytes:14260
        udp                                  frames:60 bytes:13658
          mdns                               frames:1 bytes:138
          ssdp                               frames:30 bytes:8828
          nbns                               frames:20 bytes:2200
          nbdgm                              frames:1 bytes:248
            smb                              frames:1 bytes:248
              mailslot                       frames:1 bytes:248
                browser                      frames:1 bytes:248
          dhcp                               frames:4 bytes:1864
          dns                                frames:4 bytes:380
        igmp                                 frames:10 bytes:602
      arp                                    frames:6 bytes:360
    ===================================================================

Note that there are no `pkt_comment` protocols and only a single
root-level `eth` protocol.  Additionally, the commented ICMPv6 and
SSDP packets have been merged into the first `eth` tree, and the frame
and byte counts have been incremented appropriately.
2023-08-15 14:32:21 +00:00
Niels Widger d7a5d5a01d Update sharkd rtp-stream tap to match Wireshark
Adds several columns to the rtp-stream list: `start_time`, `duration`,
`lost`, `lost_percent`, `min_delta`, `mean_delta` and `min_jitter`.
2023-08-08 19:12:21 +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
Gerald Combs 4d5c4154b1 Convert wmem to C99 types
Ping #19116.
2023-06-17 17:38:53 +00:00
Johnathan Raymond a605d7ac8c Revert sharkd newline processing changes
This reverts commits:
    812f40e470,
    6522999276,
    c9e91d7290

The changes merged as part of !6493 prevent the sharkd command from
processing either until the input buffer is full or the client sends an
EOF, by convention closing the connection. This renders sharkd unusable
for most applications.

The intended behavior from #17823 is to parse character by character
until a matching set of braces (`{}`) is detected. Until that behavior
can be implemented, reverting to the prior behavior.
2023-06-12 16:41:08 -07:00
m.kaldenbach 812f40e470 sharkd: Keep the sharkd buffer input size at 2 * 1024
Last '+1' character is used for string termination
2023-06-11 21:19:39 +00:00
m.kaldenbach 6522999276 shardk: preserve last char in buf for string termination
Avoid writing '\0' character past the end of the buffer
2023-06-11 21:19:39 +00:00
m.kaldenbach c9e91d7290 sharkd: Remove json newline restriction
Remove the restriction of having the json string on one line. See issue #17823
Valid json string input would now be:
{
   "jsonrpc": "2.0"
  , "id": 1
  , "method":"status"
}
{"jsonrpc": "2.0","id": 1, "method":"status"}{"jsonrpc": "2.0","id": 1,
"method":"status"
}{"jsonrpc": "2.0","id": 1,"method":"status"}
2023-06-11 21:19:39 +00:00
MarcoKaldenbach be1e20a951 sharkd: Remove json order restriction 2023-06-11 21:16:49 +00:00
Johnathan Raymond 54897d8c06 sharkd: Add Multicast streams output 2023-06-10 21:45:21 +00: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
Zach Chadwick c6cc4d4510 Sharkd: return json error for bad download tokens
Sharkd must always return a JSONRPC response to client input.
Fixes two cases in the processing of the "download" request where no
response was sent:

- When the `token` argument was missing
- When the `token` argument did not match an expected pattern

Two new error values were invented for this since there's not much
guidance on how to define error codes. They are currently unique and
only used in these two cases.
2023-04-12 21:42:02 +00:00
Guy Harris d17b9baec3 sharkd: allow nameless base64 items and objects.
Elements of an array don't have names.
2023-03-06 10:37:12 -08:00
Guy Harris d5a2f6fe2c sharkd: clean up the JSON marshalling.
Add routines to open and close an object, and use them.  The open
routine takes a member name as an argument, sets it, and begins an
object; the close routine ends the object.

Have sharkd_json_response_close() end the object, just as
sharkd_json_response_open() begins it.

Have sharkd_session_process_tap_stats_node_cb() take a key and use that
when opening the array.

Have sharkd_session_process_frame_cb_tree() take a key and use that when
opening the array.

This makes the structure of the code better mirror the structure of the
JSON objects it marshals.

If there's a key for a string value, but there's no string value or no
format for a string value, crash with a null-pointer dereference rather
than putting out the key and then, on the next operation, getting a
"json_dumper_bad(): Bad json_dumper state: illegal transition" error as
in, for example, issue #18886. This way, it will be a bit more obvious
what the true error is.

If thre's no key for a base-64 value, crash rather than not setting the
key, for the same reason.
2023-03-06 00:00:27 -08:00
Guy Harris 3854770f15 sharkd: don't report an error if there is no error.
If dfilter_compile() succeeds, but the filter contains deprecated
tokens, don't report an error from dfilter_compile() as a warning, as
there *is* no error from dfilter_compile().  Instead, report "Filter
contains deprecated tokens".  (Feel free to improve the error text.)

Fixes the crash, at least, in #18886.
2023-03-05 00:05:26 -08:00
Zach Chadwick ac28130c76 Sharkd: show RTP ssrc as hex and improve errors
The token format used by rtp-analyse and rtp-download expect the SSRC
field to be a hex string parsable by `ws_hexstrtou32()` as seen in
sharkd_session.c:760. The output from tap:rtp-streams was displaying
it as an unsigned integer.

For consistency, this field is now displayed as a hex string in the
output.

If the call to download an RTP stream did not match any payloads, Sharkd
would not return any information at all.

This now returns an error message indicating that there is no RTP data
available.

Adds three new selftests and sample pcap.
2023-03-04 22:54:55 +00:00
Zach Chadwick d98f6b16ef Sharkd: Return error message on load if err!=0
Fixes a bug when the return value from load_cap_file() is nonzero.
No response is currently returned causing the client to hang. A non-zero
error code can happen for a variety of reasons, one of which is when the
PCAP is truncated.

An error message from cfile_read_failure_message() is displayed on the
console, but no data was returned to the RPC client.

This adds a call to wtap_strerrror() to look up a human consumable error
message for the specific error code returned during wtap_read().

Adds new self-test to suite_sharkd.py
2023-03-01 11:33:02 +00:00
Zach Chadwick 39aa3cb58a Sharkd: Fix types of prev_frame and ref_frame
The 'frame' command accepts both 'prev_frame' and 'ref_frame' as arguments.
Both should be defined as a UINTEGER rather than a BOOL.
2023-02-25 03:28:18 +00:00
Zach Chadwick 5c0af364f1 Sharkd: Add column header labels to the "status" output 2023-02-19 01:55:21 +00:00
Zach Chadwick 583c8492e5 Zero-pad any RGB color used for a bg or fg
The `color_t_to_rgb` method returns an unsigned int, taking a 32-bit
color code and reducing it to an integer. Sharkd displays these as hex
colors.

However, if this color is missing a Red or Green component, the hex
output is missing the zero-padding for those parts of the color,
resulting in the wrong or invalid hex code.

This patch simply pads the output with zeros.
2023-02-13 19:49:16 +00:00
João Valverde 84f963dfa2 Move ui/version_info.[ch] to wsutil 2023-02-07 23:17:37 +00:00
João Valverde ae14849864 Windows: Use SpeexDSP binary package
Remove bundled code and use vcpkg binary library instead.
2022-12-16 11:11:28 +00:00
João Valverde a0d77e9329 dfilter: Return an error object instead of string
Return an struct containing error information. This simplifies
the interface to more easily provide richer diagnostics in the future.

Add an error code besides a human-readable error string to allow
checking programmatically for errors in a robust manner. Currently
there is only a generic error code, it is expected to increase
in the future.

Move error location information to the struct. Change callers and
implementation to use the new interface.
2022-11-28 15:46:44 +00:00
Guy Harris 8195bdd340 Rename a bunch of things with "conversation".
A conversation in Wireshark might have two endpoints or might have no
endpoints; few if any have one endpoint.  Distinguish between
conversations and endpoints.
2022-08-25 20:02:20 -07:00
Guy Harris 2aeaf71fa5 Change names to reflect that it's an endpoint table.
More {host, hostlist} -> endpoint.
2022-08-23 22:15:45 -07:00
Guy Harris d9e662bc54 Rename some functions and types for endpoint tables.
The "conversation table" mechanism supports two types of tables, one for
the "Conversations" menu item under "Statistics" and one for the
"Endpoints" menu item under "Statistics".  The first of them shows
statistics for conversations at various layers of the networking stack;
the second of them shows statistics for endpoints at various layers of
the networking stack.

The latter is *not* a table of hosts; an endpoint might be a host,
identified by an address at some network level (MAC, IP, etc.), or it
might be a port on a host, identified by an address/port pair.

Some data types, function names, etc. use "host" or "hostlist" or other
terms that imply that an endpoint is a host; change them to speak of
endpoints rather than hosts, using names similar to the corresponding
functions for conversations.

Provide wrapper functions and typedefs for backwards source and binary
compatibility; mark them as deprecated in favor of the new names.

Clean up some comment errors found in the process.
2022-08-23 09:55:14 +00:00
John Thacker c7a136a5c0 epan: Rearrange column includes
Move all the declarations of routines that are internal and
not for use by dissectors from column-utils.h column-info.h
Move the column max length defines into column-utils.h because
dissectors might need that

Since packet.h already includes column-utils.h, dissectors don't
need to include column-utils.h anymore.
Remove or downgrade a few other column header includes that are
unnecessary.
2022-08-13 19:37:28 +00:00
John Thacker 8ac995578c epan: Respect custom column resolved/unresolved status everywhere
Add a function to get the column text of the nth column, taking
into account whether the column is resolved or unresolved. Use
this function in the GUI, as well as in tshark, when writing
PSML, exporting dissection to PSML, etc., instead of accessing
col_data directly.

This removes the direct accesses of col_data from outside
column.c and column-utils.c

Fix #18168.
2022-07-12 00:22:11 +00:00
Roland Knall 2cf938cfa8 tap: Adding flags for tap_packet
This allows flags to be passed by the registering listener
to the collection of information
2022-06-10 05:46:15 +00:00
David Perry 70d432c357 Remove editor modelines and .editorconfig exceptions from root files 2022-02-20 19:39:37 +00:00
j.novak@netsystem.cz 6c9cb8f3fa Prefs/Extcap: Added support for password which is never stored on the disk 2021-12-30 16:03:15 +00:00
João Valverde 0ccd69e530 Replace g_strdup_printf() with ws_strdup_printf()
Use macros from inttypes.h.
2021-12-19 21:21:58 +00:00
João Valverde fe5248717f Replace g_snprintf() with snprintf()
Use macros from inttypes.h with format strings.
2021-12-19 20:06:13 +00:00
Alexis La Goutte 3eb15f04ad sharkd_session: Fix Branch condition evaluate to a garbage value
sharkd_session.c:3307:18: warning: Branch condition evaluates to a garbage value [core.uninitialized.Branch]
2021-09-07 05:56:36 +00:00
Guy Harris 3cb6403a4c wiretap: always allocate a block for a record.
Without that, you could add a comment to a record in a file format the
reading code for which doesn't allocate blocks, but the comment doesn't
get saved, as there's no block in which to save the comment option.

This simplifies some code paths, as we're either using the record's
modified block or we're using the block as read from the file, there's
no third possibility.

If we attempt to read a record, and we get an error, and a block was
allocated for the record, unreference it, so the individual file readers
don't have to worry about it.
2021-08-29 19:12:13 -07:00
Evan Huus c7ed8aa3ee Remove unused variables in sharkd_session.c
The compiler pointed them out. I'm not sure what purpose they were meant
to serve originally but they're dead now.
2021-07-19 11:03:52 -04:00
Guy Harris c4731738fc sharkd: various cleanups.
Extend sharkd_dissect_request() so that it can replace
sharkd_dissect_columns().

Have it return a status indicating success, invalid frame number, or
read error, so that the caller knows what the problem is.

Pass it pointers to the wtap_rec and Buffer to use when reading packets
from the file, so that if it's called in a loop iterating over all
frames, those structures can be initialized once, before the loop, and
cleaned up once, after the loop, rather than doing both once per loop
iteration.

Pass pointers to the read error code and additional read error
information string pointer, so that, on a file read error, that
information is available to the caller.

Get rid of sharkd_dissect_columns(); instead, use
sharkd_dissect_request(), with code from the loop body pulled into a
callback routine.  Fix that code to correctly determine whether the
current frame has any comments, rather than just treating all frames
that have blocks as having comments.

Use _U_ to mark arguments as unused, rather than throwing in a

	(void) variablename;

statement.

Move some variables used only within a loop into the for() statement or
the loop body.
2021-07-11 03:06:10 -07:00
Guy Harris dd5907d2a3 Consistently refer to blocks that have been modified as "modified".
"User" sounds as if the blocks belong to the user; at most, the current
user might have modified them directly, but they might also have, for
example, run a Lua script that, unknown to them, modified comments.
Also, a file might have "user comments" added by a previous user, who
them wrote the file and and provided it to the current user.

"Modified" seems a bit clearer than "changed".
2021-07-08 00:05:35 -07:00