From: Sapan Bhatia Date: Fri, 30 Apr 2010 15:52:11 +0000 (+0000) Subject: if_port_forward lets a slice forward traffic from one port to another X-Git-Tag: vsys-scripts-0.95-16~2 X-Git-Url: http://git.onelab.eu/?p=vsys-scripts.git;a=commitdiff_plain;h=ee8353569ded7172d035dea65bcecf0ddfb75bdc if_port_forward lets a slice forward traffic from one port to another for its allocated IP addresses. Hack for DONAR on mlab for now, but likely to come in useful later. --- diff --git a/exec/if_port_forward b/exec/if_port_forward new file mode 100755 index 0000000..36451c9 --- /dev/null +++ b/exec/if_port_forward @@ -0,0 +1,18 @@ +#!/usr/bin/perl + +$|=1; +$slice=$ARGV[0]; +$slice_ip=`cat /etc/vservers/$slice/interfaces/0/ip`; +$src_port = ; +$dst_port = ; + +chomp($slice_ip); +chomp($src_port); +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); +print "Done.\n";