<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src/sys/netinet/tcp_usrreq.c, branch stable/14</title>
<subtitle>FreeBSD source tree</subtitle>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/'/>
<entry>
<title>ddb: use %b when showing flags for a tcpcb</title>
<updated>2025-11-10T19:41:45+00:00</updated>
<author>
<name>Michael Tuexen</name>
<email>tuexen@FreeBSD.org</email>
</author>
<published>2025-11-02T16:15:47+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=3f75cdcd397995262f9e8a2a59250d43cd88d459'/>
<id>3f75cdcd397995262f9e8a2a59250d43cd88d459</id>
<content type='text'>
This is much more compact. Thanks to markj@ for suggesting the change.

Reviewed by:		markj, Peter Lei, imp, Nick Banks
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53510

(cherry picked from commit 8e8956f7f99759b21bc07e884ad89d1927c39e8d)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is much more compact. Thanks to markj@ for suggesting the change.

Reviewed by:		markj, Peter Lei, imp, Nick Banks
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53510

(cherry picked from commit 8e8956f7f99759b21bc07e884ad89d1927c39e8d)
</pre>
</div>
</content>
</entry>
<entry>
<title>ddb: optionally print inp when printing tcpcb</title>
<updated>2025-11-10T19:32:05+00:00</updated>
<author>
<name>Michael Tuexen</name>
<email>tuexen@FreeBSD.org</email>
</author>
<published>2025-10-31T18:05:02+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=117e70a21f7a950395e97f6b352867b6767f5dbc'/>
<id>117e70a21f7a950395e97f6b352867b6767f5dbc</id>
<content type='text'>
Add /i option to the ddb commands show tcpcb and show all tcpcbs,
which enables the printing of the t_inpcb.

Reviewed by:		markj
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53497

(cherry picked from commit 9aa5a79e2af9a6a8930bbe8a7a024df2cf44e433)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add /i option to the ddb commands show tcpcb and show all tcpcbs,
which enables the printing of the t_inpcb.

Reviewed by:		markj
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53497

(cherry picked from commit 9aa5a79e2af9a6a8930bbe8a7a024df2cf44e433)
</pre>
</div>
</content>
</entry>
<entry>
<title>ddb: fix handling of BBLog entries when BBLog is disabled</title>
<updated>2025-09-04T20:02:16+00:00</updated>
<author>
<name>Michael Tuexen</name>
<email>tuexen@FreeBSD.org</email>
</author>
<published>2025-06-10T16:32:39+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=9506da19ca73f54c277ffa9fd89a774a6117d2d0'/>
<id>9506da19ca73f54c277ffa9fd89a774a6117d2d0</id>
<content type='text'>
Fixes:		a62c6b0de48a ("ddb: add optional printing of BBLog entries")
Sponsored by:	Netflix, Inc.

(cherry picked from commit 0dc78204a7dcbc51bfab4c701e1335084548bc05)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Fixes:		a62c6b0de48a ("ddb: add optional printing of BBLog entries")
Sponsored by:	Netflix, Inc.

(cherry picked from commit 0dc78204a7dcbc51bfab4c701e1335084548bc05)
</pre>
</div>
</content>
</entry>
<entry>
<title>ddb: add optional printing of BBLog entries</title>
<updated>2025-09-04T20:01:26+00:00</updated>
<author>
<name>Michael Tuexen</name>
<email>tuexen@FreeBSD.org</email>
</author>
<published>2025-06-10T13:29:26+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=aded5f4203ec7aa3bd86d6c05be6b20714a2136c'/>
<id>aded5f4203ec7aa3bd86d6c05be6b20714a2136c</id>
<content type='text'>
Add a /b option to show tcpcb and show all tcpcbs to print BBLog
entries. Right now this supports the entries generated by the
FreeBSD default TCP stack. It should help in debugging issues
reported by syzkaller.
The syntax for printing sent and received packets is similar to the
one used by packetdrill, since the output of ddb will be used to
create packetdrill scripts for debugging.

Reviewed by:		thj
Tested by:		thj
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D50629

(cherry picked from commit a62c6b0de48a5b9b752976b2675ac807684b7fdb)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add a /b option to show tcpcb and show all tcpcbs to print BBLog
entries. Right now this supports the entries generated by the
FreeBSD default TCP stack. It should help in debugging issues
reported by syzkaller.
The syntax for printing sent and received packets is similar to the
one used by packetdrill, since the output of ddb will be used to
create packetdrill scripts for debugging.

Reviewed by:		thj
Tested by:		thj
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D50629

(cherry picked from commit a62c6b0de48a5b9b752976b2675ac807684b7fdb)
</pre>
</div>
</content>
</entry>
<entry>
<title>ddb: add show all tcpcbs</title>
<updated>2025-09-04T20:00:15+00:00</updated>
<author>
<name>Michael Tuexen</name>
<email>tuexen@FreeBSD.org</email>
</author>
<published>2025-05-28T10:25:26+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=6e95753ac51716aec45cef049e1493d3c96874b1'/>
<id>6e95753ac51716aec45cef049e1493d3c96874b1</id>
<content type='text'>
Add a command to show all TCP control blocks. Also provide an option
to limit the output to TCP control blocks, which are locked.
The plan is to run show all tcpcbs/l when syzkaller triggers a panic.
If a TCP control block is affected, it is most likely locked and
therefore the command shows the information of the affected TCP
control block.

Reviewed by:		markj, thj
Tested by:		thj
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D50516

(cherry picked from commit f1430567f26bc84db3818914fa91c74507d1602a)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add a command to show all TCP control blocks. Also provide an option
to limit the output to TCP control blocks, which are locked.
The plan is to run show all tcpcbs/l when syzkaller triggers a panic.
If a TCP control block is affected, it is most likely locked and
therefore the command shows the information of the affected TCP
control block.

Reviewed by:		markj, thj
Tested by:		thj
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D50516

(cherry picked from commit f1430567f26bc84db3818914fa91c74507d1602a)
</pre>
</div>
</content>
</entry>
<entry>
<title>ddb: improve show tcpcb</title>
<updated>2025-09-04T19:59:42+00:00</updated>
<author>
<name>Michael Tuexen</name>
<email>tuexen@FreeBSD.org</email>
</author>
<published>2025-05-28T10:10:51+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=ca0fcea09cf47ca8ebf37d0b90db5f66843e11cc'/>
<id>ca0fcea09cf47ca8ebf37d0b90db5f66843e11cc</id>
<content type='text'>
Print the name of the TCP function block and the name of the
congestion control algorithm. Furthermore, print some information
related to Black Box Logging.

Reviewed by:		thj
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D50535

(cherry picked from commit 8d4f495df46567dcfcbec59794e9b9137b2f38fe)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Print the name of the TCP function block and the name of the
congestion control algorithm. Furthermore, print some information
related to Black Box Logging.

Reviewed by:		thj
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D50535

(cherry picked from commit 8d4f495df46567dcfcbec59794e9b9137b2f38fe)
</pre>
</div>
</content>
</entry>
<entry>
<title>tcp: don't ever return ECONNRESET on close(2)</title>
<updated>2025-03-31T17:31:21+00:00</updated>
<author>
<name>Gleb Smirnoff</name>
<email>glebius@FreeBSD.org</email>
</author>
<published>2024-12-23T18:35:49+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=1bda3fae784ecb6e227220d20088cfde5f19eed6'/>
<id>1bda3fae784ecb6e227220d20088cfde5f19eed6</id>
<content type='text'>
The SUS doesn't mention this error code as a possible one [1]. The FreeBSD
manual page specifies a possible ECONNRESET for close(2):

[ECONNRESET]	The underlying object was a stream socket that was
		shut down by the peer before all pending data was
		delivered.

In the past it had been EINVAL (see 21367f630d72), and this EINVAL was
added as a safety measure in 623dce13c64ef.  After conversion to
ECONNRESET it had been documented in the manual page in 78e3a7fdd51e6, but
I bet wasn't ever tested to actually be ever returned, cause the
tcp-testsuite[2] didn't exist back then.  So documentation is incorrect
since 2006, if my bet wins.  Anyway, in the modern FreeBSD the condition
described above doesn't end up with ECONNRESET error code from close(2).
The error condition is reported via SO_ERROR socket option, though.  This
can be checked using the tcp-testsuite, temporarily disabling the
getsockopt(SO_ERROR) lines using sed command [3].  Most of these
getsockopt(2)s are followed by '+0.00 close(3) = 0', which will confirm
that close(2) doesn't return ECONNRESET even on a socket that has the
error stored, neither it is returned in the case described in the manual
page.  The latter case is covered by multiple tests residing in tcp-
testsuite/state-event-engine/rcv-rst-*.

