Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Add bpf_sk_storage support to bpf_tcp_ca

This patch adds bpf_sk_storage_get() and bpf_sk_storage_delete()
helper to the bpf_tcp_ca's struct_ops. That would allow
bpf-tcp-cc to:
1) share sk private data with other bpf progs.
2) use bpf_sk_storage as a private storage for a bpf-tcp-cc
if the existing icsk_ca_priv is not big enough.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200320152101.2169498-1-kafai@fb.com

authored by

Martin KaFai Lau and committed by
Daniel Borkmann
ab14fd4e 1440e792

+33
+33
net/ipv4/bpf_tcp_ca.c
··· 7 7 #include <linux/btf.h> 8 8 #include <linux/filter.h> 9 9 #include <net/tcp.h> 10 + #include <net/bpf_sk_storage.h> 10 11 11 12 static u32 optional_ops[] = { 12 13 offsetof(struct tcp_congestion_ops, init), ··· 28 27 static const struct btf_type *tcp_sock_type; 29 28 static u32 tcp_sock_id, sock_id; 30 29 30 + static int btf_sk_storage_get_ids[5]; 31 + static struct bpf_func_proto btf_sk_storage_get_proto __read_mostly; 32 + 33 + static int btf_sk_storage_delete_ids[5]; 34 + static struct bpf_func_proto btf_sk_storage_delete_proto __read_mostly; 35 + 36 + static void convert_sk_func_proto(struct bpf_func_proto *to, int *to_btf_ids, 37 + const struct bpf_func_proto *from) 38 + { 39 + int i; 40 + 41 + *to = *from; 42 + to->btf_id = to_btf_ids; 43 + for (i = 0; i < ARRAY_SIZE(to->arg_type); i++) { 44 + if (to->arg_type[i] == ARG_PTR_TO_SOCKET) { 45 + to->arg_type[i] = ARG_PTR_TO_BTF_ID; 46 + to->btf_id[i] = tcp_sock_id; 47 + } 48 + } 49 + } 50 + 31 51 static int bpf_tcp_ca_init(struct btf *btf) 32 52 { 33 53 s32 type_id; ··· 63 41 return -EINVAL; 64 42 tcp_sock_id = type_id; 65 43 tcp_sock_type = btf_type_by_id(btf, tcp_sock_id); 44 + 45 + convert_sk_func_proto(&btf_sk_storage_get_proto, 46 + btf_sk_storage_get_ids, 47 + &bpf_sk_storage_get_proto); 48 + convert_sk_func_proto(&btf_sk_storage_delete_proto, 49 + btf_sk_storage_delete_ids, 50 + &bpf_sk_storage_delete_proto); 66 51 67 52 return 0; 68 53 } ··· 196 167 switch (func_id) { 197 168 case BPF_FUNC_tcp_send_ack: 198 169 return &bpf_tcp_send_ack_proto; 170 + case BPF_FUNC_sk_storage_get: 171 + return &btf_sk_storage_get_proto; 172 + case BPF_FUNC_sk_storage_delete: 173 + return &btf_sk_storage_delete_proto; 199 174 default: 200 175 return bpf_base_func_proto(func_id); 201 176 }