OPNsense - FreeBSD source
Find a file
Gleb Smirnoff 69c05f4287 udp: make sendto(2) on unconnected UDP socket use public inpcb KPIs
UDP allows to sendto(2) on unconnected socket.  The original BSD devise
was that such action would create a temporary (for the duration of the
syscall) connection between our inpcb and remote addr:port specified in
sockaddr 'to' of the syscall.  This devise was broken in 2002 in
90162a4e87.  For more motivation on the removal of the temporary
connection see email [1].

Since the removal of the true temporary connection the sendto(2) on
unconnected socket has the following side effects:

1) After first sendto(2) the "unconnected" socket will receive datagrams
   destined to the selected port.
2) All subsequent sendto(2) calls will use the same source port.

Effectively, such sendto(2) acts like a bind(2) to INADDR_ANY:0.  Indeed,
if you do this:

	s1 = socket(PF_INET, SOCK_DGRAM, 0);
	s2 = socket(PF_INET, SOCK_DGRAM, 0);
	sendto(s1, ..., &somedestination, ...);
	bind(s2, &{ .sin_addr = INADDR_ANY, sin_port = 0 });

And then look into kgdb at resulting inpcbs, you would find them equal in
all means modulo bound to different anonymous ports.

What is even more interesting is that Linux kernel had picked up same
behavior, including that "unconnected" socket will receive datagrams.  So
it seems that such behavior is now an undocumented standard, thus I
covered it in recently added tests/sys/netinet/udp_bindings.

Now, with the above knowledge at hand, why are we using
in_pcbconnect_setup() and in_pcbinshash(), which are supposed to be
private to in_pcb.c, to achieve the binding?  Let's use public KPI
in_pcbbind() on the first sendto(2) and use in_pcbladdr() on all
sendto(2)s.  Apart from finally hiding these two should be private
functions, we no longer acquire global INP_HASH_WLOCK() for every
sendto(2) on unconnected socket as well as remove a couple workarounds.

