/plushcap/analysis/cloudflare/the-quantum-state-of-a-tcp-port

The quantum state of a TCP port

What's this blog post about?

The sharing of local port between TCP socket bindings and connect()'s can be a complicated affair in modern kernels such as those found on Linux systems. When trying to use the same local port for both bind() and connect(), one must keep in mind several factors that influence whether or not this is possible, including the fastreuse state of the bind bucket, as well as any existing owners of the desired local address. The situation can become even more complex when taking into account additional socket options such as SO_REUSEADDR and IP_BIND_ADDRESS_NO_PORT. To better understand these details, we have provided a detailed walkthrough using real-world examples and code snippets from the Linux kernel source code itself. Ultimately, while sharing local ports between bind() and connect() may be possible under certain circumstances, it is generally recommended to rely on the kernel's default behavior when assigning ports to avoid potential issues with reuse.

Company
Cloudflare

Date published
March 20, 2023

Author(s)
Jakub Sitnicki

Word count
2863

Hacker News points
182

Language
English


By Matt Makai. 2021-2024.