Skip to content

Commit

Permalink
add prefix km_ in almost all kmesh bpf map
Browse files Browse the repository at this point in the history
Signed-off-by: LiZhenCheng9527 <[email protected]>
  • Loading branch information
LiZhenCheng9527 committed Nov 30, 2024
1 parent 204d46d commit a060c7b
Show file tree
Hide file tree
Showing 60 changed files with 1,176 additions and 1,176 deletions.
12 changes: 6 additions & 6 deletions bpf/include/bpf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "common.h"
#include "inner_map_defs.h"

#define map_of_manager kmesh_manage
#define km_map_of_manager km_manage
#define MAP_SIZE_OF_MANAGER 8192
/*0x3a1(929) is the specific port handled by the cni to enable kmesh*/
#define ENABLE_KMESH_PORT 0x3a1
Expand Down Expand Up @@ -40,7 +40,7 @@ struct {
__type(value, __u32);
__uint(max_entries, MAP_SIZE_OF_MANAGER);
__uint(map_flags, BPF_F_NO_PREALLOC);
} map_of_manager SEC(".maps");
} km_map_of_manager SEC(".maps");

struct sock_storage_data {
__u64 connect_ns;
Expand All @@ -53,7 +53,7 @@ struct {
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct sock_storage_data);
} map_of_sock_storage SEC(".maps");
} km_map_of_sock_storage SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_HASH);
Expand Down Expand Up @@ -98,7 +98,7 @@ static inline void record_manager_netns_cookie(struct bpf_sock_addr *ctx)
key.netns_cookie = bpf_get_netns_cookie(ctx);
__u32 value = 0;

err = bpf_map_update_elem(&map_of_manager, &key, &value, BPF_ANY);
err = bpf_map_update_elem(&km_map_of_manager, &key, &value, BPF_ANY);
if (err)
BPF_LOG(ERR, KMESH, "record netcookie failed!, err is %d\n", err);
}
Expand All @@ -111,7 +111,7 @@ static inline bool is_kmesh_enabled(struct bpf_sock_addr *ctx)
{
struct manager_key key = {0};
key.netns_cookie = bpf_get_netns_cookie(ctx);
return bpf_map_lookup_elem(&map_of_manager, &key);
return bpf_map_lookup_elem(&km_map_of_manager, &key);
}

