11 $slicename = $ARGV[0];
12 $portnumber = <STDIN>;
18 if (-f "/dev/shm/rawtcp-$slicename") {
19 print "Sorry, only 1 port reservation is allowed per slice. You reserved ".`cat /dev/shm/rawtcp-$slicename`;
22 if ($ipaddress!~/^\d+\.\d+\.\d+\.\d+/) {
23 die("$ipaddress is not an ip address");
26 if ($portnumber!~/^\d+$/) {
27 die("$portnumber is not a port number");
30 $portnumber=int($portnumber);
31 open CMD1,"vcontext --ctx 1 --migrate -- ncontext --nid 1 --migrate fuser -n tcp $portnumber 2>/dev/null |";
33 my $fuser = join '',@f;
38 open CMD2,"chcontext --ctx 1 -- cat /proc/$fuser/vinfo|";
42 @userinfo = split /\s/,$vinfo;
43 my $uid = $userinfo[1];
44 my $slice_id = `id -u $slicename`;
47 if ($slice_id eq $uid) {
48 my $default_route = `ip route get $ipaddress`;
50 $default_route =~ /dev ([^\s]+)/;
55 die("Sorry, you don't own the next hop for that route, which is $dev");
58 #### If we made it here, it means:
59 #### 1. The user is bound to the desired port, which is in the 61000+ range.
60 #### 2. There is a local device for the supplied IP address.
61 #### 3. The calling user owns that device.
63 #### Next: Bridge the port with the device
65 my $iptables_cmd = "iptables -t nat -A PREROUTING -m tcp -p tcp --dport $portnumber -j DNAT --to $ipaddress:$portnumber";
66 system($iptables_cmd);
67 system("echo $portnumber > /dev/shm/rawtcp-$slicename");
68 print "Port reservation commands executed";
71 print "$portnumber is taken by somebody else, sorry";
75 print "Please bind to $portnumber first."