From 410367e6851e8fb386abecb88369d6fa4e9871b9 Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Tue, 9 Apr 2024 23:40:48 +0300 Subject: musl: Add musl compatibility Thanks for hints Alpine Linux project and their patches: https://git.alpinelinux.org/aports/tree/community/accel-ppp?h=master We can adjust a bit code and cmake config files to make accel-ppp buildable under musl "as is". Signed-off-by: Denys Fedoryshchenko --- accel-pppd/CMakeLists.txt | 45 ++++++++++++++++++++++++++++++++++++++++++- accel-pppd/ctrl/ipoe/arp.c | 2 ++ accel-pppd/ctrl/ipoe/ipoe.c | 2 ++ accel-pppd/ctrl/l2tp/l2tp.c | 4 ++++ accel-pppd/ctrl/pppoe/pppoe.c | 2 ++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/accel-pppd/CMakeLists.txt b/accel-pppd/CMakeLists.txt index ab8a350..d194eaa 100644 --- a/accel-pppd/CMakeLists.txt +++ b/accel-pppd/CMakeLists.txt @@ -44,6 +44,33 @@ IF (RADIUS) ADD_SUBDIRECTORY(radius) ENDIF (RADIUS) +# define __free_fn_t in musl +INCLUDE (CheckCSourceCompiles) +CHECK_C_SOURCE_COMPILES(" +#include +int main(void) +{ + __free_fn_t *f; + return 0; +}" HAVE_FREE_FN_T) +IF (HAVE_FREE_FN_T) + ADD_DEFINITIONS(-DHAVE_FREE_FN_T) +ENDIF (HAVE_FREE_FN_T) + +INCLUDE (CheckCSourceCompiles) +CHECK_C_SOURCE_COMPILES(" +#include +#include +int main(void) +{ + return 0; +}" HAVE_GOOD_IFARP) + +IF (HAVE_GOOD_IFARP) + ADD_DEFINITIONS(-DHAVE_GOOD_IFARP) +ENDIF (HAVE_GOOD_IFARP) + + ADD_SUBDIRECTORY(triton) ADD_SUBDIRECTORY(vlan-mon) ADD_SUBDIRECTORY(ctrl) @@ -62,6 +89,12 @@ ENDIF (SHAPER) INCLUDE(CheckIncludeFile) CHECK_INCLUDE_FILE("linux/netfilter/ipset/ip_set.h" HAVE_IPSET) +# MUSL does not have printf.h +CHECK_INCLUDE_FILE("printf.h" HAVE_PRINTF_H) +IF (HAVE_PRINTF_H) + ADD_DEFINITIONS(-DHAVE_PRINTF_H) +ENDIF (HAVE_PRINTF_H) + INCLUDE(CheckFunctionExists) CHECK_FUNCTION_EXISTS(setns HAVE_SETNS) @@ -123,7 +156,17 @@ ADD_EXECUTABLE(accel-pppd main.c ) -TARGET_LINK_LIBRARIES(accel-pppd triton rt pthread ${crypto_lib} pcre) +# check if we have getcontext/setcontext +INCLUDE(CheckFunctionExists) +CHECK_FUNCTION_EXISTS(getcontext HAVE_GETCONTEXT) +CHECK_FUNCTION_EXISTS(setcontext HAVE_SETCONTEXT) + +IF (HAVE_GETCONTEXT AND HAVE_SETCONTEXT) + TARGET_LINK_LIBRARIES(accel-pppd triton rt pthread ${crypto_lib} pcre) +ELSE (HAVE_GETCONTEXT AND HAVE_SETCONTEXT) + TARGET_LINK_LIBRARIES(accel-pppd triton rt pthread ${crypto_lib} pcre ucontext) +ENDIF (HAVE_GETCONTEXT AND HAVE_SETCONTEXT) + set_property(TARGET accel-pppd PROPERTY CMAKE_SKIP_BUILD_RPATH FALSE) set_property(TARGET accel-pppd PROPERTY CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set_property(TARGET accel-pppd PROPERTY INSTALL_RPATH_USE_LINK_PATH FALSE) diff --git a/accel-pppd/ctrl/ipoe/arp.c b/accel-pppd/ctrl/ipoe/arp.c index e9b55ff..ef9d385 100644 --- a/accel-pppd/ctrl/ipoe/arp.c +++ b/accel-pppd/ctrl/ipoe/arp.c @@ -13,7 +13,9 @@ #include #include #include +#ifdef HAVE_GOOD_IFARP #include +#endif #include #include "list.h" diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 61b7c23..95ff856 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -15,7 +15,9 @@ #include #include #include +#ifdef HAVE_GOOD_IFARP #include +#endif #include #include diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index 027d710..9fc2283 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -853,7 +853,11 @@ static void l2tp_tunnel_free_sessions(struct l2tp_conn_t *conn) void *sessions = conn->sessions; conn->sessions = NULL; +#ifdef HAVE_FREE_FN_T tdestroy(sessions, (__free_fn_t)l2tp_session_free); +#else + tdestroy(sessions, free); +#endif /* Let l2tp_session_free() handle the session counter and * the reference held by the tunnel. */ diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index 7668428..dd623ac 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -11,7 +11,9 @@ #include #include #include +#ifdef HAVE_PRINTF_H #include +#endif #include "crypto.h" -- cgit v1.2.3 From ce3ee7595c1239a20de589c95dd8ccce38ae49e7 Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Wed, 10 Apr 2024 00:59:40 +0300 Subject: workflows: Add CI build in Alpine As we fixed musl compatibility, we can add also basic check if accel keep working in Alpine Linux Also update default config, enable connlimit and place it before pptp, otherwise Alpine generate error: ``` [2024-04-09 22:30:09.911]loader: failed to load 'pptp': Error relocating /usr/local/lib64/accel-ppp/libpptp.so: connlimit_check: symbol not found ``` Signed-off-by: Denys Fedoryshchenko --- .github/workflows/build-and-run.yml | 38 ++++++++++++++++++++++++++++++++++++- accel-pppd/accel-ppp.conf | 4 +++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-run.yml b/.github/workflows/build-and-run.yml index 8ddbafa..2fbc938 100644 --- a/.github/workflows/build-and-run.yml +++ b/.github/workflows/build-and-run.yml @@ -77,7 +77,8 @@ jobs: path: build/accel-ppp_*.deb if-no-files-found: error - Build-in-Container: + # Debian based distros + Build-in-Container-Debian: #if: ${{ false }} # disable for now strategy: fail-fast: false @@ -215,3 +216,38 @@ jobs: run: sleep 1 - name: Check accel-ppp stat run: accel-cmd show stat + + Build-in-Container-Alpine: + runs-on: ubuntu-latest + container: + image: alpine:latest + steps: + - name: Install build tools + run: > + apk update && apk add --no-cache git cmake make g++ pcre-dev libressl-dev linux-headers libucontext-dev lua5.1-dev + - name: Check out repository code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: mkdir build + run: mkdir build + - name: Disable git security warnings + run: git config --global --add safe.directory '*' + - name: cmake + working-directory: ./build + run: > + cmake -DBUILD_IPOE_DRIVER=FALSE -DBUILD_VLAN_MON_DRIVER=FALSE -DCMAKE_INSTALL_PREFIX=/usr + -DKDIR=/usr/src/linux-headers-`uname -r` + -DLUA=TRUE -DSHAPER=FALSE -DRADIUS=TRUE .. + - name: make and install + working-directory: ./build + run: make && make install + - name: Copy default config + run: cp accel-pppd/accel-ppp.conf /etc/accel-ppp.conf + - name: Start accel-ppp with default config + run: accel-pppd -d -c /etc/accel-ppp.conf + - name: Sleep for 1 sec + run: sleep 1 + - name: Check accel-ppp stat + run: accel-cmd show stat + \ No newline at end of file diff --git a/accel-pppd/accel-ppp.conf b/accel-pppd/accel-ppp.conf index e80ffd0..abfd1ac 100644 --- a/accel-pppd/accel-ppp.conf +++ b/accel-pppd/accel-ppp.conf @@ -4,6 +4,8 @@ log_file #log_tcp #log_pgsql +connlimit + pptp l2tp #sstp @@ -25,7 +27,7 @@ pppd_compat #shaper #net-snmp #logwtmp -#connlimit + #ipv6_nd #ipv6_dhcp -- cgit v1.2.3