Page MenuHomeFreeBSD

D33098.id98885.diff
No OneTemporary

D33098.id98885.diff

diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -101,6 +101,9 @@
#endif
#include <netinet/tcp.h>
+#ifdef INVARIANTS
+#define TCPSTATES
+#endif
#include <netinet/tcp_fsm.h>
#include <netinet/tcp_seq.h>
#include <netinet/tcp_timer.h>
@@ -1755,9 +1758,12 @@
int isipv6;
#endif /* INET6 */
int optlen, tlen, win, ulen;
- bool incl_opts, lock_upgraded;
+ bool incl_opts;
uint16_t port;
int output_ret;
+#ifdef INVARIANTS
+ int thflags = th->th_flags;
+#endif
KASSERT(tp != NULL || m != NULL, ("tcp_respond: tp and m both NULL"));
NET_EPOCH_ASSERT();
@@ -2088,17 +2094,11 @@
TCP_PROBE3(debug__output, tp, th, m);
if (flags & TH_RST)
TCP_PROBE5(accept__refused, NULL, NULL, m, tp, nth);
- lock_upgraded = false;
lgb = NULL;
if ((tp != NULL) && (tp->t_logstate != TCP_LOG_STATE_OFF)) {
union tcp_log_stackspecific log;
struct timeval tv;
- lock_upgraded = !INP_WLOCKED(inp) && INP_TRY_UPGRADE(inp);
- /*
- *`If we don't already own the write lock and can't upgrade,
- * just don't log the event, but still send the response.
- */
if (INP_WLOCKED(inp)) {
memset(&log.u_bbr, 0, sizeof(log.u_bbr));
log.u_bbr.inhpts = tp->t_inpcb->inp_in_hpts;
@@ -2109,6 +2109,23 @@
log.u_bbr.delivered = 0;
lgb = tcp_log_event_(tp, nth, NULL, NULL, TCP_LOG_OUT, ERRNO_UNK,
0, &log, false, NULL, NULL, 0, &tv);
+ } else {
+ /*
+ * We can not log the packet, since we only own the
+ * read lock, but a write lock is needed.
+ * This happens only for pure SYN segments received in
+ * the initial CLOSED state or received in a state
+ * later then listen is the UDP encapsulation port is
+ * unexpected.
+ * Ensure that the above description is and stays
+ * correct.
+ */
+ KASSERT(((thflags & (TH_ACK|TH_SYN)) == TH_SYN) &&
+ ((tp->t_state == TCPS_CLOSED) ||
+ ((tp->t_state > TCPS_LISTEN) && (tp->t_port != port))),
+ ("%s: Logging of TCP segment with flags 0x%b and UDP encapsulation port %u skipped in state %s",
+ __func__, thflags, PRINT_TH_FLAGS,
+ ntohs(port), tcpstates[tp->t_state]));
}
}
@@ -2129,8 +2146,6 @@
#endif
if (lgb != NULL)
lgb->tlb_errno = output_ret;
- if (lock_upgraded)
- INP_DOWNGRADE(inp);
}
/*

File Metadata

Mime Type
text/plain
Expires
Thu, Aug 20, 6:21 PM (9 m, 32 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37005705
Default Alt Text
D33098.id98885.diff (2 KB)

Event Timeline