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