| .. | .. | 
|---|
| 10 | 10 | #include <linux/version.h> | 
|---|
| 11 | 11 | #include <uapi/linux/bpf.h> | 
|---|
| 12 | 12 | #include <uapi/linux/in6.h> | 
|---|
| 13 |  | -#include "bpf_helpers.h" | 
|---|
|  | 13 | +#include <bpf/bpf_helpers.h> | 
|---|
|  | 14 | +#include <bpf/bpf_tracing.h> | 
|---|
|  | 15 | +#include <bpf/bpf_core_read.h> | 
|---|
|  | 16 | +#include "trace_common.h" | 
|---|
| 14 | 17 |  | 
|---|
| 15 | 18 | #define MAX_NR_PORTS 65536 | 
|---|
| 16 | 19 |  | 
|---|
| 17 | 20 | /* map #0 */ | 
|---|
| 18 |  | -struct bpf_map_def SEC("maps") port_a = { | 
|---|
| 19 |  | -	.type = BPF_MAP_TYPE_ARRAY, | 
|---|
| 20 |  | -	.key_size = sizeof(u32), | 
|---|
| 21 |  | -	.value_size = sizeof(int), | 
|---|
| 22 |  | -	.max_entries = MAX_NR_PORTS, | 
|---|
| 23 |  | -}; | 
|---|
|  | 21 | +struct inner_a { | 
|---|
|  | 22 | +	__uint(type, BPF_MAP_TYPE_ARRAY); | 
|---|
|  | 23 | +	__type(key, u32); | 
|---|
|  | 24 | +	__type(value, int); | 
|---|
|  | 25 | +	__uint(max_entries, MAX_NR_PORTS); | 
|---|
|  | 26 | +} port_a SEC(".maps"); | 
|---|
| 24 | 27 |  | 
|---|
| 25 | 28 | /* map #1 */ | 
|---|
| 26 |  | -struct bpf_map_def SEC("maps") port_h = { | 
|---|
| 27 |  | -	.type = BPF_MAP_TYPE_HASH, | 
|---|
| 28 |  | -	.key_size = sizeof(u32), | 
|---|
| 29 |  | -	.value_size = sizeof(int), | 
|---|
| 30 |  | -	.max_entries = 1, | 
|---|
| 31 |  | -}; | 
|---|
|  | 29 | +struct inner_h { | 
|---|
|  | 30 | +	__uint(type, BPF_MAP_TYPE_HASH); | 
|---|
|  | 31 | +	__type(key, u32); | 
|---|
|  | 32 | +	__type(value, int); | 
|---|
|  | 33 | +	__uint(max_entries, 1); | 
|---|
|  | 34 | +} port_h SEC(".maps"); | 
|---|
| 32 | 35 |  | 
|---|
| 33 | 36 | /* map #2 */ | 
|---|
| 34 |  | -struct bpf_map_def SEC("maps") reg_result_h = { | 
|---|
| 35 |  | -	.type = BPF_MAP_TYPE_HASH, | 
|---|
| 36 |  | -	.key_size = sizeof(u32), | 
|---|
| 37 |  | -	.value_size = sizeof(int), | 
|---|
| 38 |  | -	.max_entries = 1, | 
|---|
| 39 |  | -}; | 
|---|
|  | 37 | +struct { | 
|---|
|  | 38 | +	__uint(type, BPF_MAP_TYPE_HASH); | 
|---|
|  | 39 | +	__type(key, u32); | 
|---|
|  | 40 | +	__type(value, int); | 
|---|
|  | 41 | +	__uint(max_entries, 1); | 
|---|
|  | 42 | +} reg_result_h SEC(".maps"); | 
|---|
| 40 | 43 |  | 
|---|
| 41 | 44 | /* map #3 */ | 
|---|
| 42 |  | -struct bpf_map_def SEC("maps") inline_result_h = { | 
|---|
| 43 |  | -	.type = BPF_MAP_TYPE_HASH, | 
|---|
| 44 |  | -	.key_size = sizeof(u32), | 
|---|
| 45 |  | -	.value_size = sizeof(int), | 
|---|
| 46 |  | -	.max_entries = 1, | 
|---|
| 47 |  | -}; | 
|---|
|  | 45 | +struct { | 
|---|
|  | 46 | +	__uint(type, BPF_MAP_TYPE_HASH); | 
|---|
|  | 47 | +	__type(key, u32); | 
|---|
|  | 48 | +	__type(value, int); | 
|---|
|  | 49 | +	__uint(max_entries, 1); | 
|---|
|  | 50 | +} inline_result_h SEC(".maps"); | 
|---|
| 48 | 51 |  | 
|---|
| 49 | 52 | /* map #4 */ /* Test case #0 */ | 
|---|
| 50 |  | -struct bpf_map_def SEC("maps") a_of_port_a = { | 
|---|
| 51 |  | -	.type = BPF_MAP_TYPE_ARRAY_OF_MAPS, | 
|---|
| 52 |  | -	.key_size = sizeof(u32), | 
|---|
| 53 |  | -	.inner_map_idx = 0, /* map_fd[0] is port_a */ | 
|---|
| 54 |  | -	.max_entries = MAX_NR_PORTS, | 
|---|
| 55 |  | -}; | 
|---|
|  | 53 | +struct { | 
|---|
|  | 54 | +	__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); | 
|---|
|  | 55 | +	__uint(max_entries, MAX_NR_PORTS); | 
|---|
|  | 56 | +	__uint(key_size, sizeof(u32)); | 
|---|
|  | 57 | +	__array(values, struct inner_a); /* use inner_a as inner map */ | 
|---|
|  | 58 | +} a_of_port_a SEC(".maps"); | 
|---|
| 56 | 59 |  | 
|---|
| 57 | 60 | /* map #5 */ /* Test case #1 */ | 
|---|
| 58 |  | -struct bpf_map_def SEC("maps") h_of_port_a = { | 
|---|
| 59 |  | -	.type = BPF_MAP_TYPE_HASH_OF_MAPS, | 
|---|
| 60 |  | -	.key_size = sizeof(u32), | 
|---|
| 61 |  | -	.inner_map_idx = 0, /* map_fd[0] is port_a */ | 
|---|
| 62 |  | -	.max_entries = 1, | 
|---|
| 63 |  | -}; | 
|---|
|  | 61 | +struct { | 
|---|
|  | 62 | +	__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS); | 
|---|
|  | 63 | +	__uint(max_entries, 1); | 
|---|
|  | 64 | +	__uint(key_size, sizeof(u32)); | 
|---|
|  | 65 | +	__array(values, struct inner_a); /* use inner_a as inner map */ | 
|---|
|  | 66 | +} h_of_port_a SEC(".maps"); | 
|---|
| 64 | 67 |  | 
|---|
| 65 | 68 | /* map #6 */ /* Test case #2 */ | 
|---|
| 66 |  | -struct bpf_map_def SEC("maps") h_of_port_h = { | 
|---|
| 67 |  | -	.type = BPF_MAP_TYPE_HASH_OF_MAPS, | 
|---|
| 68 |  | -	.key_size = sizeof(u32), | 
|---|
| 69 |  | -	.inner_map_idx = 1, /* map_fd[1] is port_h */ | 
|---|
| 70 |  | -	.max_entries = 1, | 
|---|
| 71 |  | -}; | 
|---|
|  | 69 | +struct { | 
|---|
|  | 70 | +	__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS); | 
|---|
|  | 71 | +	__uint(max_entries, 1); | 
|---|
|  | 72 | +	__uint(key_size, sizeof(u32)); | 
|---|
|  | 73 | +	__array(values, struct inner_h); /* use inner_h as inner map */ | 
|---|
|  | 74 | +} h_of_port_h SEC(".maps"); | 
|---|
| 72 | 75 |  | 
|---|
| 73 | 76 | static __always_inline int do_reg_lookup(void *inner_map, u32 port) | 
|---|
| 74 | 77 | { | 
|---|
| .. | .. | 
|---|
| 100 | 103 | return result ? *result : -ENOENT; | 
|---|
| 101 | 104 | } | 
|---|
| 102 | 105 |  | 
|---|
| 103 |  | -SEC("kprobe/sys_connect") | 
|---|
|  | 106 | +SEC("kprobe/__sys_connect") | 
|---|
| 104 | 107 | int trace_sys_connect(struct pt_regs *ctx) | 
|---|
| 105 | 108 | { | 
|---|
| 106 | 109 | struct sockaddr_in6 *in6; | 
|---|
| .. | .. | 
|---|
| 110 | 113 | void *outer_map, *inner_map; | 
|---|
| 111 | 114 | bool inline_hash = false; | 
|---|
| 112 | 115 |  | 
|---|
| 113 |  | -	in6 = (struct sockaddr_in6 *)PT_REGS_PARM2(ctx); | 
|---|
| 114 |  | -	addrlen = (int)PT_REGS_PARM3(ctx); | 
|---|
|  | 116 | +	in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(ctx); | 
|---|
|  | 117 | +	addrlen = (int)PT_REGS_PARM3_CORE(ctx); | 
|---|
| 115 | 118 |  | 
|---|
| 116 | 119 | if (addrlen != sizeof(*in6)) | 
|---|
| 117 | 120 | return 0; | 
|---|
| 118 | 121 |  | 
|---|
| 119 |  | -	ret = bpf_probe_read(dst6, sizeof(dst6), &in6->sin6_addr); | 
|---|
|  | 122 | +	ret = bpf_probe_read_user(dst6, sizeof(dst6), &in6->sin6_addr); | 
|---|
| 120 | 123 | if (ret) { | 
|---|
| 121 | 124 | inline_ret = ret; | 
|---|
| 122 | 125 | goto done; | 
|---|
| .. | .. | 
|---|
| 127 | 130 |  | 
|---|
| 128 | 131 | test_case = dst6[7]; | 
|---|
| 129 | 132 |  | 
|---|
| 130 |  | -	ret = bpf_probe_read(&port, sizeof(port), &in6->sin6_port); | 
|---|
|  | 133 | +	ret = bpf_probe_read_user(&port, sizeof(port), &in6->sin6_port); | 
|---|
| 131 | 134 | if (ret) { | 
|---|
| 132 | 135 | inline_ret = ret; | 
|---|
| 133 | 136 | goto done; | 
|---|