Wireshark-dev: Re: [Wireshark-dev] Wireshark-dev Digest, Vol 23, Issue 11

From: Philip Frey1 <PHF@xxxxxxxxxxxxxx>
Date: Fri, 4 Apr 2008 18:22:34 +0200

Hi Guy,

> Message: 2
> Date: Fri, 04 Apr 2008 02:17:34 -0700
> From: Guy Harris <guy@xxxxxxxxxxxx>
> Subject: Re: [Wireshark-dev] Share CRC32C code between MPA and iSCSI
> To: Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx>
> Cc: markb@xxxxxxxxxx, geyves@xxxxxxxxxxxxxxx
> Message-ID: <47F5F22E.2040102@xxxxxxxxxxxx>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Philip Frey1 wrote:
>
> > we have developed a dissector for the MPA (Marker PDU Aligned Framing)
> > protocol which is part of the iWARP stack.
> > Since we also need to do some CRC32C calculations (same as iSCSI),
>
> ...and, it appears, SCTP.

Good catch.

> The SCTP dissector has the same CRC table; its CRC routine starts with
> 0xFFFFFFFF - which, when byte-swapped, is unchanged - and then adds in
> to the CRC a bunch of bytes and 0's, flips the bits in the result, and
> then swaps the bytes.  Your CRC32 routine doesn't flip the bits, so the
> right way to combine them might be to:
>
>    export the CRC32 table from crc32c.c, declaring it in crc32.h;
>
>    moving the CRC32C macro from packet-sctp.c to crc32.h;
>
>    moving the CRC32C_SWAP macro from crc32c.c to crc32.h (or see whether
> GLib 1.2.x and 2.x define something equivalent, and use that);
>
>    have calculate_crc32() use the CRC32C macro:
>
> guint32 calculate_crc32(const void *buf, int len, guint32 crc)
> {
>    const guint8 *p = (const guint8 *)buf;
>    crc = CRC32C_SWAP(crc);
>    while (len-- > 0) {
>       CRC32C(crc, *p++);
>    }
>    return CRC32C_SWAP(crc);
> }
>
>    have sctp_crc32c() use CRC32C_PRELOAD instead of ~0L.
>
> There might be some other merging that could be done.

I have implemented exactly as you suggested (assuming I understood your suggestion
correctly). :-D

Please find attached the modified files:
(I merged everything into the crc32-files and got rid of the crc32c files)



If that is what you had in mind, then I will contribute it by sending my diff
to the bug-list of wireshark (as suggested in the README.developer).

Cheers,
 Phil

Attachment: crc32.h
Description: Binary data

Attachment: crc32.c
Description: Binary data

Attachment: packet-iscsi.c
Description: Binary data

Attachment: packet-iwarp-mpa.c
Description: Binary data

Attachment: packet-sctp.c
Description: Binary data