net/tls/tls_main.c
Source file repositories/reference/linux-study-clean/net/tls/tls_main.c
File Facts
- System
- Linux kernel
- Corpus path
net/tls/tls_main.c- Extension
.c- Size
- 32227 bytes
- Lines
- 1263
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hnet/tcp.hnet/inet_common.hlinux/highmem.hlinux/netdevice.hlinux/sched/signal.hlinux/inetdevice.hlinux/inet_diag.hnet/snmp.hnet/tls.htls.h
Detected Declarations
function update_sk_protfunction wait_on_pending_writerfunction tls_push_sgfunction tls_handle_open_recordfunction tls_process_cmsgfunction for_each_cmsghdrfunction tls_push_partial_recordfunction tls_free_partial_recordfunction tls_write_spacefunction tls_ctx_freefunction tls_sk_proto_cleanupfunction tls_sk_proto_closefunction tls_sk_pollfunction do_tls_getsockopt_conffunction do_tls_getsockopt_tx_zcfunction do_tls_getsockopt_no_padfunction do_tls_getsockopt_tx_payload_lenfunction do_tls_getsockoptfunction tls_getsockoptfunction validate_crypto_infofunction do_tls_setsockopt_conffunction do_tls_setsockopt_tx_zcfunction do_tls_setsockopt_no_padfunction do_tls_setsockopt_tx_payload_lenfunction do_tls_setsockoptfunction tls_setsockoptfunction tls_disconnectfunction build_proto_opsfunction tls_build_protofunction unlikelyfunction build_protosfunction tls_initfunction tls_updatefunction tls_user_configfunction tls_get_infofunction tls_get_info_sizefunction tls_init_netfunction tls_exit_netfunction tls_registerfunction tls_unregistermodule init tls_register
Annotated Snippet
static struct proto_ops tls_proto_ops[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG];
static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG],
const struct proto *base);
void update_sk_prot(struct sock *sk, struct tls_context *ctx)
{
int ip_ver = sk->sk_family == AF_INET6 ? TLSV6 : TLSV4;
WRITE_ONCE(sk->sk_prot,
&tls_prots[ip_ver][ctx->tx_conf][ctx->rx_conf]);
WRITE_ONCE(sk->sk_socket->ops,
&tls_proto_ops[ip_ver][ctx->tx_conf][ctx->rx_conf]);
}
int wait_on_pending_writer(struct sock *sk, long *timeo)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
int ret, rc = 0;
add_wait_queue(sk_sleep(sk), &wait);
while (1) {
if (!*timeo) {
rc = -EAGAIN;
break;
}
if (signal_pending(current)) {
rc = sock_intr_errno(*timeo);
break;
}
ret = sk_wait_event(sk, timeo,
!READ_ONCE(sk->sk_write_pending), &wait);
if (ret) {
if (ret < 0)
rc = ret;
break;
}
}
remove_wait_queue(sk_sleep(sk), &wait);
return rc;
}
int tls_push_sg(struct sock *sk,
struct tls_context *ctx,
struct scatterlist *sg,
u16 first_offset,
int flags)
{
struct bio_vec bvec;
struct msghdr msg = {
.msg_flags = MSG_SPLICE_PAGES | flags,
};
int ret = 0;
struct page *p;
size_t size;
int offset = first_offset;
size = sg->length - offset;
offset += sg->offset;
ctx->splicing_pages = true;
while (1) {
/* is sending application-limited? */
tcp_rate_check_app_limited(sk);
p = sg_page(sg);
retry:
bvec_set_page(&bvec, p, size, offset);
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size);
ret = tcp_sendmsg_locked(sk, &msg, size);
if (ret != size) {
if (ret > 0) {
offset += ret;
size -= ret;
goto retry;
}
offset -= sg->offset;
ctx->partially_sent_offset = offset;
ctx->partially_sent_record = (void *)sg;
ctx->splicing_pages = false;
return ret;
}
put_page(p);
sk_mem_uncharge(sk, sg->length);
sg = sg_next(sg);
if (!sg)
Annotation
- Immediate include surface: `linux/module.h`, `net/tcp.h`, `net/inet_common.h`, `linux/highmem.h`, `linux/netdevice.h`, `linux/sched/signal.h`, `linux/inetdevice.h`, `linux/inet_diag.h`.
- Detected declarations: `function update_sk_prot`, `function wait_on_pending_writer`, `function tls_push_sg`, `function tls_handle_open_record`, `function tls_process_cmsg`, `function for_each_cmsghdr`, `function tls_push_partial_record`, `function tls_free_partial_record`, `function tls_write_space`, `function tls_ctx_free`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.