aboutsummaryrefslogtreecommitdiff
path: root/contrib/groff/devdvi/I
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2025-02-22 02:11:17 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2025-02-22 02:11:17 +0000
commit69c05f42871406b4b2b2dac00a268d1da0cacd3e (patch)
treeccbd4b49830baffcc58968922e466f551acf14e1 /contrib/groff/devdvi/I
parentad77d3177f3ef3de8ee503f7f204919a292d6818 (diff)
udp: make sendto(2) on unconnected UDP socket use public inpcb KPIsHEADmain
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 90162a4e87f0. 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
Diffstat (limited to 'contrib/groff/devdvi/I')
0 files changed, 0 insertions, 0 deletions