Esempio n. 1
0
    def handle_packet_from_outside(data):
        logging.debug('--------------------------------------------------')
        logging.debug('--------------------------------------------------')
        logging.debug('got packet: %s' % pktstr(data))
        pkt = Packet(data)

        if pkt.is_tcp() and pkt.is_valid_tcp():
            logging.debug('passing on tcp packet ...')
            tcp_conn = server.handle_tcp(pkt)
            if tcp_conn:
                tcp_pts = tcp_conn.get_packets_to_send()
                if tcp_pts:
                    for tcp, data in tcp_pts:
                        eth = pkt.get_reversed_eth()
                        ip = pkt.get_reversed_ip(new_ttl=64,
                                                 new_tlen=pkt.ip_hlen +
                                                 len(tcp) + len(data))
                        p = eth + ip + Packet.cksum_tcp_hdr(ip, tcp,
                                                            data) + data
                        logging.debug('sending packet: %s' % pktstr(p))
                        try:
                            raw_socket.send(p)
                        except socket.error:
                            logging.exception('failed to send packet')
                            sys.exit(-1)
                else:
                    logging.debug('no packets to send back')
Esempio n. 2
0
File: Topology.py Progetto: smbz/vns
 def send_packets(self):
     """Send any waiting packets"""
     if self.intf and self.pkt:
         for (_, tcp_conn) in self.http_server.connections.iteritems():
             if tcp_conn and not tcp_conn.dead:
                 tcp_pts = tcp_conn.get_packets_to_send()
                 for tcp, data in tcp_pts:
                     eth = self.pkt.get_reversed_eth()
                     ip = self.pkt.get_reversed_ip(new_ttl=64, new_tlen=self.pkt.ip_hlen+len(tcp)+len(data))
                     pkt_out = eth + ip + Packet.cksum_tcp_hdr(ip, tcp, data) + data
                     logging.debug('%s sending packet from HTTP server: %s' % (self, pktstr(pkt_out)))
                     self.intf.link.send_to_other(self.intf, pkt_out)
Esempio n. 3
0
 def handle_http_request(self, intf, pkt):
     """Forward the received packet from an HTTP client to the web server."""
     tcp_conn = self.http_server.handle_tcp(pkt)
     if tcp_conn:
         tcp_pts = tcp_conn.get_packets_to_send()
         if tcp_pts:
             for tcp, data in tcp_pts:
                 eth = pkt.get_reversed_eth()
                 ip = pkt.get_reversed_ip(new_ttl=64, new_tlen=pkt.ip_hlen+len(tcp)+len(data))
                 pkt_out = eth + ip + Packet.cksum_tcp_hdr(ip, tcp, data) + data
                 logging.debug('%s sending packet from HTTP server: %s' % (self, pktstr(pkt_out)))
                 intf.link.send_to_other(intf, pkt_out)
Esempio n. 4
0
    def handle_packet_from_outside(data):
        logging.debug('--------------------------------------------------')
        logging.debug('--------------------------------------------------')
        logging.debug('got packet: %s' % pktstr(data))
        pkt = Packet(data)

        if pkt.is_tcp() and pkt.is_valid_tcp():
            logging.debug('passing on tcp packet ...')
            tcp_conn = server.handle_tcp(pkt)
            if tcp_conn:
                tcp_pts = tcp_conn.get_packets_to_send()
                if tcp_pts:
                    for tcp, data in tcp_pts:
                        eth = pkt.get_reversed_eth()
                        ip = pkt.get_reversed_ip(new_ttl=64, new_tlen=pkt.ip_hlen+len(tcp)+len(data))
                        p = eth + ip + Packet.cksum_tcp_hdr(ip, tcp, data) + data
                        logging.debug('sending packet: %s' % pktstr(p))
                        try:
                            raw_socket.send(p)
                        except socket.error:
                            logging.exception('failed to send packet')
                            sys.exit(-1)
                else:
                    logging.debug('no packets to send back')