Changeset 46ae62c in mainline
- Timestamp:
- 2010-11-04T18:26:43Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a873201
- Parents:
- d8f95529
- Location:
- uspace/srv/net/tl/udp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/udp/udp.c
rd8f95529 r46ae62c 51 51 #include <adt/dynamic_fifo.h> 52 52 #include <errno.h> 53 #include <err.h>54 53 55 54 #include <net/socket_codes.h> … … 103 102 int udp_initialize(async_client_conn_t client_connection) 104 103 { 105 ERROR_DECLARE;106 107 104 measured_string_t names[] = { 108 105 { … … 118 115 size_t count = sizeof(names) / sizeof(measured_string_t); 119 116 char *data; 117 int rc; 120 118 121 119 fibril_rwlock_initialize(&udp_globals.lock); … … 124 122 udp_globals.icmp_phone = icmp_connect_module(SERVICE_ICMP, 125 123 ICMP_CONNECT_TIMEOUT); 124 126 125 udp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_UDP, 127 126 SERVICE_UDP, client_connection); 128 if (udp_globals.ip_phone < 0) 127 if (udp_globals.ip_phone < 0) { 128 fibril_rwlock_write_unlock(&udp_globals.lock); 129 129 return udp_globals.ip_phone; 130 } 130 131 131 132 // read default packet dimensions 132 ERROR_PROPAGATE(ip_packet_size_req(udp_globals.ip_phone, -1, 133 &udp_globals.packet_dimension)); 134 ERROR_PROPAGATE(socket_ports_initialize(&udp_globals.sockets)); 135 if (ERROR_OCCURRED(packet_dimensions_initialize( 136 &udp_globals.dimensions))) { 133 rc = ip_packet_size_req(udp_globals.ip_phone, -1, 134 &udp_globals.packet_dimension); 135 if (rc != EOK) { 136 fibril_rwlock_write_unlock(&udp_globals.lock); 137 return rc; 138 } 139 140 rc = socket_ports_initialize(&udp_globals.sockets); 141 if (rc != EOK) { 142 fibril_rwlock_write_unlock(&udp_globals.lock); 143 return rc; 144 } 145 146 rc = packet_dimensions_initialize(&udp_globals.dimensions); 147 if (rc != EOK) { 137 148 socket_ports_destroy(&udp_globals.sockets); 138 return ERROR_CODE; 139 } 149 fibril_rwlock_write_unlock(&udp_globals.lock); 150 return rc; 151 } 152 140 153 udp_globals.packet_dimension.prefix += sizeof(udp_header_t); 141 154 udp_globals.packet_dimension.content -= sizeof(udp_header_t); … … 147 160 // get configuration 148 161 configuration = &names[0]; 149 ERROR_PROPAGATE(net_get_conf_req(udp_globals.net_phone, &configuration, 150 count, &data)); 162 rc = net_get_conf_req(udp_globals.net_phone, &configuration, count, 163 &data); 164 if (rc != EOK) { 165 socket_ports_destroy(&udp_globals.sockets); 166 fibril_rwlock_write_unlock(&udp_globals.lock); 167 return rc; 168 } 169 151 170 if (configuration) { 152 171 if (configuration[0].value) … … 201 220 udp_process_packet(device_id_t device_id, packet_t packet, services_t error) 202 221 { 203 ERROR_DECLARE;204 205 222 size_t length; 206 223 size_t offset; … … 219 236 struct sockaddr *dest; 220 237 packet_dimension_ref packet_dimension; 238 int rc; 221 239 222 240 switch (error) { … … 232 250 return udp_release_and_return(packet, result); 233 251 length = (size_t) result; 234 if (ERROR_OCCURRED(packet_trim(packet, length, 0)))235 return udp_release_and_return(packet,236 ERROR_CODE);252 rc = packet_trim(packet, length, 0); 253 if (rc != EOK) 254 return udp_release_and_return(packet, rc); 237 255 break; 238 256 default: … … 253 271 254 272 // trim all but UDP header 255 if (ERROR_OCCURRED(packet_trim(packet, offset, 0))) 256 return udp_release_and_return(packet, ERROR_CODE); 273 rc = packet_trim(packet, offset, 0); 274 if (rc != EOK) 275 return udp_release_and_return(packet, rc); 257 276 258 277 // get udp header … … 284 303 if (result <= 0) 285 304 return udp_release_and_return(packet, result); 286 287 if (ERROR_OCCURRED(ip_client_get_pseudo_header(IPPROTO_UDP,288 src, result, dest, result, total_length, &ip_header,289 &length))) {290 return udp_release_and_return(packet, ERROR_CODE);305 306 rc = ip_client_get_pseudo_header(IPPROTO_UDP, src, result, dest, 307 result, total_length, &ip_header, &length); 308 if (rc != EOK) { 309 return udp_release_and_return(packet, rc); 291 310 } else { 292 311 checksum = compute_checksum(0, ip_header, length); … … 307 326 308 327 if (total_length < length) { 309 if (ERROR_OCCURRED(packet_trim(next_packet, 0, 310 length - total_length))) { 311 return udp_release_and_return(packet, 312 ERROR_CODE); 313 } 328 rc = packet_trim(next_packet, 0, length - total_length); 329 if (rc != EOK) 330 return udp_release_and_return(packet, rc); 314 331 315 332 // add partial checksum if set … … 360 377 361 378 // queue the received packet 362 if (ERROR_OCCURRED(dyn_fifo_push(&socket->received, 363 packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE)) || 364 ERROR_OCCURRED(tl_get_ip_packet_dimension(udp_globals.ip_phone, 365 &udp_globals.dimensions, device_id, &packet_dimension))) { 366 return udp_release_and_return(packet, ERROR_CODE); 367 } 379 rc = dyn_fifo_push(&socket->received, packet_get_id(packet), 380 SOCKET_MAX_RECEIVED_SIZE); 381 if (rc != EOK) 382 return udp_release_and_return(packet, rc); 383 384 rc = tl_get_ip_packet_dimension(udp_globals.ip_phone, 385 &udp_globals.dimensions, device_id, &packet_dimension); 386 if (rc != EOK) 387 return udp_release_and_return(packet, rc); 368 388 369 389 // notify the destination socket … … 436 456 size_t *data_fragment_size, int flags) 437 457 { 438 ERROR_DECLARE;439 440 458 socket_core_ref socket; 441 459 packet_t packet; … … 451 469 device_id_t device_id; 452 470 packet_dimension_ref packet_dimension; 453 454 ERROR_PROPAGATE(tl_get_address_port(addr, addrlen, &dest_port)); 471 int rc; 472 473 rc = tl_get_address_port(addr, addrlen, &dest_port); 474 if (rc != EOK) 475 return rc; 455 476 456 477 socket = socket_cores_find(local_sockets, socket_id); … … 466 487 // might be changed in the meantime 467 488 // if (socket->port <= 0) { 468 if (ERROR_OCCURRED(socket_bind_free_port( 469 &udp_globals.sockets, socket, 470 UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, 471 udp_globals.last_used_port))) { 489 rc = socket_bind_free_port(&udp_globals.sockets, 490 socket, UDP_FREE_PORTS_START, 491 UDP_FREE_PORTS_END, 492 udp_globals.last_used_port); 493 if (rc != EOK) { 472 494 // fibril_rwlock_write_unlock( 473 495 // &udp_globals.lock); 474 496 // fibril_rwlock_read_lock( 475 497 // &udp_globals.lock); 476 return ERROR_CODE;498 return rc; 477 499 } 478 500 // set the next port as the search starting port … … 487 509 488 510 if (udp_globals.checksum_computing) { 489 if (ERROR_OCCURRED(ip_get_route_req(udp_globals.ip_phone, 490 IPPROTO_UDP, addr, addrlen, &device_id, &ip_header, 491 &headerlen))) { 492 return udp_release_and_return(packet, ERROR_CODE); 493 } 511 rc = ip_get_route_req(udp_globals.ip_phone, IPPROTO_UDP, addr, 512 addrlen, &device_id, &ip_header, &headerlen); 513 if (rc != EOK) 514 return udp_release_and_return(packet, rc); 494 515 // get the device packet dimension 495 // ERROR_PROPAGATE(tl_get_ip_packet_dimension(udp_globals.ip_phone, 496 // &udp_globals.dimensions, device_id, &packet_dimension)); 516 // rc = tl_get_ip_packet_dimension(udp_globals.ip_phone, 517 // &udp_globals.dimensions, device_id, &packet_dimension); 518 // if (rc != EOK) 519 // return rc; 497 520 } 498 521 // } else { 499 522 // do not ask all the time 500 ERROR_PROPAGATE(ip_packet_size_req(udp_globals.ip_phone, -1, 501 &udp_globals.packet_dimension)); 523 rc = ip_packet_size_req(udp_globals.ip_phone, -1, 524 &udp_globals.packet_dimension); 525 if (rc != EOK) 526 return rc; 502 527 packet_dimension = &udp_globals.packet_dimension; 503 528 // } … … 529 554 return udp_release_and_return(packet, result); 530 555 531 if (ERROR_OCCURRED(pq_add(&packet, next_packet, index, 0))) 532 return udp_release_and_return(packet, ERROR_CODE); 556 rc = pq_add(&packet, next_packet, index, 0); 557 if (rc != EOK) 558 return udp_release_and_return(packet, rc); 533 559 534 560 total_length += (size_t) result; … … 547 573 if (udp_globals.checksum_computing) { 548 574 // update the pseudo header 549 if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length( 550 ip_header, headerlen, total_length + UDP_HEADER_SIZE))) { 575 rc = ip_client_set_pseudo_header_data_length(ip_header, 576 headerlen, total_length + UDP_HEADER_SIZE); 577 if (rc != EOK) { 551 578 free(ip_header); 552 return udp_release_and_return(packet, ERROR_CODE);579 return udp_release_and_return(packet, rc); 553 580 } 554 581 … … 565 592 566 593 // prepare the first packet fragment 567 if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 568 0, 0))) { 569 return udp_release_and_return(packet, ERROR_CODE); 570 } 594 rc = ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 0, 0); 595 if (rc != EOK) 596 return udp_release_and_return(packet, rc); 571 597 572 598 // send the packet … … 600 626 size_t *addrlen) 601 627 { 602 ERROR_DECLARE;603 604 628 socket_core_ref socket; 605 629 int packet_id; … … 610 634 uint8_t *data; 611 635 int result; 636 int rc; 612 637 613 638 // find the socket … … 620 645 if (packet_id < 0) 621 646 return NO_DATA; 622 623 ERROR_PROPAGATE(packet_translate_remote(udp_globals.net_phone, &packet, 624 packet_id)); 647 648 rc = packet_translate_remote(udp_globals.net_phone, &packet, packet_id); 649 if (rc != EOK) 650 return rc; 625 651 626 652 // get udp header … … 634 660 // set the source address port 635 661 result = packet_get_addr(packet, (uint8_t **) &addr, NULL); 636 if (ERROR_OCCURRED(tl_set_address_port(addr, result,637 ntohs(header->source_port)))) {662 rc = tl_set_address_port(addr, result, ntohs(header->source_port)); 663 if (rc != EOK) { 638 664 pq_release_remote(udp_globals.net_phone, packet_id); 639 return ERROR_CODE;665 return rc; 640 666 } 641 667 *addrlen = (size_t) result; 642 668 643 669 // send the source address 644 ERROR_PROPAGATE(data_reply(addr, *addrlen)); 670 rc = data_reply(addr, *addrlen); 671 if (rc != EOK) 672 return rc; 645 673 646 674 // trim the header 647 ERROR_PROPAGATE(packet_trim(packet, UDP_HEADER_SIZE, 0)); 675 rc = packet_trim(packet, UDP_HEADER_SIZE, 0); 676 if (rc != EOK) 677 return rc; 648 678 649 679 // reply the packets 650 ERROR_PROPAGATE(socket_reply_packets(packet, &length)); 680 rc = socket_reply_packets(packet, &length); 681 if (rc != EOK) 682 return rc; 651 683 652 684 // release the packet … … 826 858 ipc_call_t *answer, int *answer_count) 827 859 { 828 ERROR_DECLARE;829 830 860 packet_t packet; 861 int rc; 831 862 832 863 *answer_count = 0; … … 834 865 switch (IPC_GET_METHOD(*call)) { 835 866 case NET_TL_RECEIVED: 836 if (ERROR_NONE(packet_translate_remote(udp_globals.net_phone, 837 &packet, IPC_GET_PACKET(call)))) { 838 ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call), 839 packet, SERVICE_UDP, IPC_GET_ERROR(call)); 840 } 841 return ERROR_CODE; 842 867 rc = packet_translate_remote(udp_globals.net_phone, &packet, 868 IPC_GET_PACKET(call)); 869 if (rc != EOK) 870 return rc; 871 return udp_received_msg(IPC_GET_DEVICE(call), packet, 872 SERVICE_UDP, IPC_GET_ERROR(call)); 843 873 case IPC_M_CONNECT_TO_ME: 844 874 return udp_process_client_messages(callid, * call); … … 850 880 /** Default thread for new connections. 851 881 * 852 * @param[in] iid The initial message identifier. 853 * @param[in] icall The initial message call structure. 854 * 882 * @param[in] iid The initial message identifier. 883 * @param[in] icall The initial message call structure. 855 884 */ 856 885 static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall) … … 898 927 int main(int argc, char *argv[]) 899 928 { 900 ERROR_DECLARE;929 int rc; 901 930 902 931 /* Start the module */ 903 if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection))) 904 return ERROR_CODE; 905 906 return EOK; 932 rc = tl_module_start_standalone(tl_client_connection); 933 return rc; 907 934 } 908 935 -
uspace/srv/net/tl/udp/udp_module.c
rd8f95529 r46ae62c 44 44 #include <async.h> 45 45 #include <stdio.h> 46 #include <err .h>46 #include <errno.h> 47 47 #include <ipc/ipc.h> 48 48 #include <ipc/services.h> … … 59 59 int tl_module_start_standalone(async_client_conn_t client_connection) 60 60 { 61 ERROR_DECLARE;62 63 61 ipcarg_t phonehash; 62 int rc; 64 63 65 64 async_set_client_connection(client_connection); … … 67 66 if (udp_globals.net_phone < 0) 68 67 return udp_globals.net_phone; 69 70 ERROR_PROPAGATE(pm_init()); 71 if (ERROR_OCCURRED(udp_initialize(client_connection)) || 72 ERROR_OCCURRED(REGISTER_ME(SERVICE_UDP, &phonehash))) { 73 pm_destroy(); 74 return ERROR_CODE; 75 } 68 69 rc = pm_init(); 70 if (rc != EOK) 71 return EOK; 72 73 rc = udp_initialize(client_connection); 74 if (rc != EOK) 75 goto out; 76 77 rc = REGISTER_ME(SERVICE_UDP, &phonehash); 78 if (rc != EOK) 79 goto out; 76 80 77 81 async_manager(); 78 82 83 out: 79 84 pm_destroy(); 80 return EOK;85 return rc; 81 86 } 82 87
Note:
See TracChangeset
for help on using the changeset viewer.