[1] https://mail-archive.FreeBSD.org/cgi/mid.cgi?200210141935.aa83883

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D49043
2025-02-21 18:11:17 -08:00
.cirrus-ci Cirrus-CI: add some timing info on pkg install failure 2021-08-04 15:02:00 -04:00
.github github: Add new checklist workflow 2025-01-24 15:27:08 -05:00
bin csh: Remove gethost dependency on tc.const.h 2025-02-08 19:30:55 -05:00
cddl zfs: merge openzfs/zfs@6a2f7b384 2025-02-20 17:40:55 +01:00
contrib ntp: Another patch to address IPv6 pool regression 2025-02-18 09:11:45 -08:00
crypto ssh: Remove reference to now-upstreamed patch 2025-02-20 18:41:14 -05:00
etc mtree: Add missing flua/freebsd/sys entry 2025-02-05 19:53:23 +00:00
gnu Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
include rpc: limited multithread support for svc_nl 2025-02-01 01:00:28 -08:00
kerberos5 Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
lib libefivar: Add Display Only format for Hard Drive 2025-02-20 20:14:26 +00:00
libexec libsys: Don't create or expose __realpathat 2025-02-19 20:05:47 +00:00
release pkg-stage.sh: kde5 -> kde 2025-02-19 11:24:06 -08:00
rescue nvmf: Switch several ioctls to using nvlists 2024-12-30 13:52:21 -05:00
sbin nvmecontrol: Add more keys for CA page (Additional smart data) 2025-02-21 17:23:44 -07:00
secure ssh: Consolidate HAVE_LDNS / LIBWRAP in ssh.mk 2025-02-20 18:33:46 -05:00
share pf.conf.5: rephrase log() documentation 2025-02-21 09:11:03 +01:00
stand loader.efi: add "gop blt <on|off>" command 2025-02-20 21:50:20 +02:00
sys udp: make sendto(2) on unconnected UDP socket use public inpcb KPIs 2025-02-21 18:11:17 -08:00
targets gvinum(8): Remove userland tool for managing vinum volumes 2025-01-23 11:20:43 -05:00
tests tests/netinet: add few tests for sending a broadcast packet 2025-02-21 18:11:12 -08:00
tools wlanstats: move from tools to usr.sbin 2025-02-19 02:56:59 +00:00
usr.bin shar: Make sure a sed failure in the generated archive results in failure 2025-02-18 09:16:48 -08:00
usr.sbin snmp_pf: fix rules->label use 2025-02-21 09:49:06 +01:00
.arcconfig arcanist: use FreeBSD/git project repository instead of FreeBSD/svn 2022-08-23 14:16:41 +00:00
.arclint arc lint: ignore /tests/ in chmod 2017-12-19 03:38:06 +00:00
.cirrus.yml Cirrus-CI: Bump image to (supported) 13.4 2025-02-21 13:49:42 -05:00
.clang-format clang-format: Minor tweaks 2024-04-30 17:33:43 -04:00
.git-blame-ignore-revs git-blame-ignore-revs: list rtld-elf reformatting 2025-01-21 03:57:21 +02:00
.gitattributes Remove SVN related Git attributes 2023-12-26 10:28:28 -07:00
.gitignore .gitignore: add sys/*/compile 2024-02-02 09:20:36 -07:00
.mailmap mailmap: Translate my personal address 2024-06-22 08:57:56 +02:00
CONTRIBUTING.md CONTRIBUTING.md/style: spring cleaning 2024-05-10 15:07:03 -06:00
COPYRIGHT copyright: Happy New Year 2025 2025-01-01 00:04:28 +00:00
LOCKS Update LOCKS for Git 2023-12-26 10:28:25 -07:00
MAINTAINERS man filesystems: fix more xrefs after move to s4 2024-06-27 18:32:05 -06:00
Makefile Makefile: Fix several issues with bmake upgrade 2025-01-29 19:17:09 +00:00
Makefile.inc1 sys: syscalls: add a test syscall definition file 2025-02-18 22:02:19 +00:00
Makefile.libcompat Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
Makefile.sys.inc Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
ObsoleteFiles.inc ObsoleteFiles.inc: Remove test debug file from wrong dir 2025-02-13 17:05:33 +00:00
README.md Update README.md to add pointer to release page. 2024-05-09 20:40:46 -06:00
RELNOTES RELNOTES: document pf's ABI breakage 2025-02-18 16:53:12 +01:00
UPDATING UPDATING: Add entry for commit 4517fbfd42 2025-02-14 13:08:58 -08:00

FreeBSD Source:

This is the top level of the FreeBSD source directory.

FreeBSD is an operating system used to power modern servers, desktops, and embedded platforms. A large community has continually developed it for more than thirty years. Its advanced networking, security, and storage features have made FreeBSD the platform of choice for many of the busiest web sites and most pervasive embedded networking and storage devices.

For copyright information, please see the file COPYRIGHT in this directory. Additional copyright information also exists for some sources in this tree - please see the specific source directories for more information.

The Makefile in this directory supports a number of targets for building components (or all) of the FreeBSD source tree. See build(7), config(8), FreeBSD handbook on building userland, and Handbook for kernels for more information, including setting make(1) variables.

For information on the CPU architectures and platforms supported by FreeBSD, see the FreeBSD website's Platforms page.

For official FreeBSD bootable images, see the release page.

Source Roadmap:

Directory Description
bin System/user commands.
cddl Various commands and libraries under the Common Development and Distribution License.
contrib Packages contributed by 3rd parties.
crypto Cryptography stuff (see crypto/README).
etc Template files for /etc.
gnu Commands and libraries under the GNU General Public License (GPL) or Lesser General Public License (LGPL). Please see gnu/COPYING and gnu/COPYING.LIB for more information.
include System include files.
kerberos5 Kerberos5 (Heimdal) package.
lib System libraries.
libexec System daemons.
release Release building Makefile & associated tools.
rescue Build system for statically linked /rescue utilities.
sbin System commands.
secure Cryptographic libraries and commands.
share Shared resources.
stand Boot loader sources.
sys Kernel sources (see sys/README.md).
targets Support for experimental DIRDEPS_BUILD
tests Regression tests which can be run by Kyua. See tests/README for additional information.
tools Utilities for regression testing and miscellaneous tasks.
usr.bin User commands.
usr.sbin System administration commands.

For information on synchronizing your source tree with one or more of the FreeBSD Project's development branches, please see FreeBSD Handbook.