|  |  | @ -1,16 +1,16 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | use std::path::{Path, PathBuf}; |  |  |  | use std::path::{Path, PathBuf}; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | use anyhow::anyhow; |  |  |  | use anyhow::{Context as _, Result}; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | use aya_tool::{bindgen, write_to_file}; |  |  |  | use aya_tool::{bindgen, write_to_file}; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | use crate::codegen::{Architecture, SysrootOptions}; |  |  |  | use crate::codegen::{Architecture, SysrootOptions}; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyhow::Error> { |  |  |  | pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<()> { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     codegen_internal_btf_bindings(libbpf_dir)?; |  |  |  |     codegen_internal_btf_bindings(libbpf_dir)?; | 
			
		
	
		
		
			
				
					
					|  |  |  |     codegen_bindings(opts, libbpf_dir) |  |  |  |     codegen_bindings(opts, libbpf_dir) | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | fn codegen_internal_btf_bindings(libbpf_dir: &Path) -> Result<(), anyhow::Error> { |  |  |  | fn codegen_internal_btf_bindings(libbpf_dir: &Path) -> Result<()> { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     let dir = PathBuf::from("aya-obj"); |  |  |  |     let dir = PathBuf::from("aya-obj"); | 
			
		
	
		
		
			
				
					
					|  |  |  |     let generated = dir.join("src/generated"); |  |  |  |     let generated = dir.join("src/generated"); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -26,10 +26,7 @@ fn codegen_internal_btf_bindings(libbpf_dir: &Path) -> Result<(), anyhow::Error> | 
			
		
	
		
		
			
				
					
					|  |  |  |         bindgen = bindgen.allowlist_type(x); |  |  |  |         bindgen = bindgen.allowlist_type(x); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     let bindings = bindgen |  |  |  |     let bindings = bindgen.generate().context("bindgen failed")?.to_string(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         .generate() |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         .map_err(|op| anyhow!("bindgen failed - {op}"))? |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         .to_string(); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     // write the bindings, with the original helpers removed
 |  |  |  |     // write the bindings, with the original helpers removed
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     write_to_file(generated.join("btf_internal_bindings.rs"), &bindings)?; |  |  |  |     write_to_file(generated.join("btf_internal_bindings.rs"), &bindings)?; | 
			
		
	
	
		
		
			
				
					|  |  | @ -37,7 +34,7 @@ fn codegen_internal_btf_bindings(libbpf_dir: &Path) -> Result<(), anyhow::Error> | 
			
		
	
		
		
			
				
					
					|  |  |  |     Ok(()) |  |  |  |     Ok(()) | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyhow::Error> { |  |  |  | fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<()> { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     let SysrootOptions { |  |  |  |     let SysrootOptions { | 
			
		
	
		
		
			
				
					
					|  |  |  |         x86_64_sysroot, |  |  |  |         x86_64_sysroot, | 
			
		
	
		
		
			
				
					
					|  |  |  |         aarch64_sysroot, |  |  |  |         aarch64_sysroot, | 
			
		
	
	
		
		
			
				
					|  |  | @ -47,130 +44,151 @@ fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyh | 
			
		
	
		
		
			
				
					
					|  |  |  |         s390x_sysroot, |  |  |  |         s390x_sysroot, | 
			
		
	
		
		
			
				
					
					|  |  |  |         mips_sysroot, |  |  |  |         mips_sysroot, | 
			
		
	
		
		
			
				
					
					|  |  |  |     } = opts; |  |  |  |     } = opts; | 
			
		
	
		
		
			
				
					
					|  |  |  |     let types = [ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // BPF
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_TYPES", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_cmd", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_insn", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_attr", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_map_type", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_prog_type", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_attach_type", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_prog_info", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_map_info", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_link_info", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_link_type", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_btf_info", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_func_id", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_func_info", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_line_info", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_lpm_trie_key", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_cpumap_val", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_devmap_val", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_stats_type", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_perf_event_type", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_task_fd_type", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // BTF
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_header", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_ext_info", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_ext_info_sec", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_type", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_enum", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_array", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_member", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_param", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_var", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_var_secinfo", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_func_linkage", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "btf_decl_tag", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // PERF
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_event_attr", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_sw_ids", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_hw_id", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_hw_cache_id", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_hw_cache_op_id", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_hw_cache_op_result_id", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_event_sample_format", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_event_mmap_page", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_event_header", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_type_id", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "perf_event_type", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // NETLINK
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "ifinfomsg", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "tcmsg", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "nlmsgerr_attrs", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // ITER
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "bpf_cgroup_iter_order", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // NETFILTER
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "nf_inet_hooks", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     ]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     let vars = [ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // BPF
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_PSEUDO_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_ALU", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_ALU64", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_LDX", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_ST", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_STX", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_LD", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_K", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_X", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_DW", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_W", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_H", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_B", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_IMM", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_MEM", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_SUB", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_MOV", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_F_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_JMP", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_CALL", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_EXIT", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "SO_ATTACH_BPF", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "SO_DETACH_BPF", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // BTF
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BTF_INT_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BTF_KIND_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BTF_VAR_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // PERF
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "PERF_FLAG_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "PERF_EVENT_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "PERF_MAX_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // NETLINK
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "NLMSG_ALIGNTO", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "IFLA_XDP_FD", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TCA_KIND", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TCA_OPTIONS", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TCA_BPF_FD", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TCA_BPF_NAME", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TCA_BPF_FLAGS", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TCA_BPF_FLAG_ACT_DIRECT", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "XDP_FLAGS_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TC_H_MAJ_MASK", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TC_H_MIN_MASK", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TC_H_UNSPEC", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TC_H_ROOT", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TC_H_INGRESS", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TC_H_CLSACT", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TC_H_MIN_PRIORITY", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TC_H_MIN_INGRESS", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "TC_H_MIN_EGRESS", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // Ringbuf
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "BPF_RINGBUF_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // NETFILTER
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         "NFPROTO_.*", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     ]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     let dir = PathBuf::from("aya-obj"); |  |  |  |     let dir = PathBuf::from("aya-obj"); | 
			
		
	
		
		
			
				
					
					|  |  |  |     let generated = dir.join("src/generated"); |  |  |  |     let generated = dir.join("src/generated"); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     let builder = || { |  |  |  |     let builder = || { | 
			
		
	
		
		
			
				
					
					|  |  |  |         bindgen::user_builder() |  |  |  |         let mut bindgen = bindgen::user_builder() | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             .header(dir.join("include/linux_wrapper.h").to_str().unwrap()) |  |  |  |             .header(dir.join("include/linux_wrapper.h").to_str().unwrap()) | 
			
		
	
		
		
			
				
					
					|  |  |  |             .clang_args(["-I", libbpf_dir.join("include/uapi").to_str().unwrap()]) |  |  |  |             .clang_args(["-I", libbpf_dir.join("include/uapi").to_str().unwrap()]) | 
			
		
	
		
		
			
				
					
					|  |  |  |             .clang_args(["-I", libbpf_dir.join("include").to_str().unwrap()]) |  |  |  |             .clang_args(["-I", libbpf_dir.join("include").to_str().unwrap()]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // BPF_F_LINK is defined twice. Once in an anonymous enum
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // which bindgen will constify, and once via #define macro
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // which generates a duplicate const.
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             .blocklist_var("BPF_F_LINK") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             .constified_enum("BPF_F_.*") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             .constified_enum("BTF_KIND_.*") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             .constified_enum("BTF_VAR_.*") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             .constified_enum("IFLA_.*") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             .constified_enum("TCA_.*") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             .constified_enum("BPF_RINGBUF_.*") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // NETFILTER
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             .constified_enum("NFPROTO_.*"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         let types = [ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // BPF
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_cmd", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_insn", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_attr", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_map_type", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_prog_type", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_attach_type", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_prog_info", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_map_info", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_link_info", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_link_type", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_btf_info", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_func_id", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_func_info", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_line_info", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_lpm_trie_key", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_cpumap_val", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_devmap_val", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_stats_type", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_perf_event_type", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_task_fd_type", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // BTF
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_header", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_ext_info", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_ext_info_sec", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_type", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_enum", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_array", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_member", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_param", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_var", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_var_secinfo", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_func_linkage", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "btf_decl_tag", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // PERF
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_event_attr", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_sw_ids", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_hw_id", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_hw_cache_id", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_hw_cache_op_id", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_hw_cache_op_result_id", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_event_sample_format", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_event_mmap_page", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_event_header", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_type_id", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "perf_event_type", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // NETLINK
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "ifinfomsg", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "tcmsg", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "nlmsgerr_attrs", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // ITER
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "bpf_cgroup_iter_order", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // NETFILTER
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "nf_inet_hooks", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         ]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         let vars = [ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // BPF
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_PSEUDO_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_ALU", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_ALU64", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_LDX", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_ST", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_STX", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_LD", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_K", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_X", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_DW", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_W", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_H", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_B", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_IMM", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_MEM", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_SUB", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_MOV", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_F_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_JMP", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_CALL", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_EXIT", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "SO_ATTACH_BPF", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "SO_DETACH_BPF", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // BTF
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BTF_INT_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BTF_KIND_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BTF_VAR_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // PERF
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "PERF_FLAG_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "PERF_EVENT_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "PERF_MAX_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // NETLINK
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "NLMSG_ALIGNTO", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "IFLA_XDP_FD", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TCA_KIND", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TCA_OPTIONS", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TCA_BPF_FD", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TCA_BPF_NAME", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TCA_BPF_FLAGS", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TCA_BPF_FLAG_ACT_DIRECT", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "XDP_FLAGS_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TC_H_MAJ_MASK", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TC_H_MIN_MASK", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TC_H_UNSPEC", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TC_H_ROOT", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TC_H_INGRESS", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TC_H_CLSACT", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TC_H_MIN_PRIORITY", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TC_H_MIN_INGRESS", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "TC_H_MIN_EGRESS", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // Ringbuf
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "BPF_RINGBUF_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // NETFILTER
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             "NFPROTO_.*", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         ]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         for x in &types { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             bindgen = bindgen.allowlist_type(x); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         for x in &vars { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             bindgen = bindgen.allowlist_var(x); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         bindgen | 
			
		
	
		
		
			
				
					
					|  |  |  |     }; |  |  |  |     }; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for arch in Architecture::supported() { |  |  |  |     for arch in Architecture::supported() { | 
			
		
	
	
		
		
			
				
					|  |  | @ -202,38 +220,7 @@ fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyh | 
			
		
	
		
		
			
				
					
					|  |  |  |         }; |  |  |  |         }; | 
			
		
	
		
		
			
				
					
					|  |  |  |         bindgen = bindgen.clang_args(["-I", sysroot.to_str().unwrap()]); |  |  |  |         bindgen = bindgen.clang_args(["-I", sysroot.to_str().unwrap()]); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         for x in &types { |  |  |  |         let bindings = bindgen.generate().context("bindgen failed")?.to_string(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             bindgen = bindgen.allowlist_type(x); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         for x in &vars { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             bindgen = bindgen |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .allowlist_var(x) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // BPF_F_LINK is defined twice. Once in an anonymous enum
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // which bindgen will constify, and once via #define macro
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // which generates a duplicate const.
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .blocklist_var("BPF_F_LINK") |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .constified_enum("BPF_F_.*") |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .constified_enum("BTF_KIND_.*") |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .constified_enum("BTF_VAR_.*") |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .constified_enum("IFLA_.*") |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .constified_enum("TCA_.*") |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .constified_enum("BPF_RINGBUF_.*") |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // NETFILTER
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .constified_enum("NFPROTO_.*"); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         for x in &types { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             bindgen = bindgen.allowlist_type(x); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         for x in &vars { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             bindgen = bindgen.allowlist_var(x); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         let bindings = bindgen |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             .generate() |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             .map_err(|op| anyhow!("bindgen failed - {op}"))? |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             .to_string(); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         // write the bindings, with the original helpers removed
 |  |  |  |         // write the bindings, with the original helpers removed
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         write_to_file( |  |  |  |         write_to_file( | 
			
		
	
	
		
		
			
				
					|  |  | 
 |