However, the deleted block of code could be entered in a race condition
between close(2) and processing of incoming packet, when connection had
already been half-closed with shutdown(SHUT_WR) and sits in TCPS_LAST_ACK.
This was reported in the bug 146845.  With the block deleted, we will
continue into tcp_disconnect() which has proper handling of INP_DROPPED.

The race explanation follows.  The connection is in TCPS_LAST_ACK.  The
network input thread acquires the tcpcb lock first, sets INP_DROPPED,
acquires the socket lock in soisdisconnected() and clears SS_ISCONNECTED.
Meanwhile, the syscall thread goes through sodisconnect() which checks for
SS_ISCONNECTED locklessly(!).  The check passes and the thread blocks on
the tcpcb lock in tcp_usr_disconnect().  Once input thread releases the
lock, the syscall thread observes INP_DROPPED and returns ECONNRESET.

- Thread 1: tcp_do_segment()-&gt;tcp_close()-&gt;in_pcbdrop(),soisdisconnected()
- Thread 2: sys_close()...-&gt;soclose()-&gt;sodisconnect()-&gt;tcp_usr_disconnect()

Note that the lockless operation in sodisconnect() isn't correct, but
enforcing the socket lock there will not fix the problem.

[1] https://pubs.opengroup.org/onlinepubs/9799919799/
[2] https://github.com/freebsd-net/tcp-testsuite
[3] sed -i "" -Ee '/\+0\.00 getsockopt\(3, SOL_SOCKET, SO_ERROR, \[ECONNRESET\]/d' $(grep -lr ECONNRESET tcp-testsuite)

PR:			146845
Reviewed by:		tuexen, rrs, imp
Differential Revision:	https://reviews.freebsd.org/D48148

(cherry picked from commit 053a988497342a6fd0a717cc097d09c23f83e103)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The SUS doesn't mention this error code as a possible one [1]. The FreeBSD
manual page specifies a possible ECONNRESET for close(2):

[ECONNRESET]	The underlying object was a stream socket that was
		shut down by the peer before all pending data was
		delivered.

In the past it had been EINVAL (see 21367f630d72), and this EINVAL was
added as a safety measure in 623dce13c64ef.  After conversion to
ECONNRESET it had been documented in the manual page in 78e3a7fdd51e6, but
I bet wasn't ever tested to actually be ever returned, cause the
tcp-testsuite[2] didn't exist back then.  So documentation is incorrect
since 2006, if my bet wins.  Anyway, in the modern FreeBSD the condition
described above doesn't end up with ECONNRESET error code from close(2).
The error condition is reported via SO_ERROR socket option, though.  This
can be checked using the tcp-testsuite, temporarily disabling the
getsockopt(SO_ERROR) lines using sed command [3].  Most of these
getsockopt(2)s are followed by '+0.00 close(3) = 0', which will confirm
that close(2) doesn't return ECONNRESET even on a socket that has the
error stored, neither it is returned in the case described in the manual
page.  The latter case is covered by multiple tests residing in tcp-
testsuite/state-event-engine/rcv-rst-*.

However, the deleted block of code could be entered in a race condition
between close(2) and processing of incoming packet, when connection had
already been half-closed with shutdown(SHUT_WR) and sits in TCPS_LAST_ACK.
This was reported in the bug 146845.  With the block deleted, we will
continue into tcp_disconnect() which has proper handling of INP_DROPPED.

The race explanation follows.  The connection is in TCPS_LAST_ACK.  The
network input thread acquires the tcpcb lock first, sets INP_DROPPED,
acquires the socket lock in soisdisconnected() and clears SS_ISCONNECTED.
Meanwhile, the syscall thread goes through sodisconnect() which checks for
SS_ISCONNECTED locklessly(!).  The check passes and the thread blocks on
the tcpcb lock in tcp_usr_disconnect().  Once input thread releases the
lock, the syscall thread observes INP_DROPPED and returns ECONNRESET.

- Thread 1: tcp_do_segment()-&gt;tcp_close()-&gt;in_pcbdrop(),soisdisconnected()
- Thread 2: sys_close()...-&gt;soclose()-&gt;sodisconnect()-&gt;tcp_usr_disconnect()

Note that the lockless operation in sodisconnect() isn't correct, but
enforcing the socket lock there will not fix the problem.

