NSENTER selector and nat table seletors included
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Task type variables
|
||||
NSENTER=$NSENTER
|
||||
PREROUTING=$PREROUTING
|
||||
POSTROUTING=$POSTROUTING
|
||||
|
||||
# Mandatory task variables
|
||||
NAME=$NAME-$COMMENT
|
||||
CHAIN=$CHAIN
|
||||
COMMENT=$COMMENT
|
||||
PROTOCOL=$TYPE
|
||||
VPN_IP=$VPN_IP
|
||||
VPN_NETWORK=$VPN_NETWORK
|
||||
|
||||
##############################
|
||||
|
||||
@@ -41,22 +45,42 @@ for source_ip_index in $(seq 1 $COUNT_SOURCE_IP) ; do
|
||||
# NSENTER Specific settings #
|
||||
if [[ "$NSENTER" == "true" ]] ; then
|
||||
|
||||
if [[ "$PREROUTING" == "true" ]] || [[ "$POSTROUTING" == "true" ]] ; then
|
||||
iptables="nsenter -t $(docker inspect --format {{.State.Pid}} $NAME) -n -- $IPTABLES -t nat";
|
||||
|
||||
# DELETE UNECESSARY LINES FROM PREVIOUS RULES
|
||||
LINES=$($iptables --line-number -n | grep $VPN_NETWORK | awk '{print $1}'| tac)
|
||||
if [[ "$PREROUTING" == "true" ]] ; then
|
||||
LINES=$($iptables --line-number -n | grep $COMMENT | awk '{print $1}'| tac)
|
||||
|
||||
# DELETE UNECESSARY LINES FROM PREVIOUS RULES
|
||||
if [ -n "$LINES" ] ; then
|
||||
for i in $LINES; do
|
||||
$iptables -D $CHAIN $i
|
||||
$iptables -D PREROUTING $i
|
||||
sleep 0.1
|
||||
done
|
||||
fi
|
||||
|
||||
$iptables -I POSTROUTING -m state --state established,related -j ACCEPT;
|
||||
|
||||
$iptables -I PREROUTING -d $SOURCE_IP -p $PROTOCOL --dport $SOURCE_PORT -m comment --comment "$COMMENT" -j DNAT --to $TARGET_IP:$TARGET_PORT
|
||||
|
||||
elif [[ "$POSTROUTING" == "true" ]] ; then
|
||||
LINES=$($iptables --line-number -n | grep $COMMENT | awk '{print $1}'| tac)
|
||||
|
||||
# DELETE UNECESSARY LINES FROM PREVIOUS RULES
|
||||
if [ -n "$LINES" ] ; then
|
||||
for i in $LINES; do
|
||||
$iptables -D POSTROUTING $i
|
||||
sleep 0.1
|
||||
done
|
||||
fi
|
||||
|
||||
$iptables -I POSTROUTING -d $TARGET_IP -p $PROTOCOL --dport $TARGET_PORT -m comment --comment "$COMMENT" -j MASQUERADE
|
||||
|
||||
else
|
||||
ip_route="nsenter -t $(docker inspect --format {{.State.Pid}} $NAME) -n -- ip route";
|
||||
|
||||
|
||||
fi
|
||||
|
||||
|
||||
else
|
||||
if $IPTABLES --list $CHAIN |grep ESTABLISHED |grep RELATED|grep ACCEPT ; then
|
||||
echo "nothing to do";
|
||||
|
Reference in New Issue
Block a user