Changeset 0b81cad0 in mainline
- Timestamp:
- 2010-11-06T00:19:13Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1712f87
- Parents:
- 0485135 (diff), 0578271 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/packet/generic/packet_server.c
r0485135 r0b81cad0 212 212 213 213 for (index = 0; index < FREE_QUEUES_COUNT; index++) { 214 if (length > ps_globals.sizes[index]) 214 if ((length > ps_globals.sizes[index]) && 215 (index < FREE_QUEUES_COUNT - 1)) 215 216 continue; 216 217 -
uspace/srv/net/il/arp/arp.c
r0485135 r0b81cad0 55 55 #include <ipc/il.h> 56 56 #include <byteorder.h> 57 #include <err .h>57 #include <errno.h> 58 58 59 59 #include <net/modules.h> … … 179 179 measured_string_ref address) 180 180 { 181 ERROR_DECLARE;181 int rc; 182 182 183 183 *proto = (arp_proto_ref) malloc(sizeof(arp_proto_t)); 184 184 if (!*proto) 185 185 return ENOMEM; 186 186 187 (*proto)->service = service; 187 188 (*proto)->addr = address; 188 189 (*proto)->addr_data = address->value; 189 if (ERROR_OCCURRED(arp_addr_initialize(&(*proto)->addresses))) { 190 191 rc = arp_addr_initialize(&(*proto)->addresses); 192 if (rc != EOK) { 190 193 free(*proto); 191 return ERROR_CODE; 192 } 194 return rc; 195 } 196 193 197 return EOK; 194 198 } … … 214 218 services_t protocol, measured_string_ref address) 215 219 { 216 ERROR_DECLARE;217 218 220 arp_device_ref device; 219 221 arp_proto_ref proto; 222 hw_type_t hardware; 220 223 int index; 221 hw_type_t hardware;224 int rc; 222 225 223 226 fibril_rwlock_write_lock(&arp_globals.lock); … … 237 240 proto->addr_data = address->value; 238 241 } else { 239 if (ERROR_OCCURRED(arp_proto_create(&proto, protocol,240 address))) {242 rc = arp_proto_create(&proto, protocol, address); 243 if (rc != EOK) { 241 244 fibril_rwlock_write_unlock(&arp_globals.lock); 242 return ERROR_CODE;245 return rc; 243 246 } 244 247 index = arp_protos_add(&device->protos, proto->service, … … 265 268 device->hardware = hardware; 266 269 device->device_id = device_id; 267 if (ERROR_OCCURRED(arp_protos_initialize(&device->protos)) || 268 ERROR_OCCURRED(arp_proto_create(&proto, protocol, 269 address))) { 270 rc = arp_protos_initialize(&device->protos); 271 if (rc != EOK) { 270 272 fibril_rwlock_write_unlock(&arp_globals.lock); 271 273 free(device); 272 return ERROR_CODE; 274 return rc; 275 } 276 rc = arp_proto_create(&proto, protocol, address); 277 if (rc != EOK) { 278 fibril_rwlock_write_unlock(&arp_globals.lock); 279 free(device); 280 return rc; 273 281 } 274 282 index = arp_protos_add(&device->protos, proto->service, proto); … … 293 301 294 302 // get packet dimensions 295 if (ERROR_OCCURRED(nil_packet_size_req(device->phone, device_id, 296 &device->packet_dimension))) { 303 rc = nil_packet_size_req(device->phone, device_id, 304 &device->packet_dimension); 305 if (rc != EOK) { 297 306 fibril_rwlock_write_unlock(&arp_globals.lock); 298 307 arp_protos_destroy(&device->protos); 299 308 free(device); 300 return ERROR_CODE;309 return rc; 301 310 } 302 311 303 312 // get hardware address 304 if (ERROR_OCCURRED(nil_get_addr_req(device->phone, device_id, 305 &device->addr, &device->addr_data))) { 313 rc = nil_get_addr_req(device->phone, device_id, &device->addr, 314 &device->addr_data); 315 if (rc != EOK) { 306 316 fibril_rwlock_write_unlock(&arp_globals.lock); 307 317 arp_protos_destroy(&device->protos); 308 318 free(device); 309 return ERROR_CODE;319 return rc; 310 320 } 311 321 312 322 // get broadcast address 313 if (ERROR_OCCURRED(nil_get_broadcast_addr_req(device->phone,314 device_id, &device->broadcast_addr,315 &device->broadcast_data))) {323 rc = nil_get_broadcast_addr_req(device->phone, device_id, 324 &device->broadcast_addr, &device->broadcast_data); 325 if (rc != EOK) { 316 326 fibril_rwlock_write_unlock(&arp_globals.lock); 317 327 free(device->addr); … … 319 329 arp_protos_destroy(&device->protos); 320 330 free(device); 321 return ERROR_CODE; 322 } 323 324 if (ERROR_OCCURRED(arp_cache_add(&arp_globals.cache, 325 device->device_id, device))) { 331 return rc; 332 } 333 334 rc = arp_cache_add(&arp_globals.cache, device->device_id, 335 device); 336 if (rc != EOK) { 326 337 fibril_rwlock_write_unlock(&arp_globals.lock); 327 338 free(device->addr); … … 331 342 arp_protos_destroy(&device->protos); 332 343 free(device); 333 return ERROR_CODE;344 return rc; 334 345 } 335 346 printf("%s: Device registered (id: %d, type: 0x%x, service: %d," … … 351 362 int arp_initialize(async_client_conn_t client_connection) 352 363 { 353 ERROR_DECLARE;364 int rc; 354 365 355 366 fibril_rwlock_initialize(&arp_globals.lock); 356 367 fibril_rwlock_write_lock(&arp_globals.lock); 357 368 arp_globals.client_connection = client_connection; 358 ERROR_PROPAGATE(arp_cache_initialize(&arp_globals.cache));369 rc = arp_cache_initialize(&arp_globals.cache); 359 370 fibril_rwlock_write_unlock(&arp_globals.lock); 360 return EOK; 371 372 return rc; 361 373 } 362 374 … … 406 418 static int arp_receive_message(device_id_t device_id, packet_t packet) 407 419 { 408 ERROR_DECLARE;409 410 420 size_t length; 411 421 arp_header_ref header; … … 417 427 uint8_t *des_hw; 418 428 uint8_t *des_proto; 429 int rc; 419 430 420 431 length = packet_get_data_length(packet); … … 467 478 return ENOMEM; 468 479 469 ERROR_PROPAGATE(arp_addr_add(&proto->addresses, 470 (char *) src_proto, CONVERT_SIZE(uint8_t, char, 471 header->protocol_length), hw_source)); 480 rc = arp_addr_add(&proto->addresses, (char *) src_proto, 481 CONVERT_SIZE(uint8_t, char, 482 header->protocol_length), hw_source); 483 if (rc != EOK) 484 return rc; 472 485 } 473 486 if (ntohs(header->operation) == ARPOP_REQUEST) { … … 480 493 memcpy(des_hw, hw_source->value, 481 494 header->hardware_length); 482 ERROR_PROPAGATE(packet_set_addr(packet, src_hw, des_hw, 483 header->hardware_length)); 495 496 rc = packet_set_addr(packet, src_hw, des_hw, 497 header->hardware_length); 498 if (rc != EOK) 499 return rc; 500 484 501 nil_send_msg(device->phone, device_id, packet, 485 502 SERVICE_ARP); … … 596 613 ipc_call_t *answer, int *answer_count) 597 614 { 598 ERROR_DECLARE;599 600 615 measured_string_ref address; 601 616 measured_string_ref translation; … … 603 618 packet_t packet; 604 619 packet_t next; 620 int rc; 605 621 606 622 *answer_count = 0; … … 610 626 611 627 case NET_ARP_DEVICE: 612 ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1)); 613 if (ERROR_OCCURRED(arp_device_message(IPC_GET_DEVICE(call), 614 IPC_GET_SERVICE(call), ARP_GET_NETIF(call), address))) { 628 rc = measured_strings_receive(&address, &data, 1); 629 if (rc != EOK) 630 return rc; 631 632 rc = arp_device_message(IPC_GET_DEVICE(call), 633 IPC_GET_SERVICE(call), ARP_GET_NETIF(call), address); 634 if (rc != EOK) { 615 635 free(address); 616 636 free(data); 617 637 } 618 return ERROR_CODE;638 return rc; 619 639 620 640 case NET_ARP_TRANSLATE: 621 ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1)); 641 rc = measured_strings_receive(&address, &data, 1); 642 if (rc != EOK) 643 return rc; 644 622 645 fibril_rwlock_read_lock(&arp_globals.lock); 623 646 translation = arp_translate_message(IPC_GET_DEVICE(call), … … 629 652 return ENOENT; 630 653 } 631 ERROR_CODE= measured_strings_reply(translation, 1);654 rc = measured_strings_reply(translation, 1); 632 655 fibril_rwlock_read_unlock(&arp_globals.lock); 633 return ERROR_CODE;656 return rc; 634 657 635 658 case NET_ARP_CLEAR_DEVICE: … … 637 660 638 661 case NET_ARP_CLEAR_ADDRESS: 639 ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1)); 662 rc = measured_strings_receive(&address, &data, 1); 663 if (rc != EOK) 664 return rc; 665 640 666 arp_clear_address_req(0, IPC_GET_DEVICE(call), 641 667 IPC_GET_SERVICE(call), address); … … 652 678 653 679 case NET_IL_RECEIVED: 654 if (ERROR_NONE(packet_translate_remote(arp_globals.net_phone, 655 &packet, IPC_GET_PACKET(call)))) { 656 fibril_rwlock_read_lock(&arp_globals.lock); 657 do { 658 next = pq_detach(packet); 659 ERROR_CODE = 660 arp_receive_message(IPC_GET_DEVICE(call), 661 packet); 662 if (ERROR_CODE != 1) { 663 pq_release_remote(arp_globals.net_phone, 664 packet_get_id(packet)); 665 } 666 packet = next; 667 } while (packet); 668 fibril_rwlock_read_unlock(&arp_globals.lock); 669 } 670 return ERROR_CODE; 680 rc = packet_translate_remote(arp_globals.net_phone, &packet, 681 IPC_GET_PACKET(call)); 682 if (rc != EOK) 683 return rc; 684 685 fibril_rwlock_read_lock(&arp_globals.lock); 686 do { 687 next = pq_detach(packet); 688 rc = arp_receive_message(IPC_GET_DEVICE(call), packet); 689 if (rc != 1) { 690 pq_release_remote(arp_globals.net_phone, 691 packet_get_id(packet)); 692 } 693 packet = next; 694 } while (packet); 695 fibril_rwlock_read_unlock(&arp_globals.lock); 696 697 return EOK; 671 698 672 699 case NET_IL_MTU_CHANGED: … … 727 754 int main(int argc, char *argv[]) 728 755 { 729 ERROR_DECLARE;756 int rc; 730 757 731 758 /* Start the module */ 732 ERROR_PROPAGATE(il_module_start_standalone(il_client_connection));733 return EOK;759 rc = il_module_start_standalone(il_client_connection); 760 return rc; 734 761 } 735 762 -
uspace/srv/net/il/arp/arp_module.c
r0485135 r0b81cad0 41 41 #include <async.h> 42 42 #include <stdio.h> 43 #include <err .h>43 #include <errno.h> 44 44 45 45 #include <ipc/ipc.h> … … 66 66 int il_module_start_standalone(async_client_conn_t client_connection) 67 67 { 68 ERROR_DECLARE; 68 ipcarg_t phonehash; 69 int rc; 69 70 70 71 async_set_client_connection(client_connection); 71 72 arp_globals.net_phone = net_connect_module(); 72 ERROR_PROPAGATE(pm_init());73 73 74 ipcarg_t phonehash; 75 if (ERROR_OCCURRED(arp_initialize(client_connection)) || 76 ERROR_OCCURRED(REGISTER_ME(SERVICE_ARP, &phonehash))) { 77 pm_destroy(); 78 return ERROR_CODE; 79 } 74 rc = pm_init(); 75 if (rc != EOK) 76 return rc; 77 78 rc = arp_initialize(client_connection); 79 if (rc != EOK) 80 goto out; 81 82 rc = REGISTER_ME(SERVICE_ARP, &phonehash); 83 if (rc != EOK) 84 goto out; 80 85 81 86 async_manager(); 82 87 88 out: 83 89 pm_destroy(); 84 return EOK;90 return rc; 85 91 } 86 92 -
uspace/srv/net/il/ip/ip.c
r0485135 r0b81cad0 41 41 #include <async.h> 42 42 #include <errno.h> 43 #include <err.h>44 43 #include <fibril_synch.h> 45 44 #include <stdio.h> … … 254 253 int ip_initialize(async_client_conn_t client_connection) 255 254 { 256 ERROR_DECLARE;255 int rc; 257 256 258 257 fibril_rwlock_initialize(&ip_globals.lock); … … 265 264 ip_globals.gateway.gateway.s_addr = 0; 266 265 ip_globals.gateway.netif = NULL; 267 ERROR_PROPAGATE(ip_netifs_initialize(&ip_globals.netifs));268 ERROR_PROPAGATE(ip_protos_initialize(&ip_globals.protos));269 266 ip_globals.client_connection = client_connection; 270 ERROR_PROPAGATE(modules_initialize(&ip_globals.modules)); 271 ERROR_PROPAGATE(add_module(NULL, &ip_globals.modules, ARP_NAME, 272 ARP_FILENAME, SERVICE_ARP, 0, arp_connect_module)); 267 268 rc = ip_netifs_initialize(&ip_globals.netifs); 269 if (rc != EOK) 270 goto out; 271 rc = ip_protos_initialize(&ip_globals.protos); 272 if (rc != EOK) 273 goto out; 274 rc = modules_initialize(&ip_globals.modules); 275 if (rc != EOK) 276 goto out; 277 rc = add_module(NULL, &ip_globals.modules, ARP_NAME, ARP_FILENAME, 278 SERVICE_ARP, 0, arp_connect_module); 279 280 out: 273 281 fibril_rwlock_write_unlock(&ip_globals.lock); 274 282 275 return EOK;283 return rc; 276 284 } 277 285 … … 302 310 static int ip_netif_initialize(ip_netif_ref ip_netif) 303 311 { 304 ERROR_DECLARE;305 306 312 measured_string_t names[] = { 307 313 { … … 342 348 char *data; 343 349 measured_string_t address; 344 int index;345 350 ip_route_ref route; 346 351 in_addr_t gateway; 352 int index; 353 int rc; 347 354 348 355 ip_netif->arp = NULL; … … 354 361 355 362 // get configuration 356 ERROR_PROPAGATE(net_get_device_conf_req(ip_globals.net_phone, 357 ip_netif->device_id, &configuration, count, &data)); 363 rc = net_get_device_conf_req(ip_globals.net_phone, ip_netif->device_id, 364 &configuration, count, &data); 365 if (rc != EOK) 366 return rc; 367 358 368 if (configuration) { 359 369 if (configuration[0].value) … … 383 393 return index; 384 394 } 385 if (ERROR_OCCURRED(inet_pton(AF_INET, 386 configuration[2].value, 387 (uint8_t *) &route->address.s_addr)) || 388 ERROR_OCCURRED(inet_pton(AF_INET, 389 configuration[3].value, 390 (uint8_t *) &route->netmask.s_addr)) || 395 396 if ((inet_pton(AF_INET, configuration[2].value, 397 (uint8_t *) &route->address.s_addr) != EOK) || 398 (inet_pton(AF_INET, configuration[3].value, 399 (uint8_t *) &route->netmask.s_addr) != EOK) || 391 400 (inet_pton(AF_INET, configuration[4].value, 392 401 (uint8_t *) &gateway.s_addr) == EINVAL) || … … 434 443 address.value = (char *) &route->address.s_addr; 435 444 address.length = CONVERT_SIZE(in_addr_t, char, 1); 436 ERROR_PROPAGATE(arp_device_req(ip_netif->arp->phone, 445 446 rc = arp_device_req(ip_netif->arp->phone, 437 447 ip_netif->device_id, SERVICE_IP, ip_netif->service, 438 &address)); 448 &address); 449 if (rc != EOK) 450 return rc; 439 451 } else { 440 452 ip_netif->arp = 0; … … 443 455 444 456 // get packet dimensions 445 ERROR_PROPAGATE(nil_packet_size_req(ip_netif->phone, 446 ip_netif->device_id, &ip_netif->packet_dimension)); 457 rc = nil_packet_size_req(ip_netif->phone, ip_netif->device_id, 458 &ip_netif->packet_dimension); 459 if (rc != EOK) 460 return rc; 461 447 462 if (ip_netif->packet_dimension.content < IP_MIN_CONTENT) { 448 463 printf("Maximum transmission unit %d bytes is too small, at " … … 610 625 measured_string_ref destination) 611 626 { 612 ERROR_DECLARE;613 614 627 size_t length; 615 628 ip_header_ref header; … … 617 630 ip_header_ref middle_header; 618 631 packet_t next; 632 int rc; 619 633 620 634 length = packet_get_data_length(packet); … … 624 638 header = (ip_header_ref) packet_get_data(packet); 625 639 if (destination) { 626 ERROR_PROPAGATE(packet_set_addr(packet, NULL, 627 (uint8_t *) destination->value, 628 CONVERT_SIZE(char, uint8_t, destination->length))); 640 rc = packet_set_addr(packet, NULL, (uint8_t *) destination->value, 641 CONVERT_SIZE(char, uint8_t, destination->length)); 629 642 } else { 630 ERROR_PROPAGATE(packet_set_addr(packet, NULL, NULL, 0)); 631 } 643 rc = packet_set_addr(packet, NULL, NULL, 0); 644 } 645 if (rc != EOK) 646 return rc; 647 632 648 header->version = IPV4; 633 649 header->fragment_offset_high = 0; … … 669 685 IP_HEADER_CHECKSUM(middle_header); 670 686 if (destination) { 671 if (ERROR_OCCURRED(packet_set_addr(next, NULL,687 rc = packet_set_addr(next, NULL, 672 688 (uint8_t *) destination->value, 673 689 CONVERT_SIZE(char, uint8_t, 674 destination->length)))) { 690 destination->length)); 691 if (rc != EOK) { 675 692 free(last_header); 676 return ERROR_CODE;693 return rc; 677 694 } 678 695 } … … 699 716 IP_HEADER_CHECKSUM(middle_header); 700 717 if (destination) { 701 if (ERROR_OCCURRED(packet_set_addr(next, NULL,718 rc = packet_set_addr(next, NULL, 702 719 (uint8_t *) destination->value, 703 CONVERT_SIZE(char, uint8_t, 704 destination->length)))) {720 CONVERT_SIZE(char, uint8_t, destination->length)); 721 if (rc != EOK) { 705 722 free(last_header); 706 return ERROR_CODE;707 723 return rc; 724 } 708 725 } 709 726 length += packet_get_data_length(next); … … 741 758 const struct sockaddr *src, const struct sockaddr *dest, socklen_t addrlen) 742 759 { 743 ERROR_DECLARE;744 745 760 void *data; 746 761 size_t offset; 762 int rc; 747 763 748 764 data = packet_suffix(new_packet, length); … … 752 768 memcpy(data, ((void *) header) + IP_TOTAL_LENGTH(header) - length, 753 769 length); 754 ERROR_PROPAGATE(packet_trim(packet, 0, length)); 770 771 rc = packet_trim(packet, 0, length); 772 if (rc != EOK) 773 return rc; 774 755 775 header->total_length = htons(IP_TOTAL_LENGTH(header) - length); 756 776 new_header->total_length = htons(IP_HEADER_LENGTH(new_header) + length); … … 761 781 IP_COMPUTE_FRAGMENT_OFFSET_LOW(offset); 762 782 new_header->header_checksum = IP_HEADER_CHECKSUM(new_header); 763 ERROR_PROPAGATE(packet_set_addr(new_packet, (const uint8_t *) src, 764 (const uint8_t *) dest, addrlen)); 783 784 rc = packet_set_addr(new_packet, (const uint8_t *) src, 785 (const uint8_t *) dest, addrlen); 786 if (rc != EOK) 787 return rc; 765 788 766 789 return pq_insert_after(packet, new_packet); … … 796 819 socklen_t addr_len) 797 820 { 798 ERROR_DECLARE;799 800 821 packet_t new_packet; 801 822 ip_header_ref header; … … 806 827 socklen_t addrlen; 807 828 int result; 829 int rc; 808 830 809 831 result = packet_get_addr(packet, (uint8_t **) &src, (uint8_t **) &dest); … … 839 861 840 862 // trim the unused space 841 if (ERROR_OCCURRED(packet_trim(new_packet, 0,842 IP_HEADER_LENGTH(header) - IP_HEADER_LENGTH(last_header)) )) {843 return ip_release_and_return(packet, ERROR_CODE);844 }863 rc = packet_trim(new_packet, 0, 864 IP_HEADER_LENGTH(header) - IP_HEADER_LENGTH(last_header)); 865 if (rc != EOK) 866 return ip_release_and_return(packet, rc); 845 867 846 868 // biggest multiple of 8 lower than content 847 869 // TODO even fragmentation? 848 870 length = length & ~0x7; 849 if (ERROR_OCCURRED(ip_fragment_packet_data(packet, new_packet, header,850 871 872 rc = ip_fragment_packet_data(packet, new_packet, header, last_header, 851 873 ((IP_HEADER_DATA_LENGTH(header) - 852 874 ((length - IP_HEADER_LENGTH(header)) & ~0x7)) % 853 ((length - IP_HEADER_LENGTH(last_header)) & ~0x7)), src, dest,854 addrlen))) {855 return ip_release_and_return(packet, ERROR_CODE);856 }875 ((length - IP_HEADER_LENGTH(last_header)) & ~0x7)), 876 src, dest, addrlen); 877 if (rc != EOK) 878 return ip_release_and_return(packet, rc); 857 879 858 880 // mark the first as fragmented … … 872 894 return ip_release_and_return(packet, ENOMEM); 873 895 874 if (ERROR_OCCURRED(ip_fragment_packet_data(packet, new_packet,875 header,middle_header,876 (length - IP_HEADER_LENGTH(middle_header)) & ~0x7, src,877 dest, addrlen))) {878 return ip_release_and_return(packet, ERROR_CODE);879 }896 rc = ip_fragment_packet_data(packet, new_packet, header, 897 middle_header, 898 (length - IP_HEADER_LENGTH(middle_header)) & ~0x7, 899 src, dest, addrlen); 900 if (rc != EOK) 901 return ip_release_and_return(packet, rc); 880 902 } 881 903 … … 974 996 in_addr_t *src, in_addr_t dest, services_t error) 975 997 { 976 ERROR_DECLARE;977 978 998 measured_string_t destination; 979 999 measured_string_ref translation; 980 1000 char *data; 981 1001 int phone; 1002 int rc; 982 1003 983 1004 // get destination hardware address … … 987 1008 destination.length = CONVERT_SIZE(dest.s_addr, char, 1); 988 1009 989 if (ERROR_OCCURRED(arp_translate_req(netif->arp->phone,990 netif->device_id, SERVICE_IP, &destination, &translation,991 &data))) {1010 rc = arp_translate_req(netif->arp->phone, netif->device_id, 1011 SERVICE_IP, &destination, &translation, &data); 1012 if (rc != EOK) { 992 1013 pq_release_remote(ip_globals.net_phone, 993 1014 packet_get_id(packet)); 994 return ERROR_CODE;1015 return rc; 995 1016 } 996 1017 … … 1014 1035 } 1015 1036 1016 if (ERROR_OCCURRED(ip_prepare_packet(src, dest, packet, translation))) { 1037 rc = ip_prepare_packet(src, dest, packet, translation); 1038 if (rc != EOK) { 1017 1039 pq_release_remote(ip_globals.net_phone, packet_get_id(packet)); 1018 1040 } else { … … 1032 1054 } 1033 1055 1034 return ERROR_CODE;1056 return rc; 1035 1057 } 1036 1058 … … 1158 1180 ip_device_req_local(int il_phone, device_id_t device_id, services_t netif) 1159 1181 { 1160 ERROR_DECLARE;1161 1162 1182 ip_netif_ref ip_netif; 1163 1183 ip_route_ref route; 1164 1184 int index; 1185 int rc; 1165 1186 1166 1187 ip_netif = (ip_netif_ref) malloc(sizeof(ip_netif_t)); … … 1168 1189 return ENOMEM; 1169 1190 1170 if (ERROR_OCCURRED(ip_routes_initialize(&ip_netif->routes))) { 1191 rc = ip_routes_initialize(&ip_netif->routes); 1192 if (rc != EOK) { 1171 1193 free(ip_netif); 1172 return ERROR_CODE;1194 return rc; 1173 1195 } 1174 1196 … … 1178 1200 1179 1201 fibril_rwlock_write_lock(&ip_globals.netifs_lock); 1180 if (ERROR_OCCURRED(ip_netif_initialize(ip_netif))) { 1202 1203 rc = ip_netif_initialize(ip_netif); 1204 if (rc != EOK) { 1181 1205 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 1182 1206 ip_routes_destroy(&ip_netif->routes); 1183 1207 free(ip_netif); 1184 return ERROR_CODE;1208 return rc; 1185 1209 } 1186 1210 if (ip_netif->arp) … … 1226 1250 services_t sender, services_t error) 1227 1251 { 1228 ERROR_DECLARE;1229 1230 1252 int addrlen; 1231 1253 ip_netif_ref netif; … … 1236 1258 in_addr_t *src; 1237 1259 int phone; 1260 int rc; 1238 1261 1239 1262 // addresses in the host byte order … … 1323 1346 } 1324 1347 1325 ERROR_CODE= ip_send_route(packet, netif, route, src, *dest, error);1348 rc = ip_send_route(packet, netif, route, src, *dest, error); 1326 1349 fibril_rwlock_read_unlock(&ip_globals.netifs_lock); 1327 1350 1328 return ERROR_CODE;1351 return rc; 1329 1352 } 1330 1353 … … 1431 1454 services_t error) 1432 1455 { 1433 ERROR_DECLARE;1434 1435 1456 ip_proto_ref proto; 1436 1457 int phone; … … 1442 1463 struct sockaddr_in dest_in; 1443 1464 socklen_t addrlen; 1465 int rc; 1444 1466 1445 1467 if ((header->flags & IPFLAG_MORE_FRAGMENTS) || … … 1467 1489 } 1468 1490 1469 if (ERROR_OCCURRED(packet_set_addr(packet, (uint8_t *) src,1470 (uint8_t *) dest, addrlen))) {1471 return ip_release_and_return(packet, ERROR_CODE);1472 }1491 rc = packet_set_addr(packet, (uint8_t *) src, (uint8_t *) dest, 1492 addrlen); 1493 if (rc != EOK) 1494 return ip_release_and_return(packet, rc); 1473 1495 1474 1496 // trim padding if present 1475 1497 if (!error && 1476 1498 (IP_TOTAL_LENGTH(header) < packet_get_data_length(packet))) { 1477 if (ERROR_OCCURRED(packet_trim(packet, 0, 1478 packet_get_data_length(packet) - IP_TOTAL_LENGTH(header)))) 1479 return ip_release_and_return(packet, ERROR_CODE); 1499 rc = packet_trim(packet, 0, 1500 packet_get_data_length(packet) - IP_TOTAL_LENGTH(header)); 1501 if (rc != EOK) 1502 return ip_release_and_return(packet, rc); 1480 1503 } 1481 1504 … … 1498 1521 received_msg = proto->received_msg; 1499 1522 fibril_rwlock_read_unlock(&ip_globals.protos_lock); 1500 ERROR_CODE= received_msg(device_id, packet, service, error);1523 rc = received_msg(device_id, packet, service, error); 1501 1524 } else { 1502 ERROR_CODE= tl_received_msg(proto->phone, device_id, packet,1525 rc = tl_received_msg(proto->phone, device_id, packet, 1503 1526 proto->service, error); 1504 1527 fibril_rwlock_read_unlock(&ip_globals.protos_lock); 1505 1528 } 1506 1529 1507 return ERROR_CODE;1530 return rc; 1508 1531 } 1509 1532 … … 1532 1555 ip_process_packet(device_id_t device_id, packet_t packet) 1533 1556 { 1534 ERROR_DECLARE;1535 1536 1557 ip_header_ref header; 1537 1558 in_addr_t dest; … … 1541 1562 struct sockaddr_in addr_in; 1542 1563 socklen_t addrlen; 1564 int rc; 1543 1565 1544 1566 header = (ip_header_ref) packet_get_data(packet); … … 1585 1607 } 1586 1608 1587 ERROR_PROPAGATE(packet_set_addr(packet, NULL, (uint8_t *) &addr, 1588 addrlen)); 1609 rc = packet_set_addr(packet, NULL, (uint8_t *) &addr, addrlen); 1610 if (rc != EOK) 1611 return rc; 1589 1612 1590 1613 route = ip_find_route(dest); … … 1867 1890 int *answer_count) 1868 1891 { 1869 ERROR_DECLARE;1870 1871 1892 packet_t packet; 1872 1893 struct sockaddr *addr; … … 1878 1899 size_t headerlen; 1879 1900 device_id_t device_id; 1901 int rc; 1880 1902 1881 1903 *answer_count = 0; … … 1893 1915 1894 1916 case NET_IL_SEND: 1895 ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, 1896 &packet, IPC_GET_PACKET(call))); 1917 rc = packet_translate_remote(ip_globals.net_phone, &packet, 1918 IPC_GET_PACKET(call)); 1919 if (rc != EOK) 1920 return rc; 1897 1921 return ip_send_msg_local(0, IPC_GET_DEVICE(call), packet, 0, 1898 1922 IPC_GET_ERROR(call)); … … 1903 1927 1904 1928 case NET_IL_RECEIVED: 1905 ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, 1906 &packet, IPC_GET_PACKET(call))); 1929 rc = packet_translate_remote(ip_globals.net_phone, &packet, 1930 IPC_GET_PACKET(call)); 1931 if (rc != EOK) 1932 return rc; 1907 1933 return ip_receive_message(IPC_GET_DEVICE(call), packet); 1908 1934 1909 1935 case NET_IP_RECEIVED_ERROR: 1910 ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, 1911 &packet, IPC_GET_PACKET(call))); 1936 rc = packet_translate_remote(ip_globals.net_phone, &packet, 1937 IPC_GET_PACKET(call)); 1938 if (rc != EOK) 1939 return rc; 1912 1940 return ip_received_error_msg_local(0, IPC_GET_DEVICE(call), 1913 1941 packet, IPC_GET_TARGET(call), IPC_GET_ERROR(call)); … … 1923 1951 1924 1952 case NET_IP_GET_ROUTE: 1925 ERROR_PROPAGATE(data_receive((void **) &addr, &addrlen)); 1926 ERROR_PROPAGATE(ip_get_route_req_local(0, IP_GET_PROTOCOL(call), 1927 addr, (socklen_t) addrlen, &device_id, &header, 1928 &headerlen)); 1953 rc = data_receive((void **) &addr, &addrlen); 1954 if (rc != EOK) 1955 return rc; 1956 1957 rc = ip_get_route_req_local(0, IP_GET_PROTOCOL(call), addr, 1958 (socklen_t) addrlen, &device_id, &header, &headerlen); 1959 if (rc != EOK) 1960 return rc; 1961 1929 1962 IPC_SET_DEVICE(answer, device_id); 1930 1963 IP_SET_HEADERLEN(answer, headerlen); 1931 1964 1932 1965 *answer_count = 2; 1933 1934 if (ERROR_NONE(data_reply(&headerlen, sizeof(headerlen)))) 1935 ERROR_CODE = data_reply(header, headerlen); 1966 1967 rc = data_reply(&headerlen, sizeof(headerlen)); 1968 if (rc == EOK) 1969 rc = data_reply(header, headerlen); 1936 1970 1937 1971 free(header); 1938 return ERROR_CODE;1972 return rc; 1939 1973 1940 1974 case NET_IL_PACKET_SPACE: 1941 ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call), 1942 &addrlen, &prefix, &content, &suffix)); 1975 rc = ip_packet_size_message(IPC_GET_DEVICE(call), &addrlen, 1976 &prefix, &content, &suffix); 1977 if (rc != EOK) 1978 return rc; 1979 1943 1980 IPC_SET_ADDR(answer, addrlen); 1944 1981 IPC_SET_PREFIX(answer, prefix); … … 2005 2042 int main(int argc, char *argv[]) 2006 2043 { 2007 ERROR_DECLARE;2044 int rc; 2008 2045 2009 2046 /* Start the module */ 2010 ERROR_PROPAGATE(il_module_start_standalone(il_client_connection));2011 return EOK;2047 rc = il_module_start_standalone(il_client_connection); 2048 return rc; 2012 2049 } 2013 2050 -
uspace/srv/net/il/ip/ip_module.c
r0485135 r0b81cad0 44 44 #include <ipc/ipc.h> 45 45 #include <ipc/services.h> 46 #include <err .h>46 #include <errno.h> 47 47 48 48 #include <net/modules.h> … … 66 66 int il_module_start_standalone(async_client_conn_t client_connection) 67 67 { 68 ERROR_DECLARE; 68 ipcarg_t phonehash; 69 int rc; 69 70 70 71 async_set_client_connection(client_connection); 71 72 ip_globals.net_phone = net_connect_module(); 72 ERROR_PROPAGATE(pm_init()); 73 74 rc = pm_init(); 75 if (rc != EOK) 76 return rc; 73 77 74 ipcarg_t phonehash; 75 if (ERROR_OCCURRED(ip_initialize(client_connection)) || 76 ERROR_OCCURRED(REGISTER_ME(SERVICE_IP, &phonehash))) { 77 pm_destroy(); 78 return ERROR_CODE; 79 } 78 rc = ip_initialize(client_connection); 79 if (rc != EOK) 80 goto out; 81 82 rc = REGISTER_ME(SERVICE_IP, &phonehash); 83 if (rc != EOK) 84 goto out; 80 85 81 86 async_manager(); 82 87 88 out: 83 89 pm_destroy(); 84 return EOK;90 return rc; 85 91 } 86 92 -
uspace/srv/net/netif/lo/lo.c
r0485135 r0b81cad0 37 37 #include <async.h> 38 38 #include <errno.h> 39 #include <err.h>40 39 #include <stdio.h> 41 40 #include <str.h> … … 83 82 int netif_get_device_stats(device_id_t device_id, device_stats_ref stats) 84 83 { 85 ERROR_DECLARE;86 87 84 netif_device_t *device; 85 int rc; 88 86 89 87 if (!stats) 90 88 return EBADMEM; 91 ERROR_PROPAGATE(find_device(device_id, &device)); 89 rc = find_device(device_id, &device); 90 if (rc != EOK) 91 return rc; 92 92 memcpy(stats, (device_stats_ref) device->specific, 93 93 sizeof(device_stats_t)); … … 164 164 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io) 165 165 { 166 ERROR_DECLARE;167 168 166 netif_device_t *device; 167 int rc; 169 168 170 169 // create a new device 171 ERROR_PROPAGATE(create(device_id, &device)); 170 rc = create(device_id, &device); 171 if (rc != EOK) 172 return rc; 172 173 // print the settings 173 174 printf("%s: Device created (id: %d)\n", NAME, device->device_id); … … 177 178 int netif_send_message(device_id_t device_id, packet_t packet, services_t sender) 178 179 { 179 ERROR_DECLARE;180 181 180 netif_device_t *device; 182 181 size_t length; 183 182 packet_t next; 184 183 int phone; 185 186 ERROR_PROPAGATE(find_device(device_id, &device)); 184 int rc; 185 186 rc = find_device(device_id, &device); 187 if (rc != EOK) 188 return EOK; 187 189 if (device->state != NETIF_ACTIVE) { 188 190 netif_pq_release(packet_get_id(packet)); … … 259 261 int main(int argc, char *argv[]) 260 262 { 261 ERROR_DECLARE;263 int rc; 262 264 263 265 /* Start the module */ 264 ERROR_PROPAGATE(netif_module_start(netif_client_connection));265 return EOK;266 rc = netif_module_start(netif_client_connection); 267 return rc; 266 268 } 267 269 -
uspace/srv/net/nil/eth/eth.c
r0485135 r0b81cad0 42 42 #include <byteorder.h> 43 43 #include <str.h> 44 #include <err .h>44 #include <errno.h> 45 45 46 46 #include <ipc/ipc.h> … … 196 196 int nil_initialize(int net_phone) 197 197 { 198 ERROR_DECLARE;198 int rc; 199 199 200 200 fibril_rwlock_initialize(ð_globals.devices_lock); … … 208 208 CONVERT_SIZE(uint8_t, char, ETH_ADDR)); 209 209 if (!eth_globals.broadcast_addr) { 210 ERROR_CODE= ENOMEM;210 rc = ENOMEM; 211 211 goto out; 212 212 } 213 if (ERROR_OCCURRED(eth_devices_initialize(ð_globals.devices))) { 213 rc = eth_devices_initialize(ð_globals.devices); 214 if (rc != EOK) { 214 215 free(eth_globals.broadcast_addr); 215 216 goto out; 216 217 } 217 if (ERROR_OCCURRED(eth_protos_initialize(ð_globals.protos))) { 218 rc = eth_protos_initialize(ð_globals.protos); 219 if (rc != EOK) { 218 220 free(eth_globals.broadcast_addr); 219 221 eth_devices_destroy(ð_globals.devices); … … 223 225 fibril_rwlock_write_unlock(ð_globals.devices_lock); 224 226 225 return ERROR_CODE;227 return rc; 226 228 } 227 229 … … 234 236 static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall) 235 237 { 236 ERROR_DECLARE;237 238 238 packet_t packet; 239 int rc; 239 240 240 241 while (true) { … … 246 247 break; 247 248 case NET_NIL_RECEIVED: 248 if (ERROR_NONE(packet_translate_remote(249 eth_globals.net_phone, &packet,250 IPC_GET_PACKET(icall)))) {251 ERROR_CODE= nil_received_msg_local(0,249 rc = packet_translate_remote(eth_globals.net_phone, 250 &packet, IPC_GET_PACKET(icall)); 251 if (rc == EOK) { 252 rc = nil_received_msg_local(0, 252 253 IPC_GET_DEVICE(icall), packet, 0); 253 254 } 254 ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);255 ipc_answer_0(iid, (ipcarg_t) rc); 255 256 break; 256 257 default: … … 282 283 eth_device_message(device_id_t device_id, services_t service, size_t mtu) 283 284 { 284 ERROR_DECLARE;285 286 285 eth_device_ref device; 287 286 int index; … … 300 299 char *data; 301 300 eth_proto_ref proto; 301 int rc; 302 302 303 303 fibril_rwlock_write_lock(ð_globals.devices_lock); … … 351 351 352 352 configuration = &names[0]; 353 if (ERROR_OCCURRED(net_get_device_conf_req(eth_globals.net_phone, 354 device->device_id, &configuration, count, &data))) { 353 rc = net_get_device_conf_req(eth_globals.net_phone, device->device_id, 354 &configuration, count, &data); 355 if (rc != EOK) { 355 356 fibril_rwlock_write_unlock(ð_globals.devices_lock); 356 357 free(device); 357 return ERROR_CODE;358 return rc; 358 359 } 359 360 if (configuration) { … … 387 388 388 389 // get hardware address 389 if (ERROR_OCCURRED(netif_get_addr_req(device->phone, device->device_id, 390 &device->addr, &device->addr_data))) { 390 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr, 391 &device->addr_data); 392 if (rc != EOK) { 391 393 fibril_rwlock_write_unlock(ð_globals.devices_lock); 392 394 free(device); 393 return ERROR_CODE;395 return rc; 394 396 } 395 397 … … 429 431 static eth_proto_ref eth_process_packet(int flags, packet_t packet) 430 432 { 431 ERROR_DECLARE;432 433 433 eth_header_snap_ref header; 434 434 size_t length; … … 437 437 size_t suffix; 438 438 eth_fcs_ref fcs; 439 uint8_t * data; 439 uint8_t *data; 440 int rc; 440 441 441 442 length = packet_get_data_length(packet); … … 488 489 489 490 if (IS_DUMMY(flags)) { 490 if ( (~compute_crc32(~0U, data, length * 8)) != ntohl(*fcs))491 if (~compute_crc32(~0U, data, length * 8) != ntohl(*fcs)) 491 492 return NULL; 492 493 suffix += sizeof(eth_fcs_t); 493 494 } 494 495 495 if (ERROR_OCCURRED(packet_set_addr(packet,496 header->header. source_address, header->header.destination_address,497 ETH_ADDR)) || ERROR_OCCURRED(packet_trim(packet, prefix, suffix))) {496 rc = packet_set_addr(packet, header->header.source_address, 497 header->header.destination_address, ETH_ADDR); 498 if (rc != EOK) 498 499 return NULL; 499 } 500 501 rc = packet_trim(packet, prefix, suffix); 502 if (rc != EOK) 503 return NULL; 500 504 501 505 return eth_protos_find(ð_globals.protos, type); … … 781 785 eth_send_message(device_id_t device_id, packet_t packet, services_t sender) 782 786 { 783 ERROR_DECLARE;784 785 787 eth_device_ref device; 786 788 packet_t next; 787 789 packet_t tmp; 788 790 int ethertype; 791 int rc; 789 792 790 793 ethertype = htons(protocol_map(SERVICE_ETHERNET, sender)); … … 804 807 next = packet; 805 808 do { 806 if (ERROR_OCCURRED(eth_prepare_packet(device->flags, next, 807 (uint8_t *) device->addr->value, ethertype, device->mtu))) { 809 rc = eth_prepare_packet(device->flags, next, 810 (uint8_t *) device->addr->value, ethertype, device->mtu); 811 if (rc != EOK) { 808 812 // release invalid packet 809 813 tmp = pq_detach(next); … … 832 836 ipc_call_t *answer, int *answer_count) 833 837 { 834 ERROR_DECLARE;835 836 838 measured_string_ref address; 837 839 packet_t packet; … … 840 842 size_t suffix; 841 843 size_t content; 844 int rc; 842 845 843 846 *answer_count = 0; … … 850 853 IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 851 854 case NET_NIL_SEND: 852 ERROR_PROPAGATE(packet_translate_remote(eth_globals.net_phone, 853 &packet, IPC_GET_PACKET(call))); 855 rc = packet_translate_remote(eth_globals.net_phone, &packet, 856 IPC_GET_PACKET(call)); 857 if (rc != EOK) 858 return rc; 854 859 return eth_send_message(IPC_GET_DEVICE(call), packet, 855 860 IPC_GET_SERVICE(call)); 856 861 case NET_NIL_PACKET_SPACE: 857 ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call), 858 &addrlen, &prefix, &content, &suffix)); 862 rc = eth_packet_space_message(IPC_GET_DEVICE(call), &addrlen, 863 &prefix, &content, &suffix); 864 if (rc != EOK) 865 return rc; 859 866 IPC_SET_ADDR(answer, addrlen); 860 867 IPC_SET_PREFIX(answer, prefix); … … 864 871 return EOK; 865 872 case NET_NIL_ADDR: 866 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), 867 ETH_LOCAL_ADDR, &address)); 873 rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_LOCAL_ADDR, 874 &address); 875 if (rc != EOK) 876 return rc; 868 877 return measured_strings_reply(address, 1); 869 878 case NET_NIL_BROADCAST_ADDR: 870 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), 871 ETH_BROADCAST_ADDR, &address)); 879 rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_BROADCAST_ADDR, 880 &address); 881 if (rc != EOK) 882 return EOK; 872 883 return measured_strings_reply(address, 1); 873 884 case IPC_M_CONNECT_TO_ME: … … 923 934 int main(int argc, char *argv[]) 924 935 { 925 ERROR_DECLARE;936 int rc; 926 937 927 938 /* Start the module */ 928 ERROR_PROPAGATE(nil_module_start_standalone(nil_client_connection));929 return EOK;939 rc = nil_module_start_standalone(nil_client_connection); 940 return rc; 930 941 } 931 942 -
uspace/srv/net/nil/eth/eth_module.c
r0485135 r0b81cad0 40 40 #include <async.h> 41 41 #include <stdio.h> 42 #include <err .h>42 #include <errno.h> 43 43 44 44 #include <ipc/ipc.h> … … 52 52 int nil_module_start_standalone(async_client_conn_t client_connection) 53 53 { 54 ERROR_DECLARE; 54 ipcarg_t phonehash; 55 int rc; 55 56 56 57 async_set_client_connection(client_connection); 57 58 int net_phone = net_connect_module(); 58 ERROR_PROPAGATE(pm_init()); 59 60 rc = pm_init(); 61 if (rc != EOK) 62 return rc; 59 63 60 ipcarg_t phonehash; 61 if (ERROR_OCCURRED(nil_initialize(net_phone)) || 62 ERROR_OCCURRED(REGISTER_ME(SERVICE_ETHERNET, &phonehash))) { 63 pm_destroy(); 64 return ERROR_CODE; 65 } 64 rc = nil_initialize(net_phone); 65 if (rc != EOK) 66 goto out; 67 68 rc = REGISTER_ME(SERVICE_ETHERNET, &phonehash); 69 if (rc != EOK) 70 goto out; 66 71 67 72 async_manager(); 68 73 74 out: 69 75 pm_destroy(); 70 return EOK;76 return rc; 71 77 } 72 78 -
uspace/srv/net/nil/nildummy/nildummy.c
r0485135 r0b81cad0 41 41 #include <stdio.h> 42 42 #include <str.h> 43 #include <err.h>44 43 #include <ipc/ipc.h> 45 44 #include <ipc/net.h> … … 82 81 int nil_initialize(int net_phone) 83 82 { 84 ERROR_DECLARE;83 int rc; 85 84 86 85 fibril_rwlock_initialize(&nildummy_globals.devices_lock); … … 91 90 nildummy_globals.net_phone = net_phone; 92 91 nildummy_globals.proto.phone = 0; 93 ERROR_CODE= nildummy_devices_initialize(&nildummy_globals.devices);92 rc = nildummy_devices_initialize(&nildummy_globals.devices); 94 93 95 94 fibril_rwlock_write_unlock(&nildummy_globals.protos_lock); 96 95 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 97 96 98 return ERROR_CODE;97 return rc; 99 98 } 100 99 … … 107 106 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall) 108 107 { 109 ERROR_DECLARE;110 111 108 packet_t packet; 109 int rc; 112 110 113 111 while (true) { 114 112 switch (IPC_GET_METHOD(*icall)) { 115 113 case NET_NIL_DEVICE_STATE: 116 ERROR_CODE= nil_device_state_msg_local(0,114 rc = nil_device_state_msg_local(0, 117 115 IPC_GET_DEVICE(icall), IPC_GET_STATE(icall)); 118 ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);116 ipc_answer_0(iid, (ipcarg_t) rc); 119 117 break; 120 118 121 119 case NET_NIL_RECEIVED: 122 if (ERROR_NONE(packet_translate_remote(123 nildummy_globals.net_phone, &packet,124 IPC_GET_PACKET(icall)))) {125 ERROR_CODE= nil_received_msg_local(0,120 rc = packet_translate_remote(nildummy_globals.net_phone, 121 &packet, IPC_GET_PACKET(icall)); 122 if (rc == EOK) { 123 rc = nil_received_msg_local(0, 126 124 IPC_GET_DEVICE(icall), packet, 0); 127 125 } 128 ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);126 ipc_answer_0(iid, (ipcarg_t) rc); 129 127 break; 130 128 … … 155 153 nildummy_device_message(device_id_t device_id, services_t service, size_t mtu) 156 154 { 157 ERROR_DECLARE;158 159 155 nildummy_device_ref device; 160 156 int index; 157 int rc; 161 158 162 159 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); … … 216 213 217 214 // get hardware address 218 if (ERROR_OCCURRED(netif_get_addr_req(device->phone, device->device_id, 219 &device->addr, &device->addr_data))) { 215 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr, 216 &device->addr_data); 217 if (rc != EOK) { 220 218 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 221 219 free(device); 222 return ERROR_CODE;220 return rc; 223 221 } 224 222 … … 380 378 ipc_call_t *answer, int *answer_count) 381 379 { 382 ERROR_DECLARE;383 384 380 measured_string_ref address; 385 381 packet_t packet; … … 388 384 size_t suffix; 389 385 size_t content; 386 int rc; 390 387 391 388 *answer_count = 0; … … 399 396 400 397 case NET_NIL_SEND: 401 ERROR_PROPAGATE(packet_translate_remote( 402 nildummy_globals.net_phone, &packet, IPC_GET_PACKET(call))); 398 rc = packet_translate_remote(nildummy_globals.net_phone, 399 &packet, IPC_GET_PACKET(call)); 400 if (rc != EOK) 401 return rc; 403 402 return nildummy_send_message(IPC_GET_DEVICE(call), packet, 404 403 IPC_GET_SERVICE(call)); 405 404 406 405 case NET_NIL_PACKET_SPACE: 407 ERROR_PROPAGATE(nildummy_packet_space_message( 408 IPC_GET_DEVICE(call), &addrlen, &prefix, &content, 409 &suffix)); 406 rc = nildummy_packet_space_message(IPC_GET_DEVICE(call), 407 &addrlen, &prefix, &content, &suffix); 408 if (rc != EOK) 409 return rc; 410 410 IPC_SET_ADDR(answer, addrlen); 411 411 IPC_SET_PREFIX(answer, prefix); … … 416 416 417 417 case NET_NIL_ADDR: 418 ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), 419 &address)); 418 rc = nildummy_addr_message(IPC_GET_DEVICE(call), &address); 419 if (rc != EOK) 420 return rc; 420 421 return measured_strings_reply(address, 1); 421 422 422 423 case NET_NIL_BROADCAST_ADDR: 423 ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), 424 &address)); 424 rc = nildummy_addr_message(IPC_GET_DEVICE(call), &address); 425 if (rc != EOK) 426 return rc; 425 427 return measured_strings_reply(address, 1); 426 428 … … 476 478 int main(int argc, char *argv[]) 477 479 { 478 ERROR_DECLARE;480 int rc; 479 481 480 482 /* Start the module */ 481 ERROR_PROPAGATE(nil_module_start_standalone(nil_client_connection));482 return EOK;483 rc = nil_module_start_standalone(nil_client_connection); 484 return rc; 483 485 } 484 486 -
uspace/srv/net/nil/nildummy/nildummy.h
r0485135 r0b81cad0 62 62 * @see nildummy_proto 63 63 */ 64 typedef struct nildummy_proto 64 typedef struct nildummy_proto nildummy_proto_t; 65 65 66 66 /** Type definition of the dummy nil protocol specific data pointer. … … 100 100 101 101 /** Dummy nil global data. */ 102 struct 102 struct nildummy_globals { 103 103 /** Networking module phone. */ 104 104 int net_phone; -
uspace/srv/net/nil/nildummy/nildummy_module.c
r0485135 r0b81cad0 38 38 #include <async.h> 39 39 #include <stdio.h> 40 #include <err .h>40 #include <errno.h> 41 41 42 42 #include <ipc/ipc.h> … … 52 52 int nil_module_start_standalone(async_client_conn_t client_connection) 53 53 { 54 ERROR_DECLARE; 54 ipcarg_t phonehash; 55 int rc; 55 56 56 57 async_set_client_connection(client_connection); 57 58 int net_phone = net_connect_module(); 58 ERROR_PROPAGATE(pm_init());59 59 60 ipcarg_t phonehash; 61 if (ERROR_OCCURRED(nil_initialize(net_phone)) || 62 ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))) { 63 pm_destroy(); 64 return ERROR_CODE; 65 } 60 rc = pm_init(); 61 if (rc != EOK) 62 return rc; 63 64 65 rc = nil_initialize(net_phone); 66 if (rc != EOK) 67 goto out; 68 69 rc = REGISTER_ME(SERVICE_NILDUMMY, &phonehash); 70 if (rc != EOK) 71 goto out; 66 72 67 73 async_manager(); 68 74 75 out: 69 76 pm_destroy(); 70 return EOK;77 return rc; 71 78 } 72 79 -
uspace/srv/net/tl/icmp/icmp.c
r0485135 r0b81cad0 54 54 #include <byteorder.h> 55 55 #include <errno.h> 56 #include <err.h>57 56 58 57 #include <net/socket_codes.h> … … 161 160 int dont_fragment) 162 161 { 163 ERROR_DECLARE;162 int rc; 164 163 165 164 // do not send an error if disabled … … 172 171 header->checksum = ICMP_CHECKSUM(header, 173 172 packet_get_data_length(packet)); 174 if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl, 175 tos, dont_fragment, 0))) { 176 return icmp_release_and_return(packet, ERROR_CODE); 177 } 173 174 rc = ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl, tos, 175 dont_fragment, 0); 176 if (rc != EOK) 177 return icmp_release_and_return(packet, rc); 178 178 179 179 return ip_send_msg(icmp_globals.ip_phone, -1, packet, SERVICE_ICMP, … … 249 249 const struct sockaddr * addr, socklen_t addrlen) 250 250 { 251 ERROR_DECLARE;252 253 251 icmp_header_ref header; 254 252 packet_t packet; … … 257 255 icmp_reply_ref reply; 258 256 int reply_key; 259 int result;260 257 int index; 258 int rc; 261 259 262 260 if (addrlen <= 0) … … 265 263 length = (size_t) addrlen; 266 264 // TODO do not ask all the time 267 ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1, 268 &icmp_globals.packet_dimension)); 265 rc = ip_packet_size_req(icmp_globals.ip_phone, -1, 266 &icmp_globals.packet_dimension); 267 if (rc != EOK) 268 return rc; 269 269 270 270 packet = packet_get_4_remote(icmp_globals.net_phone, size, … … 277 277 // prepare the requesting packet 278 278 // set the destination address 279 if (ERROR_OCCURRED(packet_set_addr(packet, NULL, (const uint8_t *) addr, 280 length))) { 281 return icmp_release_and_return(packet, ERROR_CODE); 282 } 279 rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length); 280 if (rc != EOK) 281 return icmp_release_and_return(packet, rc); 283 282 284 283 // allocate space in the packet … … 329 328 // wait for the reply 330 329 // timeout in microseconds 331 if (ERROR_OCCURRED(fibril_condvar_wait_timeout(&reply->condvar, 332 &reply->mutex, timeout * 1000))) { 333 result = ERROR_CODE; 334 } else { 335 // read the result 336 result = reply->result; 337 } 330 rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex, 331 timeout * 1000); 332 if (rc == EOK) 333 rc = reply->result; 338 334 339 335 // drop the reply mutex before locking the globals again … … 344 340 icmp_replies_exclude_index(&icmp_globals.replies, index); 345 341 346 return r esult;342 return rc; 347 343 } 348 344 … … 413 409 int icmp_initialize(async_client_conn_t client_connection) 414 410 { 415 ERROR_DECLARE;416 417 411 measured_string_t names[] = { 418 412 { … … 428 422 size_t count = sizeof(names) / sizeof(measured_string_t); 429 423 char *data; 424 int rc; 430 425 431 426 fibril_rwlock_initialize(&icmp_globals.lock); … … 433 428 icmp_replies_initialize(&icmp_globals.replies); 434 429 icmp_echo_data_initialize(&icmp_globals.echo_data); 430 435 431 icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP, 436 432 SERVICE_ICMP, client_connection); 437 if (icmp_globals.ip_phone < 0) 433 if (icmp_globals.ip_phone < 0) { 434 fibril_rwlock_write_unlock(&icmp_globals.lock); 438 435 return icmp_globals.ip_phone; 439 440 ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1, 441 &icmp_globals.packet_dimension)); 436 } 437 438 rc = ip_packet_size_req(icmp_globals.ip_phone, -1, 439 &icmp_globals.packet_dimension); 440 if (rc != EOK) { 441 fibril_rwlock_write_unlock(&icmp_globals.lock); 442 return rc; 443 } 444 442 445 icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE; 443 446 icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE; … … 448 451 // get configuration 449 452 configuration = &names[0]; 450 ERROR_PROPAGATE(net_get_conf_req(icmp_globals.net_phone, &configuration, 451 count, &data)); 453 rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count, 454 &data); 455 if (rc != EOK) { 456 fibril_rwlock_write_unlock(&icmp_globals.lock); 457 return rc; 458 } 459 452 460 if (configuration) { 453 461 if (configuration[0].value) { … … 519 527 static int icmp_process_packet(packet_t packet, services_t error) 520 528 { 521 ERROR_DECLARE;522 523 529 size_t length; 524 530 uint8_t *src; … … 529 535 icmp_type_t type; 530 536 icmp_code_t code; 537 int rc; 531 538 532 539 switch (error) { … … 541 548 length = (size_t) result; 542 549 // remove the error header 543 ERROR_PROPAGATE(packet_trim(packet, length, 0)); 550 rc = packet_trim(packet, length, 0); 551 if (rc != EOK) 552 return rc; 544 553 break; 545 554 default: … … 549 558 // get rid of the ip header 550 559 length = ip_client_header_length(packet); 551 ERROR_PROPAGATE(packet_trim(packet, length, 0)); 560 rc = packet_trim(packet, length, 0); 561 if (rc != EOK) 562 return rc; 552 563 553 564 length = packet_get_data_length(packet); … … 582 593 switch (header->type) { 583 594 case ICMP_ECHOREPLY: 584 if (error) 595 if (error) 585 596 icmp_process_echo_reply(packet, header, type, code); 586 597 else … … 654 665 services_t receiver, services_t error) 655 666 { 656 ERROR_DECLARE; 657 658 if (ERROR_OCCURRED(icmp_process_packet(packet, error))) 659 return icmp_release_and_return(packet, ERROR_CODE); 667 int rc; 668 669 rc = icmp_process_packet(packet, error); 670 if (rc != EOK) 671 return icmp_release_and_return(packet, rc); 660 672 661 673 return EOK; … … 682 694 static int icmp_process_message(ipc_call_t *call) 683 695 { 684 ERROR_DECLARE;685 686 696 packet_t packet; 697 int rc; 687 698 688 699 switch (IPC_GET_METHOD(*call)) { 689 700 case NET_ICMP_DEST_UNREACH: 690 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,691 &packet, IPC_GET_PACKET(call)))) {692 ERROR_CODE = icmp_destination_unreachable_msg_local(0,693 ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);694 }695 return ERROR_CODE;701 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 702 IPC_GET_PACKET(call)); 703 if (rc != EOK) 704 return rc; 705 return icmp_destination_unreachable_msg_local(0, 706 ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet); 696 707 case NET_ICMP_SOURCE_QUENCH: 697 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,698 &packet, IPC_GET_PACKET(call)))) {699 ERROR_CODE = icmp_source_quench_msg_local(0, packet);700 }701 return ERROR_CODE;708 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 709 IPC_GET_PACKET(call)); 710 if (rc != EOK) 711 return rc; 712 return icmp_source_quench_msg_local(0, packet); 702 713 case NET_ICMP_TIME_EXCEEDED: 703 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,704 &packet, IPC_GET_PACKET(call)))) {705 ERROR_CODE = icmp_time_exceeded_msg_local(0,706 ICMP_GET_CODE(call), packet);707 }708 return ERROR_CODE;714 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 715 IPC_GET_PACKET(call)); 716 if (rc != EOK) 717 return rc; 718 return icmp_time_exceeded_msg_local(0, ICMP_GET_CODE(call), 719 packet); 709 720 case NET_ICMP_PARAMETERPROB: 710 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone, 711 &packet, IPC_GET_PACKET(call)))) { 712 ERROR_CODE = icmp_parameter_problem_msg_local(0, 713 ICMP_GET_CODE(call), ICMP_GET_POINTER(call), 714 packet); 715 } 716 return ERROR_CODE; 721 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 722 IPC_GET_PACKET(call)); 723 if (rc != EOK) 724 return rc; 725 return icmp_parameter_problem_msg_local(0, ICMP_GET_CODE(call), 726 ICMP_GET_POINTER(call), packet); 717 727 default: 718 728 return ENOTSUP; … … 757 767 break; 758 768 } 759 } while (icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);769 } while (icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL); 760 770 761 771 echo_data->identifier = index; … … 779 789 static int icmp_process_client_messages(ipc_callid_t callid, ipc_call_t call) 780 790 { 781 ERROR_DECLARE;782 783 791 bool keep_on_going = true; 784 792 ipc_call_t answer; … … 788 796 ipc_callid_t data_callid; 789 797 icmp_echo_ref echo_data; 790 int r es;798 int rc = EOK; 791 799 792 800 /* … … 794 802 * - Answer the first NET_ICMP_INIT call. 795 803 */ 796 res = EOK;797 804 answer_count = 0; 798 805 … … 803 810 // assign a new identifier 804 811 fibril_rwlock_write_lock(&icmp_globals.lock); 805 r es= icmp_bind_free_id(echo_data);812 rc = icmp_bind_free_id(echo_data); 806 813 fibril_rwlock_write_unlock(&icmp_globals.lock); 807 if (r es< 0) {814 if (rc < 0) { 808 815 free(echo_data); 809 return r es;816 return rc; 810 817 } 811 818 812 819 while (keep_on_going) { 813 820 // answer the call 814 answer_call(callid, r es, &answer, answer_count);821 answer_call(callid, rc, &answer, answer_count); 815 822 816 823 // refresh data … … 824 831 case IPC_M_PHONE_HUNGUP: 825 832 keep_on_going = false; 826 r es= EHANGUP;833 rc = EHANGUP; 827 834 break; 828 835 829 836 case NET_ICMP_ECHO: 830 837 if (!async_data_write_receive(&data_callid, &length)) { 831 r es= EINVAL;838 rc = EINVAL; 832 839 break; 833 840 } … … 835 842 addr = malloc(length); 836 843 if (!addr) { 837 r es= ENOMEM;844 rc = ENOMEM; 838 845 break; 839 846 } 840 847 841 if (ERROR_OCCURRED(async_data_write_finalize( 842 data_callid, addr, length))) { 848 rc = async_data_write_finalize(data_callid, addr, 849 length); 850 if (rc != EOK) { 843 851 free(addr); 844 res = ERROR_CODE;845 852 break; 846 853 } 847 854 848 855 fibril_rwlock_write_lock(&icmp_globals.lock); 849 r es= icmp_echo(echo_data->identifier,856 rc = icmp_echo(echo_data->identifier, 850 857 echo_data->sequence_number, ICMP_GET_SIZE(call), 851 858 ICMP_GET_TIMEOUT(call), ICMP_GET_TTL(call), … … 864 871 865 872 default: 866 r es= icmp_process_message(&call);873 rc = icmp_process_message(&call); 867 874 } 868 875 … … 874 881 fibril_rwlock_write_unlock(&icmp_globals.lock); 875 882 876 return r es;883 return rc; 877 884 } 878 885 … … 894 901 ipc_call_t *answer, int *answer_count) 895 902 { 896 ERROR_DECLARE;897 898 903 packet_t packet; 904 int rc; 899 905 900 906 *answer_count = 0; 901 907 switch (IPC_GET_METHOD(*call)) { 902 908 case NET_TL_RECEIVED: 903 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone, 904 &packet, IPC_GET_PACKET(call)))) { 905 ERROR_CODE = 906 icmp_received_msg_local(IPC_GET_DEVICE(call), 907 packet, SERVICE_ICMP, IPC_GET_ERROR(call)); 908 } 909 return ERROR_CODE; 909 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 910 IPC_GET_PACKET(call)); 911 if (rc != EOK) 912 return rc; 913 return icmp_received_msg_local(IPC_GET_DEVICE(call), packet, 914 SERVICE_ICMP, IPC_GET_ERROR(call)); 910 915 911 916 case NET_ICMP_INIT: … … 970 975 int main(int argc, char *argv[]) 971 976 { 972 ERROR_DECLARE;977 int rc; 973 978 974 979 /* Start the module */ 975 ERROR_PROPAGATE(tl_module_start_standalone(tl_client_connection));976 return EOK;980 rc = tl_module_start_standalone(tl_client_connection); 981 return rc; 977 982 } 978 983 -
uspace/srv/net/tl/icmp/icmp_module.c
r0485135 r0b81cad0 43 43 #include <async.h> 44 44 #include <stdio.h> 45 #include <err .h>45 #include <errno.h> 46 46 #include <ipc/ipc.h> 47 47 #include <ipc/services.h> … … 58 58 int tl_module_start_standalone(async_client_conn_t client_connection) 59 59 { 60 ERROR_DECLARE;61 62 60 ipcarg_t phonehash; 61 int rc; 63 62 64 63 async_set_client_connection(client_connection); … … 67 66 return icmp_globals.net_phone; 68 67 69 ERROR_PROPAGATE(pm_init()); 70 if (ERROR_OCCURRED(icmp_initialize(client_connection)) || 71 ERROR_OCCURRED(REGISTER_ME(SERVICE_ICMP, &phonehash))) { 72 pm_destroy(); 73 return ERROR_CODE; 74 } 68 rc = pm_init(); 69 if (rc != EOK) 70 return rc; 71 72 rc = icmp_initialize(client_connection); 73 if (rc != EOK) 74 goto out; 75 76 rc = REGISTER_ME(SERVICE_ICMP, &phonehash); 77 if (rc != EOK) 78 goto out; 75 79 76 80 async_manager(); 77 81 82 out: 78 83 pm_destroy(); 79 return EOK;84 return rc; 80 85 } 81 86 … … 89 94 /** @} 90 95 */ 91 -
uspace/srv/net/tl/tcp/tcp.c
r0485135 r0b81cad0 47 47 #include <stdio.h> 48 48 #include <errno.h> 49 #include <err.h>50 49 51 50 #include <ipc/ipc.h> … … 235 234 int tcp_initialize(async_client_conn_t client_connection) 236 235 { 237 ERROR_DECLARE;236 int rc; 238 237 239 238 assert(client_connection); … … 246 245 tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP, 247 246 SERVICE_TCP, client_connection); 248 if (tcp_globals.ip_phone < 0) 247 if (tcp_globals.ip_phone < 0) { 248 fibril_rwlock_write_unlock(&tcp_globals.lock); 249 249 return tcp_globals.ip_phone; 250 } 250 251 251 ERROR_PROPAGATE(socket_ports_initialize(&tcp_globals.sockets)); 252 if (ERROR_OCCURRED(packet_dimensions_initialize( 253 &tcp_globals.dimensions))) { 252 rc = socket_ports_initialize(&tcp_globals.sockets); 253 if (rc != EOK) 254 goto out; 255 256 rc = packet_dimensions_initialize(&tcp_globals.dimensions); 257 if (rc != EOK) { 254 258 socket_ports_destroy(&tcp_globals.sockets); 255 return ERROR_CODE;259 goto out; 256 260 } 257 261 258 262 tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1; 263 264 out: 259 265 fibril_rwlock_write_unlock(&tcp_globals.lock); 260 261 return EOK; 266 return rc; 262 267 } 263 268 … … 266 271 services_t error) 267 272 { 268 ERROR_DECLARE;273 int rc; 269 274 270 275 if (receiver != SERVICE_TCP) … … 272 277 273 278 fibril_rwlock_write_lock(&tcp_globals.lock); 274 if (ERROR_OCCURRED(tcp_process_packet(device_id, packet, error))) 279 rc = tcp_process_packet(device_id, packet, error); 280 if (rc != EOK) 275 281 fibril_rwlock_write_unlock(&tcp_globals.lock); 276 282 277 printf("receive %d \n", ERROR_CODE);278 279 return ERROR_CODE;283 printf("receive %d \n", rc); 284 285 return rc; 280 286 } 281 287 282 288 int tcp_process_packet(device_id_t device_id, packet_t packet, services_t error) 283 289 { 284 ERROR_DECLARE;285 286 290 size_t length; 287 291 size_t offset; … … 299 303 struct sockaddr *dest; 300 304 size_t addrlen; 305 int rc; 301 306 302 307 switch (error) { … … 311 316 312 317 length = (size_t) result; 313 if (ERROR_OCCURRED(packet_trim(packet, length, 0))) 314 return tcp_release_and_return(packet, ERROR_CODE); 318 rc = packet_trim(packet, length, 0); 319 if (rc != EOK) 320 return tcp_release_and_return(packet, rc); 315 321 break; 316 322 default: … … 333 339 334 340 // trim all but TCP header 335 if (ERROR_OCCURRED(packet_trim(packet, offset, 0))) 336 return tcp_release_and_return(packet, ERROR_CODE); 341 rc = packet_trim(packet, offset, 0); 342 if (rc != EOK) 343 return tcp_release_and_return(packet, rc); 337 344 338 345 // get tcp header … … 350 357 addrlen = (size_t) result; 351 358 352 if (ERROR_OCCURRED(tl_set_address_port(src, addrlen,353 ntohs(header->source_port))))354 return tcp_release_and_return(packet, ERROR_CODE);359 rc = tl_set_address_port(src, addrlen, ntohs(header->source_port)); 360 if (rc != EOK) 361 return tcp_release_and_return(packet, rc); 355 362 356 363 // find the destination socket … … 413 420 } 414 421 415 if (ERROR_OCCURRED(ip_client_get_pseudo_header(IPPROTO_TCP, src, 416 addrlen, dest, addrlen, total_length, 417 &socket_data->pseudo_header, &socket_data->headerlen))) { 422 rc = ip_client_get_pseudo_header(IPPROTO_TCP, src, addrlen, 423 dest, addrlen, total_length, &socket_data->pseudo_header, 424 &socket_data->headerlen); 425 if (rc != EOK) { 418 426 fibril_rwlock_write_unlock(socket_data->local_lock); 419 return tcp_release_and_return(packet, ERROR_CODE); 420 } 421 422 } else if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length( 423 socket_data->pseudo_header, socket_data->headerlen, 424 total_length))) { 425 fibril_rwlock_write_unlock(socket_data->local_lock); 426 return tcp_release_and_return(packet, ERROR_CODE); 427 return tcp_release_and_return(packet, rc); 428 } 429 } else { 430 rc = ip_client_set_pseudo_header_data_length( 431 socket_data->pseudo_header, socket_data->headerlen, 432 total_length); 433 if (rc != EOK) { 434 fibril_rwlock_write_unlock(socket_data->local_lock); 435 return tcp_release_and_return(packet, rc); 436 } 427 437 } 428 438 … … 434 444 fibril_rwlock_write_unlock(socket_data->local_lock); 435 445 436 if (ERROR_NONE(tl_prepare_icmp_packet(tcp_globals.net_phone, 437 tcp_globals.icmp_phone, packet, error))) { 446 rc = tl_prepare_icmp_packet(tcp_globals.net_phone, 447 tcp_globals.icmp_phone, packet, error); 448 if (rc == EOK) { 438 449 // checksum error ICMP 439 450 icmp_parameter_problem_msg(tcp_globals.icmp_phone, … … 452 463 switch (socket_data->state) { 453 464 case TCP_SOCKET_LISTEN: 454 ERROR_CODE = tcp_process_listen(socket, socket_data, header,455 packet,src, dest, addrlen);465 rc = tcp_process_listen(socket, socket_data, header, packet, 466 src, dest, addrlen); 456 467 break; 457 468 case TCP_SOCKET_SYN_RECEIVED: 458 ERROR_CODE = tcp_process_syn_received(socket, socket_data,459 header,packet);469 rc = tcp_process_syn_received(socket, socket_data, header, 470 packet); 460 471 break; 461 472 case TCP_SOCKET_SYN_SENT: 462 ERROR_CODE = tcp_process_syn_sent(socket, socket_data, header, 463 packet); 473 rc = tcp_process_syn_sent(socket, socket_data, header, packet); 464 474 break; 465 475 case TCP_SOCKET_FIN_WAIT_1: … … 472 482 // ack releasing the socket gets processed later 473 483 case TCP_SOCKET_ESTABLISHED: 474 ERROR_CODE = tcp_process_established(socket, socket_data,475 header,packet, fragments, total_length);484 rc = tcp_process_established(socket, socket_data, header, 485 packet, fragments, total_length); 476 486 break; 477 487 default: … … 479 489 } 480 490 481 if (ERROR_CODE != EOK) { 482 printf("process %d\n", ERROR_CODE); 491 if (rc != EOK) { 483 492 fibril_rwlock_write_unlock(socket_data->local_lock); 493 printf("process %d\n", rc); 484 494 } 485 495 … … 491 501 tcp_header_ref header, packet_t packet, int fragments, size_t total_length) 492 502 { 493 ERROR_DECLARE;494 495 503 packet_t next_packet; 496 504 packet_t tmp_packet; … … 501 509 size_t offset; 502 510 uint32_t new_sequence_number; 511 int rc; 503 512 504 513 assert(socket); … … 541 550 } 542 551 543 if ((offset > 0) && (ERROR_OCCURRED(packet_trim(packet, 544 offset, 0)))) 545 return tcp_release_and_return(packet, ERROR_CODE); 552 if (offset > 0) { 553 rc = packet_trim(packet, offset, 0); 554 if (rc != EOK) 555 return tcp_release_and_return(packet, rc); 556 } 546 557 547 558 assert(new_sequence_number == socket_data->next_incoming); … … 575 586 if (length <= offset) 576 587 next_packet = pq_next(next_packet); 577 else if (ERROR_OCCURRED(packet_trim(next_packet, 0, 578 length - offset))) 579 return tcp_release_and_return(packet, 580 ERROR_CODE); 588 else { 589 rc = packet_trim(next_packet, 0, 590 length - offset)); 591 if (rc != EOK) 592 return tcp_release_and_return(packet, 593 rc); 594 } 581 595 offset -= length; 582 596 total_length -= length - offset; … … 603 617 // remove the header 604 618 total_length -= TCP_HEADER_LENGTH(header); 605 if (ERROR_OCCURRED(packet_trim(packet,606 TCP_HEADER_LENGTH(header), 0)))607 return tcp_release_and_return(packet, ERROR_CODE);619 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); 620 if (rc != EOK) 621 return tcp_release_and_return(packet, rc); 608 622 609 623 if (total_length) { 610 ERROR_PROPAGATE(tcp_queue_received_packet(socket, 611 socket_data, packet, fragments, total_length)); 624 rc = tcp_queue_received_packet(socket, socket_data, 625 packet, fragments, total_length); 626 if (rc != EOK) 627 return rc; 612 628 } else { 613 629 total_length = 1; … … 617 633 packet = socket_data->incoming; 618 634 while (packet) { 619 620 if (ERROR_OCCURRED(pq_get_order(socket_data->incoming, 621 &order, NULL))) { 635 rc = pq_get_order(socket_data->incoming, &order, NULL); 636 if (rc != EOK) { 622 637 // remove the corrupted packet 623 638 next_packet = pq_detach(packet); … … 656 671 socket_data->next_incoming) { 657 672 // queue received data 658 ERROR_PROPAGATE( 659 tcp_queue_received_packet(socket, 673 rc = tcp_queue_received_packet(socket, 660 674 socket_data, packet, 1, 661 packet_get_data_length(packet))); 675 packet_get_data_length(packet)); 676 if (rc != EOK) 677 return rc; 662 678 socket_data->next_incoming = 663 679 new_sequence_number; … … 677 693 new_sequence_number; 678 694 } 679 if (ERROR_NONE(packet_trim(packet,680 length, 0))) {695 rc = packet_trim(packet,length, 0); 696 if (rc == EOK) { 681 697 // queue received data 682 ERROR_PROPAGATE( 683 tcp_queue_received_packet( 698 rc = tcp_queue_received_packet( 684 699 socket, socket_data, packet, 685 700 1, packet_get_data_length( 686 packet))); 701 packet)); 702 if (rc != EOK) 703 return rc; 687 704 socket_data->next_incoming = 688 705 new_sequence_number; … … 709 726 // remove the header 710 727 total_length -= TCP_HEADER_LENGTH(header); 711 if (ERROR_OCCURRED(packet_trim(packet,712 TCP_HEADER_LENGTH(header), 0)))713 return tcp_release_and_return(packet, ERROR_CODE);728 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); 729 if (rc != EOK) 730 return tcp_release_and_return(packet, rc); 714 731 715 732 next_packet = pq_detach(packet); 716 733 length = packet_get_data_length(packet); 717 if (ERROR_OCCURRED(pq_add(&socket_data->incoming, packet, 718 new_sequence_number, length))) { 734 rc = pq_add(&socket_data->incoming, packet, new_sequence_number, 735 length); 736 if (rc != EOK) { 719 737 // remove the corrupted packets 720 738 pq_release_remote(tcp_globals.net_phone, … … 727 745 tmp_packet = pq_detach(next_packet); 728 746 length = packet_get_data_length(next_packet); 729 if (ERROR_OCCURRED(pq_set_order(next_packet, 730 new_sequence_number, length)) || 731 ERROR_OCCURRED(pq_insert_after(packet, 732 next_packet))) { 747 748 rc = pq_set_order(next_packet, 749 new_sequence_number, length); 750 if (rc != EOK) { 751 pq_release_remote(tcp_globals.net_phone, 752 packet_get_id(next_packet)); 753 } 754 rc = pq_insert_after(packet, next_packet); 755 if (rc != EOK) { 733 756 pq_release_remote(tcp_globals.net_phone, 734 757 packet_get_id(next_packet)); … … 762 785 if (!packet) { 763 786 // create the notification packet 764 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 765 socket_data, 0, 0)); 766 ERROR_PROPAGATE(tcp_queue_prepare_packet(socket, socket_data, 767 packet, 1)); 787 rc = tcp_create_notification_packet(&packet, socket, 788 socket_data, 0, 0); 789 if (rc != EOK) 790 return rc; 791 rc = tcp_queue_prepare_packet(socket, socket_data, packet, 1); 792 if (rc != EOK) 793 return rc; 768 794 packet = tcp_send_prepare_packet(socket, socket_data, packet, 1, 769 795 socket_data->last_outgoing + 1); … … 783 809 size_t total_length) 784 810 { 785 ERROR_DECLARE;786 787 811 packet_dimension_ref packet_dimension; 812 int rc; 788 813 789 814 assert(socket); … … 795 820 796 821 // queue the received packet 797 if (ERROR_OCCURRED(dyn_fifo_push(&socket->received, 798 packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE)) || 799 ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 800 &tcp_globals.dimensions, socket_data->device_id, 801 &packet_dimension))) { 802 return tcp_release_and_return(packet, ERROR_CODE); 803 } 822 rc = dyn_fifo_push(&socket->received, packet_get_id(packet), 823 SOCKET_MAX_RECEIVED_SIZE); 824 if (rc != EOK) 825 return tcp_release_and_return(packet, rc); 826 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 827 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 828 if (rc != EOK) 829 return tcp_release_and_return(packet, rc); 804 830 805 831 // decrease the window size … … 820 846 tcp_header_ref header, packet_t packet) 821 847 { 822 ERROR_DECLARE;823 824 848 packet_t next_packet; 849 int rc; 825 850 826 851 assert(socket); … … 844 869 } 845 870 // trim if longer than the header 846 if ((packet_get_data_length(packet) > sizeof(*header)) && 847 ERROR_OCCURRED(packet_trim(packet, 0, 848 packet_get_data_length(packet) - sizeof(*header)))) { 849 return tcp_release_and_return(packet, ERROR_CODE); 871 if (packet_get_data_length(packet) > sizeof(*header)) { 872 rc = packet_trim(packet, 0, 873 packet_get_data_length(packet) - sizeof(*header)); 874 if (rc != EOK) 875 return tcp_release_and_return(packet, rc); 850 876 } 851 877 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); … … 876 902 size_t addrlen) 877 903 { 878 ERROR_DECLARE;879 880 904 packet_t next_packet; 881 905 socket_core_ref socket; … … 884 908 int listening_socket_id = listening_socket->socket_id; 885 909 int listening_port = listening_socket->port; 910 int rc; 886 911 887 912 assert(listening_socket); … … 913 938 memcpy(socket_data->addr, src, socket_data->addrlen); 914 939 socket_data->dest_port = ntohs(header->source_port); 915 if (ERROR_OCCURRED(tl_set_address_port(socket_data->addr, 916 socket_data->addrlen, socket_data->dest_port))) { 940 rc = tl_set_address_port(socket_data->addr, socket_data->addrlen, 941 socket_data->dest_port); 942 if (rc != EOK) { 917 943 free(socket_data->addr); 918 944 free(socket_data); 919 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 920 return ERROR_CODE; 945 return tcp_release_and_return(packet, rc); 921 946 } 922 947 923 948 // create a socket 924 949 socket_id = -1; 925 if (ERROR_OCCURRED(socket_create(socket_data->local_sockets, 926 listening_socket->phone, socket_data, &socket_id))) { 950 rc = socket_create(socket_data->local_sockets, listening_socket->phone, 951 socket_data, &socket_id); 952 if (rc != EOK) { 927 953 free(socket_data->addr); 928 954 free(socket_data); 929 return tcp_release_and_return(packet, ERROR_CODE);955 return tcp_release_and_return(packet, rc); 930 956 } 931 957 … … 964 990 assert(socket_data); 965 991 966 ERROR_CODE = socket_port_add(&tcp_globals.sockets, listening_port,967 socket,(const char *) socket_data->addr, socket_data->addrlen);992 rc = socket_port_add(&tcp_globals.sockets, listening_port, socket, 993 (const char *) socket_data->addr, socket_data->addrlen); 968 994 assert(socket == socket_port_find(&tcp_globals.sockets, listening_port, 969 995 (const char *) socket_data->addr, socket_data->addrlen)); 970 996 971 // ERROR_CODE= socket_bind_free_port(&tcp_globals.sockets, socket,997 // rc = socket_bind_free_port(&tcp_globals.sockets, socket, 972 998 // TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 973 999 // tcp_globals.last_used_port); 974 1000 // tcp_globals.last_used_port = socket->port; 975 1001 fibril_rwlock_write_unlock(&tcp_globals.lock); 976 if ( ERROR_CODE!= EOK) {1002 if (rc != EOK) { 977 1003 socket_destroy(tcp_globals.net_phone, socket->socket_id, 978 1004 socket_data->local_sockets, &tcp_globals.sockets, 979 1005 tcp_free_socket_data); 980 return tcp_release_and_return(packet, ERROR_CODE);1006 return tcp_release_and_return(packet, rc); 981 1007 } 982 1008 … … 992 1018 993 1019 // trim if longer than the header 994 if ((packet_get_data_length(packet) > sizeof(*header)) && 995 ERROR_OCCURRED(packet_trim(packet, 0, 996 packet_get_data_length(packet) - sizeof(*header)))) { 1020 if (packet_get_data_length(packet) > sizeof(*header)) { 1021 rc = packet_trim(packet, 0, 1022 packet_get_data_length(packet) - sizeof(*header)); 1023 if (rc != EOK) { 1024 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1025 socket_data->local_sockets, &tcp_globals.sockets, 1026 tcp_free_socket_data); 1027 return tcp_release_and_return(packet, rc); 1028 } 1029 } 1030 1031 tcp_prepare_operation_header(socket, socket_data, header, 1, 0); 1032 1033 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1034 if (rc != EOK) { 997 1035 socket_destroy(tcp_globals.net_phone, socket->socket_id, 998 1036 socket_data->local_sockets, &tcp_globals.sockets, 999 1037 tcp_free_socket_data); 1000 return tcp_release_and_return(packet, ERROR_CODE); 1001 } 1002 1003 tcp_prepare_operation_header(socket, socket_data, header, 1, 0); 1004 1005 if (ERROR_OCCURRED(tcp_queue_packet(socket, socket_data, packet, 1))) { 1006 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1007 socket_data->local_sockets, &tcp_globals.sockets, 1008 tcp_free_socket_data); 1009 return ERROR_CODE; 1038 return rc; 1010 1039 } 1011 1040 … … 1031 1060 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet) 1032 1061 { 1033 ERROR_DECLARE;1034 1035 1062 socket_core_ref listening_socket; 1036 1063 tcp_socket_data_ref listening_socket_data; 1064 int rc; 1037 1065 1038 1066 assert(socket); … … 1059 1087 1060 1088 // queue the received packet 1061 if (ERROR_NONE(dyn_fifo_push(&listening_socket->accepted, 1062 (-1 * socket->socket_id), 1063 listening_socket_data->backlog))) { 1064 1089 rc = dyn_fifo_push(&listening_socket->accepted, 1090 (-1 * socket->socket_id), listening_socket_data->backlog); 1091 if (rc == EOK) { 1065 1092 // notify the destination socket 1066 1093 async_msg_5(socket->phone, NET_SOCKET_ACCEPTED, … … 1077 1104 1078 1105 // create the notification packet 1079 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 1080 socket_data, 0, 1)); 1106 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 1107 if (rc != EOK) 1108 return rc; 1081 1109 1082 1110 // send the packet 1083 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 1)); 1111 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1112 if (rc != EOK) 1113 return rc; 1084 1114 1085 1115 // flush packets … … 1198 1228 ipc_call_t *answer, int *answer_count) 1199 1229 { 1200 ERROR_DECLARE;1201 1202 1230 packet_t packet; 1231 int rc; 1203 1232 1204 1233 assert(call); … … 1209 1238 switch (IPC_GET_METHOD(*call)) { 1210 1239 case NET_TL_RECEIVED: 1211 //fibril_rwlock_read_lock(&tcp_globals.lock); 1212 if (ERROR_NONE(packet_translate_remote(tcp_globals.net_phone, 1213 &packet, IPC_GET_PACKET(call)))) { 1214 ERROR_CODE = tcp_received_msg(IPC_GET_DEVICE(call), 1215 packet, SERVICE_TCP, IPC_GET_ERROR(call)); 1216 } 1217 //fibril_rwlock_read_unlock(&tcp_globals.lock); 1218 return ERROR_CODE; 1219 1240 // fibril_rwlock_read_lock(&tcp_globals.lock); 1241 rc = packet_translate_remote(tcp_globals.net_phone, &packet, 1242 IPC_GET_PACKET(call)); 1243 if (rc != EOK) { 1244 // fibril_rwlock_read_unlock(&tcp_globals.lock); 1245 return rc; 1246 } 1247 rc = tcp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_TCP, 1248 IPC_GET_ERROR(call)); 1249 // fibril_rwlock_read_unlock(&tcp_globals.lock); 1250 return rc; 1220 1251 case IPC_M_CONNECT_TO_ME: 1221 1252 return tcp_process_client_messages(callid, *call); … … 1662 1693 struct sockaddr *addr, socklen_t addrlen) 1663 1694 { 1664 ERROR_DECLARE;1665 1666 1695 socket_core_ref socket; 1696 int rc; 1667 1697 1668 1698 assert(local_sockets); … … 1675 1705 return ENOTSOCK; 1676 1706 1677 if (ERROR_OCCURRED(tcp_connect_core(socket, local_sockets, addr,1678 addrlen))) {1707 rc = tcp_connect_core(socket, local_sockets, addr, addrlen); 1708 if (rc != EOK) { 1679 1709 tcp_free_socket_data(socket); 1680 1710 // unbind if bound … … 1685 1715 } 1686 1716 } 1687 return ERROR_CODE;1717 return rc; 1688 1718 } 1689 1719 … … 1692 1722 struct sockaddr *addr, socklen_t addrlen) 1693 1723 { 1694 ERROR_DECLARE;1695 1696 1724 tcp_socket_data_ref socket_data; 1697 1725 packet_t packet; 1726 int rc; 1698 1727 1699 1728 assert(socket); … … 1711 1740 1712 1741 // get the destination port 1713 ERROR_PROPAGATE(tl_get_address_port(addr, addrlen, 1714 &socket_data->dest_port)); 1742 rc = tl_get_address_port(addr, addrlen, &socket_data->dest_port); 1743 if (rc != EOK) 1744 return rc; 1745 1715 1746 if (socket->port <= 0) { 1716 1747 // try to find a free port 1717 ERROR_PROPAGATE(socket_bind_free_port(&tcp_globals.sockets, 1718 socket, TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 1719 tcp_globals.last_used_port)); 1748 rc = socket_bind_free_port(&tcp_globals.sockets, socket, 1749 TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 1750 tcp_globals.last_used_port); 1751 if (rc != EOK) 1752 return rc; 1720 1753 // set the next port as the search starting port number 1721 1754 tcp_globals.last_used_port = socket->port; 1722 1755 } 1723 1756 1724 ERROR_PROPAGATE(ip_get_route_req(tcp_globals.ip_phone, IPPROTO_TCP,1757 rc = ip_get_route_req(tcp_globals.ip_phone, IPPROTO_TCP, 1725 1758 addr, addrlen, &socket_data->device_id, 1726 &socket_data->pseudo_header, &socket_data->headerlen)); 1759 &socket_data->pseudo_header, &socket_data->headerlen); 1760 if (rc != EOK) 1761 return rc; 1727 1762 1728 1763 // create the notification packet 1729 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 1730 socket_data, 1, 0)); 1764 rc = tcp_create_notification_packet(&packet, socket, socket_data, 1, 0); 1765 if (rc != EOK) 1766 return rc; 1731 1767 1732 1768 // unlock the globals and wait for an operation … … 1736 1772 socket_data->addrlen = addrlen; 1737 1773 // send the packet 1738 if (ERROR_OCCURRED(tcp_queue_packet(socket, socket_data, packet, 1)) || 1739 ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, socket_data, 1740 0, TCP_SOCKET_INITIAL, NET_DEFAULT_TCP_INITIAL_TIMEOUT, false))) { 1774 1775 if (((rc = tcp_queue_packet(socket, socket_data, packet, 1)) != EOK) || 1776 ((rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data, 0, 1777 TCP_SOCKET_INITIAL, NET_DEFAULT_TCP_INITIAL_TIMEOUT, false)) != 1778 EOK)) { 1741 1779 socket_data->addr = NULL; 1742 1780 socket_data->addrlen = 0; … … 1754 1792 fibril_condvar_wait(&socket_data->operation.condvar, 1755 1793 &socket_data->operation.mutex); 1756 ERROR_CODE= socket_data->operation.result;1757 if ( ERROR_CODE!= EOK) {1794 rc = socket_data->operation.result; 1795 if (rc != EOK) { 1758 1796 socket_data->addr = NULL; 1759 1797 socket_data->addrlen = 0; … … 1762 1800 socket_data->addr = NULL; 1763 1801 socket_data->addrlen = 0; 1764 ERROR_CODE= EINTR;1802 rc = EINTR; 1765 1803 } 1766 1804 } … … 1769 1807 1770 1808 // return the result 1771 return ERROR_CODE;1809 return rc; 1772 1810 } 1773 1811 … … 1776 1814 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length) 1777 1815 { 1778 ERROR_DECLARE;1779 1780 1816 tcp_header_ref header; 1817 int rc; 1781 1818 1782 1819 assert(socket); … … 1793 1830 header->sequence_number = htonl(socket_data->next_outgoing); 1794 1831 1795 if (ERROR_OCCURRED(packet_set_addr(packet, NULL, 1796 (uint8_t *) socket_data->addr, socket_data->addrlen))) 1832 rc = packet_set_addr(packet, NULL, (uint8_t *) socket_data->addr, 1833 socket_data->addrlen); 1834 if (rc != EOK) 1797 1835 return tcp_release_and_return(packet, EINVAL); 1798 1836 … … 1808 1846 packet_t packet, size_t data_length) 1809 1847 { 1810 ERROR_DECLARE;1848 int rc; 1811 1849 1812 1850 assert(socket); … … 1814 1852 assert(socket->specific_data == socket_data); 1815 1853 1816 ERROR_PROPAGATE(tcp_queue_prepare_packet(socket, socket_data, packet, 1817 data_length)); 1818 1819 if (ERROR_OCCURRED(pq_add(&socket_data->outgoing, packet, 1820 socket_data->next_outgoing, data_length))) 1821 return tcp_release_and_return(packet, ERROR_CODE); 1854 rc = tcp_queue_prepare_packet(socket, socket_data, packet, data_length); 1855 if (rc != EOK) 1856 return rc; 1857 1858 rc = pq_add(&socket_data->outgoing, packet, socket_data->next_outgoing, 1859 data_length); 1860 if (rc != EOK) 1861 return tcp_release_and_return(packet, rc); 1822 1862 1823 1863 socket_data->next_outgoing += data_length; … … 1828 1868 tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref socket_data) 1829 1869 { 1830 ERROR_DECLARE;1831 1832 1870 packet_t packet; 1833 1871 packet_t copy; … … 1835 1873 packet_t previous = NULL; 1836 1874 size_t data_length; 1875 int rc; 1837 1876 1838 1877 assert(socket); … … 1859 1898 if (!sending) { 1860 1899 sending = copy; 1861 } else if (ERROR_OCCURRED(pq_insert_after(previous, copy))) { 1862 pq_release_remote(tcp_globals.net_phone, 1863 packet_get_id(copy)); 1864 return sending; 1900 } else { 1901 rc = pq_insert_after(previous, copy); 1902 if (rc != EOK) { 1903 pq_release_remote(tcp_globals.net_phone, 1904 packet_get_id(copy)); 1905 return sending; 1906 } 1865 1907 } 1866 1908 … … 1884 1926 packet_t packet, size_t data_length, size_t sequence_number) 1885 1927 { 1886 ERROR_DECLARE;1887 1888 1928 tcp_header_ref header; 1889 1929 uint32_t checksum; 1930 int rc; 1890 1931 1891 1932 assert(socket); … … 1894 1935 1895 1936 // adjust the pseudo header 1896 if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length(1897 socket_data-> pseudo_header, socket_data->headerlen,1898 packet_get_data_length(packet)))) {1937 rc = ip_client_set_pseudo_header_data_length(socket_data->pseudo_header, 1938 socket_data->headerlen, packet_get_data_length(packet)); 1939 if (rc != EOK) { 1899 1940 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1900 1941 return NULL; … … 1921 1962 checksum = compute_checksum(0, socket_data->pseudo_header, 1922 1963 socket_data->headerlen); 1923 checksum = compute_checksum(checksum, (uint8_t *) packet_get_data(packet), 1964 checksum = compute_checksum(checksum, 1965 (uint8_t *) packet_get_data(packet), 1924 1966 packet_get_data_length(packet)); 1925 1967 header->checksum = htons(flip_checksum(compact_checksum(checksum))); 1926 1968 1927 1969 // prepare the packet 1928 if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 1929 0, 0)) || ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, 1930 socket_data, sequence_number, socket_data->state, 1931 socket_data->timeout, true))) { 1970 rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0); 1971 if (rc != EOK) { 1972 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1973 return NULL; 1974 } 1975 rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data, 1976 sequence_number, socket_data->state, socket_data->timeout, true); 1977 if (rc != EOK) { 1932 1978 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1933 1979 return NULL; … … 2038 2084 size_t *addrlen) 2039 2085 { 2040 ERROR_DECLARE;2041 2042 2086 socket_core_ref socket; 2043 2087 tcp_socket_data_ref socket_data; … … 2045 2089 packet_t packet; 2046 2090 size_t length; 2091 int rc; 2047 2092 2048 2093 assert(local_sockets); … … 2066 2111 // send the source address if desired 2067 2112 if (addrlen) { 2068 ERROR_PROPAGATE(data_reply(socket_data->addr, 2069 socket_data->addrlen)); 2113 rc = data_reply(socket_data->addr, socket_data->addrlen); 2114 if (rc != EOK) 2115 return rc; 2070 2116 *addrlen = socket_data->addrlen; 2071 2117 } … … 2076 2122 return NO_DATA; 2077 2123 2078 ERROR_PROPAGATE(packet_translate_remote(tcp_globals.net_phone, &packet, 2079 packet_id)); 2124 rc = packet_translate_remote(tcp_globals.net_phone, &packet, packet_id); 2125 if (rc != EOK) 2126 return rc; 2080 2127 2081 2128 // reply the packets 2082 ERROR_PROPAGATE(socket_reply_packets(packet, &length)); 2129 rc = socket_reply_packets(packet, &length); 2130 if (rc != EOK) 2131 return rc; 2083 2132 2084 2133 // release the packet … … 2093 2142 size_t *data_fragment_size, int flags) 2094 2143 { 2095 ERROR_DECLARE;2096 2097 2144 socket_core_ref socket; 2098 2145 tcp_socket_data_ref socket_data; … … 2103 2150 int index; 2104 2151 int result; 2152 int rc; 2105 2153 2106 2154 assert(local_sockets); … … 2123 2171 return ENOTCONN; 2124 2172 2125 ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2126 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension)); 2173 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2174 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2175 if (rc != EOK) 2176 return rc; 2127 2177 2128 2178 *data_fragment_size = … … 2145 2195 2146 2196 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); 2147 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 2148 0)); 2197 rc = tcp_queue_packet(socket, socket_data, packet, 0); 2198 if (rc != EOK) 2199 return rc; 2149 2200 } 2150 2201 … … 2165 2216 tcp_close_message(socket_cores_ref local_sockets, int socket_id) 2166 2217 { 2167 ERROR_DECLARE;2168 2169 2218 socket_core_ref socket; 2170 2219 tcp_socket_data_ref socket_data; 2171 2220 packet_t packet; 2221 int rc; 2172 2222 2173 2223 // find the socket … … 2194 2244 default: 2195 2245 // just destroy 2196 if (ERROR_NONE(socket_destroy(tcp_globals.net_phone, socket_id,2246 rc = socket_destroy(tcp_globals.net_phone, socket_id, 2197 2247 local_sockets, &tcp_globals.sockets, 2198 tcp_free_socket_data))) { 2248 tcp_free_socket_data); 2249 if (rc == EOK) { 2199 2250 fibril_rwlock_write_unlock(socket_data->local_lock); 2200 2251 fibril_rwlock_write_unlock(&tcp_globals.lock); 2201 2252 } 2202 return ERROR_CODE;2253 return rc; 2203 2254 } 2204 2255 … … 2207 2258 2208 2259 // create the notification packet 2209 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 2210 socket_data, 0, 1)); 2260 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 2261 if (rc != EOK) 2262 return rc; 2211 2263 2212 2264 // send the packet 2213 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 1)); 2265 rc = tcp_queue_packet(socket, socket_data, packet, 1); 2266 if (rc != EOK) 2267 return rc; 2214 2268 2215 2269 // flush packets … … 2230 2284 tcp_socket_data_ref socket_data, int synchronize, int finalize) 2231 2285 { 2232 ERROR_DECLARE;2233 2234 2286 packet_dimension_ref packet_dimension; 2235 2287 tcp_header_ref header; 2288 int rc; 2236 2289 2237 2290 assert(packet); 2238 2291 2239 2292 // get the device packet dimension 2240 ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2241 &tcp_globals.dimensions, socket_data->device_id, 2242 &packet_dimension)); 2293 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2294 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2295 if (rc != EOK) 2296 return rc; 2243 2297 2244 2298 // get a new packet … … 2265 2319 int new_socket_id, size_t *data_fragment_size, size_t *addrlen) 2266 2320 { 2267 ERROR_DECLARE;2268 2269 2321 socket_core_ref accepted; 2270 2322 socket_core_ref socket; 2271 2323 tcp_socket_data_ref socket_data; 2272 2324 packet_dimension_ref packet_dimension; 2325 int rc; 2273 2326 2274 2327 assert(local_sockets); … … 2304 2357 // TODO can it be in another state? 2305 2358 if (socket_data->state == TCP_SOCKET_ESTABLISHED) { 2306 ERROR_PROPAGATE(data_reply(socket_data->addr, 2307 socket_data->addrlen)); 2308 ERROR_PROPAGATE(tl_get_ip_packet_dimension( 2309 tcp_globals.ip_phone, &tcp_globals.dimensions, 2310 socket_data->device_id, &packet_dimension)); 2359 rc = data_reply(socket_data->addr, 2360 socket_data->addrlen); 2361 if (rc != EOK) 2362 return rc; 2363 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2364 &tcp_globals.dimensions, socket_data->device_id, 2365 &packet_dimension); 2366 if (rc != EOK) 2367 return rc; 2311 2368 *addrlen = socket_data->addrlen; 2312 2369 … … 2318 2375 2319 2376 if (new_socket_id > 0) { 2320 ERROR_PROPAGATE(socket_cores_update( 2321 local_sockets, accepted->socket_id, 2322 new_socket_id)); 2377 rc = socket_cores_update(local_sockets, 2378 accepted->socket_id, new_socket_id); 2379 if (rc != EOK) 2380 return rc; 2323 2381 accepted->socket_id = new_socket_id; 2324 2382 } … … 2430 2488 main(int argc, char *argv[]) 2431 2489 { 2432 ERROR_DECLARE; 2433 2434 /* 2435 Start the module 2436 */ 2437 if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection))) 2438 return ERROR_CODE; 2439 2440 return EOK; 2490 int rc; 2491 2492 rc = tl_module_start_standalone(tl_client_connection); 2493 return rc; 2441 2494 } 2442 2495 -
uspace/srv/net/tl/tcp/tcp_module.c
r0485135 r0b81cad0 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> … … 61 61 int tl_module_start_standalone(async_client_conn_t client_connection) 62 62 { 63 ERROR_DECLARE; 64 63 ipcarg_t phonehash; 64 int rc; 65 65 66 async_set_client_connection(client_connection); 66 67 tcp_globals.net_phone = net_connect_module(); 67 ERROR_PROPAGATE(pm_init()); 68 69 ipcarg_t phonehash; 70 if (ERROR_OCCURRED(tcp_initialize(client_connection)) || 71 ERROR_OCCURRED(REGISTER_ME(SERVICE_TCP, &phonehash))) { 72 pm_destroy(); 73 return ERROR_CODE; 74 } 68 69 rc = pm_init(); 70 if (rc != EOK) 71 return rc; 72 73 rc = tcp_initialize(client_connection); 74 if (rc != EOK) 75 goto out; 76 77 rc = REGISTER_ME(SERVICE_TCP, &phonehash); 78 if (rc != EOK) 79 goto out; 75 80 76 81 async_manager(); 77 82 83 out: 78 84 pm_destroy(); 79 return EOK;85 return rc; 80 86 } 81 87 -
uspace/srv/net/tl/udp/udp.c
r0485135 r0b81cad0 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); … … 460 481 if ((socket->port <= 0) && udp_globals.autobinding) { 461 482 // bind the socket to a random free port if not bound 462 // do { 463 // try to find a free port 464 // fibril_rwlock_read_unlock(&udp_globals.lock); 465 // fibril_rwlock_write_lock(&udp_globals.lock); 466 // might be changed in the meantime 467 // 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))) { 472 // fibril_rwlock_write_unlock( 473 // &udp_globals.lock); 474 // fibril_rwlock_read_lock( 475 // &udp_globals.lock); 476 return ERROR_CODE; 477 } 478 // set the next port as the search starting port 479 // number 480 udp_globals.last_used_port = socket->port; 481 // } 482 // fibril_rwlock_write_unlock(&udp_globals.lock); 483 // fibril_rwlock_read_lock(&udp_globals.lock); 484 // might be changed in the meantime 485 // } while (socket->port <= 0); 483 rc = socket_bind_free_port(&udp_globals.sockets, socket, 484 UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, 485 udp_globals.last_used_port); 486 if (rc != EOK) 487 return rc; 488 // set the next port as the search starting port number 489 udp_globals.last_used_port = socket->port; 486 490 } 487 491 488 492 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 } 493 rc = ip_get_route_req(udp_globals.ip_phone, IPPROTO_UDP, addr, 494 addrlen, &device_id, &ip_header, &headerlen); 495 if (rc != EOK) 496 return rc; 494 497 // 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)); 498 // rc = tl_get_ip_packet_dimension(udp_globals.ip_phone, 499 // &udp_globals.dimensions, device_id, &packet_dimension); 500 // if (rc != EOK) 501 // return rc; 497 502 } 498 503 // } else { 499 504 // do not ask all the time 500 ERROR_PROPAGATE(ip_packet_size_req(udp_globals.ip_phone, -1, 501 &udp_globals.packet_dimension)); 505 rc = ip_packet_size_req(udp_globals.ip_phone, -1, 506 &udp_globals.packet_dimension); 507 if (rc != EOK) 508 return rc; 502 509 packet_dimension = &udp_globals.packet_dimension; 503 510 // } … … 529 536 return udp_release_and_return(packet, result); 530 537 531 if (ERROR_OCCURRED(pq_add(&packet, next_packet, index, 0))) 532 return udp_release_and_return(packet, ERROR_CODE); 538 rc = pq_add(&packet, next_packet, index, 0); 539 if (rc != EOK) 540 return udp_release_and_return(packet, rc); 533 541 534 542 total_length += (size_t) result; … … 547 555 if (udp_globals.checksum_computing) { 548 556 // update the pseudo header 549 if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length( 550 ip_header, headerlen, total_length + UDP_HEADER_SIZE))) { 557 rc = ip_client_set_pseudo_header_data_length(ip_header, 558 headerlen, total_length + UDP_HEADER_SIZE); 559 if (rc != EOK) { 551 560 free(ip_header); 552 return udp_release_and_return(packet, ERROR_CODE);561 return udp_release_and_return(packet, rc); 553 562 } 554 563 … … 565 574 566 575 // 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 } 576 rc = ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 0, 0); 577 if (rc != EOK) 578 return udp_release_and_return(packet, rc); 579 580 /* Release the UDP global lock on success. */ 581 fibril_rwlock_write_unlock(&udp_globals.lock); 571 582 572 583 // send the packet 573 fibril_rwlock_write_unlock(&udp_globals.lock);574 584 ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0); 575 585 … … 600 610 size_t *addrlen) 601 611 { 602 ERROR_DECLARE;603 604 612 socket_core_ref socket; 605 613 int packet_id; … … 610 618 uint8_t *data; 611 619 int result; 620 int rc; 612 621 613 622 // find the socket … … 620 629 if (packet_id < 0) 621 630 return NO_DATA; 622 623 ERROR_PROPAGATE(packet_translate_remote(udp_globals.net_phone, &packet, 624 packet_id)); 631 632 rc = packet_translate_remote(udp_globals.net_phone, &packet, packet_id); 633 if (rc != EOK) { 634 (void) dyn_fifo_pop(&socket->received); 635 return rc; 636 } 625 637 626 638 // get udp header 627 639 data = packet_get_data(packet); 628 640 if (!data) { 629 pq_release_remote(udp_globals.net_phone, packet_id);630 return NO_DATA;641 (void) dyn_fifo_pop(&socket->received); 642 return udp_release_and_return(packet, NO_DATA); 631 643 } 632 644 header = (udp_header_ref) data; … … 634 646 // set the source address port 635 647 result = packet_get_addr(packet, (uint8_t **) &addr, NULL); 636 if (ERROR_OCCURRED(tl_set_address_port(addr, result,637 ntohs(header->source_port)))) {638 pq_release_remote(udp_globals.net_phone, packet_id);639 return ERROR_CODE;648 rc = tl_set_address_port(addr, result, ntohs(header->source_port)); 649 if (rc != EOK) { 650 (void) dyn_fifo_pop(&socket->received); 651 return udp_release_and_return(packet, rc); 640 652 } 641 653 *addrlen = (size_t) result; 642 654 643 655 // send the source address 644 ERROR_PROPAGATE(data_reply(addr, *addrlen)); 656 rc = data_reply(addr, *addrlen); 657 switch (rc) { 658 case EOK: 659 break; 660 case EOVERFLOW: 661 return rc; 662 default: 663 (void) dyn_fifo_pop(&socket->received); 664 return udp_release_and_return(packet, rc); 665 } 645 666 646 667 // trim the header 647 ERROR_PROPAGATE(packet_trim(packet, UDP_HEADER_SIZE, 0)); 668 rc = packet_trim(packet, UDP_HEADER_SIZE, 0); 669 if (rc != EOK) { 670 (void) dyn_fifo_pop(&socket->received); 671 return udp_release_and_return(packet, rc); 672 } 648 673 649 674 // reply the packets 650 ERROR_PROPAGATE(socket_reply_packets(packet, &length)); 651 652 // release the packet 653 dyn_fifo_pop(&socket->received); 654 pq_release_remote(udp_globals.net_phone, packet_get_id(packet)); 655 656 // return the total length 657 return (int) length; 675 rc = socket_reply_packets(packet, &length); 676 switch (rc) { 677 case EOK: 678 break; 679 case EOVERFLOW: 680 return rc; 681 default: 682 (void) dyn_fifo_pop(&socket->received); 683 return udp_release_and_return(packet, rc); 684 } 685 686 (void) dyn_fifo_pop(&socket->received); 687 688 // release the packet and return the total length 689 return udp_release_and_return(packet, (int) length); 658 690 } 659 691 … … 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
r0485135 r0b81cad0 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.