Changes in uspace/srv/net/il/ip/ip.c [02314f8:fd8e8e1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/ip/ip.c
r02314f8 rfd8e8e1 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
Note:
See TracChangeset
for help on using the changeset viewer.