summaryrefslogtreecommitdiff
path: root/bpf/bpf_conf_user.h
blob: aa696b7d77b8696956d40359fedf4efe03bd3947 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#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