### Get XDP Program Priority with Libxdp (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__run_prio The `xdp_program__run_prio` function retrieves the priority of an XDP program. Higher values indicate later execution, while lower values indicate earlier execution. It returns an unsigned integer on success or a negative error code on failure. ```c unsigned int xdp_program__run_prio(const struct xdp_program *xdp_prog); ``` -------------------------------- ### Get Next Loaded Program in Dispatcher using Libxdp Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__next_prog The `xdp_multiprog__next_prog` function retrieves the next loaded program within an XDP dispatcher. It takes the current program and the multiprogramming context as input. The function returns a pointer to the next `xdp_program` on success or a negative error code on failure. ```c struct xdp_program *xdp_multiprog__next_prog(const struct xdp_program *prog, const struct xdp_multiprog *mp); ``` -------------------------------- ### Get Libxdp Dispatcher Program Reference (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__main_prog The `xdp_multiprog__main_prog` function retrieves a pointer to the dispatcher program within a multiprogram context. It takes a constant pointer to a `struct xdp_multiprog` as input. The function returns a pointer to a `struct xdp_program` on success, or a negative error code if an issue occurs. ```c struct xdp_program *xdp_multiprog__main_prog(const struct xdp_multiprog *mp); ``` -------------------------------- ### Get Hardware Program Reference with Libxdp xdp_multiprog__hw_prog (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__hw_prog The `xdp_multiprog__hw_prog` function retrieves a pointer to the `xdp_program` structure representing the program currently loaded on a network interface. This is particularly useful when the loaded program is not the dispatcher. It returns a pointer to `struct xdp_program` on success or a negative error code on failure. ```c struct xdp_program *xdp_multiprog__hw_prog(const struct xdp_multiprog *mp); ``` -------------------------------- ### Get xdp_program from bpf_obj (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__from_bpf_obj Retrieves an `xdp_program` from a given `bpf_object` using a specified section name. It returns a pointer to the `xdp_program` on success or a negative error code on failure. This function is crucial for associating BPF programs with XDP contexts. ```c struct xdp_program *xdp_program__from_bpf_obj(struct bpf_object *obj, const char *section_name); ``` -------------------------------- ### Get xdp_program from File Descriptor (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__from_fd Retrieves an `xdp_program` structure associated with a given file descriptor. This function is crucial for managing XDP programs loaded via file descriptors. It returns a pointer to the `xdp_program` on success or a negative error code (e.g., -ENOENT) on failure. ```c struct xdp_program *xdp_program__from_fd(int fd); ``` -------------------------------- ### Get xdp_multiprog attach mode using C Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__attach_mode This C function retrieves the `xdp_attach_mode` for a given `xdp_multiprog`. It returns the `enum xdp_attach_mode` or `XDP_MODE_UNSPEC` if the mode is not found. No external dependencies are required beyond standard C types. ```c enum xdp_attach_mode xdp_multiprog__attach_mode(const struct xdp_multiprog *mp); ``` -------------------------------- ### Get xdp_multiprog from Interface Index (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__get_from_ifindex Retrieves the `xdp_multiprog` dispatcher program using the network interface index. Returns 0 on success or a negative error code on failure, such as -EBUSY if the dispatcher is unreachable or -ENOENT if the interface index does not exist. This function is part of the Libxdp library. ```c struct xdp_multiprog *xdp_multiprog__get_from_ifindex(int ifindex); ``` -------------------------------- ### Get Packet Buffer Address Pointer with Libxdp xsk_ring_prod__fill_addr Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_prod__fill_addr This C function retrieves a pointer to a slot in the fill ring, allowing the user to set the address of a packet buffer. It takes a pointer to the fill ring and an index as input, returning the `__u64` address of the packet. This is a core operation for managing packet buffers in XDP. ```c __u64 *xsk_ring_prod__fill_addr(struct xsk_ring_prod *fill, __u32 idx); ``` -------------------------------- ### Get Packet Data Pointer with Libxdp xsk_umem__get_data (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__get_data Retrieves a pointer to packet data using the Rx descriptor in aligned mode. This function is part of the Libxdp library for eBPF I/O. In unaligned mode, alternative functions like `xsk_umem__extract_addr` are required. ```c void *xsk_umem__get_data(void *umem_area, __u64 addr); ``` -------------------------------- ### Get UMEM File Descriptor with Libxdp xsk_umem__fd (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__fd The xsk_umem__fd function from Libxdp returns the file descriptor associated with a given umem. It takes a pointer to an xsk_umem structure as input. On success, it returns the file descriptor; otherwise, it returns a negative error code, such as -EINVAL for invalid arguments. ```c int xsk_umem__fd(const struct xsk_umem *umem); ``` -------------------------------- ### Get XDP Socket File Descriptor using Libxdp (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_socket__fd The `xsk_socket__fd` function retrieves the file descriptor for a given `xsk_socket` structure. It returns the file descriptor on success or a negative error code (e.g., -EINVAL) on failure. This is crucial for interacting with the socket using standard system calls. ```c int xsk_socket__fd(const struct xsk_socket *xsk); ``` -------------------------------- ### Get Consumer Ring Completion Address (Libxdp C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_cons__comp_addr Retrieves the memory address of a specific completion entry within the consumer ring of an XDP socket. It takes a pointer to the consumer ring structure and an index as input. The function returns a 64-bit unsigned integer representing the address on success, or a negative error code on failure. This function is part of the Libxdp library. ```c const __u64 *xsk_ring_cons__comp_addr(const struct xsk_ring_cons *comp, __u32 idx); ``` -------------------------------- ### xsk_setup_xdp_prog Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_setup_xdp_prog Sets up an XDP program on a specified network interface using the Libxdp library. ```APIDOC ## xsk_setup_xdp_prog ### Description This function sets up an XDP program on a specified network interface. ### Method N/A (This is a C function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c int xsk_setup_xdp_prog(int ifindex, int *xsks_map_fd); ``` ### Response #### Success Response 0 on success. #### Error Response Negative error code on failure: - **-ENOENT**: if file not found #### Response Example ```c // Example usage (conceptual) int ifindex = 1; // Example interface index int xsks_map_fd; int ret = xsk_setup_xdp_prog(ifindex, &xsks_map_fd); if (ret == 0) { // Success } else { // Handle error } ``` ``` -------------------------------- ### Set up XDP Program with xsk_setup_xdp_prog (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_setup_xdp_prog The xsk_setup_xdp_prog function is used to attach an XDP program to a specified network interface. It returns 0 on success and a negative error code on failure, such as -ENOENT if the file is not found. The function takes the interface index and a file descriptor for the sockets map as input. ```c int xsk_setup_xdp_prog(int ifindex, int *xsks_map_fd); ``` -------------------------------- ### Find xdp_program from file using Libxdp C Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__find_file The `xdp_program__find_file` function in Libxdp locates and returns an `xdp_program` based on a provided filename and section name. It searches for the BPF object file within the `LIBXDP_OBJECT_PATH` environment variable, with default system paths. It returns a pointer to `struct xdp_program` on success or a negative error code on failure. The `opts` parameter allows for custom open options. ```c struct xdp_program *xdp_program__find_file(const char *filename, const char *section_name, struct bpf_object_open_opts *opts); ``` -------------------------------- ### Configure XDP Program Metadata for Dispatcher Source: https://docs.ebpf.io/ebpf-library/libxdp/libxdp This snippet demonstrates how to define metadata for an XDP program, such as priority and chain call actions, which are used by the libxdp dispatcher to manage program execution order. This configuration must be done before the program is attached to the dispatcher. ```c #include #include struct { __uint(priority, 10); // priority __uint(XDP_PASS, 1); // chain call action __uint(XDP_DROP, 1); // chain call action } XDP_RUN_CONFIG(my_xdp_func); ``` -------------------------------- ### Create UMEM Area with File Descriptor using Libxdp (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__create_with_fd The `xsk_umem__create_with_fd` function in Libxdp creates a user memory (umem) area associated with a given file descriptor. It takes pointers to the umem structure, the file descriptor, the memory area, its size, fill and completion ring configurations, and a configuration structure. It returns 0 on success or a negative error code on failure, such as invalid arguments or insufficient memory. ```c int xsk_umem__create_with_fd(struct xsk_umem **umem, int fd, void *umem_area, __u64 size, struct xsk_ring_prod *fill, struct xsk_ring_cons *comp, const struct xsk_umem_config *config); ``` -------------------------------- ### Create UMEM Area with xsk_umem__create (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__create The `xsk_umem__create` function in Libxdp is used to allocate and initialize a user memory area (umem). It requires pointers to the memory area, fill and completion rings, and a configuration structure. The function returns 0 on success or a negative error code on failure, such as invalid arguments or insufficient memory. ```c int xsk_umem__create(struct xsk_umem **umem, void *umem_area, __u64 size, struct xsk_ring_prod *fill, struct xsk_ring_cons *comp, const struct xsk_umem_config *config); ``` -------------------------------- ### Libxdp xdp_program__from_pin Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__from_pin Retrieves an `xdp_program` from a specified pin path. ```APIDOC ## Libxdp xdp_program__from_pin Function ### Description Returns the `xdp_program` found at the specified path. ### Method This is a function call within the Libxdp library, not a traditional HTTP API endpoint. ### Endpoint N/A ### Parameters #### Path Parameters - **pin_path** (const char *) - Required - The path where the xdp_program is pinned. ### Request Example ```c struct xdp_program *prog = xdp_program__from_pin("/sys/fs/bpf/my_program"); ``` ### Response #### Success Response - **struct xdp_program** - A pointer to the `xdp_program` structure if found successfully. #### Error Response - **Negative integer** - An error code indicating failure (e.g., -ENOENT if the path does not exist). #### Response Example ```c if (prog) { // Program found and loaded } else { // Handle error } ``` ``` -------------------------------- ### Load XDP Program from Pin Path (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__from_pin Retrieves an `xdp_program` structure from a specified pin path on the file system. It returns a pointer to the `xdp_program` on success or a negative error code on failure. This function is essential for accessing previously pinned XDP programs. ```c struct xdp_program *xdp_program__from_pin(const char *pin_path); ``` -------------------------------- ### Set XDP Program Run Priority (Libxdp C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__set_run_prio The `xdp_program__set_run_prio` function in Libxdp sets the execution priority for an XDP program before it is loaded. The priority is an unsigned integer, where lower values mean earlier execution and higher values mean later execution. The default priority is 50. This function must be called before the program is loaded to the dispatcher. It returns 0 on success or a negative error code (e.g., -EINVAL) on failure. ```c int xdp_program__set_run_prio(struct xdp_program *xdp_prog, unsigned int run_prio); ``` -------------------------------- ### Libxdp xsk_ring_prod__submit Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_prod__submit Submits filled slots so the kernel can process them. ```APIDOC ## xsk_ring_prod__submit ### Description Submit the filled slots so the kernel can process them. ### Method N/A (This is a function definition, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c void xsk_ring_prod__submit(struct xsk_ring_prod *prod, __u32 nb); ``` ### Response #### Success Response (N/A) No return value. #### Response Example None ``` -------------------------------- ### Libxdp xdp_multiprog__next_prog Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__next_prog Retrieves the next loaded program from a dispatcher. Returns a pointer to the next xdp_program on success or a negative error code on failure. ```APIDOC ## Libxdp xdp_multiprog__next_prog ### Description Allows to get the next loaded program in the dispatcher. ### Method N/A (This is a function definition, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c struct xdp_program *xdp_multiprog__next_prog(const struct xdp_program *prog, const struct xdp_multiprog *mp); ``` ### Response #### Success Response `struct xdp_program` pointer of the next program if success. #### Error Response A negative error code in case of failure. #### Response Example ```c // On success: struct xdp_program *next_prog = xdp_multiprog__next_prog(current_prog, multiprog_instance); // On failure: int error_code = xdp_multiprog__next_prog(current_prog, multiprog_instance); // error_code will be negative ``` -------------------------------- ### Open XDP Program from File using Libxdp Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__open_file The `xdp_program__open_file` function associates an `xdp_program` structure with a specified filename and section name. It can handle filenames with paths and returns a pointer to `struct xdp_program` on success or a negative error code on failure. The function accepts optional `bpf_object_open_opts` for advanced configuration. ```c struct xdp_program *xdp_program__open_file(const char *filename, const char *section_name, struct bpf_object_open_opts *opts); ``` -------------------------------- ### Libxdp xsk_socket__create Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_socket__create Creates an AF_XDP socket with exclusive ownership of a umem. Returns 0 on success or a negative error code on failure. ```APIDOC ## Libxdp xsk_socket__create Function ### Description Creates an AF_XDP socket with exclusive ownership of a umem. ### Method N/A (This is a function definition, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Function Signature ```c int xsk_socket__create(struct xsk_socket **xsk, const char *ifname, __u32 queue_id, struct xsk_umem *umem, struct xsk_ring_cons *rx, struct xsk_ring_prod *tx, const struct xsk_socket_config *config); ``` ### Returns 0 on success, or a negative error in case of failure: - **-EINVAL**: if arguments are invalid - **-EFAULT**: if memory address is invalid - **-ENOMEM**: if no data space available - **-ENOPROTOOPT**: if option is not supported by the protocol ### Example ```c // Example usage would go here, but is currently incomplete. // Contributions are very welcome. ``` ``` -------------------------------- ### Libxdp xdp_program__print_chain_call_actions Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__print_chain_call_actions This function returns to the buffer the chain call actions associated with an `xdp_program`. ```APIDOC ## Libxdp function `xdp_program__print_chain_call_actions` ### Description Return to the buffer the chain call actions associated to a `xdp_program`. ### Method N/A (This is a C function, not a REST API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c int xdp_program__print_chain_call_actions(const struct xdp_program *prog, char *buf, size_t buf_len); ``` ### Response #### Success Response (0) Returns 0 on success. #### Error Response - **-EINVAL**: If arguments are invalid. #### Response Example ```c // On success, 'buf' will contain the chain call actions. // On failure, a negative error code will be returned. ``` ``` -------------------------------- ### Create AF_XDP Socket with Libxdp (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_socket__create The `xsk_socket__create` function in Libxdp is used to establish an AF_XDP socket. It requires the interface name, queue ID, user memory (umem), receive and transmit rings, and a configuration structure. It returns 0 on success or a negative error code on failure, such as invalid arguments or memory issues. ```c int xsk_socket__create(struct xsk_socket **xsk, const char *ifname, __u32 queue_id, struct xsk_umem *umem, struct xsk_ring_cons *rx, struct xsk_ring_prod *tx, const struct xsk_socket_config *config); ``` -------------------------------- ### Libxdp xsk_socket__create_shared Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_socket__create_shared Creates an AF_XDP socket and shares the ownership of the umem between multiple sockets. ```APIDOC ## Libxdp xsk_socket__create_shared ### Description Creates an AF_XDP socket and share the ownership of the umem between multiple sockets. ### Method N/A (This is a C function, not an HTTP API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c int xsk_socket__create_shared(struct xsk_socket **xsk_ptr, const char *ifname, __u32 queue_id, struct xsk_umem *umem, struct xsk_ring_cons *rx, struct xsk_ring_prod *tx, struct xsk_ring_prod *fill, struct xsk_ring_cons *comp, const struct xsk_socket_config *config); ``` ### Response #### Success Response (0) Returns 0 on success. #### Error Response - **-EINVAL**: if arguments are invalid - **-EFAULT**: if memory address is invalid - **-ENOMEM**: if no data space available - **-ENOPROTOOPT**: if option is not supported by the protocol #### Response Example ```c // Success 0 // Failure example -EINVAL ``` ``` -------------------------------- ### Libxdp xsk_ring_cons__peek Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_cons__peek Checks for new packets in the consumer ring and returns the number of available packets. ```APIDOC ## xsk_ring_cons__peek ### Description Checks for new packets in the ring. ### Method Not Applicable (Function Definition) ### Endpoint Not Applicable (Function Definition) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c __u32 xsk_ring_cons__peek(struct xsk_ring_cons *cons, __u32 nb, __u32 *idx); ``` ### Response #### Success Response (Return Value) - **__u32** (unsigned integer) - Returns the number of packets that are available in the consumer ring (`idx`). This value can be less than or equal to the number of packets requested to peek. ``` -------------------------------- ### Libxdp xdp_program__from_bpf_obj Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__from_bpf_obj Retrieves the xdp_program associated with a bpf object and section name. ```APIDOC ## Libxdp xdp_program__from_bpf_obj ### Description Return the `xdp_program` associated to a bpf object with the section name. ### Method N/A (This is a C function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c struct xdp_program *xdp_program__from_bpf_obj(struct bpf_object *obj, const char *section_name); ``` ### Response #### Success Response `struct xdp_program` on success. #### Error Response A negative error code in case of failure. #### Response Example ```c // On success: struct xdp_program *prog = xdp_program__from_bpf_obj(bpf_obj, "my_section"); // On failure: int err = xdp_program__from_bpf_obj(bpf_obj, "invalid_section"); // err will be negative ``` -------------------------------- ### xdp_program__set_run_prio Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__set_run_prio Sets the priority for an XDP program before it is loaded to the dispatcher. The priority determines the execution order, with lower values running earlier and higher values running later. The default priority is 50. This function must be called before the program is loaded. ```APIDOC ## xdp_program__set_run_prio ### Description This function allows setting a priority for the program when loaded to the dispatcher. The priority of a program is an integer used to determine the order in which programs are executed on the interface. A lower value means the program runs earlier, and a higher value means it runs later. The default priority is 50. **Warning:** This function only works before the program is loaded to the dispatcher. ### Method `xdp_program__set_run_prio(struct xdp_program *xdp_prog, unsigned int run_prio)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c struct xdp_program *prog = xdp_program__open_file("path/to/program.o", NULL, NULL, false); if (!prog) { // Handle error } // Set priority to run earlier (e.g., 10) int ret = xdp_program__set_run_prio(prog, 10); if (ret < 0) { // Handle error } // Load the program (example) // xdp_program__load(prog, ...); xdp_program__close(prog); ``` ### Response #### Success Response (0) Returns 0 on success. #### Error Response (< 0) - **-EINVAL**: If arguments are invalid. #### Response Example ``` 0 ``` ``` -------------------------------- ### Print Chain Call Actions for XDP Program (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__print_chain_call_actions Retrieves the chain call actions associated with an `xdp_program` and returns them in a buffer. It returns 0 on success or a negative error code on failure, such as -EINVAL for invalid arguments. The function requires a pointer to the `xdp_program` and a buffer with its length to store the actions. ```c int xdp_program__print_chain_call_actions(const struct xdp_program *prog, char *buf, size_t buf_len); ``` -------------------------------- ### Libxdp xdp_multiprog__main_prog Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__main_prog This function returns a reference to the dispatcher program managed by the xdp_multiprog structure. It returns a pointer to an `xdp_program` on success, or a negative error code on failure. ```APIDOC ## Libxdp xdp_multiprog__main_prog Function ### Description Returns a reference to the dispatcher program only. ### Returns `struct xdp_program` on success, or a negative error code in case of failure. ### Usage ```c struct xdp_program *xdp_multiprog__main_prog(const struct xdp_multiprog *mp); ``` ### Example ```c // Example usage is not provided as the documentation is incomplete. // Contributions are welcome to improve this section. ``` ``` -------------------------------- ### xdp_program__run_prio Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__run_prio Retrieves the priority of an XDP program. Higher values indicate later execution, while lower values indicate earlier execution. ```APIDOC ## xdp_program__run_prio Function ### Description Retrieves the priority of an XDP program. The priority determines the execution order, with higher values running later and lower values running earlier. ### Method N/A (This is a library function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c const struct xdp_program *xdp_prog = ...; // Assume xdp_prog is initialized unsigned int priority = xdp_program__run_prio(xdp_prog); ``` ### Response #### Success Response - **unsigned int**: The priority of the XDP program. A higher value means the program runs later, and a lower value means it runs earlier. #### Error Response - **int**: A negative error code if the operation fails. For example, -EINVAL if arguments are invalid. #### Response Example ```c // Success unsigned int priority = 5; // Failure int error = -1; ``` ``` -------------------------------- ### Check Libxdp Dispatcher Legacy Status (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__is_legacy The `xdp_multiprog__is_legacy` function determines if the dispatcher program loaded is considered legacy, unrecognized, or if another program is loaded instead of the dispatcher. It returns true if the dispatcher is legacy or unrecognized, and false if it is identified. ```c bool xdp_multiprog__is_legacy(const struct xdp_multiprog *mp); ``` -------------------------------- ### Libxdp xsk_umem__add_offset_to_addr Function Signature Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__add_offset_to_addr This C function signature defines how to use `xsk_umem__add_offset_to_addr` in Libxdp. It takes a `__u64` address and returns a `__u64` representing the new address after adding an offset. This function is intended for unaligned memory access scenarios. ```c __u64 xsk_umem__add_offset_to_addr(__u64 addr); ``` -------------------------------- ### Libxdp xdp_multiprog__hw_prog Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__hw_prog This function returns a reference to the program loaded in the interface, which is useful if it's not the dispatcher. It returns a struct xdp_program on success or a negative error code on failure. ```APIDOC ## Libxdp xdp_multiprog__hw_prog Function ### Description Returns a reference to the program loaded in the interface (useful if it's not the dispatcher). ### Method N/A (This is a C function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c struct xdp_program *xdp_multiprog__hw_prog(const struct xdp_multiprog *mp); ``` ### Response #### Success Response `struct xdp_program` - A reference to the loaded program. #### Error Response Negative integer - An error code indicating failure. #### Response Example ```c // Success struct xdp_program *prog = xdp_multiprog__hw_prog(my_multiprog); // Failure int err = xdp_multiprog__hw_prog(my_multiprog); ``` ``` -------------------------------- ### Libxdp xsk_ring_prod__fill_addr Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_prod__fill_addr This function retrieves a pointer to a slot in the fill ring, allowing you to set the address of a packet buffer. ```APIDOC ## Libxdp function `xsk_ring_prod__fill_addr` ### Description Use this function to get a pointer to a slot in the **fill** ring to set the address of a packet buffer. ### Method N/A (This is a function definition, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c __u64 *xsk_ring_prod__fill_addr(struct xsk_ring_prod *fill, __u32 idx); ``` ### Response #### Success Response (200) - **__u64** (unsigned 64-bit integer) - The address of the packet buffer slot in the fill ring. #### Response Example ```json { "address": "0x123456789abcdef0" } ``` ``` -------------------------------- ### Libxdp xsk_ring_cons__peek Function Definition and Usage (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_cons__peek Defines and shows the usage of the `xsk_ring_cons__peek` function from the Libxdp library. This function checks for new packets in the consumer ring and returns the number of available packets. It is crucial for packet processing applications using XDP sockets. ```c __u32 xsk_ring_cons__peek(struct xsk_ring_cons *cons, __u32 nb, __u32 *idx); ``` -------------------------------- ### Libxdp xsk_umem__create_with_fd Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__create_with_fd Creates a user memory area using a file descriptor. This function is part of the Libxdp library for eBPF development. ```APIDOC ## Libxdp xsk_umem__create_with_fd ### Description Create an umem area using a file descriptor. ### Method N/A (This is a C function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### C Function Signature ```c int xsk_umem__create_with_fd(struct xsk_umem **umem, int fd, void *umem_area, __u64 size, struct xsk_ring_prod *fill, struct xsk_ring_cons *comp, const struct xsk_umem_config *config); ``` ### Returns 0 on success, or a negative error in case of failure: - **-EINVAL** if arguments are invalid - **-EFAULT** if the memory address is invalid - **-ENOMEM** if no space memory left ### Example ```c // Example usage would go here, but is currently missing. // Docs could be improved. This part of the docs is incomplete, contributions are very welcome. ``` ``` -------------------------------- ### Submit Filled Slots with Libxdp xsk_ring_prod__submit (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_prod__submit The `xsk_ring_prod__submit` function in Libxdp is used to submit a specified number of filled buffer slots from a producer ring to the kernel for processing. It takes a pointer to the producer ring structure and the number of slots to submit as arguments. This function does not return any value. ```c void xsk_ring_prod__submit(struct xsk_ring_prod *prod, __u32 nb); ``` -------------------------------- ### xdp_program__from_id Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__from_id Retrieves the xdp_program associated with a given program ID. ```APIDOC ## xdp_program__from_id ### Description Return the `xdp_program` associated to an id. ### Method GET ### Endpoint `/websites/ebpf_io_ebpf-library_libxdp/xdp_program__from_id` ### Parameters #### Query Parameters - **prog_id** (unsigned int) - Required - The ID of the xdp_program to retrieve. ### Response #### Success Response (200) - **xdp_program** (struct xdp_program) - A pointer to the xdp_program structure on success. #### Error Response - **-ENOENT** (int) - If no such file or directory. - **-EINVAL** (int) - If arguments are invalid. ### Request Example ```json { "prog_id": 123 } ``` ### Response Example ```json { "xdp_program": { "// ... xdp_program structure fields ...": "..." } } ``` ``` -------------------------------- ### Create Shared AF_XDP Socket with Libxdp (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_socket__create_shared Defines the `xsk_socket__create_shared` function in C, used to create an AF_XDP socket. This function allows sharing the ownership of the umem between multiple sockets. It returns 0 on success or a negative error code on failure, such as invalid arguments or memory issues. ```c int xsk_socket__create_shared(struct xsk_socket **xsk_ptr, const char *ifname, __u32 queue_id, struct xsk_umem *umem, struct xsk_ring_cons *rx, struct xsk_ring_prod *tx, struct xsk_ring_prod *fill, struct xsk_ring_cons *comp, const struct xsk_socket_config *config); ``` -------------------------------- ### Libxdp xdp_program__set_chain_call_enabled Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__set_chain_call_enabled This function allows adding actions to the chain call. If the program returns this `xdp_action`, the packet will be sent to the next program; otherwise, it will not. This must be called before loading the program to the dispatcher. ```APIDOC ## Libxdp xdp_program__set_chain_call_enabled ### Description Allows adding actions to the chain call. If the program returns this `xdp_action`, the packet will be sent to the next program (in order of the priority); otherwise, it will not. By default, this is set to XDP_PASS. This only works before the load of the program to the dispatcher. ### Method N/A (This is a C function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c int xdp_program__set_chain_call_enabled(struct xdp_program *prog, unsigned int action, bool enabled); ``` ### Response #### Success Response 0 on success #### Error Response Negative error code on failure: - **-EINVAL**: if arguments are invalid #### Response Example ```c 0 // on success -1 // on failure (e.g., -EINVAL) ``` ``` -------------------------------- ### Libxdp: Enable/Disable XDP Chain Call Action Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__set_chain_call_enabled Configures whether a specific XDP action triggers a chain call to the next program. This function must be called before loading the XDP program. It returns 0 on success or a negative error code on failure, such as -EINVAL for invalid arguments. ```c int xdp_program__set_chain_call_enabled(struct xdp_program *prog, unsigned int action, bool enabled); ``` -------------------------------- ### Check Kernel Wakeup Need with xsk_ring_prod__needs_wakeup (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_prod__needs_wakeup This C function checks if the kernel requires a wakeup to process the producer ring. It returns a non-zero value if a wakeup is needed, prompting calls to `recvmsg`, `sendto`, or `poll`. Enabling `XDP_USE_NEED_WAKEUP` is recommended. ```c int xsk_ring_prod__needs_wakeup(const struct xsk_ring_prod *r); ``` -------------------------------- ### Reserve Slots in Producer Ring (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_prod__reserve The `xsk_ring_prod__reserve` function in Libxdp is used to reserve one or more slots in a producer ring. It returns the number of successfully reserved slots (`idx`) or 0 on failure. The number of reserved slots may be less than or equal to the number requested. ```c __u32 xsk_ring_prod__reserve(struct xsk_ring_prod *prod, __u32 nb, __u32 *idx); ``` -------------------------------- ### xdp_program__chain_call_enabled Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__chain_call_enabled Checks if the provided xdp_action is configured for call chain execution within an xdp_program. ```APIDOC ## xdp_program__chain_call_enabled ### Description Return, true or false, if the `xdp_action` passed in parameter is set to be call chain action. ### Returns `true` if the action is set to be call chain action, else false ### Usage ```c bool xdp_program__chain_call_enabled(const struct xdp_program *xdp_prog, enum xdp_action action); ``` ### Example Docs could be improved This part of the docs is incomplete, contributions are very welcome ``` -------------------------------- ### Detach Programs with xdp_multiprog__detach (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__detach The xdp_multiprog__detach function is used to detach programs managed by a dispatcher. It takes a pointer to the multiprog structure and the interface index as arguments. It returns 0 on success or a negative error code on failure, such as -EINVAL for invalid arguments. Note that this function only detaches the programs; it does not close them. ```c int xdp_multiprog__detach(struct xdp_multiprog *mp, int ifindex); ``` -------------------------------- ### Retrieve xdp_program by ID using Libxdp C Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__from_id The xdp_program__from_id function retrieves a pointer to an xdp_program structure associated with a given program ID. It returns a pointer to the xdp_program on success or a negative error code on failure, such as -ENOENT if the ID does not exist or -EINVAL for invalid arguments. This function is part of the Libxdp library for eBPF program management. ```c struct xdp_program *xdp_program__from_id(__u32 prog_id); ``` -------------------------------- ### xdp_multiprog__is_legacy Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_multiprog__is_legacy Checks if the dispatcher program in xdp_multiprog is considered legacy or unrecognized. ```APIDOC ## xdp_multiprog__is_legacy Function ### Description Indicate whether the dispatcher program has been identified. ### Method N/A (This is a C function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c const struct xdp_multiprog *mp = ...; // Assume mp is initialized bool is_legacy = xdp_multiprog__is_legacy(mp); ``` ### Response #### Success Response - **bool** (true/false) - Returns true if the dispatcher is legacy, unrecognized, or another program that is not the dispatcher is loaded. Returns false if the dispatcher is identified. #### Response Example ```json { "return_value": true } ``` ### Notes This part of the docs is incomplete, contributions are very welcome. ``` -------------------------------- ### Libxdp xsk_ring_prod__reserve Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_prod__reserve Reserves one or more slots in a producer ring. Returns the number of slots successfully reserved. ```APIDOC ## xsk_ring_prod__reserve ### Description Reserve one or more slots in a **producer** ring. ### Method N/A (This is a function definition, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c __u32 xsk_ring_prod__reserve(struct xsk_ring_prod *prod, __u32 nb, __u32 *idx); ``` ### Response #### Success Response `__u32` number of slots that were successfully reserved (`idx`) on success, or a 0 in case of failure. Note It can be less than or equal to the number of packets requested to reserve. #### Response Example N/A (Function return value) ``` -------------------------------- ### Libxdp xsk_ring_prod__tx_desc Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_prod__tx_desc This function allows access to a specific transmit descriptor in the TX ring. It returns information about the packet to be transmitted. ```APIDOC ## Libxdp xsk_ring_prod__tx_desc Function ### Description This function allows access to a specific transmit descriptor in the **TX** ring. ### Method N/A (This is a function definition, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c struct xdp_desc *xsk_ring_prod__tx_desc(struct xsk_ring_prod *tx, __u32 idx); ``` ### Response #### Success Response (N/A) - **struct xdp_desc** (pointer) - Informations about the packet to be transmitted. #### Response Example N/A ``` -------------------------------- ### xsk_umem__fd Function Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__fd Retrieves the file descriptor associated with an xsk_umem object. ```APIDOC ## xsk_umem__fd ### Description This function returns the file descriptor of the umem passed in parameter. ### Method GET ### Endpoint /websites/ebpf_io_ebpf-library_libxdp/xsk_umem__fd ### Parameters #### Path Parameters - **umem** (struct xsk_umem *) - Required - The umem object for which to retrieve the file descriptor. ### Request Example ```c int fd = xsk_umem__fd(my_umem); ``` ### Response #### Success Response (0) - **file descriptor** (int) - The file descriptor of the umem on success. #### Error Response (-EINVAL) - **error code** (int) - Returns a negative error code in case of failure, such as -EINVAL if arguments are invalid. ``` -------------------------------- ### Libxdp xsk_ring_cons__rx_desc Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_cons__rx_desc Retrieves the receive descriptor at a specific index in the Rx ring. ```APIDOC ## xsk_ring_cons__rx_desc ### Description This function is used to retrieve the receive descriptor at a specific index in the **Rx** ring. ### Method GET (Conceptual - this is a function call, not an HTTP endpoint) ### Endpoint N/A (Library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c const struct xdp_desc *xsk_ring_cons__rx_desc(const struct xsk_ring_cons *rx, __u32 idx); ``` ### Response #### Success Response `struct xdp_desc` - Represents the receive descriptor at the given index in the Rx ring. #### Error Response Negative error code - Indicates failure. #### Response Example ```c // Success: struct xdp_desc desc = *xsk_ring_cons__rx_desc(rx_ring, index); // Failure: int error_code = xsk_ring_cons__rx_desc(rx_ring, invalid_index); ``` ``` -------------------------------- ### Update XSK Map with AF_XDP Socket (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_socket__update_xskmap The `xsk_socket__update_xskmap` function in Libxdp is used to associate an AF_XDP socket with an XSK map. It takes a pointer to the `xsk_socket` structure and the file descriptor of the XSK map as input. The function returns 0 on success or a negative error code on failure, such as -EINVAL for invalid arguments or -ENOENT if the entry is not found. ```c int xsk_socket__update_xskmap(struct xsk_socket *xsk, int xsks_map_fd); ``` -------------------------------- ### Libxdp xsk_umem__extract_offset Function Definition Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__extract_offset Defines the `xsk_umem__extract_offset` function signature in Libxdp. This function extracts an offset from a given address in unaligned mode. It returns a `__u64` representing the new address. Note that `xsk_umem__extract_addr` and `xsk_umem__add_offset_to_addr` are required for its use in unaligned mode, while `xsk_umem_get_data` is used in aligned mode. ```c __u64 xsk_umem__extract_offset(__u64 addr); ``` -------------------------------- ### Retrieve Rx Descriptor with xsk_ring_cons__rx_desc (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_cons__rx_desc This C function retrieves the receive descriptor at a specific index in the Rx ring. It takes a pointer to the consumer ring and an index as input. The function returns a pointer to an `xdp_desc` structure on success or a negative error code on failure. This is a core function for processing received network packets with XDP. ```c const struct xdp_desc *xsk_ring_cons__rx_desc(const struct xsk_ring_cons *rx, __u32 idx); ``` -------------------------------- ### Extract Memory Address (Unaligned Mode) - Libxdp C Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__extract_addr The `xsk_umem__extract_addr` function extracts a memory address in unaligned mode. It returns a `__u64` representing the address. This function should be used in conjunction with `xsk_umem__extract_offset` and `xsk_umem__add_offset_to_addr`. For aligned mode, use `xsk_umem_get_data`. ```c __u64 xsk_umem__extract_addr(__u64 addr); ``` -------------------------------- ### Delete UMEM Area with xsk_umem__delete (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_umem__delete This C code snippet demonstrates the usage of the `xsk_umem__delete` function from the Libxdp library. This function is used to deallocate a user memory (umem) area. It returns 0 on success or a negative error code (e.g., -EINVAL, -EBUSY) on failure. ```c int xsk_umem__delete(struct xsk_umem *umem); ``` -------------------------------- ### Access TX Ring Descriptor with xsk_ring_prod__tx_desc (C) Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_prod__tx_desc The `xsk_ring_prod__tx_desc` function provides access to a specific transmit descriptor within the TX ring buffer. It returns a pointer to an `xdp_desc` structure containing information about the packet to be transmitted. This function is crucial for managing packet transmission in XDP. ```c struct xdp_desc *xsk_ring_prod__tx_desc(struct xsk_ring_prod *tx, __u32 idx); ``` -------------------------------- ### Check XDP Call Chain Enabled Status with Libxdp Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xdp_program__chain_call_enabled This C function checks if a given XDP action is configured for call chaining within an XDP program. It takes a pointer to an `xdp_program` structure and an `xdp_action` enum as input. The function returns a boolean value: `true` if the action is set for call chaining, and `false` otherwise. ```c bool xdp_program__chain_call_enabled(const struct xdp_program *xdp_prog, enum xdp_action action); ``` -------------------------------- ### Libxdp xsk_ring_cons__cancel Function Signature Source: https://docs.ebpf.io/ebpf-library/libxdp/functions/xsk_ring_cons__cancel This C code snippet shows the function signature for `xsk_ring_cons__cancel`. This function is used to cancel the reservation of one or more slots in a consumer ring within the Libxdp library. It takes a pointer to a consumer ring structure and the number of slots to cancel as arguments. ```c void xsk_ring_cons__cancel(struct xsk_ring_cons *cons, __u32 nb); ```