Changeset b40bfac in mainline for uspace/srv/net/il/ip/ip.c
- Timestamp:
- 2010-11-08T07:13:25Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 63a1e60
- Parents:
- d70a463 (diff), 3da12d74 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/ip/ip.c
rd70a463 rb40bfac 41 41 #include <async.h> 42 42 #include <errno.h> 43 #include <err.h>44 43 #include <fibril_synch.h> 45 44 #include <stdio.h> … … 254 253 int ip_initialize(async_client_conn_t client_connection) 255 254 { 256 ERROR_DECLARE;255 int rc; 257 256 258 257 fibril_rwlock_initialize(&ip_globals.lock); … … 265 264 ip_globals.gateway.gateway.s_addr = 0; 266 265 ip_globals.gateway.netif = NULL; 267 ERROR_PROPAGATE(ip_netifs_initialize(&ip_globals.netifs));268 ERROR_PROPAGATE(ip_protos_initialize(&ip_globals.protos));269 266 ip_globals.client_connection = client_connection; 270 ERROR_PROPAGATE(modules_initialize(&ip_globals.modules)); 271 ERROR_PROPAGATE(add_module(NULL, &ip_globals.modules, ARP_NAME, 272 ARP_FILENAME, SERVICE_ARP, 0, arp_connect_module)); 267 268 rc = ip_netifs_initialize(&ip_globals.netifs); 269 if (rc != EOK) 270 goto out; 271 rc = ip_protos_initialize(&ip_globals.protos); 272 if (rc != EOK) 273 goto out; 274 rc = modules_initialize(&ip_globals.modules); 275 if (rc != EOK) 276 goto out; 277 rc = add_module(NULL, &ip_globals.modules, ARP_NAME, ARP_FILENAME, 278 SERVICE_ARP, 0, arp_connect_module); 279 280 out: 273 281 fibril_rwlock_write_unlock(&ip_globals.lock); 274 282 275 return EOK;283 return rc; 276 284 } 277 285 … … 302 310 static int ip_netif_initialize(ip_netif_ref ip_netif) 303 311 { 304 ERROR_DECLARE;305 306 312 measured_string_t names[] = { 307 313 { … … 342 348 char *data; 343 349 measured_string_t address; 344 int index;345 350 ip_route_ref route; 346 351 in_addr_t gateway; 352 int index; 353 int rc; 347 354 348 355 ip_netif->arp = NULL; … … 354 361 355 362 // get configuration 356 ERROR_PROPAGATE(net_get_device_conf_req(ip_globals.net_phone, 357 ip_netif->device_id, &configuration, count, &data)); 363 rc = net_get_device_conf_req(ip_globals.net_phone, ip_netif->device_id, 364 &configuration, count, &data); 365 if (rc != EOK) 366 return rc; 367 358 368 if (configuration) { 359 369 if (configuration[0].value) … … 383 393 return index; 384 394 } 385 if (ERROR_OCCURRED(inet_pton(AF_INET, 386 configuration[2].value, 387 (uint8_t *) &route->address.s_addr)) || 388 ERROR_OCCURRED(inet_pton(AF_INET, 389 configuration[3].value, 390 (uint8_t *) &route->netmask.s_addr)) || 395 396 if ((inet_pton(AF_INET, configuration[2].value, 397 (uint8_t *) &route->address.s_addr) != EOK) || 398 (inet_pton(AF_INET, configuration[3].value, 399 (uint8_t *) &route->netmask.s_addr) != EOK) || 391 400 (inet_pton(AF_INET, configuration[4].value, 392 401 (uint8_t *) &gateway.s_addr) == EINVAL) || … … 434 443 address.value = (char *) &route->address.s_addr; 435 444 address.length = CONVERT_SIZE(in_addr_t, char, 1); 436 ERROR_PROPAGATE(arp_device_req(ip_netif->arp->phone, 445 446 rc = arp_device_req(ip_netif->arp->phone, 437 447 ip_netif->device_id, SERVICE_IP, ip_netif->service, 438 &address)); 448 &address); 449 if (rc != EOK) 450 return rc; 439 451 } else { 440 452 ip_netif->arp = 0; … … 443 455 444 456 // get packet dimensions 445 ERROR_PROPAGATE(nil_packet_size_req(ip_netif->phone, 446 ip_netif->device_id, &ip_netif->packet_dimension)); 457 rc = nil_packet_size_req(ip_netif->phone, ip_netif->device_id, 458 &ip_netif->packet_dimension); 459 if (rc != EOK) 460 return rc; 461 447 462 if (ip_netif->packet_dimension.content < IP_MIN_CONTENT) { 448 463 printf("Maximum transmission unit %d bytes is too small, at " … … 610 625 measured_string_ref destination) 611 626 { 612 ERROR_DECLARE;613 614 627 size_t length; 615 628 ip_header_ref header; … … 617 630 ip_header_ref middle_header; 618 631 packet_t next; 632 int rc; 619 633 620 634 length = packet_get_data_length(packet); … … 624 638 header = (ip_header_ref) packet_get_data(packet); 625 639 if (destination) { 626 ERROR_PROPAGATE(packet_set_addr(packet, NULL, 627 (uint8_t *) destination->value, 628 CONVERT_SIZE(char, uint8_t, destination->length))); 640 rc = packet_set_addr(packet, NULL, (uint8_t *) destination->value, 641 CONVERT_SIZE(char, uint8_t, destination->length)); 629 642 } else { 630 ERROR_PROPAGATE(packet_set_addr(packet, NULL, NULL, 0)); 631 } 643 rc = packet_set_addr(packet, NULL, NULL, 0); 644 } 645 if (rc != EOK) 646 return rc; 647 632 648 header->version = IPV4; 633 649 header->fragment_offset_high = 0; … … 669 685 IP_HEADER_CHECKSUM(middle_header); 670 686 if (destination) { 671 if (ERROR_OCCURRED(packet_set_addr(next, NULL,687 rc = packet_set_addr(next, NULL, 672 688 (uint8_t *) destination->value, 673 689 CONVERT_SIZE(char, uint8_t, 674 destination->length)))) { 690 destination->length)); 691 if (rc != EOK) { 675 692 free(last_header); 676 return ERROR_CODE;693 return rc; 677 694 } 678 695 } … … 699 716 IP_HEADER_CHECKSUM(middle_header); 700 717 if (destination) { 701 if (ERROR_OCCURRED(packet_set_addr(next, NULL,718 rc = packet_set_addr(next, NULL, 702 719 (uint8_t *) destination->value, 703 CONVERT_SIZE(char, uint8_t, 704 destination->length)))) {720 CONVERT_SIZE(char, uint8_t, destination->length)); 721 if (rc != EOK) { 705 722 free(last_header); 706 return ERROR_CODE;707 723 return rc; 724 } 708 725 } 709 726 length += packet_get_data_length(next); … … 741 758 const struct sockaddr *src, const struct sockaddr *dest, socklen_t addrlen) 742 759 { 743 ERROR_DECLARE;744 745 760 void *data; 746 761 size_t offset; 762 int rc; 747 763 748 764 data = packet_suffix(new_packet, length); … … 752 768 memcpy(data, ((void *) header) + IP_TOTAL_LENGTH(header) - length, 753 769 length); 754 ERROR_PROPAGATE(packet_trim(packet, 0, length)); 770 771 rc = packet_trim(packet, 0, length); 772 if (rc != EOK) 773 return rc; 774 755 775 header->total_length = htons(IP_TOTAL_LENGTH(header) - length); 756 776 new_header->total_length = htons(IP_HEADER_LENGTH(new_header) + length); … … 761 781 IP_COMPUTE_FRAGMENT_OFFSET_LOW(offset); 762 782 new_header->header_checksum = IP_HEADER_CHECKSUM(new_header); 763 ERROR_PROPAGATE(packet_set_addr(new_packet, (const uint8_t *) src, 764 (const uint8_t *) dest, addrlen)); 783 784 rc = packet_set_addr(new_packet, (const uint8_t *) src, 785 (const uint8_t *) dest, addrlen); 786 if (rc != EOK) 787 return rc; 765 788 766 789 return pq_insert_after(packet, new_packet); … … 796 819 socklen_t addr_len) 797 820 { 798 ERROR_DECLARE;799 800 821 packet_t new_packet; 801 822 ip_header_ref header; … … 806 827 socklen_t addrlen; 807 828 int result; 829 int rc; 808 830 809 831 result = packet_get_addr(packet, (uint8_t **) &src, (uint8_t **) &dest); … … 839 861 840 862 // trim the unused space 841 if (ERROR_OCCURRED(packet_trim(new_packet, 0,842 IP_HEADER_LENGTH(header) - IP_HEADER_LENGTH(last_header)) )) {843 return ip_release_and_return(packet, ERROR_CODE);844 }863 rc = packet_trim(new_packet, 0, 864 IP_HEADER_LENGTH(header) - IP_HEADER_LENGTH(last_header)); 865 if (rc != EOK) 866 return ip_release_and_return(packet, rc); 845 867 846 868 // biggest multiple of 8 lower than content 847 869 // TODO even fragmentation? 848 870 length = length & ~0x7; 849 if (ERROR_OCCURRED(ip_fragment_packet_data(packet, new_packet, header,850 871 872 rc = ip_fragment_packet_data(packet, new_packet, header, last_header, 851 873 ((IP_HEADER_DATA_LENGTH(header) - 852 874 ((length - IP_HEADER_LENGTH(header)) & ~0x7)) % 853 ((length - IP_HEADER_LENGTH(last_header)) & ~0x7)), src, dest,854 addrlen))) {855 return ip_release_and_return(packet, ERROR_CODE);856 }875 ((length - IP_HEADER_LENGTH(last_header)) & ~0x7)), 876 src, dest, addrlen); 877 if (rc != EOK) 878 return ip_release_and_return(packet, rc); 857 879 858 880 // mark the first as fragmented … … 872 894 return ip_release_and_return(packet, ENOMEM); 873 895 874 if (ERROR_OCCURRED(ip_fragment_packet_data(packet, new_packet,875 header,middle_header,876 (length - IP_HEADER_LENGTH(middle_header)) & ~0x7, src,877 dest, addrlen))) {878 return ip_release_and_return(packet, ERROR_CODE);879 }896 rc = ip_fragment_packet_data(packet, new_packet, header, 897 middle_header, 898 (length - IP_HEADER_LENGTH(middle_header)) & ~0x7, 899 src, dest, addrlen); 900 if (rc != EOK) 901 return ip_release_and_return(packet, rc); 880 902 } 881 903 … … 974 996 in_addr_t *src, in_addr_t dest, services_t error) 975 997 { 976 ERROR_DECLARE;977 978 998 measured_string_t destination; 979 999 measured_string_ref translation; 980 1000 char *data; 981 1001 int phone; 1002 int rc; 982 1003 983 1004 // get destination hardware address … … 987 1008 destination.length = CONVERT_SIZE(dest.s_addr, char, 1); 988 1009 989 if (ERROR_OCCURRED(arp_translate_req(netif->arp->phone,990 netif->device_id, SERVICE_IP, &destination, &translation,991 &data))) {1010 rc = arp_translate_req(netif->arp->phone, netif->device_id, 1011 SERVICE_IP, &destination, &translation, &data); 1012 if (rc != EOK) { 992 1013 pq_release_remote(ip_globals.net_phone, 993 1014 packet_get_id(packet)); 994 return ERROR_CODE;1015 return rc; 995 1016 } 996 1017 … … 1014 1035 } 1015 1036 1016 if (ERROR_OCCURRED(ip_prepare_packet(src, dest, packet, translation))) { 1037 rc = ip_prepare_packet(src, dest, packet, translation); 1038 if (rc != EOK) { 1017 1039 pq_release_remote(ip_globals.net_phone, packet_get_id(packet)); 1018 1040 } else { … … 1032 1054 } 1033 1055 1034 return ERROR_CODE;1056 return rc; 1035 1057 } 1036 1058 … … 1158 1180 ip_device_req_local(int il_phone, device_id_t device_id, services_t netif) 1159 1181 { 1160 ERROR_DECLARE;1161 1162 1182 ip_netif_ref ip_netif; 1163 1183 ip_route_ref route; 1164 1184 int index; 1185 int rc; 1165 1186 1166 1187 ip_netif = (ip_netif_ref) malloc(sizeof(ip_netif_t)); … … 1168 1189 return ENOMEM; 1169 1190 1170 if (ERROR_OCCURRED(ip_routes_initialize(&ip_netif->routes))) { 1191 rc = ip_routes_initialize(&ip_netif->routes); 1192 if (rc != EOK) { 1171 1193 free(ip_netif); 1172 return ERROR_CODE;1194 return rc; 1173 1195 } 1174 1196 … … 1178 1200 1179 1201 fibril_rwlock_write_lock(&ip_globals.netifs_lock); 1180 if (ERROR_OCCURRED(ip_netif_initialize(ip_netif))) { 1202 1203 rc = ip_netif_initialize(ip_netif); 1204 if (rc != EOK) { 1181 1205 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 1182 1206 ip_routes_destroy(&ip_netif->routes); 1183 1207 free(ip_netif); 1184 return ERROR_CODE;1208 return rc; 1185 1209 } 1186 1210 if (ip_netif->arp) … … 1226 1250 services_t sender, services_t error) 1227 1251 { 1228 ERROR_DECLARE;1229 1230 1252 int addrlen; 1231 1253 ip_netif_ref netif; … … 1236 1258 in_addr_t *src; 1237 1259 int phone; 1260 int rc; 1238 1261 1239 1262 // addresses in the host byte order … … 1323 1346 } 1324 1347 1325 ERROR_CODE= ip_send_route(packet, netif, route, src, *dest, error);1348 rc = ip_send_route(packet, netif, route, src, *dest, error); 1326 1349 fibril_rwlock_read_unlock(&ip_globals.netifs_lock); 1327 1350 1328 return ERROR_CODE;1351 return rc; 1329 1352 } 1330 1353 … … 1431 1454 services_t error) 1432 1455 { 1433 ERROR_DECLARE;1434 1435 1456 ip_proto_ref proto; 1436 1457 int phone; … … 1442 1463 struct sockaddr_in dest_in; 1443 1464 socklen_t addrlen; 1465 int rc; 1444 1466 1445 1467 if ((header->flags & IPFLAG_MORE_FRAGMENTS) || … … 1467 1489 } 1468 1490 1469 if (ERROR_OCCURRED(packet_set_addr(packet, (uint8_t *) src,1470 (uint8_t *) dest, addrlen))) {1471 return ip_release_and_return(packet, ERROR_CODE);1472 }1491 rc = packet_set_addr(packet, (uint8_t *) src, (uint8_t *) dest, 1492 addrlen); 1493 if (rc != EOK) 1494 return ip_release_and_return(packet, rc); 1473 1495 1474 1496 // trim padding if present 1475 1497 if (!error && 1476 1498 (IP_TOTAL_LENGTH(header) < packet_get_data_length(packet))) { 1477 if (ERROR_OCCURRED(packet_trim(packet, 0, 1478 packet_get_data_length(packet) - IP_TOTAL_LENGTH(header)))) 1479 return ip_release_and_return(packet, ERROR_CODE); 1499 rc = packet_trim(packet, 0, 1500 packet_get_data_length(packet) - IP_TOTAL_LENGTH(header)); 1501 if (rc != EOK) 1502 return ip_release_and_return(packet, rc); 1480 1503 } 1481 1504 … … 1498 1521 received_msg = proto->received_msg; 1499 1522 fibril_rwlock_read_unlock(&ip_globals.protos_lock); 1500 ERROR_CODE= received_msg(device_id, packet, service, error);1523 rc = received_msg(device_id, packet, service, error); 1501 1524 } else { 1502 ERROR_CODE= tl_received_msg(proto->phone, device_id, packet,1525 rc = tl_received_msg(proto->phone, device_id, packet, 1503 1526 proto->service, error); 1504 1527 fibril_rwlock_read_unlock(&ip_globals.protos_lock); 1505 1528 } 1506 1529 1507 return ERROR_CODE;1530 return rc; 1508 1531 } 1509 1532 … … 1532 1555 ip_process_packet(device_id_t device_id, packet_t packet) 1533 1556 { 1534 ERROR_DECLARE;1535 1536 1557 ip_header_ref header; 1537 1558 in_addr_t dest; … … 1541 1562 struct sockaddr_in addr_in; 1542 1563 socklen_t addrlen; 1564 int rc; 1543 1565 1544 1566 header = (ip_header_ref) packet_get_data(packet); … … 1585 1607 } 1586 1608 1587 ERROR_PROPAGATE(packet_set_addr(packet, NULL, (uint8_t *) &addr, 1588 addrlen)); 1609 rc = packet_set_addr(packet, NULL, (uint8_t *) &addr, addrlen); 1610 if (rc != EOK) 1611 return rc; 1589 1612 1590 1613 route = ip_find_route(dest); … … 1867 1890 int *answer_count) 1868 1891 { 1869 ERROR_DECLARE;1870 1871 1892 packet_t packet; 1872 1893 struct sockaddr *addr; … … 1878 1899 size_t headerlen; 1879 1900 device_id_t device_id; 1901 int rc; 1880 1902 1881 1903 *answer_count = 0; … … 1893 1915 1894 1916 case NET_IL_SEND: 1895 ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, 1896 &packet, IPC_GET_PACKET(call))); 1917 rc = packet_translate_remote(ip_globals.net_phone, &packet, 1918 IPC_GET_PACKET(call)); 1919 if (rc != EOK) 1920 return rc; 1897 1921 return ip_send_msg_local(0, IPC_GET_DEVICE(call), packet, 0, 1898 1922 IPC_GET_ERROR(call)); … … 1903 1927 1904 1928 case NET_IL_RECEIVED: 1905 ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, 1906 &packet, IPC_GET_PACKET(call))); 1929 rc = packet_translate_remote(ip_globals.net_phone, &packet, 1930 IPC_GET_PACKET(call)); 1931 if (rc != EOK) 1932 return rc; 1907 1933 return ip_receive_message(IPC_GET_DEVICE(call), packet); 1908 1934 1909 1935 case NET_IP_RECEIVED_ERROR: 1910 ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, 1911 &packet, IPC_GET_PACKET(call))); 1936 rc = packet_translate_remote(ip_globals.net_phone, &packet, 1937 IPC_GET_PACKET(call)); 1938 if (rc != EOK) 1939 return rc; 1912 1940 return ip_received_error_msg_local(0, IPC_GET_DEVICE(call), 1913 1941 packet, IPC_GET_TARGET(call), IPC_GET_ERROR(call)); … … 1923 1951 1924 1952 case NET_IP_GET_ROUTE: 1925 ERROR_PROPAGATE(data_receive((void **) &addr, &addrlen)); 1926 ERROR_PROPAGATE(ip_get_route_req_local(0, IP_GET_PROTOCOL(call), 1927 addr, (socklen_t) addrlen, &device_id, &header, 1928 &headerlen)); 1953 rc = data_receive((void **) &addr, &addrlen); 1954 if (rc != EOK) 1955 return rc; 1956 1957 rc = ip_get_route_req_local(0, IP_GET_PROTOCOL(call), addr, 1958 (socklen_t) addrlen, &device_id, &header, &headerlen); 1959 if (rc != EOK) 1960 return rc; 1961 1929 1962 IPC_SET_DEVICE(answer, device_id); 1930 1963 IP_SET_HEADERLEN(answer, headerlen); 1931 1964 1932 1965 *answer_count = 2; 1933 1934 if (ERROR_NONE(data_reply(&headerlen, sizeof(headerlen)))) 1935 ERROR_CODE = data_reply(header, headerlen); 1966 1967 rc = data_reply(&headerlen, sizeof(headerlen)); 1968 if (rc == EOK) 1969 rc = data_reply(header, headerlen); 1936 1970 1937 1971 free(header); 1938 return ERROR_CODE;1972 return rc; 1939 1973 1940 1974 case NET_IL_PACKET_SPACE: 1941 ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call), 1942 &addrlen, &prefix, &content, &suffix)); 1975 rc = ip_packet_size_message(IPC_GET_DEVICE(call), &addrlen, 1976 &prefix, &content, &suffix); 1977 if (rc != EOK) 1978 return rc; 1979 1943 1980 IPC_SET_ADDR(answer, addrlen); 1944 1981 IPC_SET_PREFIX(answer, prefix); … … 2005 2042 int main(int argc, char *argv[]) 2006 2043 { 2007 ERROR_DECLARE;2044 int rc; 2008 2045 2009 2046 /* Start the module */ 2010 ERROR_PROPAGATE(il_module_start_standalone(il_client_connection));2011 return EOK;2047 rc = il_module_start_standalone(il_client_connection); 2048 return rc; 2012 2049 } 2013 2050
Note:
See TracChangeset
for help on using the changeset viewer.