Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A constant map is used to pass constants #968

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions bpf/include/bpf_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ struct {
__type(value, struct log_event);
} tmp_log_buf SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__uint(key_size, sizeof(__u32));
__uint(value_size, sizeof(__u32));
} bpf_log_level SEC(".maps");

/* Add this macro to get ip addr from ctx variable, include bpf_sock_addr or bpf_sock_ops, weird
reason is that would not be print ipaddr, when directly pass `&ctx->remote_ipv4` to bpf_trace_printk, maybe ctx pass in
to printk would be changed*/
Expand Down Expand Up @@ -98,7 +91,7 @@ static inline int map_lookup_log_level()
{
int zero = 0;
int *value = NULL;
value = kmesh_map_lookup_elem(&bpf_log_level, &zero);
value = kmesh_map_lookup_elem(&bpf_config_map, &zero);
if (!value)
return BPF_LOG_INFO;
return *value;
Expand Down
7 changes: 7 additions & 0 deletions bpf/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ struct {
__type(value, struct buf);
} tmp_buf SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__uint(key_size, sizeof(__u32));
__uint(value_size, sizeof(__u32));
} bpf_config_map SEC(".maps");

#if KERNEL_VERSION_HIGHER_5_13_0
static inline int convert_v4(char *data, __u32 *ip)
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/ads/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (sc *BpfAds) Start() error {
}

func (sc *BpfAds) GetBpfLogLevelMap() *ebpf.Map {
return sc.SockConn.BpfLogLevel
return sc.SockConn.BpfConfigMap
}

func (sc *BpfAds) Stop() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpf/workload/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (w *BpfWorkload) Stop() error {
}

func (w *BpfWorkload) GetBpfLogLevelMap() *ebpf.Map {
return w.SockConn.BpfLogLevel
return w.SockConn.BpfConfigMap
}

func (w *BpfWorkload) Load() error {
Expand Down
Loading