Generally, you only need to use a vro to access the Internet. However, for a qualified network administrator, you must know the working process of the vro, in particular, you need to know how data passes through a vro.
1. When data passes through a router, the connect function can be called on the original interface. The connect function only sets the destination address. Re-apply: the port number is meaningless for the original interface. For the output, we can call write or send instead of sendto because the destination address has been specified after connect is called.
2. normal output is usually completed through sendto or sendmsg and the destination IP address is specified. If the set of interfaces have been connected, you can also call write, writev, or send. If the IP_HDRINCL option is not set, the start address of the data written by the kernel is the first byte after the IP header.
In this case, the kernel constructs an IP header and installs it before the data from the process. The kernel sets the protocol field in 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 data written by the kernel is actually the first byte in the IP header. The data provided by the user must include the IP header. In this case, the entire IP header except the following two items can be constructed by the process. The IPv4 field can be set to 0 and the kernel needs to set this value. And only when this field is 0, the kernel sets it and the IPv4 header checksum is calculated and stored by the kernel.
4. If the protocol type, namely the third parameter protocol, is specified when the original interface is created, it does not mean that only data packets of this type can be sent. For example, even if you specify protocol as IPPROTO_TCP, you can also send user-assembled UDP packets. However, if the IP_HDRINCL option is not set, then, the kernel will specify the following packet as a TCP packet in the protocol field of the IP header (but it is a UDP packet at this time ).
The packet is sent to the peer TCP layer. Generally, the packet is discarded because the appropriate TCP interface cannot be found to receive the packet. However, this package can be received on the original interface of the target host.
5. If the IP_HDRINCL option has been set, set up your own IP Address Header as usual, but even if we do not set up an IP address header, you can still use sendto or sendmsg and specify the destination IP address to send data. However, such data packets cannot be received by using the original interface on the target machine, because the IP header needs to be verified in ip_rcv () and the checksum should be analyzed, therefore, the packet will be discarded, but the packet should be received at the link layer.
6. If the IP_HDRINCL option is set and the data packet length is too long, the data is discarded and the error code EMSGSIZE is returned. If the IP_HDRINCL option is not set and the data packet length is too long, the data packet will be split. To receive the original interface, the first packet to be received must have a complete and correct IP header, otherwise, it cannot pass the packet header check and verification in ip_rcv.
7. During the packet received by the original interface, the kernel verifies and verifies the received IP packet, but does not detect or verify any fields in the IP packet. For example, when we create the original set of interfaces, the specified protocol parameter is IPPROTO_TCP, and the kernel does not perform TCP checksum verification, instead, copy all the packets whose protocol field is TCP in the IP header and submit them to the original interface.
8. All TCP packets received by the original interface are packets sorted by TCP after IP address reorganization. If the specified protocol parameter is not zero when the original interface is created (the third parameter of socket), the protocol field of the received datagram should match.
Otherwise, the datagram is not transmitted to this interface. If a local IP address is bound to the original interface, the destination IP address of the received datagram should match the bound IP address. Otherwise, the packet will not be transmitted to the interface.
If the original packet interface specifies an IP address of the other Party through connect, the source IP address of the received packet should match the connection address; otherwise, the packet is not transmitted to the interface.
The original interface does not receive any ARP or RARP interface, because net_rx_action () will pass ARP or RARP packets to the ARP receiving function class for processing, the receiving function ip_rcv () will not be passed to the IP layer, because some ICMP data packets have been responded by the system before being passed to the original interface, and will not be passed to the upper layer.