Skip to content

Commit

Permalink
Fix errors when compiling C source files into eBPF bytecode on a syst…
Browse files Browse the repository at this point in the history
…em with Linux headers version 6.2 or higher.
  • Loading branch information
weixiang committed Jun 7, 2024
1 parent b5ab4dd commit aec5ef5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Release Notes.

#### Bug Fixes
* Fixed the issue where `conntrack` could not find the Reply IP in the access log module.
* Fix errors when compiling C source files into eBPF bytecode on a system with Linux headers version 6.2 or higher.

#### Documentation

Expand Down
8 changes: 4 additions & 4 deletions bpf/accesslog/l24/read_l3.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 10000);
__type(key, __u64);
__type(value, struct bpf_list_head);
__type(value, struct c_bpf_list_head);
} ip_list_rcv_args_map SEC(".maps");

#define ip_list_foreach_skb(loc, time) \
Expand Down Expand Up @@ -74,7 +74,7 @@ int ip_list_rcv(struct pt_regs * ctx) {
struct skb_receive_detail *detail = NULL;

struct sk_buff *skb = NULL, *next = NULL;
struct bpf_list_head skb_list = init_bpf_list_head();
struct c_bpf_list_head skb_list = init_bpf_list_head();
list_for_each_entry_init()
ip_list_foreach_skb(enter_ip_rcv_time, enter_rcv_time)
ip_list_foreach_skb(enter_ip_rcv_time, enter_rcv_time)
Expand All @@ -95,7 +95,7 @@ int ip_list_rcv(struct pt_regs * ctx) {
SEC("kretprobe/ip_list_rcv")
int ip_list_rcv_ret(struct pt_regs * ctx) {
__u64 id = bpf_get_current_pid_tgid();
struct bpf_list_head *head = bpf_map_lookup_elem(&ip_list_rcv_args_map, &id);
struct c_bpf_list_head *head = bpf_map_lookup_elem(&ip_list_rcv_args_map, &id);
if (head == NULL) {
return 0;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ int ip_sublist_rcv_finish(struct pt_regs * ctx) {
struct skb_receive_detail *detail = NULL;

struct sk_buff *skb = NULL, *next = NULL;
struct bpf_list_head skb_list = init_bpf_list_head();
struct c_bpf_list_head skb_list = init_bpf_list_head();
list_for_each_entry_init()
ip_list_foreach_skb(ip_rcv_finish_time, rcv_finish_time)
ip_list_foreach_skb(ip_rcv_finish_time, rcv_finish_time)
Expand Down
16 changes: 8 additions & 8 deletions bpf/include/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,32 @@
if (list_should_enter)

// Customized BPF List implementation
struct bpf_list_head {
struct c_bpf_list_head {
void *data;
struct bpf_list_head *next;
struct c_bpf_list_head *next;
};

static inline struct bpf_list_head init_bpf_list_head() {
struct bpf_list_head head = {};
static inline struct c_bpf_list_head init_bpf_list_head() {
struct c_bpf_list_head head = {};
head.data = NULL;
head.next = NULL;
return head;
}

static inline struct bpf_list_head append_bpf_list_head(struct bpf_list_head* head, void *data) {
struct bpf_list_head new_head = init_bpf_list_head();
static inline struct c_bpf_list_head append_bpf_list_head(struct c_bpf_list_head* head, void *data) {
struct c_bpf_list_head new_head = init_bpf_list_head();
new_head.data = data;
new_head.next = head;
return new_head;
}

static inline int bpf_list_empty(struct bpf_list_head *head) {
static inline int bpf_list_empty(struct c_bpf_list_head *head) {
return head->next == NULL;
}

#define bpf_list_for_each_init() \
bool bpf_list_is_first = true; \
struct bpf_list_head *current_node = NULL;
struct c_bpf_list_head *current_node = NULL;

#define bpf_list_for_each_foreach(pos, head) \
if (bpf_list_is_first) { \
Expand Down

0 comments on commit aec5ef5

Please sign in to comment.