26.12.2013 Views

lwIP - A Minimal TCP/IP implementation - Wikia

lwIP - A Minimal TCP/IP implementation - Wikia

lwIP - A Minimal TCP/IP implementation - Wikia

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9 UDP PROCESSING 8.3 Forwarding packets<br />

8.3 Forwarding packets<br />

If none of the network interfaces has the same <strong>IP</strong> address as an incoming packet’s destination<br />

address, the packet should be forwarded. This is done by the function ip forward(). Here, the<br />

TTL field is decreased and if it reaches zero, an ICMP error message is sent to the original sender of<br />

the <strong>IP</strong> packet and the packet is discarded. Since the <strong>IP</strong> header is changed, the <strong>IP</strong> header checksum<br />

needs to be adjusted. The is no need to recompute the entire checksum, however, since simple<br />

arithmetic can be used to adjust the original <strong>IP</strong> checksum [MK90, Rij94]. Finally, the packet<br />

is forwarded to the appropriate network interface. The algorithm used to find the appropriate<br />

network interface is the same that is used when sending <strong>IP</strong> packets.<br />

8.4 ICMP processing<br />

ICMP processing is fairly simple. ICMP packets received by ip input() are handed over to<br />

icmp input(), which decodes the ICMP header and takes the appropriate action. Some ICMP<br />

messages are passed to upper layer protocols and those are taken care of by special functions in the<br />

transport layer. ICMP destination unreachable messages can be sent by transport layer protocols,<br />

in particular by UDP, and the function icmp dest unreach() is used for this.<br />

Transport layer<br />

icmp_dest_unreach()<br />

icmp_input()<br />

Internetwork layer<br />

ip_output()<br />

ip_input()<br />

netif−>output()<br />

Network interface layer<br />

Figure 6. ICMP processing<br />

Using ICMP ECHO messages to probe a network is widely used, and therefore ICMP echo<br />

processing is optimized for performance. The actual processing takes place in icmp input(), and<br />

consists of swapping the <strong>IP</strong> destination and source addresses of the incoming packet, change the<br />

ICMP type to echo reply and adjust the ICMP checksum. The packet is then passed back to the<br />

<strong>IP</strong> layer for transmission.<br />

9 UDP processing<br />

UDP is a simple protocol used for demultiplexing packets between different processes. The state<br />

for each UDP session is kept in a PCB structure as shown in Figure 7. The UDP PCBs are kept<br />

on a linked list which is searched for a match when a UDP datagram arrives.<br />

The UDP PCB structure contains a pointer to the next PCB in the global linked list of UDP<br />

PCBs. A UDP session is defined by the <strong>IP</strong> addresses and port numbers of the end-points and<br />

these are stored in the local ip, dest ip, local port and dest port fields. The flags field<br />

indicates what UDP checksum policy that should be used for this session. This can be either to<br />

switch UDP checksumming off completely, or to use UDP Lite [LDP99] in which the checksum<br />

covers only parts of the datagram. If UDP Lite is used, the chksum len field specifies how much<br />

of the datagram that should be checksummed.<br />

The last two arguments recv and recv arg are used when a datagram is received in the session<br />

specified by the PCB. The function pointed to by recv is called when a datagram is received.<br />

8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!