├── .gitignore ├── .gitmodules ├── CONTRIBUTING ├── LICENSE ├── Makefile ├── README.md ├── bench-afxdp ├── Makefile ├── README.org ├── utils.h ├── xdpsock.c ├── xdpsock.h └── xdpsock_kern.c ├── configure ├── eTran ├── Makefile ├── README.md ├── common │ ├── base │ │ ├── atomic.h │ │ ├── compiler.h │ │ ├── cpu.cc │ │ ├── cpu.h │ │ ├── ipc.cc │ │ ├── ipc.h │ │ ├── kref.h │ │ ├── lock.h │ │ ├── lrpc.cc │ │ ├── lrpc.h │ │ ├── math.h │ │ ├── mem_pool.cc │ │ ├── mem_pool.h │ │ ├── stddef.h │ │ └── types.h │ ├── intf │ │ ├── intf.h │ │ └── intf_ebpf.h │ ├── shm │ │ ├── shm_wrapper.cc │ │ └── shm_wrapper.h │ ├── tran_def │ │ ├── homa.h │ │ └── tcp.h │ └── xskbp │ │ ├── xsk_buffer_pool.cc │ │ └── xsk_buffer_pool.h ├── homa_app │ ├── Makefile │ ├── common_mk │ │ └── common.mk │ ├── cp_node.cc │ ├── dist.cc │ ├── dist.h │ ├── homa.h │ ├── homa_api.c │ ├── test_utils.cc │ ├── test_utils.h │ ├── time_trace.cc │ └── time_trace.h ├── lib │ ├── eTran_common.cc │ ├── eTran_posix.cc │ ├── eTran_rpc.cc │ ├── include │ │ ├── app_if.h │ │ ├── eTran_common.h │ │ ├── eTran_posix.h │ │ ├── eTran_rpc.h │ │ ├── eTran_socket.h │ │ ├── homa_if.h │ │ ├── tcp_if.h │ │ └── xsk_if.h │ ├── interpose.cc │ ├── socket.cc │ └── xsk_if.cc ├── micro_kernel │ ├── Makefile │ ├── cc.cc │ ├── common_mk │ │ └── common.mk │ ├── control_plane.cc │ ├── eBPF │ │ ├── Makefile │ │ ├── ebpf_fib.h │ │ ├── ebpf_kfunc.h │ │ ├── ebpf_lb.h │ │ ├── ebpf_queue.h │ │ ├── ebpf_utils.h │ │ ├── entrance │ │ │ ├── Makefile │ │ │ └── entrance.c │ │ ├── homa │ │ │ ├── Makefile │ │ │ ├── bss_data_defs.h │ │ │ ├── eTran_defs.h │ │ │ ├── homa.h │ │ │ ├── main.c │ │ │ ├── pacing.h │ │ │ └── rpc.h │ │ └── tcp │ │ │ ├── Makefile │ │ │ ├── eTran_defs.h │ │ │ ├── main.c │ │ │ ├── pacing.h │ │ │ └── tcp.h │ ├── ebpf.cc │ ├── ebpf.h │ ├── homa.cc │ ├── micro_kernel.cc │ ├── nic.cc │ ├── nic.h │ ├── runtime │ │ ├── app_if.h │ │ ├── defs.h │ │ ├── ebpf_if.h │ │ ├── homa.h │ │ └── tcp.h │ ├── tcp.cc │ ├── trans_ebpf.cc │ ├── trans_ebpf.h │ └── utils │ │ └── utils.h ├── shared_lib │ ├── Makefile │ └── common_mk │ │ └── common.mk └── tcp_app │ ├── Makefile │ ├── common_mk │ └── common.mk │ ├── epoll_client.cc │ ├── epoll_server.cc │ ├── flexkvs │ ├── benchmark.h │ ├── commandline.c │ ├── hashtable.c │ ├── ialloc.c │ ├── iokvs.h │ ├── jenkins_hash.c │ ├── protocol_binary.h │ ├── rng.c │ ├── rng.h │ ├── settings.c │ ├── socket_shim.h │ ├── utils.c │ ├── utils.h │ └── workload.c │ ├── flexkvs_bench.cc │ ├── flexkvs_server.cc │ ├── lat_client.cc │ └── lat_server.cc ├── headers └── linux │ └── err.h ├── include ├── bpf │ ├── builtins.h │ ├── compiler.h │ └── errno.h ├── jhash.h └── xdp │ ├── context_helpers.h │ └── parsing_helpers.h ├── install.sh ├── lib ├── Makefile ├── common.mk ├── defines.mk ├── install │ ├── .gitignore │ ├── include │ │ └── .gitignore │ └── lib │ │ └── .gitignore ├── libbpf │ ├── .gitattributes │ ├── .github │ │ ├── PULL_REQUEST_TEMPLATE.md │ │ ├── actions │ │ │ ├── build-selftests │ │ │ │ ├── action.yml │ │ │ │ ├── build_selftests.sh │ │ │ │ ├── helpers.sh │ │ │ │ ├── prepare_selftests-4.9.0.sh │ │ │ │ ├── prepare_selftests-5.5.0.sh │ │ │ │ └── vmlinux.h │ │ │ ├── debian │ │ │ │ └── action.yml │ │ │ ├── setup │ │ │ │ └── action.yml │ │ │ └── vmtest │ │ │ │ └── action.yml │ │ └── workflows │ │ │ ├── build.yml │ │ │ ├── cifuzz.yml │ │ │ ├── codeql.yml │ │ │ ├── coverity.yml │ │ │ ├── lint.yml │ │ │ ├── ondemand.yml │ │ │ ├── pahole.yml │ │ │ └── test.yml │ ├── .readthedocs.yaml │ ├── BPF-CHECKPOINT-COMMIT │ ├── CHECKPOINT-COMMIT │ ├── LICENSE │ ├── LICENSE.BSD-2-Clause │ ├── LICENSE.LGPL-2.1 │ ├── README.md │ ├── SYNC.md │ ├── ci │ │ ├── diffs │ │ │ ├── .keep │ │ │ └── 0001-selftests-bpf-xskxceiver-ksft_print_msg-fix-format-t.patch │ │ ├── managers │ │ │ ├── debian.sh │ │ │ ├── test_compile.sh │ │ │ ├── travis_wait.bash │ │ │ └── ubuntu.sh │ │ └── vmtest │ │ │ ├── configs │ │ │ ├── ALLOWLIST-4.9.0 │ │ │ ├── ALLOWLIST-5.5.0 │ │ │ ├── DENYLIST-5.5.0 │ │ │ ├── DENYLIST-latest │ │ │ └── DENYLIST-latest.s390x │ │ │ ├── helpers.sh │ │ │ └── run_selftests.sh │ ├── docs │ │ ├── .gitignore │ │ ├── api.rst │ │ ├── conf.py │ │ ├── index.rst │ │ ├── libbpf_build.rst │ │ ├── libbpf_naming_convention.rst │ │ ├── libbpf_overview.rst │ │ ├── program_types.rst │ │ └── sphinx │ │ │ ├── Makefile │ │ │ ├── doxygen │ │ │ └── Doxyfile │ │ │ └── requirements.txt │ ├── fuzz │ │ ├── bpf-object-fuzzer.c │ │ └── bpf-object-fuzzer_seed_corpus.zip │ ├── include │ │ ├── asm │ │ │ └── barrier.h │ │ ├── linux │ │ │ ├── compiler.h │ │ │ ├── err.h │ │ │ ├── filter.h │ │ │ ├── kernel.h │ │ │ ├── list.h │ │ │ ├── overflow.h │ │ │ ├── ring_buffer.h │ │ │ └── types.h │ │ └── uapi │ │ │ └── linux │ │ │ ├── bpf.h │ │ │ ├── bpf_common.h │ │ │ ├── btf.h │ │ │ ├── fcntl.h │ │ │ ├── if_link.h │ │ │ ├── if_xdp.h │ │ │ ├── netdev.h │ │ │ ├── netlink.h │ │ │ ├── openat2.h │ │ │ ├── perf_event.h │ │ │ ├── pkt_cls.h │ │ │ └── pkt_sched.h │ ├── scripts │ │ ├── build-fuzzers.sh │ │ ├── coverity.sh │ │ └── sync-kernel.sh │ └── src │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── bpf.c │ │ ├── bpf.h │ │ ├── bpf_core_read.h │ │ ├── bpf_endian.h │ │ ├── bpf_gen_internal.h │ │ ├── bpf_helper_defs.h │ │ ├── bpf_helpers.h │ │ ├── bpf_prog_linfo.c │ │ ├── bpf_tracing.h │ │ ├── btf.c │ │ ├── btf.h │ │ ├── btf_dump.c │ │ ├── elf.c │ │ ├── gen_loader.c │ │ ├── hashmap.c │ │ ├── hashmap.h │ │ ├── libbpf.c │ │ ├── libbpf.h │ │ ├── libbpf.map │ │ ├── libbpf.pc.template │ │ ├── libbpf_common.h │ │ ├── libbpf_errno.c │ │ ├── libbpf_internal.h │ │ ├── libbpf_legacy.h │ │ ├── libbpf_probes.c │ │ ├── libbpf_version.h │ │ ├── linker.c │ │ ├── netlink.c │ │ ├── nlattr.c │ │ ├── nlattr.h │ │ ├── relo_core.c │ │ ├── relo_core.h │ │ ├── ringbuf.c │ │ ├── skel_internal.h │ │ ├── str_error.c │ │ ├── str_error.h │ │ ├── strset.c │ │ ├── strset.h │ │ ├── usdt.bpf.h │ │ ├── usdt.c │ │ ├── zip.c │ │ └── zip.h ├── testenv │ ├── README.org │ ├── config.sh │ ├── setup-env.sh │ └── testenv.sh ├── util │ ├── Makefile │ ├── json_writer.c │ ├── json_writer.h │ ├── logging.c │ ├── logging.h │ └── util.mk └── xdp-tools │ ├── .clang-format │ ├── .github │ ├── scripts │ │ ├── .config │ │ ├── prepare_test_kernel.sh │ │ ├── prepare_test_tools.sh │ │ ├── run_tests.sh │ │ └── run_tests_in_vm.sh │ └── workflows │ │ ├── covscan.yml │ │ ├── release.yml │ │ └── selftests.yml │ ├── .gitignore │ ├── .gitmodules │ ├── .lgtm.yml │ ├── LICENSE │ ├── LICENSES │ ├── BSD-2-Clause │ ├── GPL-2.0 │ └── LGPL-2.1 │ ├── Makefile │ ├── README.org │ ├── configure │ ├── headers │ ├── bpf │ │ ├── bpf_trace_helpers.h │ │ └── vmlinux.h │ ├── linux │ │ ├── bpf.h │ │ ├── btf.h │ │ ├── compiler-gcc.h │ │ ├── compiler.h │ │ ├── compiler_types.h │ │ ├── err.h │ │ ├── hashtable.h │ │ ├── hlist.h │ │ ├── icmp.h │ │ ├── if.h │ │ ├── if_link.h │ │ ├── if_xdp.h │ │ ├── jhash.h │ │ ├── list.h │ │ └── perf-sys.h │ └── xdp │ │ ├── libxdp.h │ │ ├── parsing_helpers.h │ │ ├── prog_dispatcher.h │ │ ├── xdp_helpers.h │ │ ├── xdp_sample.bpf.h │ │ ├── xdp_sample_common.bpf.h │ │ ├── xdp_sample_shared.h │ │ ├── xdp_stats_kern.h │ │ ├── xdp_stats_kern_user.h │ │ └── xsk.h │ ├── lib │ ├── Makefile │ ├── README.org │ ├── common.mk │ ├── defines.mk │ ├── export-man.el │ ├── libbpf │ │ ├── .gitattributes │ │ ├── .github │ │ │ ├── PULL_REQUEST_TEMPLATE.md │ │ │ ├── actions │ │ │ │ ├── build-selftests │ │ │ │ │ ├── action.yml │ │ │ │ │ ├── build_selftests.sh │ │ │ │ │ ├── helpers.sh │ │ │ │ │ ├── prepare_selftests-4.9.0.sh │ │ │ │ │ ├── prepare_selftests-5.5.0.sh │ │ │ │ │ └── vmlinux.h │ │ │ │ ├── debian │ │ │ │ │ └── action.yml │ │ │ │ ├── setup │ │ │ │ │ └── action.yml │ │ │ │ └── vmtest │ │ │ │ │ └── action.yml │ │ │ └── workflows │ │ │ │ ├── build.yml │ │ │ │ ├── cifuzz.yml │ │ │ │ ├── codeql.yml │ │ │ │ ├── coverity.yml │ │ │ │ ├── lint.yml │ │ │ │ ├── ondemand.yml │ │ │ │ ├── pahole.yml │ │ │ │ └── test.yml │ │ ├── .readthedocs.yaml │ │ ├── BPF-CHECKPOINT-COMMIT │ │ ├── CHECKPOINT-COMMIT │ │ ├── LICENSE │ │ ├── LICENSE.BSD-2-Clause │ │ ├── LICENSE.LGPL-2.1 │ │ ├── README.md │ │ ├── SYNC.md │ │ ├── ci │ │ │ ├── diffs │ │ │ │ ├── .keep │ │ │ │ └── 0001-selftests-bpf-xskxceiver-ksft_print_msg-fix-format-t.patch │ │ │ ├── managers │ │ │ │ ├── debian.sh │ │ │ │ ├── test_compile.sh │ │ │ │ ├── travis_wait.bash │ │ │ │ └── ubuntu.sh │ │ │ └── vmtest │ │ │ │ ├── configs │ │ │ │ ├── ALLOWLIST-4.9.0 │ │ │ │ ├── ALLOWLIST-5.5.0 │ │ │ │ ├── DENYLIST-5.5.0 │ │ │ │ ├── DENYLIST-latest │ │ │ │ └── DENYLIST-latest.s390x │ │ │ │ ├── helpers.sh │ │ │ │ └── run_selftests.sh │ │ ├── docs │ │ │ ├── .gitignore │ │ │ ├── api.rst │ │ │ ├── conf.py │ │ │ ├── index.rst │ │ │ ├── libbpf_build.rst │ │ │ ├── libbpf_naming_convention.rst │ │ │ ├── libbpf_overview.rst │ │ │ ├── program_types.rst │ │ │ └── sphinx │ │ │ │ ├── Makefile │ │ │ │ ├── doxygen │ │ │ │ └── Doxyfile │ │ │ │ └── requirements.txt │ │ ├── fuzz │ │ │ ├── bpf-object-fuzzer.c │ │ │ └── bpf-object-fuzzer_seed_corpus.zip │ │ ├── include │ │ │ ├── asm │ │ │ │ └── barrier.h │ │ │ ├── linux │ │ │ │ ├── compiler.h │ │ │ │ ├── err.h │ │ │ │ ├── filter.h │ │ │ │ ├── kernel.h │ │ │ │ ├── list.h │ │ │ │ ├── overflow.h │ │ │ │ ├── ring_buffer.h │ │ │ │ └── types.h │ │ │ └── uapi │ │ │ │ └── linux │ │ │ │ ├── bpf.h │ │ │ │ ├── bpf_common.h │ │ │ │ ├── btf.h │ │ │ │ ├── fcntl.h │ │ │ │ ├── if_link.h │ │ │ │ ├── if_xdp.h │ │ │ │ ├── netdev.h │ │ │ │ ├── netlink.h │ │ │ │ ├── openat2.h │ │ │ │ ├── perf_event.h │ │ │ │ ├── pkt_cls.h │ │ │ │ └── pkt_sched.h │ │ ├── scripts │ │ │ ├── build-fuzzers.sh │ │ │ ├── coverity.sh │ │ │ └── sync-kernel.sh │ │ └── src │ │ │ ├── .gitignore │ │ │ ├── Makefile │ │ │ ├── bpf.c │ │ │ ├── bpf.h │ │ │ ├── bpf_core_read.h │ │ │ ├── bpf_endian.h │ │ │ ├── bpf_gen_internal.h │ │ │ ├── bpf_helper_defs.h │ │ │ ├── bpf_helpers.h │ │ │ ├── bpf_prog_linfo.c │ │ │ ├── bpf_tracing.h │ │ │ ├── btf.c │ │ │ ├── btf.h │ │ │ ├── btf_dump.c │ │ │ ├── elf.c │ │ │ ├── gen_loader.c │ │ │ ├── hashmap.c │ │ │ ├── hashmap.h │ │ │ ├── libbpf.c │ │ │ ├── libbpf.h │ │ │ ├── libbpf.map │ │ │ ├── libbpf.pc.template │ │ │ ├── libbpf_common.h │ │ │ ├── libbpf_errno.c │ │ │ ├── libbpf_internal.h │ │ │ ├── libbpf_legacy.h │ │ │ ├── libbpf_probes.c │ │ │ ├── libbpf_version.h │ │ │ ├── linker.c │ │ │ ├── netlink.c │ │ │ ├── nlattr.c │ │ │ ├── nlattr.h │ │ │ ├── relo_core.c │ │ │ ├── relo_core.h │ │ │ ├── ringbuf.c │ │ │ ├── root │ │ │ └── usr │ │ │ │ └── include │ │ │ │ └── bpf │ │ │ │ ├── bpf.h │ │ │ │ ├── bpf_core_read.h │ │ │ │ ├── bpf_endian.h │ │ │ │ ├── bpf_helper_defs.h │ │ │ │ ├── bpf_helpers.h │ │ │ │ ├── bpf_tracing.h │ │ │ │ ├── btf.h │ │ │ │ ├── libbpf.h │ │ │ │ ├── libbpf_common.h │ │ │ │ ├── libbpf_legacy.h │ │ │ │ ├── libbpf_version.h │ │ │ │ ├── skel_internal.h │ │ │ │ └── usdt.bpf.h │ │ │ ├── skel_internal.h │ │ │ ├── str_error.c │ │ │ ├── str_error.h │ │ │ ├── strset.c │ │ │ ├── strset.h │ │ │ ├── usdt.bpf.h │ │ │ ├── usdt.c │ │ │ ├── zip.c │ │ │ └── zip.h │ ├── libxdp │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── README.org │ │ ├── bpf_instr.h │ │ ├── compat.h │ │ ├── libxdp.3 │ │ ├── libxdp.c │ │ ├── libxdp.man~ │ │ ├── libxdp.map │ │ ├── libxdp.mk │ │ ├── libxdp.pc.template │ │ ├── libxdp_internal.h │ │ ├── protocol.org │ │ ├── tests │ │ │ ├── .gitignore │ │ │ ├── Makefile │ │ │ ├── check_kern_compat.c │ │ │ ├── test-libxdp.sh │ │ │ ├── test_dispatcher_versions.c │ │ │ ├── test_runner.sh │ │ │ ├── test_utils.h │ │ │ ├── test_xdp_frags.c │ │ │ ├── test_xsk_refcnt.c │ │ │ ├── xdp_dispatcher_v1.c │ │ │ ├── xdp_dispatcher_v1.h │ │ │ └── xdp_pass.c │ │ ├── xdp-dispatcher.c.in │ │ ├── xsk.c │ │ ├── xsk_def_xdp_prog.c │ │ ├── xsk_def_xdp_prog.h │ │ └── xsk_def_xdp_prog_5.3.c │ ├── testing │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── run_tests.sh │ │ ├── setup-netns-env.sh │ │ ├── test-tool.c │ │ ├── test_config.install.sh │ │ ├── test_long_func_name.c │ │ ├── test_runner.sh │ │ ├── xdp_drop.c │ │ └── xdp_pass.c │ └── util │ │ ├── Makefile │ │ ├── compat.h │ │ ├── logging.c │ │ ├── logging.h │ │ ├── params.c │ │ ├── params.h │ │ ├── stats.c │ │ ├── stats.h │ │ ├── util.c │ │ ├── util.h │ │ ├── util.mk │ │ ├── xdp_sample.bpf.c │ │ ├── xdp_sample.c │ │ ├── xdp_sample.h │ │ ├── xpcapng.c │ │ └── xpcapng.h │ ├── mkarchive.sh │ ├── packaging │ └── rpm │ │ ├── README.org │ │ └── xdp-tools.spec │ ├── version.mk │ ├── xdp-bench │ ├── .gitignore │ ├── Makefile │ ├── README.org │ ├── hash_func01.h │ ├── tests │ │ └── test-xdp-bench.sh │ ├── xdp-bench.8 │ ├── xdp-bench.c │ ├── xdp-bench.h │ ├── xdp_basic.bpf.c │ ├── xdp_basic.c │ ├── xdp_redirect_basic.bpf.c │ ├── xdp_redirect_basic.c │ ├── xdp_redirect_cpumap.bpf.c │ ├── xdp_redirect_cpumap.c │ ├── xdp_redirect_devmap.bpf.c │ ├── xdp_redirect_devmap.c │ ├── xdp_redirect_devmap_multi.bpf.c │ └── xdp_redirect_devmap_multi.c │ ├── xdp-dump │ ├── .gitignore │ ├── Makefile │ ├── README.org │ ├── tests │ │ └── test-xdpdump.sh │ ├── xdpdump.8 │ ├── xdpdump.c │ ├── xdpdump.h │ ├── xdpdump_bpf.c │ └── xdpdump_xdp.c │ ├── xdp-filter │ ├── .gitignore │ ├── Makefile │ ├── README.org │ ├── common_kern_user.h │ ├── extract_features.sh │ ├── tests │ │ ├── common.py │ │ ├── test-xdp-filter.sh │ │ ├── test_basic.py │ │ └── test_slow.py │ ├── xdp-filter.8 │ ├── xdp-filter.c │ ├── xdpfilt_alw_all.c │ ├── xdpfilt_alw_eth.c │ ├── xdpfilt_alw_ip.c │ ├── xdpfilt_alw_tcp.c │ ├── xdpfilt_alw_udp.c │ ├── xdpfilt_dny_all.c │ ├── xdpfilt_dny_eth.c │ ├── xdpfilt_dny_ip.c │ ├── xdpfilt_dny_tcp.c │ ├── xdpfilt_dny_udp.c │ └── xdpfilt_prog.h │ ├── xdp-loader │ ├── .gitignore │ ├── Makefile │ ├── README.org │ ├── tests │ │ └── test-xdp-loader.sh │ ├── xdp-loader.8 │ └── xdp-loader.c │ ├── xdp-monitor │ ├── .gitignore │ ├── Makefile │ ├── README.org │ ├── tests │ │ └── test-xdp-monitor.sh │ ├── xdp-monitor.8 │ ├── xdp-monitor.c │ └── xdp_monitor.bpf.c │ └── xdp-trafficgen │ ├── .gitignore │ ├── Makefile │ ├── README.org │ ├── tests │ └── test-xdp-trafficgen.sh │ ├── xdp-trafficgen.8 │ ├── xdp-trafficgen.8~ │ ├── xdp-trafficgen.c │ ├── xdp-trafficgen.h │ └── xdp_trafficgen.bpf.c └── process-proxy ├── Makefile ├── README.org ├── non_priviledged_process.c ├── priviledged_process.c ├── xdpsock.h └── xdpsock_kern.c /.gitignore: -------------------------------------------------------------------------------- 1 | config.mk 2 | .ccls-cache 3 | compile_commands.json 4 | *.ll 5 | *.o 6 | *.so 7 | *.a 8 | *.skel.h 9 | *.d 10 | *.tmp 11 | .vscode 12 | .cache 13 | lib/libbpf-install/ 14 | llvm.sh 15 | bpftool/ 16 | 17 | # Ignore all executables 18 | bench-afxdp/xdpsock 19 | process-proxy/non_priviledged_process 20 | process-proxy/priviledged_process 21 | 22 | eTran/micro_kernel/micro_kernel 23 | eTran/tcp_app/lat_client 24 | eTran/tcp_app/lat_server 25 | eTran/tcp_app/epoll_server 26 | eTran/tcp_app/epoll_client 27 | eTran/tcp_app/flexkvs_bench 28 | eTran/tcp_app/flexkvs_server 29 | eTran/homa_app/cp_node 30 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/libbpf"] 2 | path = lib/libbpf 3 | url = https://github.com/xdp-project/libbpf.git 4 | ignore = dirty 5 | [submodule "lib/xdp-tools"] 6 | path = lib/xdp-tools 7 | url = https://github.com/xdp-project/xdp-tools 8 | ignore = dirty -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | This repository exists to serve as an example of well-written code that uses BPF 2 | so that others can learn best practices. Examples range from small snippets 3 | demonstrating a single feature, to slightly larger functional applications. 4 | 5 | If you have a code example that you think others would benefit from, you are 6 | very welcome to open a pull request adding your example to this repository. When 7 | doing so, please bear in mind the following guidelines: 8 | 9 | - Code should be written following the Linux kernel style guide for C code. 10 | There's a .clang-format file in the kernel source tree you can use to aid 11 | formatting. 12 | 13 | - The code example should generally use the infrastructure in this repository 14 | for building. This includes the Makefile and header files in include/. If your 15 | example requires changes to this infrastructure that is OK; just include those 16 | as separate commits in the beginning of your PR. 17 | 18 | - Make sure to split out your changes into separate commits that can be reviewed 19 | independently, with a well-written commit message for each describing your 20 | change at a high level. The kernel guide to submitting patches may be helpful 21 | here, specifically the sections on "Describe your changes" and "Separate your 22 | changes": https://docs.kernel.org/process/submitting-patches.html 23 | 24 | - Code contributions should generally be licensed as GPLv2, or optionally 25 | dual-licensed GPLv2/BSD. Source files should have SPDX headers indicating 26 | their license, and your commits should include a Signed-off-by header 27 | serving as your Developer's Certificate of Origin (see 28 | https://docs.kernel.org/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin) 29 | 30 | - Make sure to include your code directory in the top-level Makefile, and add a 31 | README.org file inside the directory describing what your example does. 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Zhongjie Chen, Qingkai Meng, Yang Zhou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 2 | # Top level Makefile for bpf-examples 3 | 4 | ifeq ("$(origin V)", "command line") 5 | VERBOSE = $(V) 6 | endif 7 | ifndef VERBOSE 8 | VERBOSE = 0 9 | endif 10 | 11 | ifeq ($(VERBOSE),0) 12 | MAKEFLAGS += --no-print-directory 13 | Q = @ 14 | endif 15 | 16 | .PHONY: check_submodule help clobber distclean clean $(SUBDIRS) 17 | 18 | all: lib $(SUBDIRS) 19 | 20 | lib: config.mk check_submodule 21 | @echo; echo $@; $(MAKE) -C $@ 22 | 23 | $(SUBDIRS): lib 24 | @echo; echo $@; $(MAKE) -C $@ 25 | 26 | help: 27 | @echo "Make Targets:" 28 | @echo " all - build binaries" 29 | @echo " clean - remove products of build" 30 | @echo " distclean - remove configuration and build" 31 | @echo " install - install binaries on local machine" 32 | @echo " test - run test suite" 33 | @echo " archive - create tarball of all sources" 34 | @echo "" 35 | @echo "Make Arguments:" 36 | @echo " V=[0|1] - set build verbosity level" 37 | 38 | config.mk: configure 39 | sh configure 40 | 41 | check_submodule: 42 | @if [ -d .git ] && `git submodule status lib/libbpf | grep -q '^+'`; then \ 43 | echo "" ;\ 44 | echo "** WARNING **: git submodule SHA-1 out-of-sync" ;\ 45 | echo " consider running: git submodule update" ;\ 46 | echo "" ;\ 47 | fi\ 48 | 49 | clobber: 50 | touch config.mk 51 | $(MAKE) clean 52 | rm -f config.mk cscope.* compile_commands.json 53 | 54 | distclean: clobber 55 | 56 | clean: check_submodule 57 | $(Q)for i in $(SUBDIRS); \ 58 | do $(MAKE) -C $$i clean; done 59 | $(Q)$(MAKE) -C lib clean 60 | 61 | compile_commands.json: clean 62 | compiledb make V=1 63 | -------------------------------------------------------------------------------- /bench-afxdp/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 | 3 | USER_TARGETS := xdpsock 4 | BPF_TARGETS := xdpsock_kern 5 | 6 | LDLIBS += -lpthread 7 | LIB_DIR = ../lib 8 | 9 | include $(LIB_DIR)/common.mk 10 | -------------------------------------------------------------------------------- /bench-afxdp/xdpsock.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 2 | * 3 | * Copyright(c) 2019 - 2022 Intel Corporation. 4 | */ 5 | 6 | #ifndef XDPSOCK_H_ 7 | #define XDPSOCK_H_ 8 | 9 | #define MAX_SOCKS 4 10 | 11 | #define SOCKET_NAME "sock_cal_bpf_fd" 12 | #define MAX_NUM_OF_CLIENTS 10 13 | 14 | #define CLOSE_CONN 1 15 | 16 | typedef __u64 u64; 17 | typedef __u32 u32; 18 | 19 | #endif /* XDPSOCK_H */ 20 | -------------------------------------------------------------------------------- /eTran/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | 3 | all: 4 | $(MAKE) -C ../ 5 | $(MAKE) -C shared_lib 6 | $(MAKE) -C micro_kernel 7 | $(MAKE) -C tcp_app 8 | $(MAKE) -C homa_app 9 | 10 | clean: 11 | $(MAKE) -C shared_lib clean 12 | $(MAKE) -C micro_kernel clean 13 | $(MAKE) -C tcp_app clean 14 | $(MAKE) -C homa_app clean -------------------------------------------------------------------------------- /eTran/README.md: -------------------------------------------------------------------------------- 1 | # Code Structure 2 | 3 | - `common/`: common code used by application library and microkernel 4 | - `lib/`: code for application library 5 | - `shared_lib/`: shared library 6 | - `tcp_app/`: TCP applications using Socket API 7 | - `homa_app/`: Homa applications using Customized event-loop API 8 | - `micro_kernel/`: microkernel 9 | - `eBPF`: eBPF code -------------------------------------------------------------------------------- /eTran/common/base/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * compiler.h - useful compiler hints, intrinsics, and attributes 3 | */ 4 | 5 | #pragma once 6 | 7 | #ifndef likely 8 | #define likely(x) __builtin_expect(!!(x), 1) 9 | #endif 10 | #ifndef unlikely 11 | #define unlikely(x) __builtin_expect(!!(x), 0) 12 | #endif 13 | #define unreachable() __builtin_unreachable() 14 | 15 | #define prefetch0(x) __builtin_prefetch((x), 0, 3) 16 | #define prefetch1(x) __builtin_prefetch((x), 0, 2) 17 | #define prefetch2(x) __builtin_prefetch((x), 0, 1) 18 | #define prefetchnta(x) __builtin_prefetch((x), 0, 0) 19 | #define prefetch(x) prefetch0(x) 20 | 21 | /* variable attributes */ 22 | #define __packed __attribute__((packed)) 23 | #define __notused __attribute__((unused)) 24 | #define __used __attribute__((used)) 25 | #define __aligned(x) __attribute__((aligned(x))) 26 | 27 | /* function attributes */ 28 | #define __noinline __attribute__((noinline)) 29 | #define __noreturn __attribute__((noreturn)) 30 | #define __must_use_return __attribute__((warn_unused_result)) 31 | #define __pure __attribute__((pure)) 32 | #define __weak __attribute__((weak)) 33 | #define __malloc __attribute__((malloc)) 34 | #define __assume_aligned(x) __attribute__((assume_aligned(x))) 35 | 36 | #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 37 | 38 | #if GCC_VERSION >= 40800 39 | #define HAS_BUILTIN_BSWAP 1 40 | #endif 41 | 42 | #define barrier() asm volatile("" ::: "memory") 43 | 44 | #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) 45 | 46 | #define type_is_native(t) \ 47 | (sizeof(t) == sizeof(char) || \ 48 | sizeof(t) == sizeof(short) || \ 49 | sizeof(t) == sizeof(int) || \ 50 | sizeof(t) == sizeof(long)) 51 | 52 | /* 53 | * These attributes are defined only with the sparse checker tool. 54 | */ 55 | #ifdef __CHECKER__ 56 | #define __rcu __attribute__((noderef, address_space(1))) 57 | #define __perthread __attribute__((noderef, address_space(2))) 58 | #define __force __attribute__((force)) 59 | #undef __assume_aligned 60 | #define __assume_aligned(x) 61 | #else /* __CHECKER__ */ 62 | #define __rcu 63 | #define __perthread 64 | #define __force 65 | #endif /* __CHECKER__ */ -------------------------------------------------------------------------------- /eTran/common/base/cpu.cc: -------------------------------------------------------------------------------- 1 | #include "cpu.h" -------------------------------------------------------------------------------- /eTran/common/base/ipc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | int transfer_fd(int sockfd, int fd); 14 | int receive_fd(int sockfd, int *fd); 15 | 16 | int transfer_fds(int sockfd, int* fds, int fd_count); 17 | int receive_fds(int sockfd, int* fds, int fd_count); 18 | 19 | ssize_t write_all(int fd, const void *buffer, size_t count); 20 | ssize_t read_all(int fd, void *buffer, size_t count); 21 | 22 | static inline void kick_evfd(int evfd) 23 | { 24 | uint64_t u = 1; 25 | ssize_t ret = write(evfd, &u, sizeof(u)); 26 | (void)ret; 27 | } 28 | 29 | static inline uint64_t consume_evfd(int evfd) 30 | { 31 | uint64_t u; 32 | ssize_t ret = read(evfd, &u, sizeof(u)); 33 | if (ret != sizeof(u)) 34 | return 0; 35 | return u; 36 | } 37 | -------------------------------------------------------------------------------- /eTran/common/base/kref.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kref.h - generic support for reference counts 3 | * 4 | * This implementation is inspired by the following paper: 5 | * Kroah-Hartman, Greg, kobjects and krefs. Linux Symposium 2004 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | struct kref { 14 | atomic32_t cnt; 15 | }; 16 | 17 | /** 18 | * kref_init - initializes the reference count to one 19 | * @ref: the kref 20 | */ 21 | static inline void 22 | kref_init(struct kref *ref) 23 | { 24 | atomic32_set(&ref->cnt, 1); 25 | } 26 | 27 | /** 28 | * kref_initn - initializes the reference count to @n 29 | * @ref: the kref 30 | * @n: the initial reference count 31 | */ 32 | static inline void 33 | kref_initn(struct kref *ref, int n) 34 | { 35 | atomic32_set(&ref->cnt, n); 36 | } 37 | 38 | /** 39 | * kref_get - atomically increments the reference count 40 | * @ref: the kref 41 | */ 42 | static inline void 43 | kref_get(struct kref *ref) 44 | { 45 | assert(atomic32_read(&ref->cnt) > 0); 46 | atomic32_inc(&ref->cnt); 47 | } 48 | 49 | /** 50 | * kref_put - atomically decrements the reference count, releasing the object 51 | * when it reaches zero 52 | * @ref: the kref 53 | * @release: a pointer to the release function 54 | */ 55 | static inline void 56 | kref_put(struct kref *ref, void (*release)(struct kref *ref)) 57 | { 58 | assert(release); 59 | if (atomic32_dec_and_test(&ref->cnt)) 60 | release(ref); 61 | } 62 | 63 | /** 64 | * kref_released - has this kref been released? 65 | * @ref: the kref 66 | * 67 | * WARNING: this is unsafe without additional synchronization. For example, use 68 | * this function while holding a lock that prevents the release() function from 69 | * removing the object from the data structure you are accessing. 70 | * 71 | * Returns true if the reference count has dropped to zero. 72 | */ 73 | static inline bool 74 | kref_released(struct kref *ref) 75 | { 76 | return atomic32_read(&ref->cnt) == 0; 77 | } 78 | -------------------------------------------------------------------------------- /eTran/common/base/lock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | typedef struct 10 | { 11 | volatile int locked; 12 | } spinlock_t; 13 | 14 | #define SPINLOCK_INITIALIZER \ 15 | { \ 16 | .locked = 0 \ 17 | } 18 | #define DEFINE_SPINLOCK(x) spinlock_t x = SPINLOCK_INITIALIZER 19 | #define DECLARE_SPINLOCK(x) extern spinlock_t x 20 | 21 | static inline void spin_lock_init(spinlock_t *lock) 22 | { 23 | lock->locked = 0; 24 | } 25 | 26 | static inline bool spin_lock_try(spinlock_t *lock) 27 | { 28 | return __sync_lock_test_and_set(&lock->locked, 1) == 0; 29 | } 30 | 31 | static inline void spin_lock(spinlock_t *lock) 32 | { 33 | while (__sync_lock_test_and_set(&lock->locked, 1)) 34 | { 35 | while (lock->locked) 36 | { 37 | cpu_relax(); 38 | } 39 | } 40 | } 41 | 42 | static inline void spin_unlock(spinlock_t *lock) 43 | { 44 | assert(lock->locked == 1); 45 | __sync_lock_release(&lock->locked); 46 | } -------------------------------------------------------------------------------- /eTran/common/base/lrpc.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lrpc.cc - shared memory communication channels 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int __lrpc_send(struct lrpc_chan_out *chan, lrpc_msg *msg) 9 | { 10 | lrpc_msg *dst; 11 | uint64_t cmd = msg->cmd; 12 | 13 | assert(chan->send_head - chan->send_tail == chan->size); 14 | 15 | chan->send_tail = load_acquire(chan->recv_head_wb); 16 | 17 | if (chan->send_head - chan->send_tail == chan->size) 18 | return -1; 19 | 20 | dst = &chan->tbl[chan->send_head & (chan->size - 1)]; 21 | 22 | memcpy(dst->data, msg->data, sizeof(dst->data)); 23 | 24 | cmd |= (chan->send_head++ & chan->size) ? 0 : LRPC_DONE_PARITY; 25 | store_release(&dst->cmd, cmd); 26 | return 0; 27 | } 28 | 29 | /** 30 | * lrpc_init_out - initializes an egress shared memory channel 31 | * @chan: the channel struct to initialize 32 | * @tbl: a buffer to store channel messages 33 | * @size: the number of message elements in the buffer 34 | * @recv_head_wb: a pointer to the head position of the receiver 35 | * 36 | * returns 0 if successful, or -EINVAL if @size is not a power of two. 37 | */ 38 | int lrpc_init_out(struct lrpc_chan_out *chan, lrpc_msg *tbl, 39 | unsigned int size, uint32_t *recv_head_wb) 40 | { 41 | if (!is_power_of_two(size)) 42 | return -EINVAL; 43 | 44 | memset(chan, 0, sizeof(*chan)); 45 | chan->tbl = tbl; 46 | chan->size = size; 47 | chan->recv_head_wb = recv_head_wb; 48 | return 0; 49 | } 50 | 51 | /** 52 | * lrpc_init_in - initializes an ingress shared memory channel 53 | * @chan: the channel struct to initialize 54 | * @tbl: a buffer to store channel messages 55 | * @size: the number of message elements in the buffer 56 | * @recv_head_wb: a pointer to the head position of the receiver 57 | * 58 | * returns 0 if successful, or -EINVAL if @size is not a power of two. 59 | */ 60 | int lrpc_init_in(struct lrpc_chan_in *chan, lrpc_msg *tbl, 61 | unsigned int size, uint32_t *recv_head_wb) 62 | { 63 | if (!is_power_of_two(size)) 64 | return -EINVAL; 65 | 66 | memset(chan, 0, sizeof(*chan)); 67 | chan->tbl = tbl; 68 | chan->size = size; 69 | chan->recv_head_wb = recv_head_wb; 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /eTran/common/base/math.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #define CEIL_DIV(a, b) (((a) + (b) - 1) / (b)) 8 | 9 | static inline size_t round_up(size_t x, size_t power_of_two_number) { 10 | assert (is_power_of_two(power_of_two_number)); 11 | return (x + power_of_two_number - 1) & ~(power_of_two_number - 1); 12 | } 13 | 14 | /// Return the index of the most significant bit of x. The index of the 2^0 15 | /// bit is 1. (x = 0 returns 0, x = 1 returns 1.) 16 | static inline size_t msb_index(int x) 17 | { 18 | assert(x < INT32_MAX / 2); 19 | int index; 20 | asm("bsrl %1, %0" : "=r"(index) : "r"(x << 1)); 21 | return static_cast(index); 22 | } -------------------------------------------------------------------------------- /eTran/common/base/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* Atomic types */ 6 | typedef struct { 7 | volatile int32_t counter; 8 | } atomic32_t; 9 | 10 | typedef struct { 11 | volatile int64_t counter; 12 | } atomic64_t; -------------------------------------------------------------------------------- /eTran/common/shm/shm_wrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | typedef uintptr_t shmptr_t; 10 | 11 | struct shm_wrapper { 12 | std::string name; 13 | int fd; 14 | 15 | uint32_t size; 16 | void *addr; 17 | }; 18 | 19 | struct shm_wrapper *shm_wrapper_create(const std::string &__name, size_t __len); 20 | struct shm_wrapper *shm_wrapper_attach(const std::string &__name, size_t __len); 21 | 22 | void shm_wrapper_destroy(struct shm_wrapper *); 23 | void shm_wrapper_detach(struct shm_wrapper *); 24 | 25 | // Given a pointer, return the offset from the start of the shared memory region 26 | static inline shmptr_t ptr_to_shmptr(void *ptr, struct shm_wrapper *shm) 27 | { 28 | shmptr_t offset = (uintptr_t)ptr - (uintptr_t)shm->addr; 29 | assert(offset < shm->size); 30 | return offset; 31 | } 32 | 33 | // Given an offset from the start of the shared memory region, return the pointer 34 | static inline uintptr_t shmptr_to_ptr(shmptr_t shmptr, struct shm_wrapper *shm) 35 | { 36 | assert(shmptr < shm->size); 37 | return (uintptr_t)shm->addr + shmptr; 38 | } -------------------------------------------------------------------------------- /eTran/homa_app/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CC = gcc 3 | 4 | LIB_DIR:= ../../lib 5 | # Include $(OBJECT_LIBXDP), $(OBJECT_LIBBPF) 6 | include ./common_mk/common.mk 7 | 8 | LIBBPF_LIBXDP_HDRS = $(LIB_DIR)/install/include 9 | COMMON_HDRS := ../common 10 | APPLIB_HDRS := ../lib/include 11 | 12 | CP_NODE := cp_node 13 | 14 | COMMON_DIR := ../common 15 | COMMON_TARGETS_SRC := $(wildcard $(COMMON_DIR)/*/*.cc) 16 | COMMON_TARGETS_DEPS = $(COMMON_TARGETS_SRC:.cc=.d) 17 | COMMON_TARGETS_OBJS += $(COMMON_TARGETS_SRC:.cc=.o) 18 | 19 | CP_NODE_DIR := ../lib 20 | CP_NODE_RUNTIME_SRC := $(wildcard $(CP_NODE_DIR)/*.cc) 21 | CP_NODE_RUNTIME_DEPS = $(CP_NODE_RUNTIME_SRC:.cc=.d) 22 | CP_NODE_RUNTIME_OBJS += $(CP_NODE_RUNTIME_SRC:.cc=.o) 23 | 24 | CP_NODE_INCLUDE_DIR := -I./ -I$(COMMON_HDRS) -I$(APPLIB_HDRS) -I$(LIBBPF_LIBXDP_HDRS) 25 | CP_NODE_CFLAGS := -Wall -Werror -fno-strict-aliasing -O3 -g -Wno-pointer-arith 26 | CP_NODE_LDLIBS := $(OBJECT_LIBXDP) $(OBJECT_LIBBPF) -lpthread -ltcmalloc -lrt -lelf -lz 27 | CP_NODE_OBJS := dist.o test_utils.o time_trace.o homa_api.o cp_node.o 28 | 29 | all: $(CP_NODE) 30 | 31 | $(CP_NODE): %: $(COMMON_TARGETS_OBJS) $(CP_NODE_RUNTIME_OBJS) $(CP_NODE_OBJS) $(APPLIBHDR) 32 | $(CXX) $(CP_NODE_CFLAGS) $(CP_NODE_INCLUDE_DIR) -o $@ $^ $(CP_NODE_LDLIBS) 33 | 34 | %.o: %.c 35 | $(CC) $(CP_NODE_CFLAGS) $(CP_NODE_INCLUDE_DIR) -c -o $@ $< 36 | 37 | %.o: %.cc 38 | $(CXX) $(CP_NODE_CFLAGS) $(CP_NODE_INCLUDE_DIR) -c -o $@ $< 39 | 40 | .PHONY: clean 41 | clean:: 42 | $(Q)rm -f $(CP_NODE) $(COMMON_TARGETS_OBJS) $(CP_NODE_RUNTIME_OBJS) $(CP_NODE_OBJS) $(COMMON_TARGETS_DEPS) $(CP_NODE_RUNTIME_DEPS) 43 | 44 | -include $(COMMON_TARGETS_DEPS) 45 | -include $(CP_NODE_RUNTIME_DEPS) 46 | 47 | ########## rules for .d files ########## 48 | %.d: %.c 49 | @set -e; \ 50 | rm -f $@; \ 51 | $(CC) -MM $(CP_NODE_INCLUDE_DIR) $< > $@.tmp; \ 52 | sed 's,\(.*\)\.o\:,$*\.o $*\.d\:,g' < $@.tmp > $@; \ 53 | rm -f $@.tmp; 54 | 55 | %.d: %.cc 56 | @set -e; \ 57 | rm -f $@; \ 58 | $(CXX) -MM $(CP_NODE_INCLUDE_DIR) $< > $@.tmp; \ 59 | sed 's,\(.*\)\.o\:,$*\.o $*\.d\:,g' < $@.tmp > $@; \ 60 | rm -f $@.tmp; 61 | -------------------------------------------------------------------------------- /eTran/homa_app/common_mk/common.mk: -------------------------------------------------------------------------------- 1 | # get list of objects in util 2 | include $(LIB_DIR)/util/util.mk 3 | 4 | include $(LIB_DIR)/defines.mk 5 | 6 | # Detect submodule libbpf source file changes 7 | ifeq ($(SYSTEM_LIBBPF),n) 8 | LIBBPF_SOURCES := $(wildcard $(LIBBPF_DIR)/src/*.[ch]) 9 | endif 10 | 11 | all: $(OBJECT_LIBBPF) $(OBJECT_LIBXDP) 12 | 13 | $(OBJECT_LIBXDP): $(OBJECT_LIBBPF) $(LIBXDP_SOURCES) 14 | $(Q)$(MAKE) -C $(LIB_DIR) libxdp 15 | 16 | $(OBJECT_LIBBPF): $(LIBBPF_SOURCES) 17 | $(Q)$(MAKE) -C $(LIB_DIR) libbpf 18 | 19 | 20 | -------------------------------------------------------------------------------- /eTran/homa_app/test_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2019-2022 Stanford University 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | */ 15 | 16 | #ifndef _TEST_UTILS_H 17 | #define _TEST_UTILS_H 18 | 19 | #include 20 | 21 | #include "homa.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | #define sizeof32(type) static_cast(sizeof(type)) 29 | 30 | extern int check_buffer(void *buffer, size_t length); 31 | extern int check_message(struct homa_recvmsg_args *control, 32 | char *region, size_t length, int skip); 33 | extern int get_int(const char *s, const char *msg); 34 | extern void pin_thread(int core); 35 | extern void print_dist(uint64_t times[], int count); 36 | extern void seed_buffer(void *buffer, size_t length, int seed); 37 | extern const char* 38 | print_address(const sockaddr_in_union *addr); 39 | extern double to_seconds(uint64_t cycles); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* _TEST_UTILS_H */ 46 | -------------------------------------------------------------------------------- /eTran/lib/include/eTran_common.h: -------------------------------------------------------------------------------- 1 | #ifndef ETRAN_H 2 | #define ETRAN_H 3 | 4 | constexpr char MICRO_KERNEL_SOCK_PATH[] = "/tmp/micro_kernel_socket"; 5 | constexpr unsigned int RX_BATCH_SIZE = 32; 6 | constexpr unsigned int TX_BATCH_SIZE = 32; 7 | constexpr unsigned int CQ_BATCH_SIZE = 32; 8 | 9 | int eTran_init(struct eTran_cfg *cfg); 10 | void eTran_intr(int sig); 11 | void eTran_exit(void); 12 | 13 | struct app_ctx_per_thread *eTran_get_tctx(void); 14 | 15 | // Statistics API 16 | void eTran_dump_io_stats(struct app_ctx_per_thread *tctx); 17 | void eTran_dump_all_io_stats(void); 18 | 19 | #endif -------------------------------------------------------------------------------- /eTran/lib/include/homa_if.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #define HOMA_MSS (1514 - 14 - 20 - HOMA_DATA_H) 7 | #define HOMA_PAYLOAD_OFFSET (14 + 20 + HOMA_DATA_H) 8 | 9 | struct eTranhoma_socket { 10 | uint32_t local_ip; 11 | uint16_t local_port; 12 | 13 | struct eTran_socket_t *s; 14 | 15 | eTranhoma_socket() { 16 | local_ip = 0; 17 | local_port = 0; 18 | s = nullptr; 19 | } 20 | }; 21 | 22 | enum eTranhoma_event_type { 23 | ETRANHOMA_EV_SOCKET_BIND, 24 | ETRANHOMA_EV_SOCKET_CLOSE, 25 | }; 26 | 27 | struct eTranhoma_event { 28 | enum eTranhoma_event_type type; 29 | union { 30 | struct { 31 | int16_t status; 32 | struct eTranhoma_socket *hs; 33 | int fd; 34 | } bind; 35 | 36 | struct { 37 | int16_t status; 38 | struct eTranhoma_socket *hs; 39 | int fd; 40 | } close; 41 | 42 | } ev; 43 | }; 44 | 45 | struct eTran_homa_rpc_tuple { 46 | uint32_t remote_ip; 47 | uint16_t remote_port; 48 | uint64_t rpcid; 49 | 50 | // constructor 51 | eTran_homa_rpc_tuple(uint32_t remote_ip, uint16_t remote_port, uint64_t rpcid) 52 | : remote_ip(remote_ip), remote_port(remote_port), rpcid(rpcid) {} 53 | 54 | uint32_t hash() const 55 | { 56 | return ((std::hash()(remote_ip) ^ (std::hash()(rpcid) << 1)) >> 1) ^ 57 | (std::hash()(remote_port) << 1); 58 | } 59 | }; 60 | 61 | struct eTran_homa_rpc_tuple_hash 62 | { 63 | std::size_t operator()(const eTran_homa_rpc_tuple &k) const 64 | { 65 | return ((std::hash()(k.remote_ip) ^ (std::hash()(k.rpcid) << 1)) >> 1) ^ 66 | (std::hash()(k.remote_port) << 1); 67 | } 68 | }; 69 | 70 | struct eTran_homa_rpc_tuple_equal 71 | { 72 | bool operator()(const eTran_homa_rpc_tuple &lhs, const eTran_homa_rpc_tuple &rhs) const 73 | { 74 | return lhs.remote_ip == rhs.remote_ip && lhs.remote_port == rhs.remote_port && lhs.rpcid == rhs.rpcid; 75 | } 76 | }; -------------------------------------------------------------------------------- /eTran/micro_kernel/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | 3 | # $(OBJECT_LIBXDP) $(OBJECT_LIBBPF) 4 | include ./common_mk/common.mk 5 | 6 | LIBBPF_LIBXDP_DIR = $(LIB_DIR)/install/include 7 | COMMON_HDRS := ../common 8 | 9 | K_INCLUDE_DIR := -I./ -I$(COMMON_HDRS) -I$(LIBBPF_LIBXDP_DIR) 10 | K_CFLAGS := -Wall -Werror -fno-strict-aliasing -O3 -g 11 | K_LDLIBS := $(OBJECT_LIBXDP) $(OBJECT_LIBBPF) -lpthread -ltcmalloc -lrt -lelf -lz 12 | 13 | COMMON_DIR := ../common 14 | RUNTIME_DIR := ./runtime 15 | UTILS_DIR := ./utils 16 | 17 | COMMON_TARGETS_SRC := $(wildcard $(COMMON_DIR)/*/*.cc) 18 | COMMON_TARGETS_DEPS = $(COMMON_TARGETS_SRC:.cc=.d) 19 | COMMON_TARGETS_OBJS += $(COMMON_TARGETS_SRC:.cc=.o) 20 | 21 | RUNTIME_TARGETS_SRC := $(wildcard $(RUNTIME_DIR)/*.cc) 22 | RUNTIME_TARGETS_DEPS := $(RUNTIME_TARGETS_SRC:.cc=.d) 23 | RUNTIME_TARGETS_OBJS += $(RUNTIME_TARGETS_SRC:.cc=.o) 24 | 25 | UTILS_TARGETS_SRC := $(wildcard $(UTILS_DIR)/*.cc) 26 | UTILS_TARGETS_DEPS := $(UTILS_TARGETS_SRC:.cc=.d) 27 | UTILS_TARGETS_OBJS += $(UTILS_TARGETS_SRC:.cc=.o) 28 | 29 | KERNEL_SRC := $(wildcard *.cc) 30 | KERNEL_DEPS := $(KERNEL_SRC:.cc=.d) 31 | KERNEL_OBJS := $(KERNEL_SRC:.cc=.o) 32 | 33 | all: bpf micro_kernel 34 | 35 | micro_kernel: $(COMMON_TARGETS_OBJS) $(RUNTIME_TARGETS_OBJS) $(UTILS_TARGETS_OBJS) $(KERNEL_OBJS) 36 | $(CXX) $(K_CFLAGS) $(K_INCLUDE_DIR) -o $@ $^ $(K_LDLIBS) 37 | 38 | $(COMMON_TARGETS_OBJS): $(OBJECT_LIBXDP) 39 | $(RUNTIME_TARGETS_OBJS): $(OBJECT_LIBXDP) 40 | $(KERNEL_OBJS): $(OBJECT_LIBXDP) 41 | 42 | bpf: micro_kernel 43 | make -C eBPF 44 | 45 | %.o: %.cc 46 | $(CXX) $(K_CFLAGS) $(K_INCLUDE_DIR) -c -o $@ $< 47 | 48 | .PHONY: clean 49 | clean:: 50 | make -C eBPF clean 51 | rm -f micro_kernel $(COMMON_TARGETS_OBJS) $(RUNTIME_TARGETS_OBJS) $(UTILS_TARGETS_OBJS) $(KERNEL_OBJS) $(COMMON_TARGETS_DEPS) $(RUNTIME_TARGETS_DEPS) $(UTILS_TARGETS_DEPS) $(KERNEL_DEPS) 52 | 53 | -include $(COMMON_TARGETS_DEPS) 54 | -include $(RUNTIME_TARGETS_DEPS) 55 | -include $(UTILS_TARGETS_DEPS) 56 | -include $(KERNEL_DEPS) 57 | 58 | ########## rules for generating .d files ########## 59 | %.d: %.cc 60 | @set -e; \ 61 | rm -f $@; \ 62 | $(CXX) -MM $(K_INCLUDE_DIR) $< > $@.tmp; \ 63 | sed 's,\(.*\)\.o\:,$*\.o $*\.d\:,g' < $@.tmp > $@; \ 64 | rm -f $@.tmp; 65 | -------------------------------------------------------------------------------- /eTran/micro_kernel/common_mk/common.mk: -------------------------------------------------------------------------------- 1 | LIB_DIR:= ../../lib 2 | 3 | # get list of objects in util 4 | include $(LIB_DIR)/util/util.mk 5 | 6 | include $(LIB_DIR)/defines.mk 7 | 8 | # Detect submodule libbpf source file changes 9 | ifeq ($(SYSTEM_LIBBPF),n) 10 | LIBBPF_SOURCES := $(wildcard $(LIBBPF_DIR)/src/*.[ch]) 11 | endif 12 | 13 | all: $(OBJECT_LIBBPF) $(OBJECT_LIBXDP) 14 | 15 | $(OBJECT_LIBXDP): $(OBJECT_LIBBPF) $(LIBXDP_SOURCES) 16 | $(Q)$(MAKE) -C $(LIB_DIR) libxdp 17 | 18 | $(OBJECT_LIBBPF): $(LIBBPF_SOURCES) 19 | $(Q)$(MAKE) -C $(LIB_DIR) libbpf -------------------------------------------------------------------------------- /eTran/micro_kernel/eBPF/Makefile: -------------------------------------------------------------------------------- 1 | protocols := entrance homa tcp 2 | 3 | all: $(protocols) 4 | 5 | $(protocols): 6 | $(MAKE) -C $@ 7 | 8 | .PHONY: clean $(protocols) 9 | clean: 10 | for dir in $(protocols); do \ 11 | $(MAKE) -C $$dir clean; \ 12 | done -------------------------------------------------------------------------------- /eTran/micro_kernel/eBPF/ebpf_queue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "ebpf_fib.h" 7 | 8 | struct bpf_map { 9 | enum bpf_map_type map_type; 10 | __u32 key_size; 11 | __u32 value_size; 12 | __u32 max_entries; 13 | __u32 id; 14 | } __attribute__((preserve_access_index)); 15 | 16 | struct xdp_frame { 17 | void *data; 18 | __u16 len; 19 | __u16 headroom; 20 | __u32 metasize; 21 | __u32 frame_sz; 22 | __u32 flags; 23 | int tx_ifindex; 24 | } __attribute__((preserve_access_index)); 25 | 26 | /* Operations on BPF_MAP_TYPE_PKT_QUEUE */ 27 | extern int pkt_queue_enqueue(struct bpf_map *map, struct xdp_frame *xdp, __u64 index) __ksym; 28 | extern struct xdp_frame *pkt_queue_dequeue(struct bpf_map *map, __u64 flags, __u64 *rank) __ksym; 29 | extern bool pkt_queue_empty(struct bpf_map *map, __u64 flags, __u64 *rank) __ksym; 30 | 31 | /* Operations on frame stored in BPF_MAP_TYPE_PKT_QUEUE */ 32 | extern int bpf_dynptr_from_xdp_frame(struct xdp_frame *xdp, __u64 flags, struct bpf_dynptr *ptr__uninit) __ksym; 33 | extern void *bpf_dynptr_slice(const struct bpf_dynptr *ptr, __u32 offset, void *buffer, __u32 buffer__szk) __ksym; 34 | extern void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr *ptr, __u32 offset, void *buffer, __u32 buffer__szk) __ksym; 35 | extern int bpf_packet_drop(struct xdp_frame *pkt) __ksym; 36 | extern int bpf_packet_send(struct xdp_frame *pkt, int ifindex, __u64 flags) __ksym; 37 | extern int bpf_packet_flush(void) __ksym; -------------------------------------------------------------------------------- /eTran/micro_kernel/eBPF/entrance/Makefile: -------------------------------------------------------------------------------- 1 | # Compile eBPF code with the makefile from bpf-examples 2 | eBPF_DIR := ./ 3 | 4 | BPF_TARGETS := $(eBPF_DIR)/entrance 5 | BPF_HEADERS := $(wildcard $(eBPF_DIR)/*.h) ../../../common/intf/intf_ebpf.h ../../../common/tran_def/homa.h ../../../common/tran_def/tcp.h 6 | 7 | BPF_CFLAGS := -Wno-address-of-packed-member -I../../../intf -I../../../common/ -I../ 8 | 9 | LIB_DIR = ../../../../lib 10 | include $(LIB_DIR)/common.mk -------------------------------------------------------------------------------- /eTran/micro_kernel/eBPF/homa/Makefile: -------------------------------------------------------------------------------- 1 | # Compile eBPF code with the makefile from bpf-examples 2 | eBPF_DIR := ./ 3 | 4 | BPF_TARGETS := $(eBPF_DIR)/main 5 | BPF_HEADERS := $(wildcard $(eBPF_DIR)/*.h) ../../../common/intf/intf_ebpf.h ../../../common/tran_def/homa.h ../*.h 6 | 7 | BPF_CFLAGS := -Wno-address-of-packed-member -I../../../intf -I../../../common/ -I../ 8 | 9 | LIB_DIR = ../../../../lib 10 | include $(LIB_DIR)/common.mk -------------------------------------------------------------------------------- /eTran/micro_kernel/eBPF/homa/eTran_defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "ebpf_kfunc.h" 11 | #include "ebpf_utils.h" 12 | 13 | #include "bss_data_defs.h" 14 | 15 | /************** Tail call programs at XDP_GEN **************/ 16 | enum { 17 | XDP_GEN_CHOOSE_RPC_TO_GRANT = 0, 18 | XDP_GEN_COMPLETE_GRANT_1, 19 | XDP_GEN_COMPLETE_GRANT_2, 20 | XDP_GEN_COMPLETE_GRANT_3, 21 | XDP_GEN_COMPLETE_GRANT_4, 22 | XDP_GEN_COMPLETE_GRANT_5, 23 | XDP_GEN_COMPLETE_GRANT_6, 24 | XDP_GEN_COMPLETE_GRANT_7, 25 | XDP_GEN_COMPLETE_GRANT_8, 26 | XDP_GEN_MAX_TAIL_CALL 27 | }; 28 | 29 | struct { 30 | __uint(type, BPF_MAP_TYPE_PROG_ARRAY); 31 | __uint(max_entries, XDP_GEN_MAX_TAIL_CALL); 32 | __uint(key_size, sizeof(int)); 33 | __uint(value_size, sizeof(int)); 34 | } xdp_gen_tail_call_map SEC(".maps"); 35 | /************** Tail call programs at XDP_GEN **************/ 36 | 37 | // ctx->rx_queue_index --> struct slow_path_info 38 | struct { 39 | __uint(type, BPF_MAP_TYPE_ARRAY); 40 | __uint(max_entries, MAX_NIC_QUEUES); 41 | __uint(key_size, sizeof(__u32)); 42 | __uint(value_size, sizeof(struct slow_path_info)); 43 | } slow_path_map SEC(".maps"); 44 | 45 | struct { 46 | __uint(type, BPF_MAP_TYPE_XSKMAP); 47 | __uint(max_entries, MAX_XSK_FD); 48 | __uint(key_size, sizeof(int)); 49 | __uint(value_size, sizeof(int)); 50 | } xsks_map SEC(".maps"); -------------------------------------------------------------------------------- /eTran/micro_kernel/eBPF/tcp/Makefile: -------------------------------------------------------------------------------- 1 | # Compile eBPF code with the makefile from bpf-examples 2 | eBPF_DIR := ./ 3 | 4 | BPF_TARGETS := $(eBPF_DIR)/main 5 | BPF_HEADERS := $(wildcard $(eBPF_DIR)/*.h) ../../../common/intf/intf_ebpf.h ../../../common/tran_def/tcp.h ../*.h 6 | 7 | BPF_CFLAGS := -Wno-address-of-packed-member -I../../../intf -I../../../common/ 8 | 9 | LIB_DIR = ../../../../lib 10 | include $(LIB_DIR)/common.mk -------------------------------------------------------------------------------- /eTran/micro_kernel/eBPF/tcp/eTran_defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #define DEFAULT_MTU 1500 8 | #define ETH_HDR_LEN 14 9 | #define IP_HDR_LEN 20 10 | 11 | #define XDP_GEN_PKT_SIZE 128 12 | #define NAPI_BATCH_SIZE 64 13 | 14 | // #define XDP_DEBUG 15 | // #define XDP_EGRESS_DEBUG 16 | // #define XDP_GEN_DEBUG -------------------------------------------------------------------------------- /eTran/micro_kernel/ebpf.h: -------------------------------------------------------------------------------- 1 | #ifndef EBPF_H 2 | #define EBPF_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include "nic.h" 10 | 11 | struct ebpf_info_t 12 | { 13 | /* interface name */ 14 | std::string if_name; 15 | /* interface index */ 16 | int ifindex; 17 | /* XDP program */ 18 | struct xdp_program *xdp_prog; 19 | /* XDP attach mode */ 20 | enum xdp_attach_mode attach_mode; 21 | /* XDP bind flags */ 22 | unsigned int xdp_bind_flags; 23 | /* enable busy polling */ 24 | bool busy_poll; 25 | /* busy polling batch size */ 26 | int busy_poll_batch_size; 27 | /* XDP program fd */ 28 | int xdp_fd; 29 | /* XDP_EGRESS program fd */ 30 | int xdp_egress_fd; 31 | /* XDP_GEN program fd */ 32 | int xdp_gen_fd; 33 | /* CPUMAP program fd */ 34 | int cpumap_prog_fd; 35 | }; 36 | 37 | #endif // EBPF_H -------------------------------------------------------------------------------- /eTran/micro_kernel/runtime/defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #define INIT_CHECK(call) do { \ 9 | int ret = (call); \ 10 | if (ret) { \ 11 | fprintf(stderr, "ERROR: %s failed (%d): %s\n", #call, ret, strerror(-ret)); \ 12 | return ret; \ 13 | } \ 14 | } while (0) 15 | 16 | #define SUPPORT_PROTO(proto) ((proto) == IPPROTO_TCP || (proto) == IPPROTO_HOMA) 17 | 18 | // #define DEBUG_TCP 19 | 20 | const std::string ENTRANCE_BPF_OBJ_PATH = "eBPF/entrance/entrance.o"; 21 | const std::string TCP_BPF_OBJ_PATH = "eBPF/tcp/main.o"; 22 | const std::string HOMA_BPF_OBJ_PATH = "eBPF/homa/main.o"; 23 | const std::string MICRO_KERNEL_SOCK_PATH = "/tmp/micro_kernel_socket"; 24 | const unsigned int MAX_APP_THREADS = 20; 25 | const unsigned int MAX_SUPPORT_APP = 32; 26 | const unsigned int CP_CPU = 19; 27 | 28 | const int enrollment_to_ms = 0; 29 | const int network_to_ms = 0; 30 | // interval between processing slowpath 31 | const int sp_interval_ms = 1; 32 | 33 | const unsigned int IO_BATCH_SIZE = 32; 34 | 35 | const uint16_t PORT_MIN = 1000; 36 | const uint16_t PORT_MAX = 60000; 37 | 38 | // ebpf.cc 39 | extern int ebpf_init(void); 40 | extern void ebpf_exit(); 41 | 42 | // control_plance.cc 43 | extern int ctx_init(void); 44 | extern int thread_init(void); 45 | extern void wait_thread(void); 46 | extern void shutdown_thread(void); 47 | 48 | extern void dump_bpf_maps(); 49 | extern void dump_ring_stats(void); 50 | 51 | extern void kick_napi(void); -------------------------------------------------------------------------------- /eTran/micro_kernel/runtime/homa.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define HOMA_MSS (1514 - 14 - 20 - HOMA_DATA_H) 8 | 9 | /* How many resends are need for aborting this RPC */ 10 | #define ABORT_RESEND 10 11 | /* How many ticks are needed for sending NEED_ACK packet */ 12 | #define NEED_ACK_TICK 15 13 | /* How many ticks are needed for sending RESEND packet */ 14 | #define RESEND_TICK 15 15 | 16 | struct homa_socket 17 | { 18 | struct app_ctx_per_thread *tctx; 19 | opaque_ptr opaque_socket; 20 | int fd; 21 | uint32_t local_ip; 22 | uint16_t local_port; 23 | 24 | homa_socket() {} 25 | }; 26 | 27 | int homa_bind(struct app_ctx_per_thread *tctx, struct appout_homa_bind_t *homa_bind_msg_in); 28 | int homa_close(struct app_ctx_per_thread *tctx, opaque_ptr opaque_socket); 29 | 30 | void free_homa_resources(struct app_ctx *actx); 31 | 32 | void process_homa_cmd(struct app_ctx_per_thread *tctx, lrpc_msg *msg); 33 | 34 | int poll_homa_to(void); 35 | 36 | -------------------------------------------------------------------------------- /eTran/micro_kernel/utils/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | static inline bool exec_cmd(const std::string &cmd, std::string &result) 4 | { 5 | std::FILE *pipe = popen(cmd.c_str(), "r"); 6 | if (!pipe) 7 | return false; 8 | 9 | char buffer[128]; 10 | result.clear(); 11 | while (fgets(buffer, sizeof(buffer), pipe) != nullptr) 12 | { 13 | result += buffer; 14 | } 15 | 16 | pclose(pipe); 17 | return true; 18 | } 19 | 20 | static inline bool exec_cmd(const std::string &cmd) 21 | { 22 | std::string unused_result; 23 | return exec_cmd(cmd, unused_result); 24 | } -------------------------------------------------------------------------------- /eTran/shared_lib/Makefile: -------------------------------------------------------------------------------- 1 | # This file is used to generate shared library for eTran 2 | CXX = g++ 3 | CC = gcc 4 | 5 | SHARED_LIB = libetran.so 6 | 7 | COMMON_DIR := ../common 8 | APP_LIB := ../lib 9 | LIBBPF_LIBXDP_DIR:= ../../lib/install/include 10 | 11 | # $(OBJECT_LIBXDP) $(OBJECT_LIBBPF) 12 | include ./common_mk/common.mk 13 | 14 | CFLAGS := -Wall -Werror -fno-strict-aliasing -O3 -g -Wno-pointer-arith 15 | INCLUDE_DIR := -I$(COMMON_DIR) -I$(APP_LIB)/include -I$(LIBBPF_LIBXDP_DIR) 16 | LDLIBS := -lpthread -ltcmalloc -lrt -lelf -lz 17 | 18 | COMMON_TARGETS_SRC := $(wildcard $(COMMON_DIR)/*/*.cc) 19 | COMMON_TARGETS_DEPS = $(COMMON_TARGETS_SRC:.cc=.d) 20 | COMMON_TARGETS_OBJS += $(COMMON_TARGETS_SRC:.cc=.o) 21 | 22 | APP_LIB_TARGETS_SRC := $(wildcard $(APP_LIB)/*.cc) 23 | APP_LIB_TARGETS_DEPS = $(APP_LIB_TARGETS_SRC:.cc=.d) 24 | APP_LIB_TARGETS_OBJS += $(APP_LIB_TARGETS_SRC:.cc=.o) 25 | 26 | all: $(SHARED_LIB) 27 | $(SHARED_LIB): $(COMMON_TARGETS_OBJS) $(APP_LIB_TARGETS_OBJS) 28 | $(CXX) -shared -fPIC -o $@ $^ $(LDLIBS) 29 | 30 | $(COMMON_TARGETS_OBJS): $(OBJECT_LIBXDP) 31 | $(APP_LIB_TARGETS_OBJS): $(OBJECT_LIBXDP) 32 | 33 | %.o: %.cc 34 | $(CXX) -fPIC $(CFLAGS) $(INCLUDE_DIR) -o $@ $< -c 35 | 36 | %.o: %.c 37 | $(CC) -fPIC $(CFLAGS) $(INCLUDE_DIR) -o $@ $< -c 38 | 39 | .phony: clean 40 | clean: 41 | $(Q)rm -rf $(SHARED_LIB) $(COMMON_TARGETS_OBJS) $(COMMON_TARGETS_DEPS) $(APP_LIB_TARGETS_OBJS) $(APP_LIB_TARGETS_DEPS) 42 | 43 | -include $(COMMON_TARGETS_DEPS) 44 | -include $(APP_LIB_TARGETS_DEPS) 45 | 46 | ########## rules for generating .d files ########## 47 | %.d: %.c 48 | @set -e; \ 49 | rm -f $@; \ 50 | $(CC) -MM $(INCLUDE_DIR) $< > $@.tmp; \ 51 | sed 's,\(.*\)\.o\:,$*\.o $*\.d\:,g' < $@.tmp > $@; \ 52 | rm -f $@.tmp; 53 | 54 | %.d: %.cc 55 | @set -e; \ 56 | rm -f $@; \ 57 | $(CXX) -MM $(INCLUDE_DIR) $< > $@.tmp; \ 58 | sed 's,\(.*\)\.o\:,$*\.o $*\.d\:,g' < $@.tmp > $@; \ 59 | rm -f $@.tmp; -------------------------------------------------------------------------------- /eTran/shared_lib/common_mk/common.mk: -------------------------------------------------------------------------------- 1 | LIB_DIR:= ../../lib 2 | 3 | # get list of objects in util 4 | include $(LIB_DIR)/util/util.mk 5 | 6 | include $(LIB_DIR)/defines.mk 7 | 8 | # Detect submodule libbpf source file changes 9 | ifeq ($(SYSTEM_LIBBPF),n) 10 | LIBBPF_SOURCES := $(wildcard $(LIBBPF_DIR)/src/*.[ch]) 11 | endif 12 | 13 | all: $(OBJECT_LIBBPF) $(OBJECT_LIBXDP) 14 | 15 | $(OBJECT_LIBXDP): $(OBJECT_LIBBPF) $(LIBXDP_SOURCES) 16 | $(Q)$(MAKE) -C $(LIB_DIR) libxdp 17 | 18 | $(OBJECT_LIBBPF): $(LIBBPF_SOURCES) 19 | $(Q)$(MAKE) -C $(LIB_DIR) libbpf 20 | 21 | 22 | -------------------------------------------------------------------------------- /eTran/tcp_app/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CC = gcc 3 | 4 | A_CFLAGS := -Wall -Werror -fno-strict-aliasing -O3 -g -Wno-pointer-arith -Wno-address-of-packed-member 5 | A_LDLIBS := -lpthread -ltcmalloc -lrt -lelf -lz 6 | 7 | # List of applications 8 | APPS := epoll_client epoll_server \ 9 | lat_client lat_server \ 10 | 11 | OTHER_APPS := flexkvs_server flexkvs_bench 12 | OTHER_APPS_OBJS := $(OTHER_APPS:=.o) 13 | 14 | APP_CPP_SRCS := $(addsuffix .cc, $(APPS)) 15 | APP_CPP_OBJS := $(APP_CPP_SRCS:.cc=.o) 16 | APP_CPP_DEPS := $(APP_CPP_SRCS:.cc=.d) 17 | 18 | FLEXKVS_COMMON=flexkvs/utils.o flexkvs/hashtable.o flexkvs/ialloc.o flexkvs/jenkins_hash.o flexkvs/settings.o 19 | BENCH_COMMON=flexkvs/rng.o flexkvs/commandline.o flexkvs/workload.o 20 | 21 | all: $(APPS) $(OTHER_APPS) 22 | 23 | $(APPS): %: %.o 24 | $(CXX) -o $@ $^ $(A_LDLIBS) 25 | 26 | flexkvs_server: %: $(FLEXKVS_COMMON) %.o 27 | $(CXX) $(A_CFLAGS) -o $@ $^ $(A_LDLIBS) 28 | 29 | flexkvs_bench: %: $(BENCH_COMMON) $(FLEXKVS_COMMON) %.o 30 | $(CXX) $(A_CFLAGS) -o $@ $^ $(A_LDLIBS) 31 | 32 | %.o: %.cc 33 | $(CXX) -fPIC $(A_CFLAGS) $(A_INCLUDE_DIR) -c -o $@ $< 34 | 35 | %.o: %.c 36 | $(CC) -fPIC $(A_CFLAGS) $(A_INCLUDE_DIR) -c -o $@ $< 37 | 38 | .PHONY: clean 39 | clean:: 40 | $(Q)rm -f $(APPS) $(APP_CPP_OBJS) $(APP_CPP_DEPS) $(OTHER_APPS) $(OTHER_APPS_OBJS) $(FLEXKVS_COMMON) $(BENCH_COMMON) 41 | 42 | -include $(APP_CPP_DEPS) 43 | 44 | ########## rules for generating .d files ########## 45 | %.d: %.c 46 | @set -e; \ 47 | rm -f $@; \ 48 | $(CC) -MM $(A_INCLUDE_DIR) $< > $@.tmp; \ 49 | sed 's,\(.*\)\.o\:,$*\.o $*\.d\:,g' < $@.tmp > $@; \ 50 | rm -f $@.tmp; 51 | 52 | %.d: %.cc 53 | @set -e; \ 54 | rm -f $@; \ 55 | $(CXX) -MM $(A_INCLUDE_DIR) $< > $@.tmp; \ 56 | sed 's,\(.*\)\.o\:,$*\.o $*\.d\:,g' < $@.tmp > $@; \ 57 | rm -f $@.tmp; 58 | -------------------------------------------------------------------------------- /eTran/tcp_app/common_mk/common.mk: -------------------------------------------------------------------------------- 1 | # Expect this is defined by including Makefile, but define if not 2 | LIB_DIR ?= ../lib 3 | 4 | # get list of objects in util 5 | include $(LIB_DIR)/util/util.mk 6 | 7 | include $(LIB_DIR)/defines.mk 8 | 9 | # Detect submodule libbpf source file changes 10 | ifeq ($(SYSTEM_LIBBPF),n) 11 | LIBBPF_SOURCES := $(wildcard $(LIBBPF_DIR)/src/*.[ch]) 12 | endif 13 | 14 | all: $(OBJECT_LIBBPF) $(OBJECT_LIBXDP) 15 | 16 | $(OBJECT_LIBBPF): $(LIBBPF_SOURCES) 17 | $(Q)$(MAKE) -C $(LIB_DIR) libbpf 18 | 19 | $(OBJECT_LIBXDP): $(LIBXDP_SOURCES) 20 | $(Q)$(MAKE) -C $(LIB_DIR) libxdp 21 | 22 | -------------------------------------------------------------------------------- /eTran/tcp_app/flexkvs/rng.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 University of Washington, Max Planck Institute for 3 | * Software Systems, and The University of Texas at Austin 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef RNG_H_ 26 | #define RNG_H_ 27 | 28 | #include 29 | #include 30 | 31 | struct rng { 32 | uint64_t seed; 33 | }; 34 | 35 | void rng_init(struct rng *rng, uint64_t seed); 36 | uint32_t rng_gen32(struct rng *rng); 37 | /** Double uniform between 0 and 1 */ 38 | double rng_gend(struct rng *rng); 39 | void rng_gen(struct rng *rng, void *buf, size_t size); 40 | 41 | #endif // ndef RNG_H_ 42 | -------------------------------------------------------------------------------- /eTran/tcp_app/flexkvs/settings.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 University of Washington, Max Planck Institute for 3 | * Software Systems, and The University of Texas at Austin 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include "iokvs.h" 29 | 30 | struct settings settings; 31 | 32 | int settings_init(int argc, char *argv[]) 33 | { 34 | settings.udpport = 11211; 35 | settings.verbose = 1; 36 | settings.segsize = 256 * 1024; 37 | settings.segmaxnum = 4096; 38 | settings.segcqsize = 32 * 1024; 39 | settings.clean_ratio = 0.8; 40 | 41 | if (argc != 4) { 42 | fprintf(stderr, "Usage: flexkvs CONFIG THREADS QUEUES\n"); 43 | return -1; 44 | } 45 | settings.numqueues = atoi(argv[3]); 46 | settings.numcores = atoi(argv[2]); 47 | settings.config_file = argv[1]; 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /headers/linux/err.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_ERR_H 4 | #define __LINUX_ERR_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define MAX_ERRNO 4095 11 | 12 | #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO) 13 | 14 | static inline void * ERR_PTR(long error_) 15 | { 16 | return (void *) error_; 17 | } 18 | 19 | static inline long PTR_ERR(const void *ptr) 20 | { 21 | return (long) ptr; 22 | } 23 | 24 | static inline bool IS_ERR(const void *ptr) 25 | { 26 | return IS_ERR_VALUE((unsigned long)ptr); 27 | } 28 | 29 | static inline bool IS_ERR_OR_NULL(const void *ptr) 30 | { 31 | return (!ptr) || IS_ERR_VALUE((unsigned long)ptr); 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/bpf/errno.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright (C) 2016-2020 Authors of Cilium */ 3 | 4 | #ifndef __BPF_ERRNO__ 5 | #define __BPF_ERRNO__ 6 | 7 | /* Few basic errno codes as we don't want to include errno.h. */ 8 | 9 | #ifndef EPERM 10 | # define EPERM 1 11 | #endif 12 | #ifndef ENOENT 13 | # define ENOENT 2 14 | #endif 15 | #ifndef ENXIO 16 | # define ENXIO 6 17 | #endif 18 | #ifndef ENOMEM 19 | # define ENOMEM 12 20 | #endif 21 | #ifndef EFAULT 22 | # define EFAULT 14 23 | #endif 24 | #ifndef EINVAL 25 | # define EINVAL 22 26 | #endif 27 | #ifndef ENOTSUP 28 | # define ENOTSUP 95 29 | #endif 30 | #ifndef EADDRINUSE 31 | # define EADDRINUSE 98 32 | #endif 33 | #ifndef ENOTSUPP 34 | # define ENOTSUPP 524 35 | #endif 36 | 37 | #endif /* __BPF_ERRNO__ */ 38 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # bpftool 4 | pushd . > /dev/null 5 | git clone --recurse-submodules https://github.com/libbpf/bpftool.git 6 | cd bpftool/src 7 | sudo make install 8 | sudo cp /usr/local/sbin/bpftool /usr/local/bin/ 9 | popd > /dev/null 10 | rm -rf bpftool/ 11 | 12 | # llvm-16 13 | wget https://apt.llvm.org/llvm.sh 14 | chmod u+x llvm.sh 15 | sudo ./llvm.sh 16 16 | sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 100 17 | sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 100 18 | sudo update-alternatives --install /usr/bin/llc llc /usr/bin/llc-16 100 19 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | 2 | LIBBPF_CFLAGS:=$(if $(CFLAGS),$(CFLAGS),-g -O2 -Werror -Wall) -fPIC 3 | 4 | LIB_DIR = . 5 | LIB_INSTALL := $(LIB_DIR)/install 6 | include defines.mk 7 | 8 | SUBDIRS=util 9 | 10 | all: $(OBJECT_LIBBPF) $(OBJECT_LIBXDP) 11 | @set -e; \ 12 | for i in $(SUBDIRS); \ 13 | do echo; echo " $$i"; $(MAKE) -C $$i; done 14 | 15 | $(OBJECT_LIBXDP): $(OBJECT_LIBBPF) 16 | 17 | .PHONY: clean 18 | clean: libbpf_clean libxdp_clean 19 | @for i in $(SUBDIRS); \ 20 | do $(MAKE) -C $$i clean; done 21 | $(Q)find $(LIB_INSTALL) -type f -not -name .gitignore -delete 22 | $(Q)find $(LIB_INSTALL) -type d -empty -delete 23 | 24 | install: 25 | install -m 0755 -d $(DESTDIR)$(HDRDIR) 26 | $(MAKE) -C libxdp install 27 | $(MAKE) -C testing install 28 | 29 | 30 | libbpf: $(OBJECT_LIBBPF) 31 | libxdp: libbpf $(OBJECT_LIBXDP) 32 | 33 | # Handle libbpf as git submodule 34 | ifeq ($(SYSTEM_LIBBPF),n) 35 | ifeq ($(VERBOSE),0) 36 | P:= >/dev/null 37 | endif 38 | 39 | # Detect submodule libbpf source file changes 40 | LIBBPF_SOURCES := $(wildcard libbpf/src/*.[ch]) 41 | 42 | $(LIB_INSTALL)/lib/libbpf.a: $(LIBBPF_SOURCES) 43 | @echo ; echo " libbpf" 44 | $(QUIET_CC)$(MAKE) -C libbpf/src CFLAGS="$(LIBBPF_CFLAGS)" $P 45 | $(QUIET_INSTALL)$(MAKE) -C libbpf/src DESTDIR=../../$(LIB_INSTALL) PREFIX= install_headers $P 46 | $(Q)cp -fp libbpf/src/libbpf.a install/lib/ 47 | 48 | .PHONY: libbpf_clean 49 | libbpf_clean: 50 | $(Q)$(MAKE) -C libbpf/src clean $P 51 | 52 | else 53 | 54 | libbpf_clean: 55 | @echo -n 56 | endif 57 | 58 | # Handle libbpf as git submodule 59 | ifeq ($(SYSTEM_LIBXDP),n) 60 | ifeq ($(VERBOSE),0) 61 | P:= >/dev/null 62 | endif 63 | 64 | # Detect submodule libbpf source file changes 65 | LIBXDP_SOURCES := $(wildcard xdp-tools/lib/libxdp/libxdp*.[ch]) xdp-tools/lib/libxdp/xsk.c 66 | 67 | 68 | $(LIB_INSTALL)/lib/libxdp.a: $(LIBXDP_SOURCES) 69 | @echo ; echo " libxdp" 70 | $(QUIET_CC)$(MAKE) -C xdp-tools BUILD_STATIC_ONLY=1 libxdp $P 71 | $(QUIET_INSTALL)$(MAKE) -C xdp-tools DESTDIR=../../../$(LIB_INSTALL) PREFIX= BUILD_STATIC_ONLY=1 libxdp_install $P 72 | 73 | .PHONY: libxdp_clean 74 | libxdp_clean: 75 | $(Q)$(MAKE) -C xdp-tools clean $P 76 | 77 | else 78 | 79 | libxdp_clean: 80 | @echo -n 81 | endif 82 | -------------------------------------------------------------------------------- /lib/defines.mk: -------------------------------------------------------------------------------- 1 | CFLAGS ?= -O2 -g 2 | BPF_CFLAGS ?= -Wno-visibility 3 | 4 | include $(LIB_DIR)/../config.mk 5 | 6 | PREFIX?=/usr/local 7 | LIBDIR?=$(PREFIX)/lib 8 | SBINDIR?=$(PREFIX)/sbin 9 | HDRDIR?=$(PREFIX)/include/xdp 10 | DATADIR?=$(PREFIX)/share 11 | MANDIR?=$(DATADIR)/man 12 | BPF_DIR_MNT ?=/sys/fs/bpf 13 | BPF_OBJECT_DIR ?=$(LIBDIR)/bpf 14 | MAX_DISPATCHER_ACTIONS ?=10 15 | 16 | # headers/ dir contains include header files needed to compile BPF programs 17 | HEADER_DIR = $(LIB_DIR)/../headers 18 | # include/ dir contains the projects own include header files 19 | INCLUDE_DIR = $(LIB_DIR)/../include 20 | TEST_DIR = $(LIB_DIR)/testing 21 | LIBBPF_DIR := $(LIB_DIR)/libbpf 22 | 23 | DEFINES := -DBPF_DIR_MNT=\"$(BPF_DIR_MNT)\" -DBPF_OBJECT_PATH=\"$(BPF_OBJECT_DIR)\" 24 | 25 | ifeq ($(DEBUG),1) 26 | DEFINES += -DDEBUG 27 | endif 28 | 29 | HAVE_FEATURES := 30 | 31 | CFLAGS += $(DEFINES) 32 | BPF_CFLAGS += $(DEFINES) 33 | 34 | CONFIGMK := $(LIB_DIR)/../config.mk 35 | LIBMK := Makefile $(CONFIGMK) $(LIB_DIR)/defines.mk $(LIB_DIR)/common.mk $(LIB_DIR)/util/util.mk 36 | 37 | -------------------------------------------------------------------------------- /lib/install/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !include 4 | !lib 5 | -------------------------------------------------------------------------------- /lib/install/include/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /lib/install/lib/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /lib/libbpf/.gitattributes: -------------------------------------------------------------------------------- 1 | assets/** export-ignore 2 | -------------------------------------------------------------------------------- /lib/libbpf/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for considering a contribution! 2 | 3 | Please note that the `libbpf` authoritative source code is developed as part of bpf-next Linux source tree under tools/lib/bpf subdirectory and is periodically synced to Github. As such, all the libbpf changes should be sent to BPF mailing list, please don't open PRs here unless you are changing Github-specific parts of libbpf (e.g., Github-specific Makefile). 4 | -------------------------------------------------------------------------------- /lib/libbpf/.github/actions/build-selftests/action.yml: -------------------------------------------------------------------------------- 1 | name: 'build-selftests' 2 | description: 'Build BPF selftests' 3 | inputs: 4 | repo-path: 5 | description: 'where is the source code' 6 | required: true 7 | kernel: 8 | description: 'kernel version or LATEST' 9 | required: true 10 | default: 'LATEST' 11 | vmlinux: 12 | description: 'where is vmlinux file' 13 | required: true 14 | default: '${{ github.workspace }}/vmlinux' 15 | 16 | runs: 17 | using: "composite" 18 | steps: 19 | - shell: bash 20 | run: | 21 | source $GITHUB_ACTION_PATH/../../../ci/vmtest/helpers.sh 22 | foldable start "Setup Env" 23 | sudo apt-get install -y qemu-kvm zstd binutils-dev elfutils libcap-dev libelf-dev libdw-dev python3-docutils 24 | foldable end 25 | - shell: bash 26 | run: | 27 | export KERNEL=${{ inputs.kernel }} 28 | export REPO_ROOT="${{ github.workspace }}" 29 | export REPO_PATH="${{ inputs.repo-path }}" 30 | export VMLINUX_BTF="${{ inputs.vmlinux }}" 31 | ${{ github.action_path }}/build_selftests.sh 32 | -------------------------------------------------------------------------------- /lib/libbpf/.github/actions/build-selftests/build_selftests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | THISDIR="$(cd $(dirname $0) && pwd)" 6 | 7 | source ${THISDIR}/helpers.sh 8 | 9 | foldable start prepare_selftests "Building selftests" 10 | 11 | LIBBPF_PATH="${REPO_ROOT}" 12 | 13 | llvm_default_version() { 14 | echo "16" 15 | } 16 | 17 | llvm_latest_version() { 18 | echo "17" 19 | } 20 | 21 | LLVM_VERSION=$(llvm_default_version) 22 | if [[ "${LLVM_VERSION}" == $(llvm_latest_version) ]]; then 23 | REPO_DISTRO_SUFFIX="" 24 | else 25 | REPO_DISTRO_SUFFIX="-${LLVM_VERSION}" 26 | fi 27 | 28 | echo "deb https://apt.llvm.org/focal/ llvm-toolchain-focal${REPO_DISTRO_SUFFIX} main" \ 29 | | sudo tee /etc/apt/sources.list.d/llvm.list 30 | 31 | PREPARE_SELFTESTS_SCRIPT=${THISDIR}/prepare_selftests-${KERNEL}.sh 32 | if [ -f "${PREPARE_SELFTESTS_SCRIPT}" ]; then 33 | (cd "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" && ${PREPARE_SELFTESTS_SCRIPT}) 34 | fi 35 | 36 | if [[ "${KERNEL}" = 'LATEST' ]]; then 37 | VMLINUX_H= 38 | else 39 | VMLINUX_H=${THISDIR}/vmlinux.h 40 | fi 41 | 42 | cd ${REPO_ROOT}/${REPO_PATH} 43 | make headers 44 | make \ 45 | CLANG=clang-${LLVM_VERSION} \ 46 | LLC=llc-${LLVM_VERSION} \ 47 | LLVM_STRIP=llvm-strip-${LLVM_VERSION} \ 48 | VMLINUX_BTF="${VMLINUX_BTF}" \ 49 | VMLINUX_H=${VMLINUX_H} \ 50 | -C "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" \ 51 | -j $((4*$(nproc))) > /dev/null 52 | cd - 53 | mkdir ${LIBBPF_PATH}/selftests 54 | cp -R "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" \ 55 | ${LIBBPF_PATH}/selftests 56 | cd ${LIBBPF_PATH} 57 | rm selftests/bpf/.gitignore 58 | git add selftests 59 | 60 | foldable end prepare_selftests 61 | -------------------------------------------------------------------------------- /lib/libbpf/.github/actions/build-selftests/helpers.sh: -------------------------------------------------------------------------------- 1 | # shellcheck shell=bash 2 | 3 | # $1 - start or end 4 | # $2 - fold identifier, no spaces 5 | # $3 - fold section description 6 | foldable() { 7 | local YELLOW='\033[1;33m' 8 | local NOCOLOR='\033[0m' 9 | if [ $1 = "start" ]; then 10 | line="::group::$2" 11 | if [ ! -z "${3:-}" ]; then 12 | line="$line - ${YELLOW}$3${NOCOLOR}" 13 | fi 14 | else 15 | line="::endgroup::" 16 | fi 17 | echo -e "$line" 18 | } 19 | 20 | __print() { 21 | local TITLE="" 22 | if [[ -n $2 ]]; then 23 | TITLE=" title=$2" 24 | fi 25 | echo "::$1${TITLE}::$3" 26 | } 27 | 28 | # $1 - title 29 | # $2 - message 30 | print_error() { 31 | __print error $1 $2 32 | } 33 | 34 | # $1 - title 35 | # $2 - message 36 | print_notice() { 37 | __print notice $1 $2 38 | } 39 | -------------------------------------------------------------------------------- /lib/libbpf/.github/actions/build-selftests/prepare_selftests-4.9.0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | printf "all:\n\ttouch bpf_testmod.ko\n\nclean:\n" > bpf_testmod/Makefile 4 | -------------------------------------------------------------------------------- /lib/libbpf/.github/actions/build-selftests/prepare_selftests-5.5.0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | printf "all:\n\ttouch bpf_testmod.ko\n\nclean:\n" > bpf_testmod/Makefile 4 | -------------------------------------------------------------------------------- /lib/libbpf/.github/actions/debian/action.yml: -------------------------------------------------------------------------------- 1 | name: 'debian' 2 | description: 'Build' 3 | inputs: 4 | target: 5 | description: 'Run target' 6 | required: true 7 | runs: 8 | using: "composite" 9 | steps: 10 | - run: | 11 | source /tmp/ci_setup 12 | bash -x $CI_ROOT/managers/debian.sh SETUP 13 | bash -x $CI_ROOT/managers/debian.sh ${{ inputs.target }} 14 | bash -x $CI_ROOT/managers/debian.sh CLEANUP 15 | shell: bash 16 | 17 | -------------------------------------------------------------------------------- /lib/libbpf/.github/actions/setup/action.yml: -------------------------------------------------------------------------------- 1 | name: 'setup' 2 | description: 'setup env, create /tmp/ci_setup' 3 | runs: 4 | using: "composite" 5 | steps: 6 | - id: variables 7 | run: | 8 | export REPO_ROOT=$GITHUB_WORKSPACE 9 | export CI_ROOT=$REPO_ROOT/ci 10 | # this is somewhat ugly, but that is the easiest way to share this code with 11 | # arch specific docker 12 | echo 'echo ::group::Env setup' > /tmp/ci_setup 13 | echo export DEBIAN_FRONTEND=noninteractive >> /tmp/ci_setup 14 | echo sudo apt-get update >> /tmp/ci_setup 15 | echo sudo apt-get install -y aptitude qemu-kvm zstd binutils-dev elfutils libcap-dev libelf-dev libdw-dev libguestfs-tools >> /tmp/ci_setup 16 | echo export PROJECT_NAME='libbpf' >> /tmp/ci_setup 17 | echo export AUTHOR_EMAIL="$(git log -1 --pretty=\"%aE\")" >> /tmp/ci_setup 18 | echo export REPO_ROOT=$GITHUB_WORKSPACE >> /tmp/ci_setup 19 | echo export CI_ROOT=$REPO_ROOT/ci >> /tmp/ci_setup 20 | echo export VMTEST_ROOT=$CI_ROOT/vmtest >> /tmp/ci_setup 21 | echo 'echo ::endgroup::' >> /tmp/ci_setup 22 | shell: bash 23 | 24 | -------------------------------------------------------------------------------- /lib/libbpf/.github/workflows/cifuzz.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # https://google.github.io/oss-fuzz/getting-started/continuous-integration/ 3 | name: CIFuzz 4 | on: 5 | push: 6 | branches: 7 | - master 8 | pull_request: 9 | branches: 10 | - master 11 | jobs: 12 | Fuzzing: 13 | runs-on: ubuntu-latest 14 | if: github.repository == 'libbpf/libbpf' 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | sanitizer: [address, undefined, memory] 19 | steps: 20 | - name: Build Fuzzers (${{ matrix.sanitizer }}) 21 | id: build 22 | uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master 23 | with: 24 | oss-fuzz-project-name: 'libbpf' 25 | dry-run: false 26 | allowed-broken-targets-percentage: 0 27 | sanitizer: ${{ matrix.sanitizer }} 28 | - name: Run Fuzzers (${{ matrix.sanitizer }}) 29 | uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master 30 | with: 31 | oss-fuzz-project-name: 'libbpf' 32 | fuzz-seconds: 300 33 | dry-run: false 34 | sanitizer: ${{ matrix.sanitizer }} 35 | - name: Upload Crash 36 | uses: actions/upload-artifact@v1 37 | if: failure() && steps.build.outcome == 'success' 38 | with: 39 | name: ${{ matrix.sanitizer }}-artifacts 40 | path: ./out/artifacts 41 | -------------------------------------------------------------------------------- /lib/libbpf/.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vi: ts=2 sw=2 et: 3 | 4 | name: "CodeQL" 5 | 6 | on: 7 | push: 8 | branches: 9 | - master 10 | pull_request: 11 | branches: 12 | - master 13 | 14 | permissions: 15 | contents: read 16 | 17 | jobs: 18 | analyze: 19 | name: Analyze 20 | runs-on: ubuntu-22.04 21 | concurrency: 22 | group: ${{ github.workflow }}-${{ matrix.language }}-${{ github.ref }} 23 | cancel-in-progress: true 24 | permissions: 25 | actions: read 26 | security-events: write 27 | 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | language: ['cpp', 'python'] 32 | 33 | steps: 34 | - name: Checkout repository 35 | uses: actions/checkout@v3 36 | 37 | - name: Initialize CodeQL 38 | uses: github/codeql-action/init@v2 39 | with: 40 | languages: ${{ matrix.language }} 41 | queries: +security-extended,security-and-quality 42 | 43 | - name: Setup 44 | uses: ./.github/actions/setup 45 | 46 | - name: Build 47 | run: | 48 | source /tmp/ci_setup 49 | make -C ./src 50 | 51 | - name: Perform CodeQL Analysis 52 | uses: github/codeql-action/analyze@v2 53 | -------------------------------------------------------------------------------- /lib/libbpf/.github/workflows/coverity.yml: -------------------------------------------------------------------------------- 1 | name: libbpf-ci-coverity 2 | 3 | on: 4 | schedule: 5 | - cron: '0 18 * * *' 6 | 7 | 8 | jobs: 9 | coverity: 10 | runs-on: ubuntu-latest 11 | if: github.repository == 'libbpf/libbpf' 12 | name: Coverity 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: ./.github/actions/setup 16 | - name: Run coverity 17 | run: | 18 | source "${GITHUB_WORKSPACE}"/ci/vmtest/helpers.sh 19 | foldable start "Setup CI env" 20 | source /tmp/ci_setup 21 | export COVERITY_SCAN_NOTIFICATION_EMAIL="${AUTHOR_EMAIL}" 22 | export COVERITY_SCAN_BRANCH_PATTERN=${GITHUB_REF##refs/*/} 23 | export TRAVIS_BRANCH=${COVERITY_SCAN_BRANCH_PATTERN} 24 | foldable end 25 | scripts/coverity.sh 26 | env: 27 | COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} 28 | COVERITY_SCAN_PROJECT_NAME: libbpf 29 | COVERITY_SCAN_BUILD_COMMAND_PREPEND: 'cd src/' 30 | COVERITY_SCAN_BUILD_COMMAND: 'make' 31 | - name: SCM log 32 | run: cat /home/runner/work/libbpf/libbpf/src/cov-int/scm_log.txt 33 | -------------------------------------------------------------------------------- /lib/libbpf/.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: "lint" 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | 9 | jobs: 10 | shellcheck: 11 | name: ShellCheck 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v3 16 | - name: Run ShellCheck 17 | uses: ludeeus/action-shellcheck@master 18 | env: 19 | SHELLCHECK_OPTS: --severity=error 20 | -------------------------------------------------------------------------------- /lib/libbpf/.github/workflows/ondemand.yml: -------------------------------------------------------------------------------- 1 | name: ondemand 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | kernel-origin: 7 | description: 'git repo for linux kernel' 8 | default: 'https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git' 9 | required: true 10 | kernel-rev: 11 | description: 'rev/tag/branch for linux kernel' 12 | default: "master" 13 | required: true 14 | pahole-origin: 15 | description: 'git repo for pahole' 16 | default: 'https://git.kernel.org/pub/scm/devel/pahole/pahole.git' 17 | required: true 18 | pahole-rev: 19 | description: 'ref/tag/branch for pahole' 20 | default: "master" 21 | required: true 22 | 23 | jobs: 24 | vmtest: 25 | runs-on: ubuntu-latest 26 | name: vmtest with customized pahole/Kernel 27 | steps: 28 | - uses: actions/checkout@v3 29 | - uses: ./.github/actions/setup 30 | - uses: ./.github/actions/vmtest 31 | with: 32 | kernel: 'LATEST' 33 | kernel-rev: ${{ github.event.inputs.kernel-rev }} 34 | kernel-origin: ${{ github.event.inputs.kernel-origin }} 35 | pahole: ${{ github.event.inputs.pahole-rev }} 36 | pahole-origin: ${{ github.event.inputs.pahole-origin }} 37 | -------------------------------------------------------------------------------- /lib/libbpf/.github/workflows/pahole.yml: -------------------------------------------------------------------------------- 1 | name: pahole-staging 2 | 3 | on: 4 | schedule: 5 | - cron: '0 18 * * *' 6 | 7 | 8 | jobs: 9 | vmtest: 10 | runs-on: ubuntu-20.04 11 | name: Kernel LATEST + staging pahole 12 | env: 13 | STAGING: tmp.master 14 | steps: 15 | - uses: actions/checkout@v3 16 | - uses: ./.github/actions/setup 17 | - uses: ./.github/actions/vmtest 18 | with: 19 | kernel: LATEST 20 | pahole: $STAGING 21 | -------------------------------------------------------------------------------- /lib/libbpf/.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: libbpf-ci 2 | 3 | on: 4 | pull_request: 5 | push: 6 | schedule: 7 | - cron: '0 18 * * *' 8 | 9 | concurrency: 10 | group: ci-test-${{ github.head_ref }} 11 | cancel-in-progress: true 12 | 13 | jobs: 14 | vmtest: 15 | runs-on: ${{ matrix.runs_on }} 16 | name: Kernel ${{ matrix.kernel }} on ${{ matrix.runs_on }} + selftests 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | include: 21 | - kernel: 'LATEST' 22 | runs_on: ubuntu-20.04 23 | arch: 'x86_64' 24 | - kernel: '5.5.0' 25 | runs_on: ubuntu-20.04 26 | arch: 'x86_64' 27 | - kernel: '4.9.0' 28 | runs_on: ubuntu-20.04 29 | arch: 'x86_64' 30 | - kernel: 'LATEST' 31 | runs_on: s390x 32 | arch: 's390x' 33 | steps: 34 | # Allow CI user to access /dev/kvm (via qemu) w/o group change/relogin 35 | # by changing permissions set by udev. 36 | - name: Set /dev/kvm permissions 37 | shell: bash 38 | run: | 39 | if [ -e /dev/kvm ]; then 40 | echo "/dev/kvm exists" 41 | if [ $(id -u) != 0 ]; then 42 | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \ 43 | | sudo tee /etc/udev/rules.d/99-kvm4all.rules > /dev/null 44 | sudo udevadm control --reload-rules 45 | sudo udevadm trigger --name-match=kvm 46 | fi 47 | else 48 | echo "/dev/kvm does not exist" 49 | fi 50 | - uses: actions/checkout@v3 51 | name: Checkout 52 | - uses: ./.github/actions/setup 53 | name: Setup 54 | - uses: ./.github/actions/vmtest 55 | name: vmtest 56 | with: 57 | kernel: ${{ matrix.kernel }} 58 | arch: ${{ matrix.arch }} 59 | -------------------------------------------------------------------------------- /lib/libbpf/.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | build: 9 | os: "ubuntu-22.04" 10 | tools: 11 | python: "3.11" 12 | 13 | # Build documentation in the docs/ directory with Sphinx 14 | sphinx: 15 | builder: html 16 | configuration: docs/conf.py 17 | 18 | formats: 19 | - htmlzip 20 | - pdf 21 | - epub 22 | 23 | # Optionally set the version of Python and requirements required to build your docs 24 | python: 25 | install: 26 | - requirements: docs/sphinx/requirements.txt 27 | -------------------------------------------------------------------------------- /lib/libbpf/BPF-CHECKPOINT-COMMIT: -------------------------------------------------------------------------------- 1 | bc4fbf022c68967cb49b2b820b465cf90de974b8 2 | -------------------------------------------------------------------------------- /lib/libbpf/CHECKPOINT-COMMIT: -------------------------------------------------------------------------------- 1 | 750011e239a50873251c16207b0fe78eabf8577e 2 | -------------------------------------------------------------------------------- /lib/libbpf/LICENSE: -------------------------------------------------------------------------------- 1 | LGPL-2.1 OR BSD-2-Clause 2 | -------------------------------------------------------------------------------- /lib/libbpf/LICENSE.BSD-2-Clause: -------------------------------------------------------------------------------- 1 | Valid-License-Identifier: BSD-2-Clause 2 | SPDX-URL: https://spdx.org/licenses/BSD-2-Clause.html 3 | Usage-Guide: 4 | To use the BSD 2-clause "Simplified" License put the following SPDX 5 | tag/value pair into a comment according to the placement guidelines in 6 | the licensing rules documentation: 7 | SPDX-License-Identifier: BSD-2-Clause 8 | License-Text: 9 | 10 | Copyright (c) 2015 The Libbpf Authors. All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | 18 | 2. Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /lib/libbpf/ci/diffs/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eTran-NSDI25/eTran/f26ef186bde0f9b3b899712e44112de47b7d5a65/lib/libbpf/ci/diffs/.keep -------------------------------------------------------------------------------- /lib/libbpf/ci/managers/test_compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euox pipefail 3 | 4 | EXTRA_CFLAGS=${EXTRA_CFLAGS:-} 5 | EXTRA_LDFLAGS=${EXTRA_LDFLAGS:-} 6 | 7 | cat << EOF > main.c 8 | #include 9 | int main() { 10 | return bpf_object__open(0) < 0; 11 | } 12 | EOF 13 | 14 | # static linking 15 | ${CC:-cc} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o main -I./include/uapi -I./install/usr/include main.c ./build/libbpf.a -lelf -lz 16 | -------------------------------------------------------------------------------- /lib/libbpf/ci/managers/travis_wait.bash: -------------------------------------------------------------------------------- 1 | # This was borrowed from https://github.com/travis-ci/travis-build/tree/master/lib/travis/build/bash 2 | # to get around https://github.com/travis-ci/travis-ci/issues/9979. It should probably be removed 3 | # as soon as Travis CI has started to provide an easy way to export the functions to bash scripts. 4 | 5 | travis_jigger() { 6 | local cmd_pid="${1}" 7 | shift 8 | local timeout="${1}" 9 | shift 10 | local count=0 11 | 12 | echo -e "\\n" 13 | 14 | while [[ "${count}" -lt "${timeout}" ]]; do 15 | count="$((count + 1))" 16 | echo -ne "Still running (${count} of ${timeout}): ${*}\\r" 17 | sleep 60 18 | done 19 | 20 | echo -e "\\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"${*}\"${ANSI_RESET}\\n" 21 | kill -9 "${cmd_pid}" 22 | } 23 | 24 | travis_wait() { 25 | local timeout="${1}" 26 | 27 | if [[ "${timeout}" =~ ^[0-9]+$ ]]; then 28 | shift 29 | else 30 | timeout=20 31 | fi 32 | 33 | local cmd=("${@}") 34 | local log_file="travis_wait_${$}.log" 35 | 36 | "${cmd[@]}" &>"${log_file}" & 37 | local cmd_pid="${!}" 38 | 39 | travis_jigger "${!}" "${timeout}" "${cmd[@]}" & 40 | local jigger_pid="${!}" 41 | local result 42 | 43 | { 44 | set +e 45 | wait "${cmd_pid}" 2>/dev/null 46 | result="${?}" 47 | ps -p"${jigger_pid}" &>/dev/null && kill "${jigger_pid}" 48 | set -e 49 | } 50 | 51 | if [[ "${result}" -eq 0 ]]; then 52 | echo -e "\\n${ANSI_GREEN}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}" 53 | else 54 | echo -e "\\n${ANSI_RED}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}" 55 | fi 56 | 57 | echo -e "\\n${ANSI_GREEN}Log:${ANSI_RESET}\\n" 58 | cat "${log_file}" 59 | 60 | return "${result}" 61 | } 62 | -------------------------------------------------------------------------------- /lib/libbpf/ci/managers/ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eux 3 | 4 | RELEASE="focal" 5 | 6 | apt-get update 7 | apt-get install -y pkg-config 8 | 9 | source "$(dirname $0)/travis_wait.bash" 10 | 11 | cd $REPO_ROOT 12 | 13 | EXTRA_CFLAGS="-Werror -Wall -fsanitize=address,undefined" 14 | EXTRA_LDFLAGS="-Werror -Wall -fsanitize=address,undefined" 15 | mkdir build install 16 | cc --version 17 | make -j$((4*$(nproc))) EXTRA_CFLAGS="${EXTRA_CFLAGS}" EXTRA_LDFLAGS="${EXTRA_LDFLAGS}" -C ./src -B OBJDIR=../build 18 | ldd build/libbpf.so 19 | if ! ldd build/libbpf.so | grep -q libelf; then 20 | echo "FAIL: No reference to libelf.so in libbpf.so!" 21 | exit 1 22 | fi 23 | make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install 24 | EXTRA_CFLAGS=${EXTRA_CFLAGS} EXTRA_LDFLAGS=${EXTRA_LDFLAGS} $(dirname $0)/test_compile.sh 25 | -------------------------------------------------------------------------------- /lib/libbpf/ci/vmtest/configs/ALLOWLIST-4.9.0: -------------------------------------------------------------------------------- 1 | # btf_dump -- need to disable data dump sub-tests 2 | core_retro 3 | cpu_mask 4 | hashmap 5 | legacy_printk 6 | perf_buffer 7 | section_names 8 | 9 | -------------------------------------------------------------------------------- /lib/libbpf/ci/vmtest/configs/ALLOWLIST-5.5.0: -------------------------------------------------------------------------------- 1 | # attach_probe 2 | autoload 3 | bpf_verif_scale 4 | cgroup_attach_autodetach 5 | cgroup_attach_override 6 | core_autosize 7 | core_extern 8 | core_read_macros 9 | core_reloc 10 | core_retro 11 | cpu_mask 12 | endian 13 | get_branch_snapshot 14 | get_stackid_cannot_attach 15 | global_data 16 | global_data_init 17 | global_func_args 18 | hashmap 19 | legacy_printk 20 | linked_funcs 21 | linked_maps 22 | map_lock 23 | obj_name 24 | perf_buffer 25 | perf_event_stackmap 26 | pinning 27 | pkt_md_access 28 | probe_user 29 | queue_stack_map 30 | raw_tp_writable_reject_nbd_invalid 31 | raw_tp_writable_test_run 32 | rdonly_maps 33 | section_names 34 | signal_pending 35 | sockmap_ktls 36 | spinlock 37 | stacktrace_map 38 | stacktrace_map_raw_tp 39 | static_linked 40 | task_fd_query_rawtp 41 | task_fd_query_tp 42 | tc_bpf 43 | tcp_estats 44 | tcp_rtt 45 | tp_attach_query 46 | usdt/urand_pid_attach 47 | xdp 48 | xdp_noinline 49 | xdp_perf 50 | -------------------------------------------------------------------------------- /lib/libbpf/ci/vmtest/configs/DENYLIST-5.5.0: -------------------------------------------------------------------------------- 1 | # This complements ALLOWLIST-5.5.0 but excludes subtest that can't work on 5.5 2 | 3 | btf # "size check test", "func (Non zero vlen)" 4 | tailcalls # tailcall_bpf2bpf_1, tailcall_bpf2bpf_2, tailcall_bpf2bpf_3 5 | tc_bpf/tc_bpf_non_root 6 | -------------------------------------------------------------------------------- /lib/libbpf/ci/vmtest/configs/DENYLIST-latest: -------------------------------------------------------------------------------- 1 | decap_sanity # weird failure with decap_sanity_ns netns already existing, TBD 2 | empty_skb # waiting the fix in bpf tree to make it to bpf-next 3 | bpf_nf/tc-bpf-ct # test consistently failing on x86: https://github.com/libbpf/libbpf/pull/698#issuecomment-1590341200 4 | bpf_nf/xdp-ct # test consistently failing on x86: https://github.com/libbpf/libbpf/pull/698#issuecomment-1590341200 5 | kprobe_multi_bench_attach # suspected to cause crashes in CI 6 | find_vma # test consistently fails on latest kernel, see https://github.com/libbpf/libbpf/issues/754 for details 7 | bpf_cookie/perf_event 8 | send_signal/send_signal_nmi 9 | send_signal/send_signal_nmi_thread 10 | -------------------------------------------------------------------------------- /lib/libbpf/ci/vmtest/configs/DENYLIST-latest.s390x: -------------------------------------------------------------------------------- 1 | # TEMPORARY 2 | sockmap_listen/sockhash VSOCK test_vsock_redir 3 | usdt/basic # failing verifier due to bounds check after LLVM update 4 | usdt/multispec # same as above 5 | -------------------------------------------------------------------------------- /lib/libbpf/ci/vmtest/helpers.sh: -------------------------------------------------------------------------------- 1 | # shellcheck shell=bash 2 | 3 | # $1 - start or end 4 | # $2 - fold identifier, no spaces 5 | # $3 - fold section description 6 | foldable() { 7 | local YELLOW='\033[1;33m' 8 | local NOCOLOR='\033[0m' 9 | if [ $1 = "start" ]; then 10 | line="::group::$2" 11 | if [ ! -z "${3:-}" ]; then 12 | line="$line - ${YELLOW}$3${NOCOLOR}" 13 | fi 14 | else 15 | line="::endgroup::" 16 | fi 17 | echo -e "$line" 18 | } 19 | 20 | __print() { 21 | local TITLE="" 22 | if [[ -n $2 ]]; then 23 | TITLE=" title=$2" 24 | fi 25 | echo "::$1${TITLE}::$3" 26 | } 27 | 28 | # $1 - title 29 | # $2 - message 30 | print_error() { 31 | __print error $1 $2 32 | } 33 | 34 | # $1 - title 35 | # $2 - message 36 | print_notice() { 37 | __print notice $1 $2 38 | } 39 | -------------------------------------------------------------------------------- /lib/libbpf/docs/.gitignore: -------------------------------------------------------------------------------- 1 | sphinx/build 2 | sphinx/doxygen/build -------------------------------------------------------------------------------- /lib/libbpf/docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Configuration file for the Sphinx documentation builder. 4 | # 5 | # This file only contains a selection of the most common options. For a full 6 | # list see the documentation: 7 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 8 | 9 | import os 10 | import subprocess 11 | 12 | project = "libbpf" 13 | 14 | extensions = [ 15 | 'sphinx.ext.autodoc', 16 | 'sphinx.ext.doctest', 17 | 'sphinx.ext.mathjax', 18 | 'sphinx.ext.viewcode', 19 | 'sphinx.ext.imgmath', 20 | 'sphinx.ext.todo', 21 | 'sphinx_rtd_theme', 22 | 'breathe', 23 | ] 24 | 25 | # List of patterns, relative to source directory, that match files and 26 | # directories to ignore when looking for source files. 27 | # This pattern also affects html_static_path and html_extra_path. 28 | exclude_patterns = [] 29 | 30 | read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True' 31 | 32 | if read_the_docs_build: 33 | subprocess.call('cd sphinx ; make clean', shell=True) 34 | subprocess.call('cd sphinx/doxygen ; doxygen', shell=True) 35 | 36 | html_theme = 'sphinx_rtd_theme' 37 | 38 | breathe_projects = { "libbpf": "./sphinx/doxygen/build/xml/" } 39 | breathe_default_project = "libbpf" 40 | breathe_show_define_initializer = True 41 | breathe_show_enumvalue_initializer = True 42 | -------------------------------------------------------------------------------- /lib/libbpf/docs/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 | 3 | .. _libbpf: 4 | 5 | ====== 6 | libbpf 7 | ====== 8 | 9 | If you are looking to develop BPF applications using the libbpf library, this 10 | directory contains important documentation that you should read. 11 | 12 | To get started, it is recommended to begin with the :doc:`libbpf Overview 13 | ` document, which provides a high-level understanding of the 14 | libbpf APIs and their usage. This will give you a solid foundation to start 15 | exploring and utilizing the various features of libbpf to develop your BPF 16 | applications. 17 | 18 | .. toctree:: 19 | :maxdepth: 1 20 | 21 | libbpf_overview 22 | API Documentation 23 | program_types 24 | libbpf_naming_convention 25 | libbpf_build 26 | 27 | 28 | All general BPF questions, including kernel functionality, libbpf APIs and their 29 | application, should be sent to bpf@vger.kernel.org mailing list. You can 30 | `subscribe `_ to the mailing list 31 | search its `archive `_. Please search the archive 32 | before asking new questions. It may be that this was already addressed or 33 | answered before. 34 | -------------------------------------------------------------------------------- /lib/libbpf/docs/libbpf_build.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 | 3 | Building libbpf 4 | =============== 5 | 6 | libelf and zlib are internal dependencies of libbpf and thus are required to link 7 | against and must be installed on the system for applications to work. 8 | pkg-config is used by default to find libelf, and the program called 9 | can be overridden with PKG_CONFIG. 10 | 11 | If using pkg-config at build time is not desired, it can be disabled by 12 | setting NO_PKG_CONFIG=1 when calling make. 13 | 14 | To build both static libbpf.a and shared libbpf.so: 15 | 16 | .. code-block:: bash 17 | 18 | $ cd src 19 | $ make 20 | 21 | To build only static libbpf.a library in directory build/ and install them 22 | together with libbpf headers in a staging directory root/: 23 | 24 | .. code-block:: bash 25 | 26 | $ cd src 27 | $ mkdir build root 28 | $ BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=root make install 29 | 30 | To build both static libbpf.a and shared libbpf.so against a custom libelf 31 | dependency installed in /build/root/ and install them together with libbpf 32 | headers in a build directory /build/root/: 33 | 34 | .. code-block:: bash 35 | 36 | $ cd src 37 | $ PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make -------------------------------------------------------------------------------- /lib/libbpf/docs/sphinx/Makefile: -------------------------------------------------------------------------------- 1 | SPHINXBUILD ?= sphinx-build 2 | SOURCEDIR = ../src 3 | BUILDDIR = build 4 | 5 | help: 6 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" 7 | 8 | %: 9 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" 10 | -------------------------------------------------------------------------------- /lib/libbpf/docs/sphinx/requirements.txt: -------------------------------------------------------------------------------- 1 | breathe 2 | sphinx_rtd_theme 3 | -------------------------------------------------------------------------------- /lib/libbpf/fuzz/bpf-object-fuzzer.c: -------------------------------------------------------------------------------- 1 | #include "libbpf.h" 2 | 3 | static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args) 4 | { 5 | return 0; 6 | } 7 | 8 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 9 | struct bpf_object *obj = NULL; 10 | DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts); 11 | int err; 12 | 13 | libbpf_set_print(libbpf_print_fn); 14 | 15 | opts.object_name = "fuzz-object"; 16 | obj = bpf_object__open_mem(data, size, &opts); 17 | err = libbpf_get_error(obj); 18 | if (err) 19 | return 0; 20 | 21 | bpf_object__close(obj); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /lib/libbpf/fuzz/bpf-object-fuzzer_seed_corpus.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eTran-NSDI25/eTran/f26ef186bde0f9b3b899712e44112de47b7d5a65/lib/libbpf/fuzz/bpf-object-fuzzer_seed_corpus.zip -------------------------------------------------------------------------------- /lib/libbpf/include/asm/barrier.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | #ifndef __ASM_BARRIER_H 3 | #define __ASM_BARRIER_H 4 | 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /lib/libbpf/include/linux/compiler.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_COMPILER_H 4 | #define __LINUX_COMPILER_H 5 | 6 | #define likely(x) __builtin_expect(!!(x), 1) 7 | #define unlikely(x) __builtin_expect(!!(x), 0) 8 | 9 | #define READ_ONCE(x) (*(volatile typeof(x) *)&x) 10 | #define WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v) 11 | 12 | #define barrier() asm volatile("" ::: "memory") 13 | 14 | #if defined(__x86_64__) 15 | 16 | # define smp_rmb() barrier() 17 | # define smp_wmb() barrier() 18 | # define smp_mb() asm volatile("lock; addl $0,-132(%%rsp)" ::: "memory", "cc") 19 | 20 | # define smp_store_release(p, v) \ 21 | do { \ 22 | barrier(); \ 23 | WRITE_ONCE(*p, v); \ 24 | } while (0) 25 | 26 | # define smp_load_acquire(p) \ 27 | ({ \ 28 | typeof(*p) ___p = READ_ONCE(*p); \ 29 | barrier(); \ 30 | ___p; \ 31 | }) 32 | 33 | #elif defined(__aarch64__) 34 | 35 | # define smp_rmb() asm volatile("dmb ishld" ::: "memory") 36 | # define smp_wmb() asm volatile("dmb ishst" ::: "memory") 37 | # define smp_mb() asm volatile("dmb ish" ::: "memory") 38 | 39 | #endif 40 | 41 | #ifndef smp_mb 42 | # define smp_mb() __sync_synchronize() 43 | #endif 44 | 45 | #ifndef smp_rmb 46 | # define smp_rmb() smp_mb() 47 | #endif 48 | 49 | #ifndef smp_wmb 50 | # define smp_wmb() smp_mb() 51 | #endif 52 | 53 | #ifndef smp_store_release 54 | # define smp_store_release(p, v) \ 55 | do { \ 56 | smp_mb(); \ 57 | WRITE_ONCE(*p, v); \ 58 | } while (0) 59 | #endif 60 | 61 | #ifndef smp_load_acquire 62 | # define smp_load_acquire(p) \ 63 | ({ \ 64 | typeof(*p) ___p = READ_ONCE(*p); \ 65 | smp_mb(); \ 66 | ___p; \ 67 | }) 68 | #endif 69 | 70 | #endif /* __LINUX_COMPILER_H */ 71 | -------------------------------------------------------------------------------- /lib/libbpf/include/linux/err.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_ERR_H 4 | #define __LINUX_ERR_H 5 | 6 | #include 7 | #include 8 | 9 | #define MAX_ERRNO 4095 10 | 11 | #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO) 12 | 13 | static inline void * ERR_PTR(long error_) 14 | { 15 | return (void *) error_; 16 | } 17 | 18 | static inline long PTR_ERR(const void *ptr) 19 | { 20 | return (long) ptr; 21 | } 22 | 23 | static inline bool IS_ERR(const void *ptr) 24 | { 25 | return IS_ERR_VALUE((unsigned long)ptr); 26 | } 27 | 28 | static inline bool IS_ERR_OR_NULL(const void *ptr) 29 | { 30 | return (!ptr) || IS_ERR_VALUE((unsigned long)ptr); 31 | } 32 | 33 | static inline long PTR_ERR_OR_ZERO(const void *ptr) 34 | { 35 | return IS_ERR(ptr) ? PTR_ERR(ptr) : 0; 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/libbpf/include/linux/kernel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_KERNEL_H 4 | #define __LINUX_KERNEL_H 5 | 6 | #ifndef offsetof 7 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 8 | #endif 9 | 10 | #ifndef container_of 11 | #define container_of(ptr, type, member) ({ \ 12 | const typeof(((type *)0)->member) * __mptr = (ptr); \ 13 | (type *)((char *)__mptr - offsetof(type, member)); }) 14 | #endif 15 | 16 | #ifndef max 17 | #define max(x, y) ({ \ 18 | typeof(x) _max1 = (x); \ 19 | typeof(y) _max2 = (y); \ 20 | (void) (&_max1 == &_max2); \ 21 | _max1 > _max2 ? _max1 : _max2; }) 22 | #endif 23 | 24 | #ifndef min 25 | #define min(x, y) ({ \ 26 | typeof(x) _min1 = (x); \ 27 | typeof(y) _min2 = (y); \ 28 | (void) (&_min1 == &_min2); \ 29 | _min1 < _min2 ? _min1 : _min2; }) 30 | #endif 31 | 32 | #ifndef roundup 33 | #define roundup(x, y) ( \ 34 | { \ 35 | const typeof(y) __y = y; \ 36 | (((x) + (__y - 1)) / __y) * __y; \ 37 | } \ 38 | ) 39 | #endif 40 | 41 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 42 | #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /lib/libbpf/include/linux/ring_buffer.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | #ifndef _TOOLS_LINUX_RING_BUFFER_H_ 3 | #define _TOOLS_LINUX_RING_BUFFER_H_ 4 | 5 | #include 6 | 7 | static inline __u64 ring_buffer_read_head(struct perf_event_mmap_page *base) 8 | { 9 | return smp_load_acquire(&base->data_head); 10 | } 11 | 12 | static inline void ring_buffer_write_tail(struct perf_event_mmap_page *base, 13 | __u64 tail) 14 | { 15 | smp_store_release(&base->data_tail, tail); 16 | } 17 | 18 | #endif /* _TOOLS_LINUX_RING_BUFFER_H_ */ 19 | -------------------------------------------------------------------------------- /lib/libbpf/include/linux/types.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_TYPES_H 4 | #define __LINUX_TYPES_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #define __bitwise__ 16 | #define __bitwise __bitwise__ 17 | 18 | typedef __u16 __bitwise __le16; 19 | typedef __u16 __bitwise __be16; 20 | typedef __u32 __bitwise __le32; 21 | typedef __u32 __bitwise __be32; 22 | typedef __u64 __bitwise __le64; 23 | typedef __u64 __bitwise __be64; 24 | 25 | #ifndef __aligned_u64 26 | # define __aligned_u64 __u64 __attribute__((aligned(8))) 27 | #endif 28 | 29 | struct list_head { 30 | struct list_head *next, *prev; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/libbpf/include/uapi/linux/bpf_common.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef _UAPI__LINUX_BPF_COMMON_H__ 3 | #define _UAPI__LINUX_BPF_COMMON_H__ 4 | 5 | /* Instruction classes */ 6 | #define BPF_CLASS(code) ((code) & 0x07) 7 | #define BPF_LD 0x00 8 | #define BPF_LDX 0x01 9 | #define BPF_ST 0x02 10 | #define BPF_STX 0x03 11 | #define BPF_ALU 0x04 12 | #define BPF_JMP 0x05 13 | #define BPF_RET 0x06 14 | #define BPF_MISC 0x07 15 | 16 | /* ld/ldx fields */ 17 | #define BPF_SIZE(code) ((code) & 0x18) 18 | #define BPF_W 0x00 /* 32-bit */ 19 | #define BPF_H 0x08 /* 16-bit */ 20 | #define BPF_B 0x10 /* 8-bit */ 21 | /* eBPF BPF_DW 0x18 64-bit */ 22 | #define BPF_MODE(code) ((code) & 0xe0) 23 | #define BPF_IMM 0x00 24 | #define BPF_ABS 0x20 25 | #define BPF_IND 0x40 26 | #define BPF_MEM 0x60 27 | #define BPF_LEN 0x80 28 | #define BPF_MSH 0xa0 29 | 30 | /* alu/jmp fields */ 31 | #define BPF_OP(code) ((code) & 0xf0) 32 | #define BPF_ADD 0x00 33 | #define BPF_SUB 0x10 34 | #define BPF_MUL 0x20 35 | #define BPF_DIV 0x30 36 | #define BPF_OR 0x40 37 | #define BPF_AND 0x50 38 | #define BPF_LSH 0x60 39 | #define BPF_RSH 0x70 40 | #define BPF_NEG 0x80 41 | #define BPF_MOD 0x90 42 | #define BPF_XOR 0xa0 43 | 44 | #define BPF_JA 0x00 45 | #define BPF_JEQ 0x10 46 | #define BPF_JGT 0x20 47 | #define BPF_JGE 0x30 48 | #define BPF_JSET 0x40 49 | #define BPF_SRC(code) ((code) & 0x08) 50 | #define BPF_K 0x00 51 | #define BPF_X 0x08 52 | 53 | #ifndef BPF_MAXINSNS 54 | #define BPF_MAXINSNS 4096 55 | #endif 56 | 57 | #endif /* _UAPI__LINUX_BPF_COMMON_H__ */ 58 | -------------------------------------------------------------------------------- /lib/libbpf/include/uapi/linux/openat2.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef _UAPI_LINUX_OPENAT2_H 3 | #define _UAPI_LINUX_OPENAT2_H 4 | 5 | #include 6 | 7 | /* 8 | * Arguments for how openat2(2) should open the target path. If only @flags and 9 | * @mode are non-zero, then openat2(2) operates very similarly to openat(2). 10 | * 11 | * However, unlike openat(2), unknown or invalid bits in @flags result in 12 | * -EINVAL rather than being silently ignored. @mode must be zero unless one of 13 | * {O_CREAT, O_TMPFILE} are set. 14 | * 15 | * @flags: O_* flags. 16 | * @mode: O_CREAT/O_TMPFILE file mode. 17 | * @resolve: RESOLVE_* flags. 18 | */ 19 | struct open_how { 20 | __u64 flags; 21 | __u64 mode; 22 | __u64 resolve; 23 | }; 24 | 25 | /* how->resolve flags for openat2(2). */ 26 | #define RESOLVE_NO_XDEV 0x01 /* Block mount-point crossings 27 | (includes bind-mounts). */ 28 | #define RESOLVE_NO_MAGICLINKS 0x02 /* Block traversal through procfs-style 29 | "magic-links". */ 30 | #define RESOLVE_NO_SYMLINKS 0x04 /* Block traversal through all symlinks 31 | (implies OEXT_NO_MAGICLINKS) */ 32 | #define RESOLVE_BENEATH 0x08 /* Block "lexical" trickery like 33 | "..", symlinks, and absolute 34 | paths which escape the dirfd. */ 35 | #define RESOLVE_IN_ROOT 0x10 /* Make all jumps to "/" and ".." 36 | be scoped inside the dirfd 37 | (similar to chroot(2)). */ 38 | #define RESOLVE_CACHED 0x20 /* Only complete if resolution can be 39 | completed through cached lookup. May 40 | return -EAGAIN if that's not 41 | possible. */ 42 | 43 | #endif /* _UAPI_LINUX_OPENAT2_H */ 44 | -------------------------------------------------------------------------------- /lib/libbpf/src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | /libbpf.pc 4 | /libbpf.so* 5 | /staticobjs 6 | /sharedobjs 7 | -------------------------------------------------------------------------------- /lib/libbpf/src/libbpf.pc.template: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 | 3 | prefix=@PREFIX@ 4 | libdir=@LIBDIR@ 5 | includedir=${prefix}/include 6 | 7 | Name: libbpf 8 | Description: BPF library 9 | Version: @VERSION@ 10 | Libs: -L${libdir} -lbpf 11 | Requires.private: libelf zlib 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /lib/libbpf/src/libbpf_version.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | /* Copyright (C) 2021 Facebook */ 3 | #ifndef __LIBBPF_VERSION_H 4 | #define __LIBBPF_VERSION_H 5 | 6 | #define LIBBPF_MAJOR_VERSION 1 7 | #define LIBBPF_MINOR_VERSION 3 8 | 9 | #endif /* __LIBBPF_VERSION_H */ 10 | -------------------------------------------------------------------------------- /lib/libbpf/src/str_error.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 | #undef _GNU_SOURCE 3 | #include 4 | #include 5 | #include "str_error.h" 6 | 7 | /* make sure libbpf doesn't use kernel-only integer typedefs */ 8 | #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64 9 | 10 | /* 11 | * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl 12 | * libc, while checking strerror_r() return to avoid having to check this in 13 | * all places calling it. 14 | */ 15 | char *libbpf_strerror_r(int err, char *dst, int len) 16 | { 17 | int ret = strerror_r(err < 0 ? -err : err, dst, len); 18 | if (ret) 19 | snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret); 20 | return dst; 21 | } 22 | -------------------------------------------------------------------------------- /lib/libbpf/src/str_error.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | #ifndef __LIBBPF_STR_ERROR_H 3 | #define __LIBBPF_STR_ERROR_H 4 | 5 | char *libbpf_strerror_r(int err, char *dst, int len); 6 | #endif /* __LIBBPF_STR_ERROR_H */ 7 | -------------------------------------------------------------------------------- /lib/libbpf/src/strset.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | /* Copyright (c) 2021 Facebook */ 4 | #ifndef __LIBBPF_STRSET_H 5 | #define __LIBBPF_STRSET_H 6 | 7 | #include 8 | #include 9 | 10 | struct strset; 11 | 12 | struct strset *strset__new(size_t max_data_sz, const char *init_data, size_t init_data_sz); 13 | void strset__free(struct strset *set); 14 | 15 | const char *strset__data(const struct strset *set); 16 | size_t strset__data_size(const struct strset *set); 17 | 18 | int strset__find_str(struct strset *set, const char *s); 19 | int strset__add_str(struct strset *set, const char *s); 20 | 21 | #endif /* __LIBBPF_STRSET_H */ 22 | -------------------------------------------------------------------------------- /lib/libbpf/src/zip.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LIBBPF_ZIP_H 4 | #define __LIBBPF_ZIP_H 5 | 6 | #include 7 | 8 | /* Represents an open zip archive. 9 | * Only basic ZIP files are supported, in particular the following are not 10 | * supported: 11 | * - encryption 12 | * - streaming 13 | * - multi-part ZIP files 14 | * - ZIP64 15 | */ 16 | struct zip_archive; 17 | 18 | /* Carries information on name, compression method, and data corresponding to a 19 | * file in a zip archive. 20 | */ 21 | struct zip_entry { 22 | /* Compression method as defined in pkzip spec. 0 means data is uncompressed. */ 23 | __u16 compression; 24 | 25 | /* Non-null terminated name of the file. */ 26 | const char *name; 27 | /* Length of the file name. */ 28 | __u16 name_length; 29 | 30 | /* Pointer to the file data. */ 31 | const void *data; 32 | /* Length of the file data. */ 33 | __u32 data_length; 34 | /* Offset of the file data within the archive. */ 35 | __u32 data_offset; 36 | }; 37 | 38 | /* Open a zip archive. Returns NULL in case of an error. */ 39 | struct zip_archive *zip_archive_open(const char *path); 40 | 41 | /* Close a zip archive and release resources. */ 42 | void zip_archive_close(struct zip_archive *archive); 43 | 44 | /* Look up an entry corresponding to a file in given zip archive. */ 45 | int zip_archive_find_entry(struct zip_archive *archive, const char *name, struct zip_entry *out); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/testenv/config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # These are the config options for the testlab 4 | 5 | 6 | SETUP_SCRIPT="$(dirname "$0")/setup-env.sh" 7 | STATEDIR="${TMPDIR:-/tmp}/bpf-examples" 8 | IP6_SUBNET=fc00:dead:cafe # must have exactly three :-separated elements 9 | IP6_PREFIX_SIZE=64 # Size of assigned prefixes 10 | IP6_FULL_PREFIX_SIZE=48 # Size of IP6_SUBNET 11 | IP4_SUBNET=10.11 12 | IP4_PREFIX_SIZE=24 # Size of assigned prefixes 13 | IP4_FULL_PREFIX_SIZE=16 # Size of IP4_SUBNET 14 | VLAN_IDS=(1 2) 15 | GENERATED_NAME_PREFIX="bpfex" 16 | -------------------------------------------------------------------------------- /lib/testenv/setup-env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0-or-later 3 | # 4 | # Script to setup things inside a test environment, used by testenv.sh for 5 | # executing commands. 6 | # 7 | # Author: Toke Høiland-Jørgensen (toke@redhat.com) 8 | # Date: 7 March 2019 9 | # Copyright (c) 2019 Red Hat 10 | 11 | 12 | die() 13 | { 14 | echo "$1" >&2 15 | exit 1 16 | } 17 | 18 | [ -n "$TESTENV_NAME" ] || die "TESTENV_NAME missing from environment" 19 | [ -n "$1" ] || die "Usage: $0 " 20 | 21 | set -o nounset 22 | 23 | mount -t bpf bpf /sys/fs/bpf/ || die "Unable to mount /sys/fs/bpf inside test environment" 24 | 25 | exec "$@" 26 | -------------------------------------------------------------------------------- /lib/util/Makefile: -------------------------------------------------------------------------------- 1 | include util.mk 2 | 3 | LIB_DIR ?= .. 4 | 5 | include $(LIB_DIR)/defines.mk 6 | 7 | all: $(UTIL_OBJS) 8 | 9 | # Create expansions for dependencies 10 | UTIL_H := ${UTIL_OBJS:.o=.h} 11 | 12 | CFLAGS+= -I$(LIB_DIR)/install/include 13 | 14 | $(UTIL_OBJS): %.o: %.c $(UTIL_H) $(LIBMK) 15 | $(QUIET_CC)$(CC) $(CFLAGS) -Wall -I../../headers -c -o $@ $< 16 | 17 | clean: 18 | $(Q)rm -f $(UTIL_OBJS) 19 | -------------------------------------------------------------------------------- /lib/util/logging.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #ifndef __LOGGING_H 4 | #define __LOGGING_H 5 | 6 | /* This matches the libbpf logging levels, but with an additional VERBOSE level; 7 | * we demote all libbpf messages by one level so debug messages only show up on 8 | * VERBOSE. 9 | */ 10 | enum logging_print_level { 11 | LOG_WARN, 12 | LOG_INFO, 13 | LOG_DEBUG, 14 | LOG_VERBOSE, 15 | }; 16 | 17 | extern void logging_print(enum logging_print_level level, const char *format, 18 | ...) __attribute__((format(printf, 2, 3))); 19 | 20 | #define __pr(level, fmt, ...) \ 21 | do { \ 22 | logging_print(level, fmt, ##__VA_ARGS__); \ 23 | } while (0) 24 | 25 | #define pr_warn(fmt, ...) __pr(LOG_WARN, fmt, ##__VA_ARGS__) 26 | #define pr_info(fmt, ...) __pr(LOG_INFO, fmt, ##__VA_ARGS__) 27 | #define pr_debug(fmt, ...) __pr(LOG_DEBUG, fmt, ##__VA_ARGS__) 28 | 29 | void init_lib_logging(void); 30 | void silence_libbpf_logging(void); 31 | void silence_libxdp_logging(void); 32 | enum logging_print_level set_log_level(enum logging_print_level level); 33 | enum logging_print_level increase_log_level(); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/util/util.mk: -------------------------------------------------------------------------------- 1 | # list of objects in this directory 2 | UTIL_OBJS := json_writer.o logging.o 3 | -------------------------------------------------------------------------------- /lib/xdp-tools/.github/scripts/prepare_test_kernel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | if [[ "$KERNEL_VERSION" == "LATEST" ]]; then 6 | git clone --depth 1 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git kernel 7 | cd kernel 8 | cp "$GITHUB_WORKSPACE"/.github/scripts/.config .config 9 | make -j $(nproc) olddefconfig all 10 | else 11 | KERNEL_VERSION_COMPLETE="$KERNEL_VERSION"-"$KERNEL_PATCH_VERSION".x86_64 12 | PACKAGES_URL=https://kojipkgs.fedoraproject.org/packages/kernel/ 13 | PACKAGES_URL+="$KERNEL_VERSION"/"$KERNEL_PATCH_VERSION"/x86_64 14 | 15 | for package in core modules modules-extra devel; do 16 | wget -nv "$PACKAGES_URL"/kernel-"$package"-"$KERNEL_VERSION_COMPLETE".rpm 17 | rpm2cpio kernel-"$package"-"$KERNEL_VERSION_COMPLETE".rpm | cpio -di 18 | done 19 | find lib -name "*.xz" -exec xz -d {} \; 20 | 21 | mv lib/modules/"$KERNEL_VERSION_COMPLETE" kernel 22 | mkdir -p kernel/arch/x86/boot 23 | cp kernel/vmlinuz kernel/arch/x86/boot/bzImage 24 | cp kernel/config kernel/.config 25 | rsync -a usr/src/kernels/"$KERNEL_VERSION_COMPLETE"/ kernel/ 26 | fi -------------------------------------------------------------------------------- /lib/xdp-tools/.github/scripts/prepare_test_tools.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | 6 | echo ::group::Install xdp-test-harness 7 | sudo python3 -m pip install xdp_test_harness 8 | echo ::endgroup:: 9 | 10 | 11 | echo ::group::Install virtme 12 | git clone https://github.com/amluto/virtme 13 | sudo python3 -m pip install ./virtme 14 | echo ::endgroup:: 15 | 16 | 17 | if [[ $KERNEL_VERSION == "LATEST" ]]; then 18 | echo ::group::Install pahole 19 | # In the repo there is only version 1.15 and we need newer. 20 | git clone https://git.kernel.org/pub/scm/devel/pahole/pahole.git 21 | mkdir pahole/build 22 | cd pahole/build 23 | cmake -D__LIB=lib .. 24 | sudo make install 25 | sudo ldconfig /usr/local/lib 26 | echo ::endgroup:: 27 | fi 28 | -------------------------------------------------------------------------------- /lib/xdp-tools/.github/scripts/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export $(cat ENVVARS | xargs -d '\n') 4 | 5 | make test V=1 >> TEST_OUTPUT 2>&1 6 | echo $? > TEST_RESULT 7 | -------------------------------------------------------------------------------- /lib/xdp-tools/.github/scripts/run_tests_in_vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ENVVARS="KERNEL_VERSION KERNEL_PATCH_VERSION DID_UNSHARE CLANG LLC" 4 | 5 | touch ENVVARS 6 | for v in $ENVVARS; do 7 | val=$(eval echo '$'$v) 8 | echo "$v=$val" >> ENVVARS 9 | done 10 | 11 | touch TEST_OUTPUT 12 | tail -f TEST_OUTPUT & 13 | 14 | sudo virtme-run --kdir kernel --script-exec .github/scripts/run_tests.sh --pwd --rw --mods=auto --qemu-opts -cpu qemu64 -machine accel=tcg -m 2G 15 | 16 | kill %1 17 | 18 | exit "$(cat TEST_RESULT)" 19 | -------------------------------------------------------------------------------- /lib/xdp-tools/.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "tagged-release" 3 | 4 | on: 5 | push: 6 | tags: 7 | - "v*" 8 | 9 | jobs: 10 | tagged-release: 11 | name: "Tagged Release" 12 | runs-on: "ubuntu-latest" 13 | 14 | steps: 15 | - name: Check out repository code 16 | uses: actions/checkout@v2 17 | with: 18 | submodules: recursive 19 | 20 | - name: "Create source archive" 21 | run: | 22 | make archive 23 | 24 | - uses: "marvinpinto/action-automatic-releases@v1.2.1" 25 | with: 26 | repo_token: "${{ secrets.GITHUB_TOKEN }}" 27 | prerelease: false 28 | files: | 29 | *.tar.gz 30 | -------------------------------------------------------------------------------- /lib/xdp-tools/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.exp 13 | *.ll 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | config.mk 55 | xdp-dispatcher.c 56 | 57 | *.man 58 | *.rpm 59 | 60 | /xdp-tools-*.tar.gz 61 | 62 | .ccls-cache 63 | .clangd 64 | .cache 65 | compile_commands.json 66 | 67 | # BPF skeleton files 68 | *.skel.h 69 | -------------------------------------------------------------------------------- /lib/xdp-tools/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libbpf"] 2 | path = lib/libbpf 3 | url = https://github.com/libbpf/libbpf.git 4 | ignore = untracked 5 | -------------------------------------------------------------------------------- /lib/xdp-tools/.lgtm.yml: -------------------------------------------------------------------------------- 1 | extraction: 2 | cpp: 3 | after_prepare: 4 | - export RELAXED_LLVM_VERSION=1 5 | path_classifiers: 6 | library: 7 | - lib/libbpf/*/* 8 | - lib/libbpf/* 9 | -------------------------------------------------------------------------------- /lib/xdp-tools/LICENSE: -------------------------------------------------------------------------------- 1 | The code in this repository is licensed by a mix of GPL-2.0, LGPL-2.1 and 2 | BSD-2-Clause licenses, as indicated by the SPDX license headers in individual 3 | source files. The full text of these licenses is available in the files in the 4 | LICENSES subdirectory. 5 | -------------------------------------------------------------------------------- /lib/xdp-tools/LICENSES/BSD-2-Clause: -------------------------------------------------------------------------------- 1 | Valid-License-Identifier: BSD-2-Clause 2 | SPDX-URL: https://spdx.org/licenses/BSD-2-Clause.html 3 | Usage-Guide: 4 | To use the BSD 2-clause "Simplified" License put the following SPDX 5 | tag/value pair into a comment according to the placement guidelines in 6 | the licensing rules documentation: 7 | SPDX-License-Identifier: BSD-2-Clause 8 | License-Text: 9 | 10 | Copyright (c) . All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | 18 | 2. Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /lib/xdp-tools/README.org: -------------------------------------------------------------------------------- 1 | * xdp-tools - Library and utilities for use with XDP 2 | 3 | This repository contains the =libxdp= library for working with the eXpress Data 4 | Path facility of the Linux kernel, and a collection of utilities and example 5 | code that uses the library. 6 | 7 | The repository contains the following: 8 | 9 | - [[lib/libxdp/][lib/libxdp/]] - the =libxdp= library itself - can be built standalone using =make libxdp= 10 | - [[xdp-loader/][xdp-loader/]] - a command-line utility for loading XDP programs using =libxdp= 11 | - [[xdp-filter/][xdp-filter/]] - a simple packet filtering utility powered by XDP 12 | - [[xdp-dump/][xdp-dump/]] - a tcpdump-like tool for capturing packets at the XDP layer 13 | - [[xdp-monitor/][xdp-monitor/]] - a simple XDP tracepoint monitoring tool 14 | - [[xdp-bench/][xdp-bench/]] - an XDP benchmarking tool 15 | - [[xdp-trafficgen/][xdp-trafficgen/]] - an XDP-based packet generator 16 | - [[headers/xdp/][headers/xdp/]] - reusable eBPF code snippets for XDP (installed in /usr/include/xdp by =make install=). 17 | - [[lib/util/][lib/util/]] - common code shared between the different utilities 18 | - [[packaging/][packaging/]] - files used for distro packaging 19 | - lib/libbpf/ - a git submodule with [[https://github.com/libbpf/libbpf][libbpf]], used if the system version is not recent enough 20 | 21 | To compile, first run =./configure=, then simply type =make=. Make sure you 22 | either have a sufficiently recent libbpf installed on your system, or that you 23 | pulled down the libbpf git submodule (=git submodule init && git submodule 24 | update=). 25 | 26 | For a general introduction to XDP, please see the [[https://github.com/xdp-project/xdp-tutorial][XDP tutorial]], and for more BPF 27 | and XDP examples, see the [[https://github.com/xdp-project/bpf-examples][bpf-examples repository]]. 28 | 29 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/bpf/vmlinux.h: -------------------------------------------------------------------------------- 1 | #ifndef __VMLINUX_H__ 2 | #define __VMLINUX_H__ 3 | 4 | #ifndef BPF_NO_PRESERVE_ACCESS_INDEX 5 | #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record) 6 | #endif 7 | 8 | struct net_device { 9 | int ifindex; 10 | }; 11 | 12 | struct xdp_cpumap_stats { 13 | unsigned int redirect; 14 | unsigned int pass; 15 | unsigned int drop; 16 | }; 17 | 18 | struct bpf_prog { 19 | }; 20 | 21 | struct bpf_map { 22 | }; 23 | 24 | #ifndef BPF_NO_PRESERVE_ACCESS_INDEX 25 | #pragma clang attribute pop 26 | #endif 27 | 28 | #endif /* __VMLINUX_H__ */ 29 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/linux/compiler-gcc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | #ifndef _TOOLS_LINUX_COMPILER_H_ 3 | #error "Please don't include directly, include instead." 4 | #endif 5 | 6 | /* 7 | * Common definitions for all gcc versions go here. 8 | */ 9 | #ifndef GCC_VERSION 10 | #define GCC_VERSION (__GNUC__ * 10000 \ 11 | + __GNUC_MINOR__ * 100 \ 12 | + __GNUC_PATCHLEVEL__) 13 | #endif 14 | 15 | #if GCC_VERSION >= 70000 && !defined(__CHECKER__) 16 | # define __fallthrough __attribute__ ((fallthrough)) 17 | #endif 18 | 19 | #if __has_attribute(__error__) 20 | # define __compiletime_error(message) __attribute__((error(message))) 21 | #endif 22 | 23 | /* &a[0] degrades to a pointer: a different type from an array */ 24 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) 25 | 26 | #ifndef __pure 27 | #define __pure __attribute__((pure)) 28 | #endif 29 | #define noinline __attribute__((noinline)) 30 | #ifndef __packed 31 | #define __packed __attribute__((packed)) 32 | #endif 33 | #ifndef __noreturn 34 | #define __noreturn __attribute__((noreturn)) 35 | #endif 36 | #ifndef __aligned 37 | #define __aligned(x) __attribute__((aligned(x))) 38 | #endif 39 | #define __printf(a, b) __attribute__((format(printf, a, b))) 40 | #define __scanf(a, b) __attribute__((format(scanf, a, b))) 41 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/linux/compiler_types.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | #ifndef __LINUX_COMPILER_TYPES_H 3 | #define __LINUX_COMPILER_TYPES_H 4 | 5 | /* Builtins */ 6 | 7 | /* 8 | * __has_builtin is supported on gcc >= 10, clang >= 3 and icc >= 21. 9 | * In the meantime, to support gcc < 10, we implement __has_builtin 10 | * by hand. 11 | */ 12 | #ifndef __has_builtin 13 | #define __has_builtin(x) (0) 14 | #endif 15 | 16 | #ifdef __CHECKER__ 17 | /* context/locking */ 18 | # define __must_hold(x) __attribute__((context(x,1,1))) 19 | # define __acquires(x) __attribute__((context(x,0,1))) 20 | # define __releases(x) __attribute__((context(x,1,0))) 21 | # define __acquire(x) __context__(x,1) 22 | # define __release(x) __context__(x,-1) 23 | # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) 24 | #else /* __CHECKER__ */ 25 | /* context/locking */ 26 | # define __must_hold(x) 27 | # define __acquires(x) 28 | # define __releases(x) 29 | # define __acquire(x) (void)0 30 | # define __release(x) (void)0 31 | # define __cond_lock(x,c) (c) 32 | #endif /* __CHECKER__ */ 33 | 34 | /* Compiler specific macros. */ 35 | #ifdef __GNUC__ 36 | #include 37 | #endif 38 | 39 | #endif /* __LINUX_COMPILER_TYPES_H */ 40 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/linux/err.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_ERR_H 4 | #define __LINUX_ERR_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define MAX_ERRNO 4095 11 | 12 | #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO) 13 | 14 | static inline void * ERR_PTR(long error_) 15 | { 16 | return (void *) error_; 17 | } 18 | 19 | static inline long PTR_ERR(const void *ptr) 20 | { 21 | return (long) ptr; 22 | } 23 | 24 | static inline bool IS_ERR(const void *ptr) 25 | { 26 | return IS_ERR_VALUE((unsigned long)ptr); 27 | } 28 | 29 | static inline bool IS_ERR_OR_NULL(const void *ptr) 30 | { 31 | return (!ptr) || IS_ERR_VALUE((unsigned long)ptr); 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/linux/if.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 2 | /* Truncated header from the kernel sources that just defines the name sizes 3 | * below; used by icmp.h */ 4 | #ifndef _LINUX_IF_H 5 | #define _LINUX_IF_H 6 | 7 | #define IFNAMSIZ 16 8 | #define IFALIASZ 256 9 | #define ALTIFNAMSIZ 128 10 | 11 | #endif /* _LINUX_IF_H */ 12 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/linux/perf-sys.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copied from $(LINUX)/tools/perf/perf-sys.h (kernel 4.18) */ 3 | #ifndef _PERF_SYS_H 4 | #define _PERF_SYS_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | /* 12 | * remove the following headers to allow for userspace program compilation 13 | * #include 14 | * #include 15 | */ 16 | #ifdef __powerpc__ 17 | #define CPUINFO_PROC {"cpu"} 18 | #endif 19 | 20 | #ifdef __s390__ 21 | #define CPUINFO_PROC {"vendor_id"} 22 | #endif 23 | 24 | #ifdef __sh__ 25 | #define CPUINFO_PROC {"cpu type"} 26 | #endif 27 | 28 | #ifdef __hppa__ 29 | #define CPUINFO_PROC {"cpu"} 30 | #endif 31 | 32 | #ifdef __sparc__ 33 | #define CPUINFO_PROC {"cpu"} 34 | #endif 35 | 36 | #ifdef __alpha__ 37 | #define CPUINFO_PROC {"cpu model"} 38 | #endif 39 | 40 | #ifdef __arm__ 41 | #define CPUINFO_PROC {"model name", "Processor"} 42 | #endif 43 | 44 | #ifdef __mips__ 45 | #define CPUINFO_PROC {"cpu model"} 46 | #endif 47 | 48 | #ifdef __arc__ 49 | #define CPUINFO_PROC {"Processor"} 50 | #endif 51 | 52 | #ifdef __xtensa__ 53 | #define CPUINFO_PROC {"core ID"} 54 | #endif 55 | 56 | #ifndef CPUINFO_PROC 57 | #define CPUINFO_PROC { "model name", } 58 | #endif 59 | 60 | static inline int 61 | sys_perf_event_open(struct perf_event_attr *attr, 62 | pid_t pid, int cpu, int group_fd, 63 | unsigned long flags) 64 | { 65 | int fd; 66 | 67 | fd = syscall(__NR_perf_event_open, attr, pid, cpu, 68 | group_fd, flags); 69 | 70 | #ifdef HAVE_ATTR_TEST 71 | if (unlikely(test_attr__enabled)) 72 | test_attr__open(attr, pid, cpu, fd, group_fd, flags); 73 | #endif 74 | return fd; 75 | } 76 | 77 | #endif /* _PERF_SYS_H */ 78 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/xdp/prog_dispatcher.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-clause) */ 2 | 3 | #ifndef __PROG_DISPATCHER_H 4 | #define __PROG_DISPATCHER_H 5 | 6 | #include 7 | 8 | #define XDP_METADATA_SECTION "xdp_metadata" 9 | #define XDP_DISPATCHER_VERSION 2 10 | 11 | /* magic byte is 'X' + 'D' + 'P' (88+68+80=236) */ 12 | #define XDP_DISPATCHER_MAGIC 236 13 | /* default retval for dispatcher corresponds to the highest bit in the 14 | * chain_call_actions bitmap; we use this to make sure the dispatcher always 15 | * continues the calls chain if a function does not have an freplace program 16 | * attached. 17 | */ 18 | #define XDP_DISPATCHER_RETVAL 31 19 | 20 | #ifndef MAX_DISPATCHER_ACTIONS 21 | #define MAX_DISPATCHER_ACTIONS 10 22 | #endif 23 | 24 | struct xdp_dispatcher_config { 25 | __u8 magic; /* Set to XDP_DISPATCHER_MAGIC */ 26 | __u8 dispatcher_version; /* Set to XDP_DISPATCHER_VERSION */ 27 | __u8 num_progs_enabled; /* Number of active program slots */ 28 | __u8 is_xdp_frags; /* Whether this dispatcher is loaded with XDP frags support */ 29 | __u32 chain_call_actions[MAX_DISPATCHER_ACTIONS]; 30 | __u32 run_prios[MAX_DISPATCHER_ACTIONS]; 31 | __u32 program_flags[MAX_DISPATCHER_ACTIONS]; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/xdp/xdp_helpers.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-clause) */ 2 | 3 | #ifndef __XDP_HELPERS_H 4 | #define __XDP_HELPERS_H 5 | 6 | #define _CONCAT(x,y) x ## y 7 | #define XDP_RUN_CONFIG(f) _CONCAT(_,f) SEC(".xdp_run_config") 8 | 9 | #define XDP_DEFAULT_RUN_PRIO 50 10 | #define XDP_DEFAULT_CHAIN_CALL_ACTIONS (1< 6 | 7 | struct datarec { 8 | size_t processed; 9 | size_t dropped; 10 | size_t issue; 11 | union { 12 | size_t xdp_pass; 13 | size_t info; 14 | }; 15 | size_t xdp_drop; 16 | size_t xdp_redirect; 17 | } __attribute__((aligned(64))); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/xdp/xdp_stats_kern.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | /* Used *ONLY* by BPF-prog running kernel side. */ 4 | #ifndef __XDP_STATS_KERN_H 5 | #define __XDP_STATS_KERN_H 6 | 7 | /* Data record type 'struct datarec' is defined in common/xdp_stats_kern_user.h, 8 | * programs using this header must first include that file. 9 | */ 10 | #ifndef __XDP_STATS_KERN_USER_H 11 | #warning "You forgot to #include <../common/xdp_stats_kern_user.h>" 12 | #include <../common/xdp_stats_kern_user.h> 13 | #endif 14 | 15 | #ifndef XDP_STATS_MAP_PINNING 16 | #define XDP_STATS_MAP_PINNING LIBBPF_PIN_BY_NAME 17 | #endif 18 | 19 | /* Keeps stats per (enum) xdp_action */ 20 | struct { 21 | __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); 22 | __uint(max_entries, XDP_ACTION_MAX); 23 | __type(key, __u32); 24 | __type(value, struct xdp_stats_record); 25 | __uint(pinning, LIBBPF_PIN_BY_NAME); 26 | } XDP_STATS_MAP_NAME SEC(".maps"); 27 | 28 | 29 | static __always_inline 30 | __u32 xdp_stats_record_action(struct xdp_md *ctx, __u32 action) 31 | { 32 | if (action >= XDP_ACTION_MAX) 33 | return XDP_ABORTED; 34 | 35 | /* Lookup in kernel BPF-side return pointer to actual data record */ 36 | struct xdp_stats_record *rec = bpf_map_lookup_elem(&xdp_stats_map, &action); 37 | if (!rec) 38 | return XDP_ABORTED; 39 | 40 | /* BPF_MAP_TYPE_PERCPU_ARRAY returns a data record specific to current 41 | * CPU and XDP hooks runs under Softirq, which makes it safe to update 42 | * without atomic operations. 43 | */ 44 | rec->rx_packets++; 45 | rec->rx_bytes += (ctx->data_end - ctx->data); 46 | 47 | return action; 48 | } 49 | 50 | #endif /* __XDP_STATS_KERN_H */ 51 | -------------------------------------------------------------------------------- /lib/xdp-tools/headers/xdp/xdp_stats_kern_user.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | /* Used by BPF-prog kernel side BPF-progs and userspace programs, 4 | * for sharing xdp_stats common struct and DEFINEs. 5 | */ 6 | #ifndef __XDP_STATS_KERN_USER_H 7 | #define __XDP_STATS_KERN_USER_H 8 | 9 | /* This is the data record stored in the map */ 10 | struct xdp_stats_record { 11 | union { 12 | __u64 packets; 13 | __u64 rx_packets; 14 | }; 15 | union { 16 | __u64 bytes; 17 | __u64 rx_bytes; 18 | }; 19 | }; 20 | 21 | #ifndef XDP_ACTION_MAX 22 | #define XDP_ACTION_MAX (XDP_REDIRECT + 1) 23 | #endif 24 | 25 | #define XDP_STATS_MAP_NAME xdp_stats_map 26 | 27 | #endif /* __XDP_STATS_KERN_USER_H */ 28 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/Makefile: -------------------------------------------------------------------------------- 1 | 2 | LIBBPF_CFLAGS:=$(if $(CFLAGS),$(CFLAGS),-g -O2 -Werror -Wall) -fPIC 3 | 4 | LIB_DIR = . 5 | include defines.mk 6 | 7 | SUBDIRS=util testing 8 | .PHONY: $(SUBDIRS) 9 | 10 | all: $(SUBDIRS) libxdp 11 | 12 | util: libxdp 13 | @echo; echo " $@"; $(MAKE) -C $@ 14 | 15 | testing: libxdp util 16 | @echo; echo " $@"; $(MAKE) -C $@ 17 | 18 | .PHONY: libxdp 19 | libxdp: $(OBJECT_LIBBPF) 20 | @echo; echo " $@"; $(MAKE) -C $@ 21 | 22 | .PHONY: clean 23 | clean: libbpf_clean 24 | @for i in $(SUBDIRS) libxdp; \ 25 | do $(MAKE) -C $$i clean; done 26 | 27 | .PHONY: install 28 | install: libxdp_install 29 | $(MAKE) -C testing install 30 | 31 | .PHONY: libxdp_install 32 | libxdp_install: libxdp 33 | install -m 0755 -d $(DESTDIR)$(HDRDIR) 34 | $(MAKE) -C libxdp install 35 | 36 | libbpf: $(OBJECT_LIBBPF) 37 | 38 | # Handle libbpf as git submodule 39 | ifeq ($(SYSTEM_LIBBPF),n) 40 | ifeq ($(VERBOSE),0) 41 | P:= >/dev/null 42 | endif 43 | 44 | # Detect submodule libbpf source file changes 45 | LIBBPF_SOURCES := $(wildcard libbpf/src/*.[ch]) 46 | 47 | .PHONY: libbpf_clean 48 | libbpf/src/libbpf.a: $(LIBBPF_SOURCES) 49 | @echo ; echo " libbpf" 50 | $(QUIET_CC)$(MAKE) -C libbpf/src CFLAGS="$(LIBBPF_CFLAGS)" $P 51 | $(QUIET_INSTALL)$(MAKE) -C libbpf/src install_headers DESTDIR=root $P 52 | 53 | libbpf_clean: 54 | $(Q)$(MAKE) -C libbpf/src clean $P 55 | 56 | else 57 | 58 | libbpf_clean: 59 | @echo -n 60 | endif 61 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/README.org: -------------------------------------------------------------------------------- 1 | * Library files 2 | 3 | This directory contains common Makefile definitions, and common code used by the 4 | different utilities. The libbpf subdir is a git submodule linking to the 5 | upstream libbpf github repository. 6 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/defines.mk: -------------------------------------------------------------------------------- 1 | CFLAGS ?= -O2 -g 2 | BPF_CFLAGS ?= -Wno-visibility -fno-stack-protector 3 | BPF_TARGET ?= bpf 4 | 5 | HAVE_FEATURES := 6 | 7 | include $(LIB_DIR)/../config.mk 8 | include $(LIB_DIR)/../version.mk 9 | 10 | PREFIX?=/usr/local 11 | LIBDIR?=$(PREFIX)/lib 12 | SBINDIR?=$(PREFIX)/sbin 13 | HDRDIR?=$(PREFIX)/include/xdp 14 | DATADIR?=$(PREFIX)/share 15 | RUNDIR?=/run 16 | MANDIR?=$(DATADIR)/man 17 | SCRIPTSDIR?=$(DATADIR)/xdp-tools 18 | BPF_DIR_MNT ?=/sys/fs/bpf 19 | BPF_OBJECT_DIR ?=$(LIBDIR)/bpf 20 | MAX_DISPATCHER_ACTIONS ?=10 21 | 22 | HEADER_DIR = $(LIB_DIR)/../headers 23 | TEST_DIR = $(LIB_DIR)/testing 24 | LIBXDP_DIR := $(LIB_DIR)/libxdp 25 | LIBBPF_DIR := $(LIB_DIR)/libbpf 26 | 27 | DEFINES := -DBPF_DIR_MNT=\"$(BPF_DIR_MNT)\" -DBPF_OBJECT_PATH=\"$(BPF_OBJECT_DIR)\" \ 28 | -DMAX_DISPATCHER_ACTIONS=$(MAX_DISPATCHER_ACTIONS) -DTOOLS_VERSION=\"$(TOOLS_VERSION)\" \ 29 | -DLIBBPF_VERSION=\"$(LIBBPF_VERSION)\" -DRUNDIR=\"$(RUNDIR)\" 30 | 31 | DEFINES += $(foreach feat,$(HAVE_FEATURES),-DHAVE_$(feat)) 32 | 33 | ifneq ($(PRODUCTION),1) 34 | DEFINES += -DDEBUG 35 | endif 36 | 37 | ifeq ($(SYSTEM_LIBBPF),y) 38 | DEFINES += -DLIBBPF_DYNAMIC 39 | endif 40 | 41 | DEFINES += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 42 | 43 | CFLAGS += -std=gnu11 -Wextra -Werror $(DEFINES) 44 | BPF_CFLAGS += $(DEFINES) $(filter -ffile-prefix-map=%,$(CFLAGS)) 45 | 46 | CONFIGMK := $(LIB_DIR)/../config.mk 47 | LIBMK := Makefile $(CONFIGMK) $(LIB_DIR)/defines.mk $(LIB_DIR)/common.mk $(LIB_DIR)/../version.mk 48 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.gitattributes: -------------------------------------------------------------------------------- 1 | assets/** export-ignore 2 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for considering a contribution! 2 | 3 | Please note that the `libbpf` authoritative source code is developed as part of bpf-next Linux source tree under tools/lib/bpf subdirectory and is periodically synced to Github. As such, all the libbpf changes should be sent to BPF mailing list, please don't open PRs here unless you are changing Github-specific parts of libbpf (e.g., Github-specific Makefile). 4 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/actions/build-selftests/action.yml: -------------------------------------------------------------------------------- 1 | name: 'build-selftests' 2 | description: 'Build BPF selftests' 3 | inputs: 4 | repo-path: 5 | description: 'where is the source code' 6 | required: true 7 | kernel: 8 | description: 'kernel version or LATEST' 9 | required: true 10 | default: 'LATEST' 11 | vmlinux: 12 | description: 'where is vmlinux file' 13 | required: true 14 | default: '${{ github.workspace }}/vmlinux' 15 | 16 | runs: 17 | using: "composite" 18 | steps: 19 | - shell: bash 20 | run: | 21 | source $GITHUB_ACTION_PATH/../../../ci/vmtest/helpers.sh 22 | foldable start "Setup Env" 23 | sudo apt-get install -y qemu-kvm zstd binutils-dev elfutils libcap-dev libelf-dev libdw-dev python3-docutils 24 | foldable end 25 | - shell: bash 26 | run: | 27 | export KERNEL=${{ inputs.kernel }} 28 | export REPO_ROOT="${{ github.workspace }}" 29 | export REPO_PATH="${{ inputs.repo-path }}" 30 | export VMLINUX_BTF="${{ inputs.vmlinux }}" 31 | ${{ github.action_path }}/build_selftests.sh 32 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/actions/build-selftests/build_selftests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | THISDIR="$(cd $(dirname $0) && pwd)" 6 | 7 | source ${THISDIR}/helpers.sh 8 | 9 | foldable start prepare_selftests "Building selftests" 10 | 11 | LIBBPF_PATH="${REPO_ROOT}" 12 | 13 | llvm_default_version() { 14 | echo "16" 15 | } 16 | 17 | llvm_latest_version() { 18 | echo "17" 19 | } 20 | 21 | LLVM_VERSION=$(llvm_default_version) 22 | if [[ "${LLVM_VERSION}" == $(llvm_latest_version) ]]; then 23 | REPO_DISTRO_SUFFIX="" 24 | else 25 | REPO_DISTRO_SUFFIX="-${LLVM_VERSION}" 26 | fi 27 | 28 | echo "deb https://apt.llvm.org/focal/ llvm-toolchain-focal${REPO_DISTRO_SUFFIX} main" \ 29 | | sudo tee /etc/apt/sources.list.d/llvm.list 30 | 31 | PREPARE_SELFTESTS_SCRIPT=${THISDIR}/prepare_selftests-${KERNEL}.sh 32 | if [ -f "${PREPARE_SELFTESTS_SCRIPT}" ]; then 33 | (cd "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" && ${PREPARE_SELFTESTS_SCRIPT}) 34 | fi 35 | 36 | if [[ "${KERNEL}" = 'LATEST' ]]; then 37 | VMLINUX_H= 38 | else 39 | VMLINUX_H=${THISDIR}/vmlinux.h 40 | fi 41 | 42 | cd ${REPO_ROOT}/${REPO_PATH} 43 | make headers 44 | make \ 45 | CLANG=clang-${LLVM_VERSION} \ 46 | LLC=llc-${LLVM_VERSION} \ 47 | LLVM_STRIP=llvm-strip-${LLVM_VERSION} \ 48 | VMLINUX_BTF="${VMLINUX_BTF}" \ 49 | VMLINUX_H=${VMLINUX_H} \ 50 | -C "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" \ 51 | -j $((4*$(nproc))) > /dev/null 52 | cd - 53 | mkdir ${LIBBPF_PATH}/selftests 54 | cp -R "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" \ 55 | ${LIBBPF_PATH}/selftests 56 | cd ${LIBBPF_PATH} 57 | rm selftests/bpf/.gitignore 58 | git add selftests 59 | 60 | foldable end prepare_selftests 61 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/actions/build-selftests/helpers.sh: -------------------------------------------------------------------------------- 1 | # shellcheck shell=bash 2 | 3 | # $1 - start or end 4 | # $2 - fold identifier, no spaces 5 | # $3 - fold section description 6 | foldable() { 7 | local YELLOW='\033[1;33m' 8 | local NOCOLOR='\033[0m' 9 | if [ $1 = "start" ]; then 10 | line="::group::$2" 11 | if [ ! -z "${3:-}" ]; then 12 | line="$line - ${YELLOW}$3${NOCOLOR}" 13 | fi 14 | else 15 | line="::endgroup::" 16 | fi 17 | echo -e "$line" 18 | } 19 | 20 | __print() { 21 | local TITLE="" 22 | if [[ -n $2 ]]; then 23 | TITLE=" title=$2" 24 | fi 25 | echo "::$1${TITLE}::$3" 26 | } 27 | 28 | # $1 - title 29 | # $2 - message 30 | print_error() { 31 | __print error $1 $2 32 | } 33 | 34 | # $1 - title 35 | # $2 - message 36 | print_notice() { 37 | __print notice $1 $2 38 | } 39 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/actions/build-selftests/prepare_selftests-4.9.0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | printf "all:\n\ttouch bpf_testmod.ko\n\nclean:\n" > bpf_testmod/Makefile 4 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/actions/build-selftests/prepare_selftests-5.5.0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | printf "all:\n\ttouch bpf_testmod.ko\n\nclean:\n" > bpf_testmod/Makefile 4 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/actions/debian/action.yml: -------------------------------------------------------------------------------- 1 | name: 'debian' 2 | description: 'Build' 3 | inputs: 4 | target: 5 | description: 'Run target' 6 | required: true 7 | runs: 8 | using: "composite" 9 | steps: 10 | - run: | 11 | source /tmp/ci_setup 12 | bash -x $CI_ROOT/managers/debian.sh SETUP 13 | bash -x $CI_ROOT/managers/debian.sh ${{ inputs.target }} 14 | bash -x $CI_ROOT/managers/debian.sh CLEANUP 15 | shell: bash 16 | 17 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/actions/setup/action.yml: -------------------------------------------------------------------------------- 1 | name: 'setup' 2 | description: 'setup env, create /tmp/ci_setup' 3 | runs: 4 | using: "composite" 5 | steps: 6 | - id: variables 7 | run: | 8 | export REPO_ROOT=$GITHUB_WORKSPACE 9 | export CI_ROOT=$REPO_ROOT/ci 10 | # this is somewhat ugly, but that is the easiest way to share this code with 11 | # arch specific docker 12 | echo 'echo ::group::Env setup' > /tmp/ci_setup 13 | echo export DEBIAN_FRONTEND=noninteractive >> /tmp/ci_setup 14 | echo sudo apt-get update >> /tmp/ci_setup 15 | echo sudo apt-get install -y aptitude qemu-kvm zstd binutils-dev elfutils libcap-dev libelf-dev libdw-dev libguestfs-tools >> /tmp/ci_setup 16 | echo export PROJECT_NAME='libbpf' >> /tmp/ci_setup 17 | echo export AUTHOR_EMAIL="$(git log -1 --pretty=\"%aE\")" >> /tmp/ci_setup 18 | echo export REPO_ROOT=$GITHUB_WORKSPACE >> /tmp/ci_setup 19 | echo export CI_ROOT=$REPO_ROOT/ci >> /tmp/ci_setup 20 | echo export VMTEST_ROOT=$CI_ROOT/vmtest >> /tmp/ci_setup 21 | echo 'echo ::endgroup::' >> /tmp/ci_setup 22 | shell: bash 23 | 24 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/workflows/cifuzz.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # https://google.github.io/oss-fuzz/getting-started/continuous-integration/ 3 | name: CIFuzz 4 | on: 5 | push: 6 | branches: 7 | - master 8 | pull_request: 9 | branches: 10 | - master 11 | jobs: 12 | Fuzzing: 13 | runs-on: ubuntu-latest 14 | if: github.repository == 'libbpf/libbpf' 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | sanitizer: [address, undefined, memory] 19 | steps: 20 | - name: Build Fuzzers (${{ matrix.sanitizer }}) 21 | id: build 22 | uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master 23 | with: 24 | oss-fuzz-project-name: 'libbpf' 25 | dry-run: false 26 | allowed-broken-targets-percentage: 0 27 | sanitizer: ${{ matrix.sanitizer }} 28 | - name: Run Fuzzers (${{ matrix.sanitizer }}) 29 | uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master 30 | with: 31 | oss-fuzz-project-name: 'libbpf' 32 | fuzz-seconds: 300 33 | dry-run: false 34 | sanitizer: ${{ matrix.sanitizer }} 35 | - name: Upload Crash 36 | uses: actions/upload-artifact@v1 37 | if: failure() && steps.build.outcome == 'success' 38 | with: 39 | name: ${{ matrix.sanitizer }}-artifacts 40 | path: ./out/artifacts 41 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vi: ts=2 sw=2 et: 3 | 4 | name: "CodeQL" 5 | 6 | on: 7 | push: 8 | branches: 9 | - master 10 | pull_request: 11 | branches: 12 | - master 13 | 14 | permissions: 15 | contents: read 16 | 17 | jobs: 18 | analyze: 19 | name: Analyze 20 | runs-on: ubuntu-22.04 21 | concurrency: 22 | group: ${{ github.workflow }}-${{ matrix.language }}-${{ github.ref }} 23 | cancel-in-progress: true 24 | permissions: 25 | actions: read 26 | security-events: write 27 | 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | language: ['cpp', 'python'] 32 | 33 | steps: 34 | - name: Checkout repository 35 | uses: actions/checkout@v3 36 | 37 | - name: Initialize CodeQL 38 | uses: github/codeql-action/init@v2 39 | with: 40 | languages: ${{ matrix.language }} 41 | queries: +security-extended,security-and-quality 42 | 43 | - name: Setup 44 | uses: ./.github/actions/setup 45 | 46 | - name: Build 47 | run: | 48 | source /tmp/ci_setup 49 | make -C ./src 50 | 51 | - name: Perform CodeQL Analysis 52 | uses: github/codeql-action/analyze@v2 53 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/workflows/coverity.yml: -------------------------------------------------------------------------------- 1 | name: libbpf-ci-coverity 2 | 3 | on: 4 | schedule: 5 | - cron: '0 18 * * *' 6 | 7 | 8 | jobs: 9 | coverity: 10 | runs-on: ubuntu-latest 11 | if: github.repository == 'libbpf/libbpf' 12 | name: Coverity 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: ./.github/actions/setup 16 | - name: Run coverity 17 | run: | 18 | source "${GITHUB_WORKSPACE}"/ci/vmtest/helpers.sh 19 | foldable start "Setup CI env" 20 | source /tmp/ci_setup 21 | export COVERITY_SCAN_NOTIFICATION_EMAIL="${AUTHOR_EMAIL}" 22 | export COVERITY_SCAN_BRANCH_PATTERN=${GITHUB_REF##refs/*/} 23 | export TRAVIS_BRANCH=${COVERITY_SCAN_BRANCH_PATTERN} 24 | foldable end 25 | scripts/coverity.sh 26 | env: 27 | COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} 28 | COVERITY_SCAN_PROJECT_NAME: libbpf 29 | COVERITY_SCAN_BUILD_COMMAND_PREPEND: 'cd src/' 30 | COVERITY_SCAN_BUILD_COMMAND: 'make' 31 | - name: SCM log 32 | run: cat /home/runner/work/libbpf/libbpf/src/cov-int/scm_log.txt 33 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: "lint" 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | 9 | jobs: 10 | shellcheck: 11 | name: ShellCheck 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v3 16 | - name: Run ShellCheck 17 | uses: ludeeus/action-shellcheck@master 18 | env: 19 | SHELLCHECK_OPTS: --severity=error 20 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/workflows/ondemand.yml: -------------------------------------------------------------------------------- 1 | name: ondemand 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | kernel-origin: 7 | description: 'git repo for linux kernel' 8 | default: 'https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git' 9 | required: true 10 | kernel-rev: 11 | description: 'rev/tag/branch for linux kernel' 12 | default: "master" 13 | required: true 14 | pahole-origin: 15 | description: 'git repo for pahole' 16 | default: 'https://git.kernel.org/pub/scm/devel/pahole/pahole.git' 17 | required: true 18 | pahole-rev: 19 | description: 'ref/tag/branch for pahole' 20 | default: "master" 21 | required: true 22 | 23 | jobs: 24 | vmtest: 25 | runs-on: ubuntu-latest 26 | name: vmtest with customized pahole/Kernel 27 | steps: 28 | - uses: actions/checkout@v3 29 | - uses: ./.github/actions/setup 30 | - uses: ./.github/actions/vmtest 31 | with: 32 | kernel: 'LATEST' 33 | kernel-rev: ${{ github.event.inputs.kernel-rev }} 34 | kernel-origin: ${{ github.event.inputs.kernel-origin }} 35 | pahole: ${{ github.event.inputs.pahole-rev }} 36 | pahole-origin: ${{ github.event.inputs.pahole-origin }} 37 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/workflows/pahole.yml: -------------------------------------------------------------------------------- 1 | name: pahole-staging 2 | 3 | on: 4 | schedule: 5 | - cron: '0 18 * * *' 6 | 7 | 8 | jobs: 9 | vmtest: 10 | runs-on: ubuntu-20.04 11 | name: Kernel LATEST + staging pahole 12 | env: 13 | STAGING: tmp.master 14 | steps: 15 | - uses: actions/checkout@v3 16 | - uses: ./.github/actions/setup 17 | - uses: ./.github/actions/vmtest 18 | with: 19 | kernel: LATEST 20 | pahole: $STAGING 21 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: libbpf-ci 2 | 3 | on: 4 | pull_request: 5 | push: 6 | schedule: 7 | - cron: '0 18 * * *' 8 | 9 | concurrency: 10 | group: ci-test-${{ github.head_ref }} 11 | cancel-in-progress: true 12 | 13 | jobs: 14 | vmtest: 15 | runs-on: ${{ matrix.runs_on }} 16 | name: Kernel ${{ matrix.kernel }} on ${{ matrix.runs_on }} + selftests 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | include: 21 | - kernel: 'LATEST' 22 | runs_on: ubuntu-20.04 23 | arch: 'x86_64' 24 | - kernel: '5.5.0' 25 | runs_on: ubuntu-20.04 26 | arch: 'x86_64' 27 | - kernel: '4.9.0' 28 | runs_on: ubuntu-20.04 29 | arch: 'x86_64' 30 | - kernel: 'LATEST' 31 | runs_on: s390x 32 | arch: 's390x' 33 | steps: 34 | # Allow CI user to access /dev/kvm (via qemu) w/o group change/relogin 35 | # by changing permissions set by udev. 36 | - name: Set /dev/kvm permissions 37 | shell: bash 38 | run: | 39 | if [ -e /dev/kvm ]; then 40 | echo "/dev/kvm exists" 41 | if [ $(id -u) != 0 ]; then 42 | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \ 43 | | sudo tee /etc/udev/rules.d/99-kvm4all.rules > /dev/null 44 | sudo udevadm control --reload-rules 45 | sudo udevadm trigger --name-match=kvm 46 | fi 47 | else 48 | echo "/dev/kvm does not exist" 49 | fi 50 | - uses: actions/checkout@v3 51 | name: Checkout 52 | - uses: ./.github/actions/setup 53 | name: Setup 54 | - uses: ./.github/actions/vmtest 55 | name: vmtest 56 | with: 57 | kernel: ${{ matrix.kernel }} 58 | arch: ${{ matrix.arch }} 59 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | build: 9 | os: "ubuntu-22.04" 10 | tools: 11 | python: "3.11" 12 | 13 | # Build documentation in the docs/ directory with Sphinx 14 | sphinx: 15 | builder: html 16 | configuration: docs/conf.py 17 | 18 | formats: 19 | - htmlzip 20 | - pdf 21 | - epub 22 | 23 | # Optionally set the version of Python and requirements required to build your docs 24 | python: 25 | install: 26 | - requirements: docs/sphinx/requirements.txt 27 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/BPF-CHECKPOINT-COMMIT: -------------------------------------------------------------------------------- 1 | bc4fbf022c68967cb49b2b820b465cf90de974b8 2 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/CHECKPOINT-COMMIT: -------------------------------------------------------------------------------- 1 | 750011e239a50873251c16207b0fe78eabf8577e 2 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/LICENSE: -------------------------------------------------------------------------------- 1 | LGPL-2.1 OR BSD-2-Clause 2 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/LICENSE.BSD-2-Clause: -------------------------------------------------------------------------------- 1 | Valid-License-Identifier: BSD-2-Clause 2 | SPDX-URL: https://spdx.org/licenses/BSD-2-Clause.html 3 | Usage-Guide: 4 | To use the BSD 2-clause "Simplified" License put the following SPDX 5 | tag/value pair into a comment according to the placement guidelines in 6 | the licensing rules documentation: 7 | SPDX-License-Identifier: BSD-2-Clause 8 | License-Text: 9 | 10 | Copyright (c) 2015 The Libbpf Authors. All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | 18 | 2. Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/diffs/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eTran-NSDI25/eTran/f26ef186bde0f9b3b899712e44112de47b7d5a65/lib/xdp-tools/lib/libbpf/ci/diffs/.keep -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/managers/test_compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euox pipefail 3 | 4 | EXTRA_CFLAGS=${EXTRA_CFLAGS:-} 5 | EXTRA_LDFLAGS=${EXTRA_LDFLAGS:-} 6 | 7 | cat << EOF > main.c 8 | #include 9 | int main() { 10 | return bpf_object__open(0) < 0; 11 | } 12 | EOF 13 | 14 | # static linking 15 | ${CC:-cc} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o main -I./include/uapi -I./install/usr/include main.c ./build/libbpf.a -lelf -lz 16 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/managers/travis_wait.bash: -------------------------------------------------------------------------------- 1 | # This was borrowed from https://github.com/travis-ci/travis-build/tree/master/lib/travis/build/bash 2 | # to get around https://github.com/travis-ci/travis-ci/issues/9979. It should probably be removed 3 | # as soon as Travis CI has started to provide an easy way to export the functions to bash scripts. 4 | 5 | travis_jigger() { 6 | local cmd_pid="${1}" 7 | shift 8 | local timeout="${1}" 9 | shift 10 | local count=0 11 | 12 | echo -e "\\n" 13 | 14 | while [[ "${count}" -lt "${timeout}" ]]; do 15 | count="$((count + 1))" 16 | echo -ne "Still running (${count} of ${timeout}): ${*}\\r" 17 | sleep 60 18 | done 19 | 20 | echo -e "\\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"${*}\"${ANSI_RESET}\\n" 21 | kill -9 "${cmd_pid}" 22 | } 23 | 24 | travis_wait() { 25 | local timeout="${1}" 26 | 27 | if [[ "${timeout}" =~ ^[0-9]+$ ]]; then 28 | shift 29 | else 30 | timeout=20 31 | fi 32 | 33 | local cmd=("${@}") 34 | local log_file="travis_wait_${$}.log" 35 | 36 | "${cmd[@]}" &>"${log_file}" & 37 | local cmd_pid="${!}" 38 | 39 | travis_jigger "${!}" "${timeout}" "${cmd[@]}" & 40 | local jigger_pid="${!}" 41 | local result 42 | 43 | { 44 | set +e 45 | wait "${cmd_pid}" 2>/dev/null 46 | result="${?}" 47 | ps -p"${jigger_pid}" &>/dev/null && kill "${jigger_pid}" 48 | set -e 49 | } 50 | 51 | if [[ "${result}" -eq 0 ]]; then 52 | echo -e "\\n${ANSI_GREEN}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}" 53 | else 54 | echo -e "\\n${ANSI_RED}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}" 55 | fi 56 | 57 | echo -e "\\n${ANSI_GREEN}Log:${ANSI_RESET}\\n" 58 | cat "${log_file}" 59 | 60 | return "${result}" 61 | } 62 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/managers/ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eux 3 | 4 | RELEASE="focal" 5 | 6 | apt-get update 7 | apt-get install -y pkg-config 8 | 9 | source "$(dirname $0)/travis_wait.bash" 10 | 11 | cd $REPO_ROOT 12 | 13 | EXTRA_CFLAGS="-Werror -Wall -fsanitize=address,undefined" 14 | EXTRA_LDFLAGS="-Werror -Wall -fsanitize=address,undefined" 15 | mkdir build install 16 | cc --version 17 | make -j$((4*$(nproc))) EXTRA_CFLAGS="${EXTRA_CFLAGS}" EXTRA_LDFLAGS="${EXTRA_LDFLAGS}" -C ./src -B OBJDIR=../build 18 | ldd build/libbpf.so 19 | if ! ldd build/libbpf.so | grep -q libelf; then 20 | echo "FAIL: No reference to libelf.so in libbpf.so!" 21 | exit 1 22 | fi 23 | make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install 24 | EXTRA_CFLAGS=${EXTRA_CFLAGS} EXTRA_LDFLAGS=${EXTRA_LDFLAGS} $(dirname $0)/test_compile.sh 25 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/vmtest/configs/ALLOWLIST-4.9.0: -------------------------------------------------------------------------------- 1 | # btf_dump -- need to disable data dump sub-tests 2 | core_retro 3 | cpu_mask 4 | hashmap 5 | legacy_printk 6 | perf_buffer 7 | section_names 8 | 9 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/vmtest/configs/ALLOWLIST-5.5.0: -------------------------------------------------------------------------------- 1 | # attach_probe 2 | autoload 3 | bpf_verif_scale 4 | cgroup_attach_autodetach 5 | cgroup_attach_override 6 | core_autosize 7 | core_extern 8 | core_read_macros 9 | core_reloc 10 | core_retro 11 | cpu_mask 12 | endian 13 | get_branch_snapshot 14 | get_stackid_cannot_attach 15 | global_data 16 | global_data_init 17 | global_func_args 18 | hashmap 19 | legacy_printk 20 | linked_funcs 21 | linked_maps 22 | map_lock 23 | obj_name 24 | perf_buffer 25 | perf_event_stackmap 26 | pinning 27 | pkt_md_access 28 | probe_user 29 | queue_stack_map 30 | raw_tp_writable_reject_nbd_invalid 31 | raw_tp_writable_test_run 32 | rdonly_maps 33 | section_names 34 | signal_pending 35 | sockmap_ktls 36 | spinlock 37 | stacktrace_map 38 | stacktrace_map_raw_tp 39 | static_linked 40 | task_fd_query_rawtp 41 | task_fd_query_tp 42 | tc_bpf 43 | tcp_estats 44 | tcp_rtt 45 | tp_attach_query 46 | usdt/urand_pid_attach 47 | xdp 48 | xdp_noinline 49 | xdp_perf 50 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/vmtest/configs/DENYLIST-5.5.0: -------------------------------------------------------------------------------- 1 | # This complements ALLOWLIST-5.5.0 but excludes subtest that can't work on 5.5 2 | 3 | btf # "size check test", "func (Non zero vlen)" 4 | tailcalls # tailcall_bpf2bpf_1, tailcall_bpf2bpf_2, tailcall_bpf2bpf_3 5 | tc_bpf/tc_bpf_non_root 6 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/vmtest/configs/DENYLIST-latest: -------------------------------------------------------------------------------- 1 | decap_sanity # weird failure with decap_sanity_ns netns already existing, TBD 2 | empty_skb # waiting the fix in bpf tree to make it to bpf-next 3 | bpf_nf/tc-bpf-ct # test consistently failing on x86: https://github.com/libbpf/libbpf/pull/698#issuecomment-1590341200 4 | bpf_nf/xdp-ct # test consistently failing on x86: https://github.com/libbpf/libbpf/pull/698#issuecomment-1590341200 5 | kprobe_multi_bench_attach # suspected to cause crashes in CI 6 | find_vma # test consistently fails on latest kernel, see https://github.com/libbpf/libbpf/issues/754 for details 7 | bpf_cookie/perf_event 8 | send_signal/send_signal_nmi 9 | send_signal/send_signal_nmi_thread 10 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/vmtest/configs/DENYLIST-latest.s390x: -------------------------------------------------------------------------------- 1 | # TEMPORARY 2 | sockmap_listen/sockhash VSOCK test_vsock_redir 3 | usdt/basic # failing verifier due to bounds check after LLVM update 4 | usdt/multispec # same as above 5 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/ci/vmtest/helpers.sh: -------------------------------------------------------------------------------- 1 | # shellcheck shell=bash 2 | 3 | # $1 - start or end 4 | # $2 - fold identifier, no spaces 5 | # $3 - fold section description 6 | foldable() { 7 | local YELLOW='\033[1;33m' 8 | local NOCOLOR='\033[0m' 9 | if [ $1 = "start" ]; then 10 | line="::group::$2" 11 | if [ ! -z "${3:-}" ]; then 12 | line="$line - ${YELLOW}$3${NOCOLOR}" 13 | fi 14 | else 15 | line="::endgroup::" 16 | fi 17 | echo -e "$line" 18 | } 19 | 20 | __print() { 21 | local TITLE="" 22 | if [[ -n $2 ]]; then 23 | TITLE=" title=$2" 24 | fi 25 | echo "::$1${TITLE}::$3" 26 | } 27 | 28 | # $1 - title 29 | # $2 - message 30 | print_error() { 31 | __print error $1 $2 32 | } 33 | 34 | # $1 - title 35 | # $2 - message 36 | print_notice() { 37 | __print notice $1 $2 38 | } 39 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/docs/.gitignore: -------------------------------------------------------------------------------- 1 | sphinx/build 2 | sphinx/doxygen/build -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Configuration file for the Sphinx documentation builder. 4 | # 5 | # This file only contains a selection of the most common options. For a full 6 | # list see the documentation: 7 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 8 | 9 | import os 10 | import subprocess 11 | 12 | project = "libbpf" 13 | 14 | extensions = [ 15 | 'sphinx.ext.autodoc', 16 | 'sphinx.ext.doctest', 17 | 'sphinx.ext.mathjax', 18 | 'sphinx.ext.viewcode', 19 | 'sphinx.ext.imgmath', 20 | 'sphinx.ext.todo', 21 | 'sphinx_rtd_theme', 22 | 'breathe', 23 | ] 24 | 25 | # List of patterns, relative to source directory, that match files and 26 | # directories to ignore when looking for source files. 27 | # This pattern also affects html_static_path and html_extra_path. 28 | exclude_patterns = [] 29 | 30 | read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True' 31 | 32 | if read_the_docs_build: 33 | subprocess.call('cd sphinx ; make clean', shell=True) 34 | subprocess.call('cd sphinx/doxygen ; doxygen', shell=True) 35 | 36 | html_theme = 'sphinx_rtd_theme' 37 | 38 | breathe_projects = { "libbpf": "./sphinx/doxygen/build/xml/" } 39 | breathe_default_project = "libbpf" 40 | breathe_show_define_initializer = True 41 | breathe_show_enumvalue_initializer = True 42 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/docs/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 | 3 | .. _libbpf: 4 | 5 | ====== 6 | libbpf 7 | ====== 8 | 9 | If you are looking to develop BPF applications using the libbpf library, this 10 | directory contains important documentation that you should read. 11 | 12 | To get started, it is recommended to begin with the :doc:`libbpf Overview 13 | ` document, which provides a high-level understanding of the 14 | libbpf APIs and their usage. This will give you a solid foundation to start 15 | exploring and utilizing the various features of libbpf to develop your BPF 16 | applications. 17 | 18 | .. toctree:: 19 | :maxdepth: 1 20 | 21 | libbpf_overview 22 | API Documentation 23 | program_types 24 | libbpf_naming_convention 25 | libbpf_build 26 | 27 | 28 | All general BPF questions, including kernel functionality, libbpf APIs and their 29 | application, should be sent to bpf@vger.kernel.org mailing list. You can 30 | `subscribe `_ to the mailing list 31 | search its `archive `_. Please search the archive 32 | before asking new questions. It may be that this was already addressed or 33 | answered before. 34 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/docs/libbpf_build.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 | 3 | Building libbpf 4 | =============== 5 | 6 | libelf and zlib are internal dependencies of libbpf and thus are required to link 7 | against and must be installed on the system for applications to work. 8 | pkg-config is used by default to find libelf, and the program called 9 | can be overridden with PKG_CONFIG. 10 | 11 | If using pkg-config at build time is not desired, it can be disabled by 12 | setting NO_PKG_CONFIG=1 when calling make. 13 | 14 | To build both static libbpf.a and shared libbpf.so: 15 | 16 | .. code-block:: bash 17 | 18 | $ cd src 19 | $ make 20 | 21 | To build only static libbpf.a library in directory build/ and install them 22 | together with libbpf headers in a staging directory root/: 23 | 24 | .. code-block:: bash 25 | 26 | $ cd src 27 | $ mkdir build root 28 | $ BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=root make install 29 | 30 | To build both static libbpf.a and shared libbpf.so against a custom libelf 31 | dependency installed in /build/root/ and install them together with libbpf 32 | headers in a build directory /build/root/: 33 | 34 | .. code-block:: bash 35 | 36 | $ cd src 37 | $ PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/docs/sphinx/Makefile: -------------------------------------------------------------------------------- 1 | SPHINXBUILD ?= sphinx-build 2 | SOURCEDIR = ../src 3 | BUILDDIR = build 4 | 5 | help: 6 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" 7 | 8 | %: 9 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" 10 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/docs/sphinx/requirements.txt: -------------------------------------------------------------------------------- 1 | breathe 2 | sphinx_rtd_theme 3 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/fuzz/bpf-object-fuzzer.c: -------------------------------------------------------------------------------- 1 | #include "libbpf.h" 2 | 3 | static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args) 4 | { 5 | return 0; 6 | } 7 | 8 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 9 | struct bpf_object *obj = NULL; 10 | DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts); 11 | int err; 12 | 13 | libbpf_set_print(libbpf_print_fn); 14 | 15 | opts.object_name = "fuzz-object"; 16 | obj = bpf_object__open_mem(data, size, &opts); 17 | err = libbpf_get_error(obj); 18 | if (err) 19 | return 0; 20 | 21 | bpf_object__close(obj); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/fuzz/bpf-object-fuzzer_seed_corpus.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eTran-NSDI25/eTran/f26ef186bde0f9b3b899712e44112de47b7d5a65/lib/xdp-tools/lib/libbpf/fuzz/bpf-object-fuzzer_seed_corpus.zip -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/include/asm/barrier.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | #ifndef __ASM_BARRIER_H 3 | #define __ASM_BARRIER_H 4 | 5 | #include 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/include/linux/compiler.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_COMPILER_H 4 | #define __LINUX_COMPILER_H 5 | 6 | #define likely(x) __builtin_expect(!!(x), 1) 7 | #define unlikely(x) __builtin_expect(!!(x), 0) 8 | 9 | #define READ_ONCE(x) (*(volatile typeof(x) *)&x) 10 | #define WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v) 11 | 12 | #define barrier() asm volatile("" ::: "memory") 13 | 14 | #if defined(__x86_64__) 15 | 16 | # define smp_rmb() barrier() 17 | # define smp_wmb() barrier() 18 | # define smp_mb() asm volatile("lock; addl $0,-132(%%rsp)" ::: "memory", "cc") 19 | 20 | # define smp_store_release(p, v) \ 21 | do { \ 22 | barrier(); \ 23 | WRITE_ONCE(*p, v); \ 24 | } while (0) 25 | 26 | # define smp_load_acquire(p) \ 27 | ({ \ 28 | typeof(*p) ___p = READ_ONCE(*p); \ 29 | barrier(); \ 30 | ___p; \ 31 | }) 32 | 33 | #elif defined(__aarch64__) 34 | 35 | # define smp_rmb() asm volatile("dmb ishld" ::: "memory") 36 | # define smp_wmb() asm volatile("dmb ishst" ::: "memory") 37 | # define smp_mb() asm volatile("dmb ish" ::: "memory") 38 | 39 | #endif 40 | 41 | #ifndef smp_mb 42 | # define smp_mb() __sync_synchronize() 43 | #endif 44 | 45 | #ifndef smp_rmb 46 | # define smp_rmb() smp_mb() 47 | #endif 48 | 49 | #ifndef smp_wmb 50 | # define smp_wmb() smp_mb() 51 | #endif 52 | 53 | #ifndef smp_store_release 54 | # define smp_store_release(p, v) \ 55 | do { \ 56 | smp_mb(); \ 57 | WRITE_ONCE(*p, v); \ 58 | } while (0) 59 | #endif 60 | 61 | #ifndef smp_load_acquire 62 | # define smp_load_acquire(p) \ 63 | ({ \ 64 | typeof(*p) ___p = READ_ONCE(*p); \ 65 | smp_mb(); \ 66 | ___p; \ 67 | }) 68 | #endif 69 | 70 | #endif /* __LINUX_COMPILER_H */ 71 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/include/linux/err.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_ERR_H 4 | #define __LINUX_ERR_H 5 | 6 | #include 7 | #include 8 | 9 | #define MAX_ERRNO 4095 10 | 11 | #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO) 12 | 13 | static inline void * ERR_PTR(long error_) 14 | { 15 | return (void *) error_; 16 | } 17 | 18 | static inline long PTR_ERR(const void *ptr) 19 | { 20 | return (long) ptr; 21 | } 22 | 23 | static inline bool IS_ERR(const void *ptr) 24 | { 25 | return IS_ERR_VALUE((unsigned long)ptr); 26 | } 27 | 28 | static inline bool IS_ERR_OR_NULL(const void *ptr) 29 | { 30 | return (!ptr) || IS_ERR_VALUE((unsigned long)ptr); 31 | } 32 | 33 | static inline long PTR_ERR_OR_ZERO(const void *ptr) 34 | { 35 | return IS_ERR(ptr) ? PTR_ERR(ptr) : 0; 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/include/linux/kernel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_KERNEL_H 4 | #define __LINUX_KERNEL_H 5 | 6 | #ifndef offsetof 7 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 8 | #endif 9 | 10 | #ifndef container_of 11 | #define container_of(ptr, type, member) ({ \ 12 | const typeof(((type *)0)->member) * __mptr = (ptr); \ 13 | (type *)((char *)__mptr - offsetof(type, member)); }) 14 | #endif 15 | 16 | #ifndef max 17 | #define max(x, y) ({ \ 18 | typeof(x) _max1 = (x); \ 19 | typeof(y) _max2 = (y); \ 20 | (void) (&_max1 == &_max2); \ 21 | _max1 > _max2 ? _max1 : _max2; }) 22 | #endif 23 | 24 | #ifndef min 25 | #define min(x, y) ({ \ 26 | typeof(x) _min1 = (x); \ 27 | typeof(y) _min2 = (y); \ 28 | (void) (&_min1 == &_min2); \ 29 | _min1 < _min2 ? _min1 : _min2; }) 30 | #endif 31 | 32 | #ifndef roundup 33 | #define roundup(x, y) ( \ 34 | { \ 35 | const typeof(y) __y = y; \ 36 | (((x) + (__y - 1)) / __y) * __y; \ 37 | } \ 38 | ) 39 | #endif 40 | 41 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 42 | #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/include/linux/ring_buffer.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | #ifndef _TOOLS_LINUX_RING_BUFFER_H_ 3 | #define _TOOLS_LINUX_RING_BUFFER_H_ 4 | 5 | #include 6 | 7 | static inline __u64 ring_buffer_read_head(struct perf_event_mmap_page *base) 8 | { 9 | return smp_load_acquire(&base->data_head); 10 | } 11 | 12 | static inline void ring_buffer_write_tail(struct perf_event_mmap_page *base, 13 | __u64 tail) 14 | { 15 | smp_store_release(&base->data_tail, tail); 16 | } 17 | 18 | #endif /* _TOOLS_LINUX_RING_BUFFER_H_ */ 19 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/include/linux/types.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LINUX_TYPES_H 4 | #define __LINUX_TYPES_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #define __bitwise__ 16 | #define __bitwise __bitwise__ 17 | 18 | typedef __u16 __bitwise __le16; 19 | typedef __u16 __bitwise __be16; 20 | typedef __u32 __bitwise __le32; 21 | typedef __u32 __bitwise __be32; 22 | typedef __u64 __bitwise __le64; 23 | typedef __u64 __bitwise __be64; 24 | 25 | #ifndef __aligned_u64 26 | # define __aligned_u64 __u64 __attribute__((aligned(8))) 27 | #endif 28 | 29 | struct list_head { 30 | struct list_head *next, *prev; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/include/uapi/linux/bpf_common.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef _UAPI__LINUX_BPF_COMMON_H__ 3 | #define _UAPI__LINUX_BPF_COMMON_H__ 4 | 5 | /* Instruction classes */ 6 | #define BPF_CLASS(code) ((code) & 0x07) 7 | #define BPF_LD 0x00 8 | #define BPF_LDX 0x01 9 | #define BPF_ST 0x02 10 | #define BPF_STX 0x03 11 | #define BPF_ALU 0x04 12 | #define BPF_JMP 0x05 13 | #define BPF_RET 0x06 14 | #define BPF_MISC 0x07 15 | 16 | /* ld/ldx fields */ 17 | #define BPF_SIZE(code) ((code) & 0x18) 18 | #define BPF_W 0x00 /* 32-bit */ 19 | #define BPF_H 0x08 /* 16-bit */ 20 | #define BPF_B 0x10 /* 8-bit */ 21 | /* eBPF BPF_DW 0x18 64-bit */ 22 | #define BPF_MODE(code) ((code) & 0xe0) 23 | #define BPF_IMM 0x00 24 | #define BPF_ABS 0x20 25 | #define BPF_IND 0x40 26 | #define BPF_MEM 0x60 27 | #define BPF_LEN 0x80 28 | #define BPF_MSH 0xa0 29 | 30 | /* alu/jmp fields */ 31 | #define BPF_OP(code) ((code) & 0xf0) 32 | #define BPF_ADD 0x00 33 | #define BPF_SUB 0x10 34 | #define BPF_MUL 0x20 35 | #define BPF_DIV 0x30 36 | #define BPF_OR 0x40 37 | #define BPF_AND 0x50 38 | #define BPF_LSH 0x60 39 | #define BPF_RSH 0x70 40 | #define BPF_NEG 0x80 41 | #define BPF_MOD 0x90 42 | #define BPF_XOR 0xa0 43 | 44 | #define BPF_JA 0x00 45 | #define BPF_JEQ 0x10 46 | #define BPF_JGT 0x20 47 | #define BPF_JGE 0x30 48 | #define BPF_JSET 0x40 49 | #define BPF_SRC(code) ((code) & 0x08) 50 | #define BPF_K 0x00 51 | #define BPF_X 0x08 52 | 53 | #ifndef BPF_MAXINSNS 54 | #define BPF_MAXINSNS 4096 55 | #endif 56 | 57 | #endif /* _UAPI__LINUX_BPF_COMMON_H__ */ 58 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/include/uapi/linux/openat2.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef _UAPI_LINUX_OPENAT2_H 3 | #define _UAPI_LINUX_OPENAT2_H 4 | 5 | #include 6 | 7 | /* 8 | * Arguments for how openat2(2) should open the target path. If only @flags and 9 | * @mode are non-zero, then openat2(2) operates very similarly to openat(2). 10 | * 11 | * However, unlike openat(2), unknown or invalid bits in @flags result in 12 | * -EINVAL rather than being silently ignored. @mode must be zero unless one of 13 | * {O_CREAT, O_TMPFILE} are set. 14 | * 15 | * @flags: O_* flags. 16 | * @mode: O_CREAT/O_TMPFILE file mode. 17 | * @resolve: RESOLVE_* flags. 18 | */ 19 | struct open_how { 20 | __u64 flags; 21 | __u64 mode; 22 | __u64 resolve; 23 | }; 24 | 25 | /* how->resolve flags for openat2(2). */ 26 | #define RESOLVE_NO_XDEV 0x01 /* Block mount-point crossings 27 | (includes bind-mounts). */ 28 | #define RESOLVE_NO_MAGICLINKS 0x02 /* Block traversal through procfs-style 29 | "magic-links". */ 30 | #define RESOLVE_NO_SYMLINKS 0x04 /* Block traversal through all symlinks 31 | (implies OEXT_NO_MAGICLINKS) */ 32 | #define RESOLVE_BENEATH 0x08 /* Block "lexical" trickery like 33 | "..", symlinks, and absolute 34 | paths which escape the dirfd. */ 35 | #define RESOLVE_IN_ROOT 0x10 /* Make all jumps to "/" and ".." 36 | be scoped inside the dirfd 37 | (similar to chroot(2)). */ 38 | #define RESOLVE_CACHED 0x20 /* Only complete if resolution can be 39 | completed through cached lookup. May 40 | return -EAGAIN if that's not 41 | possible. */ 42 | 43 | #endif /* _UAPI_LINUX_OPENAT2_H */ 44 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | /libbpf.pc 4 | /libbpf.so* 5 | /staticobjs 6 | /sharedobjs 7 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/src/libbpf.pc.template: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 | 3 | prefix=@PREFIX@ 4 | libdir=@LIBDIR@ 5 | includedir=${prefix}/include 6 | 7 | Name: libbpf 8 | Description: BPF library 9 | Version: @VERSION@ 10 | Libs: -L${libdir} -lbpf 11 | Requires.private: libelf zlib 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/src/libbpf_version.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | /* Copyright (C) 2021 Facebook */ 3 | #ifndef __LIBBPF_VERSION_H 4 | #define __LIBBPF_VERSION_H 5 | 6 | #define LIBBPF_MAJOR_VERSION 1 7 | #define LIBBPF_MINOR_VERSION 3 8 | 9 | #endif /* __LIBBPF_VERSION_H */ 10 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/src/root/usr/include/bpf/libbpf_version.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | /* Copyright (C) 2021 Facebook */ 3 | #ifndef __LIBBPF_VERSION_H 4 | #define __LIBBPF_VERSION_H 5 | 6 | #define LIBBPF_MAJOR_VERSION 1 7 | #define LIBBPF_MINOR_VERSION 3 8 | 9 | #endif /* __LIBBPF_VERSION_H */ 10 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/src/str_error.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 | #undef _GNU_SOURCE 3 | #include 4 | #include 5 | #include "str_error.h" 6 | 7 | /* make sure libbpf doesn't use kernel-only integer typedefs */ 8 | #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64 9 | 10 | /* 11 | * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl 12 | * libc, while checking strerror_r() return to avoid having to check this in 13 | * all places calling it. 14 | */ 15 | char *libbpf_strerror_r(int err, char *dst, int len) 16 | { 17 | int ret = strerror_r(err < 0 ? -err : err, dst, len); 18 | if (ret) 19 | snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret); 20 | return dst; 21 | } 22 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/src/str_error.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | #ifndef __LIBBPF_STR_ERROR_H 3 | #define __LIBBPF_STR_ERROR_H 4 | 5 | char *libbpf_strerror_r(int err, char *dst, int len); 6 | #endif /* __LIBBPF_STR_ERROR_H */ 7 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/src/strset.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | /* Copyright (c) 2021 Facebook */ 4 | #ifndef __LIBBPF_STRSET_H 5 | #define __LIBBPF_STRSET_H 6 | 7 | #include 8 | #include 9 | 10 | struct strset; 11 | 12 | struct strset *strset__new(size_t max_data_sz, const char *init_data, size_t init_data_sz); 13 | void strset__free(struct strset *set); 14 | 15 | const char *strset__data(const struct strset *set); 16 | size_t strset__data_size(const struct strset *set); 17 | 18 | int strset__find_str(struct strset *set, const char *s); 19 | int strset__add_str(struct strset *set, const char *s); 20 | 21 | #endif /* __LIBBPF_STRSET_H */ 22 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libbpf/src/zip.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 | 3 | #ifndef __LIBBPF_ZIP_H 4 | #define __LIBBPF_ZIP_H 5 | 6 | #include 7 | 8 | /* Represents an open zip archive. 9 | * Only basic ZIP files are supported, in particular the following are not 10 | * supported: 11 | * - encryption 12 | * - streaming 13 | * - multi-part ZIP files 14 | * - ZIP64 15 | */ 16 | struct zip_archive; 17 | 18 | /* Carries information on name, compression method, and data corresponding to a 19 | * file in a zip archive. 20 | */ 21 | struct zip_entry { 22 | /* Compression method as defined in pkzip spec. 0 means data is uncompressed. */ 23 | __u16 compression; 24 | 25 | /* Non-null terminated name of the file. */ 26 | const char *name; 27 | /* Length of the file name. */ 28 | __u16 name_length; 29 | 30 | /* Pointer to the file data. */ 31 | const void *data; 32 | /* Length of the file data. */ 33 | __u32 data_length; 34 | /* Offset of the file data within the archive. */ 35 | __u32 data_offset; 36 | }; 37 | 38 | /* Open a zip archive. Returns NULL in case of an error. */ 39 | struct zip_archive *zip_archive_open(const char *path); 40 | 41 | /* Close a zip archive and release resources. */ 42 | void zip_archive_close(struct zip_archive *archive); 43 | 44 | /* Look up an entry corresponding to a file in given zip archive. */ 45 | int zip_archive_find_entry(struct zip_archive *archive, const char *name, struct zip_entry *out); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/.gitignore: -------------------------------------------------------------------------------- 1 | *.so.* 2 | *.a 3 | *.pc 4 | sharedobjs/ 5 | staticobjs/ 6 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H 2 | #define __COMPAT_H 3 | 4 | #ifndef HAVE_SECURE_GETENV 5 | #include 6 | // Source: https://www.openwall.com/lists/musl/2019/05/28/3 7 | static inline char *secure_getenv(const char *name) 8 | { 9 | return libc.secure ? NULL : getenv(name); 10 | } 11 | #endif 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/libxdp.mk: -------------------------------------------------------------------------------- 1 | LIBXDP_VERSION := $(shell sed -ne "/LIBXDP_[0-9\.]\+ {/ {s/LIBXDP_\([0-9\.]\+\) {/\1/;p}" $(LIB_DIR)/libxdp/libxdp.map | tail -n 1) 2 | LIBXDP_MAJOR_VERSION := $(shell echo $(LIBXDP_VERSION) | sed 's/\..*//') 3 | 4 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/libxdp.pc.template: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 | 3 | prefix=@PREFIX@ 4 | libdir=@LIBDIR@ 5 | includedir=${prefix}/include 6 | 7 | Name: libxdp 8 | Description: XDP library 9 | Version: @VERSION@ 10 | Libs: -L${libdir} -lxdp 11 | Requires.private: libbpf 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/tests/.gitignore: -------------------------------------------------------------------------------- 1 | test_xsk_refcnt 2 | check_kern_compat 3 | test_xdp_frags 4 | test_dispatcher_versions 5 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/tests/check_kern_compat.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #include "test_utils.h" 4 | #include "../libxdp_internal.h" 5 | 6 | int main(__unused int argc, __unused char** argv) 7 | { 8 | silence_libbpf_logging(); 9 | return libxdp_check_kern_compat(); 10 | } 11 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/tests/test_utils.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #ifndef __TEST_UTILS_H 4 | #define __TEST_UTILS_H 5 | 6 | #include 7 | #include 8 | 9 | #define __unused __attribute__((unused)) 10 | 11 | static int libbpf_silent_func(__unused enum libbpf_print_level level, 12 | __unused const char *format, 13 | __unused va_list args) 14 | { 15 | return 0; 16 | } 17 | 18 | static inline void silence_libbpf_logging(void) 19 | { 20 | libbpf_set_print(libbpf_silent_func); 21 | } 22 | 23 | static int libxdp_silent_func(__unused enum libxdp_print_level level, 24 | __unused const char *format, 25 | __unused va_list args) 26 | { 27 | return 0; 28 | } 29 | 30 | static int libxdp_verbose_func(__unused enum libxdp_print_level level, 31 | __unused const char *format, 32 | __unused va_list args) 33 | { 34 | fprintf(stderr, " "); 35 | vfprintf(stderr, format, args); 36 | return 0; 37 | } 38 | 39 | static inline void silence_libxdp_logging(void) 40 | { 41 | libxdp_set_print(libxdp_silent_func); 42 | } 43 | 44 | static inline void verbose_libxdp_logging(void) 45 | { 46 | libxdp_set_print(libxdp_verbose_func); 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/tests/xdp_dispatcher_v1.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "xdp_dispatcher_v1.h" 8 | 9 | #define XDP_METADATA_SECTION "xdp_metadata" 10 | #define XDP_DISPATCHER_VERSION_V1 1 11 | #define XDP_DISPATCHER_RETVAL 31 12 | 13 | 14 | static volatile const struct xdp_dispatcher_config_v1 conf = {}; 15 | 16 | __attribute__ ((noinline)) 17 | int prog0(struct xdp_md *ctx) { 18 | volatile int ret = XDP_DISPATCHER_RETVAL; 19 | 20 | if (!ctx) 21 | return XDP_ABORTED; 22 | return ret; 23 | } 24 | __attribute__ ((noinline)) 25 | 26 | SEC("xdp") 27 | int xdp_dispatcher(struct xdp_md *ctx) 28 | { 29 | __u8 num_progs_enabled = conf.num_progs_enabled; 30 | int ret; 31 | 32 | if (num_progs_enabled < 1) 33 | goto out; 34 | ret = prog0(ctx); 35 | if (!((1U << ret) & conf.chain_call_actions[0])) 36 | return ret; 37 | 38 | out: 39 | return XDP_PASS; 40 | } 41 | 42 | char _license[] SEC("license") = "GPL"; 43 | __uint(dispatcher_version, XDP_DISPATCHER_VERSION_V1) SEC(XDP_METADATA_SECTION); 44 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/tests/xdp_dispatcher_v1.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #ifndef __XDP_DISPATCHER_V1_H 4 | #define __XDP_DISPATCHER_V1_H 5 | 6 | #ifndef MAX_DISPATCHER_ACTIONS 7 | #define MAX_DISPATCHER_ACTIONS 10 8 | #endif 9 | 10 | struct xdp_dispatcher_config_v1 { 11 | __u8 num_progs_enabled; 12 | __u32 chain_call_actions[MAX_DISPATCHER_ACTIONS]; 13 | __u32 run_prios[MAX_DISPATCHER_ACTIONS]; 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/tests/xdp_pass.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | #include 3 | #include 4 | 5 | SEC("xdp") 6 | int xdp_pass(struct xdp_md *ctx) 7 | { 8 | return XDP_PASS; 9 | } 10 | 11 | char _license[] SEC("license") = "GPL"; 12 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/xsk_def_xdp_prog.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "xsk_def_xdp_prog.h" 8 | 9 | #define DEFAULT_QUEUE_IDS 64 10 | 11 | struct { 12 | __uint(type, BPF_MAP_TYPE_XSKMAP); 13 | __uint(key_size, sizeof(int)); 14 | __uint(value_size, sizeof(int)); 15 | __uint(max_entries, DEFAULT_QUEUE_IDS); 16 | } xsks_map SEC(".maps"); 17 | 18 | struct { 19 | __uint(priority, 20); 20 | __uint(XDP_PASS, 1); 21 | } XDP_RUN_CONFIG(xsk_def_prog); 22 | 23 | /* Program refcount, in order to work properly, 24 | * must be declared before any other global variables 25 | * and initialized with '1'. 26 | */ 27 | volatile int refcnt = 1; 28 | 29 | /* This is the program for post 5.3 kernels. */ 30 | SEC("xdp") 31 | int xsk_def_prog(struct xdp_md *ctx) 32 | { 33 | /* Make sure refcount is referenced by the program */ 34 | if (!refcnt) 35 | return XDP_PASS; 36 | 37 | /* A set entry here means that the corresponding queue_id 38 | * has an active AF_XDP socket bound to it. 39 | */ 40 | return bpf_redirect_map(&xsks_map, ctx->rx_queue_index, XDP_PASS); 41 | } 42 | 43 | char _license[] SEC("license") = "GPL"; 44 | __uint(xsk_prog_version, XSK_PROG_VERSION) SEC(XDP_METADATA_SECTION); 45 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/xsk_def_xdp_prog.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 | 3 | #ifndef __LIBXDP_XSK_DEF_XDP_PROG_H 4 | #define __LIBXDP_XSK_DEF_XDP_PROG_H 5 | 6 | #define XDP_METADATA_SECTION "xdp_metadata" 7 | #define XSK_PROG_VERSION 1 8 | 9 | #endif /* __LIBXDP_XSK_DEF_XDP_PROG_H */ 10 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/libxdp/xsk_def_xdp_prog_5.3.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "xsk_def_xdp_prog.h" 8 | 9 | #define DEFAULT_QUEUE_IDS 64 10 | 11 | struct { 12 | __uint(type, BPF_MAP_TYPE_XSKMAP); 13 | __uint(key_size, sizeof(int)); 14 | __uint(value_size, sizeof(int)); 15 | __uint(max_entries, DEFAULT_QUEUE_IDS); 16 | } xsks_map SEC(".maps"); 17 | 18 | struct { 19 | __uint(priority, 20); 20 | __uint(XDP_PASS, 1); 21 | } XDP_RUN_CONFIG(xsk_def_prog); 22 | 23 | /* Program refcount, in order to work properly, 24 | * must be declared before any other global variables 25 | * and initialized with '1'. 26 | */ 27 | volatile int refcnt = 1; 28 | 29 | /* This is the program for 5.3 kernels and older. */ 30 | SEC("xdp") 31 | int xsk_def_prog(struct xdp_md *ctx) 32 | { 33 | int index = ctx->rx_queue_index; 34 | 35 | /* Make sure refcount is referenced by the program */ 36 | if (!refcnt) 37 | return XDP_PASS; 38 | 39 | /* A set entry here means that the corresponding queue_id 40 | * has an active AF_XDP socket bound to it. 41 | */ 42 | if (bpf_map_lookup_elem(&xsks_map, &index)) 43 | return bpf_redirect_map(&xsks_map, index, 0); 44 | return XDP_PASS; 45 | 46 | } 47 | 48 | char _license[] SEC("license") = "GPL"; 49 | __uint(xsk_prog_version, XSK_PROG_VERSION) SEC(XDP_METADATA_SECTION); 50 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/testing/.gitignore: -------------------------------------------------------------------------------- 1 | test-tool 2 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/testing/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 | 3 | TEST_TARGETS := test-tool 4 | XDP_TARGETS := test_long_func_name xdp_drop xdp_pass 5 | SCRIPTS_FILES := test_runner.sh setup-netns-env.sh run_tests.sh 6 | XDP_OBJ_INSTALL := 7 | 8 | LIB_DIR = .. 9 | 10 | include $(LIB_DIR)/common.mk 11 | 12 | install_local:: 13 | install -m 0755 -d $(DESTDIR)$(SCRIPTSDIR) 14 | install -m 0644 test_config.install.sh $(DESTDIR)$(SCRIPTSDIR)/test_config.sh 15 | install -m 0644 $(XDP_OBJ) $(DESTDIR)$(SCRIPTSDIR)/ 16 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/testing/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TEST_PROG_DIR="${TEST_PROG_DIR:-$(dirname "${BASH_SOURCE[0]}")}" 4 | TESTS_DIR="${TESTS_DIR:-$TEST_PROG_DIR/tests}" 5 | TEST_RUNNER="$TEST_PROG_DIR/test_runner.sh" 6 | 7 | RET=0 8 | 9 | echo "Running all tests from $TESTS_DIR" 10 | for f in "$TESTS_DIR"/*/test-*.sh; do 11 | if [[ ! -f "$f" ]]; then 12 | echo "No tests found!" 13 | exit 1 14 | fi 15 | 16 | "$TEST_RUNNER" "$f" || RET=1 17 | done 18 | 19 | exit $RET 20 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/testing/setup-netns-env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0-or-later 3 | # 4 | # Script to setup things inside a test environment, used by testenv.sh for 5 | # executing commands. 6 | # 7 | # Author: Toke Høiland-Jørgensen (toke@redhat.com) 8 | # Date: 7 March 2019 9 | # Copyright (c) 2019 Red Hat 10 | 11 | 12 | die() 13 | { 14 | echo "$1" >&2 15 | exit 1 16 | } 17 | 18 | [ -n "$TESTENV_NAME" ] || die "TESTENV_NAME missing from environment" 19 | [ -n "$1" ] || die "Usage: $0 " 20 | 21 | set -o nounset 22 | 23 | mount -t bpf bpf /sys/fs/bpf/ || die "Unable to mount /sys/fs/bpf inside test environment" 24 | 25 | exec "$@" 26 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/testing/test_config.install.sh: -------------------------------------------------------------------------------- 1 | # Test config for having tools in $PATH - to be installed along with the 2 | # test runners in /usr/share/xdp-tools 3 | 4 | XDP_FILTER=xdp-filter 5 | XDP_LOADER=xdp-loader 6 | XDP_BENCH=xdp-bench 7 | XDP_MONITOR=xdp-monitor 8 | XDP_TRAFFICGEN=xdp-trafficgen 9 | XDPDUMP=xdpdump 10 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/testing/test_long_func_name.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define bpf_debug(fmt, ...) \ 6 | { \ 7 | char __fmt[] = fmt; \ 8 | bpf_trace_printk(__fmt, sizeof(__fmt), \ 9 | ##__VA_ARGS__); \ 10 | } 11 | 12 | SEC("xdp") 13 | int xdp_test_prog_with_a_long_name(struct xdp_md *ctx) 14 | { 15 | bpf_debug("PASS[1]: prog %u\n", ctx->ingress_ifindex); 16 | return XDP_PASS; 17 | } 18 | 19 | SEC("xdp") 20 | int xdp_test_prog_with_a_long_name_too(struct xdp_md *ctx) 21 | { 22 | bpf_debug("PASS[2]: prog %u\n", ctx->ingress_ifindex); 23 | return XDP_PASS; 24 | } 25 | 26 | struct { 27 | __uint(priority, 5); 28 | __uint(XDP_PASS, 1); 29 | } XDP_RUN_CONFIG(xdp_test_prog_with_a_long_name); 30 | 31 | char _license[] SEC("license") = "GPL"; 32 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/testing/xdp_drop.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | SEC("xdp") 5 | int xdp_drop(struct xdp_md *ctx) 6 | { 7 | return XDP_DROP; 8 | } 9 | 10 | char _license[] SEC("license") = "GPL"; 11 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/testing/xdp_pass.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct { 6 | __uint(priority, 10); 7 | __uint(XDP_PASS, 1); 8 | } XDP_RUN_CONFIG(xdp_pass); 9 | 10 | SEC("xdp") 11 | int xdp_pass(struct xdp_md *ctx) 12 | { 13 | return XDP_PASS; 14 | } 15 | 16 | char _license[] SEC("license") = "GPL"; 17 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/util/Makefile: -------------------------------------------------------------------------------- 1 | include util.mk 2 | 3 | LIB_DIR ?= .. 4 | 5 | include $(LIB_DIR)/defines.mk 6 | include $(LIBXDP_DIR)/libxdp.mk 7 | 8 | all: $(UTIL_OBJS) 9 | 10 | UTIL_SKEL_H = $(UTIL_BPF_OBJS:.bpf.o=.skel.h) 11 | 12 | $(UTIL_OBJS): %.o: %.c %.h $(UTIL_SKEL_H) $(LIBMK) 13 | $(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) -Wall -I../../headers -c -o $@ $< 14 | 15 | clean: 16 | $(Q)rm -f $(UTIL_OBJS) $(UTIL_BPF_OBJS) $(UTIL_SKEL_H) 17 | 18 | BPF_CFLAGS += -I$(HEADER_DIR) $(ARCH_INCLUDES) 19 | 20 | $(UTIL_BPF_OBJS): %.o: %.c $(KERN_USER_H) $(BPF_HEADERS) $(LIBMK) 21 | $(QUIET_CLANG)$(CLANG) -S \ 22 | -target $(BPF_TARGET) \ 23 | -D __BPF_TRACING__ \ 24 | $(BPF_CFLAGS) \ 25 | -Wall \ 26 | -Wno-unused-value \ 27 | -Wno-pointer-sign \ 28 | -Wno-compare-distinct-pointer-types \ 29 | -Werror \ 30 | -O2 -emit-llvm -c -g -o ${@:.o=.ll} $< 31 | $(QUIET_LLC)$(LLC) -march=$(BPF_TARGET) -filetype=obj -o $@ ${@:.o=.ll} 32 | 33 | $(UTIL_SKEL_H): %.skel.h: %.bpf.o 34 | $(QUIET_GEN)$(BPFTOOL) gen skeleton $< name ${@:.skel.h=} > $@ 35 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/util/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H 2 | #define __COMPAT_H 3 | 4 | #ifndef HAVE_LIBBPF_BTF__TYPE_CNT 5 | static __u32 btf__type_cnt(const struct btf *btf) 6 | { 7 | /* old function didn't include 'void' type in count */ 8 | return btf__get_nr_types(btf) + 1; 9 | } 10 | #endif 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/util/logging.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #ifndef __LOGGING_H 4 | #define __LOGGING_H 5 | 6 | /* This matches the libbpf logging levels, but with an additional VERBOSE level; 7 | * we demote all libbpf messages by one level so debug messages only show up on 8 | * VERBOSE. 9 | */ 10 | enum logging_print_level { 11 | LOG_WARN, 12 | LOG_INFO, 13 | LOG_DEBUG, 14 | LOG_VERBOSE, 15 | }; 16 | 17 | extern void logging_print(enum logging_print_level level, const char *format, 18 | ...) __attribute__((format(printf, 2, 3))); 19 | 20 | #define __pr(level, fmt, ...) \ 21 | do { \ 22 | logging_print(level, fmt, ##__VA_ARGS__); \ 23 | } while (0) 24 | 25 | #define pr_warn(fmt, ...) __pr(LOG_WARN, fmt, ##__VA_ARGS__) 26 | #define pr_info(fmt, ...) __pr(LOG_INFO, fmt, ##__VA_ARGS__) 27 | #define pr_debug(fmt, ...) __pr(LOG_DEBUG, fmt, ##__VA_ARGS__) 28 | 29 | void init_lib_logging(void); 30 | void silence_libbpf_logging(void); 31 | void silence_libxdp_logging(void); 32 | enum logging_print_level set_log_level(enum logging_print_level level); 33 | enum logging_print_level increase_log_level(); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/util/stats.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #ifndef __STATS_H 4 | #define __STATS_H 5 | 6 | #include 7 | 8 | #include "xdp/xdp_stats_kern_user.h" 9 | 10 | struct record { 11 | __u64 timestamp; 12 | bool enabled; 13 | struct xdp_stats_record total; /* defined in common_kern_user.h */ 14 | }; 15 | 16 | struct stats_record { 17 | struct record stats[XDP_ACTION_MAX]; 18 | }; 19 | 20 | int stats_print_one(struct stats_record *stats_rec); 21 | int stats_print(struct stats_record *stats_rec, 22 | struct stats_record *stats_prev); 23 | int stats_collect(int map_fd, __u32 map_type, struct stats_record *stats_rec); 24 | int stats_poll(int map_fd, int interval, bool *exit, const char *pin_dir, const char *map_name); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/util/util.mk: -------------------------------------------------------------------------------- 1 | UTIL_OBJS := params.o logging.o util.o stats.o xpcapng.o xdp_sample.o 2 | UTIL_BPF_OBJS := xdp_sample.bpf.o 3 | -------------------------------------------------------------------------------- /lib/xdp-tools/lib/util/xdp_sample.bpf.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | SEC("tp_btf/xdp_cpumap_kthread") 10 | int BPF_PROG(tp_xdp_cpumap_kthread, int map_id, unsigned int processed, 11 | unsigned int drops, int sched, struct xdp_cpumap_stats *xdp_stats) 12 | { 13 | bpf_printk("Stats: %d %u %u %d %d\n", 14 | map_id, processed, drops, sched, xdp_stats->pass); 15 | return 0; 16 | } 17 | 18 | char _license[] SEC("license") = "GPL"; 19 | -------------------------------------------------------------------------------- /lib/xdp-tools/mkarchive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION="$1" 4 | WORKDIR=$(dirname "${BASH_SOURCE[0]}") 5 | OUTFILE="$WORKDIR/xdp-tools-$VERSION.tar.gz" 6 | PREFIX=xdp-tools-$VERSION 7 | TMPDIR=$(mktemp -d) 8 | 9 | set -o errexit 10 | set -o nounset 11 | 12 | trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM 13 | 14 | [ -d .git ] || exit 1 15 | if git status -s | grep -Eq '^ ?[AM]'; then 16 | echo "Please commit changes first" >&2 17 | exit 1 18 | fi 19 | 20 | git archive -o "$TMPDIR/xdp-tools.tar.gz" --prefix "${PREFIX}/" HEAD 21 | ( cd lib/libbpf && git archive -o "$TMPDIR/libbpf.tar.gz" --prefix "${PREFIX}/lib/libbpf/" HEAD) 22 | tar -C "$TMPDIR" -xzf "$TMPDIR/xdp-tools.tar.gz" 23 | tar -C "$TMPDIR" -xzf "$TMPDIR/libbpf.tar.gz" 24 | tar -C "$TMPDIR" -czf "$OUTFILE" "$PREFIX" 25 | 26 | 27 | echo "Created $OUTFILE" 28 | -------------------------------------------------------------------------------- /lib/xdp-tools/version.mk: -------------------------------------------------------------------------------- 1 | TOOLS_VERSION := "1.3.1" 2 | 3 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-bench/.gitignore: -------------------------------------------------------------------------------- 1 | xdp-bench 2 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-bench/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 | 3 | XDP_TARGETS := xdp_redirect_basic.bpf xdp_redirect_cpumap.bpf xdp_redirect_devmap.bpf \ 4 | xdp_redirect_devmap_multi.bpf xdp_basic.bpf 5 | BPF_SKEL_TARGETS := $(XDP_TARGETS) 6 | 7 | # Don't install skeleton object files 8 | XDP_OBJ_INSTALL := 9 | 10 | TOOL_NAME := xdp-bench 11 | MAN_PAGE := xdp-bench.8 12 | TEST_FILE := tests/test-xdp-bench.sh 13 | USER_TARGETS := xdp-bench 14 | USER_EXTRA_C := xdp_redirect_basic.c xdp_redirect_cpumap.c xdp_redirect_devmap.c \ 15 | xdp_redirect_devmap_multi.c xdp_basic.c 16 | EXTRA_USER_DEPS := xdp-bench.h 17 | 18 | LIB_DIR = ../lib 19 | 20 | include $(LIB_DIR)/common.mk 21 | 22 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-bench/hash_func01.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1 2 | * 3 | * Based on Paul Hsieh's (LGPG 2.1) hash function 4 | * From: http://www.azillionmonkeys.com/qed/hash.html 5 | */ 6 | 7 | #define get16bits(d) (*((const __u16 *) (d))) 8 | 9 | static __always_inline 10 | __u32 SuperFastHash(const char *data, int len, __u32 initval) { 11 | __u32 hash = initval; 12 | __u32 tmp; 13 | int rem; 14 | 15 | if (len <= 0 || data == NULL) return 0; 16 | 17 | rem = len & 3; 18 | len >>= 2; 19 | 20 | /* Main loop */ 21 | #pragma clang loop unroll(full) 22 | for (;len > 0; len--) { 23 | hash += get16bits (data); 24 | tmp = (get16bits (data+2) << 11) ^ hash; 25 | hash = (hash << 16) ^ tmp; 26 | data += 2*sizeof (__u16); 27 | hash += hash >> 11; 28 | } 29 | 30 | /* Handle end cases */ 31 | switch (rem) { 32 | case 3: hash += get16bits (data); 33 | hash ^= hash << 16; 34 | hash ^= ((signed char)data[sizeof (__u16)]) << 18; 35 | hash += hash >> 11; 36 | break; 37 | case 2: hash += get16bits (data); 38 | hash ^= hash << 11; 39 | hash += hash >> 17; 40 | break; 41 | case 1: hash += (signed char)*data; 42 | hash ^= hash << 10; 43 | hash += hash >> 1; 44 | } 45 | 46 | /* Force "avalanching" of final 127 bits */ 47 | hash ^= hash << 3; 48 | hash += hash >> 5; 49 | hash ^= hash << 4; 50 | hash += hash >> 17; 51 | hash ^= hash << 25; 52 | hash += hash >> 6; 53 | 54 | return hash; 55 | } 56 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-bench/xdp_basic.bpf.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | /* Copyright (c) 2016 John Fastabend 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of version 2 of the GNU General Public 6 | * License as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * General Public License for more details. 12 | */ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | const volatile bool read_data = 0; 20 | const volatile bool swap_macs = 0; 21 | const volatile bool rxq_stats = 0; 22 | const volatile enum xdp_action action = XDP_DROP; 23 | 24 | SEC("xdp") 25 | int xdp_basic_prog(struct xdp_md *ctx) 26 | { 27 | void *data_end = (void *)(long)ctx->data_end; 28 | void *data = (void *)(long)ctx->data; 29 | __u32 key = bpf_get_smp_processor_id(); 30 | struct datarec *rec, *rxq_rec; 31 | struct ethhdr *eth = data; 32 | __u64 nh_off; 33 | 34 | nh_off = sizeof(*eth); 35 | if (data + nh_off > data_end) 36 | return XDP_DROP; 37 | 38 | rec = bpf_map_lookup_elem(&rx_cnt, &key); 39 | if (!rec) 40 | return XDP_PASS; 41 | NO_TEAR_INC(rec->processed); 42 | 43 | if (rxq_stats) { 44 | key = ctx->rx_queue_index; 45 | rxq_rec = bpf_map_lookup_elem(&rxq_cnt, &key); 46 | if (!rxq_rec) 47 | return XDP_PASS; 48 | NO_TEAR_INC(rxq_rec->processed); 49 | } 50 | 51 | if (read_data) { 52 | if (bpf_ntohs(eth->h_proto) < ETH_P_802_3_MIN) 53 | return XDP_ABORTED; 54 | 55 | if (swap_macs) 56 | swap_src_dst_mac(data); 57 | } 58 | 59 | if (action == XDP_DROP) { 60 | NO_TEAR_INC(rec->dropped); 61 | if (rxq_stats) 62 | NO_TEAR_INC(rxq_rec->dropped); 63 | } 64 | 65 | return action; 66 | } 67 | 68 | char _license[] SEC("license") = "GPL"; 69 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-bench/xdp_redirect_basic.bpf.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | /* Copyright (c) 2016 John Fastabend 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of version 2 of the GNU General Public 6 | * License as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * General Public License for more details. 12 | */ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | const volatile int ifindex_out; 20 | 21 | SEC("xdp") 22 | int xdp_redirect_basic_prog(struct xdp_md *ctx) 23 | { 24 | void *data_end = (void *)(long)ctx->data_end; 25 | void *data = (void *)(long)ctx->data; 26 | __u32 key = bpf_get_smp_processor_id(); 27 | struct ethhdr *eth = data; 28 | struct datarec *rec; 29 | __u64 nh_off; 30 | 31 | nh_off = sizeof(*eth); 32 | if (data + nh_off > data_end) 33 | return XDP_DROP; 34 | 35 | rec = bpf_map_lookup_elem(&rx_cnt, &key); 36 | if (!rec) 37 | return XDP_PASS; 38 | NO_TEAR_INC(rec->processed); 39 | 40 | swap_src_dst_mac(data); 41 | return bpf_redirect(ifindex_out, 0); 42 | } 43 | 44 | char _license[] SEC("license") = "GPL"; 45 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-bench/xdp_redirect_devmap_multi.bpf.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct { 9 | __uint(type, BPF_MAP_TYPE_DEVMAP_HASH); 10 | __uint(key_size, sizeof(int)); 11 | __uint(value_size, sizeof(int)); 12 | __uint(max_entries, 32); 13 | } forward_map_general SEC(".maps"); 14 | 15 | struct { 16 | __uint(type, BPF_MAP_TYPE_DEVMAP_HASH); 17 | __uint(key_size, sizeof(int)); 18 | __uint(value_size, sizeof(struct bpf_devmap_val)); 19 | __uint(max_entries, 32); 20 | } forward_map_native SEC(".maps"); 21 | 22 | /* map to store egress interfaces mac addresses */ 23 | struct { 24 | __uint(type, BPF_MAP_TYPE_HASH); 25 | __type(key, __u32); 26 | __type(value, __be64); 27 | __uint(max_entries, 32); 28 | } mac_map SEC(".maps"); 29 | 30 | static int xdp_redirect_devmap_multi(struct xdp_md *ctx, void *forward_map) 31 | { 32 | __u32 key = bpf_get_smp_processor_id(); 33 | struct datarec *rec; 34 | 35 | rec = bpf_map_lookup_elem(&rx_cnt, &key); 36 | if (!rec) 37 | return XDP_PASS; 38 | NO_TEAR_INC(rec->processed); 39 | 40 | return bpf_redirect_map(forward_map, 0, 41 | BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS); 42 | } 43 | 44 | SEC("xdp") 45 | int redir_multi_general(struct xdp_md *ctx) 46 | { 47 | return xdp_redirect_devmap_multi(ctx, &forward_map_general); 48 | } 49 | 50 | SEC("xdp") 51 | int redir_multi_native(struct xdp_md *ctx) 52 | { 53 | return xdp_redirect_devmap_multi(ctx, &forward_map_native); 54 | } 55 | 56 | SEC("xdp/devmap") 57 | int xdp_devmap_prog(struct xdp_md *ctx) 58 | { 59 | void *data_end = (void *)(long)ctx->data_end; 60 | void *data = (void *)(long)ctx->data; 61 | __u32 key = ctx->egress_ifindex; 62 | struct ethhdr *eth = data; 63 | __be64 *mac; 64 | __u64 nh_off; 65 | 66 | nh_off = sizeof(*eth); 67 | if (data + nh_off > data_end) 68 | return XDP_DROP; 69 | 70 | mac = bpf_map_lookup_elem(&mac_map, &key); 71 | if (mac) 72 | __builtin_memcpy(eth->h_source, mac, ETH_ALEN); 73 | 74 | return XDP_PASS; 75 | } 76 | 77 | char _license[] SEC("license") = "GPL"; 78 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-dump/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | xdpdump 3 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-dump/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 | TOOL_NAME := xdpdump 3 | XDP_TARGETS := xdpdump_bpf xdpdump_xdp 4 | USER_TARGETS := xdpdump 5 | TEST_FILE := tests/test-xdpdump.sh 6 | 7 | # Disable warnings about VLAs not being at the end of a structure when building 8 | # with clang. The code is fine, but clang's complaint coupled with -Werror would 9 | # break the build. See https://github.com/xdp-project/xdp-tools/issues/304 10 | CFLAGS += "-Wno-gnu-variable-sized-type-not-at-end" 11 | LIB_DIR = ../lib 12 | USER_LIBS = -lpcap 13 | MAN_PAGE := xdpdump.8 14 | 15 | include $(LIB_DIR)/common.mk 16 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-filter/.gitignore: -------------------------------------------------------------------------------- 1 | *.ll 2 | xdp-filter 3 | prog_features.h 4 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-filter/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 | 3 | XDP_TARGETS := xdpfilt_dny_udp xdpfilt_dny_tcp xdpfilt_dny_ip \ 4 | xdpfilt_dny_eth xdpfilt_dny_all \ 5 | xdpfilt_alw_udp xdpfilt_alw_tcp xdpfilt_alw_ip \ 6 | xdpfilt_alw_eth xdpfilt_alw_all 7 | 8 | TOOL_NAME := xdp-filter 9 | USER_TARGETS := xdp-filter 10 | EXTRA_DEPS := xdpfilt_prog.h 11 | MAN_PAGE := xdp-filter.8 12 | TEST_FILE := tests/test-xdp-filter.sh 13 | TEST_FILE_DEPS := $(wildcard tests/*.py) 14 | 15 | USER_GEN := prog_features.h 16 | EXTRA_USER_DEPS := $(USER_GEN) 17 | 18 | LIB_DIR = ../lib 19 | 20 | include $(LIB_DIR)/common.mk 21 | 22 | prog_features.h: ${XDP_TARGETS:=.o} extract_features.sh 23 | $(Q)sh extract_features.sh $^ > $@ || ( ret=$$?; rm -f $@; exit $$ret ) 24 | 25 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-filter/common_kern_user.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_KERN_USER_H 2 | #define COMMON_KERN_USER_H 3 | 4 | #define FEAT_TCP (1<<0) 5 | #define FEAT_UDP (1<<1) 6 | #define FEAT_IPV6 (1<<2) 7 | #define FEAT_IPV4 (1<<3) 8 | #define FEAT_ETHERNET (1<<4) 9 | #define FEAT_ALL (FEAT_TCP|FEAT_UDP|FEAT_IPV6|FEAT_IPV4|FEAT_ETHERNET) 10 | #define FEAT_ALLOW (1<<5) 11 | #define FEAT_DENY (1<<6) 12 | 13 | #define MAP_FLAG_SRC (1<<0) 14 | #define MAP_FLAG_DST (1<<1) 15 | #define MAP_FLAG_TCP (1<<2) 16 | #define MAP_FLAG_UDP (1<<3) 17 | #define MAP_FLAGS (MAP_FLAG_SRC|MAP_FLAG_DST|MAP_FLAG_TCP|MAP_FLAG_UDP) 18 | 19 | #define COUNTER_SHIFT 6 20 | 21 | #define MAP_NAME_PORTS filter_ports 22 | #define MAP_NAME_IPV4 filter_ipv4 23 | #define MAP_NAME_IPV6 filter_ipv6 24 | #define MAP_NAME_ETHERNET filter_ethernet 25 | 26 | #include "xdp/xdp_stats_kern_user.h" 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-filter/extract_features.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cat</dev/null) 16 | [ "$?" -ne "0" ] && continue 17 | 18 | found=0 19 | for w in $featstring; do 20 | if [ "$w" = "0x00000000" ]; then 21 | found=1 22 | else 23 | if [ "$found" -eq "1" ]; then 24 | feats=$w 25 | break 26 | fi 27 | fi 28 | done 29 | 30 | echo " {\"$f\", 0x$feats}," 31 | done 32 | 33 | cat< 7 | #include 8 | 9 | char _license[] SEC("license") = "GPL"; 10 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-trafficgen/.gitignore: -------------------------------------------------------------------------------- 1 | xdp-trafficgen 2 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-trafficgen/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 | 3 | XDP_TARGETS := xdp_trafficgen.bpf 4 | BPF_SKEL_TARGETS := $(XDP_TARGETS) 5 | 6 | # Don't install skeleton object files 7 | XDP_OBJ_INSTALL := 8 | 9 | TOOL_NAME := xdp-trafficgen 10 | USER_TARGETS := xdp-trafficgen 11 | MAN_PAGE := xdp-trafficgen.8 12 | EXTRA_DEPS := xdp-trafficgen.h 13 | USER_LIBS = -lpthread 14 | TEST_FILE := tests/test-xdp-trafficgen.sh 15 | 16 | LIB_DIR = ../lib 17 | 18 | include $(LIB_DIR)/common.mk 19 | 20 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-trafficgen/tests/test-xdp-trafficgen.sh: -------------------------------------------------------------------------------- 1 | XDP_LOADER=${XDP_LOADER:-./xdp-loader} 2 | XDP_TRAFFICGEN=${XDP_TRAFFICGEN:-./xdp-trafficgen} 3 | ALL_TESTS="test_udp test_tcp" 4 | 5 | PIDS="" 6 | 7 | skip_if_missing_kernel_support() 8 | { 9 | $XDP_TRAFFICGEN probe 10 | ret=$? 11 | if [ "$ret" -eq "161" ]; then 12 | exit $SKIPPED_TEST 13 | elif [ "$ret" -ne "0" ]; then 14 | exit 1 15 | fi 16 | } 17 | 18 | test_udp() 19 | { 20 | skip_if_missing_kernel_support 21 | export XDP_SAMPLE_IMMEDIATE_EXIT=1 22 | 23 | check_run $XDP_TRAFFICGEN udp $NS -n 1 24 | } 25 | 26 | test_tcp() 27 | { 28 | skip_if_missing_kernel_support 29 | export XDP_SAMPLE_IMMEDIATE_EXIT=1 30 | 31 | PID=$(start_background_ns_devnull "nc -6 -l 10000") 32 | $XDP_TRAFFICGEN tcp -i $NS $INSIDE_IP6 -n 1 33 | res=$? 34 | stop_background $PID 35 | return $res 36 | } 37 | 38 | cleanup_tests() 39 | { 40 | $XDP_LOADER unload $NS --all >/dev/null 2>&1 41 | $XDP_LOADER clean >/dev/null 2>&1 42 | } 43 | -------------------------------------------------------------------------------- /lib/xdp-tools/xdp-trafficgen/xdp-trafficgen.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | 3 | #ifndef XDP_TRAFFICGEN_H 4 | #define XDP_TRAFFICGEN_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | struct tcp_flowkey { 11 | struct in6_addr src_ip; 12 | struct in6_addr dst_ip; 13 | __u16 dst_port; 14 | __u16 src_port; 15 | }; 16 | 17 | #define FLOW_STATE_NEW 1 18 | #define FLOW_STATE_RUNNING 2 19 | #define FLOW_STATE_DONE 3 20 | 21 | struct tcp_flowstate { 22 | struct bpf_spin_lock lock; 23 | __u8 dst_mac[ETH_ALEN]; 24 | __u8 src_mac[ETH_ALEN]; 25 | __u64 last_progress; 26 | __u64 retransmits; 27 | __u32 flow_state; 28 | __u32 seq; /* our last sent seqno */ 29 | __u32 ack_seq; /* last seqno that got acked */ 30 | __u32 rcv_seq; /* receiver's seqno (our ACK seq) */ 31 | __u32 dupack; 32 | __u32 last_print; 33 | __u32 highest_seq; 34 | __u16 window; 35 | __u8 wscale; 36 | }; 37 | 38 | struct trafficgen_config { 39 | int ifindex_out; 40 | __u16 port_start; 41 | __u16 port_range; 42 | }; 43 | 44 | struct trafficgen_state { 45 | struct tcp_flowkey flow_key; 46 | __u16 next_port; 47 | }; 48 | 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /process-proxy/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 | 3 | USER_TARGETS := non_priviledged_process priviledged_process 4 | BPF_TARGETS := xdpsock_kern 5 | 6 | LDLIBS += -lpthread 7 | LIB_DIR = ../lib 8 | 9 | include $(LIB_DIR)/common.mk 10 | -------------------------------------------------------------------------------- /process-proxy/xdpsock.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 2 | * 3 | * Copyright(c) 2019 - 2022 Intel Corporation. 4 | */ 5 | 6 | #ifndef XDPSOCK_H_ 7 | #define XDPSOCK_H_ 8 | 9 | #define MAX_SOCKS 4 10 | 11 | #define SOCKET_NAME "sock_cal_bpf_fd" 12 | #define MAX_NUM_OF_CLIENTS 10 13 | 14 | #define CLOSE_CONN 1 15 | 16 | typedef __u64 u64; 17 | typedef __u32 u32; 18 | 19 | #endif /* XDPSOCK_H */ 20 | -------------------------------------------------------------------------------- /process-proxy/xdpsock_kern.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | #include 3 | #include 4 | #include "xdpsock.h" 5 | 6 | /* This XDP program is only needed for multi-buffer and XDP_SHARED_UMEM modes. 7 | * If you do not use these modes, libbpf can supply an XDP program for you. 8 | */ 9 | char LICENSE[] SEC("license") = "GPL"; 10 | struct { 11 | __uint(type, BPF_MAP_TYPE_XSKMAP); 12 | __uint(max_entries, MAX_SOCKS); 13 | __uint(key_size, sizeof(int)); 14 | __uint(value_size, sizeof(int)); 15 | } xsks_map SEC(".maps"); 16 | 17 | int num_socks = 0; 18 | static unsigned int rr; 19 | 20 | SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx) 21 | { 22 | rr = (rr + 1) & (num_socks - 1); 23 | return bpf_redirect_map(&xsks_map, rr, XDP_DROP); 24 | } 25 | --------------------------------------------------------------------------------