NSENTER section changes.
This commit is contained in:
@@ -11,6 +11,7 @@ echo 1 > /proc/sys/net/ipv4/ip_forward
|
|||||||
|
|
||||||
##############################
|
##############################
|
||||||
|
|
||||||
|
IPTABLES=/sbin/iptables-legacy
|
||||||
|
|
||||||
###############################
|
###############################
|
||||||
|
|
||||||
@@ -38,51 +39,33 @@ for source_ip_index in $(seq 1 $COUNT_SOURCE_IP) ; do
|
|||||||
# NSENTER Specific settings #
|
# NSENTER Specific settings #
|
||||||
if [[ "$NSENTER" == "true" ]] ; then
|
if [[ "$NSENTER" == "true" ]] ; then
|
||||||
|
|
||||||
iptables="nsenter -t $(docker inspect --format {{.State.Pid}} $NAME) -n -- /sbin/iptables-legacy -t nat";
|
iptables="nsenter -t $(docker inspect --format {{.State.Pid}} $NAME) -n -- $IPTABLES -t nat";
|
||||||
|
|
||||||
if $iptables --list POSTROUTING |grep ESTABLISHED |grep RELATED|grep ACCEPT ; then
|
if $iptables --list POSTROUTING |grep ESTABLISHED |grep RELATED|grep ACCEPT ; then
|
||||||
echo "nothing to do";
|
echo "nothing to do";
|
||||||
else $iptables -I POSTROUTING -m state --state established,related -j ACCEPT;
|
else $iptables -I POSTROUTING -m state --state established,related -j ACCEPT;
|
||||||
fi
|
|
||||||
|
|
||||||
for source_port_index in $(seq 1 $COUNT_SOURCE_PORT) ; do
|
|
||||||
if set |grep SOURCE_PORT_ ; then
|
|
||||||
SOURCE_PORT=$(eval "echo \${"SOURCE_PORT_$source_port_index"}")
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# DELETE UNECESSARY LINES FROM PREVIOUS RULES
|
$iptables -I PREROUTING -d $SOURCE_IP -p $PROTOCOL --dport $SOURCE_PORT -m comment --comment "$COMMENT" -j DNAT --to $TARGET_IP:$TARGET_PORT
|
||||||
LINES=$($iptables --line-number -n --list POSTROUTING | grep $SOURCE_IP |grep $TARGET_IP |grep $PROTOCOL |grep $SOURCE_PORT |grep $TARGET_PORT | awk '{print $1}'| tac)
|
|
||||||
|
|
||||||
if [ -n "$LINES" ] ; then
|
|
||||||
for i in $LINES; do
|
|
||||||
$iptables -D PREROUTING $i
|
|
||||||
sleep 0.1
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
$iptables -I PREROUTING -d $SOURCE_IP -p $PROTOCOL --dport $SOURCE_PORT -m comment --comment "$COMMENT" -j DNAT --to $TARGET_IP:$TARGET_PORT
|
|
||||||
|
|
||||||
done
|
|
||||||
else
|
else
|
||||||
iptables="/sbin/iptables-legacy"
|
if $IPTABLES --list $CHAIN |grep ESTABLISHED |grep RELATED|grep ACCEPT ; then
|
||||||
|
|
||||||
if $iptables --list $CHAIN |grep ESTABLISHED |grep RELATED|grep ACCEPT ; then
|
|
||||||
echo "nothing to do";
|
echo "nothing to do";
|
||||||
else $iptables -I $CHAIN -m state --state established,related -j ACCEPT;
|
else $IPTABLES -I $CHAIN -m state --state established,related -j ACCEPT;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# DELETE UNECESSARY LINES FROM PREVIOUS RULES
|
# DELETE UNECESSARY LINES FROM PREVIOUS RULES
|
||||||
LINES=$($iptables --line-number -n --list $CHAIN | grep $SOURCE_IP |grep $TARGET_IP |grep $PROTOCOL |grep $TARGET_PORT | awk '{print $1}'| tac)
|
LINES=$($IPTABLES --line-number -n --list $CHAIN | grep $SOURCE_IP |grep $TARGET_IP |grep $PROTOCOL |grep $TARGET_PORT | awk '{print $1}'| tac)
|
||||||
|
|
||||||
if [ -n "$LINES" ] ; then
|
if [ -n "$LINES" ] ; then
|
||||||
for i in $LINES; do
|
for i in $LINES; do
|
||||||
$iptables -D $CHAIN $i
|
$IPTABLES -D $CHAIN $i
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$iptables -I $CHAIN -s $SOURCE_IP -d $TARGET_IP -p $PROTOCOL --dport $TARGET_PORT -m comment --comment "$COMMENT" -j ACCEPT
|
$IPTABLES -I $CHAIN -s $SOURCE_IP -d $TARGET_IP -p $PROTOCOL --dport $TARGET_PORT -m comment --comment "$COMMENT" -j ACCEPT
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user