This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-kni/bpf/bpf_conf_user.h
luwenpeng f7ea81dad8 TSG-10254 eBPF支持二元组分流
TSG-10527 eBPF支持四元组分流
TSG-10369 KNI多线程在TAP模式下支持eBPF分流
2022-05-31 17:38:42 +08:00

67 lines
1.8 KiB
C

#ifndef _BPF_CONF_USER_H_
#define _BPF_CONF_USER_H_
#ifdef __cplusplus
extern "C"
{
#endif
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
#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