Some re-formatting of uip.c.

This commit is contained in:
Richard Barry 2010-09-10 18:45:22 +00:00
parent 2641267c85
commit c7fbe1d601

View file

@ -19,13 +19,13 @@
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote * 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior * products derived from this software without specific prior
* written permission. * written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -712,7 +712,7 @@ void uip_process( u8_t flag )
uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
/* Check if we were invoked because of a poll request for a /* Check if we were invoked because of a poll request for a
particular connection. */ particular connection. */
if( flag == UIP_POLL_REQUEST ) if( flag == UIP_POLL_REQUEST )
{ {
if( (uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED && !uip_outstanding(uip_connr) ) if( (uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED && !uip_outstanding(uip_connr) )
@ -809,7 +809,7 @@ void uip_process( u8_t flag )
{ {
case UIP_SYN_RCVD: case UIP_SYN_RCVD:
/* In the SYN_RCVD state, we should retransmit our /* In the SYN_RCVD state, we should retransmit our
SYNACK. */ SYNACK. */
goto tcp_send_synack; goto tcp_send_synack;
#if UIP_ACTIVE_OPEN #if UIP_ACTIVE_OPEN
@ -895,24 +895,24 @@ void uip_process( u8_t flag )
#endif /* UIP_CONF_IPV6 */ #endif /* UIP_CONF_IPV6 */
/* Check the size of the packet. If the size reported to us in /* Check the size of the packet. If the size reported to us in
uip_len is smaller the size reported in the IP header, we assume uip_len is smaller the size reported in the IP header, we assume
that the packet has been corrupted in transit. If the size of that the packet has been corrupted in transit. If the size of
uip_len is larger than the size reported in the IP packet header, uip_len is larger than the size reported in the IP packet header,
the packet has been padded and we set uip_len to the correct the packet has been padded and we set uip_len to the correct
value.. */ value.. */
if( (BUF->len[ 0 ] << 8) + BUF->len[ 1 ] <= uip_len ) if( (BUF->len[ 0 ] << 8) + BUF->len[ 1 ] <= uip_len )
{ {
uip_len = ( BUF->len[ 0 ] << 8 ) + BUF->len[ 1 ]; uip_len = ( BUF->len[ 0 ] << 8 ) + BUF->len[ 1 ];
#if UIP_CONF_IPV6 #if UIP_CONF_IPV6
/* The length reported in the IPv6 header is the /* The length reported in the IPv6 header is the
length of the payload that follows the length of the payload that follows the
header. However, uIP uses the uip_len variable header. However, uIP uses the uip_len variable
for holding the size of the entire packet, for holding the size of the entire packet,
including the IP header. For IPv4 this is not a including the IP header. For IPv4 this is not a
problem as the length field in the IPv4 header problem as the length field in the IPv4 header
contains the length of the entire packet. But contains the length of the entire packet. But
for IPv6 we need to add the size of the IPv6 for IPv6 we need to add the size of the IPv6
header (40 bytes). */ header (40 bytes). */
uip_len += 40; uip_len += 40;
#endif /* UIP_CONF_IPV6 */ #endif /* UIP_CONF_IPV6 */
} }
@ -1313,9 +1313,9 @@ udp_send:
} }
/* If we didn't find and active connection that expected the packet, /* If we didn't find and active connection that expected the packet,
either this packet is an old duplicate, or this is a SYN packet either this packet is an old duplicate, or this is a SYN packet
destined for a connection in LISTEN. If the SYN flag isn't set, destined for a connection in LISTEN. If the SYN flag isn't set,
it is an old packet and we send a RST. */ it is an old packet and we send a RST. */
if( (BUF->flags & TCP_CTL) != TCP_SYN ) if( (BUF->flags & TCP_CTL) != TCP_SYN )
{ {
goto reset; goto reset;
@ -1366,8 +1366,8 @@ reset:
BUF->ackno[ 0 ] = c; BUF->ackno[ 0 ] = c;
/* We also have to increase the sequence number we are /* We also have to increase the sequence number we are
acknowledging. If the least significant byte overflowed, we need acknowledging. If the least significant byte overflowed, we need
to propagate the carry to the other bytes as well. */ to propagate the carry to the other bytes as well. */
if( ++BUF->ackno[ 3 ] == 0 ) if( ++BUF->ackno[ 3 ] == 0 )
{ {
if( ++BUF->ackno[ 2 ] == 0 ) if( ++BUF->ackno[ 2 ] == 0 )
@ -1392,15 +1392,15 @@ reset:
goto tcp_send_noconn; goto tcp_send_noconn;
/* This label will be jumped to if we matched the incoming packet /* This label will be jumped to if we matched the incoming packet
with a connection in LISTEN. In that case, we should create a new with a connection in LISTEN. In that case, we should create a new
connection and send a SYNACK in return. */ connection and send a SYNACK in return. */
found_listen: found_listen:
/* First we check if there are any connections avaliable. Unused /* First we check if there are any connections avaliable. Unused
connections are kept in the same table as used connections, but connections are kept in the same table as used connections, but
unused ones have the tcpstate set to CLOSED. Also, connections in unused ones have the tcpstate set to CLOSED. Also, connections in
TIME_WAIT are kept track of and we'll use the oldest one if no TIME_WAIT are kept track of and we'll use the oldest one if no
CLOSED connections are found. Thanks to Eddie C. Dost for a very CLOSED connections are found. Thanks to Eddie C. Dost for a very
nice algorithm for the TIME_WAIT search. */ nice algorithm for the TIME_WAIT search. */
uip_connr = 0; uip_connr = 0;
for( c = 0; c < UIP_CONNS; ++c ) for( c = 0; c < UIP_CONNS; ++c )
{ {
@ -1506,7 +1506,7 @@ tcp_send_syn:
#endif /* UIP_ACTIVE_OPEN */ #endif /* UIP_ACTIVE_OPEN */
/* We send out the TCP Maximum Segment Size option with our /* We send out the TCP Maximum Segment Size option with our
SYNACK. */ SYNACK. */
BUF->optdata[ 0 ] = TCP_OPT_MSS; BUF->optdata[ 0 ] = TCP_OPT_MSS;
BUF->optdata[ 1 ] = TCP_OPT_MSS_LEN; BUF->optdata[ 1 ] = TCP_OPT_MSS_LEN;
BUF->optdata[ 2 ] = ( UIP_TCP_MSS ) / 256; BUF->optdata[ 2 ] = ( UIP_TCP_MSS ) / 256;
@ -1521,9 +1521,9 @@ found:
uip_flags = 0; uip_flags = 0;
/* We do a very naive form of TCP reset processing; we just accept /* We do a very naive form of TCP reset processing; we just accept
any RST and kill our connection. We should in fact check if the any RST and kill our connection. We should in fact check if the
sequence number of this reset is wihtin our advertised window sequence number of this reset is wihtin our advertised window
before we accept the reset. */ before we accept the reset. */
if( BUF->flags & TCP_RST ) if( BUF->flags & TCP_RST )
{ {
uip_connr->tcpstateflags = UIP_CLOSED; uip_connr->tcpstateflags = UIP_CLOSED;
@ -1534,17 +1534,17 @@ found:
} }
/* Calculate the length of the data, if the application has sent /* Calculate the length of the data, if the application has sent
any data to us. */ any data to us. */
c = ( BUF->tcpoffset >> 4 ) << 2; c = ( BUF->tcpoffset >> 4 ) << 2;
/* uip_len will contain the length of the actual TCP data. This is /* uip_len will contain the length of the actual TCP data. This is
calculated by subtracing the length of the TCP header (in calculated by subtracing the length of the TCP header (in
c) and the length of the IP header (20 bytes). */ c) and the length of the IP header (20 bytes). */
uip_len = uip_len - c - UIP_IPH_LEN; uip_len = uip_len - c - UIP_IPH_LEN;
/* First, check if the sequence number of the incoming packet is /* First, check if the sequence number of the incoming packet is
what we're expecting next. If not, we send out an ACK with the what we're expecting next. If not, we send out an ACK with the
correct numbers in. */ correct numbers in. */
if( !(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) ) if( !(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) )
{ {
if if
@ -1563,9 +1563,9 @@ found:
} }
/* Next, check if the incoming segment acknowledges any outstanding /* Next, check if the incoming segment acknowledges any outstanding
data. If so, we update the sequence number, reset the length of data. If so, we update the sequence number, reset the length of
the outstanding data, calculate RTT estimations, and reset the the outstanding data, calculate RTT estimations, and reset the
retransmission timer. */ retransmission timer. */
if( (BUF->flags & TCP_ACK) && uip_outstanding(uip_connr) ) if( (BUF->flags & TCP_ACK) && uip_outstanding(uip_connr) )
{ {
uip_add32( uip_connr->snd_nxt, uip_connr->len ); uip_add32( uip_connr->snd_nxt, uip_connr->len );
@ -1623,9 +1623,9 @@ found:
ESTABLISHED to LAST_ACK). */ ESTABLISHED to LAST_ACK). */
case UIP_SYN_RCVD: case UIP_SYN_RCVD:
/* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and /* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and
we are waiting for an ACK that acknowledges the data we sent we are waiting for an ACK that acknowledges the data we sent
out the last time. Therefore, we want to have the UIP_ACKDATA out the last time. Therefore, we want to have the UIP_ACKDATA
flag set. If so, we enter the ESTABLISHED state. */ flag set. If so, we enter the ESTABLISHED state. */
if( uip_flags & UIP_ACKDATA ) if( uip_flags & UIP_ACKDATA )
{ {
uip_connr->tcpstateflags = UIP_ESTABLISHED; uip_connr->tcpstateflags = UIP_ESTABLISHED;
@ -1864,22 +1864,22 @@ appsend:
if( uip_connr->len == 0 ) if( uip_connr->len == 0 )
{ {
/* The application cannot send more than what is allowed by /* The application cannot send more than what is allowed by
the mss (the minumum of the MSS and the available the mss (the minumum of the MSS and the available
window). */ window). */
if( uip_slen > uip_connr->mss ) if( uip_slen > uip_connr->mss )
{ {
uip_slen = uip_connr->mss; uip_slen = uip_connr->mss;
} }
/* Remember how much data we send out now so that we know /* Remember how much data we send out now so that we know
when everything has been acknowledged. */ when everything has been acknowledged. */
uip_connr->len = uip_slen; uip_connr->len = uip_slen;
} }
else else
{ {
/* If the application already had unacknowledged data, we /* If the application already had unacknowledged data, we
make sure that the application does not send (i.e., make sure that the application does not send (i.e.,
retransmit) out more than it previously sent out. */ retransmit) out more than it previously sent out. */
uip_slen = uip_connr->len; uip_slen = uip_connr->len;
} }
} }
@ -1889,7 +1889,7 @@ apprexmit:
uip_appdata = uip_sappdata; uip_appdata = uip_sappdata;
/* If the application has data to be sent, or if the incoming /* If the application has data to be sent, or if the incoming
packet had new data in it, we must send out a packet. */ packet had new data in it, we must send out a packet. */
if( uip_slen > 0 && uip_connr->len > 0 ) if( uip_slen > 0 && uip_connr->len > 0 )
{ {
/* Add the length of the IP and TCP headers. */ /* Add the length of the IP and TCP headers. */
@ -2004,7 +2004,7 @@ apprexmit:
goto drop; goto drop;
/* We jump here when we are ready to send the packet, and just want /* We jump here when we are ready to send the packet, and just want
to set the appropriate TCP sequence numbers in the TCP header. */ to set the appropriate TCP sequence numbers in the TCP header. */
tcp_send_ack: tcp_send_ack:
BUF->flags = TCP_ACK; BUF->flags = TCP_ACK;
@ -2015,9 +2015,9 @@ tcp_send_noopts:
BUF->tcpoffset = ( UIP_TCPH_LEN / 4 ) << 4; BUF->tcpoffset = ( UIP_TCPH_LEN / 4 ) << 4;
/* We're done with the input processing. We are now ready to send a /* We're done with the input processing. We are now ready to send a
reply. Our job is to fill in all the fields of the TCP and IP reply. Our job is to fill in all the fields of the TCP and IP
headers before calculating the checksum and finally send the headers before calculating the checksum and finally send the
packet. */ packet. */
tcp_send: tcp_send:
BUF->ackno[ 0 ] = uip_connr->rcv_nxt[ 0 ]; BUF->ackno[ 0 ] = uip_connr->rcv_nxt[ 0 ];
BUF->ackno[ 1 ] = uip_connr->rcv_nxt[ 1 ]; BUF->ackno[ 1 ] = uip_connr->rcv_nxt[ 1 ];