if_port_forward lets a slice forward traffic from one port to another
authorSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 30 Apr 2010 15:52:11 +0000 (15:52 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 30 Apr 2010 15:52:11 +0000 (15:52 +0000)
for its allocated IP addresses. Hack for DONAR on mlab for now, but
likely to come in useful later.

exec/if_port_forward [new file with mode: 0755]

diff --git a/exec/if_port_forward b/exec/if_port_forward
new file mode 100755 (executable)
index 0000000..36451c9
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+$|=1;
+$slice=$ARGV[0];
+$slice_ip=`cat /etc/vservers/$slice/interfaces/0/ip`;
+$src_port = <STDIN>;
+$dst_port = <STDIN>;
+
+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";