vincentmli / BPFire

BPFire development tree
36 stars 3 forks source link

lunatik addon for BPFire #40

Closed vincentmli closed 1 month ago

vincentmli commented 1 month ago

following diff to lunatik Makefile to build lunatik addon in BPFire

root@r210:/home/vincent/go/src/github.com/vincentmli/BPFire/cache/lunatik-5.3.2# git diff
diff --git a/Makefile b/Makefile
index ec172541..06c0fdb8 100644
--- a/Makefile
+++ b/Makefile
@@ -3,14 +3,14 @@

 MODULES_INSTALL_PATH = /lib/modules/${shell uname -r}
 SCRIPTS_INSTALL_PATH = /lib/modules/lua
-LUNATIK_INSTALL_PATH = /usr/local/sbin
-LUA_API = lua/lua.h lua/lauxlib.h lua/lualib.h
+LUNATIK_INSTALL_PATH = /usr/sbin
+LUA_API = $(PWD)/lua/lua.h $(PWD)/lua/lauxlib.h $(PWD)/lua/lualib.h
 KDIR ?= ${MODULES_INSTALL_PATH}/build
 RM = rm -f
 MKDIR = mkdir -p -m 0755
 INSTALL = install -o root -g root

-all: lunatik_sym.h
+all: $(LUA_API)/lunatik_sym.h
        ${MAKE} -C ${KDIR} M=${PWD} CONFIG_LUNATIK=m    \
        CONFIG_LUNATIK_RUN=m CONFIG_LUNATIK_RUNTIME=y CONFIG_LUNATIK_DEVICE=m   \
        CONFIG_LUNATIK_LINUX=m CONFIG_LUNATIK_NOTIFIER=m CONFIG_LUNATIK_SOCKET=m \
@@ -70,6 +70,6 @@ install: scripts_install modules_install
 uninstall: scripts_uninstall modules_uninstall
        depmod -a

-lunatik_sym.h: $(LUA_API)
+$(LUA_API)/lunatik_sym.h: $(LUA_API)
        ${shell ./gensymbols.sh $(LUA_API) > lunatik_sym.h}

see https://github.com/luainkernel/lunatik/issues/189

vincentmli commented 1 month ago

lunatik change:

    BPFire lunatik build change

    adjust lunatik kernel module and https.o build
    for BPFire chroot environment

    see https://github.com/luainkernel/lunatik/issues/189

    Signed-off-by: Vincent Li <vincent.mc.li@gmail.com>

diff --git a/Makefile b/Makefile
index ec172541..1c72f3e1 100644
--- a/Makefile
+++ b/Makefile
@@ -3,14 +3,14 @@

 MODULES_INSTALL_PATH = /lib/modules/${shell uname -r}
 SCRIPTS_INSTALL_PATH = /lib/modules/lua
-LUNATIK_INSTALL_PATH = /usr/local/sbin
-LUA_API = lua/lua.h lua/lauxlib.h lua/lualib.h
+LUNATIK_INSTALL_PATH = /usr/sbin
+LUNATIK_EBPF_INSTALL_PATH = /usr/lib/bpf
 KDIR ?= ${MODULES_INSTALL_PATH}/build
 RM = rm -f
 MKDIR = mkdir -p -m 0755
 INSTALL = install -o root -g root

-all: lunatik_sym.h
+all:
        ${MAKE} -C ${KDIR} M=${PWD} CONFIG_LUNATIK=m    \
        CONFIG_LUNATIK_RUN=m CONFIG_LUNATIK_RUNTIME=y CONFIG_LUNATIK_DEVICE=m   \
        CONFIG_LUNATIK_LINUX=m CONFIG_LUNATIK_NOTIFIER=m CONFIG_LUNATIK_SOCKET=m \
@@ -46,6 +46,7 @@ examples_install:
        ${INSTALL} -m 0644 examples/echod/*.lua ${SCRIPTS_INSTALL_PATH}/examples/echod
        ${MKDIR} ${SCRIPTS_INSTALL_PATH}/examples/filter
        ${INSTALL} -m 0644 examples/filter/*.lua ${SCRIPTS_INSTALL_PATH}/examples/filter
+       ${INSTALL} -m 0644 examples/filter/*.o ${LUNATIK_EBPF_INSTALL_PATH}
        ${MKDIR} ${SCRIPTS_INSTALL_PATH}/examples/dnsblock
        ${INSTALL} -m 0644 examples/dnsblock/*.lua ${SCRIPTS_INSTALL_PATH}/examples/dnsblock
        ${MKDIR} ${SCRIPTS_INSTALL_PATH}/examples/dnsdoctor
@@ -69,7 +70,3 @@ install: scripts_install modules_install

 uninstall: scripts_uninstall modules_uninstall
        depmod -a
-
-lunatik_sym.h: $(LUA_API)
-       ${shell ./gensymbols.sh $(LUA_API) > lunatik_sym.h}
-
diff --git a/examples/filter/Makefile b/examples/filter/Makefile
index f7eb0f6d..4d2fd3b9 100644
--- a/examples/filter/Makefile
+++ b/examples/filter/Makefile
@@ -1,10 +1,12 @@
 # SPDX-FileCopyrightText: (c) 2023-2024 Ring Zero Desenvolvimento de Software LTDA
 # SPDX-License-Identifier: MIT OR GPL-2.0-only

+VMLINUX_BTF_PATH = /lib/modules/6.6.15-ipfire/build
+
 all: vmlinux https.o

 vmlinux:
-       bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
+       bpftool btf dump file $(VMLINUX_BTF_PATH)/vmlinux format c > vmlinux.h

 https.o: https.c
        clang -target bpf -Wall -O2 -c -g $<
vincentmli commented 1 month ago

lunatik filter sni for BPFire has limitation for chrome browser in https://github.com/luainkernel/lunatik/issues/193 and chrome browser is very popular