Updating vsys factory. This will become the new location of vsys scripts, outdating...
authorSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 27 Feb 2009 17:30:42 +0000 (17:30 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 27 Feb 2009 17:30:42 +0000 (17:30 +0000)
nfsmount [new file with mode: 0755]
pfmount
portsummary [new file with mode: 0755]

diff --git a/nfsmount b/nfsmount
new file mode 100755 (executable)
index 0000000..04115dc
--- /dev/null
+++ b/nfsmount
@@ -0,0 +1,51 @@
+#!/usr/bin/perl
+
+use strict;
+
+my $slicename=$ARGV[0];
+my $already_mounted_testfile = "/tmp/$slicename"."_nfsmounted";
+
+my $slice_dir="/vservers/$slicename/";
+
+if (-f $already_mounted_testfile) {
+       die("Sorry, only one successful NFS mount allowed per slice!");
+}
+
+my $remotepath = <STDIN>;
+my $localpath = <STDIN>;
+chomp($localpath);
+chomp($remotepath);
+$localpath=~s/\.\.//g;
+
+$localpath=$slice_dir.$localpath;
+
+unless (-d $localpath) {
+       die("Localpath does not exist, please create it first.");
+}
+
+my $hostexpr="(?=^.{1,254}$)(^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)";
+my $pathexpr="\/?[\w\d]+\/[\w\d]*\/?";
+my $nfshost;
+my $nfspath;
+
+($nfshost,$nfspath)=split ':',$remotepath;
+
+if ($nfshost!~/(?=^.{1,254}$)(^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)/) {
+       die("The hostname $nfshost does not seem to be right.");
+}
+
+if ($nfspath!~/^(((\.\.){1}\/)*|(\/){1})?(([a-zA-Z0-9]*)\/)*([a-zA-Z0-9]*)+$/) {
+       die("The remote path $nfspath does not seem to be right.");
+} 
+
+my $mntcmd="/bin/mount $remotepath $localpath";
+system($mntcmd);
+
+if ($?) {
+    print "Mount failed: $?";
+}
+else {
+    open FIL, ">$already_mounted_testfile";
+    print FIL "$remotepath $localpath";
+    close FIL;
+}
diff --git a/pfmount b/pfmount
index fb7ee6c..0282c76 100755 (executable)
--- a/pfmount
+++ b/pfmount
@@ -6,5 +6,5 @@
 DEST="/vservers/$1/pf"
 mount | grep "on $DEST type" > /dev/null
 if [ $? -eq 1 ]; then
-    mount --bind /var/local/fprobe $DEST
+    mount --bind /var/local/fprobe -o ro $DEST
 fi
diff --git a/portsummary b/portsummary
new file mode 100755 (executable)
index 0000000..f800632
--- /dev/null
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+
+import os
+import sys
+
+# NOTE: '--inet' lists only ipv4 addresses.
+ns = os.popen("ncontext --nid 1 --migrate -- vcontext --xid 1 --migrate -- netstat -apnlut --inet", 'r')
+port_summary = {}
+for line in ns:
+       try:
+               ns_fields = line.split()
+               if ns_fields[0] == "tcp" or ns_fields[0] == "udp":
+                       (src_ip, src_port) = ns_fields[3].split(':')
+                       (dst_ip, dst_port) = ns_fields[4].split(':')
+
+                       port_key='%s-%s' % (src_port, dst_port)
+
+                       if src_ip is not "0.0.0.0" and port_key in port_summary:
+                               # skip INADDR_ANY addresses and ports we've already seen.
+                               continue
+
+                       conn_state = ns_fields[5]
+                       if ns_fields[0] == "tcp":
+                               proc_field = ns_fields[6]
+                       else:
+                               if conn_state == "ESTABLISHED":
+                                       proc_field = ns_fields[6]
+                               else:
+                                       proc_field = ns_fields[5]
+
+                       if proc_field != "-":
+                               (pid,procname)= proc_field.split('/')
+                       else:
+                               # NOTE: without a PID there is no way to associate with an XID
+                               continue
+
+                       if ( ns_fields[0] == "tcp" and src_ip == "0.0.0.0" and conn_state == "LISTEN" ) or \
+                          ( ns_fields[0] == "udp" and src_ip == "0.0.0.0" ):
+                               type='C'
+                       elif src_ip == "127.0.0.1":
+                               type='l'
+                       elif src_ip != "0.0.0.0" and src_ip != "127.0.0.1":
+                               type='c'
+                       else:
+                               type='?'
+
+                       xid_stream = os.popen("vserver-info %s XID" % pid)
+                       xid = xid_stream.read()
+
+                       port_summary[port_key] = {'prot' : ns_fields[0], 
+                                                                         'src_port' : src_port, 
+                                                                         'dst_port' : dst_port, 
+                                                                         'slice' : xid[:-1], 
+                                                                         'type': type}
+       except:
+               import traceback; traceback.print_exc()
+               print line
+
+ports = port_summary.keys()
+ports.sort()
+for port in ports:
+       print "%(prot)4s\t%(src_port)6s\t%(dst_port)6s\t%(slice)5s\t%(type)s" % port_summary[port]
+