net/handshake/alert.c
Source file repositories/reference/linux-study-clean/net/handshake/alert.c
File Facts
- System
- Linux kernel
- Corpus path
net/handshake/alert.c- Extension
.c- Size
- 2661 bytes
- Lines
- 111
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/socket.hlinux/kernel.hlinux/module.hlinux/skbuff.hlinux/inet.hnet/sock.hnet/handshake.hnet/tls.hnet/tls_prot.hhandshake.htrace/events/handshake.h
Detected Declarations
function Copyrightfunction tls_get_record_typefunction tls_alert_recvexport tls_get_record_typeexport tls_alert_recv
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Handle the TLS Alert protocol
*
* Author: Chuck Lever <chuck.lever@oracle.com>
*
* Copyright (c) 2023, Oracle and/or its affiliates.
*/
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/inet.h>
#include <net/sock.h>
#include <net/handshake.h>
#include <net/tls.h>
#include <net/tls_prot.h>
#include "handshake.h"
#include <trace/events/handshake.h>
/**
* tls_alert_send - send a TLS Alert on a kTLS socket
* @sock: open kTLS socket to send on
* @level: TLS Alert level
* @description: TLS Alert description
*
* Returns zero on success or a negative errno.
*/
int tls_alert_send(struct socket *sock, u8 level, u8 description)
{
u8 record_type = TLS_RECORD_TYPE_ALERT;
u8 buf[CMSG_SPACE(sizeof(record_type))];
struct msghdr msg = { 0 };
struct cmsghdr *cmsg;
struct kvec iov;
u8 alert[2];
int ret;
trace_tls_alert_send(sock->sk, level, description);
alert[0] = level;
alert[1] = description;
iov.iov_base = alert;
iov.iov_len = sizeof(alert);
memset(buf, 0, sizeof(buf));
msg.msg_control = buf;
msg.msg_controllen = sizeof(buf);
msg.msg_flags = MSG_DONTWAIT;
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_TLS;
cmsg->cmsg_type = TLS_SET_RECORD_TYPE;
cmsg->cmsg_len = CMSG_LEN(sizeof(record_type));
memcpy(CMSG_DATA(cmsg), &record_type, sizeof(record_type));
iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, &iov, 1, iov.iov_len);
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));
trace_tls_contenttype(sk, record_type);
return record_type;
}
EXPORT_SYMBOL(tls_get_record_type);
/**
* tls_alert_recv - Parse TLS Alert messages
Annotation
- Immediate include surface: `linux/types.h`, `linux/socket.h`, `linux/kernel.h`, `linux/module.h`, `linux/skbuff.h`, `linux/inet.h`, `net/sock.h`, `net/handshake.h`.
- Detected declarations: `function Copyright`, `function tls_get_record_type`, `function tls_alert_recv`, `export tls_get_record_type`, `export tls_alert_recv`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.