#!/bin/bash

source ./kernel_config_utils.sh
source ./bpf_utils.sh

xdp_check() {
    is_error=false
    if ! kernel_config_check CONFIG_XDP_SOCKETS; then
        is_error=true
    fi
    if ! kernel_config_check CONFIG_XDP_SOCKETS_DIAG xsk_diag; then
        is_error=true
    fi
    if [ "$is_error" == "true" ]; then
        return 1
    fi

    helpers=$(cat << EOF
    bpf_map_lookup_elem
    bpf_redirect_map
EOF
)

    is_error=false
    if ! bpf_map_type_check xskmap; then
        is_error=true
    fi
    if bpf_prog_type_check xdp; then
        for helper in $helpers; do
            if ! bpf_prog_helper_check xdp $helper; then
                is_error=true
            fi
        done
    else
        is_error=true
    fi
    if [ "$is_error" == "true" ]; then
        return 1
    fi

    return 0
}

