Wireshark-dev: Re: [Wireshark-dev] splitting dissector code

From: Guy Harris <gharris@xxxxxxxxx>
Date: Thu, 21 Jul 2022 01:05:21 -0700
On Jul 21, 2022, at 12:31 AM, Riya Dixit <Riya.Dixit@xxxxxxx> wrote:

> You are referring to right document, can I not have one main file dissecting up till the common byte for all pldm message and them write a different function for different spec like bios, base in different files and call that function in the main dissector code.

Yes, you can.  For dissecting IPv4, packet-ip.c dissects the IPv4 header, and then calls different functions, depending on the protocol number in the IPv4 header, and passes it what remains of the packet after the IPv4 header; those other functions are in other files.

In the case of PLDM, the base level dissector (registered by proto_register_pldm() and proto_register_handoff_pldm(), in the source file packet-pldm.c) would dissect everything up to the PLDM Type field.  Then, based on the value of that field, it would choose the appropriate named field for the PLDM Command Code field (as the meanings of particular values for that field depend on the type) and dissect that, and, for a response, do the same for the PLDM Completion Code field.

The base-level dissector would register a dissector table for each type; that would allow the source file for a particular type to register dissectors for particular command types for that type.  The base-level dissector would then pick the appropriate dissector table, based on the type, and look up the command code in that dissector table and call the appropriate dissector, passing it a tvbuff containing the PLDM Message Payload.

The dissectors for PLDM Messaging Control and Discovery payloads would presumably be in the packet-pldm.c file, as those payloads are defined by the base specification.

The dissectors for other types would be in their own files, and would register their payload dissectors in the appropriate dissector table for that type.  Those files would have their own proto_register and proto_register_handoff routines, which would *not* be called proto_register_pldm() and proto_register_handoff_pldm() - they would have names such as, for example, proto_register_pldm_bios_c_and_c() and proto_register_handoff_pldm_c_and_c().