net/mptcp/protocol.c
Source file repositories/reference/linux-study-clean/net/mptcp/protocol.c
File Facts
- System
- Linux kernel
- Corpus path
net/mptcp/protocol.c- Extension
.c- Size
- 122778 bytes
- Lines
- 4736
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/netdevice.hlinux/sched/signal.hlinux/atomic.hnet/aligned_data.hnet/rps.hnet/sock.hnet/inet_common.hnet/inet_hashtables.hnet/protocol.hnet/tcp_states.hnet/transp_v6.hnet/mptcp.hnet/hotdata.hnet/xfrm.hasm/ioctls.hprotocol.hmib.htrace/events/mptcp.h
Detected Declarations
struct mptcp6_sockstruct mptcp_sendmsg_infostruct subflow_send_infofunction mptcp_wnd_endfunction __mptcp_try_fallbackfunction __mptcp_socket_createfunction mptcp_dropfunction __mptcp_try_coalescefunction mptcp_try_coalescefunction mptcp_ooo_try_coalescefunction mptcp_rcvbuf_growfunction mptcp_data_queue_ofofunction Ofunction mptcp_init_skbfunction __mptcp_move_skbfunction mptcp_stop_rtx_timerfunction mptcp_close_wake_upfunction mptcp_shutdown_subflowsfunction mptcp_for_each_subflowfunction mptcp_pending_data_fin_ackfunction mptcp_check_data_fin_ackfunction mptcp_pending_data_finfunction mptcp_set_datafin_timeoutfunction __mptcp_set_timeoutfunction mptcp_timeout_from_subflowfunction mptcp_set_timeoutfunction tcp_can_send_ackfunction __mptcp_subflow_send_ackfunction mptcp_subflow_send_ackfunction mptcp_send_ackfunction mptcp_subflow_cleanup_rbuffunction mptcp_subflow_could_cleanupfunction mptcp_cleanup_rbuffunction mptcp_for_each_subflowfunction mptcp_check_data_finfunction mptcp_dss_corruptionfunction __mptcp_add_backlogfunction __mptcp_move_skbs_from_subflowfunction __mptcp_ofo_queuefunction __mptcp_subflow_error_reportfunction __mptcp_error_reportfunction move_skbs_to_mskfunction mptcp_rcv_rtt_updatefunction mptcp_data_readyfunction mptcp_subflow_joinedfunction __mptcp_finish_joinfunction __mptcp_flush_join_listfunction list_for_each_entry_safe
Annotated Snippet
static const struct proto_ops *mptcp_fallback_tcp_ops(const struct sock *sk)
{
unsigned short family = READ_ONCE(sk->sk_family);
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
if (family == AF_INET6)
return &inet6_stream_ops;
#endif
WARN_ON_ONCE(family != AF_INET);
return &inet_stream_ops;
}
bool __mptcp_try_fallback(struct mptcp_sock *msk, int fb_mib)
{
struct net *net = sock_net((struct sock *)msk);
if (__mptcp_check_fallback(msk))
return true;
/* The caller possibly is not holding the msk socket lock, but
* in the fallback case only the current subflow is touching
* the OoO queue.
*/
if (!RB_EMPTY_ROOT(&msk->out_of_order_queue))
return false;
spin_lock_bh(&msk->fallback_lock);
if (!msk->allow_infinite_fallback) {
spin_unlock_bh(&msk->fallback_lock);
return false;
}
msk->allow_subflows = false;
set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
__MPTCP_INC_STATS(net, fb_mib);
spin_unlock_bh(&msk->fallback_lock);
return true;
}
static int __mptcp_socket_create(struct mptcp_sock *msk)
{
struct mptcp_subflow_context *subflow;
struct sock *sk = (struct sock *)msk;
struct socket *ssock;
int err;
err = mptcp_subflow_create_socket(sk, sk->sk_family, &ssock);
if (err)
return err;
msk->scaling_ratio = tcp_sk(ssock->sk)->scaling_ratio;
WRITE_ONCE(msk->first, ssock->sk);
subflow = mptcp_subflow_ctx(ssock->sk);
list_add(&subflow->node, &msk->conn_list);
sock_hold(ssock->sk);
subflow->request_mptcp = 1;
subflow->subflow_id = msk->subflow_id++;
/* This is the first subflow, always with id 0 */
WRITE_ONCE(subflow->local_id, 0);
mptcp_sock_graft(msk->first, sk->sk_socket);
iput(SOCK_INODE(ssock));
return 0;
}
/* If the MPC handshake is not started, returns the first subflow,
* eventually allocating it.
*/
struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk)
{
struct sock *sk = (struct sock *)msk;
int ret;
if (!((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
return ERR_PTR(-EINVAL);
if (!msk->first) {
ret = __mptcp_socket_create(msk);
if (ret)
return ERR_PTR(ret);
}
return msk->first;
}
static void mptcp_drop(struct sock *sk, struct sk_buff *skb)
{
sk_drops_skbadd(sk, skb);
__kfree_skb(skb);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/netdevice.h`, `linux/sched/signal.h`, `linux/atomic.h`, `net/aligned_data.h`, `net/rps.h`, `net/sock.h`.
- Detected declarations: `struct mptcp6_sock`, `struct mptcp_sendmsg_info`, `struct subflow_send_info`, `function mptcp_wnd_end`, `function __mptcp_try_fallback`, `function __mptcp_socket_create`, `function mptcp_drop`, `function __mptcp_try_coalesce`, `function mptcp_try_coalesce`, `function mptcp_ooo_try_coalesce`.
- 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.