Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Aug 2008 04:19:38 GMT
From:      Victor Hugo Bilouro <bilouro@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 146426 for review
Message-ID:  <200808020419.m724JcaJ032651@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=146426

Change 146426 by bilouro@bilouro_tcptest on 2008/08/02 04:19:02

	Added other reset tests.
	Scripts are functional but not done 

Affected files ...

.. //depot/projects/soc2008/bilouro_tcptest/src/scripts/tests/cresetFromNonSyncState.py#1 add
.. //depot/projects/soc2008/bilouro_tcptest/src/scripts/tests/cresetFromSyncState.py#1 add
.. //depot/projects/soc2008/bilouro_tcptest/src/scripts/tests/cresetfromclosedstate.py#4 edit
.. //depot/projects/soc2008/bilouro_tcptest/src/scripts/tests/tcptest.py#5 edit

Differences ...

==== //depot/projects/soc2008/bilouro_tcptest/src/scripts/tests/cresetfromclosedstate.py#4 (text+ko) ====

@@ -58,11 +58,6 @@
          inetd with descard server running (port 9)
          you must have access DUT's shell with kill -TERM inetd process and /etc/rc.d/inetd stop privileges 
 
-       [TESTS]
-	(a)SYN with and without ACK [80%]
-        (b)URG with and without ACK [0%]
-	(c)FIN with and without ACK [0%]
-	(d)RST with and without ACK [0%]
     """
 
     def setUp(self):
@@ -99,7 +94,7 @@
         self.tcb.output = { self.thisside : pcs.PcapConnector("ed0") , \
                         self.thatside : pcs.PcapConnector("ed0") } 
         
-    def testResetFromClosedStateWithACKSYN(self):
+    def testResetFromClosedStateSYNwithACK(self):
         """
         RFC 793 - Section 3.4 Establishing a Connection
         Page 36
@@ -114,37 +109,49 @@
         reset has sequence number zero and the ACK field is set to the sum
         of the sequence number and segment length of the incoming segment.
         The connection remains in the CLOSED state.
+        
+        Procedure:
+        (1)establish a connection
+        (2)the DUT make a active close
+        (3)we wait for a couple of MSL (enough time to connection go to closed-state)
+        (4)send a SYN with ACK of the above connection
+        (5)waits for a RESET with sequence equals to ack sent 
         """
 
+        #(1)establish a connection
         tcptest.threewayhandshakenoopt(self, self.tcb, self.thisside, self.thatside)   
 
-	print "################"
-	print "# IMPORTANT NOTE"
-	print "################"
-	print "#"
+        #(2)the DUT make a active close
+        print "################"
+        print "# IMPORTANT NOTE"
+        print "################"
+        print "#"
         print "# At this moment you shoud do the following in the device under test(DUT):"
         print '# > socket -4 | grep "\:9"'
         print "# > kill -TERM <PID_OF_INETD>"
         print "# > /etc/rc.d/inetd stop"
         print "# "
+        tcptest.passivecloseconnection(self, self.tcb, self.thisside, self.thatside) 
 
-        tcptest.passivecloseconnection(self, self.tcb, self.thisside, self.thatside) 
+        #(3)we wait for a couple of MSL (enough time to connection go to closed-state)
         print "# "
         print "# Waiting for a couple of MSL(Maximun Segment Lifetime)"
         time.sleep(60) #2MSL(freebsd7)
 
+        #(4)send a SYN with ACK of the above connection
         # 
         #--->Sending SYN
         (ipsyn, tcpsyn) = tcptest.createsyn(self, self.tcb, self.thisside, self.thatside)   
-	#createsyn set ack bit to 0 
+        #createsyn sets ack bit to 0 
         tcpsyn.ack = 1
         tcptest.createwritepacket(self, self.tcb, ipsyn, tcpsyn, self.thisside, self.thatside)   
 
-        # assert RST flag is set
-	(ipfinack, tcpfinack) = tcptest.receive(self,self.tcb, self.thisside, self.thatside) 
+        #(5)waits for a RESET with sequence equals to ack sent
+        (ipfinack, tcpfinack) = tcptest.receive(self,self.tcb, self.thisside, self.thatside) 
         tcptest.assertReset(self, self.tcb, tcpfinack, self.thisside, self.thatside, tcpsyn)
 
-    def testResetFromNonExistentConnection(self):
+    
+    def testResetFromNonExistentConnectionSYN(self):
         """
         RFC 793 - Section 3.4 Establishing a Connection
         Page 36
