]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
fixed bug #35435: No pcb state check before adding it to time-wait queue while closing
authorgoldsimon <goldsimon@gmx.de>
Sat, 11 Feb 2012 17:15:17 +0000 (18:15 +0100)
committergoldsimon <goldsimon@gmx.de>
Sat, 11 Feb 2012 17:15:17 +0000 (18:15 +0100)
CHANGELOG
src/core/tcp.c

index 5e935d199a8cf56d232d19ec023a974671dffb80..03ac6ab32a36d93f227e50e714fe41a39fb05029 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -76,6 +76,10 @@ HISTORY
 
  ++ Bugfixes:
 
+  2012-02-11: Simon Goldschmidt
+  * tcp.c: fixed bug #35435: No pcb state check before adding it to time-wait
+    queue while closing
+
   2012-01-22: Simon Goldschmidt
   * tcp.c, tcp_in.c: fixed bug #35305: pcb may be freed too early on shutdown(WR)
 
index 9adba7cb82d9d1969d16623870839e6802e26d1d..3bcd41a366dc419b660024a2fe7fdacd87709763 100644 (file)
@@ -174,7 +174,7 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
 {
   err_t err;
 
-  if (rst_on_unacked_data && (pcb->state != LISTEN)) {
+  if (rst_on_unacked_data && ((pcb->state == ESTABLISHED) || (pcb->state == CLOSE_WAIT))) {
     if ((pcb->refused_data != NULL) || (pcb->rcv_wnd != TCP_WND)) {
       /* Not all data received by application, send RST to tell the remote
          side about this. */
@@ -186,14 +186,15 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
                pcb->local_port, pcb->remote_port, PCB_ISIPV6(pcb));
 
       tcp_pcb_purge(pcb);
-
-      /* TODO: to which state do we move now? */
-
-      /* move to TIME_WAIT since we close actively */
       TCP_RMV_ACTIVE(pcb);
-      pcb->state = TIME_WAIT;
-      TCP_REG(&tcp_tw_pcbs, pcb);
-
+      if (pcb->state == ESTABLISHED) {
+        /* move to TIME_WAIT since we close actively */
+        pcb->state = TIME_WAIT;
+        TCP_REG(&tcp_tw_pcbs, pcb);
+      } else {
+        /* CLOSE_WAIT: deallocate the pcb since we already sent a RST for it */
+        memp_free(MEMP_TCP_PCB, pcb);
+      }
       return ERR_OK;
     }
   }