Restructure includes.

This commit is contained in:
Christian Deacon
2025-02-24 15:35:23 -05:00
parent 42738c7670
commit d288a78775
9 changed files with 23 additions and 17 deletions

View File

@@ -30,7 +30,7 @@ jobs:
- name: Install LibXDP.
run: sudo make libxdp_install
- name: Make project
run: LIBBPF_LIBXDP_STATIC=1 make
run: LIBXDP_STATIC=1 make
- name: Install project
run: sudo make install
- name: Store build artifacts

View File

@@ -1,6 +1,6 @@
CC = clang
LIBBPF_LIBXDP_STATIC ?= 0
LIBXDP_STATIC ?= 0
# Top-level directories.
BUILD_DIR = build
@@ -61,7 +61,7 @@ LOADER_UTILS_HELPERS_OBJ = helpers.o
# Loader objects.
LOADER_OBJS = $(BUILD_LOADER_DIR)/$(LOADER_UTILS_CONFIG_OBJ) $(BUILD_LOADER_DIR)/$(LOADER_UTILS_CMDLINE_OBJ) $(BUILD_LOADER_DIR)/$(LOADER_UTILS_XDP_OBJ) $(BUILD_LOADER_DIR)/$(LOADER_UTILS_STATS_OBJ) $(BUILD_LOADER_DIR)/$(LOADER_UTILS_HELPERS_OBJ)
ifeq ($(LIBBPF_LIBXDP_STATIC), 1)
ifeq ($(LIBXDP_STATIC), 1)
LOADER_OBJS := $(LIBBPF_OBJS) $(LIBXDP_OBJS) $(LOADER_OBJS)
endif
@@ -70,13 +70,21 @@ XDP_SRC = prog.c
XDP_OBJ = xdp_prog.o
# Includes.
INCS = -I $(SRC_DIR) -I $(LIBBPF_SRC) -I /usr/include -I /usr/local/include
INCS = -I $(SRC_DIR)
ifeq ($(LIBXDP_STATIC), 1)
INCS += -I $(XDP_TOOLS_HEADERS) -I $(LIBBPF_SRC)
else
INCS += -I /usr/include -I /usr/local/include
endif
# Flags.
FLAGS = -O2 -g
FLAGS_LOADER = -lconfig -lelf -lz
ifeq ($(LIBBPF_LIBXDP_STATIC), 0)
ifeq ($(LIBXDP_STATIC), 1)
FLAGS += -D__LIBXDP_STATIC__
else
FLAGS_LOADER += -lbpf -lxdp
endif

View File

@@ -293,13 +293,13 @@ If you receive an error similar to the one below when running the program, make
./xdpfw: error while loading shared libraries: libxdp.so.1: cannot open shared object file: No such file or directory
```
If you don't want to have LibXDP installed on your system after building the program, you can set the `LIBBPF_LIBXDP_STATIC` environmental variable to `1` while building the project with `make` or pass the `--static` flag to the [`install.sh`](./install.sh) Bash script. This will link all of the LibBPF and LibXDP object files while building the loader so you shouldn't need LibXDP installed globally.
If you don't want to have LibXDP installed on your system after building the program, you can set the `LIBXDP_STATIC` environmental variable to `1` while building the project with `make` or pass the `--static` flag to the [`install.sh`](./install.sh) Bash script. This will link all of the LibBPF and LibXDP object files while building the loader so you shouldn't need LibXDP installed globally.
For example:
```bash
# Build with LibBPF and LibXDP object files linked directly from modules/xdp-tools directories.
LIBBPF_LIBXDP_STATIC=1 make
LIBXDP_STATIC=1 make
# Install onto system.
sudo make install

View File

@@ -7,7 +7,7 @@ if [ -z "$STATIC" ]; then
fi
if [ -z "$ROOT" ]; then
LIBBPF_LIBXDP_STATIC=$STATIC make
LIBXDP_STATIC=$STATIC make
else
cd $ROOT && LIBBPF_LIBXDP_STATIC=$STATIC make
cd $ROOT && LIBXDP_STATIC=$STATIC make
fi

View File

@@ -6,7 +6,6 @@
#include <stdlib.h>
#include <libconfig.h>
#include <string.h>
#include <linux/types.h>
#include <arpa/inet.h>

View File

@@ -1,7 +1,5 @@
#pragma once
#include <bpf.h>
#include <libbpf.h>
#include <xdp/libxdp.h>
#include <common/all.h>

View File

@@ -1,7 +1,5 @@
#pragma once
#include <bpf.h>
#include <libbpf.h>
#include <xdp/libxdp.h>
#include <common/all.h>

View File

@@ -3,12 +3,16 @@
#include <common/all.h>
#include <linux/bpf.h>
#include <linux/bpf_common.h>
#include <bpf_helpers.h>
#include <xdp/xdp_helpers.h>
#include <xdp/prog_dispatcher.h>
#ifdef __LIBXDP_STATIC__
#include <bpf_helpers.h>
#else
#include <bpf/bpf_helpers.h>
#endif
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

View File

@@ -9,7 +9,6 @@
static __always_inline void UpdateIpStats(u64 *pps, u64 *bps, u32 ip, u16 port, u8 protocol, u16 pkt_len, u64 now);
static __always_inline void UpdateIp6Stats(u64 *pps, u64 *bps, u128 *ip, u16 port, u8 protocol, u16 pkt_len, u64 now);
// The source file is included directly below instead of compiled and linked as an object because when linking, there is no guarantee the compiler will inline the function (which is crucial for performance).
// I'd prefer not to include the function logic inside of the header file.
// More Info: https://stackoverflow.com/questions/24289599/always-inline-does-not-work-when-function-is-implemented-in-different-file