summaryrefslogtreecommitdiff
path: root/bpf/bpf_config_user.h
blob: beba01227ac3e28596b9d0ef327038e0f9f340d6 (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
67
68
69
70
71
72
#ifndef _BPF_CONFIG_USER_H_
#define _BPF_CONFIG_USER_H_

#ifdef __cpluscplus
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 __cpluscplus
}
#endif

#endif