Changeset 2f19103 in mainline
- 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
- Files:
-
- 25 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 /* -
uspace/srv/net/udp/assoc.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 52 52 FIBRIL_MUTEX_INITIALIZE(assoc_list_lock); 53 53 54 static udp_assoc_t *udp_assoc_find_ref( udp_sockpair_t *);55 static int udp_assoc_queue_msg(udp_assoc_t *, udp_sockpair_t *, udp_msg_t *);56 static bool udp_ socket_match(udp_sock_t *, udp_sock_t *);57 static bool udp_ sockpair_match(udp_sockpair_t *, udp_sockpair_t *);54 static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *); 55 static int udp_assoc_queue_msg(udp_assoc_t *, inet_ep2_t *, udp_msg_t *); 56 static bool udp_ep_match(inet_ep_t *, inet_ep_t *); 57 static bool udp_ep2_match(inet_ep2_t *, inet_ep2_t *); 58 58 59 59 /** Create new association structure. 60 60 * 61 * @param lsock Local socket (will be deeply copied) 62 * @param fsock Foreign socket (will be deeply copied) 61 * @param epp Endpoint pair (will be copied) 62 * @param cb Callbacks 63 * @param cb_arg Callback argument 63 64 * @return New association or NULL 64 65 */ 65 udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock, 66 udp_assoc_cb_t *cb, void *cb_arg) 66 udp_assoc_t *udp_assoc_new(inet_ep2_t *epp, udp_assoc_cb_t *cb, void *cb_arg) 67 67 { 68 68 udp_assoc_t *assoc = NULL; … … 82 82 fibril_condvar_initialize(&assoc->rcv_queue_cv); 83 83 84 if (lsock != NULL) 85 assoc->ident.local = *lsock; 86 87 if (fsock != NULL) 88 assoc->ident.foreign = *fsock; 84 if (epp != NULL) 85 assoc->ident = *epp; 89 86 90 87 assoc->cb = cb; … … 200 197 assoc, iplink); 201 198 fibril_mutex_lock(&assoc->lock); 202 assoc->ident. iplink = iplink;203 fibril_mutex_unlock(&assoc->lock); 204 } 205 206 /** Set foreign socket in association.207 * 208 * @param assoc Association 209 * @param fsock Foreign socket (deeply copied)210 */ 211 void udp_assoc_set_ foreign(udp_assoc_t *assoc, udp_sock_t *fsock)212 { 213 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_ foreign(%p, %p)", assoc, fsock);214 fibril_mutex_lock(&assoc->lock); 215 assoc->ident. foreign = *fsock;216 fibril_mutex_unlock(&assoc->lock); 217 } 218 219 /** Set local socket in association.199 assoc->ident.local_link = iplink; 200 fibril_mutex_unlock(&assoc->lock); 201 } 202 203 /** Set remote endpoint in association. 204 * 205 * @param assoc Association 206 * @param remote Remote endpoint (deeply copied) 207 */ 208 void udp_assoc_set_remote(udp_assoc_t *assoc, inet_ep_t *remote) 209 { 210 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_remote(%p, %p)", assoc, remote); 211 fibril_mutex_lock(&assoc->lock); 212 assoc->ident.remote = *remote; 213 fibril_mutex_unlock(&assoc->lock); 214 } 215 216 /** Set local endpoint in association. 220 217 * 221 218 * @param assoc Association 222 * @param l sock Local socket (deeply copied)223 * 224 */ 225 void udp_assoc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock)226 { 227 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %p)", assoc, l sock);228 fibril_mutex_lock(&assoc->lock); 229 assoc->ident.local = *l sock;219 * @param local Local endpoint (deeply copied) 220 * 221 */ 222 void udp_assoc_set_local(udp_assoc_t *assoc, inet_ep_t *local) 223 { 224 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %p)", assoc, local); 225 fibril_mutex_lock(&assoc->lock); 226 assoc->ident.local = *local; 230 227 fibril_mutex_unlock(&assoc->lock); 231 228 } … … 248 245 * 249 246 * @param assoc Association 250 * @param fsock Foreign socket or NULL not to override @a assoc247 * @param remote Remote endpoint or NULL not to override @a assoc 251 248 * @param msg Message 252 249 * 253 250 * @return EOK on success 254 * EINVAL if foreign socket is not set251 * EINVAL if remote endpoint is not set 255 252 * ENOMEM if out of resources 256 253 * EIO if no route to destination exists 257 254 */ 258 int udp_assoc_send(udp_assoc_t *assoc, udp_sock_t *fsock, udp_msg_t *msg)255 int udp_assoc_send(udp_assoc_t *assoc, inet_ep_t *remote, udp_msg_t *msg) 259 256 { 260 257 udp_pdu_t *pdu; 261 udp_sockpair_t sp;258 inet_ep2_t epp; 262 259 int rc; 263 260 264 261 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send(%p, %p, %p)", 265 assoc, fsock, msg);266 267 /* @a fsock can be used to override the foreign socket */268 sp = assoc->ident;269 if ( fsock!= NULL)270 sp.foreign = *fsock;262 assoc, remote, msg); 263 264 /* @a remote can be used to override the remote endpoint */ 265 epp = assoc->ident; 266 if (remote != NULL) 267 epp.remote = *remote; 271 268 272 269 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check addr any"); 273 270 274 if ((inet_addr_is_any(& sp.foreign.addr)) ||275 ( sp.foreign.port == UDP_PORT_ANY))271 if ((inet_addr_is_any(&epp.remote.addr)) || 272 (epp.remote.port == UDP_PORT_ANY)) 276 273 return EINVAL; 277 274 278 275 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check version"); 279 276 280 if ( sp.foreign.addr.version != sp.local.addr.version)277 if (epp.remote.addr.version != epp.local.addr.version) 281 278 return EINVAL; 282 279 283 280 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - encode pdu"); 284 281 285 rc = udp_pdu_encode(& sp, msg, &pdu);282 rc = udp_pdu_encode(&epp, msg, &pdu); 286 283 if (rc != EOK) 287 284 return ENOMEM; … … 303 300 * Pull one message from the association's receive queue. 304 301 */ 305 int udp_assoc_recv(udp_assoc_t *assoc, udp_msg_t **msg, udp_sock_t *fsock)302 int udp_assoc_recv(udp_assoc_t *assoc, udp_msg_t **msg, inet_ep_t *remote) 306 303 { 307 304 link_t *link; … … 329 326 330 327 *msg = rqe->msg; 331 * fsock = rqe->sp.foreign;328 *remote = rqe->epp.remote; 332 329 free(rqe); 333 330 … … 339 336 * Find the association to which the message belongs and queue it. 340 337 */ 341 void udp_assoc_received( udp_sockpair_t *rsp, udp_msg_t *msg)338 void udp_assoc_received(inet_ep2_t *repp, udp_msg_t *msg) 342 339 { 343 340 udp_assoc_t *assoc; 344 341 int rc; 345 342 346 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_received(%p, %p)", r sp, msg);347 348 assoc = udp_assoc_find_ref(r sp);343 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_received(%p, %p)", repp, msg); 344 345 assoc = udp_assoc_find_ref(repp); 349 346 if (assoc == NULL) { 350 347 log_msg(LOG_DEFAULT, LVL_NOTE, "No association found. Message dropped."); … … 356 353 357 354 if (0) { 358 rc = udp_assoc_queue_msg(assoc, r sp, msg);355 rc = udp_assoc_queue_msg(assoc, repp, msg); 359 356 if (rc != EOK) { 360 357 log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped."); … … 364 361 365 362 log_msg(LOG_DEFAULT, LVL_NOTE, "call assoc->cb->recv_msg"); 366 assoc->cb->recv_msg(assoc->cb_arg, r sp, msg);363 assoc->cb->recv_msg(assoc->cb_arg, repp, msg); 367 364 udp_assoc_delref(assoc); 368 365 } … … 381 378 } 382 379 383 static int udp_assoc_queue_msg(udp_assoc_t *assoc, udp_sockpair_t *sp,380 static int udp_assoc_queue_msg(udp_assoc_t *assoc, inet_ep2_t *epp, 384 381 udp_msg_t *msg) 385 382 { … … 387 384 388 385 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_queue_msg(%p, %p, %p)", 389 assoc, sp, msg);386 assoc, epp, msg); 390 387 391 388 rqe = calloc(1, sizeof(udp_rcv_queue_entry_t)); … … 394 391 395 392 link_initialize(&rqe->link); 396 rqe-> sp = *sp;393 rqe->epp = *epp; 397 394 rqe->msg = msg; 398 395 … … 406 403 } 407 404 408 /** Match socket with pattern. */409 static bool udp_ socket_match(udp_sock_t *sock, udp_sock_t *patt)405 /** Match endpoint with pattern. */ 406 static bool udp_ep_match(inet_ep_t *ep, inet_ep_t *patt) 410 407 { 411 408 char *sa, *pa; 412 409 413 410 sa = pa = (char *)"?"; 414 (void) inet_addr_format(& sock->addr, &sa);411 (void) inet_addr_format(&ep->addr, &sa); 415 412 (void) inet_addr_format(&patt->addr, &pa); 416 413 417 414 log_msg(LOG_DEFAULT, LVL_NOTE, 418 "udp_ socket_match(sock=(%s,%u), pat=(%s,%u))",419 sa, sock->port, pa, patt->port);420 415 "udp_ep_match(ep=(%s,%u), pat=(%s,%u))", 416 sa, ep->port, pa, patt->port); 417 421 418 if ((!inet_addr_is_any(&patt->addr)) && 422 (!inet_addr_compare(&patt->addr, & sock->addr)))419 (!inet_addr_compare(&patt->addr, &ep->addr))) 423 420 return false; 424 421 425 422 log_msg(LOG_DEFAULT, LVL_NOTE, "addr OK"); 426 423 427 424 if ((patt->port != UDP_PORT_ANY) && 428 (patt->port != sock->port))425 (patt->port != ep->port)) 429 426 return false; 430 427 431 428 log_msg(LOG_DEFAULT, LVL_NOTE, " -> match"); 432 429 433 430 return true; 434 431 } 435 432 436 /** Match socket pair with pattern. */437 static bool udp_ sockpair_match(udp_sockpair_t *sp, udp_sockpair_t *pattern)438 { 439 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_ sockpair_match(%p, %p)", sp, pattern);440 441 if (!udp_ socket_match(&sp->local, &pattern->local))433 /** Match endpoint pair with pattern. */ 434 static bool udp_ep2_match(inet_ep2_t *epp, inet_ep2_t *pattern) 435 { 436 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_ep2_match(%p, %p)", epp, pattern); 437 438 if (!udp_ep_match(&epp->local, &pattern->local)) 442 439 return false; 443 440 444 if (!udp_ socket_match(&sp->foreign, &pattern->foreign))441 if (!udp_ep_match(&epp->remote, &pattern->remote)) 445 442 return false; 446 443 447 log_msg(LOG_DEFAULT, LVL_DEBUG, " Socket pair matched.");444 log_msg(LOG_DEFAULT, LVL_DEBUG, "Endpoint pair matched."); 448 445 return true; 449 446 } 450 447 451 448 452 /** Find association structure for specified socket pair.453 * 454 * An association is uniquely identified by a socket pair. Look up our455 * association map and return association structure based on socket pair.449 /** Find association structure for specified endpoint pair. 450 * 451 * An association is uniquely identified by an endpoint pair. Look up our 452 * association map and return association structure based on endpoint pair. 456 453 * The association reference count is bumped by one. 457 454 * 458 * @param sp Socket pair455 * @param epp Endpoint pair 459 456 * @return Association structure or NULL if not found. 460 457 */ 461 static udp_assoc_t *udp_assoc_find_ref( udp_sockpair_t *sp)458 static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *epp) 462 459 { 463 460 char *la, *ra; 464 461 465 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_find_ref(%p)", sp);466 462 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_find_ref(%p)", epp); 463 467 464 fibril_mutex_lock(&assoc_list_lock); 468 465 469 466 log_msg(LOG_DEFAULT, LVL_NOTE, "associations:"); 470 467 list_foreach(assoc_list, link, udp_assoc_t, assoc) { 471 udp_sockpair_t *asp = &assoc->ident;472 468 inet_ep2_t *aepp = &assoc->ident; 469 473 470 la = ra = NULL; 474 471 475 (void) inet_addr_format(&a sp->local.addr, &la);476 (void) inet_addr_format(&a sp->foreign.addr, &ra);477 478 log_msg(LOG_DEFAULT, LVL_NOTE, "find_ref:a sp=%p la=%s ra=%s",479 a sp, la, ra);472 (void) inet_addr_format(&aepp->local.addr, &la); 473 (void) inet_addr_format(&aepp->remote.addr, &ra); 474 475 log_msg(LOG_DEFAULT, LVL_NOTE, "find_ref:aepp=%p la=%s ra=%s", 476 aepp, la, ra); 480 477 /* Skip unbound associations */ 481 if (a sp->local.port == UDP_PORT_ANY) {478 if (aepp->local.port == UDP_PORT_ANY) { 482 479 log_msg(LOG_DEFAULT, LVL_NOTE, "skip unbound"); 483 480 continue; 484 481 } 485 486 if (udp_ sockpair_match(sp, asp)) {482 483 if (udp_ep2_match(epp, aepp)) { 487 484 log_msg(LOG_DEFAULT, LVL_DEBUG, "Returning assoc %p", assoc); 488 485 udp_assoc_addref(assoc); … … 493 490 } 494 491 } 495 492 496 493 log_msg(LOG_DEFAULT, LVL_NOTE, "associations END"); 497 494 fibril_mutex_unlock(&assoc_list_lock); -
uspace/srv/net/udp/assoc.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define ASSOC_H 37 37 38 #include <inet/endpoint.h> 38 39 #include <ipc/loc.h> 39 40 #include <sys/types.h> 40 41 #include "udp_type.h" 41 42 42 extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *, udp_assoc_cb_t *, 43 void *); 43 extern udp_assoc_t *udp_assoc_new(inet_ep2_t *, udp_assoc_cb_t *, void *); 44 44 extern void udp_assoc_delete(udp_assoc_t *); 45 45 extern void udp_assoc_add(udp_assoc_t *); … … 48 48 extern void udp_assoc_delref(udp_assoc_t *); 49 49 extern void udp_assoc_set_iplink(udp_assoc_t *, service_id_t); 50 extern void udp_assoc_set_ foreign(udp_assoc_t *, udp_sock_t *);51 extern void udp_assoc_set_local(udp_assoc_t *, udp_sock_t *);50 extern void udp_assoc_set_remote(udp_assoc_t *, inet_ep_t *); 51 extern void udp_assoc_set_local(udp_assoc_t *, inet_ep_t *); 52 52 extern void udp_assoc_set_local_port(udp_assoc_t *, uint16_t); 53 extern int udp_assoc_send(udp_assoc_t *, udp_sock_t *, udp_msg_t *);54 extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, udp_sock_t *);55 extern void udp_assoc_received( udp_sockpair_t *, udp_msg_t *);53 extern int udp_assoc_send(udp_assoc_t *, inet_ep_t *, udp_msg_t *); 54 extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, inet_ep_t *); 55 extern void udp_assoc_received(inet_ep2_t *, udp_msg_t *); 56 56 extern void udp_assoc_reset(udp_assoc_t *); 57 57 -
uspace/srv/net/udp/pdu.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 162 162 163 163 /** Decode incoming PDU */ 164 int udp_pdu_decode(udp_pdu_t *pdu, udp_sockpair_t *sp, udp_msg_t **msg)164 int udp_pdu_decode(udp_pdu_t *pdu, inet_ep2_t *epp, udp_msg_t **msg) 165 165 { 166 166 udp_msg_t *nmsg; … … 179 179 hdr = (udp_header_t *)pdu->data; 180 180 181 sp->foreign.port = uint16_t_be2host(hdr->src_port);182 sp->foreign.addr = pdu->src;183 sp->local.port = uint16_t_be2host(hdr->dest_port);184 sp->local.addr = pdu->dest;181 epp->remote.port = uint16_t_be2host(hdr->src_port); 182 epp->remote.addr = pdu->src; 183 epp->local.port = uint16_t_be2host(hdr->dest_port); 184 epp->local.addr = pdu->dest; 185 185 186 186 length = uint16_t_be2host(hdr->length); … … 208 208 209 209 /** Encode outgoing PDU */ 210 int udp_pdu_encode( udp_sockpair_t *sp, udp_msg_t *msg, udp_pdu_t **pdu)210 int udp_pdu_encode(inet_ep2_t *epp, udp_msg_t *msg, udp_pdu_t **pdu) 211 211 { 212 212 udp_pdu_t *npdu; … … 218 218 return ENOMEM; 219 219 220 npdu->iplink = sp->iplink;221 npdu->src = sp->local.addr;222 npdu->dest = sp->foreign.addr;220 npdu->iplink = epp->local_link; 221 npdu->src = epp->local.addr; 222 npdu->dest = epp->remote.addr; 223 223 224 224 npdu->data_size = sizeof(udp_header_t) + msg->data_size; … … 230 230 231 231 hdr = (udp_header_t *)npdu->data; 232 hdr->src_port = host2uint16_t_be( sp->local.port);233 hdr->dest_port = host2uint16_t_be( sp->foreign.port);232 hdr->src_port = host2uint16_t_be(epp->local.port); 233 hdr->dest_port = host2uint16_t_be(epp->remote.port); 234 234 hdr->length = host2uint16_t_be(npdu->data_size); 235 235 hdr->checksum = 0; -
uspace/srv/net/udp/pdu.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri 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 udp_pdu_t *udp_pdu_new(void); 43 44 extern void udp_pdu_delete(udp_pdu_t *); 44 extern int udp_pdu_decode(udp_pdu_t *, udp_sockpair_t *, udp_msg_t **);45 extern int udp_pdu_encode( udp_sockpair_t *, udp_msg_t *, udp_pdu_t **);45 extern int udp_pdu_decode(udp_pdu_t *, inet_ep2_t *, udp_msg_t **); 46 extern int udp_pdu_encode(inet_ep2_t *, udp_msg_t *, udp_pdu_t **); 46 47 47 48 #endif -
uspace/srv/net/udp/service.c
rbf7587b0 r2f19103 54 54 #define MAX_MSG_SIZE DATA_XFER_LIMIT 55 55 56 static void udp_cassoc_recv_msg(void *, udp_sockpair_t *, udp_msg_t *);56 static void udp_cassoc_recv_msg(void *, inet_ep2_t *, udp_msg_t *); 57 57 58 58 static udp_assoc_cb_t udp_cassoc_cb = { … … 60 60 }; 61 61 62 static int udp_cassoc_queue_msg(udp_cassoc_t *cassoc, udp_sockpair_t *sp,62 static int udp_cassoc_queue_msg(udp_cassoc_t *cassoc, inet_ep2_t *epp, 63 63 udp_msg_t *msg) 64 64 { … … 66 66 67 67 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_cassoc_queue_msg(%p, %p, %p)", 68 cassoc, sp, msg);68 cassoc, epp, msg); 69 69 70 70 rqe = calloc(1, sizeof(udp_crcv_queue_entry_t)); … … 73 73 74 74 link_initialize(&rqe->link); 75 rqe-> sp = *sp;75 rqe->epp = *epp; 76 76 rqe->msg = msg; 77 77 rqe->cassoc = cassoc; … … 144 144 } 145 145 146 static void udp_cassoc_recv_msg(void *arg, udp_sockpair_t *sp, udp_msg_t *msg)146 static void udp_cassoc_recv_msg(void *arg, inet_ep2_t *epp, udp_msg_t *msg) 147 147 { 148 148 udp_cassoc_t *cassoc = (udp_cassoc_t *) arg; 149 149 150 udp_cassoc_queue_msg(cassoc, sp, msg);150 udp_cassoc_queue_msg(cassoc, epp, msg); 151 151 udp_ev_data(cassoc->client); 152 152 } … … 157 157 udp_assoc_t *assoc; 158 158 udp_cassoc_t *cassoc; 159 udp_sock_t local;160 udp_sock_t remote;161 159 int rc; 162 160 163 161 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_create_impl"); 164 162 165 local.addr = epp->local.addr; 166 local.port = epp->local.port; 167 remote.addr = epp->remote.addr; 168 remote.port = epp->remote.port; 169 170 assoc = udp_assoc_new(&local, &remote, NULL, NULL); 163 assoc = udp_assoc_new(epp, NULL, NULL); 171 164 if (assoc == NULL) 172 165 return EIO; … … 213 206 { 214 207 udp_msg_t msg; 215 udp_sock_t remote;216 208 udp_cassoc_t *cassoc; 217 209 int rc; … … 221 213 return rc; 222 214 223 remote.addr = dest->addr;224 remote.port = dest->port;225 226 215 msg.data = data; 227 216 msg.data_size = size; 228 rc = udp_assoc_send(cassoc->assoc, &remote, &msg);217 rc = udp_assoc_send(cassoc->assoc, dest, &msg); 229 218 if (rc != EOK) 230 219 return rc; … … 390 379 ipc_callid_t callid; 391 380 size_t size; 392 inet_ep_t ep;393 381 udp_crcv_queue_entry_t *enext; 394 382 sysarg_t assoc_id; … … 410 398 } 411 399 412 inet_ep_init(&ep); 413 ep.addr = enext->sp.foreign.addr; 414 ep.port = enext->sp.foreign.port; 415 416 rc = async_data_read_finalize(callid, &ep, max(size, (ssize_t)sizeof(ep))); 400 rc = async_data_read_finalize(callid, &enext->epp.remote, 401 max(size, (ssize_t)sizeof(inet_ep_t))); 417 402 if (rc != EOK) { 418 403 async_answer_0(iid, rc); -
uspace/srv/net/udp/ucall.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 50 50 51 51 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_create()"); 52 nassoc = udp_assoc_new(NULL, NULL, NULL , NULL);52 nassoc = udp_assoc_new(NULL, NULL, NULL); 53 53 if (nassoc == NULL) 54 54 return UDP_ENORES; … … 67 67 } 68 68 69 udp_error_t udp_uc_set_ foreign(udp_assoc_t *assoc, udp_sock_t *fsock)69 udp_error_t udp_uc_set_remote(udp_assoc_t *assoc, inet_ep_t *ep) 70 70 { 71 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_ foreign(%p, %p)", assoc, fsock);71 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_remote(%p, %p)", assoc, ep); 72 72 73 udp_assoc_set_ foreign(assoc, fsock);73 udp_assoc_set_remote(assoc, ep); 74 74 return UDP_EOK; 75 75 } 76 76 77 udp_error_t udp_uc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock)77 udp_error_t udp_uc_set_local(udp_assoc_t *assoc, inet_ep_t *ep) 78 78 { 79 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %p)", assoc, lsock);80 81 udp_assoc_set_local(assoc, lsock);79 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %p)", assoc, ep); 80 81 udp_assoc_set_local(assoc, ep); 82 82 return UDP_EOK; 83 83 } … … 86 86 { 87 87 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %" PRIu16 ")", assoc, lport); 88 88 89 89 udp_assoc_set_local_port(assoc, lport); 90 90 return UDP_EOK; 91 91 } 92 92 93 udp_error_t udp_uc_send(udp_assoc_t *assoc, udp_sock_t *fsock, void *data,93 udp_error_t udp_uc_send(udp_assoc_t *assoc, inet_ep_t *remote, void *data, 94 94 size_t size, xflags_t flags) 95 95 { … … 102 102 msg.data_size = size; 103 103 104 rc = udp_assoc_send(assoc, fsock, &msg);104 rc = udp_assoc_send(assoc, remote, &msg); 105 105 switch (rc) { 106 106 case ENOMEM: … … 115 115 116 116 udp_error_t udp_uc_receive(udp_assoc_t *assoc, void *buf, size_t size, 117 size_t *rcvd, xflags_t *xflags, udp_sock_t *fsock)117 size_t *rcvd, xflags_t *xflags, inet_ep_t *remote) 118 118 { 119 119 size_t xfer_size; … … 122 122 123 123 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: udp_uc_receive()", assoc->name); 124 rc = udp_assoc_recv(assoc, &msg, fsock);124 rc = udp_assoc_recv(assoc, &msg, remote); 125 125 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv -> %d", rc); 126 126 switch (rc) { -
uspace/srv/net/udp/ucall.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 extern udp_error_t udp_uc_create(udp_assoc_t **); 43 43 extern void udp_uc_set_iplink(udp_assoc_t *, service_id_t); 44 extern udp_error_t udp_uc_set_ foreign(udp_assoc_t *, udp_sock_t *);45 extern udp_error_t udp_uc_set_local(udp_assoc_t *, udp_sock_t *);44 extern udp_error_t udp_uc_set_remote(udp_assoc_t *, inet_ep_t *); 45 extern udp_error_t udp_uc_set_local(udp_assoc_t *, inet_ep_t *); 46 46 extern udp_error_t udp_uc_set_local_port(udp_assoc_t *, uint16_t); 47 extern udp_error_t udp_uc_send(udp_assoc_t *, udp_sock_t *, void *, size_t,47 extern udp_error_t udp_uc_send(udp_assoc_t *, inet_ep_t *, void *, size_t, 48 48 xflags_t); 49 49 extern udp_error_t udp_uc_receive(udp_assoc_t *, void *, size_t, size_t *, 50 xflags_t *, udp_sock_t *);50 xflags_t *, inet_ep_t *); 51 51 extern void udp_uc_status(udp_assoc_t *, udp_assoc_status_t *); 52 52 extern void udp_uc_destroy(udp_assoc_t *); -
uspace/srv/net/udp/udp_inet.c
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 105 105 { 106 106 udp_msg_t *dmsg; 107 udp_sockpair_t rident;107 inet_ep2_t rident; 108 108 109 109 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_received_pdu()"); -
uspace/srv/net/udp/udp_type.h
rbf7587b0 r2f19103 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <fibril.h> 40 40 #include <fibril_synch.h> 41 #include <inet/endpoint.h> 41 42 #include <ipc/loc.h> 42 43 #include <sys/types.h> … … 49 50 /* Insufficient resources */ 50 51 UDP_ENORES, 51 /* Foreign socket unspecified */52 /* Remote endpoint unspecified */ 52 53 UDP_EUNSPEC, 53 54 /* No route to destination */ … … 64 65 UDP_PORT_ANY = 0 65 66 }; 66 67 typedef struct {68 inet_addr_t addr;69 uint16_t port;70 } udp_sock_t;71 72 typedef struct {73 service_id_t iplink;74 udp_sock_t local;75 udp_sock_t foreign;76 } udp_sockpair_t;77 67 78 68 /** Unencoded UDP message (datagram) */ … … 99 89 100 90 typedef struct { 101 void (*recv_msg)(void *, udp_sockpair_t *, udp_msg_t *);91 void (*recv_msg)(void *, inet_ep2_t *, udp_msg_t *); 102 92 } udp_assoc_cb_t; 103 93 … … 106 96 * This is a rough equivalent of a TCP connection endpoint. It allows 107 97 * sending and receiving UDP datagrams and it is uniquely identified 108 * by a socket pair.98 * by an endpoint pair. 109 99 */ 110 100 typedef struct { … … 112 102 link_t link; 113 103 114 /** Association identification ( local and foreign socket) */115 udp_sockpair_t ident;104 /** Association identification (endpoint pair) */ 105 inet_ep2_t ident; 116 106 117 107 /** True if association was reset by user */ … … 141 131 /** Link to receive queue */ 142 132 link_t link; 143 /** Socket pair */144 udp_sockpair_t sp;133 /** Endpoint pair */ 134 inet_ep2_t epp; 145 135 /** Message */ 146 136 udp_msg_t *msg; … … 160 150 /** Link to receive queue */ 161 151 link_t link; 162 /** Socket pair */163 udp_sockpair_t sp;152 /** Endpoint pair */ 153 inet_ep2_t epp; 164 154 /** Message */ 165 155 udp_msg_t *msg;
Note:
See TracChangeset
for help on using the changeset viewer.