Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


Consistency check

Find socket in udptable

Send Destination unreachable message

Yes

No

udp_rcv

_ _udp4_lib_rcv

_ _udp4_lib_lookup

Destination socket found? udp_queue_rcv_skb sock_queue_rcv_skb

Figure 12-23: Code flow diagram forudp_rcv.

Source Port Destination Port
Length Checksum

Payload

0 16 32

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 (headeranddata) in bytes, and ‘‘Checksum’’ holds an optional checksum.

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

<udp.h>
struct udphdr {
__be16 source;
__be16 dest;
__be16 len;
__be16 check;
};

__udp4_lib_lookupfromnet/ipv4/udp.cis used to find a kernel-internal socket to which the packet is
sent. They employ a hashing method to find and return an instance of thesockstructure in theudphash
global array when a listening process is interested in the packet. If they cannot find a socket, they send a
destination unreachablemessage to the original system, and the contents of the packet are discarded.

Although I have not yet discussed thesockstructure, it inevitably brings the termsocketto mind, exactly
as is intended. As we are on the borderline of the application layer, the data must be passed to userspace
at some time or other using sockets as described in the sample programs at the beginning of the chapter.

(^25) The IP address need not be specified because it is already in the IP header.

Free download pdf