class TunTapHarness(object): def __init__(self, name, newCharDevHarness, addr, addr6): self._newCharDevHarness = newCharDevHarness self.name = name self.addr = addr self.addr6 = addr6 def start(self): self.char_dev = self._newCharDevHarness() self.char_dev.open() self.interface = InterfaceHarness(self.name, self.char_dev.unit) def up(self): self.interface.addIfAddr(local = self.addr.sa_local, dst = self.addr.sa_dst, mask = self.addr.sa_mask) self.interface.addIfAddr6(local = self.addr6.sa_local, dst = self.addr6.sa_dst, mask = self.addr6.sa_mask) # Lion automatically creates routes for IPv6 addresses, earlier versions don't. try: tuntap.route.addNet(dst = self.addr6.sa_remote, netmask = self.addr6.sa_mask, interface = self.interface.lladdr) except IOError as e: if e.errno != errno.EEXIST: raise e self.interface.flags |= InterfaceHarness.IFF_UP def stop(self): self.interface.flags &= ~InterfaceHarness.IFF_UP self.char_dev.close()
class TunTapHarness(object): def __init__(self, name, newCharDevHarness, addr, addr6): self._newCharDevHarness = newCharDevHarness self.name = name self.addr = addr self.addr6 = addr6 def start(self): self.char_dev = self._newCharDevHarness() self.char_dev.open() self.interface = InterfaceHarness(self.name, self.char_dev.unit) def up(self): self.interface.addIfAddr(local=self.addr.sa_local, dst=self.addr.sa_dst, mask=self.addr.sa_mask) self.interface.addIfAddr6(local=self.addr6.sa_local, dst=self.addr6.sa_dst, mask=self.addr6.sa_mask) # Lion automatically creates routes for IPv6 addresses, earlier versions don't. try: tuntap.route.addNet(dst=self.addr6.sa_remote, netmask=self.addr6.sa_mask, interface=self.interface.lladdr) except IOError as e: if e.errno != errno.EEXIST: raise e self.interface.flags |= InterfaceHarness.IFF_UP def stop(self): self.interface.flags &= ~InterfaceHarness.IFF_UP self.char_dev.close()
def start(self): self.char_dev = self._newCharDevHarness() self.char_dev.open() self.interface = InterfaceHarness(self.name, self.char_dev.unit)