Open kwjjyn opened 5 years ago
Hi, Thanks for testing this case. The user_xdp5.c is obsolete and not tested at all. I did quick fix to make it works by
diff --git a/lib/libbpf.h b/lib/libbpf.h
index 1c874b8..ada1e31 100644
--- a/lib/libbpf.h
+++ b/lib/libbpf.h
@@ -4,19 +4,19 @@
struct bpf_insn;
-int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
+static int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
int max_entries);
-int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags);
-int bpf_lookup_elem(int fd, void *key, void *value);
-int bpf_delete_elem(int fd, void *key);
-int bpf_get_next_key(int fd, void *key, void *next_key);
+static int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags);
+static int bpf_lookup_elem(int fd, void *key, void *value);
+static int bpf_delete_elem(int fd, void *key);
+static int bpf_get_next_key(int fd, void *key, void *next_key);
-int bpf_prog_load(enum bpf_prog_type prog_type,
+static int bpf_prog_load(enum bpf_prog_type prog_type,
const struct bpf_insn *insns, int insn_len,
const char *license, int kern_version);
-int bpf_obj_pin(int fd, const char *pathname);
-int bpf_obj_get(const char *pathname);
+static int bpf_obj_pin(int fd, const char *pathname);
+static int bpf_obj_get(const char *pathname);
#define LOG_BUF_SIZE 262144
extern char bpf_log_buf[LOG_BUF_SIZE];
diff --git a/tests/user_xdp5.c b/tests/user_xdp5.c
index ca13f9d..32f2875 100644
--- a/tests/user_xdp5.c
+++ b/tests/user_xdp5.c
@@ -26,13 +26,10 @@ int main(void)
{
int ret;
int fd;
- struct dstmactable_key key;
- struct dstmactable_value value;
+ struct Ingress_dstmactable_key key;
+ struct Ingress_dstmactable_value value;
- /* populate the default table */
- initialize_tables();
-
- value.action = Fallback_action;
+ value.action = Ingress_Fallback_action;
key.field0 = 0x800; // IP packet
printf("=== Open BPF map: %s ===\n", MAP_PATH TABLE);
and compile it with
root@ba8b8adc32b6:/home/p4c/extensions/p4c-xdp/tests# gcc -I. -I../../../backends/ebpf/runtime/ -I ../lib/ ../lib/libbpf.o user_xdp5.c
@williamtu : do you want to push your changes to libbpf.h as a pull request?
Actually when I update libbpf.h , I found that I can't run make
in the /tests , because the load_and_verify.c file relies on the ../lib/bpf_load.c which alse include the libbpf.h . However, the functions which bpf_load,c calls are defined static functions in the libbpf.h . So it can't be compiled right.
But it's all right. The control plane code just use libbpf.h code . And I delete the bpf_load.c , .h and dont use the bpfloader anymore.
At the last . I think maybe you can maintain a copy of libbpf.h and libbpf.c with static in another folder like lib-control . And there is no effect on the /tests . And compile the control plane code with
gcc -I../../../backends/ebpf/runtime/ -I ../lib-control/ ../lib-control/libbpf.o user_xdp5.c -o user_xdp5
Thanks for your help. I will work on a pull request.
keep it open until fixed.
Hi, When I run the below command in the /p4c/extensions/p4c-xdp/tests :
there's an error that
And then I found the header files to be included are in the /p4c/backends/ebpf/runtime/, so I move the ebpf_kernel.h and ebpf_common.h into the /tests :
however, when I compile again , some other errors occured :
could you give me some advice? Thanks.