~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/samples/bpf/tcp_dumpstats_kern.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Refer to samples/bpf/tcp_bpf.readme for the instructions on
  3  * how to run this sample program.
  4  */
  5 #include <linux/bpf.h>
  6 
  7 #include <bpf/bpf_helpers.h>
  8 #include <bpf/bpf_endian.h>
  9 
 10 #define INTERVAL                        1000000000ULL
 11 
 12 int _version SEC("version") = 1;
 13 char _license[] SEC("license") = "GPL";
 14 
 15 struct {
 16         __u32 type;
 17         __u32 map_flags;
 18         int *key;
 19         __u64 *value;
 20 } bpf_next_dump SEC(".maps") = {
 21         .type = BPF_MAP_TYPE_SK_STORAGE,
 22         .map_flags = BPF_F_NO_PREALLOC,
 23 };
 24 
 25 SEC("sockops")
 26 int _sockops(struct bpf_sock_ops *ctx)
 27 {
 28         struct bpf_tcp_sock *tcp_sk;
 29         struct bpf_sock *sk;
 30         __u64 *next_dump;
 31         __u64 now;
 32 
 33         switch (ctx->op) {
 34         case BPF_SOCK_OPS_TCP_CONNECT_CB:
 35                 bpf_sock_ops_cb_flags_set(ctx, BPF_SOCK_OPS_RTT_CB_FLAG);
 36                 return 1;
 37         case BPF_SOCK_OPS_RTT_CB:
 38                 break;
 39         default:
 40                 return 1;
 41         }
 42 
 43         sk = ctx->sk;
 44         if (!sk)
 45                 return 1;
 46 
 47         next_dump = bpf_sk_storage_get(&bpf_next_dump, sk, 0,
 48                                        BPF_SK_STORAGE_GET_F_CREATE);
 49         if (!next_dump)
 50                 return 1;
 51 
 52         now = bpf_ktime_get_ns();
 53         if (now < *next_dump)
 54                 return 1;
 55 
 56         tcp_sk = bpf_tcp_sock(sk);
 57         if (!tcp_sk)
 58                 return 1;
 59 
 60         *next_dump = now + INTERVAL;
 61 
 62         bpf_printk("dsack_dups=%u delivered=%u\n",
 63                    tcp_sk->dsack_dups, tcp_sk->delivered);
 64         bpf_printk("delivered_ce=%u icsk_retransmits=%u\n",
 65                    tcp_sk->delivered_ce, tcp_sk->icsk_retransmits);
 66 
 67         return 1;
 68 }
 69 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php