Changeset 8d48c7e in mainline
- Timestamp:
- 2015-06-02T16:00:42Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2c4bb828
- Parents:
- ab6326bc
- Location:
- uspace
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inet.c
rab6326bc r8d48c7e 177 177 178 178 dgram.tos = IPC_GET_ARG1(*icall); 179 dgram.iplink = IPC_GET_ARG2(*icall); 179 180 180 181 ipc_callid_t callid; -
uspace/lib/c/generic/iplink.c
rab6326bc r8d48c7e 47 47 static void iplink_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); 48 48 49 int iplink_open(async_sess_t *sess, iplink_ev_ops_t *ev_ops, 49 int iplink_open(async_sess_t *sess, iplink_ev_ops_t *ev_ops, void *arg, 50 50 iplink_t **riplink) 51 51 { … … 56 56 iplink->sess = sess; 57 57 iplink->ev_ops = ev_ops; 58 iplink->arg = arg; 58 59 59 60 async_exch_t *exch = async_exchange_begin(sess); … … 234 235 235 236 return (int) retval; 237 } 238 239 void *iplink_get_userptr(iplink_t *iplink) 240 { 241 return iplink->arg; 236 242 } 237 243 -
uspace/lib/c/include/inet/iplink.h
rab6326bc r8d48c7e 44 44 async_sess_t *sess; 45 45 struct iplink_ev_ops *ev_ops; 46 void *arg; 46 47 } iplink_t; 47 48 … … 81 82 } iplink_ev_ops_t; 82 83 83 extern int iplink_open(async_sess_t *, iplink_ev_ops_t *, iplink_t **);84 extern int iplink_open(async_sess_t *, iplink_ev_ops_t *, void *, iplink_t **); 84 85 extern void iplink_close(iplink_t *); 85 86 extern int iplink_send(iplink_t *, iplink_sdu_t *); … … 90 91 extern int iplink_get_mac48(iplink_t *, addr48_t *); 91 92 extern int iplink_set_mac48(iplink_t *, addr48_t); 93 extern void *iplink_get_userptr(iplink_t *); 92 94 93 95 #endif -
uspace/lib/nettl/include/nettl/amap.h
rab6326bc r8d48c7e 96 96 inet_ep2_t *); 97 97 extern void amap_remove(amap_t *, inet_ep2_t *); 98 extern int amap_find (amap_t *, inet_ep2_t *, void **);98 extern int amap_find_match(amap_t *, inet_ep2_t *, void **); 99 99 100 100 #endif -
uspace/lib/nettl/include/nettl/portrng.h
rab6326bc r8d48c7e 46 46 /** Port number */ 47 47 uint16_t pn; 48 /** User argument */ 49 void *arg; 48 50 } portrng_port_t; 49 51 … … 60 62 extern int portrng_alloc(portrng_t *, uint16_t, void *, 61 63 portrng_flags_t, uint16_t *); 64 extern int portrng_find_port(portrng_t *, uint16_t, void **); 62 65 extern void portrng_free_port(portrng_t *, uint16_t); 63 66 extern bool portrng_empty(portrng_t *); -
uspace/lib/nettl/src/amap.c
rab6326bc r8d48c7e 510 510 } 511 511 512 int amap_find(amap_t *map, inet_ep2_t *epp, void **rarg) 513 { 514 log_msg(LOG_DEFAULT, LVL_NOTE, "amap_find()"); 515 return EOK; 512 /** Find association matching an endpoint pair. 513 * 514 * Used to find which association to deliver a datagram to. 515 * 516 * @param map Association map 517 * @param epp Endpoint pair 518 * @param rarg Place to store user argument for the matching association. 519 * 520 * @return EOK on success, ENOENT if not found. 521 */ 522 int amap_find_match(amap_t *map, inet_ep2_t *epp, void **rarg) 523 { 524 int rc; 525 amap_repla_t *repla; 526 amap_laddr_t *laddr; 527 amap_llink_t *llink; 528 529 log_msg(LOG_DEFAULT, LVL_NOTE, "amap_find_match(llink=%zu)", 530 epp->local_link); 531 532 /* Remode endpoint, local address */ 533 rc = amap_repla_find(map, &epp->remote, &epp->local.addr, &repla); 534 if (rc == EOK) { 535 rc = portrng_find_port(repla->portrng, epp->local.port, 536 rarg); 537 if (rc == EOK) { 538 log_msg(LOG_DEFAULT, LVL_NOTE, "Matched repla / " 539 "port %" PRIu16, epp->local.port); 540 return EOK; 541 } 542 } 543 544 /* Local address */ 545 rc = amap_laddr_find(map, &epp->local.addr, &laddr); 546 if (rc == EOK) { 547 rc = portrng_find_port(laddr->portrng, epp->local.port, 548 rarg); 549 if (rc == EOK) { 550 log_msg(LOG_DEFAULT, LVL_NOTE, "Matched laddr / " 551 "port %" PRIu16, epp->local.port); 552 return EOK; 553 } 554 } 555 556 /* Local link */ 557 rc = amap_llink_find(map, epp->local_link, &llink); 558 if (epp->local_link != 0 && rc == EOK) { 559 rc = portrng_find_port(llink->portrng, epp->local.port, 560 rarg); 561 if (rc == EOK) { 562 log_msg(LOG_DEFAULT, LVL_NOTE, "Matched llink / " 563 "port %" PRIu16, epp->local.port); 564 return EOK; 565 } 566 } 567 568 /* Unspecified */ 569 rc = portrng_find_port(map->unspec, epp->local.port, rarg); 570 if (rc == EOK) { 571 log_msg(LOG_DEFAULT, LVL_NOTE, "Matched unspec / port %" PRIu16, 572 epp->local.port); 573 return EOK; 574 } 575 576 log_msg(LOG_DEFAULT, LVL_NOTE, "No match."); 577 return ENOENT; 516 578 } 517 579 -
uspace/lib/nettl/src/portrng.c
rab6326bc r8d48c7e 118 118 119 119 p->pn = pnum; 120 p->arg = arg; 120 121 list_append(&p->lprng, &pr->used); 121 122 *apnum = pnum; … … 123 124 pnum); 124 125 return EOK; 126 } 127 128 int portrng_find_port(portrng_t *pr, uint16_t pnum, void **rarg) 129 { 130 list_foreach(pr->used, lprng, portrng_port_t, port) { 131 if (port->pn == pnum) { 132 *rarg = port->arg; 133 return EOK; 134 } 135 } 136 137 return ENOENT; 125 138 } 126 139 -
uspace/srv/net/inetsrv/inet_link.c
rab6326bc r8d48c7e 73 73 { 74 74 memcpy(ip_addr, link_local_node_ip, 16); 75 75 76 76 ip_addr[8] = mac_addr[0] ^ 0x02; 77 77 ip_addr[9] = mac_addr[1]; … … 85 85 { 86 86 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_iplink_recv()"); 87 87 88 88 int rc; 89 89 inet_packet_t packet; 90 90 inet_link_t *ilink; 91 92 ilink = (inet_link_t *)iplink_get_userptr(iplink); 93 91 94 switch (ver) { 92 95 case ip_v4: 93 rc = inet_pdu_decode(sdu->data, sdu->size, &packet); 96 rc = inet_pdu_decode(sdu->data, sdu->size, ilink->svc_id, 97 &packet); 94 98 break; 95 99 case ip_v6: 96 rc = inet_pdu_decode6(sdu->data, sdu->size, &packet); 100 rc = inet_pdu_decode6(sdu->data, sdu->size, ilink->svc_id, 101 &packet); 97 102 break; 98 103 default: … … 100 105 return EINVAL; 101 106 } 102 107 103 108 if (rc != EOK) { 104 109 log_msg(LOG_DEFAULT, LVL_DEBUG, "failed decoding PDU"); 105 110 return rc; 106 111 } 107 112 113 log_msg(LOG_DEFAULT, LVL_NOTE, "inet_iplink_recv: link_id=%zu", packet.link_id); 108 114 log_msg(LOG_DEFAULT, LVL_DEBUG, "call inet_recv_packet()"); 109 115 rc = inet_recv_packet(&packet); 110 116 log_msg(LOG_DEFAULT, LVL_DEBUG, "call inet_recv_packet -> %d", rc); 111 117 free(packet.data); 112 118 113 119 return rc; 114 120 } … … 177 183 } 178 184 179 rc = iplink_open(ilink->sess, &inet_iplink_ev_ops, &ilink->iplink);185 rc = iplink_open(ilink->sess, &inet_iplink_ev_ops, ilink, &ilink->iplink); 180 186 if (rc != EOK) { 181 187 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed opening IP link '%s'", -
uspace/srv/net/inetsrv/inetsrv.c
rab6326bc r8d48c7e 469 469 { 470 470 async_exch_t *exch = async_exchange_begin(client->sess); 471 471 472 472 ipc_call_t answer; 473 aid_t req = async_send_1(exch, INET_EV_RECV, dgram->tos, &answer); 474 473 474 log_msg(LOG_DEFAULT, LVL_NOTE, "inet_ev_recv: iplink=%zu", 475 dgram->iplink); 476 477 aid_t req = async_send_2(exch, INET_EV_RECV, dgram->tos, 478 dgram->iplink, &answer); 479 475 480 int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t)); 476 481 if (rc != EOK) { … … 479 484 return rc; 480 485 } 481 486 482 487 rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t)); 483 488 if (rc != EOK) { … … 486 491 return rc; 487 492 } 488 493 489 494 rc = async_data_write_start(exch, dgram->data, dgram->size); 490 495 491 496 async_exchange_end(exch); 492 497 493 498 if (rc != EOK) { 494 499 async_forget(req); 495 500 return rc; 496 501 } 497 502 498 503 sysarg_t retval; 499 504 async_wait_for(req, &retval); 500 505 501 506 return (int) retval; 502 507 } … … 511 516 if (proto == IP_PROTO_ICMP) 512 517 return icmp_recv(dgram); 513 518 514 519 if (proto == IP_PROTO_ICMPV6) 515 520 return icmpv6_recv(dgram); … … 540 545 if (packet->offs == 0 && !packet->mf) { 541 546 /* It is complete deliver it immediately */ 547 dgram.iplink = packet->link_id; 542 548 dgram.src = packet->src; 543 549 dgram.dest = packet->dest; -
uspace/srv/net/inetsrv/inetsrv.h
rab6326bc r8d48c7e 75 75 76 76 typedef struct { 77 /** Local link ID */ 78 service_id_t link_id; 77 79 /** Source address */ 78 80 inet_addr_t src; -
uspace/srv/net/inetsrv/pdu.c
rab6326bc r8d48c7e 298 298 /** Decode IPv4 datagram 299 299 * 300 * @param data Serialized IPv4 datagram 301 * @param size Length of serialized IPv4 datagram 302 * @param packet IP datagram structure to be filled 300 * @param data Serialized IPv4 datagram 301 * @param size Length of serialized IPv4 datagram 302 * @param link_id Link on which PDU was received 303 * @param packet IP datagram structure to be filled 303 304 * 304 305 * @return EOK on success … … 307 308 * 308 309 */ 309 int inet_pdu_decode(void *data, size_t size, inet_packet_t *packet) 310 int inet_pdu_decode(void *data, size_t size, service_id_t link_id, 311 inet_packet_t *packet) 310 312 { 311 313 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_pdu_decode()"); … … 366 368 367 369 memcpy(packet->data, (uint8_t *) data + data_offs, packet->size); 370 packet->link_id = link_id; 368 371 369 372 return EOK; … … 372 375 /** Decode IPv6 datagram 373 376 * 374 * @param data Serialized IPv6 datagram 375 * @param size Length of serialized IPv6 datagram 376 * @param packet IP datagram structure to be filled 377 * @param data Serialized IPv6 datagram 378 * @param size Length of serialized IPv6 datagram 379 * @param link_id Link on which PDU was received 380 * @param packet IP datagram structure to be filled 377 381 * 378 382 * @return EOK on success … … 381 385 * 382 386 */ 383 int inet_pdu_decode6(void *data, size_t size, inet_packet_t *packet) 387 int inet_pdu_decode6(void *data, size_t size, service_id_t link_id, 388 inet_packet_t *packet) 384 389 { 385 390 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_pdu_decode6()"); … … 457 462 458 463 memcpy(packet->data, (uint8_t *) data + data_offs, packet->size); 459 464 packet->link_id = link_id; 460 465 return EOK; 461 466 } -
uspace/srv/net/inetsrv/pdu.h
rab6326bc r8d48c7e 38 38 #define INET_PDU_H_ 39 39 40 #include <loc.h> 40 41 #include <sys/types.h> 41 42 #include "inetsrv.h" … … 50 51 extern int inet_pdu_encode6(inet_packet_t *, addr128_t, addr128_t, size_t, 51 52 size_t, void **, size_t *, size_t *); 52 extern int inet_pdu_decode(void *, size_t, inet_packet_t *);53 extern int inet_pdu_decode6(void *, size_t, inet_packet_t *);53 extern int inet_pdu_decode(void *, size_t, service_id_t, inet_packet_t *); 54 extern int inet_pdu_decode6(void *, size_t, service_id_t, inet_packet_t *); 54 55 55 56 extern int ndp_pdu_decode(inet_dgram_t *, ndp_packet_t *); -
uspace/srv/net/inetsrv/reass.c
rab6326bc r8d48c7e 325 325 return ENOMEM; 326 326 327 /* XXX What if different fragments came from different link? */ 328 dgram.iplink = frag->packet.link_id; 327 329 dgram.size = dgram_size; 328 330 dgram.src = frag->packet.src; -
uspace/srv/net/tcp/conn.c
rab6326bc r8d48c7e 199 199 void tcp_conn_addref(tcp_conn_t *conn) 200 200 { 201 log_msg(LOG_DEFAULT, LVL_DEBUG2, "%s: tcp_conn_addref(%p)", conn->name, conn); 201 log_msg(LOG_DEFAULT, LVL_DEBUG2, "%s: tcp_conn_addref(%p) before=%zu", 202 conn->name, conn, atomic_get(&conn->refcnt)); 202 203 atomic_inc(&conn->refcnt); 203 204 } … … 211 212 void tcp_conn_delref(tcp_conn_t *conn) 212 213 { 213 log_msg(LOG_DEFAULT, LVL_DEBUG2, "%s: tcp_conn_delref(%p)", conn->name, conn); 214 log_msg(LOG_DEFAULT, LVL_DEBUG2, "%s: tcp_conn_delref(%p) before=%zu", 215 conn->name, conn, atomic_get(&conn->refcnt)); 214 216 215 217 if (atomic_predec(&conn->refcnt) == 0) … … 269 271 tcp_conn_addref(conn); 270 272 fibril_mutex_lock(&conn_list_lock); 273 274 log_msg(LOG_DEFAULT, LVL_NOTE, "tcp_conn_add: conn=%p", conn); 271 275 272 276 rc = amap_insert(amap, &conn->ident, conn, af_allow_system, &aepp); … … 365 369 } 366 370 367 /** Match endpoint with pattern. */368 static bool tcp_ep_match(inet_ep_t *ep, inet_ep_t *patt)369 {370 log_msg(LOG_DEFAULT, LVL_DEBUG2,371 "tcp_ep_match(ep=(%u), pat=(%u))", ep->port, patt->port);372 373 if ((!inet_addr_is_any(&patt->addr)) &&374 (!inet_addr_compare(&patt->addr, &ep->addr)))375 return false;376 377 if ((patt->port != inet_port_any) &&378 (patt->port != ep->port))379 return false;380 381 log_msg(LOG_DEFAULT, LVL_DEBUG2, " -> match");382 383 return true;384 }385 386 /** Match endpoint pair with pattern. */387 static bool tcp_ep2_match(inet_ep2_t *epp, inet_ep2_t *pattern)388 {389 log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_ep2_match(%p, %p)", epp, pattern);390 391 if (!tcp_ep_match(&epp->local, &pattern->local))392 return false;393 394 if (!tcp_ep_match(&epp->remote, &pattern->remote))395 return false;396 397 return true;398 }399 400 371 /** Find connection structure for specified endpoint pair. 401 372 * … … 409 380 tcp_conn_t *tcp_conn_find_ref(inet_ep2_t *epp) 410 381 { 382 int rc; 383 void *arg; 384 tcp_conn_t *conn; 385 411 386 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", epp); 412 387 413 log_msg(LOG_DEFAULT, LVL_DEBUG2, "compare conn (f:(%u), l:(%u))",414 epp->remote.port, epp->local.port);415 416 388 fibril_mutex_lock(&conn_list_lock); 417 389 418 list_foreach(conn_list, link, tcp_conn_t, conn) { 419 inet_ep2_t *cepp = &conn->ident; 420 421 log_msg(LOG_DEFAULT, LVL_DEBUG2, " - with (f:(%u), l:(%u))", 422 cepp->remote.port, cepp->local.port); 423 424 if (tcp_ep2_match(epp, cepp)) { 425 tcp_conn_addref(conn); 426 fibril_mutex_unlock(&conn_list_lock); 427 return conn; 428 } 429 } 390 rc = amap_find_match(amap, epp, &arg); 391 if (rc != EOK) { 392 assert(rc == ENOENT); 393 fibril_mutex_unlock(&conn_list_lock); 394 return NULL; 395 } 396 397 conn = (tcp_conn_t *)arg; 398 tcp_conn_addref(conn); 430 399 431 400 fibril_mutex_unlock(&conn_list_lock); 432 return NULL; 401 log_msg(LOG_DEFAULT, LVL_NOTE, "tcp_conn_find_ref: got conn=%p", 402 conn); 403 return conn; 433 404 } 434 405 … … 1209 1180 void tcp_conn_segment_arrived(tcp_conn_t *conn, tcp_segment_t *seg) 1210 1181 { 1211 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_conn_segment_arrived(%p)", 1182 log_msg(LOG_DEFAULT, LVL_NOTE, "conn=%p", conn); 1183 log_msg(LOG_DEFAULT, LVL_NOTE, "conn->name=%p", conn->name); 1184 log_msg(LOG_DEFAULT, LVL_NOTE, "%s: tcp_conn_segment_arrived(%p)", 1212 1185 conn->name, seg); 1213 1186 -
uspace/srv/net/tcp/service.c
rab6326bc r8d48c7e 156 156 } 157 157 158 conn->name = (char *) "s"; 158 159 clst->conn = conn; 159 160 … … 353 354 return EIO; 354 355 356 conn->name = (char *) "c"; 357 355 358 rc = tcp_cconn_create(client, conn, &cconn); 356 359 if (rc != EOK) { … … 402 405 if (trc != TCP_EOK) 403 406 return EIO; 407 408 conn->name = (char *) "s"; 404 409 405 410 rc = tcp_clistener_create(client, conn, &clst); -
uspace/srv/net/udp/assoc.c
rab6326bc r8d48c7e 56 56 static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *); 57 57 static int udp_assoc_queue_msg(udp_assoc_t *, inet_ep2_t *, udp_msg_t *); 58 static bool udp_ep_match(inet_ep_t *, inet_ep_t *);59 static bool udp_ep2_match(inet_ep2_t *, inet_ep2_t *);60 58 61 59 /** Initialize associations. */ … … 393 391 } 394 392 395 /** Match endpoint with pattern. */396 static bool udp_ep_match(inet_ep_t *ep, inet_ep_t *patt)397 {398 char *sa, *pa;399 400 sa = pa = (char *)"?";401 (void) inet_addr_format(&ep->addr, &sa);402 (void) inet_addr_format(&patt->addr, &pa);403 404 log_msg(LOG_DEFAULT, LVL_NOTE,405 "udp_ep_match(ep=(%s,%u), pat=(%s,%u))",406 sa, ep->port, pa, patt->port);407 408 if ((!inet_addr_is_any(&patt->addr)) &&409 (!inet_addr_compare(&patt->addr, &ep->addr)))410 return false;411 412 log_msg(LOG_DEFAULT, LVL_NOTE, "addr OK");413 414 if ((patt->port != inet_port_any) &&415 (patt->port != ep->port))416 return false;417 418 log_msg(LOG_DEFAULT, LVL_NOTE, " -> match");419 420 return true;421 }422 423 /** Match endpoint pair with pattern. */424 static bool udp_ep2_match(inet_ep2_t *epp, inet_ep2_t *pattern)425 {426 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_ep2_match(%p, %p)", epp, pattern);427 428 if (!udp_ep_match(&epp->local, &pattern->local))429 return false;430 431 if (!udp_ep_match(&epp->remote, &pattern->remote))432 return false;433 434 log_msg(LOG_DEFAULT, LVL_DEBUG, "Endpoint pair matched.");435 return true;436 }437 438 439 393 /** Find association structure for specified endpoint pair. 440 394 * … … 448 402 static udp_assoc_t *udp_assoc_find_ref(inet_ep2_t *epp) 449 403 { 450 char *la, *ra; 404 int rc; 405 void *arg; 406 udp_assoc_t *assoc; 451 407 452 408 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_find_ref(%p)", epp); 453 454 409 fibril_mutex_lock(&assoc_list_lock); 455 410 456 log_msg(LOG_DEFAULT, LVL_NOTE, "associations:"); 457 list_foreach(assoc_list, link, udp_assoc_t, assoc) { 458 inet_ep2_t *aepp = &assoc->ident; 459 460 la = ra = NULL; 461 462 (void) inet_addr_format(&aepp->local.addr, &la); 463 (void) inet_addr_format(&aepp->remote.addr, &ra); 464 465 log_msg(LOG_DEFAULT, LVL_NOTE, "find_ref:aepp=%p la=%s ra=%s", 466 aepp, la, ra); 467 /* Skip unbound associations */ 468 if (aepp->local.port == inet_port_any) { 469 log_msg(LOG_DEFAULT, LVL_NOTE, "skip unbound"); 470 continue; 471 } 472 473 if (udp_ep2_match(epp, aepp)) { 474 log_msg(LOG_DEFAULT, LVL_DEBUG, "Returning assoc %p", assoc); 475 udp_assoc_addref(assoc); 476 fibril_mutex_unlock(&assoc_list_lock); 477 return assoc; 478 } else { 479 log_msg(LOG_DEFAULT, LVL_NOTE, "not matched"); 480 } 481 } 482 483 log_msg(LOG_DEFAULT, LVL_NOTE, "associations END"); 411 rc = amap_find_match(amap, epp, &arg); 412 if (rc != EOK) { 413 assert(rc == ENOMEM); 414 fibril_mutex_unlock(&assoc_list_lock); 415 return NULL; 416 } 417 418 assoc = (udp_assoc_t *)arg; 419 udp_assoc_addref(assoc); 420 484 421 fibril_mutex_unlock(&assoc_list_lock); 485 return NULL;422 return assoc; 486 423 } 487 424 -
uspace/srv/net/udp/pdu.c
rab6326bc r8d48c7e 179 179 hdr = (udp_header_t *)pdu->data; 180 180 181 epp->local_link = pdu->iplink; 181 182 epp->remote.port = uint16_t_be2host(hdr->src_port); 182 183 epp->remote.addr = pdu->src; -
uspace/srv/net/udp/udp_inet.c
rab6326bc r8d48c7e 63 63 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_inet_ev_recv()"); 64 64 65 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_inet_ev_recv: link=%zu", 66 dgram->iplink); 67 65 68 pdu = udp_pdu_new(); 69 pdu->iplink = dgram->iplink; 66 70 pdu->data = dgram->data; 67 71 pdu->data_size = dgram->size;
Note:
See TracChangeset
for help on using the changeset viewer.