/*
Expand All @@ -124,7 +124,7 @@ static inline void remove_manager_netns_cookie(struct bpf_sock_addr *ctx)
struct manager_key key = {0};
key.netns_cookie = bpf_get_netns_cookie(ctx);

err = bpf_map_delete_elem(&map_of_manager, &key);
err = bpf_map_delete_elem(&km_map_of_manager, &key);
if (err && err != -ENOENT)
BPF_LOG(ERR, KMESH, "remove netcookie failed!, err is %d\n", err);
}
Expand Down
8 changes: 4 additions & 4 deletions bpf/include/bpf_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ struct log_event {
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 256 * 1024 /* 256 KB */);
} kmesh_events SEC(".maps");
} km_events SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, struct log_event);
} tmp_log_buf SEC(".maps");
} km_tmp_log_buf 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
Expand Down Expand Up @@ -74,7 +74,7 @@ lower than 22.09, compile would report an error of bpf_snprintf dont exist */
({ \
struct log_event *e; \
__u32 ret = 0; \
e = bpf_ringbuf_reserve(&kmesh_events, sizeof(struct log_event), 0); \
e = bpf_ringbuf_reserve(&km_events, sizeof(struct log_event), 0); \
if (!e) \
break; \
ret = Kmesh_BPF_SNPRINTF(e->msg, sizeof(e->msg), fmt, args); \
Expand All @@ -91,7 +91,7 @@ static inline int map_lookup_log_level()
{
int zero = 0;
struct kmesh_config *value = {0};
value = kmesh_map_lookup_elem(&kmesh_config_map, &zero);
value = kmesh_map_lookup_elem(&km_config_map, &zero);
if (!value)
return BPF_LOG_INFO;
return value->bpf_log_level;
Expand Down
6 changes: 3 additions & 3 deletions bpf/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ struct {
__uint(max_entries, 1);
__type(key, int);
__type(value, struct buf);
} tmp_buf SEC(".maps");
} km_tmp_buf SEC(".maps");

/*
* This map is used to store different configuration options:
Expand All @@ -149,7 +149,7 @@ struct {
__uint(max_entries, 1);
__type(key, int);
__type(value, struct kmesh_config);
} kmesh_config_map SEC(".maps");
} km_config_map SEC(".maps");

#if KERNEL_VERSION_HIGHER_5_13_0
static inline int convert_v4(char *data, __u32 *ip)
Expand Down Expand Up @@ -257,7 +257,7 @@ static inline char *ip2str(__u32 *ip_ptr, bool v4)
struct buf *buf;
int zero = 0;
int ret;
buf = bpf_map_lookup_elem(&tmp_buf, &zero);
buf = bpf_map_lookup_elem(&km_tmp_buf, &zero);
if (!buf)
return NULL;
if (v4) {
Expand Down
10 changes: 5 additions & 5 deletions bpf/kmesh/ads/include/circuit_breaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct {
__uint(value_size, sizeof(struct cluster_stats));
__uint(map_flags, BPF_F_NO_PREALLOC);
__uint(max_entries, MAP_SIZE_OF_CLUSTER);
} map_of_cluster_stats SEC(".maps");
} km_map_of_cluster_stats SEC(".maps");

struct cluster_sock_data {
__u32 cluster_id;
Expand All @@ -46,11 +46,11 @@ static inline void update_cluster_active_connections(const struct cluster_stats_
if (!key) {
return;
}
stats = kmesh_map_lookup_elem(&map_of_cluster_stats, key);
stats = kmesh_map_lookup_elem(&km_map_of_cluster_stats, key);
if (!stats) {
struct cluster_stats init_value = {0};
bpf_map_update_elem(&map_of_cluster_stats, key, &init_value, BPF_NOEXIST);
stats = kmesh_map_lookup_elem(&map_of_cluster_stats, key);
bpf_map_update_elem(&km_map_of_cluster_stats, key, &init_value, BPF_NOEXIST);
stats = kmesh_map_lookup_elem(&km_map_of_cluster_stats, key);
}

if (!stats) {
Expand Down Expand Up @@ -82,7 +82,7 @@ static inline int on_cluster_sock_bind(ctx_buff_t *ctx, const Cluster__Cluster *
key.cluster_id = cluster_id;
key.netns_cookie = cookie;
struct cluster_stats *stats = NULL;
stats = kmesh_map_lookup_elem(&map_of_cluster_stats, &key);
stats = kmesh_map_lookup_elem(&km_map_of_cluster_stats, &key);

if (stats != NULL) {
Cluster__CircuitBreakers *cbs = NULL;
Expand Down
16 changes: 8 additions & 8 deletions bpf/kmesh/ads/include/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct {
__uint(value_size, sizeof(Cluster__Cluster));
__uint(map_flags, BPF_F_NO_PREALLOC);
__uint(max_entries, MAP_SIZE_OF_CLUSTER);
} map_of_cluster SEC(".maps");
} km_map_of_cluster SEC(".maps");

struct inner_of_maglev {
__uint(type, BPF_MAP_TYPE_ARRAY);
Expand All @@ -37,7 +37,7 @@ struct {
__uint(max_entries, MAP_SIZE_OF_CLUSTER);
__uint(map_flags, BPF_F_NO_PREALLOC);
__array(values, struct inner_of_maglev);
} outer_of_maglev SEC(".maps");
} km_outer_of_maglev SEC(".maps");

struct cluster_endpoints {
__u32 ep_num;
Expand All @@ -57,34 +57,34 @@ struct {
__uint(value_size, sizeof(struct cluster_endpoints));
__uint(max_entries, MAP_SIZE_OF_ENDPOINT);
__uint(map_flags, BPF_F_NO_PREALLOC);
} map_of_cluster_eps SEC(".maps");
} km_map_of_cluster_eps SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(key_size, sizeof(int));
__uint(value_size, sizeof(struct cluster_endpoints));
__uint(max_entries, 1);
} map_of_cluster_eps_data SEC(".maps");
} km_map_of_cluster_eps_data SEC(".maps");

static inline struct cluster_endpoints *map_lookup_cluster_eps_data()
{
int location = 0;
return kmesh_map_lookup_elem(&map_of_cluster_eps_data, &location);
return kmesh_map_lookup_elem(&km_map_of_cluster_eps_data, &location);
}

static inline Cluster__Cluster *map_lookup_cluster(const char *cluster_name)
{
return kmesh_map_lookup_elem(&map_of_cluster, cluster_name);
return kmesh_map_lookup_elem(&km_map_of_cluster, cluster_name);
}

static inline struct cluster_endpoints *map_lookup_cluster_eps(const char *cluster_name)
{
return kmesh_map_lookup_elem(&map_of_cluster_eps, cluster_name);
return kmesh_map_lookup_elem(&km_map_of_cluster_eps, cluster_name);
}

static inline int map_add_cluster_eps(const char *cluster_name, const struct cluster_endpoints *eps)
{
return kmesh_map_update_elem(&map_of_cluster_eps, cluster_name, eps);
return kmesh_map_update_elem(&km_map_of_cluster_eps, cluster_name, eps);
}

static inline int
Expand Down
4 changes: 2 additions & 2 deletions bpf/kmesh/ads/include/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ struct {
__uint(value_size, sizeof(Listener__Listener));
__uint(max_entries, MAP_SIZE_OF_LISTENER);
__uint(map_flags, BPF_F_NO_PREALLOC);
} map_of_listener SEC(".maps");
} km_map_of_listener SEC(".maps");

static inline Listener__Listener *map_lookup_listener(const address_t *addr)
{
return kmesh_map_lookup_elem(&map_of_listener, addr);
return kmesh_map_lookup_elem(&km_map_of_listener, addr);
}

static inline bool listener_filter_chain_match_check(
Expand Down
8 changes: 4 additions & 4 deletions bpf/kmesh/ads/include/local_ratelimit.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct {
__type(value, struct ratelimit_value);
__uint(max_entries, MAP_SIZE_OF_LISTENER);
__uint(map_flags, BPF_F_NO_PREALLOC);
} kmesh_ratelimit SEC(".maps");
} km_ratelimit SEC(".maps");

struct ratelimit_settings {
__u64 max_tokens; /* Maximum capacity of the token bucket */
Expand All @@ -55,12 +55,12 @@ static inline int rate_limit__check_and_take(struct ratelimit_key *key, const st
__u64 topup_time;
__u64 delta;

value = bpf_map_lookup_elem(&kmesh_ratelimit, key);
value = bpf_map_lookup_elem(&km_ratelimit, key);
if (!value) {
new_value.last_topup = now;
new_value.tokens = settings->max_tokens;
bpf_map_update_elem(&kmesh_ratelimit, key, &new_value, BPF_NOEXIST);
value = bpf_map_lookup_elem(&kmesh_ratelimit, key);
bpf_map_update_elem(&km_ratelimit, key, &new_value, BPF_NOEXIST);
value = bpf_map_lookup_elem(&km_ratelimit, key);
if (!value)
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions bpf/kmesh/ads/include/route_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ struct {
__uint(value_size, sizeof(Route__RouteConfiguration));
__uint(max_entries, MAP_SIZE_OF_ROUTE);
__uint(map_flags, BPF_F_NO_PREALLOC);
} map_of_router_config SEC(".maps");
} km_map_of_router_config SEC(".maps");

static inline Route__RouteConfiguration *map_lookup_route_config(const char *route_name)
{
if (!route_name)
return NULL;

return kmesh_map_lookup_elem(&map_of_router_config, route_name);
return kmesh_map_lookup_elem(&km_map_of_router_config, route_name);
}

static inline int
Expand Down
12 changes: 6 additions & 6 deletions bpf/kmesh/ads/include/tail_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ struct {
__uint(value_size, sizeof(__u32));
__uint(max_entries, MAP_SIZE_OF_TAIL_CALL_PROG);
__uint(map_flags, 0);
} map_of_tail_call_prog SEC(".maps");
} km_map_of_tail_call_prog SEC(".maps");

static inline void kmesh_tail_call(ctx_buff_t *ctx, const __u32 index)
{
bpf_tail_call(ctx, &map_of_tail_call_prog, index);
bpf_tail_call(ctx, &km_map_of_tail_call_prog, index);
}

typedef struct {
Expand All @@ -44,21 +44,21 @@ struct {
__uint(value_size, sizeof(ctx_val_t));
__uint(max_entries, MAP_SIZE_OF_TAIL_CALL_CTX);
__uint(map_flags, BPF_F_NO_PREALLOC);
} map_of_tail_call_ctx SEC(".maps");
} km_map_of_tail_call_ctx SEC(".maps");

static inline ctx_val_t *kmesh_tail_lookup_ctx(const ctx_key_t *key)
{
return (ctx_val_t *)bpf_map_lookup_elem(&map_of_tail_call_ctx, key);
return (ctx_val_t *)bpf_map_lookup_elem(&km_map_of_tail_call_ctx, key);
}

static inline void kmesh_tail_delete_ctx(const ctx_key_t *key)
{
(void)bpf_map_delete_elem(&map_of_tail_call_ctx, key);
(void)bpf_map_delete_elem(&km_map_of_tail_call_ctx, key);
}

static inline int kmesh_tail_update_ctx(const ctx_key_t *key, const ctx_val_t *value)
{
return (int)bpf_map_update_elem(&map_of_tail_call_ctx, key, value, BPF_ANY);
return (int)bpf_map_update_elem(&km_map_of_tail_call_ctx, key, value, BPF_ANY);
}

/*
Expand Down
Loading

0 comments on commit a060c7b

Please sign in to comment.