Changeset 2f19103 in mainline for uspace/srv/net/tcp
- Timestamp:
- 2015-05-22T07:21:37Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 58e9dec
- Parents:
- bf7587b0
- Location:
- uspace/srv/net/tcp
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tcp/conn.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 #include <stdbool.h> 39 39 #include <errno.h> 40 #include <inet/endpoint.h> 40 41 #include <io/log.h> 41 42 #include <macros.h> … … 64 65 /** Create new connection structure. 65 66 * 66 * @param lsock Local socket (will be deeply copied) 67 * @param fsock Foreign socket (will be deeply copied) 67 * @param epp Endpoint pair (will be deeply copied) 68 68 * @return New connection or NULL 69 69 */ 70 tcp_conn_t *tcp_conn_new( tcp_sock_t *lsock, tcp_sock_t *fsock)70 tcp_conn_t *tcp_conn_new(inet_ep2_t *epp) 71 71 { 72 72 tcp_conn_t *conn = NULL; … … 128 128 conn->ap = ap_passive; 129 129 conn->fin_is_acked = false; 130 conn->ident.local = *lsock; 131 if (fsock != NULL) 132 conn->ident.foreign = *fsock; 130 if (epp != NULL) 131 conn->ident = *epp; 133 132 134 133 return conn; … … 335 334 } 336 335 337 /** Match socket with pattern. */338 static bool tcp_ socket_match(tcp_sock_t *sock, tcp_sock_t *patt)336 /** Match endpoint with pattern. */ 337 static bool tcp_ep_match(inet_ep_t *ep, inet_ep_t *patt) 339 338 { 340 339 log_msg(LOG_DEFAULT, LVL_DEBUG2, 341 "tcp_ socket_match(sock=(%u), pat=(%u))", sock->port, patt->port);342 340 "tcp_ep_match(ep=(%u), pat=(%u))", ep->port, patt->port); 341 343 342 if ((!inet_addr_is_any(&patt->addr)) && 344 (!inet_addr_compare(&patt->addr, & sock->addr)))343 (!inet_addr_compare(&patt->addr, &ep->addr))) 345 344 return false; 346 345 347 346 if ((patt->port != TCP_PORT_ANY) && 348 (patt->port != sock->port))347 (patt->port != ep->port)) 349 348 return false; 350 349 … … 354 353 } 355 354 356 /** Match socket pair with pattern. */357 static bool tcp_ sockpair_match(tcp_sockpair_t *sp, tcp_sockpair_t *pattern)358 { 359 log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_ sockpair_match(%p, %p)", sp, pattern);360 361 if (!tcp_ socket_match(&sp->local, &pattern->local))355 /** Match endpoint pair with pattern. */ 356 static bool tcp_ep2_match(inet_ep2_t *epp, inet_ep2_t *pattern) 357 { 358 log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_ep2_match(%p, %p)", epp, pattern); 359 360 if (!tcp_ep_match(&epp->local, &pattern->local)) 362 361 return false; 363 362 364 if (!tcp_ socket_match(&sp->foreign, &pattern->foreign))363 if (!tcp_ep_match(&epp->remote, &pattern->remote)) 365 364 return false; 366 365 … … 368 367 } 369 368 370 /** Find connection structure for specified socket pair.371 * 372 * A connection is uniquely identified by a socket pair. Look up our373 * connection map and return connection structure based on socket pair.369 /** Find connection structure for specified endpoint pair. 370 * 371 * A connection is uniquely identified by a endpoint pair. Look up our 372 * connection map and return connection structure based on endpoint pair. 374 373 * The connection reference count is bumped by one. 375 374 * 376 * @param sp Socket pair375 * @param epp Endpoint pair 377 376 * @return Connection structure or NULL if not found. 378 377 */ 379 tcp_conn_t *tcp_conn_find_ref( tcp_sockpair_t *sp)380 { 381 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", sp);382 378 tcp_conn_t *tcp_conn_find_ref(inet_ep2_t *epp) 379 { 380 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", epp); 381 383 382 log_msg(LOG_DEFAULT, LVL_DEBUG2, "compare conn (f:(%u), l:(%u))", 384 sp->foreign.port, sp->local.port);385 383 epp->remote.port, epp->local.port); 384 386 385 fibril_mutex_lock(&conn_list_lock); 387 386 388 387 list_foreach(conn_list, link, tcp_conn_t, conn) { 389 tcp_sockpair_t *csp = &conn->ident;390 388 inet_ep2_t *cepp = &conn->ident; 389 391 390 log_msg(LOG_DEFAULT, LVL_DEBUG2, " - with (f:(%u), l:(%u))", 392 c sp->foreign.port, csp->local.port);393 394 if (tcp_ sockpair_match(sp, csp)) {391 cepp->remote.port, cepp->local.port); 392 393 if (tcp_ep2_match(epp, cepp)) { 395 394 tcp_conn_addref(conn); 396 395 fibril_mutex_unlock(&conn_list_lock); … … 398 397 } 399 398 } 400 399 401 400 fibril_mutex_unlock(&conn_list_lock); 402 401 return NULL; … … 1270 1269 } 1271 1270 1272 /** Handle unexpected segment received on a socket pair.1271 /** Handle unexpected segment received on an endpoint pair. 1273 1272 * 1274 1273 * We reply with an RST unless the received segment has RST. 1275 1274 * 1276 * @param sp Socket pair which received the segment1275 * @param sp Endpoint pair which received the segment 1277 1276 * @param seg Unexpected segment 1278 1277 */ 1279 void tcp_unexpected_segment(tcp_sockpair_t *sp, tcp_segment_t *seg) 1280 { 1281 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_unexpected_segment(%p, %p)", sp, seg); 1278 void tcp_unexpected_segment(inet_ep2_t *epp, tcp_segment_t *seg) 1279 { 1280 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_unexpected_segment(%p, %p)", epp, 1281 seg); 1282 1282 1283 1283 if ((seg->ctrl & CTL_RST) == 0) 1284 tcp_reply_rst( sp, seg);1285 } 1286 1287 /** Compute flipped socket pair for response.1288 * 1289 * Flipped socket pair has local and foreign sockets exchanged.1290 * 1291 * @param sp Socket pair1292 * @param f sp Place to store flipped socket pair1293 */ 1294 void tcp_ sockpair_flipped(tcp_sockpair_t *sp, tcp_sockpair_t *fsp)1295 { 1296 f sp->local = sp->foreign;1297 f sp->foreign = sp->local;1284 tcp_reply_rst(epp, seg); 1285 } 1286 1287 /** Compute flipped endpoint pair for response. 1288 * 1289 * Flipped endpoint pair has local and remote endpoints exchanged. 1290 * 1291 * @param epp Endpoint pair 1292 * @param fepp Place to store flipped endpoint pair 1293 */ 1294 void tcp_ep2_flipped(inet_ep2_t *epp, inet_ep2_t *fepp) 1295 { 1296 fepp->local = epp->remote; 1297 fepp->remote = epp->local; 1298 1298 } 1299 1299 1300 1300 /** Send RST in response to an incoming segment. 1301 1301 * 1302 * @param sp Socket pair which received the segment1302 * @param epp Endpoint pair which received the segment 1303 1303 * @param seg Incoming segment 1304 1304 */ 1305 void tcp_reply_rst( tcp_sockpair_t *sp, tcp_segment_t *seg)1305 void tcp_reply_rst(inet_ep2_t *epp, tcp_segment_t *seg) 1306 1306 { 1307 1307 tcp_segment_t *rseg; 1308 1308 1309 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_reply_rst(%p, %p)", sp, seg);1309 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_reply_rst(%p, %p)", epp, seg); 1310 1310 1311 1311 rseg = tcp_segment_make_rst(seg); 1312 tcp_transmit_segment( sp, rseg);1312 tcp_transmit_segment(epp, rseg); 1313 1313 } 1314 1314 -
uspace/srv/net/tcp/conn.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define CONN_H 37 37 38 #include <inet/endpoint.h> 38 39 #include <stdbool.h> 39 40 #include "tcp_type.h" 40 41 41 extern tcp_conn_t *tcp_conn_new( tcp_sock_t *, tcp_sock_t *);42 extern tcp_conn_t *tcp_conn_new(inet_ep2_t *); 42 43 extern void tcp_conn_delete(tcp_conn_t *); 43 44 extern void tcp_conn_add(tcp_conn_t *); … … 47 48 extern void tcp_conn_fin_sent(tcp_conn_t *); 48 49 extern void tcp_conn_ack_of_fin_rcvd(tcp_conn_t *); 49 extern tcp_conn_t *tcp_conn_find_ref( tcp_sockpair_t *);50 extern tcp_conn_t *tcp_conn_find_ref(inet_ep2_t *); 50 51 extern void tcp_conn_addref(tcp_conn_t *); 51 52 extern void tcp_conn_delref(tcp_conn_t *); … … 55 56 extern void tcp_conn_segment_arrived(tcp_conn_t *, tcp_segment_t *); 56 57 extern void tcp_conn_trim_seg_to_wnd(tcp_conn_t *, tcp_segment_t *); 57 extern void tcp_unexpected_segment( tcp_sockpair_t *, tcp_segment_t *);58 extern void tcp_ sockpair_flipped(tcp_sockpair_t *, tcp_sockpair_t *);59 extern void tcp_reply_rst( tcp_sockpair_t *, tcp_segment_t *);58 extern void tcp_unexpected_segment(inet_ep2_t *, tcp_segment_t *); 59 extern void tcp_ep2_flipped(inet_ep2_t *, inet_ep2_t *); 60 extern void tcp_reply_rst(inet_ep2_t *, tcp_segment_t *); 60 61 61 62 #endif -
uspace/srv/net/tcp/ncsim.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 #include <async.h> 43 43 #include <errno.h> 44 #include <inet/endpoint.h> 44 45 #include <io/log.h> 45 46 #include <stdlib.h> … … 65 66 /** Bounce segment through simulator into receive queue. 66 67 * 67 * @param sp Socket pair, oriented for transmission68 * @param epp Endpoint pair, oriented for transmission 68 69 * @param seg Segment 69 70 */ 70 void tcp_ncsim_bounce_seg( tcp_sockpair_t *sp, tcp_segment_t *seg)71 void tcp_ncsim_bounce_seg(inet_ep2_t *epp, tcp_segment_t *seg) 71 72 { 72 73 tcp_squeue_entry_t *sqe; … … 75 76 76 77 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_ncsim_bounce_seg()"); 77 tcp_rqueue_bounce_seg( sp, seg);78 tcp_rqueue_bounce_seg(epp, seg); 78 79 return; 79 80 … … 92 93 93 94 sqe->delay = random() % (1000 * 1000); 94 sqe-> sp = *sp;95 sqe->epp = *epp; 95 96 sqe->seg = seg; 96 97 … … 147 148 148 149 log_msg(LOG_DEFAULT, LVL_DEBUG, "NCSim - End Sleep"); 149 tcp_rqueue_bounce_seg(&sqe-> sp, sqe->seg);150 tcp_rqueue_bounce_seg(&sqe->epp, sqe->seg); 150 151 free(sqe); 151 152 } -
uspace/srv/net/tcp/ncsim.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define NCSIM_H 37 37 38 #include <inet/endpoint.h> 38 39 #include "tcp_type.h" 39 40 40 41 extern void tcp_ncsim_init(void); 41 extern void tcp_ncsim_bounce_seg( tcp_sockpair_t *, tcp_segment_t *);42 extern void tcp_ncsim_bounce_seg(inet_ep2_t *, tcp_segment_t *); 42 43 extern void tcp_ncsim_fibril_start(void); 43 44 -
uspace/srv/net/tcp/pdu.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 #include <byteorder.h> 39 39 #include <errno.h> 40 #include <inet/endpoint.h> 40 41 #include <mem.h> 41 42 #include <stdlib.h> … … 125 126 } 126 127 127 static void tcp_header_setup( tcp_sockpair_t *sp, tcp_segment_t *seg, tcp_header_t *hdr)128 static void tcp_header_setup(inet_ep2_t *epp, tcp_segment_t *seg, tcp_header_t *hdr) 128 129 { 129 130 uint16_t doff_flags; 130 131 uint16_t doff; 131 132 132 hdr->src_port = host2uint16_t_be( sp->local.port);133 hdr->dest_port = host2uint16_t_be( sp->foreign.port);133 hdr->src_port = host2uint16_t_be(epp->local.port); 134 hdr->dest_port = host2uint16_t_be(epp->remote.port); 134 135 hdr->seq = host2uint32_t_be(seg->seq); 135 136 hdr->ack = host2uint32_t_be(seg->ack); … … 190 191 } 191 192 192 static int tcp_header_encode( tcp_sockpair_t *sp, tcp_segment_t *seg,193 static int tcp_header_encode(inet_ep2_t *epp, tcp_segment_t *seg, 193 194 void **header, size_t *size) 194 195 { … … 199 200 return ENOMEM; 200 201 201 tcp_header_setup( sp, seg, hdr);202 tcp_header_setup(epp, seg, hdr); 202 203 *header = hdr; 203 204 *size = sizeof(tcp_header_t); … … 293 294 294 295 /** Decode incoming PDU */ 295 int tcp_pdu_decode(tcp_pdu_t *pdu, tcp_sockpair_t *sp, tcp_segment_t **seg)296 int tcp_pdu_decode(tcp_pdu_t *pdu, inet_ep2_t *epp, tcp_segment_t **seg) 296 297 { 297 298 tcp_segment_t *nseg; … … 307 308 hdr = (tcp_header_t *)pdu->header; 308 309 309 sp->local.port = uint16_t_be2host(hdr->dest_port);310 sp->local.addr = pdu->dest;311 sp->foreign.port = uint16_t_be2host(hdr->src_port);312 sp->foreign.addr = pdu->src;310 epp->local.port = uint16_t_be2host(hdr->dest_port); 311 epp->local.addr = pdu->dest; 312 epp->remote.port = uint16_t_be2host(hdr->src_port); 313 epp->remote.addr = pdu->src; 313 314 314 315 *seg = nseg; … … 317 318 318 319 /** Encode outgoing PDU */ 319 int tcp_pdu_encode( tcp_sockpair_t *sp, tcp_segment_t *seg, tcp_pdu_t **pdu)320 int tcp_pdu_encode(inet_ep2_t *epp, tcp_segment_t *seg, tcp_pdu_t **pdu) 320 321 { 321 322 tcp_pdu_t *npdu; … … 327 328 return ENOMEM; 328 329 329 npdu->src = sp->local.addr;330 npdu->dest = sp->foreign.addr;331 tcp_header_encode( sp, seg, &npdu->header, &npdu->header_size);330 npdu->src = epp->local.addr; 331 npdu->dest = epp->remote.addr; 332 tcp_header_encode(epp, seg, &npdu->header, &npdu->header_size); 332 333 333 334 text_size = tcp_segment_text_size(seg); -
uspace/srv/net/tcp/pdu.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define PDU_H 37 37 38 #include <inet/endpoint.h> 38 39 #include <sys/types.h> 39 40 #include "std.h" … … 42 43 extern tcp_pdu_t *tcp_pdu_create(void *, size_t, void *, size_t); 43 44 extern void tcp_pdu_delete(tcp_pdu_t *); 44 extern int tcp_pdu_decode(tcp_pdu_t *, tcp_sockpair_t *, tcp_segment_t **);45 extern int tcp_pdu_encode( tcp_sockpair_t *, tcp_segment_t *, tcp_pdu_t **);45 extern int tcp_pdu_decode(tcp_pdu_t *, inet_ep2_t *, tcp_segment_t **); 46 extern int tcp_pdu_encode(inet_ep2_t *, tcp_segment_t *, tcp_pdu_t **); 46 47 47 48 #endif -
uspace/srv/net/tcp/rqueue.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 67 67 * This is for testing purposes only. 68 68 * 69 * @param sp Socket pair, oriented for transmission69 * @param sp Endpoint pair, oriented for transmission 70 70 * @param seg Segment 71 71 */ 72 void tcp_rqueue_bounce_seg( tcp_sockpair_t *sp, tcp_segment_t *seg)72 void tcp_rqueue_bounce_seg(inet_ep2_t *epp, tcp_segment_t *seg) 73 73 { 74 tcp_sockpair_t rident;74 inet_ep2_t rident; 75 75 76 76 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_rqueue_bounce_seg()"); … … 80 80 tcp_segment_t *dseg; 81 81 82 if (tcp_pdu_encode( sp, seg, &pdu) != EOK) {82 if (tcp_pdu_encode(epp, seg, &pdu) != EOK) { 83 83 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped."); 84 84 return; … … 97 97 #else 98 98 /* Reverse the identification */ 99 tcp_ sockpair_flipped(sp, &rident);99 tcp_ep2_flipped(epp, &rident); 100 100 101 101 /* Insert segment back into rqueue */ … … 106 106 /** Insert segment into receive queue. 107 107 * 108 * @param sp Socket pair, oriented for reception108 * @param epp Endpoint pair, oriented for reception 109 109 * @param seg Segment 110 110 */ 111 void tcp_rqueue_insert_seg( tcp_sockpair_t *sp, tcp_segment_t *seg)111 void tcp_rqueue_insert_seg(inet_ep2_t *epp, tcp_segment_t *seg) 112 112 { 113 113 tcp_rqueue_entry_t *rqe; … … 122 122 } 123 123 124 rqe-> sp = *sp;124 rqe->epp = *epp; 125 125 rqe->seg = seg; 126 126 … … 140 140 rqe = list_get_instance(link, tcp_rqueue_entry_t, link); 141 141 142 tcp_as_segment_arrived(&rqe-> sp, rqe->seg);142 tcp_as_segment_arrived(&rqe->epp, rqe->seg); 143 143 free(rqe); 144 144 } -
uspace/srv/net/tcp/rqueue.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define RQUEUE_H 37 37 38 #include <inet/endpoint.h> 38 39 #include "tcp_type.h" 39 40 40 41 extern void tcp_rqueue_init(void); 41 extern void tcp_rqueue_bounce_seg( tcp_sockpair_t *, tcp_segment_t *);42 extern void tcp_rqueue_insert_seg( tcp_sockpair_t *, tcp_segment_t *);42 extern void tcp_rqueue_bounce_seg(inet_ep2_t *, tcp_segment_t *); 43 extern void tcp_rqueue_insert_seg(inet_ep2_t *, tcp_segment_t *); 43 44 extern void tcp_rqueue_handler(void *); 44 45 extern void tcp_rqueue_fibril_start(void); -
uspace/srv/net/tcp/service.c
rbf7587b0 r2f19103 108 108 tcp_clst_t *clst; 109 109 tcp_cconn_t *cconn; 110 inet_ep2_t epp; 110 111 int rc; 111 112 tcp_error_t trc; … … 145 146 /* Replenish sentinel connection */ 146 147 147 trc = tcp_uc_open(&clst->elocal, NULL, ap_passive, tcp_open_nonblock, 148 inet_ep2_init(&epp); 149 epp.local = clst->elocal; 150 151 trc = tcp_uc_open(&epp, ap_passive, tcp_open_nonblock, 148 152 &conn); 149 153 if (trc != TCP_EOK) { … … 331 335 tcp_conn_t *conn; 332 336 tcp_cconn_t *cconn; 333 tcp_sock_t local; 334 tcp_sock_t remote; 335 inet_addr_t local_addr; 337 inet_ep2_t cepp; 336 338 int rc; 337 339 tcp_error_t trc; … … 340 342 341 343 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl"); 344 345 cepp = *epp; 342 346 343 347 /* Fill in local address? */ … … 345 349 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " 346 350 "determine local address"); 347 rc = inet_get_srcaddr(&epp->remote.addr, 0, & local_addr);351 rc = inet_get_srcaddr(&epp->remote.addr, 0, &cepp.local.addr); 348 352 if (rc != EOK) { 349 353 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " … … 354 358 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " 355 359 "local address specified"); 356 local_addr = epp->local.addr;357 360 } 358 361 359 362 /* Allocate local port? */ 360 if ( epp->local.port == 0) {361 epp->local.port = 49152; /* XXX */362 }363 364 local.addr = local_addr;365 local.port = epp->local.port;366 remote.addr = epp->remote.addr;367 remote.port = epp->remote.port;368 369 inet_addr_format(& local_addr, &slocal);370 inet_addr_format(& remote.addr, &sremote);363 if (cepp.local.port == 0) { 364 cepp.local.port = 49152; /* XXX */ 365 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " 366 "allocated local port %" PRIu16, cepp.local.port); 367 } else { 368 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create_impl: " 369 "local port %" PRIu16 " specified", cepp.local.port); 370 } 371 372 inet_addr_format(&cepp.local.addr, &slocal); 373 inet_addr_format(&cepp.remote.addr, &sremote); 371 374 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_create: local=%s remote=%s", 372 375 slocal, sremote); 373 374 trc = tcp_uc_open(&local, &remote, ap_active, tcp_open_nonblock, &conn); 376 free(slocal); 377 free(sremote); 378 379 trc = tcp_uc_open(&cepp, ap_active, tcp_open_nonblock, &conn); 375 380 if (trc != TCP_EOK) 376 381 return EIO; … … 386 391 tcp_uc_set_cb(conn, &tcp_service_cb, cconn); 387 392 388 // assoc->cb = &udp_cassoc_cb;389 // assoc->cb_arg = cassoc;390 391 393 *rconn_id = cconn->id; 392 394 return EOK; … … 415 417 tcp_conn_t *conn; 416 418 tcp_clst_t *clst; 417 tcp_sock_t local;419 inet_ep2_t epp; 418 420 int rc; 419 421 tcp_error_t trc; … … 421 423 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_listener_create_impl"); 422 424 423 local.addr = ep->addr; 424 local.port = ep->port; 425 426 trc = tcp_uc_open(&local, NULL, ap_passive, tcp_open_nonblock, &conn); 425 inet_ep2_init(&epp); 426 epp.local.addr = ep->addr; 427 epp.local.port = ep->port; 428 429 trc = tcp_uc_open(&epp, ap_passive, tcp_open_nonblock, &conn); 427 430 if (trc != TCP_EOK) 428 431 return EIO; … … 435 438 } 436 439 437 clst->elocal = local;440 clst->elocal = epp.local; 438 441 439 442 /* XXX Is there a race here (i.e. the connection is already active)? */ -
uspace/srv/net/tcp/tcp.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 160 160 { 161 161 tcp_segment_t *dseg; 162 tcp_sockpair_t rident;162 inet_ep2_t rident; 163 163 164 164 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_received_pdu()"); -
uspace/srv/net/tcp/tcp_type.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 43 43 #include <sys/types.h> 44 44 #include <inet/addr.h> 45 #include <inet/endpoint.h> 45 46 46 47 struct tcp_conn; … … 89 90 /* Connection reset */ 90 91 TCP_ERESET, 91 /* Foreign socket unspecified */92 /* Remote endpoint unspecified */ 92 93 TCP_EUNSPEC, 93 94 /* Insufficient resources */ … … 112 113 } tcp_control_t; 113 114 114 typedef struct {115 inet_addr_t addr;116 uint16_t port;117 } tcp_sock_t;118 119 115 enum tcp_port { 120 116 TCP_PORT_ANY = 0 121 117 }; 122 123 typedef struct {124 tcp_sock_t local;125 tcp_sock_t foreign;126 } tcp_sockpair_t;127 118 128 119 /** Connection incoming segments queue */ … … 171 162 void *cb_arg; 172 163 173 /** Connection identification (local and foreign socket) */174 tcp_sockpair_t ident;164 /** Connection identification (local and remote endpoint) */ 165 inet_ep2_t ident; 175 166 176 167 /** Active or passive connection */ … … 280 271 typedef struct { 281 272 link_t link; 282 tcp_sockpair_t sp;273 inet_ep2_t epp; 283 274 tcp_segment_t *seg; 284 275 } tcp_rqueue_entry_t; … … 288 279 link_t link; 289 280 suseconds_t delay; 290 tcp_sockpair_t sp;281 inet_ep2_t epp; 291 282 tcp_segment_t *seg; 292 283 } tcp_squeue_entry_t; … … 339 330 typedef struct tcp_clst { 340 331 /** Local endpoint */ 341 tcp_sock_t elocal;332 inet_ep_t elocal; 342 333 /** Connection */ 343 334 tcp_conn_t *conn; … … 360 351 } tcp_client_t; 361 352 362 #define TCP_SOCK_FRAGMENT_SIZE 1024363 364 typedef struct tcp_sockdata {365 /** Lock */366 fibril_mutex_t lock;367 /** Socket core */368 // socket_core_t *sock_core;369 /** Client */370 tcp_client_t *client;371 /** Connection */372 tcp_conn_t *conn;373 /** Local address */374 inet_addr_t laddr;375 /** Backlog size */376 int backlog;377 /** Array of listening connections, @c backlog elements */378 struct tcp_sock_lconn **lconn;379 /** List of connections (from lconn) that are ready to be accepted */380 list_t ready;381 /** Receiving fibril */382 fid_t recv_fibril;383 uint8_t recv_buffer[TCP_SOCK_FRAGMENT_SIZE];384 size_t recv_buffer_used;385 fibril_mutex_t recv_buffer_lock;386 fibril_condvar_t recv_buffer_cv;387 tcp_error_t recv_error;388 } tcp_sockdata_t;389 390 typedef struct tcp_sock_lconn {391 tcp_conn_t *conn;392 tcp_sockdata_t *socket;393 int index;394 link_t ready_list;395 } tcp_sock_lconn_t;396 397 353 #endif 398 354 -
uspace/srv/net/tcp/test.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 50 50 { 51 51 tcp_conn_t *conn; 52 tcp_sock_t lsock; 53 tcp_sock_t fsock; 52 inet_ep2_t epp; 54 53 char rcv_buf[RCV_BUF_SIZE + 1]; 55 54 size_t rcvd; … … 57 56 58 57 printf("test_srv()\n"); 59 60 inet_addr(&lsock.addr, 127, 0, 0, 1); 61 lsock.port = 80; 62 63 inet_addr(&fsock.addr, 127, 0, 0, 1); 64 fsock.port = 1024; 65 58 59 inet_ep2_init(&epp); 60 61 inet_addr(&epp.local.addr, 127, 0, 0, 1); 62 epp.local.port = 80; 63 64 inet_addr(&epp.remote.addr, 127, 0, 0, 1); 65 epp.remote.port = 1024; 66 66 67 printf("S: User open...\n"); 67 tcp_uc_open(& lsock, &fsock, ap_passive, 0, &conn);68 tcp_uc_open(&epp, ap_passive, 0, &conn); 68 69 conn->name = (char *) "S"; 69 70 … … 93 94 { 94 95 tcp_conn_t *conn; 95 tcp_sock_t lsock; 96 tcp_sock_t fsock; 96 inet_ep2_t epp; 97 97 const char *msg = "Hello World!"; 98 98 99 99 printf("test_cli()\n"); 100 101 inet_addr(&lsock.addr, 127, 0, 0, 1); 102 lsock.port = 1024; 103 104 inet_addr(&fsock.addr, 127, 0, 0, 1); 105 fsock.port = 80; 100 101 inet_ep2_init(&epp); 102 103 inet_addr(&epp.local.addr, 127, 0, 0, 1); 104 epp.local.port = 1024; 105 106 inet_addr(&epp.remote.addr, 127, 0, 0, 1); 107 epp.remote.port = 80; 106 108 107 109 async_usleep(1000*1000*3); 108 110 printf("C: User open...\n"); 109 tcp_uc_open(& lsock, &fsock, ap_active, 0, &conn);111 tcp_uc_open(&epp, ap_active, 0, &conn); 110 112 conn->name = (char *) "C"; 111 113 -
uspace/srv/net/tcp/tqueue.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 282 282 } 283 283 284 void tcp_transmit_segment( tcp_sockpair_t *sp, tcp_segment_t *seg)284 void tcp_transmit_segment(inet_ep2_t *epp, tcp_segment_t *seg) 285 285 { 286 286 log_msg(LOG_DEFAULT, LVL_DEBUG, 287 287 "tcp_transmit_segment(l:(%u),f:(%u), %p)", 288 sp->local.port, sp->foreign.port, seg);289 288 epp->local.port, epp->remote.port, seg); 289 290 290 log_msg(LOG_DEFAULT, LVL_DEBUG, "SEG.SEQ=%" PRIu32 ", SEG.WND=%" PRIu32, 291 291 seg->seq, seg->wnd); … … 301 301 tcp_pdu_t *pdu; 302 302 303 if (tcp_pdu_encode( sp, seg, &pdu) != EOK) {303 if (tcp_pdu_encode(epp, seg, &pdu) != EOK) { 304 304 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. Segment dropped."); 305 305 return; -
uspace/srv/net/tcp/tqueue.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define TQUEUE_H 37 37 38 #include <inet/endpoint.h> 38 39 #include "std.h" 39 40 #include "tcp_type.h" … … 48 49 extern void tcp_prepare_transmit_segment(tcp_conn_t *, tcp_segment_t *); 49 50 extern void tcp_conn_transmit_segment(tcp_conn_t *, tcp_segment_t *); 50 extern void tcp_transmit_segment( tcp_sockpair_t *, tcp_segment_t *);51 extern void tcp_transmit_segment(inet_ep2_t *, tcp_segment_t *); 51 52 extern void tcp_header_setup(tcp_conn_t *, tcp_segment_t *, tcp_header_t *); 52 53 extern void tcp_phdr_setup(tcp_conn_t *, tcp_segment_t *, tcp_phdr_t *); -
uspace/srv/net/tcp/ucall.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 50 50 /** OPEN user call 51 51 * 52 * @param lsock Local socket 53 * @param fsock Foreign socket 52 * @param epp Endpoint pair 54 53 * @param acpass Active/passive 55 54 * @param oflags Open flags … … 65 64 * establishment. 66 65 */ 67 tcp_error_t tcp_uc_open( tcp_sock_t *lsock, tcp_sock_t *fsock, acpass_t acpass,66 tcp_error_t tcp_uc_open(inet_ep2_t *epp, acpass_t acpass, 68 67 tcp_open_flags_t oflags, tcp_conn_t **conn) 69 68 { 70 69 tcp_conn_t *nconn; 71 70 72 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open(%p, % p, %s, %s, %p)",73 lsock, fsock, acpass == ap_active ? "active" : "passive",71 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open(%p, %s, %s, %p)", 72 epp, acpass == ap_active ? "active" : "passive", 74 73 oflags == tcp_open_nonblock ? "nonblock" : "none", conn); 75 74 76 nconn = tcp_conn_new( lsock, fsock);75 nconn = tcp_conn_new(epp); 77 76 tcp_conn_add(nconn); 78 77 tcp_conn_lock(nconn); … … 315 314 316 315 /** Segment arrived */ 317 void tcp_as_segment_arrived( tcp_sockpair_t *sp, tcp_segment_t *seg)316 void tcp_as_segment_arrived(inet_ep2_t *epp, tcp_segment_t *seg) 318 317 { 319 318 tcp_conn_t *conn; … … 321 320 log_msg(LOG_DEFAULT, LVL_DEBUG, 322 321 "tcp_as_segment_arrived(f:(%u), l:(%u))", 323 sp->foreign.port, sp->local.port);324 325 conn = tcp_conn_find_ref( sp);322 epp->remote.port, epp->local.port); 323 324 conn = tcp_conn_find_ref(epp); 326 325 if (conn == NULL) { 327 326 log_msg(LOG_DEFAULT, LVL_WARN, "No connection found."); 328 tcp_unexpected_segment( sp, seg);327 tcp_unexpected_segment(epp, seg); 329 328 return; 330 329 } … … 334 333 if (conn->cstate == st_closed) { 335 334 log_msg(LOG_DEFAULT, LVL_WARN, "Connection is closed."); 336 tcp_unexpected_segment( sp, seg);335 tcp_unexpected_segment(epp, seg); 337 336 tcp_conn_unlock(conn); 338 337 tcp_conn_delref(conn); … … 340 339 } 341 340 342 if (inet_addr_is_any(&conn->ident. foreign.addr))343 conn->ident. foreign.addr = sp->foreign.addr;344 345 if (conn->ident. foreign.port == TCP_PORT_ANY)346 conn->ident. foreign.port = sp->foreign.port;347 341 if (inet_addr_is_any(&conn->ident.remote.addr)) 342 conn->ident.remote.addr = epp->remote.addr; 343 344 if (conn->ident.remote.port == TCP_PORT_ANY) 345 conn->ident.remote.port = epp->remote.port; 346 348 347 if (inet_addr_is_any(&conn->ident.local.addr)) 349 conn->ident.local.addr = sp->local.addr;348 conn->ident.local.addr = epp->local.addr; 350 349 351 350 tcp_conn_segment_arrived(conn, seg); -
uspace/srv/net/tcp/ucall.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define UCALL_H 37 37 38 #include <inet/endpoint.h> 38 39 #include <sys/types.h> 39 40 #include "tcp_type.h" … … 42 43 * User calls 43 44 */ 44 extern tcp_error_t tcp_uc_open( tcp_sock_t *, tcp_sock_t *, acpass_t,45 extern tcp_error_t tcp_uc_open(inet_ep2_t *, acpass_t, 45 46 tcp_open_flags_t, tcp_conn_t **); 46 47 extern tcp_error_t tcp_uc_send(tcp_conn_t *, void *, size_t, xflags_t); … … 56 57 * Arriving segments 57 58 */ 58 extern void tcp_as_segment_arrived( tcp_sockpair_t *, tcp_segment_t *);59 extern void tcp_as_segment_arrived(inet_ep2_t *, tcp_segment_t *); 59 60 60 61 /*
Note:
See TracChangeset
for help on using the changeset viewer.