Which socket? UDP and TCP demultiplexing

Clients A, B (and D) send segments to server C. C looks at the header to choose the socket: UDP only looks at the destination (IP_D, PD); TCP looks at the four values (IP_O, PO, IP_D, PD). Follow each segment into the socket table of C.

Scenario

Transport protocol

Clients and ephemeral ports

The client’s OS chooses the source port from the ephemeral range. The new client (D, or a new connection of A, B or D) sends to the first port C listens on.

Mode

Practice

A random scenario with 4 to 6 segments, in prediction mode. Watch out for the same source port on two hosts and for ports where nobody listens.

View

Segments that reach C

Model assumptions
  • Addresses are written with letters (A, B, C, D), as in the slides. IP_O: source IP address; IP_D: destination IP address; PO: source port; PD: destination port.
  • UDP (connectionless): the socket is identified only by its destination (IP_D, PD). Segments with different origins and the same destination go to the same socket. The source port is used as the return address.
  • TCP (connection-oriented): the server has a welcome socket on the port it listens on, and one connection socket per simultaneous connection, identified by the four values (IP_O, PO, IP_D, PD). Here a segment with a new 4-tuple reaches the welcome socket, which creates the connection socket; how the connection is established is covered in GG32.
  • Processes: “one to one” is one process per connection (P0 holds the welcome socket and creates P4, P5…); “one to many” is one process with one thread per connection; event-driven (nginx, Node.js) is one process with many sockets. The number of sockets does not depend on it; the number of processes does.
  • The Protocol field of the IP header (6 = TCP, 17 = UDP) chooses the transport protocol before the port is looked at, so 443/TCP and 443/UDP are different sockets. A segment to a port where nobody listens with that protocol is discarded.
  • Ephemeral ports: the IANA range is 49152–65535; Linux uses 32768–60999 by default (net.ipv4.ip_local_port_range). Server ports are well known (80, 443…) or, as in the slides, fixed by the application (6428).