Data Structures Featured in This Chapter
The three main data structures used by the ICMP code are:
-
icmphdr ICMP header .
-
icmp_control ICMP message type descriptor. Among its fields is the routine used to process ingress messages.
-
icmp_bxm Input structure given as a parameter to the two transmit routines described in the section "Transmitting ICMP Messages." It includes all the information necessary to transmit an ICMP message.
icmphdr Structure
We saw in Figure 25-1 the structure of an ICMP message. The following, from include/linux/icmp.h, is the data structure used to define an ICMP header:
struct icmphdr {
_ _u8 type;
_ _u8 code;
_ _u16 checksum;
union {
struct {
_ _u16 id;
_ _u16 sequence;
} echo;
_ _u32 gateway;
struct {
_ _u16 _ _unused;
_ _u16 mtu;
} frag;
} un;
};First come the three fields common to all ICMP types, and then a union that provides
different fields based on the message type. For example, un.frag is used by ICMP_FRAG_NEEDED
messages, and un.echo by the query messages (i.e.,
ICMP_ECHO, ICMP_ECHOREPLY, etc.).
icmp_control Structure
For each ICMP type there is an instance of an icmp_control data structure (defined in net/ipv4/icmp.c). Among other fields, it includes a pointer
to the routine that is to be called to process ingress ICMP messages. Here are its
fields:
-
int output_entry -
int input_entry Indexes used by the receive routine
icmp_rcvand the transmission routines in the section "Transmitting ICMP Messages" to update the right SNMP counter in an array. See ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access