From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sat, 10 Oct 2020 19:02:24 +0200
Subject: fastd: update to v21

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>

diff --git a/net/fastd/Config.in b/net/fastd/Config.in
index e6440075e561093c86543943cb982d010a4ef0e0..8302f7ee4dac874b1303ebeeb836551ef202c261 100644
--- a/net/fastd/Config.in
+++ b/net/fastd/Config.in
@@ -69,7 +69,6 @@ config FASTD_WITH_CAPABILITIES
 	depends on PACKAGE_fastd
 	default n
 
-
 config FASTD_WITH_CMDLINE_USER
 	bool "Include support for setting user/group related options on the command line"
 	depends on PACKAGE_fastd
@@ -91,7 +90,7 @@ config FASTD_WITH_CMDLINE_COMMANDS
 	default n
 
 config FASTD_WITH_DYNAMIC_PEERS
-	bool "Include support for on-verify handlers"
+	bool "Include support for dynamic peers (using on-verify handlers)"
 	depends on PACKAGE_fastd
 	default n
 
@@ -100,5 +99,4 @@ config FASTD_WITH_STATUS_SOCKET
 	depends on PACKAGE_fastd
 	default y
 
-
 endmenu
diff --git a/net/fastd/Makefile b/net/fastd/Makefile
index 7483e7b003041fb59991d72d0ccfcc8a28bb17a3..c7ab056a9ae005a75a75911658607e64d6228aac 100644
--- a/net/fastd/Makefile
+++ b/net/fastd/Makefile
@@ -8,13 +8,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fastd
-PKG_VERSION:=19
-PKG_RELEASE:=2
+PKG_VERSION:=21
 
 PKG_MAINTAINER:=Matthias Schiffer <mschiffer@universe-factory.net>
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
 PKG_SOURCE_URL:=https://github.com/NeoRaider/fastd/releases/download/v$(PKG_VERSION)
-PKG_HASH:=6054608e2103b634c9d19ecd1ae058d4ec694747047130719db180578729783a
+PKG_HASH:=942f33bcd794bcb8e19da4c30c875bdfd4d0f1c24ec4dcdf51237791bbfb0d4c
 
 PKG_LICENSE:=BSD-2-Clause
 PKG_LICENSE_FILES:=COPYRIGHT
@@ -41,16 +40,16 @@ PKG_CONFIG_DEPENDS:=\
 	CONFIG_FASTD_WITH_STATUS_SOCKET
 
 
-PKG_BUILD_DEPENDS:=nacl
+PKG_BUILD_DEPENDS:=meson/host nacl
 PKG_BUILD_PARALLEL:=1
 
 include $(INCLUDE_DIR)/package.mk
-include $(INCLUDE_DIR)/cmake.mk
+include ../../devel/meson/meson.mk
 
 define Package/fastd
   SECTION:=net
   CATEGORY:=Network
-  DEPENDS:=+kmod-tun +librt +libpthread +libuecc +FASTD_WITH_STATUS_SOCKET:libjson-c +FASTD_WITH_CAPABILITIES:libcap
+  DEPENDS:=+kmod-tun +libpthread +libuecc +FASTD_WITH_STATUS_SOCKET:libjson-c +FASTD_WITH_CAPABILITIES:libcap
   TITLE:=Fast and Secure Tunneling Daemon
   URL:=https://github.com/NeoRaider/fastd/
   SUBMENU:=VPN
@@ -60,116 +59,33 @@ define Package/fastd/config
   source "$(SOURCE)/Config.in"
 endef
 
