示例#1
0
def tun_fwd(tun, remote, reconnect = None, accept_local = None, accept_remote = None, slowlocal = True, bwlimit = None):
    global TERMINATE
    global SUSPEND
    
    tunqueue = options.vif_txqueuelen or 1000
    tunkqueue = 500
    
    # in PL mode, we cannot strip PI structs
    # so we'll have to handle them
    tunchannel.tun_fwd(tun, remote,
        with_pi = options.mode.startswith('pl-'),
        ether_mode = tun_name.startswith('tap'),
        cipher_key = options.cipher_key,
        udp = options.protocol == 'udp',
        TERMINATE = TERMINATE,
        SUSPEND = SUSPEND,
        stderr = None,
        reconnect = reconnect,
        tunqueue = tunqueue,
        tunkqueue = tunkqueue,
        cipher = options.cipher,
        accept_local = accept_local,
        accept_remote = accept_remote,
        queueclass = queueclass,
        slowlocal = slowlocal,
        bwlimit = bwlimit
    )
示例#2
0
def tun_fwd(tun,
            remote,
            reconnect=None,
            accept_local=None,
            accept_remote=None,
            slowlocal=True,
            bwlimit=None):
    global TERMINATE
    global SUSPEND

    tunqueue = options.vif_txqueuelen or 1000
    tunkqueue = 500

    # in PL mode, we cannot strip PI structs
    # so we'll have to handle them
    tunchannel.tun_fwd(tun,
                       remote,
                       with_pi=options.mode.startswith('pl-'),
                       ether_mode=tun_name.startswith('tap'),
                       cipher_key=options.cipher_key,
                       udp=options.protocol == 'udp',
                       TERMINATE=TERMINATE,
                       SUSPEND=SUSPEND,
                       stderr=None,
                       reconnect=reconnect,
                       tunqueue=tunqueue,
                       tunkqueue=tunkqueue,
                       cipher=options.cipher,
                       accept_local=accept_local,
                       accept_remote=accept_remote,
                       queueclass=queueclass,
                       slowlocal=slowlocal,
                       bwlimit=bwlimit)
示例#3
0
        time.sleep(2)

    remote_port = remote_port.strip()
    remote_port = int(remote_port)

    # Connect local socket to remote port
    sock.connect((remote_host, remote_port))
    remote = os.fdopen(sock.fileno(), 'r+b', 0)

    # TODO: Test connectivity!

    # Create a ret_file to indicate success
    f = open(ret_file, 'w')
    f.write("0")
    f.close()

    # Establish tunnel
    tunchannel.tun_fwd(
        tun,
        remote,
        with_pi=True,  # Planetlab TAP devices add PI headers 
        ether_mode=(vif_type == IFF_TAP),
        udp=True,
        cipher_key=cipher_key,
        cipher=cipher,
        TERMINATE=TERMINATE,
        SUSPEND=SUSPEND,
        tunqueue=txqueuelen,
        tunkqueue=500,
        bwlimit=bwlimit)
示例#4
0
    
    remote_port = remote_port.strip()
    remote_port = int(remote_port)

    # Connect local socket to remote port
    sock.connect((remote_host, remote_port))
    remote = os.fdopen(sock.fileno(), 'r+b', 0)

    # TODO: Test connectivity!    

    # Create a ret_file to indicate success
    f = open(ret_file, 'w')
    f.write("0")
    f.close()

    # Establish tunnel
    tunchannel.tun_fwd(tun, remote,
        with_pi = True, # Planetlab TAP devices add PI headers 
        ether_mode = (vif_type == vsys.IFF_TAP),
        udp = True,
        cipher_key = cipher_key,
        cipher = cipher,
        TERMINATE = TERMINATE,
        SUSPEND = SUSPEND,
        tunqueue = txqueuelen,
        tunkqueue = 500,
        bwlimit = bwlimit
    ) 
 

示例#5
0
    def __forwarder(weak_self):
        # grab strong reference
        self = weak_self()
        if not self:
            return

        peer_port = self.peer_port
        peer_addr = self.peer_addr
        peer_proto = self.peer_proto
        peer_cipher = self.peer_cipher

        local_port = self.tun_port
        local_addr = self.tun_addr
        local_proto = self.tun_proto
        local_cipher = self.tun_cipher

        stderr = self.stderr
        ether_mode = self.ethernet_mode
        with_pi = self.with_pi

        if local_proto != peer_proto:
            raise RuntimeError, "Peering protocol mismatch: %s != %s" % (
                local_proto, peer_proto)

        if local_cipher != peer_cipher:
            raise RuntimeError, "Peering cipher mismatch: %s != %s" % (
                local_cipher, peer_cipher)

        if not peer_port or not peer_addr:
            raise RuntimeError, "Misconfigured peer for: %s" % (self, )

        if not local_port or not local_addr:
            raise RuntimeError, "Misconfigured TUN: %s" % (self, )

        TERMINATE = self._terminate
        SUSPEND = self._suspend
        cipher_key = self.tun_key
        tun = self.tun_socket
        udp = local_proto == 'udp'

        if not tun:
            raise RuntimeError, "Unconnected TUN channel %s" % (self, )

        if local_proto == 'udp':
            rsock = udp_establish(TERMINATE, local_addr, local_port, peer_addr,
                                  peer_port)
            remote = os.fdopen(rsock.fileno(), 'r+b', 0)
        elif local_proto == 'tcp':
            rsock = tcp_establish(TERMINATE, local_addr, local_port, peer_addr,
                                  peer_port)
            remote = os.fdopen(rsock.fileno(), 'r+b', 0)
        else:
            raise RuntimeError, "Bad protocol for %s: %r" % (self, local_proto)

        # notify that we're ready
        self._connected.set()

        # drop strong reference
        del self

        print >> sys.stderr, "Connected"
        tun_fwd(tun,
                remote,
                with_pi=with_pi,
                ether_mode=ether_mode,
                cipher_key=cipher_key,
                udp=udp,
                TERMINATE=TERMINATE,
                SUSPEND=SUSPEND,
                stderr=stderr,
                cipher=local_cipher)

        tun.close()
        remote.close()