Changeset 2f19103 in mainline for uspace/srv/net/tcp/conn.c
- 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
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.