-TARGET_CFLAGS += -ffunction-sections -fdata-sections
-TARGET_LDFLAGS += -Wl,--gc-sections
-
-CMAKE_OPTIONS += \
-	-DCMAKE_BUILD_TYPE:STRING=MINSIZEREL \
-	-DWITH_METHOD_CIPHER_TEST:BOOL=FALSE \
-	-DWITH_METHOD_COMPOSED_GMAC:BOOL=FALSE \
-	-DWITH_METHOD_COMPOSED_UMAC:BOOL=FALSE \
-	-DWITH_METHOD_GENERIC_GMAC:BOOL=FALSE \
-	-DWITH_METHOD_GENERIC_POLY1305:BOOL=FALSE \
-	-DWITH_METHOD_GENERIC_UMAC:BOOL=FALSE \
-	-DWITH_METHOD_NULL:BOOL=FALSE \
-	-DWITH_CIPHER_AES128_CTR:BOOL=FALSE \
-	-DWITH_CIPHER_NULL:BOOL=FALSE \
-	-DWITH_CIPHER_SALSA20:BOOL=FALSE \
-	-DWITH_CIPHER_SALSA2012:BOOL=FALSE \
-	-DWITH_MAC_GHASH:BOOL=FALSE \
-	-DWITH_MAC_UHASH:BOOL=FALSE \
-	-DWITH_CAPABILITIES:BOOL=FALSE \
-	-DWITH_CMDLINE_USER:BOOL=FALSE \
-	-DWITH_CMDLINE_LOGGING:BOOL=FALSE \
-	-DWITH_CMDLINE_OPERATION:BOOL=FALSE \
-	-DWITH_CMDLINE_COMMANDS:BOOL=FALSE \
-	-DWITH_DYNAMIC_PEERS:BOOL=FALSE \
-	-DWITH_STATUS_SOCKET:BOOL=FALSE \
-	-DENABLE_SYSTEMD:BOOL=FALSE \
-	-DENABLE_LIBSODIUM:BOOL=FALSE \
-	-DENABLE_LTO:BOOL=TRUE
-
-
-ifeq ($(CONFIG_FASTD_ENABLE_METHOD_CIPHER_TEST),y)
-CMAKE_OPTIONS += -DWITH_METHOD_CIPHER_TEST:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_ENABLE_METHOD_COMPOSED_GMAC),y)
-CMAKE_OPTIONS += -DWITH_METHOD_COMPOSED_GMAC:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_ENABLE_METHOD_COMPOSED_UMAC),y)
-CMAKE_OPTIONS += -DWITH_METHOD_COMPOSED_UMAC:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_ENABLE_METHOD_GENERIC_GMAC),y)
-CMAKE_OPTIONS += -DWITH_METHOD_GENERIC_GMAC:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_ENABLE_METHOD_GENERIC_POLY1305),y)
-CMAKE_OPTIONS += -DWITH_METHOD_GENERIC_POLY1305:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_ENABLE_METHOD_GENERIC_UMAC),y)
-CMAKE_OPTIONS += -DWITH_METHOD_GENERIC_UMAC:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_ENABLE_METHOD_NULL),y)
-CMAKE_OPTIONS += -DWITH_METHOD_NULL:BOOL=TRUE
-endif
-
-
-ifeq ($(CONFIG_FASTD_ENABLE_CIPHER_NULL),y)
-CMAKE_OPTIONS += -DWITH_CIPHER_NULL:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_ENABLE_CIPHER_SALSA20),y)
-CMAKE_OPTIONS += -DWITH_CIPHER_SALSA20:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_ENABLE_CIPHER_SALSA2012),y)
-CMAKE_OPTIONS += -DWITH_CIPHER_SALSA2012:BOOL=TRUE
-endif
-
-
-ifeq ($(CONFIG_FASTD_ENABLE_MAC_GHASH),y)
-CMAKE_OPTIONS += -DWITH_MAC_GHASH:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_ENABLE_MAC_UHASH),y)
-CMAKE_OPTIONS += -DWITH_MAC_UHASH:BOOL=TRUE
-endif
-
-
-ifeq ($(CONFIG_FASTD_WITH_CAPABILITIES),y)
-CMAKE_OPTIONS += -DWITH_CAPABILITIES:BOOL=TRUE
-endif
-
-
-ifeq ($(CONFIG_FASTD_WITH_CMDLINE_USER),y)
-CMAKE_OPTIONS += -DWITH_CMDLINE_USER:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_WITH_CMDLINE_LOGGING),y)
-CMAKE_OPTIONS += -DWITH_CMDLINE_LOGGING:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_WITH_CMDLINE_OPERATION),y)
-CMAKE_OPTIONS += -DWITH_CMDLINE_OPERATION:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_WITH_CMDLINE_COMMANDS),y)
-CMAKE_OPTIONS += -DWITH_CMDLINE_COMMANDS:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_WITH_DYNAMIC_PEERS),y)
-CMAKE_OPTIONS += -DWITH_DYNAMIC_PEERS:BOOL=TRUE
-endif
-
-ifeq ($(CONFIG_FASTD_WITH_STATUS_SOCKET),y)
-CMAKE_OPTIONS += -DWITH_STATUS_SOCKET:BOOL=TRUE
-endif
-
+feature = $(if $(CONFIG_FASTD_$(1)),enabled,disabled)
+
+MESON_ARGS += \
+	-Dcapabilities=$(call feature,WITH_CAPABILITIES) \
+	-Dcipher_aes128-ctr=disabled \
+	-Dcipher_null=$(call feature,ENABLE_CIPHER_NULL) \
+	-Dcipher_salsa20=$(call feature,ENABLE_CIPHER_SALSA20) \
+	-Dcipher_salsa2012=$(call feature,ENABLE_CIPHER_SALSA2012) \
+	-Dcmdline_commands=$(call feature,WITH_CMDLINE_COMMANDS) \
+	-Dcmdline_logging=$(call feature,WITH_CMDLINE_LOGGING) \
+	-Dcmdline_operation=$(call feature,WITH_CMDLINE_OPERATION) \
+	-Dcmdline_user=$(call feature,WITH_CMDLINE_USER) \
+	-Ddynamic_peers=$(call feature,WITH_DYNAMIC_PEERS) \
+	-Dmac_ghash=$(call feature,ENABLE_MAC_GHASH) \
+	-Dmac_uhash=$(call feature,ENABLE_MAC_UHASH) \
+	-Dmethod_cipher-test=$(call feature,ENABLE_METHOD_CIPHER_TEST) \
+	-Dmethod_composed-gmac=$(call feature,ENABLE_METHOD_COMPOSED_GMAC) \
+	-Dmethod_composed-umac=$(call feature,ENABLE_METHOD_COMPOSED_UMAC) \
+	-Dmethod_generic-gmac=$(call feature,ENABLE_METHOD_GENERIC_GMAC) \
+	-Dmethod_generic-poly1305=$(call feature,ENABLE_METHOD_GENERIC_POLY1305) \
+	-Dmethod_generic-umac=$(call feature,ENABLE_METHOD_GENERIC_UMAC) \
+	-Dmethod_null=$(call feature,ENABLE_METHOD_NULL) \
+	-Dstatus_socket=$(call feature,WITH_STATUS_SOCKET) \
+	-Dsystemd=disabled \
+	-Duse_nacl=true \
+	-Db_lto=true \
+	-Dprefix=/usr
 
 define Package/fastd/description
  Fast and secure tunneling daemon, which is optimized on small code size and few dependencies
