From 877e2d9005e4ea63fb25c3e1c581776c7f20e2c8 Mon Sep 17 00:00:00 2001 From: Eneko Date: Wed, 5 Aug 2026 12:15:39 +0200 Subject: [PATCH] feat: added IPTABLES_ARGS so --wait argument is optional --- README.md | 2 +- limitator | 39 ++++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d3ff214..f807355 100644 --- a/README.md +++ b/README.md @@ -29,4 +29,4 @@ scp -rO www root@ROUTER:/ 1) Change packages source in /etc/opkg.conf putting http://web.archive.org/web/20260213065024id_/ before the URL. For example: http://web.archive.org/web/20260213065024id_/https://archive.openwrt.org/backfire/10.03.1/brcm-2.4/packages 2) Install iptables-mod-ipopt (NO ESTOY SEGURO, SIN PONERLO FUNCIONA Y EN EL WRT54G DABA ERROR EL COMANDO IPTABLES CON EL MODULO QUOTA Y LO TENÍA INSTALADO) 3) Delete /bin/date link -4) Cannot scp files, you need to paste but vi messes with idents. Use `:set noai` command in vi. Other option is using wget from other routers (not an option for limitator.json). +4) In /etc/config/limitator set `iptables_args` to a space. The included version of iptables does not support `--wait` argument. Does not use empty string, it will assume variable is unset and it will use default value. diff --git a/limitator b/limitator index 3e16c55..0c09db4 100644 --- a/limitator +++ b/limitator @@ -23,6 +23,7 @@ config_get USED_BYTES_FILE limitator used_bytes_file '/root/limitator/used_bytes config_get LOG_FILE limitator log_file '/root/limitator/log' # A persistent file to log. config_get IPTABLES_CHAIN limitator iptables_chain 'LIMITATOR' # Name of iptables chain. config_get IPTABLES_FORWARD limitator iptables_forward 'forwarding_rule' # Name of iptables rule for forward. +config_get IPTABLES_ARGS limitator iptables_args '--wait' # Additional arguments for iptables commands. get_saved_used_bytes(){ local used_bytes @@ -55,7 +56,7 @@ get_iptables_quota_rule_num(){ } get_current_used_bytes(){ - local used_bytes=$(iptables --wait -vnxL $IPTABLES_CHAIN $(get_iptables_quota_rule_num) | awk '{print $2}') + local used_bytes=$(iptables $IPTABLES_ARGS -vnxL $IPTABLES_CHAIN $(get_iptables_quota_rule_num) | awk '{print $2}') if [ -n "$used_bytes" ];then echo -n $used_bytes else @@ -108,44 +109,44 @@ get_json(){ } reset_quota(){ - iptables --wait -Z $IPTABLES_CHAIN $(get_iptables_quota_rule_num) + iptables $IPTABLES_ARGS -Z $IPTABLES_CHAIN $(get_iptables_quota_rule_num) echo -n 0 > ${USED_BYTES_FILE} } del_iptables_rule(){ - iptables --wait -F $IPTABLES_CHAIN + iptables $IPTABLES_ARGS -F $IPTABLES_CHAIN while true do - line=$(iptables --wait -L $IPTABLES_FORWARD|sed -e '1,2d'|grep -n $IPTABLES_CHAIN|head -1|cut -d : -f 1 2>/dev/null) - [ -n "$(echo $line|grep -E ^[[:digit:]]+$)" ] && iptables --wait -D $IPTABLES_FORWARD $line || break + line=$(iptables $IPTABLES_ARGS -L $IPTABLES_FORWARD|sed -e '1,2d'|grep -n $IPTABLES_CHAIN|head -1|cut -d : -f 1 2>/dev/null) + [ -n "$(echo $line|grep -E ^[[:digit:]]+$)" ] && iptables $IPTABLES_ARGS -D $IPTABLES_FORWARD $line || break done - iptables --wait -D $IPTABLES_FORWARD 1 - iptables --wait -X $IPTABLES_CHAIN + iptables $IPTABLES_ARGS -D $IPTABLES_FORWARD 1 + iptables $IPTABLES_ARGS -X $IPTABLES_CHAIN } set_iptables_rule(){ - iptables --wait -N $IPTABLES_CHAIN + iptables $IPTABLES_ARGS -N $IPTABLES_CHAIN if [ -n "$EXCLUDE_NETWORK" ];then - iptables --wait -I $IPTABLES_CHAIN 1 -s $EXCLUDE_NETWORK -j ACCEPT - iptables --wait -I $IPTABLES_CHAIN 2 -d $EXCLUDE_NETWORK -j ACCEPT + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 1 -s $EXCLUDE_NETWORK -j ACCEPT + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 2 -d $EXCLUDE_NETWORK -j ACCEPT fi if [ -n "$EXCLUDE_NETWORK2" ];then - iptables --wait -I $IPTABLES_CHAIN 3 -s $EXCLUDE_NETWORK2 -j ACCEPT - iptables --wait -I $IPTABLES_CHAIN 4 -d $EXCLUDE_NETWORK2 -j ACCEPT + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 3 -s $EXCLUDE_NETWORK2 -j ACCEPT + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 4 -d $EXCLUDE_NETWORK2 -j ACCEPT fi if [ -n "$EXCLUDE_NETWORK3" ];then - iptables --wait -I $IPTABLES_CHAIN 5 -s $EXCLUDE_NETWORK3 -j ACCEPT - iptables --wait -I $IPTABLES_CHAIN 6 -d $EXCLUDE_NETWORK3 -j ACCEPT + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 5 -s $EXCLUDE_NETWORK3 -j ACCEPT + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 6 -d $EXCLUDE_NETWORK3 -j ACCEPT fi if [ -n "$EXCLUDE_NETWORK4" ];then - iptables --wait -I $IPTABLES_CHAIN 7 -s $EXCLUDE_NETWORK4 -j ACCEPT - iptables --wait -I $IPTABLES_CHAIN 8 -d $EXCLUDE_NETWORK4 -j ACCEPT + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 7 -s $EXCLUDE_NETWORK4 -j ACCEPT + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN 8 -d $EXCLUDE_NETWORK4 -j ACCEPT fi - iptables --wait -I $IPTABLES_CHAIN $(get_iptables_quota_rule_num) -c 0 $(get_saved_used_bytes) -m quota --quota $(get_remaining_quota) -j ACCEPT 2>> $LOG_FILE - iptables --wait -I $IPTABLES_CHAIN $(($(get_iptables_quota_rule_num) + 1)) -j REJECT 2>> $LOG_FILE + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN $(get_iptables_quota_rule_num) -c 0 $(get_saved_used_bytes) -m quota --quota $(get_remaining_quota) -j ACCEPT 2>> $LOG_FILE + iptables $IPTABLES_ARGS -I $IPTABLES_CHAIN $(($(get_iptables_quota_rule_num) + 1)) -j REJECT 2>> $LOG_FILE - iptables --wait -I $IPTABLES_FORWARD 1 -d $INTRANET -s $INTRANET -j ACCEPT + iptables $IPTABLES_ARGS -I $IPTABLES_FORWARD 1 -d $INTRANET -s $INTRANET -j ACCEPT iptables -I $IPTABLES_FORWARD 2 -j $IPTABLES_CHAIN }