net/mptcp/token_test.c
Source file repositories/reference/linux-study-clean/net/mptcp/token_test.c
File Facts
- System
- Linux kernel
- Corpus path
net/mptcp/token_test.c- Extension
.c- Size
- 4302 bytes
- Lines
- 152
- 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.
- 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
kunit/test.hprotocol.h
Detected Declarations
function mptcp_token_test_req_basicfunction mptcp_token_test_msk_basicfunction mptcp_token_test_acceptfunction mptcp_token_test_destroyed
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <kunit/test.h>
#include "protocol.h"
static struct mptcp_subflow_request_sock *build_req_sock(struct kunit *test)
{
struct mptcp_subflow_request_sock *req;
req = kunit_kzalloc(test, sizeof(struct mptcp_subflow_request_sock),
GFP_USER);
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, req);
mptcp_token_init_request((struct request_sock *)req);
sock_net_set((struct sock *)req, &init_net);
return req;
}
static void mptcp_token_test_req_basic(struct kunit *test)
{
struct mptcp_subflow_request_sock *req = build_req_sock(test);
struct mptcp_sock *null_msk = NULL;
KUNIT_ASSERT_EQ(test, 0,
mptcp_token_new_request((struct request_sock *)req));
KUNIT_EXPECT_NE(test, 0, (int)req->token);
KUNIT_EXPECT_PTR_EQ(test, null_msk, mptcp_token_get_sock(&init_net, req->token));
/* cleanup */
mptcp_token_destroy_request((struct request_sock *)req);
}
static struct inet_connection_sock *build_icsk(struct kunit *test)
{
struct inet_connection_sock *icsk;
icsk = kunit_kzalloc(test, sizeof(struct inet_connection_sock),
GFP_USER);
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, icsk);
return icsk;
}
static struct mptcp_subflow_context *build_ctx(struct kunit *test)
{
struct mptcp_subflow_context *ctx;
ctx = kunit_kzalloc(test, sizeof(struct mptcp_subflow_context),
GFP_USER);
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ctx);
return ctx;
}
static struct mptcp_sock *build_msk(struct kunit *test)
{
struct mptcp_sock *msk;
struct sock *sk;
msk = kunit_kzalloc(test, sizeof(struct mptcp_sock), GFP_USER);
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, msk);
refcount_set(&((struct sock *)msk)->sk_refcnt, 1);
sock_net_set((struct sock *)msk, &init_net);
sk = (struct sock *)msk;
/* be sure the token helpers can dereference sk->sk_prot */
sk->sk_prot = &tcp_prot;
sk->sk_protocol = IPPROTO_MPTCP;
return msk;
}
static void mptcp_token_test_msk_basic(struct kunit *test)
{
struct inet_connection_sock *icsk = build_icsk(test);
struct mptcp_subflow_context *ctx = build_ctx(test);
struct mptcp_sock *msk = build_msk(test);
struct mptcp_sock *null_msk = NULL;
struct sock *sk;
rcu_assign_pointer(icsk->icsk_ulp_data, ctx);
ctx->conn = (struct sock *)msk;
sk = (struct sock *)msk;
KUNIT_ASSERT_EQ(test, 0,
mptcp_token_new_connect((struct sock *)icsk));
KUNIT_EXPECT_NE(test, 0, (int)ctx->token);
KUNIT_EXPECT_EQ(test, ctx->token, msk->token);
KUNIT_EXPECT_PTR_EQ(test, msk, mptcp_token_get_sock(&init_net, ctx->token));
KUNIT_EXPECT_EQ(test, 2, (int)refcount_read(&sk->sk_refcnt));
mptcp_token_destroy(msk);
Annotation
- Immediate include surface: `kunit/test.h`, `protocol.h`.
- Detected declarations: `function mptcp_token_test_req_basic`, `function mptcp_token_test_msk_basic`, `function mptcp_token_test_accept`, `function mptcp_token_test_destroyed`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
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.