diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2023-07-27 13:37:10 -0400 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2023-07-28 14:07:59 -0700 |
commit | 39d0e38dcced8d4da92cd11f3ff618bacc42d8a9 (patch) | |
tree | 514352c2d07cc8ffbf575a565bbe967f56f05c2a /net | |
parent | 5dd5ad682cfe9550a37634a8f55780ebd74edbe8 (diff) | |
download | linux-stable-39d0e38dcced8d4da92cd11f3ff618bacc42d8a9.tar.gz linux-stable-39d0e38dcced8d4da92cd11f3ff618bacc42d8a9.tar.bz2 linux-stable-39d0e38dcced8d4da92cd11f3ff618bacc42d8a9.zip |
net/handshake: Add helpers for parsing incoming TLS Alerts
Kernel TLS consumers can replace common TLS Alert parsing code with
these helpers.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Link: https://lore.kernel.org/r/169047942074.5241.13791647439480672048.stgit@oracle-102.nfsv4bat.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/handshake/alert.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/net/handshake/alert.c b/net/handshake/alert.c index 2f1a16868ff6..286bf94d93a3 100644 --- a/net/handshake/alert.c +++ b/net/handshake/alert.c @@ -59,3 +59,45 @@ int tls_alert_send(struct socket *sock, u8 level, u8 description) ret = sock_sendmsg(sock, &msg); return ret < 0 ? ret : 0; } + +/** + * tls_get_record_type - Look for TLS RECORD_TYPE information + * @sk: socket (for IP address information) + * @cmsg: incoming message to be parsed + * + * Returns zero or a TLS_RECORD_TYPE value. + */ +u8 tls_get_record_type(const struct sock *sk, const struct cmsghdr *cmsg) +{ + u8 record_type; + + if (cmsg->cmsg_level != SOL_TLS) + return 0; + if (cmsg->cmsg_type != TLS_GET_RECORD_TYPE) + return 0; + + record_type = *((u8 *)CMSG_DATA(cmsg)); + return record_type; +} +EXPORT_SYMBOL(tls_get_record_type); + +/** + * tls_alert_recv - Parse TLS Alert messages + * @sk: socket (for IP address information) + * @msg: incoming message to be parsed + * @level: OUT - TLS AlertLevel value + * @description: OUT - TLS AlertDescription value + * + */ +void tls_alert_recv(const struct sock *sk, const struct msghdr *msg, + u8 *level, u8 *description) +{ + const struct kvec *iov; + u8 *data; + + iov = msg->msg_iter.kvec; + data = iov->iov_base; + *level = data[0]; + *description = data[1]; +} +EXPORT_SYMBOL(tls_alert_recv); |