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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/test_tcpbpf_kern.c

Version: ~ [ linux-5.19-rc3 ] ~ [ linux-5.18.5 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.48 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.123 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.199 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.248 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.284 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.319 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ 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 ] ~

Diff markup

Differences between /tools/testing/selftests/bpf/test_tcpbpf_kern.c (Version linux-5.0.21) and /tools/testing/selftests/bpf/test_tcpbpf_kern.c (Version linux-5.3.18)


  1 // SPDX-License-Identifier: GPL-2.0                 1 
  2 #include <stddef.h>                               
  3 #include <string.h>                               
  4 #include <linux/bpf.h>                            
  5 #include <linux/if_ether.h>                       
  6 #include <linux/if_packet.h>                      
  7 #include <linux/ip.h>                             
  8 #include <linux/ipv6.h>                           
  9 #include <linux/types.h>                          
 10 #include <linux/socket.h>                         
 11 #include <linux/tcp.h>                            
 12 #include <netinet/in.h>                           
 13 #include "bpf_helpers.h"                          
 14 #include "bpf_endian.h"                           
 15 #include "test_tcpbpf.h"                          
 16                                                   
 17 struct bpf_map_def SEC("maps") global_map = {     
 18         .type = BPF_MAP_TYPE_ARRAY,               
 19         .key_size = sizeof(__u32),                
 20         .value_size = sizeof(struct tcpbpf_glo    
 21         .max_entries = 4,                         
 22 };                                                
 23                                                   
 24 struct bpf_map_def SEC("maps") sockopt_results    
 25         .type = BPF_MAP_TYPE_ARRAY,               
 26         .key_size = sizeof(__u32),                
 27         .value_size = sizeof(int),                
 28         .max_entries = 2,                         
 29 };                                                
 30                                                   
 31 static inline void update_event_map(int event)    
 32 {                                                 
 33         __u32 key = 0;                            
 34         struct tcpbpf_globals g, *gp;             
 35                                                   
 36         gp = bpf_map_lookup_elem(&global_map,     
 37         if (gp == NULL) {                         
 38                 struct tcpbpf_globals g = {0};    
 39                                                   
 40                 g.event_map |= (1 << event);      
 41                 bpf_map_update_elem(&global_ma    
 42                             BPF_ANY);             
 43         } else {                                  
 44                 g = *gp;                          
 45                 g.event_map |= (1 << event);      
 46                 bpf_map_update_elem(&global_ma    
 47                             BPF_ANY);             
 48         }                                         
 49 }                                                 
 50                                                   
 51 int _version SEC("version") = 1;                  
 52                                                   
 53 SEC("sockops")                                    
 54 int bpf_testcb(struct bpf_sock_ops *skops)        
 55 {                                                 
 56         char header[sizeof(struct ipv6hdr) + s    
 57         struct tcphdr *thdr;                      
 58         int good_call_rv = 0;                     
 59         int bad_call_rv = 0;                      
 60         int save_syn = 1;                         
 61         int rv = -1;                              
 62         int v = 0;                                
 63         int op;                                   
 64                                                   
 65         op = (int) skops->op;                     
 66                                                   
 67         update_event_map(op);                     
 68                                                   
 69         switch (op) {                             
 70         case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_C    
 71                 /* Test failure to set largest    
 72                 bad_call_rv = bpf_sock_ops_cb_    
 73                 /* Set callback */                
 74                 good_call_rv = bpf_sock_ops_cb    
 75                                                   
 76                 /* Update results */              
 77                 {                                 
 78                         __u32 key = 0;            
 79                         struct tcpbpf_globals     
 80                                                   
 81                         gp = bpf_map_lookup_el    
 82                         if (!gp)                  
 83                                 break;            
 84                         g = *gp;                  
 85                         g.bad_cb_test_rv = bad    
 86                         g.good_cb_test_rv = go    
 87                         bpf_map_update_elem(&g    
 88                                             BP    
 89                 }                                 
 90                 break;                            
 91         case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_    
 92                 skops->sk_txhash = 0x12345f;      
 93                 v = 0xff;                         
 94                 rv = bpf_setsockopt(skops, SOL    
 95                                     sizeof(v))    
 96                 if (skops->family == AF_INET6)    
 97                         v = bpf_getsockopt(sko    
 98                                            hea    
 99                                                   
100                         if (!v) {                 
101                                 int offset = s    
102                                                   
103                                 thdr = (struct    
104                                 v = thdr->syn;    
105                                 __u32 key = 1;    
106                                                   
107                                 bpf_map_update    
108                                                   
109                         }                         
110                 }                                 
111                 break;                            
112         case BPF_SOCK_OPS_RTO_CB:                 
113                 break;                            
114         case BPF_SOCK_OPS_RETRANS_CB:             
115                 break;                            
116         case BPF_SOCK_OPS_STATE_CB:               
117                 if (skops->args[1] == BPF_TCP_    
118                         __u32 key = 0;            
119                         struct tcpbpf_globals     
120                                                   
121                         gp = bpf_map_lookup_el    
122                         if (!gp)                  
123                                 break;            
124                         g = *gp;                  
125                         if (skops->args[0] ==     
126                                 g.num_listen++    
127                         } else {                  
128                                 g.total_retran    
129                                 g.data_segs_in    
130                                 g.data_segs_ou    
131                                 g.bytes_receiv    
132                                 g.bytes_acked     
133                         }                         
134                         bpf_map_update_elem(&g    
135                                             BP    
136                 }                                 
137                 break;                            
138         case BPF_SOCK_OPS_TCP_LISTEN_CB:          
139                 bpf_sock_ops_cb_flags_set(skop    
140                 v = bpf_setsockopt(skops, IPPR    
141                                    &save_syn,     
142                 /* Update global map w/ result    
143                 __u32 key = 0;                    
144                                                   
145                 bpf_map_update_elem(&sockopt_r    
146                 break;                            
147         default:                                  
148                 rv = -1;                          
149         }                                         
150         skops->reply = rv;                        
151         return 1;                                 
152 }                                                 
153 char _license[] SEC("license") = "GPL";           
154                                                   

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp