X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=exec%2Fif_port_forward;fp=exec%2Fif_port_forward;h=400591b1f951f3882e9159a2993406296520c6c3;hb=c57a1628286a502b45358326d551b94596455fda;hp=36451c94421fd9046eb860bf6fecab6182721427;hpb=2924dcb60eeaf665a48bbb4c9595951ba1754a5d;p=vsys-scripts.git diff --git a/exec/if_port_forward b/exec/if_port_forward index 36451c9..400591b 100755 --- a/exec/if_port_forward +++ b/exec/if_port_forward @@ -12,7 +12,14 @@ chomp($dst_port); die ("Src and dst ports need to be numbers") if (($src_port=~/[^0-9]/) || ($src_port=~/[^0-9]/)); -$IPTABLES_CMD="/sbin/iptables -t nat -A PREROUTING -m tcp -p tcp -d $slice_ip --dport $src_port -j DNAT --to-destination $slice_ip:$dst_port"; -print "Invoking port forwarding command: $IPTABLES_CMD\n"; -system($IPTABLES_CMD); +$IPTABLES_CMD_1="/sbin/iptables -t nat -D PREROUTING -m tcp -p tcp -d $slice_ip --dport $src_port -j DNAT --to-destination $slice_ip:$dst_port"; + +$IPTABLES_CMD_2="/sbin/iptables -t nat -A PREROUTING -m tcp -p tcp -d $slice_ip --dport $src_port -j DNAT --to-destination $slice_ip:$dst_port"; + +print "Removing any previous instances of this rule: $IPTABLES_CMD_1\n"; +system($IPTABLES_CMD_1); + +print "Adding forwarding rule: $IPTABLES_CMD_2\n"; +system($IPTABLES_CMD_2); + print "Done.\n";