#ifndef _BPF_CONF_USER_H_ #define _BPF_CONF_USER_H_ #ifdef __cplusplus extern "C" { #endif #include #include #include "bpf_conf_def.h" static inline int bpf_conf_update_map(bpf_conf_t *conf, struct bpf_object *bpf_obj) { int bpf_conf_map_fd = bpf_object__find_map_fd_by_name(bpf_obj, "bpf_conf_map"); if (bpf_conf_map_fd < 0) { printf("ERROR: Could not find bpf_conf_map in bpf obj file\n"); return -1; } if (bpf_map_update_elem(bpf_conf_map_fd, &conf->debug_log.key, &conf->debug_log.val, 0)) { printf("ERROR: Could not update bpf_conf_map element[%s:%d].\n", conf->debug_log.key.str, conf->debug_log.val); return -1; } if (bpf_map_update_elem(bpf_conf_map_fd, &conf->hash_mode.key, &conf->hash_mode.val, 0)) { printf("ERROR: Could not update bpf_conf_map element[%s:%d].\n", conf->hash_mode.key.str, conf->hash_mode.val); return -1; } if (bpf_map_update_elem(bpf_conf_map_fd, &conf->queue_num.key, &conf->queue_num.val, 0)) { printf("ERROR: Could not update bpf_conf_map element[%s:%d].\n", conf->queue_num.key.str, conf->queue_num.val); return -1; } return 0; } static inline void bpf_conf_set_debug_log(bpf_conf_t *conf, __u32 val) { conf->debug_log.val = val; memcpy(conf->debug_log.key.str, BPF_CONF_KEY_DEBUG_LOG, strlen(BPF_CONF_KEY_DEBUG_LOG)); } static inline void bpf_conf_set_hash_mode(bpf_conf_t *conf, __u32 val) { conf->hash_mode.val = val; memcpy(conf->hash_mode.key.str, BPF_CONF_KEY_HASH_MODE, strlen(BPF_CONF_KEY_HASH_MODE)); } static inline void bpf_conf_set_queue_num(bpf_conf_t *conf, __u32 val) { conf->queue_num.val = val; memcpy(conf->queue_num.key.str, BPF_CONF_KEY_QUEUE_NUM, strlen(BPF_CONF_KEY_QUEUE_NUM)); } #ifdef __cplusplus } #endif #endif