Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: [Wireshark-dev] Using plugin support to handle pcap-ng block types

From: Paul Offord <Paul.Offord@xxxxxxxxxxxx>
Date: Mon, 29 Jan 2018 22:40:17 +0000

Hi,

 

I am writing a plugin that handles two new PCAP-NG block types – details here: https://wiki.wireshark.org/Adding%20Support%20for%20a%20New%20Block%20Type

 

I’m using Guy’s code that adds support for plugins to handle pcap-ng block types, described in https://code.wireshark.org/review/#/c/1775/

 

I have written a read block handler and registered it with Wireshark using register_pcapng_block_type_handler() and the handler gets called correctly.  Once the block has been read by my handler, I want Wireshark to continue to process it, but currently the block is ignored and Wireshark just moves on to the next block.

 

The blocks are read via a while loop in the pcapng_read(…) function of pcapng.c.  After calling a function to read the block there is a “switch (wblock.type)” section of code that decides what next to do with the block.  My new block is not defined as a switch case (not surprising), but I believe the default case should take into account the fact that a block type may have been registered.  The code in this area currently looks like this:

 

        switch (wblock.type) {

 

            case(BLOCK_TYPE_SHB):

                pcapng_debug("pcapng_read: another section header block");

                g_array_append_val(wth->shb_hdrs, wblock.block);

                break;

 

            case(BLOCK_TYPE_PB):

            case(BLOCK_TYPE_SPB):

            case(BLOCK_TYPE_EPB):

            case(BLOCK_TYPE_SYSDIG_EVENT):

            case(BLOCK_TYPE_SYSDIG_EVF):

                /* packet block - we've found a packet */

                goto got_packet;

 

            case(BLOCK_TYPE_IDB):

                /* A new interface */

                pcapng_debug("pcapng_read: block type BLOCK_TYPE_IDB");

                pcapng_process_idb(wth, pcapng, &wblock);

                wtap_block_free(wblock.block);

                break;

 

            case(BLOCK_TYPE_NRB):

                /* More name resolution entries */

                pcapng_debug("pcapng_read: block type BLOCK_TYPE_NRB");

                if (wth->nrb_hdrs == NULL) {

                    wth->nrb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));

                }

                g_array_append_val(wth->nrb_hdrs, wblock.block);

                break;

 

            case(BLOCK_TYPE_ISB):

                /* Another interface statistics report */

                pcapng_debug("pcapng_read: block type BLOCK_TYPE_ISB");

                if_stats_mand_block = (wtapng_if_stats_mandatory_t*)wtap_block_get_mandatory_data(wblock.block);

 

                … lines deleted …

 

                }

                wtap_block_free(wblock.block);

                break;

 

            default:

                /* XXX - improve handling of "unknown" blocks */

                pcapng_debug("pcapng_read: Unknown block type 0x%08x", wblock.type);

                break;

        }

    }

 

got_packet:

 

    /*pcapng_debug("Read length: %u Packet length: %u", bytes_read, wth->phdr.caplen);*/

    pcapng_debug("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset);

 

    return TRUE;

 

 

I believe that the default condition should check for a plugin registered block type and then goto got_packet.  Also, as the code stands we never free wblock.block.

 

Is this a bug, or is my understanding of what’s intended wrong?

 

Thanks and regards…Paul


______________________________________________________________________

This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.

Any views or opinions expressed are solely those of the author and do not necessarily represent those of Advance Seven Ltd. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission.

Advance Seven Ltd. Registered in England & Wales numbered 2373877 at Endeavour House, Coopers End Lane, Stansted, Essex CM24 1SJ

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________