git: e044a0bce495 - main - bblog: inherit TCP_LOG option from listener

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Sat, 06 May 2023 09:23:49 UTC
The branch main has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=e044a0bce4953ed9a98af73fa98dd16d04a9c5ed

commit e044a0bce4953ed9a98af73fa98dd16d04a9c5ed
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2023-05-06 09:21:16 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2023-05-06 09:21:16 +0000

    bblog: inherit TCP_LOG option from listener
    
    When the TCP_LOG option is used to enable logging on a listening
    socket, inherit this if the listener is not auto selected and does
    not have a log id set.
    
    Reviewed by:            cc
    MFC after:              1 week
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D38436
---
 sys/netinet/tcp_syncache.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c
index 54a347c2669e..5fc63d42b21a 100644
--- a/sys/netinet/tcp_syncache.c
+++ b/sys/netinet/tcp_syncache.c
@@ -90,6 +90,9 @@ __FBSDID("$FreeBSD$");
 #include <netinet/tcp_var.h>
 #include <netinet/tcp_syncache.h>
 #include <netinet/tcp_ecn.h>
+#ifdef TCP_BLACKBOX
+#include <netinet/tcp_log_buf.h>
+#endif
 #ifdef TCP_OFFLOAD
 #include <netinet/toecore.h>
 #endif
@@ -1013,6 +1016,20 @@ syncache_socket(struct syncache *sc, struct socket *lso, struct mbuf *m)
 
 		tod->tod_offload_socket(tod, sc->sc_todctx, so);
 	}
+#endif
+#ifdef TCP_BLACKBOX
+	/*
+	 * Inherit the log state from the listening socket, if
+	 * - the log state of the listening socket is not off and
+	 * - the listening socket was not auto selected from all sessions and
+	 * - a log id is not set on the listening socket.
+	 * This avoids inheriting a log state which was automatically set.
+	 */
+	if ((tcp_get_bblog_state(sototcpcb(lso)) != TCP_LOG_STATE_OFF) &&
+	    ((sototcpcb(lso)->t_flags2 & TF2_LOG_AUTO) == 0) &&
+	    (sototcpcb(lso)->t_lib == NULL)) {
+		tcp_log_state_change(tp, tcp_get_bblog_state(sototcpcb(lso)));
+	}
 #endif
 	/*
 	 * Copy and activate timers.