Changes in / [60898b6:a66e2993] in mainline
- Location:
- uspace
- Files:
-
- 4 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/arp/arp.c
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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
r60898b6 ra66e2993 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/udp/udp.c
r60898b6 ra66e2993 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 … … 626 617 627 618 // get the next received packet 628 packet_id = dyn_fifo_ pop(&socket->received);619 packet_id = dyn_fifo_value(&socket->received); 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 return rc; 622 623 ERROR_PROPAGATE(packet_translate_remote(udp_globals.net_phone, &packet, 624 packet_id)); 635 625 636 626 // get udp header 637 627 data = packet_get_data(packet); 638 if (!data) 639 return udp_release_and_return(packet, NO_DATA); 628 if (!data) { 629 pq_release_remote(udp_globals.net_phone, packet_id); 630 return NO_DATA; 631 } 640 632 header = (udp_header_ref) data; 641 633 642 634 // set the source address port 643 635 result = packet_get_addr(packet, (uint8_t **) &addr, NULL); 644 rc = tl_set_address_port(addr, result, ntohs(header->source_port)); 645 if (rc != EOK) 646 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; 640 } 647 641 *addrlen = (size_t) result; 648 642 649 643 // send the source address 650 rc = data_reply(addr, *addrlen); 651 if (rc != EOK) 652 return udp_release_and_return(packet, rc); 644 ERROR_PROPAGATE(data_reply(addr, *addrlen)); 653 645 654 646 // trim the header 655 rc = packet_trim(packet, UDP_HEADER_SIZE, 0); 656 if (rc != EOK) 657 return udp_release_and_return(packet, rc); 647 ERROR_PROPAGATE(packet_trim(packet, UDP_HEADER_SIZE, 0)); 658 648 659 649 // reply the packets 660 rc = socket_reply_packets(packet, &length); 661 if (rc != EOK) 662 return udp_release_and_return(packet, rc); 663 664 // release the packet and return the total length 665 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; 666 658 } 667 659 … … 834 826 ipc_call_t *answer, int *answer_count) 835 827 { 828 ERROR_DECLARE; 829 836 830 packet_t packet; 837 int rc;838 831 839 832 *answer_count = 0; … … 841 834 switch (IPC_GET_METHOD(*call)) { 842 835 case NET_TL_RECEIVED: 843 rc = packet_translate_remote(udp_globals.net_phone, &packet, 844 IPC_GET_PACKET(call)); 845 if (rc != EOK) 846 return rc; 847 return udp_received_msg(IPC_GET_DEVICE(call), packet, 848 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 849 843 case IPC_M_CONNECT_TO_ME: 850 844 return udp_process_client_messages(callid, * call); … … 856 850 /** Default thread for new connections. 857 851 * 858 * @param[in] iid The initial message identifier. 859 * @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 * 860 855 */ 861 856 static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall) … … 903 898 int main(int argc, char *argv[]) 904 899 { 905 int rc;900 ERROR_DECLARE; 906 901 907 902 /* Start the module */ 908 rc = tl_module_start_standalone(tl_client_connection); 909 return rc; 903 if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection))) 904 return ERROR_CODE; 905 906 return EOK; 910 907 } 911 908 -
uspace/srv/net/tl/udp/udp_module.c
r60898b6 ra66e2993 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.