Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
d0b3d2d
Documentation
LICENSES
arch
block
certs
crypto
drivers
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
accounting
arch
bootconfig
bpf
build
cgroup
debugging
edid
firewire
firmware
gpio
hv
iio
include
io_uring
kvm/kvm_stat
laptop
leds
lib
memory-model
objtool
pci
pcmcia
perf
power
scripts
spi
testing
fault-injection
ktest
kunit
nvdimm
radix-tree
scatterlist
selftests
android
arm64
bpf
benchs
gnu
map_tests
prog_tests
.gitignore
align.c
attach_probe.c
autoload.c
bpf_iter.c
bpf_obj_id.c
bpf_tcp_ca.c
bpf_verif_scale.c
btf.c
btf_dump.c
btf_endian.c
btf_map_in_map.c
btf_skc_cls_ingress.c
btf_write.c
cg_storage_multi.c
cgroup_attach_autodetach.c
cgroup_attach_multi.c
cgroup_attach_override.c
cgroup_link.c
cgroup_skb_sk_lookup.c
cls_redirect.c
connect_force_port.c
core_autosize.c
core_extern.c
core_reloc.c
core_retro.c
cpu_mask.c
d_path.c
enable_stats.c
endian.c
fentry_fexit.c
fentry_test.c
fexit_bpf2bpf.c
fexit_stress.c
fexit_test.c
flow_dissector.c
flow_dissector_load_bytes.c
flow_dissector_reattach.c
get_stack_raw_tp.c
get_stackid_cannot_attach.c
global_data.c
global_data_init.c
hashmap.c
kfree_skb.c
ksyms.c
ksyms_btf.c
l4lb_all.c
link_pinning.c
load_bytes_relative.c
map_lock.c
map_ptr.c
metadata.c
mmap.c
modify_return.c
ns_current_pid_tgid.c
obj_name.c
pe_preserve_elems.c
perf_branches.c
perf_buffer.c
perf_event_stackmap.c
pinning.c
pkt_access.c
pkt_md_access.c
probe_user.c
prog_run_xattr.c
queue_stack_map.c
raw_tp_test_run.c
raw_tp_writable_reject_nbd_invalid.c
raw_tp_writable_test_run.c
rdonly_maps.c
reference_tracking.c
resolve_btfids.c
ringbuf.c
ringbuf_multi.c
section_names.c
select_reuseport.c
send_signal.c
send_signal_sched_switch.c
signal_pending.c
sk_assign.c
sk_lookup.c
skb_ctx.c
skb_helpers.c
skeleton.c
snprintf_btf.c
sock_fields.c
sockmap_basic.c
sockmap_ktls.c
sockmap_listen.c
sockopt.c
sockopt_inherit.c
sockopt_multi.c
sockopt_sk.c
spinlock.c
stacktrace_build_id.c
stacktrace_build_id_nmi.c
stacktrace_map.c
stacktrace_map_raw_tp.c
subprogs.c
tailcalls.c
task_fd_query_rawtp.c
task_fd_query_tp.c
tcp_estats.c
tcp_hdr_options.c
tcp_rtt.c
tcpbpf_user.c
test_bpffs.c
test_global_funcs.c
test_local_storage.c
test_lsm.c
test_overhead.c
test_profiler.c
tp_attach_query.c
trace_ext.c
trace_printk.c
trampoline_count.c
udp_limit.c
varlen.c
vmlinux.c
xdp.c
xdp_adjust_tail.c
xdp_attach.c
xdp_bpf2bpf.c
xdp_cpumap_attach.c
xdp_devmap_attach.c
xdp_info.c
xdp_link.c
xdp_noinline.c
xdp_perf.c
progs
verifier
.gitignore
Makefile
README.rst
bench.c
bench.h
bpf_legacy.h
bpf_rand.h
bpf_rlimit.h
bpf_tcp_helpers.h
bpf_util.h
cgroup_helpers.c
cgroup_helpers.h
config
flow_dissector_load.c
flow_dissector_load.h
get_cgroup_id_user.c
netcnt_common.h
network_helpers.c
network_helpers.h
settings
test_bpftool.py
test_bpftool.sh
test_bpftool_build.sh
test_bpftool_metadata.sh
test_btf.h
test_cgroup_storage.c
test_cpp.cpp
test_current_pid_tgid_new_ns.c
test_dev_cgroup.c
test_flow_dissector.c
test_flow_dissector.sh
test_ftrace.sh
test_iptunnel_common.h
test_kmod.sh
test_lirc_mode2.sh
test_lirc_mode2_user.c
test_lpm_map.c
test_lru_map.c
test_lwt_ip_encap.sh
test_lwt_seg6local.sh
test_maps.c
test_maps.h
test_netcnt.c
test_offload.py
test_progs.c
test_progs.h
test_select_reuseport_common.h
test_skb_cgroup_id.sh
test_skb_cgroup_id_user.c
test_sock.c
test_sock_addr.c
test_sock_addr.sh
test_socket_cookie.c
test_sockmap.c
test_stub.c
test_sysctl.c
test_tag.c
test_tc_edt.sh
test_tc_redirect.sh
test_tc_tunnel.sh
test_tcp_check_syncookie.sh
test_tcp_check_syncookie_user.c
test_tcp_hdr_options.h
test_tcpbpf.h
test_tcpnotify.h
test_tcpnotify_user.c
test_tunnel.sh
test_verifier.c
test_verifier_log.c
test_xdp_meta.sh
test_xdp_redirect.sh
test_xdp_veth.sh
test_xdp_vlan.sh
test_xdp_vlan_mode_generic.sh
test_xdp_vlan_mode_native.sh
test_xdping.sh
testing_helpers.c
testing_helpers.h
trace_helpers.c
trace_helpers.h
urandom_read.c
with_addr.sh
with_tunnels.sh
xdping.c
xdping.h
breakpoints
capabilities
cgroup
clone3
core
cpu-hotplug
cpufreq
dmabuf-heaps
drivers
efivarfs
exec
filesystems
firmware
fpu
ftrace
futex
gpio
ia64
intel_pstate
ipc
ir
kcmp
kexec
kmod
kselftest
kvm
lib
livepatch
lkdtm
locking
media_tests
membarrier
memfd
memory-hotplug
mincore
mount
mqueue
net
netfilter
nsfs
ntb
openat2
pid_namespace
pidfd
powerpc
prctl
proc
pstore
ptp
ptrace
rcutorture
resctrl
rseq
rtc
safesetid
seccomp
sigaltstack
size
sparc64
splice
static_keys
sync
sysctl
tc-testing
timens
timers
tmpfs
tpm2
uevent
user
vDSO
vm
watchdog
wireguard
x86
zram
.gitignore
Makefile
gen_kselftest_tar.sh
kselftest.h
kselftest_deps.sh
kselftest_harness.h
kselftest_install.sh
kselftest_module.h
lib.mk
run_kselftest.sh
vsock
thermal/tmon
time
usb
virtio
vm
wmi
Makefile
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
tools
/
testing
/
selftests
/
bpf
/
prog_tests
/
tcpbpf_user.c
Blame
Blame
Latest commit
Alexander Duyck
and
Alexei Starovoitov
selftest/bpf: Use global variables instead of maps for test_tcpbpf_kern
Nov 4, 2020
21b5177
·
Nov 4, 2020
History
History
141 lines (113 loc) · 3.96 KB
Breadcrumbs
linux
/
tools
/
testing
/
selftests
/
bpf
/
prog_tests
/
tcpbpf_user.c
Top
File metadata and controls
Code
Blame
141 lines (113 loc) · 3.96 KB
Raw
// SPDX-License-Identifier: GPL-2.0 #include <test_progs.h> #include <network_helpers.h> #include "test_tcpbpf.h" #include "test_tcpbpf_kern.skel.h" #define LO_ADDR6 "::1" #define CG_NAME "/tcpbpf-user-test" static __u32 duration; static void verify_result(struct tcpbpf_globals *result) { __u32 expected_events = ((1 << BPF_SOCK_OPS_TIMEOUT_INIT) | (1 << BPF_SOCK_OPS_RWND_INIT) | (1 << BPF_SOCK_OPS_TCP_CONNECT_CB) | (1 << BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB) | (1 << BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB) | (1 << BPF_SOCK_OPS_NEEDS_ECN) | (1 << BPF_SOCK_OPS_STATE_CB) | (1 << BPF_SOCK_OPS_TCP_LISTEN_CB)); /* check global map */ CHECK(expected_events != result->event_map, "event_map", "unexpected event_map: actual 0x%08x != expected 0x%08x\n", result->event_map, expected_events); ASSERT_EQ(result->bytes_received, 501, "bytes_received"); ASSERT_EQ(result->bytes_acked, 1002, "bytes_acked"); ASSERT_EQ(result->data_segs_in, 1, "data_segs_in"); ASSERT_EQ(result->data_segs_out, 1, "data_segs_out"); ASSERT_EQ(result->bad_cb_test_rv, 0x80, "bad_cb_test_rv"); ASSERT_EQ(result->good_cb_test_rv, 0, "good_cb_test_rv"); ASSERT_EQ(result->num_listen, 1, "num_listen"); /* 3 comes from one listening socket + both ends of the connection */ ASSERT_EQ(result->num_close_events, 3, "num_close_events"); /* check setsockopt for SAVE_SYN */ ASSERT_EQ(result->tcp_save_syn, 0, "tcp_save_syn"); /* check getsockopt for SAVED_SYN */ ASSERT_EQ(result->tcp_saved_syn, 1, "tcp_saved_syn"); } static void run_test(struct tcpbpf_globals *result) { int listen_fd = -1, cli_fd = -1, accept_fd = -1; char buf[1000]; int err = -1; int i, rv; listen_fd = start_server(AF_INET6, SOCK_STREAM, LO_ADDR6, 0, 0); if (CHECK(listen_fd == -1, "start_server", "listen_fd:%d errno:%d\n", listen_fd, errno)) goto done; cli_fd = connect_to_fd(listen_fd, 0); if (CHECK(cli_fd == -1, "connect_to_fd(listen_fd)", "cli_fd:%d errno:%d\n", cli_fd, errno)) goto done; accept_fd = accept(listen_fd, NULL, NULL); if (CHECK(accept_fd == -1, "accept(listen_fd)", "accept_fd:%d errno:%d\n", accept_fd, errno)) goto done; /* Send 1000B of '+'s from cli_fd -> accept_fd */ for (i = 0; i < 1000; i++) buf[i] = '+'; rv = send(cli_fd, buf, 1000, 0); if (CHECK(rv != 1000, "send(cli_fd)", "rv:%d errno:%d\n", rv, errno)) goto done; rv = recv(accept_fd, buf, 1000, 0); if (CHECK(rv != 1000, "recv(accept_fd)", "rv:%d errno:%d\n", rv, errno)) goto done; /* Send 500B of '.'s from accept_fd ->cli_fd */ for (i = 0; i < 500; i++) buf[i] = '.'; rv = send(accept_fd, buf, 500, 0); if (CHECK(rv != 500, "send(accept_fd)", "rv:%d errno:%d\n", rv, errno)) goto done; rv = recv(cli_fd, buf, 500, 0); if (CHECK(rv != 500, "recv(cli_fd)", "rv:%d errno:%d\n", rv, errno)) goto done; /* * shutdown accept first to guarantee correct ordering for * bytes_received and bytes_acked when we go to verify the results. */ shutdown(accept_fd, SHUT_WR); err = recv(cli_fd, buf, 1, 0); if (CHECK(err, "recv(cli_fd) for fin", "err:%d errno:%d\n", err, errno)) goto done; shutdown(cli_fd, SHUT_WR); err = recv(accept_fd, buf, 1, 0); CHECK(err, "recv(accept_fd) for fin", "err:%d errno:%d\n", err, errno); done: if (accept_fd != -1) close(accept_fd); if (cli_fd != -1) close(cli_fd); if (listen_fd != -1) close(listen_fd); if (!err) verify_result(result); } void test_tcpbpf_user(void) { struct test_tcpbpf_kern *skel; int cg_fd = -1; skel = test_tcpbpf_kern__open_and_load(); if (CHECK(!skel, "open and load skel", "failed")) return; cg_fd = test__join_cgroup(CG_NAME); if (CHECK(cg_fd < 0, "test__join_cgroup(" CG_NAME ")", "cg_fd:%d errno:%d", cg_fd, errno)) goto err; skel->links.bpf_testcb = bpf_program__attach_cgroup(skel->progs.bpf_testcb, cg_fd); if (!ASSERT_OK_PTR(skel->links.bpf_testcb, "attach_cgroup(bpf_testcb)")) goto err; run_test(&skel->bss->global); err: if (cg_fd != -1) close(cg_fd); test_tcpbpf_kern__destroy(skel); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
You can’t perform that action at this time.