Skip to content

Commit

Permalink
add build in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwei37 committed Aug 30, 2024
1 parent 4c2a6ed commit 8bb0e86
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ jobs:
-DBUILD_BPFTIME_DAEMON=1 \
-DCMAKE_CXX_FLAGS="-DDEFAULT_LOGGER_OUTPUT_PATH='\"console\"'"
cmake --build build --config RelWithDebInfo --target install -j
- name: Build basic examples
run: |
make -C example -j
- name: Upload build results (without jit)
uses: actions/upload-artifact@v3
if: ${{!matrix.enable_jit}}
Expand Down
5 changes: 5 additions & 0 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PHONY: all xdp-counter
all: xdp-counter

xdp-counter:
$(MAKE) -C xdp-counter
18 changes: 7 additions & 11 deletions example/xdp-counter/xdp-counter.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@
#define CTRL_ARRAY_SIZE 2
#define CNTRS_ARRAY_SIZE 512

// use map type define
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, __u32);
__type(value, __u32);
__uint(max_entries, CTRL_ARRAY_SIZE);
} ctl_array SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__type(key, __u32);
__type(value, __u64);
__uint(max_entries, CNTRS_ARRAY_SIZE);
} cntrs_array SEC(".maps");
// use global variable define
__u64 cntrs_array[CNTRS_ARRAY_SIZE];

static void swap_src_dst_mac(void *data)
{
Expand All @@ -56,16 +53,15 @@ int xdp_pass(struct xdp_md* ctx) {
void* data = (void*)(long)ctx->data;
__u32 ctl_flag_pos = 0;
__u32 cntr_pos = 0;
__u32* flag = bpf_map_lookup_elem(&ctl_array, &ctl_flag_pos);

// access maps with helpers
__u32* flag = bpf_map_lookup_elem(&ctl_array, &ctl_flag_pos);
if (!flag || (*flag != 0)) {
return XDP_PASS;
};

__u64* cntr_val = bpf_map_lookup_elem(&cntrs_array, &cntr_pos);
if (cntr_val) {
*cntr_val += 1;
};
// access maps with global variables
cntrs_array[cntr_pos]++;

if (data + sizeof(struct ethhdr) > data_end)
return XDP_DROP;
Expand Down

0 comments on commit 8bb0e86

Please sign in to comment.