diff --git a/testing/mptcpd/0001-include-define-__bswap_constant_-16-32-if-needed.patch b/testing/mptcpd/0001-include-define-__bswap_constant_-16-32-if-needed.patch new file mode 100644 index 0000000000000000000000000000000000000000..c14b31fec0cb82f28a7ec0cf55d5c92620f7b183 --- /dev/null +++ b/testing/mptcpd/0001-include-define-__bswap_constant_-16-32-if-needed.patch @@ -0,0 +1,40 @@ +From 9c964d03a9c857a2d3b67be2619e0cc3d3eba8e5 Mon Sep 17 00:00:00 2001 +From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org> +Date: Wed, 20 Nov 2024 12:20:07 +0100 +Subject: [PATCH 1/4] include: define __bswap_constant_{16,32} if needed + +Some libc like musl don't support them. + +Let's simply define them if they are not defined. + +From GNU C Library, bits/byteswap.h, under LGPL. + +Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> +--- + include/mptcpd/private/sockaddr.h | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/include/mptcpd/private/sockaddr.h b/include/mptcpd/private/sockaddr.h +index 1b8de34..5d74ef8 100644 +--- a/include/mptcpd/private/sockaddr.h ++++ b/include/mptcpd/private/sockaddr.h +@@ -26,6 +26,16 @@ + */ + ///@{ + #if __BYTE_ORDER == __LITTLE_ENDIAN ++/* These 2 helpers come from GNU C Library, under LGPL */ ++# ifndef __bswap_constant_16 ++# define __bswap_constant_16(x) \ ++ ((__uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))) ++# endif ++# ifndef __bswap_constant_32 ++# define __bswap_constant_32(x) \ ++ ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) \ ++ | (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24)) ++# endif + # define MPTCPD_CONSTANT_HTONS(hs) __bswap_constant_16(hs) + # define MPTCPD_CONSTANT_HTONL(hl) __bswap_constant_32(hl) + #else +-- +2.45.2 + diff --git a/testing/mptcpd/0002-mptcpize-define-error-if-not-available.patch b/testing/mptcpd/0002-mptcpize-define-error-if-not-available.patch new file mode 100644 index 0000000000000000000000000000000000000000..2c03a4ab4383c73e7f490e02153fa2f70c33b304 --- /dev/null +++ b/testing/mptcpd/0002-mptcpize-define-error-if-not-available.patch @@ -0,0 +1,78 @@ +From 3030c1258ba1c39ced94b88958c12486be5f6c41 Mon Sep 17 00:00:00 2001 +From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org> +Date: Wed, 20 Nov 2024 12:52:27 +0100 +Subject: [PATCH 2/4] mptcpize: define error() if not available + +Some libc like musl don't support it. + +It is easy enough to define a simple version for our need. + +Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> +--- + configure.ac | 5 +++++ + src/mptcpize.c | 19 ++++++++++++++++++- + 2 files changed, 23 insertions(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index e1bc1ff..fd0e321 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -273,6 +273,11 @@ AC_CHECK_FUNC([l_netlink_message_new_sized], + [ELL has l_netlink_message_new_sized()])]) + LIBS=$mptcpd_save_libs + ++# --------------------------------------------------------------- ++# Checks for header files. ++# --------------------------------------------------------------- ++AC_CHECK_HEADERS([error.h]) ++ + # --------------------------------------------------------------- + # Enable additional C compiler warnings. We do this after all + # Autoconf tests have been run since not all autoconf macros are +diff --git a/src/mptcpize.c b/src/mptcpize.c +index b502d75..e944729 100644 +--- a/src/mptcpize.c ++++ b/src/mptcpize.c +@@ -18,7 +18,6 @@ + #include <argp.h> + #include <dlfcn.h> + #include <errno.h> +-#include <error.h> + #include <fcntl.h> + #include <stdio.h> + #include <stdlib.h> +@@ -29,6 +28,10 @@ + # include <mptcpd/private/config.h> + #endif + ++#ifdef HAVE_ERROR_H ++# include <error.h> ++#endif ++ + #define SYSTEMD_ENV_VAR "Environment=" + #define SYSTEMD_UNIT_VAR "FragmentPath=" + #define SYSTEMD_SERVICE_TAG "[Service]" +@@ -53,6 +56,20 @@ static char doc[] = + "\tdisable <unit> Update the systemd <unit>, removing\n" + "\t the above launcher.\n"; + ++#ifndef HAVE_ERROR_H ++# define ERROR_HELPER(status, errnum, format, ...) do { \ ++ if (errnum) { \ ++ errno = errnum; \ ++ perror(format); \ ++ } else { \ ++ fprintf(stderr, format "%s", __VA_ARGS__); \ ++ } \ ++ if (status) \ ++ exit(status); \ ++ } while(0) ++# define error(...) ERROR_HELPER(__VA_ARGS__, "\n") ++#endif ++ + static struct argp const argp = { 0, 0, args_doc, doc, 0, 0, 0 }; + + static void help(void) +-- +2.45.2 + diff --git a/testing/mptcpd/0003-config-special-case-for-default-logger.patch b/testing/mptcpd/0003-config-special-case-for-default-logger.patch new file mode 100644 index 0000000000000000000000000000000000000000..55264e51b162b9b295cda7b5c270fd9096dc5085 --- /dev/null +++ b/testing/mptcpd/0003-config-special-case-for-default-logger.patch @@ -0,0 +1,78 @@ +From b92bb60a032689af9fcc61f015113d873f21dabf Mon Sep 17 00:00:00 2001 +From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org> +Date: Wed, 20 Nov 2024 13:04:49 +0100 +Subject: [PATCH 3/4] config: special case for default logger + +The current version taking an unlimited number of args, and with +multiple levels of helpers doesn't seem to be supported on some embedded +environments, e.g. Alpine Linux: + + configuration.c: In function 'mptcpd_config_create': + configuration.c:54:47: error: pasting "l_log_set_" and "(" does not give a valid preprocessing token + 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) + | ^~~~~~~~~~ + configuration.c:42:36: note: in definition of macro 'MPTCPD_CONCAT_IMPL' + 42 | #define MPTCPD_CONCAT_IMPL(x, ...) x ## __VA_ARGS__ + | ^ + configuration.c:54:33: note: in expansion of macro 'MPTCPD_CONCAT' + 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) + | ^~~~~~~~~~~~~ + configuration.c:802:9: note: in expansion of macro 'MPTCPD_SET_LOG_FUNCTION' + 802 | MPTCPD_SET_LOG_FUNCTION(); // For early logging. + | ^~~~~~~~~~~~~~~~~~~~~~~ + configuration.c:54:47: error: implicit declaration of function 'l_log_set_'; did you mean 'l_log_set_null'? [-Werror=implicit-function-declaration] + 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) + | ^~~~~~~~~~ + configuration.c:42:36: note: in definition of macro 'MPTCPD_CONCAT_IMPL' + 42 | #define MPTCPD_CONCAT_IMPL(x, ...) x ## __VA_ARGS__ + | ^ + configuration.c:54:33: note: in expansion of macro 'MPTCPD_CONCAT' + 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) + | ^~~~~~~~~~~~~ + configuration.c:802:9: note: in expansion of macro 'MPTCPD_SET_LOG_FUNCTION' + 802 | MPTCPD_SET_LOG_FUNCTION(); // For early logging. + | ^~~~~~~~~~~~~~~~~~~~~~~ + configuration.c:54:47: error: called object is not a function or function pointer + 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) + | ^~~~~~~~~~ + configuration.c:42:36: note: in definition of macro 'MPTCPD_CONCAT_IMPL' + 42 | #define MPTCPD_CONCAT_IMPL(x, ...) x ## __VA_ARGS__ + | ^ + configuration.c:54:33: note: in expansion of macro 'MPTCPD_CONCAT' + 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) + | ^~~~~~~~~~~~~ + configuration.c:802:9: note: in expansion of macro 'MPTCPD_SET_LOG_FUNCTION' + 802 | MPTCPD_SET_LOG_FUNCTION(); // For early logging. + | ^~~~~~~~~~~~~~~~~~~~~~~ + +It is not clear to me why it is failing, and simplifying the +concatenation to two items, plus modifying the main helper to take the +prefix in argument don't seem to help . A simple workaround is to have a +special case for the default value, and do the concatenation only with +the other cases. + +Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> +--- + src/configuration.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/configuration.c b/src/configuration.c +index e78c8b5..8dcd3dd 100644 +--- a/src/configuration.c ++++ b/src/configuration.c +@@ -50,8 +50,12 @@ + // This should never occur! + # error Problem configuring default log message destination. + #endif ++#if MPTCPD_LOGGER == stderr ++#define MPTCPD_SET_LOG_FUNCTION l_log_set_stderr ++#else + /// Name of the default logging function determined at compile-time. + #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) ++#endif + + /** + * @brief Get the function that sets the log message destination. +-- +2.45.2 + diff --git a/testing/mptcpd/0004-scripts-use-short-stat-options.patch b/testing/mptcpd/0004-scripts-use-short-stat-options.patch new file mode 100644 index 0000000000000000000000000000000000000000..833669b272279b9bc83b5d2b4ea24d04fc14238e --- /dev/null +++ b/testing/mptcpd/0004-scripts-use-short-stat-options.patch @@ -0,0 +1,32 @@ +From 4ead8e2461ba0b86ff699149b624b35a46919f07 Mon Sep 17 00:00:00 2001 +From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org> +Date: Wed, 20 Nov 2024 15:20:28 +0100 +Subject: [PATCH 4/4] scripts: use short stat options + +Busybox's stat doesn't understand the long options: + + stat: unrecognized option: dereference + +But it does support '-L'. + +Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> +--- + scripts/check-permissions | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/scripts/check-permissions b/scripts/check-permissions +index 879661b..a8dfedb 100755 +--- a/scripts/check-permissions ++++ b/scripts/check-permissions +@@ -19,7 +19,7 @@ exit_status=0 + + for p in $@; do + # Access rights in human readable form (e.g. "drwxrwxr-x") +- perms=`stat --dereference --format=%A $p` ++ perms=`stat -L -c %A $p` + + # The write mode for "others". + other_write=`echo $perms | sed -e 's/.*\(.\).$/\1/'` +-- +2.45.2 + diff --git a/testing/mptcpd/APKBUILD b/testing/mptcpd/APKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..0ac5760f89d9af462825570c70ba2c2b984ef65e --- /dev/null +++ b/testing/mptcpd/APKBUILD @@ -0,0 +1,96 @@ +# Contributor: Matthieu Baerts (NGI0) <matttbe@kernel.org> +# Maintainer: Matthieu Baerts (NGI0) <matttbe@kernel.org> +pkgname=mptcpd +pkgver=0.13 +pkgrel=0 +pkgdesc="Multipath TCP Daemon" +url="https://mptcpd.mptcp.dev" +arch="all" +license="BSD-3-Clause" +depends="ell" +makedepends="ell-dev argp-standalone linux-headers automake autoconf-archive libtool" +options="!check" # the tests require the libc +subpackages=" + $pkgname-dbg + $pkgname-dev + $pkgname-doc + $pkgname-openrc + mptcpize + mptcpize-dbg:mptcpize_dbg + mptcpize-doc:mptcpize_doc:noarch + mptcp-get-debug:mptcp_get_debug + " +source="https://github.com/multipath-tcp/mptcpd/releases/download/v$pkgver/mptcpd-$pkgver.tar.gz + 0001-include-define-__bswap_constant_-16-32-if-needed.patch + 0002-mptcpize-define-error-if-not-available.patch + 0003-config-special-case-for-default-logger.patch + 0004-scripts-use-short-stat-options.patch + mptcpd.initd + mptcpd.confd + " + +build() { + # can be removed when 0002-mptcpize-define-error-if-not-available.patch + # is dropped, same for 'automake', 'autoconf-archive' and 'libtool' deps + autoreconf --install --symlink --force + + ./configure \ + --build=$CBUILD \ + --host=$CHOST \ + --prefix=/usr \ + --sysconfdir=/etc \ + --mandir=/usr/share/man \ + --localstatedir=/var \ + --with-kernel=upstream + make +} + +package() { + make DESTDIR="$pkgdir" install + + install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname + install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname +} + +mptcpize() { + pkgdesc="Force apps to use MPTCP instead of TCP" + amove usr/bin/mptcpize + amove usr/lib/mptcpize +} + +mptcpize_dbg() { + pkgdesc="Force apps to use MPTCP instead of TCP (dbg)" + + mkdir -p "$subpkgdir"/usr/lib/debug/usr/bin/ + mv -v "$pkgdir"-dbg/usr/lib/debug/usr/bin/mptcpize.debug \ + "$subpkgdir"/usr/lib/debug/usr/bin/ + mkdir -p "$subpkgdir"/usr/lib/debug/usr/lib/ + mv -v "$pkgdir"-dbg/usr/lib/debug/usr/lib/mptcpize \ + "$subpkgdir"/usr/lib/debug/usr/lib/ +} + +mptcpize_doc() { + pkgdesc="Force apps to use MPTCP instead of TCP (doc)" + depends="" + + mkdir -p "$subpkgdir"/usr/share/man/man8/ + mv -v "$pkgdir"-doc/usr/share/man/man8/mptcpize.8* \ + "$subpkgdir"/usr/share/man/man8/ +} + +mptcp_get_debug() { + pkgdesc="MPTCP debug info script" + depends="iproute2" + + amove usr/libexec/mptcp-get-debug +} + +sha512sums=" +5dd53c9e1c92a3242ad84d93642116e77acb24c997219c98fe30a4c6d80b283de8878bcc84a6ac4eaf51ff6dd32cff5ed2a40a869c8304faa835f3b300dbca37 mptcpd-0.13.tar.gz +e5d8f61dc2fd34abc1b6b97bac5129638ec0677c69e0cd4003d0e6e78468d1a8528e4f981972c84c116f4158694ba8e25ad3c1d3c8851484cafbb7a5e333fe2c 0001-include-define-__bswap_constant_-16-32-if-needed.patch +15ae5d2149d82784b839e99e9be34dc8f3c9f04ff367e97f8eb36c2e0d210b1c0db653e7d3f920d621b20c95ea86604a8b77304333e698123252b7e5dda53262 0002-mptcpize-define-error-if-not-available.patch +f881425ee08885be1246f36dea30ddef83292df1f6bdd5d6d3263fbe4479ed8d70854e26b4c97d5f4da5d3cb43f931194ca6b7ff818f5c6081dbec1e55cd0c53 0003-config-special-case-for-default-logger.patch +4a9ae1f877d7f4bb463fd7659e25b2f52c233524c5643a9ba3b454d77a3ffdbaadc4aa344982168d8a66809f762fd9997b0ec365263cc49967f39bbab4943ee2 0004-scripts-use-short-stat-options.patch +26fa76c4c613857d375f96d123314a45b802f2f2d91ef5f315e51600608213c9a7addeb48853f6693597f69dff506b493270031aa069cfd2c98aa9dbab435f41 mptcpd.initd +c5c9542f8a1c0afe50c856436cf4415b6beb00066f1d5b7409a0ae5427257054f3e1432f6697142d97595a8b9e8c483f4cdafbc90a65e2e64adcce830108a48b mptcpd.confd +" diff --git a/testing/mptcpd/mptcpd.confd b/testing/mptcpd/mptcpd.confd new file mode 100755 index 0000000000000000000000000000000000000000..726269524b1a98aca320ae812ce8b98949c58694 --- /dev/null +++ b/testing/mptcpd/mptcpd.confd @@ -0,0 +1,10 @@ +# Configuration for /etc/init.d/<SERVICE> + +# User (and group) to run <SERVICE> as. +#command_user="<USER>" + +# Additional arguments for <SERVICE> daemon. +#command_args= + +# Comment out to disable process supervisor. +supervisor=supervise-daemon diff --git a/testing/mptcpd/mptcpd.initd b/testing/mptcpd/mptcpd.initd new file mode 100755 index 0000000000000000000000000000000000000000..1188b0037a1e576606c47443e627366f2a2d0f2c --- /dev/null +++ b/testing/mptcpd/mptcpd.initd @@ -0,0 +1,21 @@ +#!/sbin/openrc-run + +name="MPTCP Daemon" +description="MPTCP Daemon Service" + +: ${error_logger="logger -t mptcpd -p daemon.info >/dev/null 2>&1"} +: ${start_wait=50} # milliseconds + +command="/usr/bin/mptcpd" +command_args="$command_args" +command_background="yes" +start_stop_daemon_args=" + ${start_wait:+--wait $start_wait} + ${start_stop_daemon_args:-} + " +pidfile="/run/$RC_SVCNAME.pid" + +depend() { + need net + after firewall +}