diff options
author | Bogdan Shatik <bogdikxxx@mail.ru> | 2021-01-24 14:52:52 +0300 |
---|---|---|
committer | Bogdan Shatik <bogdikxxx@mail.ru> | 2021-01-24 16:39:15 +0300 |
commit | 64e3fdbdce48eb238220e9473859e03dcf42ba19 (patch) | |
tree | 9e8d40b191fb12c17b3e4ef2f3bb5b894698827b /net/eoip/files | |
parent | 952dbc05b2a277d7367f4a2297ea1834c46dfeaa (diff) |
eoip: Add package
add eoip package,this can create ethernet
tunnels compatible with Mikrotik EoIP tunnel.
At current moment it is easiest way
to create stateless tunnel with Mikrotik.
Signed-off-by: Bogdan Shatik <bogdikxxx@mail.ru>
Diffstat (limited to 'net/eoip/files')
-rw-r--r-- | net/eoip/files/eoip.config | 6 | ||||
-rw-r--r-- | net/eoip/files/eoip.init | 105 |
2 files changed, 111 insertions, 0 deletions
diff --git a/net/eoip/files/eoip.config b/net/eoip/files/eoip.config new file mode 100644 index 000000000..cdac57ed9 --- /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 000000000..37c401e0b --- /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 +} |