aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/tcp_log_buf.c
diff options
context:
space:
mode:
authorRandall Stewart <rrs@FreeBSD.org>2023-04-01 05:46:38 +0000
committerRandall Stewart <rrs@FreeBSD.org>2023-04-01 05:46:38 +0000
commit73ee5756dee6b2110eb6fb2b2ef3cde39a1fcb4f (patch)
tree32251ae7fe68feb89a31e29ff45abcaba7750f1a /sys/netinet/tcp_log_buf.c
parent63b113af5706420b149b5b8b2189d1e4d0b9782d (diff)
Diffstat (limited to 'sys/netinet/tcp_log_buf.c')
-rw-r--r--sys/netinet/tcp_log_buf.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/sys/netinet/tcp_log_buf.c b/sys/netinet/tcp_log_buf.c
index 491e1c23588c..5a16c7593cfc 100644
--- a/sys/netinet/tcp_log_buf.c
+++ b/sys/netinet/tcp_log_buf.c
@@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$");
#include <netinet/in_var.h>
#include <netinet/tcp_var.h>
#include <netinet/tcp_log_buf.h>
+#include <netinet/tcp_seq.h>
#include <netinet/tcp_hpts.h>
/* Default expiry time */
@@ -2844,6 +2845,10 @@ tcp_log_sendfile(struct socket *so, off_t offset, size_t nbytes, int flags)
{
struct inpcb *inp;
struct tcpcb *tp;
+#ifdef TCP_REQUEST_TRK
+ struct http_sendfile_track *ent;
+ int i, fnd;
+#endif
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("tcp_log_sendfile: inp == NULL"));
@@ -2873,6 +2878,90 @@ tcp_log_sendfile(struct socket *so, off_t offset, size_t nbytes, int flags)
&tptosocket(tp)->so_snd,
TCP_LOG_SENDFILE, 0, 0, &log, false, &tv);
}
+#ifdef TCP_REQUEST_TRK
+ if (tp->t_http_req == 0) {
+ /* No http requests to track */
+ goto done;
+ }
+ fnd = 0;
+ if (tp->t_http_closed == 0) {
+ /* No closed end req to track */
+ goto skip_closed_req;
+ }
+ for(i = 0; i < MAX_TCP_HTTP_REQ; i++) {
+ /* Lets see if this one can be found */
+ ent = &tp->t_http_info[i];
+ if (ent->flags == TCP_HTTP_TRACK_FLG_EMPTY) {
+ /* Not used */
+ continue;
+ }
+ if (ent->flags & TCP_HTTP_TRACK_FLG_OPEN) {
+ /* This pass does not consider open requests */
+ continue;
+ }
+ if (ent->flags & TCP_HTTP_TRACK_FLG_COMP) {
+ /* Don't look at what we have completed */
+ continue;
+ }
+ /* If we reach here its a allocated closed end request */
+ if ((ent->start == offset) ||
+ ((offset > ent->start) && (offset < ent->end))){
+ /* Its within this request?? */
+ fnd = 1;
+ }
+ if (fnd) {
+ /*
+ * It is at or past the end, its complete.
+ */
+ ent->flags |= TCP_HTTP_TRACK_FLG_SEQV;
+ /*
+ * When an entry completes we can take (snd_una + sb_cc) and know where
+ * the end of the range really is. Note that this works since two
+ * requests must be sequential and sendfile now is complete for *this* request.
+ * we must use sb_ccc since the data may still be in-flight in TLS.
+ *
+ * We always cautiously move the end_seq only if our calculations
+ * show it happened (just in case sf has the call to here at the wrong
+ * place). When we go COMP we will stop coming here and hopefully be
+ * left with the correct end_seq.
+ */
+ if (SEQ_GT((tp->snd_una + so->so_snd.sb_ccc), ent->end_seq))
+ ent->end_seq = tp->snd_una + so->so_snd.sb_ccc;
+ if ((offset + nbytes) >= ent->end) {
+ ent->flags |= TCP_HTTP_TRACK_FLG_COMP;
+ tcp_http_log_req_info(tp, ent, i, TCP_HTTP_REQ_LOG_COMPLETE, offset, nbytes);
+ } else {
+ tcp_http_log_req_info(tp, ent, i, TCP_HTTP_REQ_LOG_MOREYET, offset, nbytes);
+ }
+ /* We assume that sendfile never sends overlapping requests */
+ goto done;
+ }
+ }
+skip_closed_req:
+ if (!fnd) {
+ /* Ok now lets look for open requests */
+ for(i = 0; i < MAX_TCP_HTTP_REQ; i++) {
+ ent = &tp->t_http_info[i];
+ if (ent->flags == TCP_HTTP_TRACK_FLG_EMPTY) {
+ /* Not used */
+ continue;
+ }
+ if ((ent->flags & TCP_HTTP_TRACK_FLG_OPEN) == 0)
+ continue;
+ /* If we reach here its an allocated open request */
+ if (ent->start == offset) {
+ /* It begins this request */
+ ent->start_seq = tp->snd_una +
+ tptosocket(tp)->so_snd.sb_ccc;
+ ent->flags |= TCP_HTTP_TRACK_FLG_SEQV;
+ break;
+ } else if (offset > ent->start) {
+ ent->flags |= TCP_HTTP_TRACK_FLG_SEQV;
+ break;
+ }
+ }
+ }
+#endif
done:
INP_WUNLOCK(inp);
}