1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020, Tessares SA. */
3 /* Copyright (c) 2022, SUSE. */
6 #include <bpf/bpf_helpers.h>
7 #include "bpf_tcp_helpers.h"
9 char _license[] SEC("license") = "GPL";
12 struct mptcp_storage {
18 char ca_name[TCP_CA_NAME_MAX];
22 __uint(type, BPF_MAP_TYPE_SK_STORAGE);
23 __uint(map_flags, BPF_F_NO_PREALLOC);
25 __type(value, struct mptcp_storage);
26 } socket_storage_map SEC(".maps");
29 int _sockops(struct bpf_sock_ops *ctx)
31 struct mptcp_storage *storage;
32 struct mptcp_sock *msk;
33 int op = (int)ctx->op;
38 if (op != BPF_SOCK_OPS_TCP_CONNECT_CB)
45 tsk = bpf_skc_to_tcp_sock(sk);
49 is_mptcp = bpf_core_field_exists(tsk->is_mptcp) ? tsk->is_mptcp : 0;
51 storage = bpf_sk_storage_get(&socket_storage_map, sk, 0,
52 BPF_SK_STORAGE_GET_F_CREATE);
57 __builtin_memset(storage->ca_name, 0, TCP_CA_NAME_MAX);
58 storage->first = NULL;
60 msk = bpf_skc_to_mptcp_sock(sk);
64 storage = bpf_sk_storage_get(&socket_storage_map, msk, 0,
65 BPF_SK_STORAGE_GET_F_CREATE);
69 storage->token = msk->token;
70 __builtin_memcpy(storage->ca_name, msk->ca_name, TCP_CA_NAME_MAX);
71 storage->first = msk->first;
74 storage->is_mptcp = is_mptcp;
75 storage->sk = (struct sock *)sk;
80 SEC("fentry/mptcp_pm_new_connection")
81 int BPF_PROG(trace_mptcp_pm_new_connection, struct mptcp_sock *msk,
82 const struct sock *ssk, int server_side)