MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ktls_decrypt

Function ktls_decrypt

freebsd/kern/uipc_ktls.c:1753–1933  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1751}
1752
1753static void
1754ktls_decrypt(struct socket *so)
1755{
1756 char tls_header[MBUF_PEXT_HDR_LEN];
1757 struct ktls_session *tls;
1758 struct sockbuf *sb;
1759 struct tls_record_layer *hdr;
1760 struct tls_get_record tgr;
1761 struct mbuf *control, *data, *m;
1762 uint64_t seqno;
1763 int error, remain, tls_len, trail_len;
1764
1765 hdr = (struct tls_record_layer *)tls_header;
1766 sb = &so->so_rcv;
1767 SOCKBUF_LOCK(sb);
1768 KASSERT(sb->sb_flags & SB_TLS_RX_RUNNING,
1769 ("%s: socket %p not running", __func__, so));
1770
1771 tls = sb->sb_tls_info;
1772 MPASS(tls != NULL);
1773
1774 for (;;) {
1775 /* Is there enough queued for a TLS header? */
1776 if (sb->sb_tlscc < tls->params.tls_hlen)
1777 break;
1778
1779 m_copydata(sb->sb_mtls, 0, tls->params.tls_hlen, tls_header);
1780 tls_len = sizeof(*hdr) + ntohs(hdr->tls_length);
1781
1782 if (hdr->tls_vmajor != tls->params.tls_vmajor ||
1783 hdr->tls_vminor != tls->params.tls_vminor)
1784 error = EINVAL;
1785 else if (tls_len < tls->params.tls_hlen || tls_len >
1786 tls->params.tls_hlen + TLS_MAX_MSG_SIZE_V10_2 +
1787 tls->params.tls_tlen)
1788 error = EMSGSIZE;
1789 else
1790 error = 0;
1791 if (__predict_false(error != 0)) {
1792 /*
1793 * We have a corrupted record and are likely
1794 * out of sync. The connection isn't
1795 * recoverable at this point, so abort it.
1796 */
1797 SOCKBUF_UNLOCK(sb);
1798 counter_u64_add(ktls_offload_corrupted_records, 1);
1799
1800 CURVNET_SET(so->so_vnet);
1801 so->so_proto->pr_usrreqs->pru_abort(so);
1802 so->so_error = error;
1803 CURVNET_RESTORE();
1804 goto deref;
1805 }
1806
1807 /* Is the entire record queued? */
1808 if (sb->sb_tlscc < tls_len)
1809 break;
1810

Callers 1

ktls_work_threadFunction · 0.85

Calls 7

m_copydataFunction · 0.85
ktls_detach_recordFunction · 0.85
sbcreatecontrol_howFunction · 0.85
sbappendcontrol_lockedFunction · 0.85
m_freemFunction · 0.70
counter_u64_addFunction · 0.50
m_freeFunction · 0.50

Tested by

no test coverage detected