73 lines
2.2 KiB
C
73 lines
2.2 KiB
C
#ifndef _BPF_CONFIG_USER_H_
|
|
#define _BPF_CONFIG_USER_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <bpf/bpf.h>
|
|
#include <bpf/libbpf.h>
|
|
|
|
#include "bpf_config_define.h"
|
|
|
|
/******************************************************************************
|
|
* Set By UserSpace
|
|
******************************************************************************/
|
|
|
|
static inline int bpf_config_update_map(struct bpf_config *config, struct bpf_object *bpf_obj)
|
|
{
|
|
int bpf_config_map_fd = bpf_object__find_map_fd_by_name(bpf_obj, "bpf_config_map");
|
|
if (bpf_config_map_fd < 0)
|
|
{
|
|
printf("ERROR: Could not find bpf_config_map in bpf object file.\n");
|
|
return -1;
|
|
}
|
|
|
|
if (bpf_map_update_elem(bpf_config_map_fd, &config->debug_log.key, &config->debug_log.val, 0))
|
|
{
|
|
printf("ERROR: Could not update bpf_config_map element[%s:%d].\n", config->debug_log.key.str, config->debug_log.val);
|
|
return -1;
|
|
}
|
|
|
|
if (bpf_map_update_elem(bpf_config_map_fd, &config->hash_mode.key, &config->hash_mode.val, 0))
|
|
{
|
|
printf("ERROR: Could not update bpf_config_map element[%s:%d].\n", config->hash_mode.key.str, config->hash_mode.val);
|
|
return -1;
|
|
}
|
|
|
|
if (bpf_map_update_elem(bpf_config_map_fd, &config->queue_num.key, &config->queue_num.val, 0))
|
|
{
|
|
printf("ERROR: Could not update bpf_config_map element[%s:%d].\n", config->queue_num.key.str, config->queue_num.val);
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static inline void bpf_config_set_debug_log(struct bpf_config *config, __u32 val)
|
|
{
|
|
config->debug_log.val = val;
|
|
memcpy(config->debug_log.key.str, BPF_CONFIG_KEY_DEBUG_LOG, strlen(BPF_CONFIG_KEY_DEBUG_LOG));
|
|
}
|
|
|
|
static inline void bpf_config_set_hash_mode(struct bpf_config *config, __u32 val)
|
|
{
|
|
config->hash_mode.val = val;
|
|
memcpy(config->hash_mode.key.str, BPF_CONFIG_KEY_HASH_MODE, strlen(BPF_CONFIG_KEY_HASH_MODE));
|
|
}
|
|
|
|
static inline void bpf_config_set_queue_num(struct bpf_config *config, __u32 val)
|
|
{
|
|
config->queue_num.val = val;
|
|
memcpy(config->queue_num.key.str, BPF_CONFIG_KEY_QUEUE_NUM, strlen(BPF_CONFIG_KEY_QUEUE_NUM));
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|