Changes in uspace/srv/net/tcp/conn.c [3e2291a9:dc12262] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tcp/conn.c
r3e2291a9 rdc12262 44 44 #include <stdlib.h> 45 45 #include "conn.h" 46 #include "inet.h"47 46 #include "iqueue.h" 48 #include "pdu.h"49 #include "rqueue.h"50 47 #include "segment.h" 51 48 #include "seq_no.h" … … 60 57 #define TIME_WAIT_TIMEOUT (2*MAX_SEGMENT_LIFETIME) 61 58 62 /** List of all allocated connections */63 59 static LIST_INITIALIZE(conn_list); 64 60 /** Taken after tcp_conn_t lock */ 65 61 static FIBRIL_MUTEX_INITIALIZE(conn_list_lock); 66 /** Connection association map */67 62 static amap_t *amap; 68 /** Taken after tcp_conn_t lock */ 69 static FIBRIL_MUTEX_INITIALIZE(amap_lock); 70 71 /** Internal loopback configuration */ 72 tcp_lb_t tcp_conn_lb = tcp_lb_none; 73 74 static void tcp_conn_seg_process(tcp_conn_t *, tcp_segment_t *); 75 static void tcp_conn_tw_timer_set(tcp_conn_t *); 76 static void tcp_conn_tw_timer_clear(tcp_conn_t *); 77 static void tcp_transmit_segment(inet_ep2_t *, tcp_segment_t *); 78 static void tcp_conn_trim_seg_to_wnd(tcp_conn_t *, tcp_segment_t *); 79 static void tcp_reply_rst(inet_ep2_t *, tcp_segment_t *); 80 81 static tcp_tqueue_cb_t tcp_conn_tqueue_cb = { 82 .transmit_seg = tcp_transmit_segment 83 }; 63 64 static void tcp_conn_seg_process(tcp_conn_t *conn, tcp_segment_t *seg); 65 static void tcp_conn_tw_timer_set(tcp_conn_t *conn); 66 static void tcp_conn_tw_timer_clear(tcp_conn_t *conn); 84 67 85 68 /** Initialize connections. */ … … 95 78 96 79 return EOK; 97 }98 99 /** Finalize connections. */100 void tcp_conns_fini(void)101 {102 assert(list_empty(&conn_list));103 104 amap_destroy(amap);105 amap = NULL;106 80 } 107 81 … … 156 130 157 131 /* Initialize retransmission queue */ 158 if (tcp_tqueue_init(&conn->retransmit, conn, &tcp_conn_tqueue_cb) 159 != EOK) { 132 if (tcp_tqueue_init(&conn->retransmit, conn) != EOK) 160 133 goto error; 161 }162 134 163 135 tqueue_inited = true; … … 175 147 if (epp != NULL) 176 148 conn->ident = *epp; 177 178 fibril_mutex_lock(&conn_list_lock);179 list_append(&conn->link, &conn_list);180 fibril_mutex_unlock(&conn_list_lock);181 149 182 150 return conn; … … 213 181 { 214 182 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_conn_free(%p)", conn->name, conn); 215 216 assert(conn->mapped == false);217 183 tcp_tqueue_fini(&conn->retransmit); 218 219 fibril_mutex_lock(&conn_list_lock);220 list_remove(&conn->link);221 fibril_mutex_unlock(&conn_list_lock);222 184 223 185 if (conn->rcv_buf != NULL) … … 309 271 310 272 tcp_conn_addref(conn); 311 fibril_mutex_lock(& amap_lock);273 fibril_mutex_lock(&conn_list_lock); 312 274 313 275 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_add: conn=%p", conn); … … 316 278 if (rc != EOK) { 317 279 tcp_conn_delref(conn); 318 fibril_mutex_unlock(& amap_lock);280 fibril_mutex_unlock(&conn_list_lock); 319 281 return rc; 320 282 } 321 283 322 284 conn->ident = aepp; 323 conn->mapped = true;324 fibril_mutex_unlock(& amap_lock);285 list_append(&conn->link, &conn_list); 286 fibril_mutex_unlock(&conn_list_lock); 325 287 326 288 return EOK; … … 331 293 * Remove connection from the connection map. 332 294 */ 333 static void tcp_conn_remove(tcp_conn_t *conn) 334 { 335 if (!conn->mapped) 336 return; 337 338 fibril_mutex_lock(&amap_lock); 295 void tcp_conn_remove(tcp_conn_t *conn) 296 { 297 fibril_mutex_lock(&conn_list_lock); 339 298 amap_remove(amap, &conn->ident); 340 conn->mapped = false;341 fibril_mutex_unlock(& amap_lock);299 list_remove(&conn->link); 300 fibril_mutex_unlock(&conn_list_lock); 342 301 tcp_conn_delref(conn); 343 302 } … … 376 335 void tcp_conn_sync(tcp_conn_t *conn) 377 336 { 378 assert(fibril_mutex_is_locked(&conn->lock));379 380 337 /* XXX select ISS */ 381 338 conn->iss = 1; … … 431 388 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", epp); 432 389 433 fibril_mutex_lock(& amap_lock);390 fibril_mutex_lock(&conn_list_lock); 434 391 435 392 rc = amap_find_match(amap, epp, &arg); 436 393 if (rc != EOK) { 437 394 assert(rc == ENOENT); 438 fibril_mutex_unlock(& amap_lock);395 fibril_mutex_unlock(&conn_list_lock); 439 396 return NULL; 440 397 } … … 443 400 tcp_conn_addref(conn); 444 401 445 fibril_mutex_unlock(& amap_lock);402 fibril_mutex_unlock(&conn_list_lock); 446 403 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref: got conn=%p", 447 404 conn); … … 455 412 void tcp_conn_reset(tcp_conn_t *conn) 456 413 { 457 assert(fibril_mutex_is_locked(&conn->lock));458 459 414 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_conn_reset()", conn->name); 460 461 if (conn->cstate == st_closed)462 return;463 464 415 conn->reset = true; 465 416 tcp_conn_state_set(conn, st_closed); … … 914 865 return cp_done; 915 866 916 if (conn->fin_is_acked) { 917 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: FIN acked -> Time-Wait", 918 conn->name); 919 tcp_conn_state_set(conn, st_time_wait); 920 } 921 867 /* TODO */ 922 868 return cp_continue; 923 869 } … … 1116 1062 log_msg(LOG_DEFAULT, LVL_DEBUG, " - FIN found in segment."); 1117 1063 1064 /* Send ACK */ 1065 tcp_tqueue_ctrl_seg(conn, CTL_ACK); 1066 1118 1067 conn->rcv_nxt++; 1119 1068 conn->rcv_wnd--; 1120 1121 /* Send ACK */1122 tcp_tqueue_ctrl_seg(conn, CTL_ACK);1123 1069 1124 1070 /* Change connection state */ … … 1265 1211 1266 1212 /* Need to remove and re-insert connection with new identity */ 1267 fibril_mutex_lock(& amap_lock);1213 fibril_mutex_lock(&conn_list_lock); 1268 1214 1269 1215 if (inet_addr_is_any(&conn->ident.remote.addr)) … … 1281 1227 assert(rc == ENOMEM); 1282 1228 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory."); 1283 fibril_mutex_unlock(& amap_lock);1229 fibril_mutex_unlock(&conn_list_lock); 1284 1230 tcp_conn_unlock(conn); 1285 1231 return; … … 1287 1233 1288 1234 amap_remove(amap, &oldepp); 1289 fibril_mutex_unlock(& amap_lock);1235 fibril_mutex_unlock(&conn_list_lock); 1290 1236 1291 1237 conn->name = (char *) "a"; … … 1376 1322 * @param seg Segment 1377 1323 */ 1378 staticvoid tcp_conn_trim_seg_to_wnd(tcp_conn_t *conn, tcp_segment_t *seg)1324 void tcp_conn_trim_seg_to_wnd(tcp_conn_t *conn, tcp_segment_t *seg) 1379 1325 { 1380 1326 uint32_t left, right; … … 1400 1346 } 1401 1347 1402 /** Transmit segment over network.1403 *1404 * @param epp Endpoint pair with source and destination information1405 * @param seg Segment (ownership retained by caller)1406 */1407 static void tcp_transmit_segment(inet_ep2_t *epp, tcp_segment_t *seg)1408 {1409 tcp_pdu_t *pdu;1410 tcp_segment_t *dseg;1411 inet_ep2_t rident;1412 1413 log_msg(LOG_DEFAULT, LVL_DEBUG,1414 "tcp_transmit_segment(l:(%u),f:(%u), %p)",1415 epp->local.port, epp->remote.port, seg);1416 1417 log_msg(LOG_DEFAULT, LVL_DEBUG, "SEG.SEQ=%" PRIu32 ", SEG.WND=%" PRIu32,1418 seg->seq, seg->wnd);1419 1420 tcp_segment_dump(seg);1421 1422 if (tcp_conn_lb == tcp_lb_segment) {1423 /* Loop back segment */1424 // tcp_ncsim_bounce_seg(sp, seg);1425 1426 /* Reverse the identification */1427 tcp_ep2_flipped(epp, &rident);1428 1429 /* Insert segment back into rqueue */1430 dseg = tcp_segment_dup(seg);1431 tcp_rqueue_insert_seg(&rident, dseg);1432 return;1433 }1434 1435 if (tcp_pdu_encode(epp, seg, &pdu) != EOK) {1436 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");1437 return;1438 }1439 1440 if (tcp_conn_lb == tcp_lb_pdu) {1441 /* Loop back PDU */1442 if (tcp_pdu_decode(pdu, &rident, &dseg) != EOK) {1443 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");1444 tcp_pdu_delete(pdu);1445 return;1446 }1447 1448 tcp_pdu_delete(pdu);1449 1450 /* Insert decoded segment into rqueue */1451 tcp_rqueue_insert_seg(&rident, dseg);1452 return;1453 }1454 1455 tcp_transmit_pdu(pdu);1456 tcp_pdu_delete(pdu);1457 }1458 1459 1348 /** Compute flipped endpoint pair for response. 1460 1349 * … … 1475 1364 * @param seg Incoming segment 1476 1365 */ 1477 staticvoid tcp_reply_rst(inet_ep2_t *epp, tcp_segment_t *seg)1366 void tcp_reply_rst(inet_ep2_t *epp, tcp_segment_t *seg) 1478 1367 { 1479 1368 tcp_segment_t *rseg;
Note:
See TracChangeset
for help on using the changeset viewer.