From: Claudio-Daniel Freire Date: Mon, 23 May 2011 09:01:07 +0000 (+0200) Subject: vroute script, minor fixes X-Git-Tag: vsys-scripts-0.95-29~3 X-Git-Url: http://git.onelab.eu/?p=vsys-scripts.git;a=commitdiff_plain;h=680804fa08b47a7fbdfc2253fbfdc0dd232420c8 vroute script, minor fixes --- diff --git a/exec/vroute b/exec/vroute index 63a9029..a2858c2 100755 --- a/exec/vroute +++ b/exec/vroute @@ -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"(?Padd|del)\s+(?P(?:\d{1,3}[.]){3}\d{1,3})(?:/(?P\d{1,2}))?\s+gw\s+(?P(?:\d{1,3}[.]){3}\d{1,3}) (?P(?: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'):