[1] https://pubs.opengroup.org/onlinepubs/9799919799/
[2] https://github.com/freebsd-net/tcp-testsuite
[3] sed -i "" -Ee '/\+0\.00 getsockopt\(3, SOL_SOCKET, SO_ERROR, \[ECONNRESET\]/d' $(grep -lr ECONNRESET tcp-testsuite)

PR:			146845
Reviewed by:		tuexen, rrs, imp
Differential Revision:	https://reviews.freebsd.org/D48148

(cherry picked from commit 053a988497342a6fd0a717cc097d09c23f83e103)
</pre>
</div>
</content>
</entry>
<entry>
<title>tcp: Add a sysctl to modify listening socket FIB inheritance</title>
<updated>2025-02-21T01:04:50+00:00</updated>
<author>
<name>Mark Johnston</name>
<email>markj@FreeBSD.org</email>
</author>
<published>2025-02-06T14:14:49+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=aa6163ff658b65f4a58d7603a7f7cfd1c39ee086'/>
<id>aa6163ff658b65f4a58d7603a7f7cfd1c39ee086</id>
<content type='text'>
Introduce the net.inet.tcp.bind_all_fibs tunable, set to 1 by default
for compatibility with current behaviour.  When set to 0, all TCP
listening sockets are private to their FIB.  Inbound connection requests
will only succeed if a matching inpcb is bound to the same FIB as the
request.

No functional change intended, as the new behaviour is not enabled by
default.

Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48663

(cherry picked from commit 5dc99e9bb985dce58e8fc85c09ef4e49bf051971)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Introduce the net.inet.tcp.bind_all_fibs tunable, set to 1 by default
for compatibility with current behaviour.  When set to 0, all TCP
listening sockets are private to their FIB.  Inbound connection requests
will only succeed if a matching inpcb is bound to the same FIB as the
request.

No functional change intended, as the new behaviour is not enabled by
default.

Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48663

(cherry picked from commit 5dc99e9bb985dce58e8fc85c09ef4e49bf051971)
</pre>
</div>
</content>
</entry>
<entry>
<title>inpcb: Add a flags parameter to in_pcbbind()</title>
<updated>2025-02-21T01:04:49+00:00</updated>
<author>
<name>Mark Johnston</name>
<email>markj@FreeBSD.org</email>
</author>
<published>2025-02-06T14:14:23+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=ff45a1ca2e7a06cbbae3722f0a37733421d07023'/>
<id>ff45a1ca2e7a06cbbae3722f0a37733421d07023</id>
<content type='text'>
Add a flag, INPBIND_FIB, which means that the inpcb is local to its FIB
number.  When this flag is specified, duplicate bindings are permitted,
so long as each FIB contains at most one inpcb bound to the same
address/port.  If an inpcb is bound with this flag, it'll have the
INP_BOUNDFIB flag set.

No functional change intended.

Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48661

(cherry picked from commit bbd0084baf7539c7042ce94f8c6770210f83f765)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add a flag, INPBIND_FIB, which means that the inpcb is local to its FIB
number.  When this flag is specified, duplicate bindings are permitted,
so long as each FIB contains at most one inpcb bound to the same
address/port.  If an inpcb is bound with this flag, it'll have the
INP_BOUNDFIB flag set.

No functional change intended.

Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48661

(cherry picked from commit bbd0084baf7539c7042ce94f8c6770210f83f765)
</pre>
</div>
</content>
</entry>
<entry>
<title>ddb: update printing of t_flags and tflags2</title>
<updated>2024-08-13T17:05:06+00:00</updated>
<author>
<name>Michael Tuexen</name>
<email>tuexen@FreeBSD.org</email>
</author>
<published>2024-08-05T09:17:30+00:00</published>
<link rel='alternate' type='text/html' href='http://cgit.freebsd.org/src/commit/?id=f18b9b2b95fd5feeb5372a8e0d2ff1eb0bd64891'/>
<id>f18b9b2b95fd5feeb5372a8e0d2ff1eb0bd64891</id>
<content type='text'>
Update the ddb printing of t_flags and t_flags2 to the current state of
definitions in tcp_var.h.

Reviewed by:		cc
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D46222

(cherry picked from commit 093d9b46f4720392e53c171eaabfd7a6a8101170)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Update the ddb printing of t_flags and t_flags2 to the current state of
definitions in tcp_var.h.

Reviewed by:		cc
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D46222

(cherry picked from commit 093d9b46f4720392e53c171eaabfd7a6a8101170)
</pre>
</div>
</content>
</entry>
</feed>
