Network protocol stack 9: skb_buff struct prior to the connect () function

Source: Internet
Author: User

When the socket function is used to create a socket, the system creates two socket/sock struct for local data management and organization, and these two data structures will not be transmitted to the network, the struct actually used to carry data is skb_buff. When the system opens the skb_buff struct space, it also opens up the space required for user data, that is, a malloc (sizeof (struct skb_buff) + size) so much space, that is, the size of skb_buff itself, plus the size required by the user space, due to malloc allocation, therefore, these spaces are consecutive parts of space, that is, after the data of the skb_buff struct is completed, the user data is followed. Therefore, the final member of the skb_buff struct is unsigned char data [0]. an array is defined with no members, that is, only the array name. The space pointed to by this array name is exactly the tail of the skb_buff struct, which is also the header of user data.

 

 

Struct sk_buff {

Struct sk_buff * volatile next;

Struct sk_buff * volatile Prev;/* the two fields are used to form the queue of the sk_buff structure */

# If config_skb_check

Int magic_debug_cookie;/* debugging purpose */

# Endif

/*This pointer is also used to form a queue in the sk_buff structure. This queue is the packet re-transmission queue, used for the TCP protocol. The resend queue is a queue directed by the send_head and send_tail fields in the sock structure. Send_head points to this teamThe column header. send_tail points to the end of the queue. The queue connection is completed by using the link3 field of the sk_buff structure.. Send_head and send_tail are pointers to the sk_buff structure, not the sk_buff_head structure.*/

Struct sk_buff * volatile link3;/*Socket to which the data packet belongs*/

Struct sock * SK;/* The time when the packet is sent. This field is used to calculate the round-trip time RTT */

Volatile unsigned long when;/* used to compute RTT's */

/* This field is also the record time, but this field is not currently used for any purpose */

Struct timeval stamp;

/* For A received packet, this field indicates the interface device that receives the packet. For a data to be sent

If this field is not null, it indicates the interface device that will send the packet */

Struct device * dev;

/* The base address of the sk_buff structure in the memory. This field is used to release the sk_buff structure */

Struct sk_buff * mem_addr;

/*This field is a union type, indicating the processing location of the data packet at different processing levels. For example, on the link layer,

The eth pointer is valid and points to the first byte of the Ethernet header. At the network layer, the IPH pointer effectively points to the first byte of the IP

One byte location. Raw pointers change with the hierarchy. At the link layer, raw pointers are equal to eth. At the network layer,

It is equal to iph. SEQ is for data packets to be sent using the TCP protocol. In this case, the field value indicates

Ack value. The ack value is equal to the serial number of the first data in the data packet plus the length value of the data.*/

Union {

Struct tcphdr * th;

Struct ethhdr * ETH;

Struct iphdr * IPH;

Struct udphdr * uh;

Unsigned char * Raw;

Unsigned long seq;

} H;

/* Pointer to the IP header. Here, a special field is used to point to the IP header. It is mainly used for raw sockets */

Struct iphdr * ip_hdr;/* For ipproto_raw */

/* This field indicates the sk_buff structure size plus the total length of the data frame */

Unsigned long mem_len;

/* This field only indicates the length of the data frame. That is, Len = mem_len-sizeof (sk_buff ).*/

Unsigned long Len;

/* These two fields are used for sharding data packets. Fraglen indicates the number of multipart data packets, while fraglist points to the multipart data packet queue */

Unsigned long fraglen;

Struct sk_buff * fraglist;/* fragment list */

Unsigned long truesize;/* same as mem_len */

Unsigned long saddr;/* Source IP address of the data packet sent */

Unsigned long daddr;/* destination IP address of the packet */

Unsigned long raddr;/* Next Hop ADDR packet next IP Address */

/*

Acked = 1 indicates that the data packet has been confirmed and can be deleted from the resend queue.

Used = 1 indicates that the data of the data packet has been read by the application and can be released.

Free = 1 is used to send data packets. When the free flag of a data packet to be sent is equal to 1, it indicates that no matter whether the data packet is

The message is sent successfully. It is released immediately after the sending operation, and no cache is required.

ARP is used for data packets to be sent. If this field is equal to 1, the data packet to be sent has been created for the MAC header. ARP = 0

Indicates that the destination hardware address in the MAC header is unknown, so you need to use the ARP Protocol to ask the recipient.

Before the data packet is fully created, the data packet is always in the sending Buffer Queue (the Buffs array element points

A queue and a queue of ARP Protocol ).

*/

Volatile char acked,

Used,

Free,

ARP;

/*

The tries field indicates that the data packet has been tries for trial sending. If the trial sending exceeds the Domain value, the tries packet will be discarded.

Send. For example, if the SYN Packet established by TCP is sent more than three times, it is discarded.

Lock indicates whether the data packet is being used by other parts of the system.

Localroute indicates whether to use LAN route (localroute = 1) or Wan Route

Pkt_type

The data packet type can be as follows:

Packet_host

This is a data packet sent to the local machine.

Packet_broadcast

Broadcast data packets.

Packet_multicast

Multicast data packets.

Packet_otherhost

This packet is sent to another machine. If the local machine is not configured as the forwarding function, this packet is discarded.

*/

Unsigned char tries, lock, localroute, pkt_type;

# Define packet_host 0/* to us */

# Define packet_broadcast 1

# Define packet_multicast 2

# Define packet_otherhost 3/* unmatched promiscuous */

/* Number of modules users use this data packet */

Unsigned short users;/* User count-see datax. C (and soon seqpacket. c/stream. c )*/

/* Same as pkt_type */

Unsigned short pkt_class;/* for drivers that need to cache the packet type with the skbuff (new PPP )*/

# Ifdef config_slave_balancing

Unsigned short in_dev_queue;/* indicates whether the data packet is being cached in the device cache queue */

# Endif

Unsigned long padding [0];/* fill the byte. Currently, it is defined as 0 bytes, that is, no padding */

Unsigned char data [0];/* points to the data section. The data is generally followed by the sk_buff structure, and may be in any address */

};

 

There is also a struct

Struct sk_buff_head {

Struct sk_buff * volatile next;

Struct sk_buff * volatile Prev;

# If config_skb_check

Int magic_debug_cookie;

# Endif

};

 

Its members are the same as those at the beginning of the sk_buff structure. In this way, you can use pointer conversion to treat sk_buff_head as the sk_buff structure, and the opposite is true.

The system organizes data through the above two structures, forms a queue, and finally transmits data over the network.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.