Wireshark-dev: Re: [Wireshark-dev] how to add global per-capture state?

From: Pascal Quantin <pascal@xxxxxxxxxxxxx>
Date: Mon, 24 Feb 2020 15:45:16 +0100
Hi Aurélien,

Le lun. 24 févr. 2020 à 15:40, Aurélien Aptel <aaptel@xxxxxxxx> a écrit :
Hi,

I'm working on the SMB2 dissector (packet-smb2.c) and I'd like to have
better support for multichannel where an authenticated session is shared
across TCP sessions.

So at the moment, we store a hashtable in the conversation. That table
maps SessionId => Session Data

When a new channel is opened for that session it will share the same ID
but since it's a different TCP connection, it will be in a different
conversation so we won't be able to lookup the existing Session Data.

The solution would be to make the SessionID=>SessionData hashtable
global per-capture instead of per-conversation.

How is this usually done in a Wireshark dissector?

I was thinking of having a global static hashtable in the dissector but
then I would need to reset it when the capture is opened/closed...

You can have a look at the dissectors using wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), ...) which defines a hash table that is automatically reset each time you open a new file (or reload the current one).

Best regards,
Pascal.