From 8185b9f54837026f4437fa38eae4165861e71a2d Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Mon, 22 Apr 2024 08:36:45 -0500 Subject: [PATCH] optimize script ipv6 condition no more forking a sed process --- scripts/shield-trigger | 9 +++------ scripts/shield-trigger-iptables | 12 ++---------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/scripts/shield-trigger b/scripts/shield-trigger index 9aed262..65adf85 100755 --- a/scripts/shield-trigger +++ b/scripts/shield-trigger @@ -27,12 +27,9 @@ null_route() { # louzy detection of IPv4 or IPv6 address # TASK="$1" - INET=$(echo "$2" | sed 's/[0-9\.]//g') - if [ -z "$INET" ] - then - INET="" - GW="127.0.0.1" - else + INET="" + GW="127.0.0.1" + if [ "${2#*:}" != "$2" ] ; then INET="-f inet6" GW="::1" fi diff --git a/scripts/shield-trigger-iptables b/scripts/shield-trigger-iptables index 3f7e92b..51d446f 100755 --- a/scripts/shield-trigger-iptables +++ b/scripts/shield-trigger-iptables @@ -22,16 +22,8 @@ # run_iptables() { - # - # louzy detection of IPv4 or IPv6 address - # - IPT=$(echo "$2" | sed 's/[0-9\.]//g') - if [ -z "$IPT" ] - then - IPT=iptables - else - IPT=ip6tables - fi + IPT="iptables" + [ "${2#*:}" != "$2" ] && IPT="ip6tables" # switch -A for iptables to -I if [ "$1" = "-A" ]