vroute script, minor fixes
authorClaudio-Daniel Freire <cdfreire@antar.inria.fr>
Mon, 23 May 2011 09:01:07 +0000 (11:01 +0200)
committerClaudio-Daniel Freire <cdfreire@antar.inria.fr>
Mon, 23 May 2011 09:01:07 +0000 (11:01 +0200)
exec/vroute

index 63a9029..a2858c2 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 # VSYS script to configure routes on virtual network interfaces from the root slice
-#   Thom Haddow - 06/10/09
+#   Claudio Freire - 2011/05/19
 #
 # Gets slice name as argv[1]
 # Takes routing rules on stdin, one per line
@@ -55,15 +55,12 @@ except:
     vnet_base = vnet_mask = None
 
 if vnet_base is None:
-    #print >>sys.stderr, "Could not find entry for slice %s in netblock config file %s" % (slicename, netblock_config)
-    #sys.exit(1)
-    vnet_base = '192.168.2.0'
-    vnet_mask = 24
+    print >>sys.stderr, "Could not find entry for slice %s in netblock config file %s" % (slicename, netblock_config)
+    sys.exit(1)
 
 vnet_int = struct.unpack('!L', socket.inet_aton(vnet_base))[0]
-vnet_int = (vnet_int >> vnet_mask) << vnet_mask
-
-mask_int = (0xffffffff << vnet_mask) & 0xffffffff
+vnet_int = (vnet_int >> (32-vnet_mask)) << (32-vnet_mask)
+mask_int = (0xffffffff >> (32-vnet_mask)) << (32-vnet_mask)
 
 # rule line regex
 rule_re = r"(?P<cmd>add|del)\s+(?P<targetbase>(?:\d{1,3}[.]){3}\d{1,3})(?:/(?P<targetprefix>\d{1,2}))?\s+gw\s+(?P<gw>(?:\d{1,3}[.]){3}\d{1,3}) (?P<dev>(?:tun|tap)%d-\d{1,5})" % (sliceid,)
@@ -77,7 +74,7 @@ for argline in sys.stdin:
     # validating overall structure in the process
     match = rule_re.match(argline)
     if not match:
-        print >>sys.stderr, "Invalid rule %r:" % (argline,)
+        print >>sys.stderr, "Invalid rule %r" % (argline,)
         continue
     
     # Validate IPs involved
@@ -123,7 +120,7 @@ for argline in sys.stdin:
     if (gw_ip_int & mask_int) != vnet_int:
         print >>sys.stderr, "Invalid rule %r: gateway must belong to the %s/%s network" % (argline, vnet_base, vnet_mask)
         continue
-    
+
     # Revalidate command (just in case)
     command = match.group("cmd")
     if command not in ('add','del'):