Tuesday, October 20, 2009

Section 25.7.  Data Structures Featured in This Chapter










25.7. 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.



25.7.1. 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.).




25.7.2. 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_rcv and the transmission routines in the section "Transmitting ICMP Messages" to update the right SNMP counter in an array. See the section "ICMP Statistics."


void (*handler)(struct sk_buff *skb)


Function invoked by the receiving routine icmp_rcv to process incoming ICMP messages.


short error


Flag that is set when the ICMP type is classified as an error (as opposed to a query). See Table 25-1.


Here are two examples where the error field is useful, as mentioned in the section "Transmitting ICMP Error Messages":


  • The kernel can check to make sure it is not replying to an ingress ICMP error message with another ICMP error message, which is prohibited.

  • ICMP types that are classified as errors are given a better TOS (IPTOS_PREC_INTERNETCONTROL) since they are considered more important (see icmp_send[*]).

    [*] This is required by RFC 1812 in section 4.3.2.5.


Refer to the section "Receiving ICMP Messages" to see how icmp_control data structures are organized.




25.7.3. icmp_bxm Structure


icmp_bxm is defined in net/ipv4/icmp.c. Here is a description of its fields:



struct sk_buff *skb


For ICMP messages sent with icmp_send, represents the ingress IP packet that triggered the transmission. For ICMP messages sent with icmp_reply, represents an ingress ICMP message request.


int offset


Offset between skb->data and skb->nh (i.e., the size of the IP header). This offset is useful when evaluating how much data can be put into the ICMP payload for those ICMP messages that require it (see the section "ICMP Payload").


int data_len


Size of the ICMP payload.


struct {




struct icmphdr icmph;
_ _u32 times[3];




} data


icmph is the header of the ICMP message to transmit. times is used by the ICMP_TIMESTAMPREPLY message type (see Figure 25-4).


int head_len


Size of the ICMP header.


struct ip_options replyopts



unsigned char optbuf


replyopts stores the IP options to use at the IP layer. It is initialized with ip_options_echo based on the IP options of skb. optbuf is an extension of replyopts that is accessed by ip_options_echo via the _ _data field of ip_options. See Chapter 19.













No comments:

Post a Comment