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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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 #include <stddef.h>
  3 #include <string.h>
  4 #include <netinet/in.h>
  5 #include <linux/bpf.h>
  6 #include <linux/if_ether.h>
  7 #include <linux/if_packet.h>
  8 #include <linux/ip.h>
  9 #include <linux/ipv6.h>
 10 #include <linux/types.h>
 11 #include <linux/socket.h>
 12 #include <linux/tcp.h>
 13 #include <bpf/bpf_helpers.h>
 14 #include <bpf/bpf_endian.h>
 15 #include "test_tcpnotify.h"
 16 
 17 struct {
 18         __uint(type, BPF_MAP_TYPE_ARRAY);
 19         __uint(max_entries, 4);
 20         __type(key, __u32);
 21         __type(value, struct tcpnotify_globals);
 22 } global_map SEC(".maps");
 23 
 24 struct {
 25         __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
 26         __uint(max_entries, 2);
 27         __type(key, int);
 28         __type(value, __u32);
 29 } perf_event_map SEC(".maps");
 30 
 31 SEC("sockops")
 32 int bpf_testcb(struct bpf_sock_ops *skops)
 33 {
 34         int rv = -1;
 35         int op;
 36 
 37         op = (int) skops->op;
 38 
 39         if (bpf_ntohl(skops->remote_port) != TESTPORT) {
 40                 skops->reply = -1;
 41                 return 0;
 42         }
 43 
 44         switch (op) {
 45         case BPF_SOCK_OPS_TIMEOUT_INIT:
 46         case BPF_SOCK_OPS_RWND_INIT:
 47         case BPF_SOCK_OPS_NEEDS_ECN:
 48         case BPF_SOCK_OPS_BASE_RTT:
 49         case BPF_SOCK_OPS_RTO_CB:
 50                 rv = 1;
 51                 break;
 52 
 53         case BPF_SOCK_OPS_TCP_CONNECT_CB:
 54         case BPF_SOCK_OPS_TCP_LISTEN_CB:
 55         case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
 56         case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB:
 57                 bpf_sock_ops_cb_flags_set(skops, (BPF_SOCK_OPS_RETRANS_CB_FLAG|
 58                                           BPF_SOCK_OPS_RTO_CB_FLAG));
 59                 rv = 1;
 60                 break;
 61         case BPF_SOCK_OPS_RETRANS_CB: {
 62                         __u32 key = 0;
 63                         struct tcpnotify_globals g, *gp;
 64                         struct tcp_notifier msg = {
 65                                 .type = 0xde,
 66                                 .subtype = 0xad,
 67                                 .source = 0xbe,
 68                                 .hash = 0xef,
 69                         };
 70 
 71                         rv = 1;
 72 
 73                         /* Update results */
 74                         gp = bpf_map_lookup_elem(&global_map, &key);
 75                         if (!gp)
 76                                 break;
 77                         g = *gp;
 78                         g.total_retrans = skops->total_retrans;
 79                         g.ncalls++;
 80                         bpf_map_update_elem(&global_map, &key, &g,
 81                                             BPF_ANY);
 82                         bpf_perf_event_output(skops, &perf_event_map,
 83                                               BPF_F_CURRENT_CPU,
 84                                               &msg, sizeof(msg));
 85                 }
 86                 break;
 87         default:
 88                 rv = -1;
 89         }
 90         skops->reply = rv;
 91         return 1;
 92 }
 93 char _license[] SEC("license") = "GPL";
 94 

~ [ 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