Alexandru Alin-Ioan
Grupa 322CA
When a packet is received from the datalink layer the type is checked and it is treated accordingly.
The router contains a static routing table that is given as a command line argument and a dynamic arp table used to store the MAC addresses and their corresponding IPs.
An IP / ICMP packet is treated as such:
- It checks if the packet is addressed to him. This means that an ICMP echo reply needs to be sent back to the sender.
- The checksum is verified to be correct.
- The TTL is decreased and if it reaches 0 an ICMP Time Exceded response is sent back to the sender.
- It searches for the best match in the routing table.
- The longest prefix match algorithm is done by using a binary search on the routing table array.
- The search is done in O(log n) complexity.
- If no route is found it sends an ICMP response with the Host unreachable message.
- It searches for the destination MAC address in the arp table. If it is not found it sends an ARP request with the destination set to broadcast and it puts the packet in a list and continues to the next one.
- Updates the ethernet header with the corresponding addresses.
An IP / ICMP packet is treated as such:
- A check is made to determine if the ARP packet is a request or a reply.
- If it is a request it updates the header by swapping the destination and source addresses, marks it as a reply, and then sends it back.
- If it is a reply the arp table is updated with the received address and then a search is made in the waiting packet list to determine which packets need to be sent to the received address. That entry is then removed from the list.
- A list entry contains the packet (as a buffer), the length of the packet, the next hop IP address and the interface of the next