Commit 30f060ee authored by Matthieu Baerts (NGI0)'s avatar Matthieu Baerts (NGI0) Committed by Geliang Tang
Browse files

mptcp: token kunit: set protocol

mainline inclusion
from mainline-v6.9-rc1
commit 28de50eeb734bbdbc1c4397134fa3501d3490a62
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9VYQ9
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=28de50eeb734bbdbc1c4397134fa3501d3490a62



--------------------------------

As it would be done when initiating an MPTCP sock.

This is not strictly needed for this test, but it will be when a later
patch will check if the right protocol is being used when calling
mptcp_sk().

Reviewed-by: default avatarMat Martineau <martineau@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240223-upstream-net-next-20240223-misc-improvements-v1-2-b6c8a10396bd@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarJackie Liu <liuyun01@kylinos.cn>
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
parent ab348dfd
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -52,14 +52,19 @@ static struct mptcp_subflow_context *build_ctx(struct kunit *test)
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 */
	((struct sock *)msk)->sk_prot = &tcp_prot;
	sk->sk_prot = &tcp_prot;
	sk->sk_protocol = IPPROTO_MPTCP;

	return msk;
}