### Example: Accessing RingBufItem Data Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/ring-buf.md Demonstrates how to get a RingBufItem and access its raw byte data for further processing. ```rust if let Some(item) = ring_buf.next_packet()? { let data = item.data(); let event = parse_event(data)?; } ``` -------------------------------- ### Complete Configuration Example Source: https://github.com/aya-rs/aya/blob/main/_autodocs/configuration.md A comprehensive example demonstrating various configuration options for loading eBPF programs, including BTF, map, global variable, program, verifier, and unsupported map configurations. ```rust use aya::{EbpfLoader, Btf, Endianness, VerifierLogLevel}; use std::path::Path; let btf = Btf::from_sys_fs().ok(); let ebpf = EbpfLoader::new() // BTF Configuration .btf(btf.as_ref()) // Map Configuration .default_map_pin_directory("/sys/fs/bpf/my-app") .map_max_entries("event_buffer", 8192) .map_max_entries("stats_map", 10000) .map_pin_path("config_map", "/etc/bpf/config") // Global Variables .override_global("SAMPLE_RATE", &50u32, false) .override_global("LOG_LEVEL", &1u32, false) .override_global("DISABLED_PIDS", &[1u32, 2u32], true) // Program Configuration .extension("override_fn") // Verifier Configuration .verifier_log_level(VerifierLogLevel::DEBUG | VerifierLogLevel::STATS) // Unsupported Maps .allow_unsupported_maps() // Load .load_file("my_program.o")?; ``` -------------------------------- ### Commit Message Examples Source: https://github.com/aya-rs/aya/blob/main/CONTRIBUTING.md Examples of well-formatted commit messages, including prefixes for subcrates and issue references. ```text subcrate: explain the commit in one line Body of commit message is a few lines of text, explaining things in more detail, possibly giving some background about the issue being fixed, etc. The body of the commit message can be several paragraphs, and please do proper word-wrap and keep columns shorter than about 72 characters or so. That way, `git log` will show things nicely even when it is indented. Fixes: #1337 Refs: #453, #154 ``` -------------------------------- ### bpf_timer_start Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya-ebpf-bindings.txt Starts a timer. Activates a timer to begin counting down. ```APIDOC ## bpf_timer_start ### Description Starts a timer. Activates a timer to begin counting down. ### Signature `pub unsafe fn bpf_timer_start(*mut bpf_timer, __u64, __u64) -> c_long` ``` -------------------------------- ### Sample Verifier Output (VERBOSE) Source: https://github.com/aya-rs/aya/blob/main/_autodocs/configuration.md An example of the detailed diagnostic output from the kernel BPF verifier when set to `VERBOSE` level. ```text 0: (b7) r0 = 1 1: (bf) r1 = r10 2: (07) r1 += -8 3: (b7) r2 = 8 4: (85) call bpf_map_update_elem#2 function bpf_map_update_elem#2 arg1 correct ``` -------------------------------- ### Create New EbpfLoader Instance Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/ebpf-loader.md Initializes a new EbpfLoader with default settings. BTF is automatically loaded if available. ```rust use aya::EbpfLoader; let loader = EbpfLoader::new(); ``` -------------------------------- ### BPF Header Start Offsets Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya-ebpf-bindings.txt Constants defining the start offsets for BPF headers, specifically for MAC and network layers. ```APIDOC ## BPF_HDR_START_OFF ### Description Constants related to the starting offsets of BPF headers. ### Constants - **BPF_HDR_START_MAC**: Type `aya_ebpf_bindings::bindings::bpf_hdr_start_off::Type` - **BPF_HDR_START_NET**: Type `aya_ebpf_bindings::bindings::bpf_hdr_start_off::Type` ### Type Alias - **Type**: `aya_ebpf_cty::ad::c_uint` ``` -------------------------------- ### DevMap Methods Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides methods for interacting with device maps, including getting values, iteration, getting the length, pinning, and setting values. ```APIDOC ## DevMap::get ### Description Retrieves a value from the device map at a given index. ### Method `get(&self, index: u32, flags: u64)` ### Parameters - **index** (u32): The index of the value to retrieve. - **flags** (u64): Flags for the get operation. ### Returns A `Result` containing the retrieved value or an error. ## DevMap::iter ### Description Returns an iterator over the entries in the device map. ### Method `iter(&self)` ### Parameters None ### Returns An iterator yielding `Result`. ## DevMap::len ### Description Returns the number of entries in the device map. ### Method `len(&self)` ### Parameters None ### Returns A `u32` representing the number of entries. ## DevMap::pin ### Description Pins the device map to a specific path. ### Method `pin>(self, path: P)` ### Parameters - **path** (P): The path to pin the map to. ### Returns A `Result<(), PinError>` indicating success or failure. ## DevMap::set ### Description Sets a value in the device map at a given index. ### Method `set(&mut self, index: u32, value: u32, program: Option<&ProgramFd>, flags: u64)` ### Parameters - **index** (u32): The index to set the value at. - **value** (u32): The value to set. - **program** (Option<&ProgramFd>): An optional program file descriptor. - **flags** (u64): Flags for the set operation. ### Returns A `Result<(), XdpMapError>` indicating success or failure. ``` -------------------------------- ### XDP Load Balancing Setup Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/xdp.md Configures an XDP program for load balancing by initializing a CPU map and attaching the program to a network interface in driver mode. ```rust use aya::maps::CpuMap; let mut ebpf = Ebpf::load_file("xdp_lb.o")?; let prog: &mut Xdp = ebpf.program_mut("xdp_load_balance")?.try_into()?; prog.load()?; // Configure CPU map for load balancing let mut cpu_map: CpuMap<_> = ebpf.map_mut("cpus")?.try_into()?; for cpu in 0..num_cpus::get() as u32 { cpu_map.insert(&cpu, &cpu, 0)?; } // Attach prog.attach("eth0", XdpMode::Drv)?; ``` -------------------------------- ### EbpfLoader::new() Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/ebpf-loader.md Creates a new EbpfLoader instance with default settings. BTF is automatically loaded if available. ```APIDOC ## EbpfLoader::new() ### Description Creates a new loader with default settings. BTF is automatically loaded from `/sys/kernel/btf/vmlinux` if available. ### Returns New EbpfLoader instance ### Example ```rust use aya::EbpfLoader; let loader = EbpfLoader::new(); ``` ``` -------------------------------- ### Get Read-Only Program Reference Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/ebpf.md Use `program()` to get a read-only reference to an eBPF program by its name. The returned `Program` enum needs to be converted to a specific program type for further use. ```rust pub fn program(&self, name: &str) -> Option<&Program> ``` ```rust if let Some(prog) = ebpf.program("my_program") { // Inspect program details } ``` -------------------------------- ### Get Read-Only eBPF Map Reference Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/ebpf.md Use `map()` to get a read-only reference to an eBPF map by its name. The returned `Map` type is opaque and requires conversion for specific operations. ```rust if let Some(map) = ebpf.map("my_map") { // Work with the map } ``` -------------------------------- ### Lsm::from_program_info Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Creates a new Lsm program instance from existing program information. ```APIDOC ## Lsm::from_program_info ### Description Creates a new Lsm program instance from existing program information. ### Method `Lsm::from_program_info(ProgramInfo, Cow<'static, str>) -> Result` ### Parameters * `ProgramInfo`: Information about the program. * `Cow<'static, str>`: A static string representing the program name. ### Returns A `Result` containing the `Lsm` instance on success, or a `ProgramError` on failure. ``` -------------------------------- ### bpf_timer_init Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya-ebpf-bindings.txt Initializes a timer. Sets up a timer for future use. ```APIDOC ## bpf_timer_init ### Description Initializes a timer. Sets up a timer for future use. ### Signature `pub unsafe fn bpf_timer_init(*mut bpf_timer, *mut c_void, __u64) -> c_long` ``` -------------------------------- ### Test Integration VM Kernels Source: https://github.com/aya-rs/aya/blob/main/test/kernel/README.md After modifying a KCONFIG fragment and rebuilding the resolved configurations, run this command to test both the aarch64 and x86_64 integration VM kernels. ```bash $ bazel test --config=remote --lockfile_mode=error \ //test/integration-test:vm_aarch64 \ //test/integration-test:vm_x86_64 ``` -------------------------------- ### XdpLink::id Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the ID of the XDP link. ```APIDOC ## XdpLink::id ### Description Returns the unique identifier of the XDP link. ### Method `pub fn id(&self) -> Self::Id` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage (assuming `xdp_link` is an instance of `aya::programs::xdp::XdpLink`) // let link_id = xdp_link.id(); ``` ### Response #### Success Response (200) - **Self::Id** (type): The `XdpLinkId` of the link. #### Response Example ```json // Success response would be an XdpLinkId // Example: 1 ``` ### Error Handling None. ``` -------------------------------- ### LsmLink::id Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the unique identifier of the LsmLink. ```APIDOC ## LsmLink::id ### Description Returns the unique identifier for this LsmLink. ### Signature `pub fn aya::programs::lsm_cgroup::LsmLink::id(&self) -> Self::Id` ### Returns The `LsmLinkId` associated with this link. ``` -------------------------------- ### Load and Attach CGroupsSkb Program with Aya Source: https://github.com/aya-rs/aya/blob/main/aya/README.md Demonstrates loading an eBPF object file, retrieving a CgroupSkb program, loading it into the kernel, and attaching it to a cgroup for ingress traffic. ```rust use std::fs::File; use aya::Ebpf; use aya::programs::{CgroupSkb, CgroupSkbAttachType}; // load the BPF code let mut ebpf = Ebpf::load_file("bpf.o")?; // get the `ingress_filter` program compiled into `bpf.o`. let ingress: &mut CgroupSkb = ebpf.program_mut("ingress_filter")?.try_into()?; // load the program into the kernel ingress.load()?; // attach the program to the root cgroup. `ingress_filter` will be called for all // incoming packets. let cgroup = File::open("/sys/fs/cgroup/unified")?; ingress.attach(cgroup, CgroupSkbAttachType::Ingress)?; ``` -------------------------------- ### Xdp::from_program_info Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Creates an XDP program from program information. ```APIDOC ## Xdp::from_program_info ### Description Constructs an `Xdp` program instance from existing `ProgramInfo`, a name, and an attach type. ### Method `pub fn from_program_info(info: ProgramInfo, name: Cow<'static, str>, attach_type: XdpAttachType) -> Result` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage (assuming `program_info` is an instance of `ProgramInfo`) // let xdp_program = Xdp::from_program_info(program_info, "my_xdp_prog".into(), XdpAttachType::Skb).unwrap(); ``` ### Response #### Success Response (200) - **Self** (type): An instance of `aya::programs::xdp::Xdp`. #### Response Example ```json // Success response would be an Xdp instance ``` ### Error Handling - **ProgramError**: If the creation from program info fails. ``` -------------------------------- ### MultiProgram Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides a method to get the file descriptor of a MultiProgram. ```APIDOC ## MultiProgram ### Description Represents a program that can manage multiple sub-programs. ### Methods - `fd(&self)`: Returns the file descriptor of the MultiProgram. ``` -------------------------------- ### SockOps::from_program_info Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Creates a SockOps program instance from program information. ```APIDOC ## SockOps::from_program_info ### Description Constructs a `SockOps` program instance from existing program information. ### Method `from_program_info` ### Parameters - `info`: The `ProgramInfo` of the existing program. - `name`: A static string slice representing the name of the program. ### Returns A `Result` containing the `SockOps` instance on success, or a `ProgramError` on failure. ``` -------------------------------- ### SchedClassifierLink Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides a method to get the file descriptor of a SchedClassifierLink. ```APIDOC ## SchedClassifierLink ### Description Represents a link to a TC (Traffic Control) classifier program. ### Methods - `fd(&self)`: Returns the file descriptor of the SchedClassifierLink. ``` -------------------------------- ### MultiProgLink Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides a method to get the file descriptor of a MultiProgLink. ```APIDOC ## MultiProgLink ### Description Represents a link that can hold multiple programs. ### Methods - `fd(&self)`: Returns the file descriptor of the MultiProgLink. ``` -------------------------------- ### SockOps::from_program_info Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Creates a SockOps program instance from existing program information and a name. ```APIDOC ## SockOps::from_program_info ### Description Creates a SockOps program instance from existing program information. ### Method `pub fn from_program_info(aya::programs::ProgramInfo, alloc::borrow::Cow<'static, str>) -> core::result::Result` ### Parameters - `aya::programs::ProgramInfo`: Information about the program. - `alloc::borrow::Cow<'static, str>`: The name of the program. ### Returns - `core::result::Result`: Ok containing the `SockOps` instance on success, or an `Err` with `ProgramError` on failure. ``` -------------------------------- ### Using ProbeKind with KProbe Source: https://github.com/aya-rs/aya/blob/main/_autodocs/types.md Demonstrates how to check the kind of a KProbe program. Ensure the KProbe program is loaded and accessible before matching its kind. ```rust use aya::programs::{KProbe, ProbeKind}; let prog: &mut KProbe = ebpf.program_mut("trace")?.try_into()?; match prog.kind() { ProbeKind::Entry => println!("Function entry probe"), ProbeKind::Return => println!("Function return probe"), } ``` -------------------------------- ### XdpLink Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides methods to detach and get the ID of an XdpLink. ```APIDOC ## XdpLink ### Description Represents a link to an XDP (eXpress Data Path) program. ### Methods - `detach(self)`: Detaches the XdpLink. - `id(&self)`: Returns the ID of the XdpLink. ### Types - `Id`: Alias for `aya::programs::xdp::XdpLinkId` ``` -------------------------------- ### UProbeLink Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides methods to detach and get the ID of a UProbeLink. ```APIDOC ## UProbeLink ### Description Represents a link to a user-space probe (uprobe) program. ### Methods - `detach(self)`: Detaches the UProbeLink. - `id(&self)`: Returns the ID of the UProbeLink. ### Types - `Id`: Alias for `aya::programs::uprobe::UProbeLinkId` ``` -------------------------------- ### CgroupSkb::from_program_info Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Creates a CgroupSkb program from existing program information. ```APIDOC ## CgroupSkb::from_program_info ### Description Constructs a `CgroupSkb` instance from `ProgramInfo`, a program name, and an optional attach type. This is useful when you have program metadata but not the program object itself. ### Method `pub fn from_program_info(aya::programs::ProgramInfo, alloc::borrow::Cow<'static, str>, core::option::Option) -> core::result::Result` ### Parameters - `aya::programs::ProgramInfo`: Information about the program. - `alloc::borrow::Cow<'static, str>`: The name of the program. - `core::option::Option`: An optional expected attach type. ### Returns - `core::result::Result`: On success, returns a `CgroupSkb` instance; otherwise, returns a `ProgramError`. ``` -------------------------------- ### Load and Attach eBPF Program Source: https://github.com/aya-rs/aya/blob/main/_autodocs/README.md Demonstrates the workflow for loading an eBPF program from an ELF file, converting it to a specific type, loading it into the kernel, and attaching it to a target function. ```rust let mut ebpf = Ebpf::load_file("program.elf")?; let prog: KProbe = ebpf.program("my_program")?.try_into()?; prog.load()?; prog.attach("target_fn", 0)?; ``` -------------------------------- ### TracePointLink Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides methods to detach and get the ID of a TracePointLink. ```APIDOC ## TracePointLink ### Description Represents a link to a tracepoint program. ### Methods - `detach(self)`: Detaches the TracePointLink. - `id(&self)`: Returns the ID of the TracePointLink. ### Types - `Id`: Alias for `aya::programs::trace_point::TracePointLinkId` ``` -------------------------------- ### Lsm::from_pin Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Creates a new Lsm program instance from a given file path. ```APIDOC ## Lsm::from_pin ### Description Creates a new Lsm program instance from a given file path. ### Method `Lsm::from_pin>(P) -> Result` ### Parameters * `P`: A type that can be converted into a reference to a Path. ### Returns A `Result` containing the `Lsm` instance on success, or a `ProgramError` on failure. ``` -------------------------------- ### BtfTracePointLink Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides methods to detach and get the ID of a BtfTracePointLink. ```APIDOC ## BtfTracePointLink ### Description Represents a link to a BTF tracepoint program. ### Methods - `detach(self)`: Detaches the BtfTracePointLink. - `id(&self)`: Returns the ID of the BtfTracePointLink. ### Types - `Id`: Alias for `aya::programs::tp_btf::BtfTracePointLinkId` ``` -------------------------------- ### Basic KProbe Attachment Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/kprobe.md Demonstrates loading an eBPF object file and attaching a kprobe to a kernel function. Ensure the eBPF object file exists and the target function name is correct. ```rust use aya::{Ebpf, programs::KProbe}; let mut ebpf = Ebpf::load_file("ebpf.o")?; // Get mutable reference and convert to KProbe type let prog: &mut KProbe = ebpf .program_mut("trace_syscall") .unwrap() .try_into()?; // Load into kernel prog.load()?; // Attach to kernel function prog.attach("sys_openat", 0)?; println!("KProbe attached: {:?}", prog.kind()); ``` -------------------------------- ### Xdp::fd Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the file descriptor of the XDP program. ```APIDOC ## Xdp::fd ### Description Returns the file descriptor associated with the loaded XDP program. ### Method `pub fn fd(&self) -> Result<&ProgramFd, ProgramError>` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage (assuming `xdp_program` is an instance of `aya::programs::xdp::Xdp`) // let fd = xdp_program.fd().unwrap(); ``` ### Response #### Success Response (200) - **&ProgramFd** (type): A reference to the program's file descriptor. #### Response Example ```json // Success response would be a ProgramFd (file descriptor integer) // Example: 3 ``` ### Error Handling - **ProgramError**: If retrieving the file descriptor fails. ``` -------------------------------- ### Convert Opaque Program Enum to KProbe (Pattern Match) Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/programs-overview.md This example illustrates converting an opaque `Program` enum to a `KProbe` by using a `match` statement. This is a flexible approach, especially when dealing with multiple possible program types or when you need to handle different program types within the same block of code. ```rust // Option 3: pattern match match ebpf.program_mut("name")? { aya::programs::Program::KProbe(prog) => { /* ... */ } _ => {} } ``` -------------------------------- ### SchedClassifier::fd Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the file descriptor of the TC program. ```APIDOC ## SchedClassifier::fd ### Description Retrieves the file descriptor associated with the TC program. ### Method `pub fn fd(&self) -> core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError>` ### Returns - `core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError>`: On success, returns a reference to the `ProgramFd`. On failure, returns a `ProgramError`. ``` -------------------------------- ### LsmCgroup::fd Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the file descriptor of the LsmCgroup program. ```APIDOC ## LsmCgroup::fd ### Description Returns the file descriptor associated with the LsmCgroup program. ### Signature `pub fn aya::programs::lsm_cgroup::LsmCgroup::fd(&self) -> core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError>` ### Returns A `core::result::Result` which is `Ok(&aya::programs::ProgramFd)` on success, containing a reference to the program's file descriptor, or `Err(aya::programs::ProgramError)` on failure. ``` -------------------------------- ### Configure eBPF Loader Source: https://github.com/aya-rs/aya/blob/main/_autodocs/README.md Demonstrates configuring an EbpfLoader with various options including BTF, map pinning, map tuning, global variable overrides, and verifier log level. ```rust use aya::{EbpfLoader, VerifierLogLevel}; let ebpf = EbpfLoader::new() // Custom BTF .btf(btf.as_ref()) // Map pinning .default_map_pin_directory("/sys/fs/bpf/my-app") // Map tuning .map_max_entries("events", 65536) // Global variables .override_global("DEBUG", &1u32, false) .override_global("SAMPLE_RATE", &100u32, false) // Verifier output .verifier_log_level(VerifierLogLevel::DEBUG) // Load .load_file("program.o")?; ``` -------------------------------- ### Build x86_64 Integration VM Kernel Configuration Source: https://github.com/aya-rs/aya/blob/main/test/kernel/README.md Use this command to resolve the x86_64 KCONFIG fragment. The resolved configuration will be available at bazel-bin/test/kernel/aya_kernel_x86_64_config.config_tree/.config. ```bash $ bazel build --lockfile_mode=error \ --platforms=@rules_rs//rs/platforms:x86_64-unknown-linux-musl \ //test/kernel:aya_kernel_x86_64_config ``` -------------------------------- ### Lsm::fd Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the file descriptor of the LSM program. ```APIDOC ## Lsm::fd ### Description Gets the file descriptor of the LSM program. ### Method `Lsm::fd(&self) -> Result<&ProgramFd, ProgramError>` ### Returns A `Result` containing a reference to the `ProgramFd` on success, or a `ProgramError` on failure. ``` -------------------------------- ### aya::test_helpers::Cgroup::root Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the root cgroup path. ```APIDOC ## aya::test_helpers::Cgroup::root ### Description Gets the root cgroup path. ### Signature `pub fn root() -> aya::test_helpers::AyaTestResult` ``` -------------------------------- ### Program Type Conversions Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Demonstrates how to attempt conversion of a generic `Program` into specific program types like CgroupDevice, CgroupSkb, etc. ```APIDOC ## Program Type Conversions ### `try_from::()` **Description**: Attempts to convert a `Program` into a `CgroupDevice`. **Returns**: A `Result` containing a reference to `CgroupDevice` or a `ProgramError`. ### `try_from::()` **Description**: Attempts to convert a `Program` into a `CgroupSkb`. **Returns**: A `Result` containing a reference to `CgroupSkb` or a `ProgramError`. ### `try_from::()` **Description**: Attempts to convert a `Program` into a `CgroupSock`. **Returns**: A `Result` containing a reference to `CgroupSock` or a `ProgramError`. ### `try_from::()` **Description**: Attempts to convert a `Program` into a `CgroupSockAddr`. **Returns**: A `Result` containing a reference to `CgroupSockAddr` or a `ProgramError`. ### `try_from::()` **Description**: Attempts to convert a `Program` into a `CgroupSockopt`. **Returns**: A `Result` containing a reference to `CgroupSockopt` or a `ProgramError`. ### `try_from::()` **Description**: Attempts to convert a `Program` into a `CgroupSysctl`. **Returns**: A `Result` containing a reference to `CgroupSysctl` or a `ProgramError`. ### `try_from::()` **Description**: Attempts to convert a `Program` into an `Extension`. **Returns**: A `Result` containing a reference to `Extension` or a `ProgramError`. ``` -------------------------------- ### SockOps::fd Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the file descriptor associated with the SockOps program. ```APIDOC ## SockOps::fd ### Description Retrieves the file descriptor of the SockOps program. ### Method `fd` ### Returns A `Result` containing a reference to the `ProgramFd` on success, or a `ProgramError` on failure. ``` -------------------------------- ### Basic HashMap Operations Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/hash-map.md Demonstrates basic operations on a HashMap, including insertion, retrieval, iteration, and removal of key-value pairs. Ensure the HashMap is correctly initialized and loaded. ```rust use aya::{Ebpf, maps::HashMap}; let mut ebpf = Ebpf::load_file("ebpf.o")?; let mut port_map: HashMap<_, u16, u32> = ebpf.map_mut("port_map")?.try_into()?; // Insert values port_map.insert(&80, &8080, 0)?; port_map.insert(&443, &8443, 0)?; // Get a value if let Ok(mapped_port) = port_map.get(&80, 0) { println!("Port 80 maps to {}", mapped_port); } // Iterate for result in port_map.iter() { let (port, mapped_to) = result?; println!("Port {} -> {}", port, mapped_to); } // Remove port_map.remove(&80)?; ``` -------------------------------- ### Load and Attach Aya Program Source: https://github.com/aya-rs/aya/blob/main/_autodocs/api-reference/programs-overview.md This snippet demonstrates the typical pattern for loading an Ebpf program, getting a mutable reference to a specific program type (KProbe in this case), loading it into the kernel, and attaching it to a target function. It also shows optional detachment. ```rust use aya::{Ebpf, programs::KProbe}; let mut ebpf = Ebpf::load_file("program.o")?; // Get mutable reference to program let prog: &mut KProbe = ebpf .program_mut("my_program") .unwrap() .try_into()?; // Load the program into kernel prog.load()?; // Attach to target let link_id = prog.attach("target_function", 0)?; // Use program... // Optionally detach prog.detach(link_id)?; ``` -------------------------------- ### CgroupSockopt::fd Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the file descriptor associated with the CgroupSockopt program. ```APIDOC ## CgroupSockopt::fd ### Description Gets the file descriptor associated with the CgroupSockopt program. ### Method `fd(&self) -> core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError>` ### Returns A `core::result::Result` containing a reference to the `ProgramFd` on success, or a `aya::programs::ProgramError` on failure. ``` -------------------------------- ### CgroupSkb::fd Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the file descriptor of the loaded CgroupSkb program. ```APIDOC ## CgroupSkb::fd ### Description Returns the file descriptor associated with the loaded CgroupSkb program. This can be useful for lower-level operations or debugging. ### Method `pub fn fd(&self) -> core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError>` ### Returns - `core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError>`: A reference to the program's file descriptor on success, or a `ProgramError`. ``` -------------------------------- ### Ebpf (Main Entry Point) Source: https://github.com/aya-rs/aya/blob/main/_autodocs/INDEX.md Core functionalities for loading and accessing eBPF programs and maps. ```APIDOC ## Ebpf (Main Entry Point) ### Description Provides the primary interface for loading eBPF bytecode and accessing its components. ### Methods - `load_file(path: &str) -> Result`: Load eBPF bytecode from a file. - `load(buffer: &[u8]) -> Result`: Load eBPF bytecode from a byte buffer. - `map(&self, name: &str) -> Option<&Map>`: Get an immutable reference to a map by name. - `map_mut(&mut self, name: &str) -> Option<&mut Map>`: Get a mutable reference to a map by name. - `take_map(&mut self, name: &str) -> Option`: Take ownership of a map by name. - `program(&self, name: &str) -> Option<&Program>`: Get an immutable reference to a program by name. - `program_mut(&mut self, name: &str) -> Option<&mut Program>`: Get a mutable reference to a program by name. - `take_program(&mut self, name: &str) -> Option`: Take ownership of a program by name. - `programs(&self) -> impl Iterator`: Iterate over all loaded programs. - `maps(&self) -> impl Iterator`: Iterate over all loaded maps. ``` -------------------------------- ### Run Local Integration Tests Source: https://github.com/aya-rs/aya/blob/main/test/README.md Execute integration tests on the local machine. Ensure you are in the root of the repository. ```bash cargo xtask integration-test local ``` -------------------------------- ### LpmTrie Operations Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Operations specific to LpmTrie, including getting elements. ```APIDOC ## get LpmTrie ### Description Retrieves a value from the LpmTrie using a key. ### Method `get` ### Parameters - `&aya::maps::lpm_trie::Key`: The key to look up. ### Returns - `core::result::Result`: A result containing the value on success or a MapError on failure. ``` -------------------------------- ### SkReuseport::from_program_info Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Creates a new SkReuseport program instance from existing program information. ```APIDOC ## SkReuseport::from_program_info ### Description Creates a new SkReuseport program instance from existing program information. ### Method `pub fn from_program_info(aya::programs::ProgramInfo, alloc::borrow::Cow<'static, str>, aya_obj::programs::sk_reuseport::SkReuseportAttachType) -> core::result::Result` ### Parameters - `program_info`: Information about the program. - `name`: The name of the program. - `attach_type`: The type of attachment for the SkReuseport program. ### Returns - `Ok(SkReuseport)` on successful creation. - `Err(aya::programs::ProgramError)` on failure. ``` -------------------------------- ### PerCpuHashMap Operations Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Operations specific to PerCpuHashMap, including getting elements. ```APIDOC ## get PerCpuHashMap ### Description Retrieves PerCpuValues from the PerCpuHashMap using a key. ### Method `get` ### Parameters - `&K`: The key to look up. ### Returns - `core::result::Result, aya::maps::MapError>`: A result containing the PerCpuValues on success or a MapError on failure. ## map PerCpuHashMap ### Description Provides access to the underlying map data for the PerCpuHashMap. ### Method `map` ### Returns - `&aya::maps::MapData`: A reference to the map data. ``` -------------------------------- ### HashMap Get Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Retrieves a value associated with a given key from the HashMap. ```APIDOC ## HashMap::get ### Description Retrieves a value from the HashMap using its key. ### Signature `pub fn get(&self, &K, u64) -> core::result::Result` ### Parameters - `&K`: A reference to the key to look up. - `u64`: Unknown parameter, possibly a flag or identifier. ### Returns A `Result` containing the value associated with the key on success, or a `MapError` on failure. ``` -------------------------------- ### CgroupSkb::try_from<&aya::programs::Program> Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Attempts to create a CgroupSkb program from a generic Program reference. ```APIDOC ## CgroupSkb::try_from<&'a aya::programs::Program> ### Description Attempts to convert a generic `&'a aya::programs::Program` into a `&'a aya::programs::cgroup_skb::CgroupSkb`. This is useful when dealing with programs of unknown types that are expected to be CgroupSkb programs. ### Method `pub fn try_from(&'a aya::programs::Program) -> core::result::Result<&'a aya::programs::cgroup_skb::CgroupSkb, aya::programs::ProgramError>` ### Parameters - `&'a aya::programs::Program`: A reference to a generic program. ### Returns - `core::result::Result<&'a aya::programs::cgroup_skb::CgroupSkb, aya::programs::ProgramError>`: On success, returns a reference to the `CgroupSkb`; otherwise, returns a `ProgramError`. ``` -------------------------------- ### aya::programs::iter::Iter TryFrom Implementations Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides conversion methods to create an `Iter` from a `Program`. ```APIDOC ## `aya::programs::iter::Iter::try_from` (from `&aya::programs::Program`) ### Description Attempts to create an immutable reference to an `Iter` from an immutable reference to a `Program`. ### Method `try_from` ### Parameters - `program` (&'a aya::programs::Program) - Required - The program to convert from. ### Returns - `core::result::Result<&'a aya::programs::iter::Iter, aya::programs::ProgramError>` - Ok with an `Iter` reference if successful, ProgramError otherwise. ## `aya::programs::iter::Iter::try_from` (from `&mut aya::programs::Program`) ### Description Attempts to create a mutable reference to an `Iter` from a mutable reference to a `Program`. ### Method `try_from` ### Parameters - `program` (&'a mut aya::programs::Program) - Required - The program to convert from. ### Returns - `core::result::Result<&'a mut aya::programs::iter::Iter, aya::programs::ProgramError>` - Ok with a mutable `Iter` reference if successful, ProgramError otherwise. ``` -------------------------------- ### DevMap Get Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Retrieves a value from a DevMap, which is used for device-related operations. ```APIDOC ## DevMap::get ### Description Retrieves a `DevMapValue` from the `DevMap` at a given index and device identifier. This is used for device-specific map operations. ### Method `get(&self, u32, u64) -> Result` ### Parameters - `index`: A `u32` representing the index within the map. - `device_id`: A `u64` representing the device identifier. ### Response - `Result`: A `Result` containing the `DevMapValue` on success, or a `MapError` if the retrieval fails. ### Error Handling - `aya::maps::MapError`: Returned if there is an error accessing the map data. ``` -------------------------------- ### aya::test_helpers::ChildCgroup::fd Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the file descriptor for the child cgroup. ```APIDOC ## aya::test_helpers::ChildCgroup::fd ### Description Gets the file descriptor for the child cgroup. ### Signature `pub fn fd(&self) -> aya::test_helpers::AyaTestResult` ``` -------------------------------- ### ProgramInfo::from_pin Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Creates a ProgramInfo instance from a pinned file path. This allows loading program metadata from a persistent location. ```APIDOC ## ProgramInfo::from_pin ### Description Creates a `ProgramInfo` instance from a path to a pinned object. This function is used to load program metadata that has been previously pinned to the filesystem. ### Method `from_pin>(path: P)` ### Parameters - `path`: A type `P` that implements `AsRef`, representing the path to the pinned program information. ### Returns - `Result`: Ok containing the `ProgramInfo` instance if loading is successful, or an `Err` with a `ProgramError` if loading fails. ``` -------------------------------- ### SchedClassifier::fd (MultiProgram) Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Gets the file descriptor of the TC program as a BorrowedFd. ```APIDOC ## SchedClassifier::fd (MultiProgram) ### Description Retrieves the file descriptor of the TC program, returning it as a `BorrowedFd`. ### Method `pub fn fd(&self) -> core::result::Result, aya::programs::ProgramError>` ### Returns - `core::result::Result, aya::programs::ProgramError>`: On success, returns a `BorrowedFd`. On failure, returns a `ProgramError`. ``` -------------------------------- ### aya::programs::xdp::XdpMode Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides methods for comparing and creating default instances of XdpMode. ```APIDOC ## XdpMode::eq ### Description Compares two XdpMode instances for equality. ### Method `eq` ### Parameters - `self`: The first XdpMode instance. - `other`: The second XdpMode instance to compare with. ### Returns - `bool`: `true` if the instances are equal, `false` otherwise. ## XdpMode::default ### Description Creates a default instance of XdpMode. ### Method `default` ### Returns - `aya::programs::xdp::XdpMode`: A new default XdpMode instance. ``` -------------------------------- ### SkSkb Methods Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides methods for attaching, detaching, loading, and managing SK SKB programs. ```APIDOC ## SkSkb::attach ### Description Attaches the SK SKB program to a SockMapFd. ### Method `attach` ### Parameters - `sock_map_fd`: The `SockMapFd` to attach the program to. ### Returns `core::result::Result` - The link ID if successful, otherwise a ProgramError. ## SkSkb::from_pin ### Description Creates a new SK SKB program from a pinned file path. ### Method `from_pin` ### Parameters - `P`: A type that implements `AsRef`, representing the path to the pinned program. - `kind`: The kind of SK SKB program. ### Returns `core::result::Result` - A new SkSkb instance or a ProgramError. ## SkSkb::load ### Description Loads the SK SKB program into the kernel. ### Method `load` ### Returns `core::result::Result<(), aya::programs::ProgramError>` - Ok if successful, otherwise a ProgramError. ## SkSkb::detach ### Description Detaches the SK SKB program from a link ID. ### Method `detach` ### Parameters - `link_id`: The `SkSkbLinkId` to detach. ### Returns `core::result::Result<(), aya::programs::ProgramError>` - Ok if successful, otherwise a ProgramError. ## SkSkb::take_link ### Description Takes ownership of a link associated with the SK SKB program. ### Method `take_link` ### Parameters - `link_id`: The `SkSkbLinkId` of the link to take. ### Returns `core::result::Result` - The `SkSkbLink` if successful, otherwise a ProgramError. ## SkSkb::fd ### Description Retrieves the file descriptor of the SK SKB program. ### Method `fd` ### Returns `core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError>` - A reference to the ProgramFd or a ProgramError. ## SkSkb::from_program_info ### Description Creates a new SK SKB program from existing program information. ### Method `from_program_info` ### Parameters - `program_info`: The existing program information. - `name`: A static string slice representing the name of the program. - `kind`: The kind of SK SKB program. ### Returns `core::result::Result` - A new SkSkb instance or a ProgramError. ## SkSkb::info ### Description Retrieves information about the SK SKB program. ### Method `info` ### Returns `core::result::Result` - ProgramInfo or a ProgramError. ``` -------------------------------- ### bpf_xdp_adjust_head Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya-ebpf-bindings.txt Adjusts the head of the XDP packet buffer. Modifies the start of the packet data. ```APIDOC ## bpf_xdp_adjust_head ### Description Adjusts the head of the XDP packet buffer. Modifies the start of the packet data. ### Signature `pub unsafe fn bpf_xdp_adjust_head(*mut xdp_md, c_int) -> c_long` ``` -------------------------------- ### Xdp::from_pin Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Creates an XDP program instance from a pinned file. ```APIDOC ## Xdp::from_pin ### Description Loads an XDP program from a file path where it has been previously pinned. ### Method `pub fn from_pin>(path: P, attach_type: XdpAttachType) -> Result` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage: // let xdp_program = Xdp::from_pin("/sys/fs/bpf/my_xdp_prog", XdpAttachType::Egress).unwrap(); ``` ### Response #### Success Response (200) - **Self** (type): An instance of `aya::programs::xdp::Xdp`. #### Response Example ```json // Success response would be an Xdp instance ``` ### Error Handling - **ProgramError**: If loading the program from the pin fails. ``` -------------------------------- ### SchedClassifier Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Provides methods to get the file descriptor and run tests for a SchedClassifier program. ```APIDOC ## SchedClassifier ### Description Represents a TC (Traffic Control) classifier program. ### Methods - `fd(&self)`: Returns the file descriptor of the SchedClassifier. - `test_run(&self, opts)`: Runs a test on the SchedClassifier program. ### Types - `Opts<'a>`: Type alias for `aya::programs::TestRunOptions<'a>` - `Result`: Type alias for `aya::programs::TestRunResult` ``` -------------------------------- ### IterableMap Operations Source: https://github.com/aya-rs/aya/blob/main/xtask/public-api/aya.txt Defines common operations for iterable maps, including getting elements. ```APIDOC ## get IterableMap ### Description Retrieves a value from an iterable map using a key. ### Method `get` ### Parameters - `&K`: The key to look up. ### Returns - `core::result::Result`: A result containing the value on success or a MapError on failure. ## map IterableMap ### Description Provides access to the underlying map data for an iterable map. ### Method `map` ### Returns - `&aya::maps::MapData`: A reference to the map data. ```