diff --git a/open-app-filter/files/appfilter.init b/open-app-filter/files/appfilter.init index 7d458fc..ad27406 100755 --- a/open-app-filter/files/appfilter.init +++ b/open-app-filter/files/appfilter.init @@ -1,4 +1,5 @@ #!/bin/sh /etc/rc.common + . /usr/share/libubox/jshn.sh . /lib/functions.sh @@ -7,19 +8,77 @@ USE_PROCD=1 OAFD_BIN="/usr/bin/oafd" FEATURE_FILE="/tmp/feature.cfg" CLASS_FILE="/tmp/app_class.txt" + +disable_offload_nat6() +{ + if [ $(uci -q show firewall.@defaults[0] | grep -c flow_offloading) -ge 1 ]; then + echo flow_offloading > /etc/appfilter/offload_mode + uci -q del firewall.@defaults[0].flow_offloading + uci commit firewall + /etc/init.d/firewall reload >/dev/null 2>&1 + elif [ $(uci -q show firewall.@defaults[0] | grep -c shortcut_fe) -ge 1 ]; then + uci -q get firewall.@defaults[0].shortcut_fe_module > /etc/appfilter/offload_mode + uci -q del firewall.@defaults[0].shortcut_fe + uci -q del firewall.@defaults[0].shortcut_fe_module + uci commit firewall + /etc/init.d/firewall reload >/dev/null 2>&1 + /etc/init.d/shortcut-fe restart + fi + if [ $(uci -q show firewall.@defaults[0] | grep -c nat6) -ge 1 ]; then + true > /etc/appfilter/firewall_nat6 + uci -q del firewall.@defaults[0].nat6 + uci commit firewall + /etc/init.d/nat6 reload >/dev/null 2>&1 + fi +} + +enable_offload() +{ + offload_mode=$(cat /etc/appfilter/offload_mode) + rm -f /etc/appfilter/offload_mode + + if [ "$offload_mode" = "flow_offloading" ]; then + uci set firewall.@defaults[0].flow_offloading='1' + uci commit firewall + /etc/init.d/firewall reload >/dev/null 2>&1 + else + uci set firewall.@defaults[0].shortcut_fe='1' + uci set firewall.@defaults[0].shortcut_fe_module="$offload_mode" + uci commit firewall + /etc/init.d/firewall reload >/dev/null 2>&1 + /etc/init.d/shortcut-fe restart + fi +} + +enable_nat6() +{ + rm -f /etc/appfilter/firewall_nat6 + uci set firewall.@defaults[0].nat6='1' + uci commit firewall + /etc/init.d/nat6 reload >/dev/null 2>&1 +} + service_triggers() { procd_add_reload_trigger "appfilter" } stop_service(){ - killall -9 oafd - rmmod oaf + killall -9 oafd >/dev/null 2>&1 + rmmod oaf >/dev/null 2>&1 + [ -f "/etc/appfilter/offload_mode" ] && enable_offload + [ -f "/etc/appfilter/firewall_nat6" ] && enable_nat6 } start_service(){ + if [ "$(uci -q get appfilter.global.enable)" != 1 ]; then + stop_service + return 1 + fi + local update - rm $FEATURE_FILE + rm -f $FEATURE_FILE + update=`uci get appfilter.feature.update` if [ x"1" == x"$update" ];then ln -s /etc/appfilter/feature.cfg $FEATURE_FILE @@ -32,6 +91,7 @@ start_service(){ ln -s /etc/appfilter/feature_en.cfg $FEATURE_FILE fi fi + disable_offload_nat6 gen_class.sh /tmp/feature.cfg insmod oaf /usr/bin/oaf_rule reload