zenith-stack 0.1.0

Zenith 全协议栈框架:AF_XDP + eBPF + TLS 1.3 + HTTP/1-2-3 + Web + Proxy + WAF,按需导入
Documentation
# Zenith eBPF Compilation Makefile
# ==================================
# Compiles eBPF C source files to BPF object files for prebuilt embedding.
#
# Usage:
#   make            # Build all eBPF programs
#   make clean      # Remove prebuilt artifacts
#   make verify     # Verify prebuilt artifacts exist and are non-empty
#
# Architecture:
#   - clang target: bpf (eBPF)
#   - Prebuilt output: bpf/prebuilt/*.o
#   - Include paths: bpf/include/ (vmlinux.h, xdp_common.h) + /usr/include (libbpf)

CLANG ?= clang
CFLAGS = -O2 -target bpf -g -c -Wall -Werror \
         -fno-stack-protector -Wno-macro-redefined \
         -Wno-unused-value -Wno-pointer-to-int-cast

SRC_DIR := src
INC_DIR := include
OUT_DIR := prebuilt

INCLUDES = -I$(INC_DIR) -I/usr/include

SRCS = $(SRC_DIR)/xdp_main.c \
       $(SRC_DIR)/xdp_redirect.c \
       $(SRC_DIR)/xdp_stats.c

OBJS = $(OUT_DIR)/xdp_main.o \
       $(OUT_DIR)/xdp_redirect.o \
       $(OUT_DIR)/xdp_stats.o

.PHONY: all clean verify dirs

all: dirs $(OBJS)

dirs:
	@mkdir -p $(OUT_DIR)

$(OUT_DIR)/xdp_main.o: $(SRC_DIR)/xdp_main.c $(INC_DIR)/xdp_common.h $(INC_DIR)/vmlinux.h
	@echo "  CC  $@"
	$(CLANG) $(CFLAGS) $(INCLUDES) $< -o $@

$(OUT_DIR)/xdp_redirect.o: $(SRC_DIR)/xdp_redirect.c $(INC_DIR)/xdp_common.h $(INC_DIR)/vmlinux.h
	@echo "  CC  $@"
	$(CLANG) $(CFLAGS) $(INCLUDES) $< -o $@

$(OUT_DIR)/xdp_stats.o: $(SRC_DIR)/xdp_stats.c $(INC_DIR)/xdp_common.h $(INC_DIR)/vmlinux.h
	@echo "  CC  $@"
	$(CLANG) $(CFLAGS) $(INCLUDES) $< -o $@

clean:
	@rm -rf $(OUT_DIR)
	@echo "Cleaned prebuilt artifacts"

verify:
	@for obj in $(OBJS); do \
		if [ ! -f "$$obj" ]; then \
			echo "FAIL: $$obj missing"; \
			exit 1; \
		fi; \
		size=$$(stat -c%s "$$obj" 2>/dev/null || echo 0); \
		if [ "$$size" -eq 0 ]; then \
			echo "FAIL: $$obj is empty (0 bytes)"; \
			exit 1; \
		fi; \
		echo "OK: $$obj ($$size bytes)"; \
	done
	@echo "All prebuilt artifacts verified."

# Print SHA-256 hashes for embedding verification
hashes:
	@for obj in $(OBJS); do \
		if [ -f "$$obj" ]; then \
			hash=$$(sha256sum "$$obj" | awk '{print $$1}'); \
			name=$$(basename "$$obj" .o); \
			echo "$$name: $$hash"; \
		fi; \
	done