WSL2-Linux-Kernel/Documentation
Kuniyuki Iwashima 4b01a96742 tcp: bind(0) remove the SO_REUSEADDR restriction when ephemeral ports are exhausted.
Commit aacd9289af ("tcp: bind() use stronger
condition for bind_conflict") introduced a restriction to forbid to bind
SO_REUSEADDR enabled sockets to the same (addr, port) tuple in order to
assign ports dispersedly so that we can connect to the same remote host.

The change results in accelerating port depletion so that we fail to bind
sockets to the same local port even if we want to connect to the different
remote hosts.

You can reproduce this issue by following instructions below.

  1. # sysctl -w net.ipv4.ip_local_port_range="32768 32768"
  2. set SO_REUSEADDR to two sockets.
  3. bind two sockets to (localhost, 0) and the latter fails.

Therefore, when ephemeral ports are exhausted, bind(0) should fallback to
the legacy behaviour to enable the SO_REUSEADDR option and make it possible
to connect to different remote (addr, port) tuples.

This patch allows us to bind SO_REUSEADDR enabled sockets to the same
(addr, port) only when net.ipv4.ip_autobind_reuse is set 1 and all
ephemeral ports are exhausted. This also allows connect() and listen() to
share ports in the following way and may break some applications. So the
ip_autobind_reuse is 0 by default and disables the feature.

  1. setsockopt(sk1, SO_REUSEADDR)
  2. setsockopt(sk2, SO_REUSEADDR)
  3. bind(sk1, saddr, 0)
  4. bind(sk2, saddr, 0)
  5. connect(sk1, daddr)
  6. listen(sk2)

If it is set 1, we can fully utilize the 4-tuples, but we should use
IP_BIND_ADDRESS_NO_PORT for bind()+connect() as possible.

The notable thing is that if all sockets bound to the same port have
both SO_REUSEADDR and SO_REUSEPORT enabled, we can bind sockets to an
ephemeral port and also do listen().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-03-12 12:08:09 -07:00
..
ABI xen: branch for v5.6-rc1 2020-02-05 17:44:14 +00:00
EDID
PCI
RCU Merge branches 'doc.2019.12.10a', 'exp.2019.12.09a', 'fixes.2020.01.24a', 'kfree_rcu.2020.01.24a', 'list.2020.01.10a', 'preempt.2020.01.24a' and 'torture.2019.12.09a' into HEAD 2020-01-24 10:37:27 -08:00
accounting
admin-guide Tracing updates: 2020-02-26 10:34:42 -08:00
arm
arm64 mm: Avoid creating virtual address aliases in brk()/mmap()/mremap() 2020-02-20 10:03:14 +00:00
block
bpf docs/bpf: Update bpf development Q/A file 2020-02-20 18:05:37 -08:00
cdrom
core-api mm, tree-wide: rename put_user_page*() to unpin_user_page*() 2020-01-31 10:30:38 -08:00
cpu-freq
crypto
dev-tools Documentation: kunit: fixed sphinx error in code block 2020-02-10 17:16:42 -07:00
devicetree dt-bindings: soc: qcom: fix IPA binding 2020-03-12 00:05:45 -07:00
doc-guide Documentation: build warnings related to missing blank lines after explicit markups has been fixed 2020-02-05 10:30:03 -07:00
driver-api Minor bug fixes for IPMI 2020-02-16 13:05:46 -08:00
fault-injection
fb
features s390 updates for the 5.6 merge window #2 2020-02-05 17:33:35 +00:00
filesystems zonefs: fix documentation typos etc. 2020-02-21 18:09:26 +09:00
firmware-guide
firmware_class
fpga
gpu
hid
hwmon Documentation/hwmon: fix xdpe12284 Sphinx warnings 2020-02-17 14:20:55 -08:00
i2c docs: i2c: writing-clients: properly name the stop condition 2020-01-29 22:02:09 +01:00
ia64
ide
iio
infiniband
input
isdn
kbuild kbuild: get rid of trailing slash from subdir- example 2020-02-27 10:03:27 +09:00
kernel-hacking
leds
livepatch
locking docs/locking: Fix outdated section names 2020-02-05 10:21:12 -07:00
m68k
maintainer Add a maintainer entry profile for documentation 2020-01-24 09:48:39 -07:00
media media updates for v5.6-rc1 2020-01-31 14:43:23 -08:00
mic
mips
misc-devices
netlabel
networking tcp: bind(0) remove the SO_REUSEADDR restriction when ephemeral ports are exhausted. 2020-03-12 12:08:09 -07:00
nios2
nvdimm docs: nvdimm: use ReST notation for subsection 2020-01-24 09:54:42 -07:00
openrisc
parisc
pcmcia
power Documentation: admin-guide: PM: Update sleep states documentation 2020-02-03 11:58:26 +01:00
powerpc powerpc updates for 5.6 2020-02-04 13:06:46 +00:00
process Documentation/process: Swap out the ambassador for Canonical 2020-02-13 15:38:41 -08:00
riscv It has been a relatively quiet cycle for documentation, but there's still a 2020-01-29 15:27:31 -08:00
s390
scheduler
scsi
security
sh
sound sound updates for 5.6-rc1 2020-01-28 16:26:57 -08:00
sparc
sphinx docs: Fix empty parallelism argument 2020-02-25 03:11:04 -07:00
sphinx-static
spi
target
timers
trace A handful of small documentation fixes that wandered in. 2020-02-07 13:03:10 -08:00
translations Documentation/process: Swap out the ambassador for Canonical 2020-02-13 15:38:41 -08:00
usb docs: usb: remove some broken references 2020-01-28 13:41:22 -07:00
userspace-api
virt KVM: s390: rstify new ioctls in api.rst 2020-02-24 19:28:40 +01:00
vm mm/zswap.c: add allocation hysteresis if pool limit is hit 2020-01-31 10:30:39 -08:00
w1
watchdog
x86 docs: remove MPX from the x86 toc 2020-02-25 03:10:22 -07:00
xtensa
.gitignore
COPYING-logo
Changes
CodingStyle
DMA-API-HOWTO.txt
DMA-API.txt
DMA-ISA-LPC.txt
DMA-attributes.txt
IPMI.txt
IRQ-affinity.txt
IRQ-domain.txt
IRQ.txt
Kconfig
Makefile
SubmittingPatches
asm-annotations.rst
atomic_bitops.txt
atomic_t.txt
bus-virt-phys-mapping.txt
conf.py
crc32.txt
debugging-modules.txt
debugging-via-ohci1394.txt
digsig.txt
docutils.conf
dontdiff
futex-requeue-pi.txt
hwspinlock.txt
index.rst
io-mapping.txt
io_ordering.txt
irqflags-tracing.txt
kobject.txt
kprobes.txt
kref.txt
logo.gif
lzo.txt
mailbox.txt
memory-barriers.txt smp_mb__{before,after}_atomic(): update Documentation 2020-02-04 03:05:23 +00:00
nommu-mmap.txt
percpu-rw-semaphore.txt
pi-futex.txt
preempt-locking.txt
rbtree.txt
remoteproc.txt
robust-futex-ABI.txt
robust-futexes.txt
rpmsg.txt
speculation.txt
static-keys.txt
tee.txt
this_cpu_ops.txt
unaligned-memory-access.txt
xz.txt