[PATCH] ICMP extensions for MPLS support for traceroute(8)

Matthew Dillon dillon at apollo.backplane.com
Thu May 10 12:16:51 PDT 2007

:> +	unsigned char   version:4;
:> +	unsigned char   reserved1:4;
:> +#else
:> +	unsigned char   reserved1:4;
:> +	unsigned char   version:4;
:> +#endif
:> +	unsigned char   reserved2;
:> +	unsigned short  checksum;
:> +};
:Please don't add new code that depends on the order of bitfields.
:(Or bitfields in general for wire protocols).

    What Joerg is saying is that the patch looks great!  But we're
    trying to get away from using bitfields so if it would not be too
    much trouble, could you just make that a u_char and extract the fields
    manually with a macro?

    Note that when used as a u_char, I'm pretty sure that no endian
    conversions are needed when doing a manual extraction.  Endian
    conversions on bitfield ordering within single bytes are an artifact
    of the way the compiler assigns the bitfield indices.  The actual
    storage (within a char) is the same.

    Take for example the IP header (now there's something I would like to
    clean up and just make _IP_VHL the default).   Note that the IP_VHL_*()
    macros do not require any endian conditionalization.

struct ip {
#ifdef _IP_VHL
        u_char  ip_vhl;                 /* version << 4 | header length >> 2 */
        u_int   ip_hl:4,                /* header length */
                ip_v:4;                 /* version */
        u_int   ip_v:4,                 /* version */
                ip_hl:4;                /* header length */
. ..

#define  IP_VHL_HL(vhl)          ((vhl) & 0x0f)
#define  IP_VHL_V(vhl)           ((vhl) >> 4)
#define  IP_VHL_BORING           0x45

					Matthew Dillon 
					<dillon at backplane.com>

More information about the Submit mailing list