net/ipv4/tcp_bpf.c
Source file repositories/reference/linux-study-clean/net/ipv4/tcp_bpf.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/tcp_bpf.c- Extension
.c- Size
- 18020 bytes
- Lines
- 760
- 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.
- 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/skmsg.hlinux/filter.hlinux/bpf.hlinux/init.hlinux/wait.hlinux/util_macros.hnet/inet_common.hnet/tls.hasm/ioctls.h
Detected Declarations
function tcp_eat_skbfunction bpf_tcp_ingressfunction tcp_bpf_pushfunction tcp_bpf_push_lockedfunction tcp_bpf_sendmsg_redirfunction tcp_msg_wait_datafunction is_next_msg_finfunction tcp_bpf_recvmsg_parserfunction tcp_bpf_ioctlfunction tcp_bpf_recvmsgfunction sk_psock_queue_emptyfunction tcp_bpf_send_verdictfunction tcp_bpf_sendmsgfunction tcp_bpf_rebuild_protosfunction tcp_bpf_check_v6_needs_rebuildfunction tcp_bpf_v4_build_protofunction tcp_bpf_assert_proto_opsfunction tcp_bpf_strp_read_sockfunction tcp_bpf_update_protofunction tcp_bpf_cloneexport tcp_bpf_sendmsg_redirexport tcp_bpf_update_proto
Annotated Snippet
if (!__sk_rmem_schedule(sk, size, false)) {
if (!copied)
ret = -ENOMEM;
break;
}
sk_mem_charge(sk, size);
atomic_add(size, &sk->sk_rmem_alloc);
sk_msg_xfer(tmp, msg, i, size);
copied += size;
if (sge->length)
get_page(sk_msg_page(tmp, i));
sk_msg_iter_var_next(i);
tmp->sg.end = i;
if (apply) {
apply_bytes -= size;
if (!apply_bytes) {
if (sge->length)
sk_msg_iter_var_prev(i);
break;
}
}
} while (i != msg->sg.end);
if (!ret) {
msg->sg.start = i;
if (!sk_psock_queue_msg(psock, tmp))
atomic_sub(copied, &sk->sk_rmem_alloc);
sk_psock_data_ready(sk, psock);
} else {
sk_msg_free(sk, tmp);
kfree(tmp);
}
release_sock(sk);
return ret;
}
static int tcp_bpf_push(struct sock *sk, struct sk_msg *msg, u32 apply_bytes,
int flags, bool uncharge)
{
struct msghdr msghdr = {};
bool apply = apply_bytes;
struct scatterlist *sge;
struct page *page;
int size, ret = 0;
u32 off;
while (1) {
struct bio_vec bvec;
bool has_tx_ulp;
sge = sk_msg_elem(msg, msg->sg.start);
size = (apply && apply_bytes < sge->length) ?
apply_bytes : sge->length;
off = sge->offset;
page = sg_page(sge);
tcp_rate_check_app_limited(sk);
retry:
msghdr.msg_flags = flags | MSG_SPLICE_PAGES;
has_tx_ulp = tls_sw_has_ctx_tx(sk);
if (has_tx_ulp)
msghdr.msg_flags |= MSG_SENDPAGE_NOPOLICY;
if (size < sge->length && msg->sg.start != msg->sg.end)
msghdr.msg_flags |= MSG_MORE;
bvec_set_page(&bvec, page, size, off);
iov_iter_bvec(&msghdr.msg_iter, ITER_SOURCE, &bvec, 1, size);
ret = tcp_sendmsg_locked(sk, &msghdr, size);
if (ret <= 0)
return ret;
if (apply)
apply_bytes -= ret;
msg->sg.size -= ret;
sge->offset += ret;
sge->length -= ret;
if (uncharge)
sk_mem_uncharge(sk, ret);
if (ret != size) {
size -= ret;
off += ret;
goto retry;
}
if (!sge->length) {
put_page(page);
sk_msg_iter_next(msg, start);
sg_init_table(sge, 1);
Annotation
- Immediate include surface: `linux/skmsg.h`, `linux/filter.h`, `linux/bpf.h`, `linux/init.h`, `linux/wait.h`, `linux/util_macros.h`, `net/inet_common.h`, `net/tls.h`.
- Detected declarations: `function tcp_eat_skb`, `function bpf_tcp_ingress`, `function tcp_bpf_push`, `function tcp_bpf_push_locked`, `function tcp_bpf_sendmsg_redir`, `function tcp_msg_wait_data`, `function is_next_msg_fin`, `function tcp_bpf_recvmsg_parser`, `function tcp_bpf_ioctl`, `function tcp_bpf_recvmsg`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.