162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/* Multipath TCP
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 2020, Tessares SA.
562306a36Sopenharmony_ci * Copyright (c) 2022, SUSE.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Author: Nicolas Rybowski <nicolas.rybowski@tessares.net>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define pr_fmt(fmt) "MPTCP: " fmt
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/bpf.h>
1362306a36Sopenharmony_ci#include "protocol.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cistruct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk)
1662306a36Sopenharmony_ci{
1762306a36Sopenharmony_ci	if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
1862306a36Sopenharmony_ci		return mptcp_sk(mptcp_subflow_ctx(sk)->conn);
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci	return NULL;
2162306a36Sopenharmony_ci}
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ciBTF_SET8_START(bpf_mptcp_fmodret_ids)
2462306a36Sopenharmony_ciBTF_ID_FLAGS(func, update_socket_protocol)
2562306a36Sopenharmony_ciBTF_SET8_END(bpf_mptcp_fmodret_ids)
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_cistatic const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = {
2862306a36Sopenharmony_ci	.owner = THIS_MODULE,
2962306a36Sopenharmony_ci	.set   = &bpf_mptcp_fmodret_ids,
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cistatic int __init bpf_mptcp_kfunc_init(void)
3362306a36Sopenharmony_ci{
3462306a36Sopenharmony_ci	return register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set);
3562306a36Sopenharmony_ci}
3662306a36Sopenharmony_cilate_initcall(bpf_mptcp_kfunc_init);
37