Transport Layer

Two main IP-based transport protocols are used — UDP to send datagrams, and TCP to set up secure, connection-oriented services. Whereas UPD is a simple, easily implemented protocol, TCP has several well-concealed (but nevertheless well-known) booby traps and stumbling blocks that make implementation all the more complex.

12.9.1 UDP

As explained in the previous section, ip_local_deliver distributes the transport data contents of IP packets. udp_rcv from net/ipv4/udp.c is used to further process UDP datagram packets. The associated code flow diagram is shown in Figure 12-23.

udp_rcv is just a wrapper function for_udp4_lib_rcv since the code is shared with the implementation of the UDP-lite protocol as defined in RFC 3828.

As usual, the input parameter passed to the function is a socket buffer. Once it has been established that the packet data are intact, it is necessary to find a listening socket using_udp4_lib_lookup. The connection parameters can be derived from the UDP header, whose structure is shown in Figure 12-24.

24Note that the names of the netfilter hooks will be changed in the same manner as noted for IPv4 in kernel 2.6.25, which was still under development when this book was written. The constants will not be prefixed NF_IP6_ anymore, but instead by NF_INET_. The same set of constants is thus used for IPv4 and IPv6.

Figure 12-23: Code flow diagram for udp_rcv.
0 16 32

Source Port

Destination Port

Length

Checksum

Payload

Figure 12-24: Structure of a UDP packet.

Figure 12-24: Structure of a UDP packet.

In figure 12-24, ''Source'' and ''Destination Port'' specify the port number of the source and destination system and accept values from 0 to 65,535 because each uses 16 bytes.25 ''Length'' is the total length of the packet (header and data) in bytes, and ''Checksum'' holds an optional checksum.

The header of a UDP packet is represented in the kernel by the following data structure:

Continue reading here: Info

Was this article helpful?

0 0