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

Configure Feed

Select the types of activity you want to include in your feed.

at v6.7-rc3 61 lines 1.3 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2023 Facebook */ 3#include "vmlinux.h" 4#include "bpf_tracing_net.h" 5#include <bpf/bpf_helpers.h> 6#include <bpf/bpf_tracing.h> 7#include <bpf/bpf_core_read.h> 8 9void *local_storage_ptr = NULL; 10void *sk_ptr = NULL; 11int cookie_found = 0; 12__u64 cookie = 0; 13__u32 omem = 0; 14 15void *bpf_rdonly_cast(void *, __u32) __ksym; 16 17struct { 18 __uint(type, BPF_MAP_TYPE_SK_STORAGE); 19 __uint(map_flags, BPF_F_NO_PREALLOC); 20 __type(key, int); 21 __type(value, int); 22} sk_storage SEC(".maps"); 23 24SEC("fexit/bpf_local_storage_destroy") 25int BPF_PROG(bpf_local_storage_destroy, struct bpf_local_storage *local_storage) 26{ 27 struct sock *sk; 28 29 if (local_storage_ptr != local_storage) 30 return 0; 31 32 sk = bpf_rdonly_cast(sk_ptr, bpf_core_type_id_kernel(struct sock)); 33 if (sk->sk_cookie.counter != cookie) 34 return 0; 35 36 cookie_found++; 37 omem = sk->sk_omem_alloc.counter; 38 local_storage_ptr = NULL; 39 40 return 0; 41} 42 43SEC("fentry/inet6_sock_destruct") 44int BPF_PROG(inet6_sock_destruct, struct sock *sk) 45{ 46 int *value; 47 48 if (!cookie || sk->sk_cookie.counter != cookie) 49 return 0; 50 51 value = bpf_sk_storage_get(&sk_storage, sk, 0, 0); 52 if (value && *value == 0xdeadbeef) { 53 cookie_found++; 54 sk_ptr = sk; 55 local_storage_ptr = sk->sk_bpf_storage; 56 } 57 58 return 0; 59} 60 61char _license[] SEC("license") = "GPL";