Changeset 9520af7 in mainline
- Timestamp:
- 2017-09-12T15:48:01Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1d40c93d
- Parents:
- 0a1e7e4
- Location:
- uspace/srv/net/tcp
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tcp/conn.c
r0a1e7e4 r9520af7 47 47 #include "iqueue.h" 48 48 #include "pdu.h" 49 #include "rqueue.h" 49 50 #include "segment.h" 50 51 #include "seq_no.h" … … 65 66 /** Connection association map */ 66 67 static amap_t *amap; 68 /** Taken after tcp_conn_t lock */ 67 69 static FIBRIL_MUTEX_INITIALIZE(amap_lock); 70 71 /** Internal loopback configuration */ 72 tcp_lb_t tcp_conn_lb = tcp_lb_none; 68 73 69 74 static void tcp_conn_seg_process(tcp_conn_t *, tcp_segment_t *); … … 71 76 static void tcp_conn_tw_timer_clear(tcp_conn_t *); 72 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 *); 73 80 74 81 static tcp_tqueue_cb_t tcp_conn_tqueue_cb = { … … 324 331 * Remove connection from the connection map. 325 332 */ 326 void tcp_conn_remove(tcp_conn_t *conn)333 static void tcp_conn_remove(tcp_conn_t *conn) 327 334 { 328 335 if (!conn->mapped) … … 369 376 void tcp_conn_sync(tcp_conn_t *conn) 370 377 { 378 assert(fibril_mutex_is_locked(&conn->lock)); 379 371 380 /* XXX select ISS */ 372 381 conn->iss = 1; … … 1358 1367 * @param seg Segment 1359 1368 */ 1360 void tcp_conn_trim_seg_to_wnd(tcp_conn_t *conn, tcp_segment_t *seg)1369 static void tcp_conn_trim_seg_to_wnd(tcp_conn_t *conn, tcp_segment_t *seg) 1361 1370 { 1362 1371 uint32_t left, right; … … 1382 1391 } 1383 1392 1393 /** Transmit segment over network. 1394 * 1395 * @param epp Endpoint pair with source and destination information 1396 * @param seg Segment (ownership retained by caller) 1397 */ 1384 1398 static void tcp_transmit_segment(inet_ep2_t *epp, tcp_segment_t *seg) 1385 1399 { 1400 tcp_pdu_t *pdu; 1401 tcp_segment_t *dseg; 1402 inet_ep2_t rident; 1403 1386 1404 log_msg(LOG_DEFAULT, LVL_DEBUG, 1387 1405 "tcp_transmit_segment(l:(%u),f:(%u), %p)", … … 1393 1411 tcp_segment_dump(seg); 1394 1412 1395 // tcp_rqueue_bounce_seg(sp, seg); 1396 // tcp_ncsim_bounce_seg(sp, seg); 1397 1398 tcp_pdu_t *pdu; 1413 if (tcp_conn_lb == tcp_lb_segment) { 1414 /* Loop back segment */ 1415 // tcp_ncsim_bounce_seg(sp, seg); 1416 1417 /* Reverse the identification */ 1418 tcp_ep2_flipped(epp, &rident); 1419 1420 /* Insert segment back into rqueue */ 1421 dseg = tcp_segment_dup(seg); 1422 tcp_rqueue_insert_seg(&rident, dseg); 1423 return; 1424 } 1399 1425 1400 1426 if (tcp_pdu_encode(epp, seg, &pdu) != EOK) { … … 1403 1429 } 1404 1430 1431 if (tcp_conn_lb == tcp_lb_pdu) { 1432 /* Loop back PDU */ 1433 if (tcp_pdu_decode(pdu, &rident, &dseg) != EOK) { 1434 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped."); 1435 tcp_pdu_delete(pdu); 1436 return; 1437 } 1438 1439 tcp_pdu_delete(pdu); 1440 1441 /* Insert decoded segment into rqueue */ 1442 tcp_rqueue_insert_seg(&rident, dseg); 1443 return; 1444 } 1445 1405 1446 tcp_transmit_pdu(pdu); 1406 1447 tcp_pdu_delete(pdu); … … 1425 1466 * @param seg Incoming segment 1426 1467 */ 1427 void tcp_reply_rst(inet_ep2_t *epp, tcp_segment_t *seg)1468 static void tcp_reply_rst(inet_ep2_t *epp, tcp_segment_t *seg) 1428 1469 { 1429 1470 tcp_segment_t *rseg; -
uspace/srv/net/tcp/conn.h
r0a1e7e4 r9520af7 45 45 extern void tcp_conn_delete(tcp_conn_t *); 46 46 extern int tcp_conn_add(tcp_conn_t *); 47 extern void tcp_conn_remove(tcp_conn_t *);48 47 extern void tcp_conn_reset(tcp_conn_t *conn); 49 48 extern void tcp_conn_sync(tcp_conn_t *); 50 49 extern void tcp_conn_fin_sent(tcp_conn_t *); 51 extern void tcp_conn_ack_of_fin_rcvd(tcp_conn_t *);52 50 extern tcp_conn_t *tcp_conn_find_ref(inet_ep2_t *); 53 51 extern void tcp_conn_addref(tcp_conn_t *); … … 58 56 extern void tcp_conn_segment_arrived(tcp_conn_t *, inet_ep2_t *, 59 57 tcp_segment_t *); 60 extern void tcp_conn_trim_seg_to_wnd(tcp_conn_t *, tcp_segment_t *);61 58 extern void tcp_unexpected_segment(inet_ep2_t *, tcp_segment_t *); 62 59 extern void tcp_ep2_flipped(inet_ep2_t *, inet_ep2_t *); 63 extern void tcp_reply_rst(inet_ep2_t *, tcp_segment_t *); 60 61 extern tcp_lb_t tcp_conn_lb; 64 62 65 63 #endif -
uspace/srv/net/tcp/ncsim.c
r0a1e7e4 r9520af7 73 73 tcp_squeue_entry_t *sqe; 74 74 tcp_squeue_entry_t *old_qe; 75 inet_ep2_t rident; 75 76 link_t *link; 76 77 77 78 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_ncsim_bounce_seg()"); 78 tcp_rqueue_bounce_seg(epp, seg); 79 tcp_ep2_flipped(epp, &rident); 80 tcp_rqueue_insert_seg(&rident, seg); 79 81 return; 80 82 … … 125 127 link_t *link; 126 128 tcp_squeue_entry_t *sqe; 129 inet_ep2_t rident; 127 130 int rc; 128 131 … … 148 151 149 152 log_msg(LOG_DEFAULT, LVL_DEBUG, "NCSim - End Sleep"); 150 tcp_rqueue_bounce_seg(&sqe->epp, sqe->seg); 153 tcp_ep2_flipped(&sqe->epp, &rident); 154 tcp_rqueue_insert_seg(&rident, sqe->seg); 151 155 free(sqe); 152 156 } -
uspace/srv/net/tcp/rqueue.c
r0a1e7e4 r9520af7 43 43 #include <fibril_synch.h> 44 44 #include "conn.h" 45 #include "pdu.h"46 45 #include "rqueue.h" 47 46 #include "segment.h" 48 47 #include "tcp_type.h" 49 48 #include "ucall.h" 50 51 /** Transcode bounced segments.52 *53 * If defined, segments bounced via the internal debugging loopback will54 * be encoded to a PDU and the decoded. Otherwise they will be bounced back55 * directly without passing the encoder-decoder.56 */57 #define BOUNCE_TRANSCODE58 49 59 50 static prodcons_t rqueue; … … 87 78 } 88 79 89 /** Bounce segment directy into receive queue without constructing the PDU.90 *91 * This is for testing purposes only.92 *93 * @param sp Endpoint pair, oriented for transmission94 * @param seg Segment95 */96 void tcp_rqueue_bounce_seg(inet_ep2_t *epp, tcp_segment_t *seg)97 {98 inet_ep2_t rident;99 100 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_rqueue_bounce_seg()");101 102 #ifdef BOUNCE_TRANSCODE103 tcp_pdu_t *pdu;104 tcp_segment_t *dseg;105 106 if (tcp_pdu_encode(epp, seg, &pdu) != EOK) {107 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");108 return;109 }110 111 if (tcp_pdu_decode(pdu, &rident, &dseg) != EOK) {112 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped.");113 return;114 }115 116 tcp_pdu_delete(pdu);117 118 /** Insert decoded segment into rqueue */119 tcp_rqueue_insert_seg(&rident, dseg);120 tcp_segment_delete(seg);121 #else122 /* Reverse the identification */123 tcp_ep2_flipped(epp, &rident);124 125 /* Insert segment back into rqueue */126 tcp_rqueue_insert_seg(&rident, seg);127 #endif128 }129 130 80 /** Insert segment into receive queue. 131 81 * 132 82 * @param epp Endpoint pair, oriented for reception 133 * @param seg Segment 83 * @param seg Segment (ownership transferred to rqueue) 134 84 */ 135 85 void tcp_rqueue_insert_seg(inet_ep2_t *epp, tcp_segment_t *seg) -
uspace/srv/net/tcp/rqueue.h
r0a1e7e4 r9520af7 42 42 extern void tcp_rqueue_fibril_start(void); 43 43 extern void tcp_rqueue_fini(void); 44 extern void tcp_rqueue_bounce_seg(inet_ep2_t *, tcp_segment_t *);45 44 extern void tcp_rqueue_insert_seg(inet_ep2_t *, tcp_segment_t *); 46 45 -
uspace/srv/net/tcp/tcp_type.h
r0a1e7e4 r9520af7 379 379 } tcp_client_t; 380 380 381 /** Internal loopback type */ 382 typedef enum { 383 /** No loopback */ 384 tcp_lb_none, 385 /** Segment loopback */ 386 tcp_lb_segment, 387 /** PDU loopback */ 388 tcp_lb_pdu 389 } tcp_lb_t; 390 381 391 #endif 382 392 -
uspace/srv/net/tcp/test/conn.c
r0a1e7e4 r9520af7 33 33 34 34 #include "../conn.h" 35 #include "../rqueue.h" 36 #include "../ucall.h" 35 37 36 38 PCUT_INIT 37 39 38 40 PCUT_TEST_SUITE(conn); 41 42 static tcp_rqueue_cb_t test_rqueue_cb = { 43 .seg_received = tcp_as_segment_arrived 44 }; 39 45 40 46 PCUT_TEST_BEFORE … … 48 54 rc = tcp_conns_init(); 49 55 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 56 57 tcp_rqueue_init(&test_rqueue_cb); 58 tcp_rqueue_fibril_start(); 50 59 } 51 60 52 61 PCUT_TEST_AFTER 53 62 { 63 tcp_rqueue_fini(); 54 64 tcp_conns_fini(); 55 65 } … … 71 81 } 72 82 73 /** Test adding, finding and removing a connection */74 PCUT_TEST(add_find_ remove)83 /** Test adding, finding and deleting a connection */ 84 PCUT_TEST(add_find_delete) 75 85 { 76 86 tcp_conn_t *conn, *cfound; … … 101 111 } 102 112 113 /** Test trying to connect to endpoint that sends RST back */ 114 PCUT_TEST(connect_rst) 115 { 116 tcp_conn_t *conn; 117 inet_ep2_t epp; 118 int rc; 119 120 tcp_conn_lb = tcp_lb_segment; 121 122 inet_ep2_init(&epp); 123 inet_addr(&epp.local.addr, 127, 0, 0, 1); 124 inet_addr(&epp.remote.addr, 127, 0, 0, 1); 125 epp.remote.port = inet_port_user_lo; 126 127 conn = tcp_conn_new(&epp); 128 PCUT_ASSERT_NOT_NULL(conn); 129 130 rc = tcp_conn_add(conn); 131 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 132 133 PCUT_ASSERT_INT_EQUALS(st_listen, conn->cstate); 134 135 tcp_conn_lock(conn); 136 tcp_conn_sync(conn); 137 PCUT_ASSERT_INT_EQUALS(st_syn_sent, conn->cstate); 138 139 while (conn->cstate == st_syn_sent) 140 fibril_condvar_wait(&conn->cstate_cv, &conn->lock); 141 142 PCUT_ASSERT_INT_EQUALS(st_closed, conn->cstate); 143 144 tcp_conn_unlock(conn); 145 tcp_conn_delete(conn); 146 } 147 103 148 PCUT_EXPORT(conn); -
uspace/srv/net/tcp/tqueue.c
r0a1e7e4 r9520af7 106 106 tcp_segment_t *seg; 107 107 108 assert(fibril_mutex_is_locked(&conn->lock)); 109 108 110 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_tqueue_ctrl_seg(%p, %u)", conn, ctrl); 109 111 … … 117 119 tcp_segment_t *rt_seg; 118 120 tcp_tqueue_entry_t *tqe; 121 122 assert(fibril_mutex_is_locked(&conn->lock)); 119 123 120 124 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_tqueue_seg(%p, %p)", conn->name, conn, … … 366 370 static void tcp_tqueue_timer_set(tcp_conn_t *conn) 367 371 { 372 assert(fibril_mutex_is_locked(&conn->lock)); 373 368 374 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set() begin", conn->name); 369 375 … … 381 387 static void tcp_tqueue_timer_clear(tcp_conn_t *conn) 382 388 { 389 assert(fibril_mutex_is_locked(&conn->lock)); 390 383 391 log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear() begin", conn->name); 384 392
Note:
See TracChangeset
for help on using the changeset viewer.