diff --git a/net/eoip/Makefile b/net/eoip/Makefile new file mode 100644 index 0000000000..ff7c832692 --- /dev/null +++ b/net/eoip/Makefile @@ -0,0 +1,55 @@ +# +# Copyright (C) 2020 Bogdan Shatik +# +# This is free software, licensed under the GNU General Public License v3. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=eoip +PKG_VERSION:=0.5 +PKG_RELEASE:=1 +PKG_MAINTAINER:=Bogdan Shatik +PKG_LICENSE:=GPL-3.0-or-later +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://github.com/bogdik/openwrt-linux-eoip/releases/download/0.5/ +PKG_HASH:=22f6f3864665adef26c7fbd57543a396108ba2dff1282af8143f18bc2a9912f8 + +PKG_INSTALL:=1 + +include $(INCLUDE_DIR)/package.mk + +define Package/eoip + TITLE:=Mikrotik-compatible userspace EoIP tunnel + URL:=https://code.google.com/p/linux-eoip/ + SECTION:=net + CATEGORY:=Network + SUBMENU:=VPN + DEPENDS:=+kmod-tun +libpthread +liblzo +endef + +define Package/eoip/conffiles +/etc/config/eoip +endef + +define Package/eoip/description + linux-eoip can create ethernet tunnels compatible with Mikrotik EoIP tunnel. + At current moment it is easiest way to create stateless tunnel with Mikrotik. +endef + +CONFIGURE_ARGS += \ + --with-kernel="$(LINUX_DIR)" \ + --with-zlib="$(STAGING_DIR)/usr" \ + --with-lzo-include="$(STAGING_DIR)/usr/include/lzo" + +define Package/eoip/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/eoip $(1)/usr/bin/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./files/eoip.config $(1)/etc/config/eoip + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/eoip.init $(1)/etc/init.d/eoip +endef + +$(eval $(call BuildPackage,eoip)) diff --git a/net/eoip/files/eoip.config b/net/eoip/files/eoip.config new file mode 100644 index 0000000000..cdac57ed9d --- /dev/null +++ b/net/eoip/files/eoip.config @@ -0,0 +1,6 @@ +config eoip + option enabled 0 + option name 0 + option idtun 123 + option dst '192.168.99.100' + option dynamic 1 diff --git a/net/eoip/files/eoip.init b/net/eoip/files/eoip.init new file mode 100644 index 0000000000..37c401e0bf --- /dev/null +++ b/net/eoip/files/eoip.init @@ -0,0 +1,105 @@ +#!/bin/sh /etc/rc.common + +START=99 +USE_PROCD=1 +INDEX=0 + +append_bool() { + local section="$1" + local option="$2" + local value="$3" + local _val + config_get_bool _val "$section" "$option" '0' + [ "$_val" -gt 0 ] && append args "$3" +} + +append_string() { + local section="$1" + local option="$2" + local value="$3" + local _val + config_get _val "$section" "$option" + [ -n "$_val" ] && append args "$3$_val" +} + +service_triggers () { + procd_open_trigger + procd_add_reload_trigger "eoip" + procd_add_config_trigger "config.change" "eoip" /etc/init.d/eoip restart + procd_add_config_trigger "config.change" "/etc/config/eoip" /etc/init.d/eoip restart + procd_close_trigger +} + +start_service() { + config_load "eoip" + echo "" > /etc/eoip.cfg + echo "#!/bin/sh" > /etc/afterStart.sh + echo "chkCount=0">> /etc/afterStart.sh + echo "while [ \$chkCount -le 10 ];do">> /etc/afterStart.sh + echo " chkStarted=\$(ip a | grep zeoip | wc -l)">> /etc/afterStart.sh + echo " if [ \$chkStarted -eq 0 ]; then">> /etc/afterStart.sh + echo " chkCount=\$((chkCount+1))">> /etc/afterStart.sh + echo " sleep 2">> /etc/afterStart.sh + echo " else">> /etc/afterStart.sh + echo " chkCount=11">> /etc/afterStart.sh + echo " fi">> /etc/afterStart.sh + echo "done">> /etc/afterStart.sh + echo "now=\$(ip a | grep \"@zeoip\" | awk '{print \$2}' | sed 's/.$//' | cut -d \"@\" -f 1)" >> /etc/afterStart.sh + echo "IFS=\$'\n'" >> /etc/afterStart.sh + echo "for s in \$now ; do" >> /etc/afterStart.sh + echo " ip link delete link dev \$s" >> /etc/afterStart.sh + echo "done" >> /etc/afterStart.sh + echo "rm /etc/afterStart.sh" >> /etc/afterStart.sh + chmod +x /etc/afterStart.sh + config_foreach start_eoip eoip + config_foreach start_eoip_vlan eoip + if [ "$(cat /etc/eoip.cfg | grep zeoip)" != '' ]; then + /etc/afterStart.sh& + procd_open_instance + args=" /etc/eoip.cfg" + procd_set_param command /usr/bin/eoip $args + procd_close_instance + else + rm /etc/afterStart.sh + fi +} + +stop_service() { + killall eoip +} + +start_eoip() { + local section="$1" runas_root + config_get_bool enabled "$section" enabled + if [ "$enabled" -gt 0 ]; then + config_get name "$section" name + config_get idtun "$section" idtun + config_get dst "$section" dst + config_get_bool dynamic "$section" dynamic 0 + if [ "${name}" != '' ] && [ "${dst}" != '' ] && [ "${idtun}" != '' ]; then + cnt=$(cat /etc/eoip.cfg | grep "zeoip${name}" | wc -l) + if [ $cnt -eq 0 ]; then + echo "[zeoip${name}]" >>/etc/eoip.cfg + echo "id=${idtun}" >>/etc/eoip.cfg + echo "dst=${dst}" >>/etc/eoip.cfg + [ "$dynamic" -gt 0 ] && echo "dynamic=${dynamic}" >>/etc/eoip.cfg + INDEX=$((INDEX+1)) + else + result=$(uci delete /etc/config/eoip.@eoip[$INDEX]) + INDEX=$((INDEX+1)) + fi + fi + fi +} + +start_eoip_vlan() { + local section="$1" runas_root + config_get name "$section" name + config_list_foreach "$section" vlan handle_vlan ${name} +} + +handle_vlan() { + local value="$1" + local name="$2" + echo "ip link add link zeoip${name} name zeoip${name}.${value} type vlan id ${value}" >> /etc/afterStart.sh +} diff --git a/net/eoip/patches/100-add_LF_to_pidfile.patch b/net/eoip/patches/100-add_LF_to_pidfile.patch new file mode 100644 index 0000000000..bb66d146d4 --- /dev/null +++ b/net/eoip/patches/100-add_LF_to_pidfile.patch @@ -0,0 +1,11 @@ +--- a/eoip.c 2013-09-25 22:50:48.272763057 +0200 ++++ b/eoip.c 2013-09-25 22:51:03.804762840 +0200 +@@ -430,7 +430,7 @@ + exit(1); + + mfd = fopen(pidfile, "w"); +- fprintf(mfd,"%d", getpid()); ++ fprintf(mfd,"%d\n", getpid()); + fclose(mfd); + + /* structure of Mikrotik EoIP: