Skip to content

Commit

Permalink
bpf_mptcp_ssk_cast
Browse files Browse the repository at this point in the history
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed Nov 24, 2024
1 parent bd61ea5 commit 4fa08af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/uapi/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -5795,6 +5795,12 @@ union bpf_attr {
* 0 on success.
*
* **-ENOENT** if the bpf_local_storage cannot be found.
*
* void *bpf_mptcp_ssk_cast(void *sk)
* Description
* Dynamically cast a *sk* pointer to a *sock* pointer.
* Return
* *sk* if casting is valid, or **NULL** otherwise.
*/
#define ___BPF_FUNC_MAPPER(FN, ctx...) \
FN(unspec, 0, ##ctx) \
Expand Down Expand Up @@ -6009,6 +6015,7 @@ union bpf_attr {
FN(user_ringbuf_drain, 209, ##ctx) \
FN(cgrp_storage_get, 210, ##ctx) \
FN(cgrp_storage_delete, 211, ##ctx) \
FN(mptcp_ssk_cast, 212, ##ctx) \
/* */

/* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't
Expand Down
16 changes: 16 additions & 0 deletions net/mptcp/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,20 @@ static struct bpf_struct_ops bpf_mptcp_pm_ops = {

/* MPTCP BPF packet scheduler */

BPF_CALL_1(bpf_mptcp_ssk_cast, struct sock *, sk)
{
BTF_TYPE_EMIT(struct sock);
return (unsigned long)sk;
}

static const struct bpf_func_proto bpf_mptcp_ssk_cast_proto = {
.func = bpf_mptcp_ssk_cast,
.gpl_only = false,
.ret_type = RET_PTR_TO_BTF_ID_OR_NULL,
.arg1_type = ARG_ANYTHING,
.ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK],
};

static const struct bpf_func_proto *
bpf_mptcp_sched_get_func_proto(enum bpf_func_id func_id,
const struct bpf_prog *prog)
Expand All @@ -294,6 +308,8 @@ bpf_mptcp_sched_get_func_proto(enum bpf_func_id func_id,
return &bpf_skc_to_tcp6_sock_proto;
case BPF_FUNC_skc_to_tcp_sock:
return &bpf_skc_to_tcp_sock_proto;
case BPF_FUNC_mptcp_ssk_cast:
return &bpf_mptcp_ssk_cast_proto;
default:
return bpf_base_func_proto(func_id, prog);
}
Expand Down
7 changes: 7 additions & 0 deletions tools/include/uapi/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -5795,6 +5795,12 @@ union bpf_attr {
* 0 on success.
*
* **-ENOENT** if the bpf_local_storage cannot be found.
*
* void *bpf_mptcp_ssk_cast(void *sk)
* Description
* Dynamically cast a *sk* pointer to a *sock* pointer.
* Return
* *sk* if casting is valid, or **NULL** otherwise.
*/
#define ___BPF_FUNC_MAPPER(FN, ctx...) \
FN(unspec, 0, ##ctx) \
Expand Down Expand Up @@ -6009,6 +6015,7 @@ union bpf_attr {
FN(user_ringbuf_drain, 209, ##ctx) \
FN(cgrp_storage_get, 210, ##ctx) \
FN(cgrp_storage_delete, 211, ##ctx) \
FN(mptcp_ssk_cast, 212, ##ctx) \
/* */

/* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't
Expand Down

0 comments on commit 4fa08af

Please sign in to comment.