Kernel Space
3.4 IP Address Translation
When source-destination-pair IP addresses are used, those user space application programs have to use this IP format to indicate the destination IP address of a sent packet. For example, in Figure 3.10a, if an application program running on Host 1 wants to send a packet to another application program running on Host 2, the packet’s destination IP address should be set as 1.1.2.1 by the sending application program. Reversely, the destination IP address should be set as 2.1.1.1.
Because the source-destination-pair IP format is unnatural to users who are fa-miliar with the original definition of IP address format, NCTUns provides a solution, called IP address translation, to alleviate users’ inconvenience. For those users who want to develop a user space routing daemon, the knowing of the source-destination-pair IP format is necessary because the routing daemon needs to manipulate the kernel’s routing table. However, for those who want to develop/use a user space traffic generator or protocol module within the simulation server, they can be un-aware of the source-destination-pair IP format and still conduct simulations using
Interface Host 1 Interface 1Router Interface 2Router
IP
Figure 3.11: An example of IP address translation the original IP address format.
An example of IP address translation is demonstrated in Figure 3.11. The net-work topology, IP assignment, and tunnel interface assignment are the same as those used in Figure 3.10a. Thus, the routing entries used in this example network are also the same as those listed in Figure 3.10c. In Figure 3.11, a packet is sent from the application program belonging to Host 1 to the application program belonging to Host 2. The packet’s traveling path is traced to show how the IP address transla-tion is applied to the source and destinatransla-tion IP addresses of the packet’s IP header.
Each step of the trace is described below.
1. When the data segment is sent out by the Host 1’ application program through
the socket, the source and destination IP addresses are recorded in some related socket data structures. In this example, the source IP address is 1.0.1.1 and the destination IP address is 1.0.2.1.
2. When the data segment is copied from the user space to the kernel space, it is stored in a sk buff data structure as well as the output interface information and destination information. Here, the first two octets of the destination IP address are replaced with the last two octets of the source IP address. Note that the source IP address is still the output interface’s IP address. The underscore indicates the changed portion of the destination IP address.
3. Referring to the destination IP address, the kernel finds out the output inter-face by searching the routing table. Then the packet is sent to tun1.
4. Once the packet arrives at tun1 from the IP layer, the first two octets of the source and the destination IP addresses are changed to 1.0. Then it undergoes a condition check.
5. If the destination IP address is equal to tun1’s IP address, then the packet has reached its destination and should be looped back to the upper layer. If this is the case, the first two octets of the source IP address are replaced with the last two octets of tun1’s IP address. Thus, the source IP address should be 1.1.1.1 and destination IP address should be 1.0.1.1. However, in this example, this is not the case.
6. Because the destination IP address is unequal to tun1’s IP address, the packet is sent to the simulation server for going through the data link layer and physical layer simulations. Note that when the simulation server gets the packet, the source IP address is 1.0.1.1 and the destination IP address is 1.0.2.1.
7. The source and destination IP addresses keep unchanged when the packet stays in the simulation server. Thus, when the packet is copied from the simulation
server to another tunnel interface tun3. The source IP address is still 1.0.1.1 and the destination IP address is still 1.0.2.1
8. Once the packet arrives at tun3 from the simulation server, the first two octets of the source IP address are replaced with the last two octets of tun3’s IP address. Here the destination IP address keeps unchanged. Thus, the source IP address is 1.2.1.1 and the destination IP address is 1.0.2.1. Then the packet undergoes a condition check.
9. If the destination IP address is equal to tun3’s IP address, then the packet has reached its destination. If this is the case, then both the source and destination IP addresses are unchanged and the packet is sent to upper layer. In this case, the source IP address should be 1.2.1.1 and the destination IP address should be 1.0.1.2. Of course, this is not the case in this example.
10. Because the destination IP address is unequal to tun3’s IP address, the first two octets of the destination IP address are replaced with the last two octets of tun3’s IP address. Now, the source IP address is 1.2.1.1 and the destination IP address is 1.2.2.1. Then the packet is sent to IP layer for being forwarded.
11. Referring to the destination IP address, that is 1.2.2.1, the kernel finds out the output interface by searching the routing table. Then the packet is sent to tun4.
12. Once the packet arrives at tun4 from the IP layer, the first two octets of the source and the destination IP addresses are changed to 1.0. Then it undergoes a condition check.
13. If the destination IP address is equal to tun4’s IP address, then the packet has reached its destination and should be looped back to the upper layer. If this is the case, the first two octets of the source IP address are replaced with the last two octets of tun4’s IP address. Thus, the source IP address should
be 2.2.1.1 and destination IP address should be 1.0.2.2. Obviously, this is not the case in this example.
14. Because the destination IP address is unequal to tun4’s IP address, the packet is sent to the simulation server for going through the data link layer and physical layer simulations. Note that when the simulation server gets the packet, the source IP address is 1.0.1.1 and the destination IP address is 1.0.2.1.
15. Again, the source and destination IP addresses keep unchanged when the packet stays in the simulation server. Thus, when the packet is copied from the simulation server to another tunnel interface tun2. The source IP address is still 1.0.1.1 and the destination IP address is still 1.0.2.1
16. Once the packet arrives at tun2 from the simulation server, the first two octets of the source IP address are replaced with the last two octets of tun2’s IP address. Here the destination IP address also keeps unchanged. Thus, the source IP address is 2.1.1.1 and the destination IP address is 1.0.2.1. Then the packet undergoes a condition check.
17. If the destination IP address is unequal to tun2’s IP address, the first two octets of the destination IP address should be replaced with the last two octets of tun2’s IP address. Thus, the source IP address should be 2.1.1.1 and the destination IP address should be 2.1.2.1. Then the packet should be sent to IP layer for being forwarded. However, this is not the case in this example.
18. Because the destination IP address is equal to tun2’s IP address, the packet has reached its destination. Both the source and destination IP addresses are unchanged and the packet is sent to upper layer. In this case, the source IP address is 2.1.1.1 and the destination IP address is 1.0.2.1. Note that unlike the destination address, the source IP address keeps in the source-destination-pair format. This is because some kernel protocol implementations need this information to send back responding packets. For example, an ICMP echo reply should be sent back when the kernel receives an ICMP echo request
(network layer). Yet another example is that a TCP acknowledge has to be sent when the kernel receives a TCP data segment (transportation layer).
19. When the data segment, stored in a sk buff data structure, is put into the socket receive buffer by the kernel, the first two octets of the source IP address are changed to 1.0. Thus, the source IP address is 1.0.1.1 and the destination IP address is 1.0.2.1 here.
20. When the Host 2’s application program refers to the IP address information from some related socket data structures, it gets that the source IP address is 1.0.1.1 and the destination IP address is 1.0.2.1.
Note that in Figure 3.11, when any user space program wants to access the IP address information, it just uses the format of 1.0.*.* instead of the source-destination-pair format. This is how the IP address translation provides the original view of IP address format to those who need not manipulate the IP routing functions.