From 1673595ee1daa527cd67d403e61d4bf76c34e437 Mon Sep 17 00:00:00 2001 From: Dengfeng Liu Date: Mon, 5 Aug 2019 20:10:04 +0800 Subject: [PATCH] kcptun: add new package kcptun is a stable & secure tunnel based on kcp with N:M multiplexing. https://github.com/xtaci/kcptun Signed-off-by: Dengfeng Liu --- net/kcptun/Makefile | 74 ++++++++++++++++++++++++++++++++++ net/kcptun/files/kcptun-c.conf | 9 +++++ net/kcptun/files/kcptun-c.init | 56 +++++++++++++++++++++++++ net/kcptun/files/kcptun-s.conf | 9 +++++ net/kcptun/files/kcptun-s.init | 56 +++++++++++++++++++++++++ 5 files changed, 204 insertions(+) create mode 100644 net/kcptun/Makefile create mode 100644 net/kcptun/files/kcptun-c.conf create mode 100644 net/kcptun/files/kcptun-c.init create mode 100644 net/kcptun/files/kcptun-s.conf create mode 100644 net/kcptun/files/kcptun-s.init diff --git a/net/kcptun/Makefile b/net/kcptun/Makefile new file mode 100644 index 000000000..b39a11271 --- /dev/null +++ b/net/kcptun/Makefile @@ -0,0 +1,74 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=kcptun +PKG_VERSION:=20190725 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/xtaci/kcptun/tar.gz/v${PKG_VERSION}? +PKG_HASH:=65c0d0d4f7e3bb3c3b91e23ff2eb6621455d6d376a4f17e6fb2017337ce711c1 + +PKG_MAINTAINER:=Dengfeng Liu +PKG_LICENSE:=MIT +PKG_LICENSE_FILES:=LICENSE + +PKG_BUILD_DEPENDS:=golang/host +PKG_BUILD_PARALLEL:=1 +PKG_USE_MIPS16:=0 + +GO_PKG:=github.com/xtaci/kcptun + +include $(INCLUDE_DIR)/package.mk +include ../../lang/golang/golang-package.mk + +define Package/kcptun/template + SECTION:=net + CATEGORY:=Network + SUBMENU:=Web Servers/Proxies + TITLE:=KCP-based Secure Tunnel + URL:=https://github.com/xtaci/kcptun + DEPENDS:=$(GO_ARCH_DEPENDS) +endef + +define Package/kcptun-c + $(call Package/kcptun/template) + TITLE+= (client) +endef + +define Package/kcptun-s + $(call Package/kcptun/template) + TITLE+= (server) +endef + +define Package/kcptun/description + kcptun is a Stable & Secure Tunnel Based On KCP with N:M Multiplexing +endef +Package/kcptun-c/description = $(Package/kcptun/description) +Package/kcptun-s/description = $(Package/kcptun/description) + +GO_PKG_LDFLAGS_X:=main.VERSION=$(PKG_VERSION) +GO_PKG_LDFLAGS:=-s -w + +define Package/kcptun/install + $(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR)) + + $(INSTALL_DIR) $(1)/usr/bin/ + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/$(2) $(1)/usr/bin/$(3) + $(INSTALL_DIR) $(1)/etc/config/ + $(INSTALL_CONF) ./files/$(3).conf $(1)/etc/config/$(3) + $(INSTALL_DIR) $(1)/etc/init.d/ + $(INSTALL_BIN) ./files/$(3).init $(1)/etc/init.d/$(3) +endef + +define Package/kcptun-c/install + $(call Package/kcptun/install,$(1),client,kcptun-c) +endef + +define Package/kcptun-s/install + $(call Package/kcptun/install,$(1),server,kcptun-s) +endef + +$(eval $(call GoBinPackage,kcptun-c)) +$(eval $(call BuildPackage,kcptun-c)) +$(eval $(call GoBinPackage,kcptun-s)) +$(eval $(call BuildPackage,kcptun-s)) diff --git a/net/kcptun/files/kcptun-c.conf b/net/kcptun/files/kcptun-c.conf new file mode 100644 index 000000000..adef9e3ea --- /dev/null +++ b/net/kcptun/files/kcptun-c.conf @@ -0,0 +1,9 @@ +config kcptun + option local_port 12948 # this port should be your service port + option remote_ip 'your vps ip' + option remote_port 29900 + option mode 'fast' + option nocomp 1 + option sndwnd 128 + option rcvwnd 512 + option disabled 1 # set 0 to enable it diff --git a/net/kcptun/files/kcptun-c.init b/net/kcptun/files/kcptun-c.init new file mode 100644 index 000000000..653d8d817 --- /dev/null +++ b/net/kcptun/files/kcptun-c.init @@ -0,0 +1,56 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2019 Dengfeng Liu + +START=99 + +USE_PROCD=1 +NAME=kcptun-c +PROG=/usr/bin/${NAME} + +validate_section_kcptun() +{ + uci_load_validate "${NAME}" kcptun "$1" "$2" \ + 'local_port:port' \ + 'remote_ip:string' \ + 'remote_port:port' \ + 'mode:string' \ + 'nocomp:bool' \ + 'sndwnd:uinteger' \ + 'rcvwnd:uinteger' \ + 'disabled:bool' +} + +kcptun_instance() +{ + [ "$2" = 0 ] || { + echo "validation failed" + return 1 + } + + [ "${disabled}" = "1" ] && return 1 + + [ "${local_port}" -gt 0 ] && [ "${local_port}" -lt 65536 ] || return 1 + + [ "${remote_port}" -gt 0 ] && [ "${remote_port}" -lt 65536 ] || return 1 + + [ -n "${remote_ip}" ] || { + return 1 + } + + procd_open_instance + procd_set_param command "${PROG}" + procd_append_param command --localaddr ":${local_port}" + procd_append_param command --remoteaddr "${remote_ip}:${remote_port}" + [ -n "${mode}" ] && procd_append_param command --mode "${mode}" + [ "${nocomp}" -eq 1 ] && procd_append_param command --nocomp + [ "${sndwnd}" -gt 0 ] && procd_append_param command --sndwnd "${sndwnd}" + [ "${rcvwnd}" -gt 0 ] && procd_append_param command --rcvwnd "${rcvwnd}" + procd_set_param respawn + procd_close_instance +} + +start_service() +{ + config_load "${NAME}" + config_foreach validate_section_kcptun kcptun kcptun_instance +} diff --git a/net/kcptun/files/kcptun-s.conf b/net/kcptun/files/kcptun-s.conf new file mode 100644 index 000000000..3537f64b5 --- /dev/null +++ b/net/kcptun/files/kcptun-s.conf @@ -0,0 +1,9 @@ +config kcptun + option local_port 29900 + option target_ip '127.0.0.1' + option target_port 12948 # this port should be your service port + option mode 'fast' + option nocomp 1 + option sndwnd 1024 + option rcvwnd 1024 + option disabled 1 # set 0 to enable it diff --git a/net/kcptun/files/kcptun-s.init b/net/kcptun/files/kcptun-s.init new file mode 100644 index 000000000..cfcb81add --- /dev/null +++ b/net/kcptun/files/kcptun-s.init @@ -0,0 +1,56 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2019 Dengfeng Liu + +START=99 + +USE_PROCD=1 +NAME=kcptun-s +PROG=/usr/bin/${NAME} + +validate_section_kcptun() +{ + uci_load_validate "${NAME}" kcptun "$1" "$2" \ + 'local_port:port' \ + 'target_ip:string' \ + 'target_port:port' \ + 'mode:string' \ + 'nocomp:bool' \ + 'sndwnd:uinteger' \ + 'rcvwnd:uinteger' \ + 'disabled:bool' +} + +kcptun_instance() +{ + [ "$2" = 0 ] || { + echo "validation failed" + return 1 + } + + [ "${disabled}" = "1" ] && return 1 + + [ "${local_port}" -gt 0 ] && [ "${local_port}" -lt 65536 ] || return 1 + + [ "${target_port}" -gt 0 ] && [ "${target_port}" -lt 65536 ] || return 1 + + [ -n "${target_ip}" ] || { + return 1 + } + + procd_open_instance + procd_set_param command "${PROG}" + procd_append_param command --listen ":${local_port}" + procd_append_param command --target "${target_ip}:${target_port}" + [ -n "${mode}" ] && procd_append_param command --mode "${mode}" + [ "${nocomp}" -eq 1 ] && procd_append_param command --nocomp + [ "${sndwnd}" -gt 0 ] && procd_append_param command --sndwnd "${sndwnd}" + [ "${rcvwnd}" -gt 0 ] && procd_append_param command --rcvwnd "${rcvwnd}" + procd_set_param respawn + procd_close_instance +} + +start_service() +{ + config_load "${NAME}" + config_foreach validate_section_kcptun kcptun kcptun_instance +}