From 0f151f9b7a6f25bb5c849a75a405ed54ee222a02 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Fri, 25 Oct 2024 19:54:29 +0100 Subject: [PATCH] mptcpd: add package Package Multipath TCP daemon (mptcpd) and wrapper (mptcpize). Signed-off-by: Daniel Golle --- net/mptcpd/Makefile | 66 ++++++ net/mptcpd/files/mptcpd.init | 11 + ...tening-socket-creation-optional.-297.patch | 193 ++++++++++++++++++ ...-ELL-0.68-l_netlink_message-API.-303.patch | 187 +++++++++++++++++ .../patches/100-include-byteswap-h.patch | 19 ++ .../110-define-bswap_constant_32.patch | 20 ++ .../patches/120-no-format-security.patch | 11 + .../patches/130-simplify-log-function.patch | 23 +++ net/mptcpd/patches/140-no-error-h.patch | 30 +++ 9 files changed, 560 insertions(+) create mode 100644 net/mptcpd/Makefile create mode 100644 net/mptcpd/files/mptcpd.init create mode 100644 net/mptcpd/patches/001-Make-listening-socket-creation-optional.-297.patch create mode 100644 net/mptcpd/patches/002-Support-ELL-0.68-l_netlink_message-API.-303.patch create mode 100644 net/mptcpd/patches/100-include-byteswap-h.patch create mode 100644 net/mptcpd/patches/110-define-bswap_constant_32.patch create mode 100644 net/mptcpd/patches/120-no-format-security.patch create mode 100644 net/mptcpd/patches/130-simplify-log-function.patch create mode 100644 net/mptcpd/patches/140-no-error-h.patch diff --git a/net/mptcpd/Makefile b/net/mptcpd/Makefile new file mode 100644 index 0000000000000..06be10e10fbd7 --- /dev/null +++ b/net/mptcpd/Makefile @@ -0,0 +1,66 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=mptcpd +PKG_VERSION:=0.12 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://github.com/multipath-tcp/mptcpd/releases/download/v$(PKG_VERSION) +PKG_HASH:=0507d497383b773a168cd35f4680b41894fcd8d941cb6619800a8e2bed831cbe + +PKG_MAINTAINER:=Daniel Golle +PKG_LICENSE:=BSD-3-clause +PKG_LICENSE_FILES:=COPYING + +PKG_BUILD_DEPENDS:=USE_MUSL:argp-standalone +PKG_BUILD_PARALLEL:=1 +PKG_CHECK_FORMAT_SECURITY:=0 +PKG_FIXUP:=autoreconf +PKG_INSTALL:=1 + +include $(INCLUDE_DIR)/package.mk + +CONFIGURE_ARGS += --with-kernel=upstream + +define Package/mptcpd/Default + SECTION:=net + CATEGORY:=Network + DEPENDS:=+ell + URL:=https://github.com/multipath-tcp/mptcpd +endef + +define Package/mptcpd + $(call Package/mptcpd/Default) + TITLE:=Multipath TCP Daemon +endef + +define Package/mptcpize + $(call Package/mptcpd/Default) + TITLE:=Multipath TCP wrapper +endef + +define Package/mptcpd/conffiles +/etc/mptcpd/mptcpd.conf +endef + +define Package/mptcpd/install + $(INSTALL_DIR) $(1)/etc/mptcpd + $(CP) $(PKG_INSTALL_DIR)/etc/mptcpd/mptcpd.conf $(1)/etc/mptcpd + $(INSTALL_DIR) $(1)/usr/bin + $(CP) $(PKG_INSTALL_DIR)/usr/bin/mptcpd $(1)/usr/bin + $(INSTALL_DIR) $(1)/usr/lib/mptcpd + $(CP) $(PKG_INSTALL_DIR)/usr/lib/libmptcpd.so* $(1)/usr/lib + $(CP) $(PKG_INSTALL_DIR)/usr/lib/mptcpd/*.so $(1)/usr/lib/mptcpd + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/mptcpd.init $(1)/etc/init.d/mptcpd +endef + +define Package/mptcpize/install + $(INSTALL_DIR) $(1)/usr/bin + $(CP) $(PKG_INSTALL_DIR)/usr/bin/mptcpize $(1)/usr/bin + $(INSTALL_DIR) $(1)/usr/lib/mptcpize + $(CP) $(PKG_INSTALL_DIR)/usr/lib/mptcpize/libmptcpwrap.so* $(1)/usr/lib/mptcpize +endef + +$(eval $(call BuildPackage,mptcpd)) +$(eval $(call BuildPackage,mptcpize)) diff --git a/net/mptcpd/files/mptcpd.init b/net/mptcpd/files/mptcpd.init new file mode 100644 index 0000000000000..2f39989233dca --- /dev/null +++ b/net/mptcpd/files/mptcpd.init @@ -0,0 +1,11 @@ +#!/bin/sh /etc/rc.common + +USE_PROCD=1 +START=10 + +start_service() { + procd_open_instance + procd_set_param command /usr/bin/mptcpd + procd_set_param respawn + procd_close_instance +} diff --git a/net/mptcpd/patches/001-Make-listening-socket-creation-optional.-297.patch b/net/mptcpd/patches/001-Make-listening-socket-creation-optional.-297.patch new file mode 100644 index 0000000000000..829532e0faf92 --- /dev/null +++ b/net/mptcpd/patches/001-Make-listening-socket-creation-optional.-297.patch @@ -0,0 +1,193 @@ +From 334bb9c87005d851f4f2549f95342b8d0a41a6db Mon Sep 17 00:00:00 2001 +From: marco-a-itl +Date: Fri, 23 Aug 2024 11:05:35 +0200 +Subject: [PATCH] Make listening socket creation optional. (#297) + +In some cases, it is known in advanced that external applications have +created or will create listening sockets, and mptcpd doesn't need to do +that to avoid reporting failures because the address and port are +already in use. + +This commit makes listening socket creation optional for userspace path +manager plugins by extending the API: it is now possible to call +`mptcpd_pm_add_addr_no_listener()` instead of `mptcpd_pm_add_addr()` to +announce a new address without creating a new listener socket. + +Fixes #296. +--- + include/mptcpd/path_manager.h | 18 ++++++++++++++++ + include/mptcpd/private/path_manager.h | 31 ++++++++++++++++----------- + lib/path_manager.c | 28 +++++++++++++++++++----- + src/netlink_pm_mptcp_org.c | 5 ++++- + src/netlink_pm_upstream.c | 25 ++++++++++----------- + 5 files changed, 76 insertions(+), 31 deletions(-) + +--- a/include/mptcpd/path_manager.h ++++ b/include/mptcpd/path_manager.h +@@ -127,6 +127,24 @@ MPTCPD_API int mptcpd_pm_add_addr(struct + mptcpd_token_t token); + + /** ++ * @brief Advertise new network address to peers without creating a listener. ++ * ++ * @param[in] pm The mptcpd path manager object. ++ * @param[in,out] addr Local IP address and port to be advertised ++ * through the MPTCP protocol @c ADD_ADDR ++ * option. If the port is zero no port will be ++ * specified on the underlying protocol level. ++ * @param[in] id MPTCP local address ID. ++ * @param[in] token MPTCP connection token. ++ * ++ * @return @c 0 if operation was successful. -1 or @c errno otherwise. ++ */ ++MPTCPD_API int mptcpd_pm_add_addr_no_listener(struct mptcpd_pm *pm, ++ struct sockaddr *addr, ++ mptcpd_aid_t id, ++ mptcpd_token_t token); ++ ++/** + * @brief Stop advertising network address to peers. + * + * @param[in] pm The mptcpd path manager object. +--- a/include/mptcpd/private/path_manager.h ++++ b/include/mptcpd/private/path_manager.h +@@ -138,18 +138,22 @@ struct mptcpd_pm_cmd_ops + /** + * @brief Advertise new network address to peers. + * +- * @param[in] pm The mptcpd path manager object. +- * @param[in,out] addr Local IP address and port to be +- * advertised through the MPTCP protocol +- * @c ADD_ADDR option. If the port is +- * zero an ephemeral port will be chosen, +- * and assigned to the appropriate +- * underlying address family-specific +- * port member, e.g. @c sin_port or +- * @c sin6_port. The port will be in +- * network byte order. +- * @param[in] id MPTCP local address ID. +- * @param[in] token MPTCP connection token. ++ * @param[in] pm The mptcpd path manager object. ++ * @param[in,out] addr Local IP address and port to be ++ * advertised through the MPTCP protocol ++ * @c ADD_ADDR option. If the port is ++ * zero an ephemeral port will be chosen, ++ * and assigned to the appropriate ++ * underlying address family-specific ++ * port member, e.g. @c sin_port or ++ * @c sin6_port. The port will be in ++ * network byte order. ++ * If listener is not created, port zero ++ * will cause no port specification at ++ * protocol level. ++ * @param[in] id MPTCP local address ID. ++ * @param[in] token MPTCP connection token. ++ * @param[in] listener Create listener. + * + * @return @c 0 if operation was successful. -1 or @c errno + * otherwise. +@@ -157,7 +161,8 @@ struct mptcpd_pm_cmd_ops + int (*add_addr)(struct mptcpd_pm *pm, + struct sockaddr *addr, + mptcpd_aid_t id, +- mptcpd_token_t token); ++ mptcpd_token_t token, ++ bool listener); + + /** + * @brief Stop advertising network address to peers. +--- a/lib/path_manager.c ++++ b/lib/path_manager.c +@@ -238,10 +238,11 @@ int mptcpd_kpm_set_flags(struct mptcpd_p + + // ------------------------------------------------------------------- + +-int mptcpd_pm_add_addr(struct mptcpd_pm *pm, +- struct sockaddr *addr, +- mptcpd_aid_t address_id, +- mptcpd_token_t token) ++static int do_pm_add_addr(struct mptcpd_pm *pm, ++ struct sockaddr *addr, ++ mptcpd_aid_t address_id, ++ mptcpd_token_t token, ++ bool listener) + { + if (pm == NULL || addr == NULL || address_id == 0) + return EINVAL; +@@ -258,7 +259,24 @@ int mptcpd_pm_add_addr(struct mptcpd_pm + return ops->add_addr(pm, + addr, + address_id, +- token); ++ token, ++ listener); ++} ++ ++int mptcpd_pm_add_addr(struct mptcpd_pm *pm, ++ struct sockaddr *addr, ++ mptcpd_aid_t address_id, ++ mptcpd_token_t token) ++{ ++ return do_pm_add_addr(pm, addr, address_id, token, true); ++} ++ ++int mptcpd_pm_add_addr_no_listener(struct mptcpd_pm *pm, ++ struct sockaddr *addr, ++ mptcpd_aid_t address_id, ++ mptcpd_token_t token) ++{ ++ return do_pm_add_addr(pm, addr, address_id, token, false); + } + + int mptcpd_pm_remove_addr(struct mptcpd_pm *pm, +--- a/src/netlink_pm_mptcp_org.c ++++ b/src/netlink_pm_mptcp_org.c +@@ -155,8 +155,11 @@ static bool append_remote_addr_attr(stru + static int mptcp_org_add_addr(struct mptcpd_pm *pm, + struct sockaddr *addr, + mptcpd_aid_t id, +- mptcpd_token_t token) ++ mptcpd_token_t token, ++ bool listener) + { ++ (void) listener; ++ + /* + Payload: + Token +--- a/src/netlink_pm_upstream.c ++++ b/src/netlink_pm_upstream.c +@@ -219,20 +219,21 @@ static int send_add_addr(struct mptcpd_p + static int upstream_announce(struct mptcpd_pm *pm, + struct sockaddr *addr, + mptcpd_aid_t id, +- mptcpd_token_t token) ++ mptcpd_token_t token, ++ bool listener) + { +- /** +- * Set up MPTCP listening socket. +- * +- * @note An ephemeral port will be assigned to the port in +- * @a addr if it is zero. +- * +- * @todo This should be optional. +- */ +- int const r = mptcpd_lm_listen(pm->lm, addr); ++ if (listener) { ++ /** ++ * Set up MPTCP listening socket. ++ * ++ * @note An ephemeral port will be assigned to the port in ++ * @a addr if it is zero. ++ */ ++ int const r = mptcpd_lm_listen(pm->lm, addr); + +- if (r != 0) +- return r; ++ if (r != 0) ++ return r; ++ } + + /** + * @todo Add support for the optional network interface index diff --git a/net/mptcpd/patches/002-Support-ELL-0.68-l_netlink_message-API.-303.patch b/net/mptcpd/patches/002-Support-ELL-0.68-l_netlink_message-API.-303.patch new file mode 100644 index 0000000000000..0fe6a4ba7f4e9 --- /dev/null +++ b/net/mptcpd/patches/002-Support-ELL-0.68-l_netlink_message-API.-303.patch @@ -0,0 +1,187 @@ +From ffa276fc8ee18321b3c2f22deae2e254a69ae4dc Mon Sep 17 00:00:00 2001 +From: Ossama Othman +Date: Sat, 14 Sep 2024 17:50:13 +0900 +Subject: [PATCH] Support ELL 0.68 l_netlink_message API. (#303) + +* configure: Check for l_netlink_message_new_sized() + +ELL 0.68 introduced a non-backward compatible change to its API by +introducing a new l_netlink_message API to simplify use of the +l_netlink_send() function. Check for the existence of the new API in +the mptcpd configure script. + +* network_monitor: Support ELL l_netlink_message API + +Support both the pre- and post- ELL 0.68 versions of l_netlink_send() +function. + +* network_monitor: Refactor l_netlink_send() calls. + +Refactor #ifdef blocks containing calls to the pre- and post-0.68 +ELL l_netlink_send() calls to a separate helper functions. This +simplifies the code, and obviates the need to have an #ifdef block +each time l_netlink_send() is called. Many thanks to Matthieu Baerts +for making this suggestion. + +* configure: Bump copyright year. +--- + configure.ac | 8 +++- + lib/network_monitor.c | 95 +++++++++++++++++++++++++++++++------------ + 2 files changed, 77 insertions(+), 26 deletions(-) + +--- a/configure.ac ++++ b/configure.ac +@@ -2,7 +2,7 @@ + # -*- Autoconf -*- + # Process this file with autoconf to produce a configure script. + # +-# Copyright (c) 2017-2023, Intel Corporation ++# Copyright (c) 2017-2024, Intel Corporation + + AC_PREREQ([2.69]) + AC_INIT([mptcpd], +@@ -265,6 +265,12 @@ AC_CHECK_FUNC([l_hashmap_replace], + [AC_DEFINE([HAVE_L_HASHMAP_REPLACE], + [], + [ELL has l_hashmap_replace()])]) ++ ++dnl l_netlink_message_new_sized() was introduced in ELL v0.68. ++AC_CHECK_FUNC([l_netlink_message_new_sized], ++ [AC_DEFINE([HAVE_L_NETLINK_MESSAGE_NEW_SIZED], ++ [], ++ [ELL has l_netlink_message_new_sized()])]) + LIBS=$mptcpd_save_libs + + # --------------------------------------------------------------- +--- a/lib/network_monitor.c ++++ b/lib/network_monitor.c +@@ -4,7 +4,7 @@ + * + * @brief mptcpd network device monitoring. + * +- * Copyright (c) 2017-2022, Intel Corporation ++ * Copyright (c) 2017-2022, 2024, Intel Corporation + */ + + #ifdef HAVE_CONFIG_H +@@ -96,6 +96,51 @@ struct mptcpd_nm + }; + + // ------------------------------------------------------------------- ++// Helper Functions ++// ------------------------------------------------------------------- ++ ++/** ++ * @brief Wrap different versions of ELL @c l_netlink_send(). ++ * ++ * ELL 0.68 changed the API for @c l_netlink_send(). This helper ++ * function wraps the two different function calls so that mptcpd will ++ * work with both pre- and post-0.68 @c l_netlink_send() APIs. ++ */ ++static unsigned int netlink_send(struct l_netlink *netlink, ++ uint16_t type, ++ uint16_t flags, ++ void const *data, ++ uint32_t len, ++ l_netlink_command_func_t function, ++ void *user_data, ++ l_netlink_destroy_func_t destroy) ++{ ++#ifdef HAVE_L_NETLINK_MESSAGE_NEW_SIZED ++ // ELL >= 0.68 ++ struct l_netlink_message *const message = ++ l_netlink_message_new_sized(type, flags, len); ++ ++ l_netlink_message_add_header(message, data, len); ++ ++ return l_netlink_send(netlink, ++ message, ++ function, ++ user_data, ++ destroy); ++#else ++ // ELL < 0.68 ++ return l_netlink_send(netlink, ++ type, ++ flags, ++ data, ++ len, ++ function, ++ user_data, ++ destroy); ++#endif ++} ++ ++// ------------------------------------------------------------------- + // Network Address Information Handling + // ------------------------------------------------------------------- + +@@ -1015,14 +1060,14 @@ static void check_default_route(struct n + */ + mptcpd_addr_get(ai); + +- if (l_netlink_send(ai->nm->rtnl, +- RTM_GETROUTE, +- 0, +- &store, +- buf - (char *) &store, +- handle_rtm_getroute, +- ai, +- NULL) == 0) { ++ if (netlink_send(ai->nm->rtnl, ++ RTM_GETROUTE, ++ 0, ++ &store, ++ buf - (char *) &store, ++ handle_rtm_getroute, ++ ai, ++ NULL) == 0) { + l_debug("Route lookup failed"); + mptcpd_addr_put(ai); + } +@@ -1388,14 +1433,14 @@ static void send_getaddr_command(void *u + + // Get IP addresses. + struct ifaddrmsg addr_msg = { .ifa_family = AF_UNSPEC }; +- if (l_netlink_send(nm->rtnl, +- RTM_GETADDR, +- NLM_F_DUMP, +- &addr_msg, +- sizeof(addr_msg), +- handle_rtm_getaddr, +- nm, +- NULL) == 0) { ++ if (netlink_send(nm->rtnl, ++ RTM_GETADDR, ++ NLM_F_DUMP, ++ &addr_msg, ++ sizeof(addr_msg), ++ handle_rtm_getaddr, ++ nm, ++ NULL) == 0) { + l_error("Unable to obtain IP addresses."); + + /* +@@ -1481,14 +1526,14 @@ struct mptcpd_nm *mptcpd_nm_create(uint3 + * resulted in an EBUSY error. + */ + struct ifinfomsg link_msg = { .ifi_family = AF_UNSPEC }; +- if (l_netlink_send(nm->rtnl, +- RTM_GETLINK, +- NLM_F_DUMP, +- &link_msg, +- sizeof(link_msg), +- handle_rtm_getlink, +- nm, +- send_getaddr_command) ++ if (netlink_send(nm->rtnl, ++ RTM_GETLINK, ++ NLM_F_DUMP, ++ &link_msg, ++ sizeof(link_msg), ++ handle_rtm_getlink, ++ nm, ++ send_getaddr_command) + == 0) { + l_error("Unable to obtain network devices."); + mptcpd_nm_destroy(nm); diff --git a/net/mptcpd/patches/100-include-byteswap-h.patch b/net/mptcpd/patches/100-include-byteswap-h.patch new file mode 100644 index 0000000000000..95ccf572e33b7 --- /dev/null +++ b/net/mptcpd/patches/100-include-byteswap-h.patch @@ -0,0 +1,19 @@ +From 80e5db2774a902f6a2f32741fe762888343222d9 Mon Sep 17 00:00:00 2001 +From: lifei76 +Date: Thu, 20 Jul 2023 16:33:42 +0800 +Subject: [PATCH 03/11] 1 + +--- + lib/network_monitor.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/lib/network_monitor.c ++++ b/lib/network_monitor.c +@@ -18,6 +18,7 @@ + #include + #include + ++#include + #include + #include + #include // For standard network interface flags. diff --git a/net/mptcpd/patches/110-define-bswap_constant_32.patch b/net/mptcpd/patches/110-define-bswap_constant_32.patch new file mode 100644 index 0000000000000..4484ca98ac795 --- /dev/null +++ b/net/mptcpd/patches/110-define-bswap_constant_32.patch @@ -0,0 +1,20 @@ +--- a/include/mptcpd/private/sockaddr.h ++++ b/include/mptcpd/private/sockaddr.h +@@ -18,6 +18,17 @@ + + #include + ++#ifndef __bswap_constant_32 ++#define __bswap_constant_32(x) \ ++ ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) \ ++ | (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24)) ++#endif ++ ++#ifndef __bswap_constant_16 ++#define __bswap_constant_16(x) \ ++ ((__uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))) ++#endif ++ + /** + * @name Swap host ordered bytes in an integer to network byte order. + * diff --git a/net/mptcpd/patches/120-no-format-security.patch b/net/mptcpd/patches/120-no-format-security.patch new file mode 100644 index 0000000000000..3a183fb2b86bb --- /dev/null +++ b/net/mptcpd/patches/120-no-format-security.patch @@ -0,0 +1,11 @@ +--- a/configure.ac ++++ b/configure.ac +@@ -321,7 +321,7 @@ AS_IF([test "x$enable_stack_protection" + # Format string vulnerabilities + # -Wformat=2 implies: + # -Wformat -Wformat-nonliteral -Wformat-security -Wformat-y2k +-AX_APPEND_COMPILE_FLAGS([-Wformat=2]) ++# AX_APPEND_COMPILE_FLAGS([-Wformat=2]) + + # Position Independent Execution (PIE) + AX_APPEND_COMPILE_FLAGS([-fPIE], [EXECUTABLE_CFLAGS]) diff --git a/net/mptcpd/patches/130-simplify-log-function.patch b/net/mptcpd/patches/130-simplify-log-function.patch new file mode 100644 index 0000000000000..6dd1262214008 --- /dev/null +++ b/net/mptcpd/patches/130-simplify-log-function.patch @@ -0,0 +1,23 @@ +From 7e1cc2d933976c20bec932613172b56c5172b7f0 Mon Sep 17 00:00:00 2001 +From: lifei76 +Date: Thu, 20 Jul 2023 18:24:37 +0800 +Subject: [PATCH 09/11] 7 + +--- + src/configuration.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +--- a/src/configuration.c ++++ b/src/configuration.c +@@ -59,7 +59,10 @@ + # error Problem configuring default log message destination. + #endif + /// Name of the default logging function determined at compile-time. +-#define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) ++ // #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) ++ ++#define MPTCPD_SET_LOG_FUNCTION l_log_set_stderr ++ + + /** + * @brief Get the function that sets the log message destination. diff --git a/net/mptcpd/patches/140-no-error-h.patch b/net/mptcpd/patches/140-no-error-h.patch new file mode 100644 index 0000000000000..b057c7b43cc51 --- /dev/null +++ b/net/mptcpd/patches/140-no-error-h.patch @@ -0,0 +1,30 @@ +--- a/src/mptcpize.c ++++ b/src/mptcpize.c +@@ -18,7 +18,7 @@ + #include + #include + #include +-#include ++//#include + #include + #include + #include +@@ -36,6 +36,18 @@ + #define PRELOAD_VAR "LD_PRELOAD=" + #define MPTCPWRAP_ENV "LD_PRELOAD="PKGLIBDIR"/libmptcpwrap.so.0.0."LIBREVISION + ++#define error(status, errnum, fmt, ...) do { \ ++ if (errnum) { \ ++ errno = errnum; \ ++ perror(fmt); \ ++ } else { \ ++ fprintf(stderr, "%s\n", fmt); \ ++ } \ ++ if (status) \ ++ exit(status); \ ++} while(0) ++ ++ + /* Program documentation. */ + static char args_doc[] = "CMD"; +