net/xfrm/espintcp.c
Source file repositories/reference/linux-study-clean/net/xfrm/espintcp.c
File Facts
- System
- Linux kernel
- Corpus path
net/xfrm/espintcp.c- Extension
.c- Size
- 13052 bytes
- Lines
- 591
- 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.
- 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
net/tcp.hnet/strparser.hnet/xfrm.hnet/esp.hnet/espintcp.hlinux/skmsg.hnet/inet_common.htrace/events/sock.hnet/hotdata.h
Detected Declarations
function handle_nonespfunction handle_espfunction espintcp_rcvfunction espintcp_parsefunction espintcp_recvmsgfunction espintcp_queue_outfunction espintcp_sendskb_lockedfunction espintcp_sendskmsg_lockedfunction espintcp_push_msgsfunction espintcp_push_skbfunction espintcp_sendmsgfunction espintcp_data_readyfunction espintcp_tx_workfunction espintcp_write_spacefunction espintcp_destructfunction tcp_is_ulp_espfunction espintcp_init_skfunction espintcp_releasefunction espintcp_closefunction espintcp_pollfunction build_protosfunction espintcp_initexport espintcp_queue_outexport espintcp_push_skbexport tcp_is_ulp_esp
Annotated Snippet
static struct proto_ops espintcp_ops __ro_after_init;
static struct proto espintcp6_prot;
static struct proto_ops espintcp6_ops;
static DEFINE_MUTEX(tcpv6_prot_mutex);
static void espintcp_data_ready(struct sock *sk)
{
struct espintcp_ctx *ctx = espintcp_getctx(sk);
trace_sk_data_ready(sk);
strp_data_ready(&ctx->strp);
}
static void espintcp_tx_work(struct work_struct *work)
{
struct espintcp_ctx *ctx = container_of(work,
struct espintcp_ctx, work);
struct sock *sk = ctx->strp.sk;
lock_sock(sk);
if (!ctx->tx_running)
espintcp_push_msgs(sk, 0);
release_sock(sk);
}
static void espintcp_write_space(struct sock *sk)
{
struct espintcp_ctx *ctx = espintcp_getctx(sk);
schedule_work(&ctx->work);
ctx->saved_write_space(sk);
}
static void espintcp_destruct(struct sock *sk)
{
struct espintcp_ctx *ctx = espintcp_getctx(sk);
ctx->saved_destruct(sk);
kfree(ctx);
}
bool tcp_is_ulp_esp(struct sock *sk)
{
return sk->sk_prot == &espintcp_prot || sk->sk_prot == &espintcp6_prot;
}
EXPORT_SYMBOL_GPL(tcp_is_ulp_esp);
static void build_protos(struct proto *espintcp_prot,
struct proto_ops *espintcp_ops,
const struct proto *orig_prot,
const struct proto_ops *orig_ops);
static int espintcp_init_sk(struct sock *sk)
{
struct inet_connection_sock *icsk = inet_csk(sk);
struct strp_callbacks cb = {
.rcv_msg = espintcp_rcv,
.parse_msg = espintcp_parse,
};
struct espintcp_ctx *ctx;
int err;
/* sockmap is not compatible with espintcp */
if (sk->sk_user_data)
return -EBUSY;
ctx = kzalloc_obj(*ctx);
if (!ctx)
return -ENOMEM;
err = strp_init(&ctx->strp, sk, &cb);
if (err)
goto free;
__sk_dst_reset(sk);
strp_check_rcv(&ctx->strp);
skb_queue_head_init(&ctx->ike_queue);
skb_queue_head_init(&ctx->out_queue);
if (sk->sk_family == AF_INET) {
sk->sk_prot = &espintcp_prot;
sk->sk_socket->ops = &espintcp_ops;
} else {
mutex_lock(&tcpv6_prot_mutex);
if (!espintcp6_prot.recvmsg)
build_protos(&espintcp6_prot, &espintcp6_ops, sk->sk_prot, sk->sk_socket->ops);
mutex_unlock(&tcpv6_prot_mutex);
sk->sk_prot = &espintcp6_prot;
Annotation
- Immediate include surface: `net/tcp.h`, `net/strparser.h`, `net/xfrm.h`, `net/esp.h`, `net/espintcp.h`, `linux/skmsg.h`, `net/inet_common.h`, `trace/events/sock.h`.
- Detected declarations: `function handle_nonesp`, `function handle_esp`, `function espintcp_rcv`, `function espintcp_parse`, `function espintcp_recvmsg`, `function espintcp_queue_out`, `function espintcp_sendskb_locked`, `function espintcp_sendskmsg_locked`, `function espintcp_push_msgs`, `function espintcp_push_skb`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern implementation candidate.
- 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.