Ask Your Question
0

Explicitely call a specific Lua dissector from a Lua tap/listener w/o a tree?

asked 2025-02-19 17:01:05 +0000

mwb gravatar image

Hi everyone,

I've been able to use a dissector for a custom protocol which transports data over USB bulk packets. The "outermost layer" of the custom protocol looks as follows:

┌────────────────────┐   ┌───────────────┐    ┌────────────────────┐
│┌───┐┌───┐┌───┐┌───┐│   │┌───┐┌───┐┌───┐│    │┌───┐┌───┐┌───┐┌───┐│
││a  ││b  ││a  ││b  ││   ││a  ││a  ││c  ││    ││a  ││b  ││a  ││c  ││
│└───┘└───┘└───┘└───┘│   │└───┘└───┘└───┘│    │└───┘└───┘└───┘└───┘│
└────────────────────┘   └───────────────┘    └────────────────────┘
USB bulk packet #1       USB bulk packet #2   USB bulk packet #3

In the next step, I'd like to call another dissector for the "inner layer" of that protocol. Let's say frames of type b.

I've written a tap/listener in Lua which is called for every frame of the "outermost layer", i.e. for frames of types a, b and c. I can identify frames of type b and want to call the dissector for the payload of the "inner layer".

What I am currently trying is: Call InnerLayerTypeB_protocol.dissector:call(some_tvb, pinfo, tapinfo) from function tap.packet(pinfo, tvb, tapinfo).

The problem: The function parameters.

First argument of type Tvb? These are the payload bytes I want to hand over to the dissector. I can construct a new Tvb object, no problem: local bc_tvb = ByteArray.tvb(stream_data, "My Tvb") -- where stream_data = fi.value taken from some specific field (local fields = { all_field_infos() } ... for ix, fi in ipairs(fields) do). That might work.

Second argument: pinfo? No problemo... as function tap.packet(pinfo, tvb, tapinfo) already gets that itself as a third argument.

Third argument: tree. I don't have access to "the existing tree"... and I don't really care. Is there a way to create an "empty tree" and use it? I don't need to access anything that exists yet, just dissect the "inner layer". Unfortunately, TreeItem:new() does not exist. I also cannot pass it nil or an empty table ({}).

According to https://www.wireshark.org/docs/wsdg_h..., a Listener "can read the tree, the packet’s Tvb buffer as well as the tapped data, but it cannot add elements to the tree". So.. can I maybe create a copy of an existing tree?

I might be mis-using something here because I haven't fully understood Wireshark concepts yet. Maybe postdissectors or chained dissectors is the way to go, but I do not understand how to use them.. if the "outer layer" is not something existant such as TCP.

Every pointer will be helpful!

Cheers

edit retag flag offensive close merge delete

Comments

Here is the Cliff Notes version. Do you want to update the tree(dissector) or the gui (tap/listener)?

Dissectors
● An existing field in a different format
● New fields
● Dissecting an unsupported protocol
Taps/Listeners
● Relate data across multiple packets
● Custom statistics
● Add menu items/utilities
Chuckc gravatar imageChuckc ( 2025-02-19 19:19:36 +0000 )edit

Hi Chuck. Thanks for your comment. Actually both. But it seems that I need two dissectors - one for the "outer layer" (dissect USB bulk payload into custom protocol frames) and one for the "inner layer" (dissect custom protocol frames of a certain type into its details -- dissecting the nesting unsupported protocol with its own fields). In the next step, I'd like to add a Tap/Listener to make sense of the "inner layer" data ("Relate data across multiple packets", like pretty-printing them in a WIndow). Challenge: selection or detection of the "certain type". I think throwing a heuristic dissector at the "outer layer" won't work as this will produce too many fale positives. I need to add some IDs to the runtime configuration -- which I've only seen available for Taps/Listeners ("Add menu items/utilities"). But I guess that I'll use command line arguments for Lua ...(more)

mwb gravatar imagemwb ( 2025-02-20 07:03:49 +0000 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2025-02-19 19:57:07 +0000

johnthacker gravatar image

You cannot call dissectors from a tap. Taps/Listeners are after all dissection has already been done. The proper way to do this is to have your outer layer dissector call the inner layer dissector for frames of type b. That is somewhat similar to the example here, but you would need to find your other Lua dissector: https://www.wireshark.org/docs/wsdg_h...

This is made a more complicated by https://gitlab.com/wireshark/wireshar... See the related https://ask.wireshark.org/question/10...

You can get around that I believe by not using a table, though you want to make sure that the subdissector is registered before the outer dissector (which can involve putting them in the same file, or making sure that the inner dissector's file comes earlier in ASCII order: (https://www.wireshark.org/docs/wsdg_h...)

edit flag offensive delete link more

Comments

Hi John. Thanks for your answer! I know get that I'll need to use two dissectors then and not a dissector and a Tap/Listener. (However, I guess that I'll still use a Tap/Listener later on the sub-protocol.) I also think that dissector/protocol + subdissector/subprotocol are the terms I should have initially used for my description instead of my "layer" choice. So dissector registration or order of definition seems to be a critical part. I'll have an eye on that when error messages show up. As mentioned in a comment to Chuck's comment above: my initial idea to dissect the subprotocol from a Tap/Listener was that I need some additional runtime configuration parameter (ID pre-selection) to identify the subprotocol within the protocol as such instead of blindly throwing every (outer) protocol payload field canddiate at it. I'll give command line arguments a ...(more)

mwb gravatar imagemwb ( 2025-02-20 07:17:21 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-02-19 17:01:05 +0000

Seen: 19 times

Last updated: 2 days ago