git: 9e2cce7e6a87 - main - Implement a function to get the next TCP- and TLS- receive sequence number.

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Wed, 26 Jan 2022 12:42:10 UTC
The branch main has been updated by hselasky:

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

commit 9e2cce7e6a87dd68af0f671f964cc7b3464ea76a
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2022-01-26 11:53:13 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2022-01-26 11:55:00 +0000

    Implement a function to get the next TCP- and TLS- receive sequence number.
    
    This function will be used by coming TLS hardware receive offload support.
    
    Differential Revision:  https://reviews.freebsd.org/D32356
    Discussed with: jhb@
    MFC after:      1 week
    Sponsored by:   NVIDIA Networking
---
 sys/kern/uipc_ktls.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 sys/sys/ktls.h       |  1 +
 2 files changed, 44 insertions(+)

diff --git a/sys/kern/uipc_ktls.c b/sys/kern/uipc_ktls.c
index 5912db865ef6..620536f28b34 100644
--- a/sys/kern/uipc_ktls.c
+++ b/sys/kern/uipc_ktls.c
@@ -1319,6 +1319,49 @@ ktls_get_rx_mode(struct socket *so, int *modep)
 	return (0);
 }
 
+/*
+ * ktls_get_rx_sequence - get the next TCP- and TLS- sequence number.
+ *
+ * This function gets information about the next TCP- and TLS-
+ * sequence number to be processed by the TLS receive worker
+ * thread. The information is extracted from the given "inpcb"
+ * structure. The values are stored in host endian format at the two
+ * given output pointer locations. The TCP sequence number points to
+ * the beginning of the TLS header.
+ *
+ * This function returns zero on success, else a non-zero error code
+ * is returned.
+ */
+int
+ktls_get_rx_sequence(struct inpcb *inp, uint32_t *tcpseq, uint64_t *tlsseq)
+{
+	struct socket *so;
+	struct tcpcb *tp;
+
+	INP_RLOCK(inp);
+	so = inp->inp_socket;
+	if (__predict_false(so == NULL)) {
+		INP_RUNLOCK(inp);
+		return (EINVAL);
+	}
+	if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
+		INP_RUNLOCK(inp);
+		return (ECONNRESET);
+	}
+
+	tp = intotcpcb(inp);
+	MPASS(tp != NULL);
+
+	SOCKBUF_LOCK(&so->so_rcv);
+	*tcpseq = tp->rcv_nxt - so->so_rcv.sb_tlscc;
+	*tlsseq = so->so_rcv.sb_tls_seqno;
+	SOCKBUF_UNLOCK(&so->so_rcv);
+
+	INP_RUNLOCK(inp);
+
+	return (0);
+}
+
 int
 ktls_get_tx_mode(struct socket *so, int *modep)
 {
diff --git a/sys/sys/ktls.h b/sys/sys/ktls.h
index a3eac69b5eeb..5cfca2d860a0 100644
--- a/sys/sys/ktls.h
+++ b/sys/sys/ktls.h
@@ -219,6 +219,7 @@ void ktls_enqueue_to_free(struct mbuf *m);
 int ktls_get_rx_mode(struct socket *so, int *modep);
 int ktls_set_tx_mode(struct socket *so, int mode);
 int ktls_get_tx_mode(struct socket *so, int *modep);
+int ktls_get_rx_sequence(struct inpcb *inp, uint32_t *tcpseq, uint64_t *tlsseq);
 int ktls_output_eagain(struct inpcb *inp, struct ktls_session *tls);
 #ifdef RATELIMIT
 int ktls_modify_txrtlmt(struct ktls_session *tls, uint64_t max_pacing_rate);