diff --git a/net/fastd/patches/0003-receive-fix-buffer-leak-when-receiving-invalid-packe.patch b/net/fastd/patches/0003-receive-fix-buffer-leak-when-receiving-invalid-packe.patch
deleted file mode 100644
index b67a85c4e4f8ca1ef72d3216afa1ad4e9370cd02..0000000000000000000000000000000000000000
--- a/net/fastd/patches/0003-receive-fix-buffer-leak-when-receiving-invalid-packe.patch
+++ /dev/null
@@ -1,42 +0,0 @@
-From f6a2651fa91c472d04cb34264718f761669c8aa1 Mon Sep 17 00:00:00 2001
-Message-Id: <f6a2651fa91c472d04cb34264718f761669c8aa1.1603136280.git.mschiffer@universe-factory.net>
-From: Matthias Schiffer <mschiffer@universe-factory.net>
-Date: Mon, 19 Oct 2020 21:08:16 +0200
-Subject: [PATCH] receive: fix buffer leak when receiving invalid packets
-
-For fastd versions before v20, this was just a memory leak (which could
-still be used for DoS, as it's remotely triggerable). With the new
-buffer management of fastd v20, this will trigger an assertion failure
-instead as soon as the buffer pool is empty.
-
-(cherry picked from commit 737925113363b6130879729cdff9ccc46c33eaea)
----
- src/receive.c | 10 ++++++++++
- 1 file changed, 10 insertions(+)
-
---- a/src/receive.c
-+++ b/src/receive.c
-@@ -186,6 +186,11 @@ static inline void handle_socket_receive
- 
- 	case PACKET_HANDSHAKE:
- 		fastd_handshake_handle(sock, local_addr, remote_addr, peer, buffer);
-+		break;
-+
-+	default:
-+		fastd_buffer_free(buffer);
-+		pr_debug("received packet with invalid type from %P[%I]", peer, remote_addr);
- 	}
- }
- 
-@@ -211,6 +216,11 @@ static inline void handle_socket_receive
- 
- 	case PACKET_HANDSHAKE:
- 		fastd_handshake_handle(sock, local_addr, remote_addr, NULL, buffer);
-+		break;
-+
-+	default:
-+		fastd_buffer_free(buffer);
-+		pr_debug("received packet with invalid type from unknown address %I", remote_addr);
- 	}
- }
- 
