From owner-p4-projects@FreeBSD.ORG Fri May 30 22:17:53 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E23E31065674; Fri, 30 May 2008 22:17:52 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A457A106564A for ; Fri, 30 May 2008 22:17:52 +0000 (UTC) (envelope-from bilouro@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id AD3958FC13 for ; Fri, 30 May 2008 22:17:52 +0000 (UTC) (envelope-from bilouro@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m4UMHq6f003282 for ; Fri, 30 May 2008 22:17:52 GMT (envelope-from bilouro@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m4UMHqc0003280 for perforce@freebsd.org; Fri, 30 May 2008 22:17:52 GMT (envelope-from bilouro@FreeBSD.org) Date: Fri, 30 May 2008 22:17:52 GMT Message-Id: <200805302217.m4UMHqc0003280@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bilouro@FreeBSD.org using -f From: Victor Hugo Bilouro To: Perforce Change Reviews Cc: Subject: PERFORCE change 142608 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 May 2008 22:17:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=142608 Change 142608 by bilouro@bilouro_tcptest on 2008/05/30 22:17:46 This version send SYN, receive SYN+ACK, send ACK But, after send the ACK the server(passive open) aswer with a RESET. I don't why yet! Affected files ... .. //depot/projects/soc2008/bilouro_tcptest/src/scripts/tcpconnect.py#3 edit Differences ... ==== //depot/projects/soc2008/bilouro_tcptest/src/scripts/tcpconnect.py#3 (text+ko) ==== @@ -45,13 +45,14 @@ # # creating a durty-code ether-ip-tcp-syn packet # + import random ip = ipv4.ipv4() ip.version = 4 # 0100 max 1111 15 *caution* :) ip.hlen = 5 # 0101 0 -> min 0101 (20 bytes) ip.tos = 0 - ip.id = 1 #time of day + ip.id = random.randrange(1,(1<<16)-1) ip.flags = 0 #study on book ip.offset = 0 ip.ttl = 64 @@ -64,7 +65,7 @@ tcppkt.sport = int(options.source_port ) tcppkt.dport = int(options.destination_port) - tcppkt.sequence = 300 + tcppkt.sequence = random.randrange(1,(1<<32)-1) tcppkt.ack_number = 0 tcppkt.offset = 5 #header length tcppkt.urgent = 0 @@ -73,7 +74,7 @@ tcppkt.reset = 0 tcppkt.syn = 1 tcppkt.fin = 0 - tcppkt.window = 65535 + tcppkt.window = (1<<16)-1 tcppkt.urg_point = 0 #tcppkt.options @@ -89,22 +90,120 @@ ether.dst = ethernet.ether_atob(options.ether_destination) ether.type = 0x800 + print "\n syn---------------------------------" + print tcppkt + print "---------------------------------" + packet = pcs.Chain([ether, ip, tcppkt]) output = pcs.PcapConnector(options.interface) + # SYN SENT out = output.write(packet.bytes, len(packet.bytes)) + + + + reply = output.read() reply = output.read() packet = ethernet.ethernet(reply) - print "\n---------------------------------" - print packet - print packet.data + print "\n syn+ack-----------------------------" + print packet.data.data print "---------------------------------" - print packet.data.data + + # + # this commented piece dont work.. don't ask me why. (now) + # + + #tcpreply = packet.data.data + + #import copy + #ipack = copy.deepcopy(ip) + #ipack.id = ip.id + 1 + + #tcpack = copy.deepcopy(tcppkt) + + #tcpack.sequence = 0 + #tcpack.ack_number = tcpreply.sequence + 1 + #tcpack.ack = 1 + #tcpack.syn = 0 + #tcpack.checksum = tcp_cksum(tcpack , ipack) + + # important, only calcs the ip checksum after fill length field + #ipack.checksum = ip_cksum(ipack) + + #packetreply = pcs.Chain([ether, ipack, tcpack]) + #out = output.write(packetreply.bytes, len(packetreply.bytes)) + + # + # ANOTHER. this worked! (please don't pay attention in how it was wrote, it's a very durty test, ok?) + # + + ipack = ipv4.ipv4() + + ipack.version = 4 # 0100 max 1111 15 *caution* :) + ipack.hlen = 5 # 0101 0 -> min 0101 (20 bytes) + ipack.tos = 0 + ipack.id = ip.id + 1 + ipack.flags = 0 #study on book + ipack.offset = 0 + ipack.ttl = 64 + ipack.protocol = pcs.IPPROTO_TCP #1 ICMP #6 TCP + ipack.src = pcs.inet_atol(options.ip_source) + ipack.dst = pcs.inet_atol(options.ip_target) + + tcpreply = packet.data.data + tcpack = tcp.tcp() + + tcpack.sport = int(options.source_port ) + tcpack.dport = int(options.destination_port) + tcpack.sequence = 0 + tcpack.ack_number = tcpreply.sequence + 1 + tcpack.offset = 5 #header length + tcpack.urgent = 0 + tcpack.ack = 1 + tcpack.push = 0 + tcpack.reset = 0 + tcpack.syn = 0 + tcpack.fin = 0 + tcpack.window = (1<<16)-1 + tcpack.urg_point = 0 + #tcpack.options + + tcpack.checksum = tcp_cksum(tcpack , ipack) + + ipack.length = len(ipack.bytes) + len(tcpack.bytes) + + # important, only calcs the ip checksum after fill length field + ipack.checksum = ip_cksum(ipack) + + etherack = ethernet.ethernet() + etherack.src = ethernet.ether_atob(options.ether_source) + etherack.dst = ethernet.ether_atob(options.ether_destination) + etherack.type = 0x800 + + packetack = pcs.Chain([etherack, ipack, tcpack]) + out = output.write(packetack.bytes, len(packetack.bytes)) + + print "\n ack---------------------------------" + print tcpack print "---------------------------------" + # /ANOTHER + + reply = output.read() + while 1: + try: + reply = output.read() + packet = ethernet.ethernet(reply) + if packet.data.data.sport == 22022: + print "\n-----------------------------" + print packet.data.data + print "---------------------------------" + except: + pass + def tcp_cksum(self, ip, data = ""): #TODO: add this method to pcs tcp.py """return tcpv4 checksum"""