12 REQ_DUMP_CONNECTIONS = 6
29 print('Deleting node ' + self.name)
31 def parse(self, args):
33 self.address = args[2]
35 args.insert(3, 'port')
38 self.cipher = int(args[6])
39 self.digest = int(args[8])
40 self.maclength = int(args[10])
41 self.compression = int(args[12])
42 self.options = int(args[14], 0x10)
43 self.status = int(args[16], 0x10)
44 self.nexthop = args[18]
46 self.distance = int(args[22])
47 self.pmtu = int(args[24])
48 self.minmtu = int(args[26])
49 self.maxmtu = int(args[28][:-1])
54 def parse(self, args):
57 self.address = args[4]
59 self.options = int(args[8], 16)
60 self.weight = int(args[10])
63 def parse(self, args):
64 if args[0].find('#') >= 0:
65 (address, self.weight) = args[0].split('#', 1)
70 if address.find('/') >= 0:
71 (self.address, self.prefixlen) = address.split('/', 1)
73 self.address = address
79 def parse(self, args):
81 self.address = args[2]
83 args.insert(3, 'port')
86 self.options = int(args[6], 0x10)
87 self.socket = int(args[8])
88 self.status = int(args[10], 0x10)
93 cookiedir = '/var/run/'
96 f = open(self.cookiefile)
97 cookie = string.split(f.readline())
99 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
100 s.connect(('127.0.0.1', int(cookie[1])))
101 self.sf = s.makefile()
103 hello = string.split(self.sf.readline())
105 self.sf.write('0 ^' + cookie[0] + ' 17\r\n')
107 resp = string.split(self.sf.readline())
108 self.port = cookie[1]
112 self.connections = {}
116 self.sf.write('18 3\r\n18 4\r\n18 5\r\n18 6\r\n')
119 for node in self.nodes.values():
121 for edge in self.edges.values():
123 for subnet in self.subnets.values():
124 subnet.visited = False
125 for connections in self.connections.values():
126 connections.visited = False
129 resp = string.split(self.sf.readline())
137 node = self.nodes.get(resp[2]) or Node()
140 self.nodes[resp[2]] = node
144 edge = self.nodes.get((resp[2], resp[4])) or Edge()
147 self.edges[(resp[2], resp[4])] = edge
151 subnet = self.subnets.get((resp[2], resp[4])) or Subnet()
152 subnet.parse(resp[2:])
153 subnet.visited = True
154 self.subnets[(resp[2], resp[4])] = subnet
155 self.nodes[subnet.owner].subnets[resp[2]] = subnet
159 connection = self.connections.get((resp[2], resp[4])) or Connection()
160 connection.parse(resp[2:])
161 connection.visited = True
162 self.connections[(resp[2], resp[4])] = connection
166 for key, subnet in self.subnets.items():
167 if not subnet.visited:
168 del self.subnets[key]
170 for key, edge in self.edges.items():
174 for key, node in self.nodes.items():
178 for key, subnet in node.subnets.items():
179 if not subnet.visited:
180 del node.subnets[key]
182 for key, connection in self.connections.items():
183 if not connection.visited:
184 del self.connections[key]
189 def disconnect(self, name):
190 self.sf.write('18 12 ' + name + '\r\n')
192 resp = string.split(self.sf.readline())
194 def debug(self, level = -1):
195 self.sf.write('18 9 ' + str(level) + '\r\n')
197 resp = string.split(self.sf.readline())
200 def __init__(self, netname = None, controlcookie = None):
201 self.tincconf = VPN.confdir + '/'
204 self.netname = netname
205 self.tincconf += netname + '/'
207 self.tincconf += 'tinc.conf'
209 if controlcookie is not None:
210 self.cookiefile = controlcookie
212 self.cookiefile = VPN.cookiedir + 'tinc.'
214 self.cookiefile += netname + '.'
215 self.cookiefile += 'cookie'