net/ipv4/tcp_fastopen.c
Source file repositories/reference/linux-study-clean/net/ipv4/tcp_fastopen.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/tcp_fastopen.c- Extension
.c- Size
- 20814 bytes
- Lines
- 690
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- 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/kernel.hlinux/tcp.hlinux/rcupdate.hnet/tcp.hnet/busy_poll.h
Detected Declarations
function abortedfunction tcp_fastopen_init_key_oncefunction tcp_fastopen_ctx_freefunction tcp_fastopen_destroy_cipherfunction tcp_fastopen_ctx_destroyfunction tcp_fastopen_reset_cipherfunction tcp_fastopen_get_cipherfunction __tcp_fastopen_cookie_gen_cipherfunction tcp_fastopen_cookie_genfunction tcp_fastopen_add_skbfunction tcp_fastopen_cookie_gen_checkfunction tcp_fastopen_queue_checkfunction tcp_fastopen_no_cookiefunction requestfunction tcp_fastopen_cookie_checkfunction writefunction tcp_fastopen_active_disablefunction tcp_fastopen_active_should_disablefunction tcp_fastopen_active_disable_ofo_checkfunction atomic_readfunction tcp_fastopen_active_detect_blackhole
Annotated Snippet
if (tcp_fastopen_cookie_match(foc, orig)) {
ret = i + 1;
goto out;
}
foc = &search_foc;
}
out:
rcu_read_unlock();
return ret;
}
static struct sock *tcp_fastopen_create_child(struct sock *sk,
struct sk_buff *skb,
struct request_sock *req)
{
struct tcp_sock *tp;
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
struct sock *child;
bool own_req;
child = inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb, req, NULL,
NULL, &own_req, NULL);
if (!child)
return NULL;
spin_lock(&queue->fastopenq.lock);
queue->fastopenq.qlen++;
spin_unlock(&queue->fastopenq.lock);
/* Initialize the child socket. Have to fix some values to take
* into account the child is a Fast Open socket and is created
* only out of the bits carried in the SYN packet.
*/
tp = tcp_sk(child);
rcu_assign_pointer(tp->fastopen_rsk, req);
tcp_rsk(req)->tfo_listener = true;
/* RFC1323: The window in SYN & SYN/ACK segments is never
* scaled. So correct it appropriately.
*/
tp->snd_wnd = ntohs(tcp_hdr(skb)->window);
tp->max_window = tp->snd_wnd;
/* Activate the retrans timer so that SYNACK can be retransmitted.
* The request socket is not added to the ehash
* because it's been added to the accept queue directly.
*/
req->timeout = tcp_timeout_init(child);
tcp_reset_xmit_timer(child, ICSK_TIME_RETRANS,
req->timeout, false);
refcount_set(&req->rsk_refcnt, 2);
sk_mark_napi_id_set(child, skb);
/* Now finish processing the fastopen child socket. */
tcp_init_transfer(child, BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, skb);
tp->rcv_nxt = TCP_SKB_CB(skb)->seq + 1;
tcp_fastopen_add_skb(child, skb);
tcp_rsk(req)->rcv_nxt = tp->rcv_nxt;
tp->rcv_wup = tp->rcv_nxt;
tp->rcv_mwnd_seq = tp->rcv_wup + tp->rcv_wnd;
/* tcp_conn_request() is sending the SYNACK,
* and queues the child into listener accept queue.
*/
return child;
}
static bool tcp_fastopen_queue_check(struct sock *sk)
{
struct fastopen_queue *fastopenq;
int max_qlen;
/* Make sure the listener has enabled fastopen, and we don't
* exceed the max # of pending TFO requests allowed before trying
* to validating the cookie in order to avoid burning CPU cycles
* unnecessarily.
*
* XXX (TFO) - The implication of checking the max_qlen before
* processing a cookie request is that clients can't differentiate
* between qlen overflow causing Fast Open to be disabled
* temporarily vs a server not supporting Fast Open at all.
*/
fastopenq = &inet_csk(sk)->icsk_accept_queue.fastopenq;
max_qlen = READ_ONCE(fastopenq->max_qlen);
if (max_qlen == 0)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/tcp.h`, `linux/rcupdate.h`, `net/tcp.h`, `net/busy_poll.h`.
- Detected declarations: `function aborted`, `function tcp_fastopen_init_key_once`, `function tcp_fastopen_ctx_free`, `function tcp_fastopen_destroy_cipher`, `function tcp_fastopen_ctx_destroy`, `function tcp_fastopen_reset_cipher`, `function tcp_fastopen_get_cipher`, `function __tcp_fastopen_cookie_gen_cipher`, `function tcp_fastopen_cookie_gen`, `function tcp_fastopen_add_skb`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.