Changes in uspace/srv/net/il/ip/ip.c [849ed54:14f1db0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/ip/ip.c
r849ed54 r14f1db0 69 69 #include <adt/module_map.h> 70 70 #include <packet/packet_client.h> 71 #include <packet_remote.h> 71 72 #include <nil_messages.h> 72 73 #include <il_messages.h> 74 #include <il_local.h> 75 #include <ip_local.h> 73 76 74 77 #include "ip.h" … … 79 82 /** IP module name. 80 83 */ 81 #define NAME "IP protocol"84 #define NAME "ip" 82 85 83 86 /** IP version 4. … … 424 427 } 425 428 426 int ip_device_req (int il_phone, device_id_t device_id, services_t netif){429 int ip_device_req_local(int il_phone, device_id_t device_id, services_t netif){ 427 430 ERROR_DECLARE; 428 431 … … 430 433 ip_route_ref route; 431 434 int index; 432 char * data;433 435 434 436 ip_netif = (ip_netif_ref) malloc(sizeof(ip_netif_t)); … … 454 456 } 455 457 // print the settings 456 printf("New device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d\n", ip_netif->device_id, ip_netif->phone, ip_netif->ipv); 457 printf("\tconfiguration\t= %s\n", ip_netif->dhcp ? "dhcp" : "static"); 458 printf("%s: Device registered (id: %d, phone: %d, ipv: %d, conf: %s)\n", 459 NAME, ip_netif->device_id, ip_netif->phone, ip_netif->ipv, 460 ip_netif->dhcp ? "dhcp" : "static"); 461 458 462 // TODO ipv6 addresses 459 data = (char *) malloc(INET_ADDRSTRLEN); 460 if(data){ 461 for(index = 0; index < ip_routes_count(&ip_netif->routes); ++ index){ 462 route = ip_routes_get_index(&ip_netif->routes, index); 463 if(route){ 464 printf("\tRouting %d:\n", index); 465 inet_ntop(AF_INET, (uint8_t *) &route->address.s_addr, data, INET_ADDRSTRLEN); 466 printf("\t\taddress\t= %s\n", data); 467 inet_ntop(AF_INET, (uint8_t *) &route->netmask.s_addr, data, INET_ADDRSTRLEN); 468 printf("\t\tnetmask\t= %s\n", data); 469 inet_ntop(AF_INET, (uint8_t *) &route->gateway.s_addr, data, INET_ADDRSTRLEN); 470 printf("\t\tgateway\t= %s\n", data); 471 } 472 } 473 inet_ntop(AF_INET, (uint8_t *) &ip_netif->broadcast.s_addr, data, INET_ADDRSTRLEN); 474 printf("\t\tbroadcast\t= %s\n", data); 475 free(data); 476 } 463 464 char address[INET_ADDRSTRLEN]; 465 char netmask[INET_ADDRSTRLEN]; 466 char gateway[INET_ADDRSTRLEN]; 467 468 for (index = 0; index < ip_routes_count(&ip_netif->routes); ++ index){ 469 route = ip_routes_get_index(&ip_netif->routes, index); 470 if (route) { 471 inet_ntop(AF_INET, (uint8_t *) &route->address.s_addr, address, INET_ADDRSTRLEN); 472 inet_ntop(AF_INET, (uint8_t *) &route->netmask.s_addr, netmask, INET_ADDRSTRLEN); 473 inet_ntop(AF_INET, (uint8_t *) &route->gateway.s_addr, gateway, INET_ADDRSTRLEN); 474 printf("%s: Route %d (address: %s, netmask: %s, gateway: %s)\n", 475 NAME, index, address, netmask, gateway); 476 } 477 } 478 479 inet_ntop(AF_INET, (uint8_t *) &ip_netif->broadcast.s_addr, address, INET_ADDRSTRLEN); 480 printf("%s: Broadcast (%s)\n", NAME, address); 481 477 482 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 478 483 return EOK; … … 595 600 } 596 601 netif->packet_dimension.content = mtu; 597 printf(" ip - device %d changed mtu to %d\n\n", device_id, mtu);602 printf("%s: Device %d changed MTU to %d\n", NAME, device_id, mtu); 598 603 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 599 604 return EOK; … … 611 616 } 612 617 netif->state = state; 613 printf(" ip - device %d changed state to %d\n\n", device_id, state);618 printf("%s: Device %d changed state to %d\n", NAME, device_id, state); 614 619 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 615 620 return EOK; … … 646 651 return index; 647 652 } 648 printf("New protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d\n", proto->protocol, proto->phone); 653 654 printf("%s: Protocol registered (protocol: %d, phone: %d)\n", 655 NAME, proto->protocol, proto->phone); 656 649 657 fibril_rwlock_write_unlock(&ip_globals.protos_lock); 650 658 return EOK; 651 659 } 652 660 653 int ip_send_msg (int il_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){661 int ip_send_msg_local(int il_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){ 654 662 ERROR_DECLARE; 655 663 … … 777 785 // sleep(1); 778 786 // ERROR_PROPAGATE(arp_translate_req(netif->arp->phone, netif->device_id, SERVICE_IP, &destination, &translation, &data)); 779 pq_release (ip_globals.net_phone, packet_get_id(packet));787 pq_release_remote(ip_globals.net_phone, packet_get_id(packet)); 780 788 return ERROR_CODE; 781 789 } … … 794 802 }else translation = NULL; 795 803 if(ERROR_OCCURRED(ip_prepare_packet(src, dest, packet, translation))){ 796 pq_release (ip_globals.net_phone, packet_get_id(packet));804 pq_release_remote(ip_globals.net_phone, packet_get_id(packet)); 797 805 }else{ 798 806 packet = ip_split_packet(packet, netif->packet_dimension.prefix, netif->packet_dimension.content, netif->packet_dimension.suffix, netif->packet_dimension.addr_len, error); … … 886 894 } 887 895 888 int ip_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 896 int ip_message_standalone(ipc_callid_t callid, ipc_call_t *call, 897 ipc_call_t *answer, int * answer_count) 898 { 889 899 ERROR_DECLARE; 890 900 891 901 packet_t packet; 892 struct sockaddr * 902 struct sockaddr *addr; 893 903 size_t addrlen; 894 904 size_t prefix; 895 905 size_t suffix; 896 906 size_t content; 897 ip_pseudo_header_refheader;907 void *header; 898 908 size_t headerlen; 899 909 device_id_t device_id; 900 910 901 911 *answer_count = 0; 902 switch (IPC_GET_METHOD(*call)){912 switch (IPC_GET_METHOD(*call)) { 903 913 case IPC_M_PHONE_HUNGUP: 904 914 return EOK; 905 915 case NET_IL_DEVICE: 906 return ip_device_req(0, IPC_GET_DEVICE(call), IPC_GET_SERVICE(call)); 916 return ip_device_req_local(0, IPC_GET_DEVICE(call), 917 IPC_GET_SERVICE(call)); 907 918 case IPC_M_CONNECT_TO_ME: 908 return ip_register(IL_GET_PROTO(call), IL_GET_SERVICE(call), IPC_GET_PHONE(call), NULL); 919 return ip_register(IL_GET_PROTO(call), IL_GET_SERVICE(call), 920 IPC_GET_PHONE(call), NULL); 909 921 case NET_IL_SEND: 910 ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call))); 911 return ip_send_msg(0, IPC_GET_DEVICE(call), packet, 0, IPC_GET_ERROR(call)); 922 ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, &packet, 923 IPC_GET_PACKET(call))); 924 return ip_send_msg_local(0, IPC_GET_DEVICE(call), packet, 0, 925 IPC_GET_ERROR(call)); 912 926 case NET_IL_DEVICE_STATE: 913 return ip_device_state_message(IPC_GET_DEVICE(call), IPC_GET_STATE(call)); 927 return ip_device_state_message(IPC_GET_DEVICE(call), 928 IPC_GET_STATE(call)); 914 929 case NET_IL_RECEIVED: 915 ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call))); 930 ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, &packet, 931 IPC_GET_PACKET(call))); 916 932 return ip_receive_message(IPC_GET_DEVICE(call), packet); 917 933 case NET_IP_RECEIVED_ERROR: 918 ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call))); 919 return ip_received_error_msg(0, IPC_GET_DEVICE(call), packet, IPC_GET_TARGET(call), IPC_GET_ERROR(call)); 934 ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, &packet, 935 IPC_GET_PACKET(call))); 936 return ip_received_error_msg_local(0, IPC_GET_DEVICE(call), packet, 937 IPC_GET_TARGET(call), IPC_GET_ERROR(call)); 920 938 case NET_IP_ADD_ROUTE: 921 return ip_add_route_req(0, IPC_GET_DEVICE(call), IP_GET_ADDRESS(call), IP_GET_NETMASK(call), IP_GET_GATEWAY(call)); 939 return ip_add_route_req_local(0, IPC_GET_DEVICE(call), 940 IP_GET_ADDRESS(call), IP_GET_NETMASK(call), IP_GET_GATEWAY(call)); 922 941 case NET_IP_SET_GATEWAY: 923 return ip_set_gateway_req(0, IPC_GET_DEVICE(call), IP_GET_GATEWAY(call)); 942 return ip_set_gateway_req_local(0, IPC_GET_DEVICE(call), 943 IP_GET_GATEWAY(call)); 924 944 case NET_IP_GET_ROUTE: 925 945 ERROR_PROPAGATE(data_receive((void **) &addr, &addrlen)); 926 ERROR_PROPAGATE(ip_get_route_req (0, IP_GET_PROTOCOL(call), addr, (socklen_t) addrlen,927 &device_id, &header, &headerlen));946 ERROR_PROPAGATE(ip_get_route_req_local(0, IP_GET_PROTOCOL(call), 947 addr, (socklen_t) addrlen, &device_id, &header, &headerlen)); 928 948 IPC_SET_DEVICE(answer, device_id); 929 949 IP_SET_HEADERLEN(answer, headerlen); 950 930 951 *answer_count = 2; 931 if(! ERROR_OCCURRED(data_reply(&headerlen, sizeof(headerlen)))){ 952 953 if (!ERROR_OCCURRED(data_reply(&headerlen, sizeof(headerlen)))) 932 954 ERROR_CODE = data_reply(header, headerlen); 933 }955 934 956 free(header); 935 957 return ERROR_CODE; 936 958 case NET_IL_PACKET_SPACE: 937 ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call), &addrlen, &prefix, &content, &suffix)); 959 ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call), 960 &addrlen, &prefix, &content, &suffix)); 938 961 IPC_SET_ADDR(answer, addrlen); 939 962 IPC_SET_PREFIX(answer, prefix); … … 943 966 return EOK; 944 967 case NET_IL_MTU_CHANGED: 945 return ip_mtu_changed_message(IPC_GET_DEVICE(call), IPC_GET_MTU(call)); 946 } 968 return ip_mtu_changed_message(IPC_GET_DEVICE(call), 969 IPC_GET_MTU(call)); 970 } 971 947 972 return ENOTSUP; 948 973 } 949 974 950 int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){ 951 if(! packet_dimension){ 975 int ip_packet_size_req_local(int ip_phone, device_id_t device_id, 976 packet_dimension_ref packet_dimension) 977 { 978 if (!packet_dimension) 952 979 return EBADMEM; 953 } 954 return ip_packet_size_message(device_id, &packet_dimension->addr_len, &packet_dimension->prefix, &packet_dimension->content, &packet_dimension->suffix); 980 981 return ip_packet_size_message(device_id, &packet_dimension->addr_len, 982 &packet_dimension->prefix, &packet_dimension->content, 983 &packet_dimension->suffix); 955 984 } 956 985 … … 998 1027 } 999 1028 1000 int ip_add_route_req (int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){1029 int ip_add_route_req_local(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){ 1001 1030 ip_route_ref route; 1002 1031 ip_netif_ref netif; … … 1062 1091 } 1063 1092 1064 int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){ 1093 int ip_set_gateway_req_local(int ip_phone, device_id_t device_id, in_addr_t gateway) 1094 { 1065 1095 ip_netif_ref netif; 1066 1096 … … 1107 1137 } 1108 1138 }else{ 1109 pq_release (ip_globals.net_phone, packet_get_id(next));1139 pq_release_remote(ip_globals.net_phone, packet_get_id(next)); 1110 1140 } 1111 1141 next = new_packet; … … 1148 1178 } 1149 1179 // create the last fragment 1150 new_packet = packet_get_4 (ip_globals.net_phone, prefix, length, suffix, ((addrlen > addr_len) ? addrlen : addr_len));1180 new_packet = packet_get_4_remote(ip_globals.net_phone, prefix, length, suffix, ((addrlen > addr_len) ? addrlen : addr_len)); 1151 1181 if(! new_packet){ 1152 1182 return ENOMEM; … … 1172 1202 // create middle framgents 1173 1203 while(IP_TOTAL_LENGTH(header) > length){ 1174 new_packet = packet_get_4 (ip_globals.net_phone, prefix, length, suffix, ((addrlen >= addr_len) ? addrlen : addr_len));1204 new_packet = packet_get_4_remote(ip_globals.net_phone, prefix, length, suffix, ((addrlen >= addr_len) ? addrlen : addr_len)); 1175 1205 if(! new_packet){ 1176 1206 return ENOMEM; … … 1352 1382 } 1353 1383 1354 int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){ 1384 /** Notify the IP module about the received error notification packet. 1385 * 1386 * @param[in] ip_phone The IP module phone used for (semi)remote calls. 1387 * @param[in] device_id The device identifier. 1388 * @param[in] packet The received packet or the received packet queue. 1389 * @param[in] target The target internetwork module service to be 1390 * delivered to. 1391 * @param[in] error The packet error reporting service. Prefixes the 1392 * received packet. 1393 * 1394 * @return EOK on success. 1395 * 1396 */ 1397 int ip_received_error_msg_local(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){ 1355 1398 uint8_t * data; 1356 1399 int offset; … … 1487 1530 next = pq_detach(packet); 1488 1531 if(next){ 1489 pq_release (ip_globals.net_phone, packet_get_id(next));1532 pq_release_remote(ip_globals.net_phone, packet_get_id(next)); 1490 1533 } 1491 1534 if(! header){ … … 1551 1594 1552 1595 int ip_release_and_return(packet_t packet, int result){ 1553 pq_release (ip_globals.net_phone, packet_get_id(packet));1596 pq_release_remote(ip_globals.net_phone, packet_get_id(packet)); 1554 1597 return result; 1555 1598 } 1556 1599 1557 int ip_get_route_req (int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, ip_pseudo_header_ref *header, size_t * headerlen){1600 int ip_get_route_req_local(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, void **header, size_t * headerlen){ 1558 1601 struct sockaddr_in * address_in; 1559 1602 // struct sockaddr_in6 * address_in6; … … 1619 1662 header_in->protocol = protocol; 1620 1663 header_in->data_length = 0; 1621 *header = (ip_pseudo_header_ref)header_in;1664 *header = header_in; 1622 1665 return EOK; 1623 1666 } 1624 1625 #ifdef CONFIG_NETWORKING_modular1626 1627 #include <il_standalone.h>1628 1667 1629 1668 /** Default thread for new connections. … … 1653 1692 1654 1693 /* Process the message */ 1655 int res = il_module_message(callid, &call, &answer, &answer_count); 1694 int res = il_module_message_standalone(callid, &call, &answer, 1695 &answer_count); 1656 1696 1657 1697 /* End if said to either by the message or the processing result */ … … 1677 1717 ERROR_DECLARE; 1678 1718 1679 /* Print the module label */1680 printf("Task %d - %s\n", task_get_id(), NAME);1681 1682 1719 /* Start the module */ 1683 if (ERROR_OCCURRED(il_module_start(il_client_connection))) { 1684 printf(" - ERROR %i\n", ERROR_CODE); 1720 if (ERROR_OCCURRED(il_module_start_standalone(il_client_connection))) 1685 1721 return ERROR_CODE; 1686 }1687 1722 1688 1723 return EOK; 1689 1724 } 1690 1725 1691 #endif /* CONFIG_NETWORKING_modular */1692 1693 1726 /** @} 1694 1727 */
Note:
See TracChangeset
for help on using the changeset viewer.