Packet transmission analysis in Router network

Source: Internet
Author: User
Tags error code sendmsg socket

This article introduces a basic knowledge about how data packets are transmitted and exchanged in routers, as long as you understand this, it will help you to configure a good network environment.

First, the problem of input

1, the original set of interfaces can receive any TCP or UDP messages.

2, to receive the original set of interface, the first to receive the packet must have a complete, correct IP header, otherwise can not be through the IP_RCV () in the Baotou inspection and inspection and verification.

3, in the original set of interfaces received packets process, the kernel will receive the IP packet checksum verification, but not the IP packet after any field detection and verification. For example, when we create the original socket, the specified protocol parameter is ipproto_tcp, and the kernel does not perform TCP checksum verification, but instead copies the protocol field in the IP header to all packets of TCP, and submits it to the original set interface.

4, the original set of interfaces received by the TCP packets are IP reorganization after the TCP sorting the previous message.

5. If the specified protocol parameter is not zero when the original socket is created (the third parameter of the socket), the Protocol field of the datagram received should match. Otherwise, the datagram is not passed to the set of interfaces.

6. If a local IP address is bound to the original socket, the destination IP address of the received datagram should match the IP address of the binding, otherwise the packet will not be passed to the socket.

7, if the original set of interface through connect to specify an IP address, then the packet received the source IP address should be matched with the connection address, otherwise the packet does not pass to the socket interface.

8. If a raw socket interface is created with a protocol parameter of 0 and no connect or bind is invoked, the socket receives a copy of each raw datagram that the kernel passes to the original set of interfaces.

9, the original set of interfaces can not receive any ARP or RARP protocol type of socket interface, because net_rx_action () ARP or RARP protocol type of packets passed to the ARP receive function class processing, will not be passed to the IP layer of the receive function IP_RCV ().

10, the original set of interfaces is not able to receive any ICMP type of packets, because some ICMP types of packets are passed to the original set of interfaces before the system has been responded to, and no longer pass up the layer.

11, if the other side of the packet fragmentation, because the original set of interface received in the IP top, so will receive the reorganization of the original IP packet.

Second, the problem of output

1, the normal output usually through sendto or sendmsg and specify the destination IP address to complete, if the socket is already connected, you can also call write, Writev or send.

2, if the IP_HDRINCL option is not set, the kernel writes the data start address is the first byte after the IP header. Because in this case, the kernel constructs the IP header and then it is put in front of the process data. The kernel sets the Protocol field for the IPV4 header to the third parameter that the user gives when calling the socket function.

3, if the IP_HDRINCL option has been set, the kernel writes the data in fact the address is the first byte of the IP header. The data provided by the user must include the IP header. The process constructs the entire IP header in addition to the following two items: The IPV4 label field can be set to 0, requiring the kernel to set the value. And only if the field is 0 o'clock, the kernel is set for it, IPV4 header checksum is computed and stored by the kernel.

4, if you create the original set of interfaces specified the protocol type, that is, the third parameter protocol, that is not to say that only the type of packet. For example, even if the protocol designated as IPPROTO_TCP, you can send the user to assemble the UDP message, but if the IP_HDRINCL option is not set, then the kernel will be in the IP header of the Protocol field indicates that the following message is TCP (but at this time is a UDP message).

Packets are sent to the other TCP layer and are generally discarded because the appropriate TCP socket interface is not found to receive the packet. However, the package can be received on the target host's original set of interfaces.

5, as mentioned earlier, at any time, the IP header checksum is set by the kernel.

6, the kernel at any time that will not be the IP packet after the field verification and validation. For example, even if we specify the third parameter protocol as IPPROTO_TCP, the kernel does not perform TCP checksum calculations and validation when the data is sent.

7, if the IP_HDRINCL option has been set, according to the general, we should build their own IP header, but even if we do not build the IP header, with sendto or sendmsg and specify the destination IP address to send data is still possible to complete. However, such packets are not received on the target machine with the original set of interfaces, because the IP header is validated in IP_RCV () and the checksum is parsed, so the packet is discarded, but it should be able to receive the packet at the link layer.

8, if the IP_HDRINCL option is set, and the packet is very long, then the data will be discarded, and will return error code emsgsize. If the IP_HDRINCL option is not set and the packet is very long, the packet is fragmented.

Because the data packet has the above structure, the computer that installs the TCP/IP protocol can communicate with each other, when using the network based on TCP/IP protocol, the network actually transmits is the packet.

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.