@@ -156,21 +163,94 @@
 
         If the incoming segment has an ACK field, the reset takes its
         sequence number from the ACK field of the segment, otherwise the
-        reset has sequence number zero and the ACK field is set to the sum
+        reset has sequence number zero and the ACK field is set to the sum 
         of the sequence number and segment length of the incoming segment.
         The connection remains in the CLOSED state.
+
+        Procedure:
+        (1)reset our tcb sequence and sport records.
+        (2)send a SYN withOUT ACK(ack bit=0, ack_number=0) 
+        (3)waits for a RESET with sequence equals to zero and ACK field is set to the sum
+        of the sequence number and segment length of the incoming segment
         """
+        self.tcb.tcpport = { self.thisside : random.randrange(50000, 60000) , \
+            self.thatside : 9}
+        self.tcb.tcpsequence = { self.thisside : random.randrange(1,(1<<32)-1),\
+            self.thatside : 0}
+
         (ipsyn, tcpsyn) = tcptest.createsyn(self, self.tcb, self.thisside, self.thatside)   
         tcptest.createwritepacket(self, self.tcb, ipsyn, tcpsyn, self.thisside, self.thatside)   
-	(ipfinack, tcpfinack) = tcptest.receive(self,self.tcb, self.thisside, self.thatside) 
+        (ipfinack, tcpfinack) = tcptest.receive(self,self.tcb, self.thisside, self.thatside) 
         tcptest.assertReset(self, self.tcb, tcpfinack, self.thisside, self.thatside, tcpsyn)
-	
-	#
-	# HELP NEEDED
-	# My calc of segment length + sequence number is less 19 of the incoming segment. Always 19. any idea?!
+
+
+    def testResetFromNonExistentConnectionFIN(self):
+        """
+        RFC 793 - Section 3.4 Establishing a Connection
+        Page 36
+
+        1.  If the connection does not exist (CLOSED) then a reset is sent
+        in response to any incoming segment except another reset.  In
+        particular, SYNs addressed to a non-existent connection are rejected
+        by this means.
+
+        If the incoming segment has an ACK field, the reset takes its
+        sequence number from the ACK field of the segment, otherwise the
+        reset has sequence number zero and the ACK field is set to the sum 
+        of the sequence number and segment length of the incoming segment.
+        The connection remains in the CLOSED state.
+
+        Procedure:
+        (1)reset our tcb sequence and sport records.
+        (2)send a ACK withOUT ACK(ack bit=0, ack_number=0) 
+        (3)waits for a RESET with sequence equals to zero and ACK field is set to the sum
+        of the sequence number and segment length of the incoming segment
+        """
+        self.tcb.tcpport = { self.thisside : random.randrange(50000, 60000) , \
+            self.thatside : 9}
+        self.tcb.tcpsequence = { self.thisside : random.randrange(1,(1<<32)-1),\
+            self.thatside : 0}
+
+        (ipfin, tcpfin) = tcptest.createfin(self, self.tcb, self.thisside, self.thatside)   
+        tcptest.createwritepacket(self, self.tcb, ipfin, tcpfin, self.thisside, self.thatside)   
+        (ipfinack, tcpfinack) = tcptest.receive(self,self.tcb, self.thisside, self.thatside) 
+        tcptest.assertReset(self, self.tcb, tcpfinack, self.thisside, self.thatside, tcpfin)
+
+
+    def testResetFromNonExistentConnectionRST(self):
+        """
+        RFC 793 - Section 3.4 Establishing a Connection
+        Page 36
+
+        1.  If the connection does not exist (CLOSED) then a reset is sent
+        in response to any incoming segment except another reset.  In
+        particular, SYNs addressed to a non-existent connection are rejected
+        by this means.
+
+        If the incoming segment has an ACK field, the reset takes its
+        sequence number from the ACK field of the segment, otherwise the
+        reset has sequence number zero and the ACK field is set to the sum 
+        of the sequence number and segment length of the incoming segment.
+        The connection remains in the CLOSED state.
+
+        Procedure:
+        (1)reset our tcb sequence and sport records.
+        (2)send a ACK withOUT ACK(ack bit=0, ack_number=0) 
+        (3)waits for a RESET with sequence equals to zero and ACK field is set to the sum
+        of the sequence number and segment length of the incoming segment
+        """
+        self.tcb.tcpport = { self.thisside : random.randrange(50000, 60000) , \
+            self.thatside : 9}
+        self.tcb.tcpsequence = { self.thisside : random.randrange(1,(1<<32)-1),\
+            self.thatside : 0}
+
+        (ipsyn, tcpsyn) = tcptest.createfakerstfromtcb(self, self.tcb, self.thisside, self.thatside)   
+        tcptest.createwritepacket(self, self.tcb, ipsyn, tcpsyn, self.thisside, self.thatside)
+        
+        #TODO:We need wait 2MSL to be sure the receiver didn't answer 
+        #TODO:We need a socket method to listen for up to certain seconds.
+        (ipfinack, tcpfinack) = tcptest.receive(self,self.tcb, self.thisside, self.thatside) 
+
 
 if __name__ == '__main__':
     unittest.main()
-
-        
-        

==== //depot/projects/soc2008/bilouro_tcptest/src/scripts/tests/tcptest.py#5 (text+ko) ====

@@ -100,7 +100,7 @@
     self.failIf(tcp.reset <1, 'reset bit must be set') 
 
     if (tcp_sent.ack_number == None or tcp_sent.ack_number == 0):
-        #Assuming that "incoming segment" has *NO* ACK Field we need assert that:
+    #Assuming that "incoming segment" has *NO* ACK Field we need assert that:
 	#(1)has sequence number zero
         self.assertEqual(tcp.sequence, 0, \
             'The incoming segment has no ack, then the reset segment we expect must have sequence equal to zero')
@@ -134,6 +134,63 @@
 
     return (ip, tcp)
 
+def createrstfromreceivedtcp(self, tcb, from_, to, tcp_received):
+    """Create tcp rst flag expertise"""
+
+    (ip, tcp) = createip(self, tcb, from_, to)
+
+    #business
+    if (tcp_received.ack_number == None or tcp_received.ack_number == 0):
+        #Assuming that "incoming segment" has *NO* ACK Field we need:
+        #(1)sequence number must be zero
+        tcp.sequence = 0
+
+        #(2)ACK field must be set to the sum of the sequence number and segment length
+        calc_sum = len(tcp_received.getbytes()) + tcp_received.sequence  
+        tcp.ack_number = calc_sum
+
+    else: #(tcp_received.ack_number > 0): 
+        #Assuming that "incoming segment" has ACK Field we need:
+        #(1)sequence number must be set to the ACK received (Reset use sequence that receiver waits for)
+        tcp.sequence   = tcp_received.ack_number
+        #tcp.ack_number = tcp_received.sequence + 1 (it is not present at rfc)
+
+    return (ip, tcp)
+
+def createfakerstfromtcb(self, tcb, from_, to):
+    """Create tcp rst flag expertise"""
+
+    (ip, tcp) = createip(self, tcb, from_, to)
+
+    #business
+    if (tcb.tcpsequence[ to ] == None or tcb.tcpsequence[ to ] == 0):
+        #Assuming that "incoming segment" has *NO* ACK Field we need:
+        #(1)sequence number must be zero
+        tcp.sequence = 0
+
+        #(2)ACK field must be set to the sum of the sequence number and segment length
+        tcp.ack_number = 666 #FAKE'
+
+    else: #(tcp_received.ack_number > 0): 
+        #Assuming that "incoming segment" has ACK Field we need:
+        #(1)sequence number must be set to the ACK received (Reset use sequence that receiver waits for)
+        tcp.sequence   = tcb.tcpsequence[ from_ ]
+        #tcp.ack_number = tcb.tcpsequence[ to ] (it is not present at rfc)
+
+    return (ip, tcp)
+
+
+def createoutofwindowack(self, tcb, from_, to):
+    #setting an out of window acknowledgment
+    tcb.tcpsequence[ to ] += 9000000 #(value greater then window size)
+
+    #avoid overflow
+    if ( tcb.tcpsequence[ to ] > (1<<32)-1 ):   
+        tcb.tcpsequence[ to ] -= (1<<32)      #without -1
+
+    return createip(self, tcb, from_, to)
+
+
 def createfin(self, tcb, from_, to):
     """Create tcp fin flag expertise"""
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808020419.m724JcaJ032651>