Changes in uspace/srv/net/il/ip/ip.c [19f857a:14f1db0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/ip/ip.c
r19f857a r14f1db0 41 41 #include <stdio.h> 42 42 #include <str.h> 43 44 43 #include <ipc/ipc.h> 45 44 #include <ipc/services.h> 46 47 45 #include <sys/types.h> 48 46 49 #include "../../err.h"50 #include "../../messages.h"51 #include "../../modules.h"52 53 #include "../../include/arp_interface.h"54 #include "../../include/byteorder.h"55 #include "../../include/checksum.h"56 #include "../../include/device.h"57 #include "../../include/icmp_client.h"58 #include "../../include/icmp_codes.h"59 #include "../../include/icmp_interface.h"60 #include "../../include/il_interface.h"61 #include "../../include/in.h"62 #include "../../include/in6.h"63 #include "../../include/inet.h"64 #include "../../include/ip_client.h"65 #include "../../include/ip_interface.h"66 #include "../../include/net_interface.h"67 #include "../../include/nil_interface.h"68 #include "../../include/tl_interface.h"69 #include "../../include/socket_codes.h"70 #include "../../include/socket_errno.h"71 #include "../../structures/measured_strings.h"72 #include "../../structures/module_map.h"73 #include "../../structures/packet/packet_client.h"74 75 #include "../../nil/nil_messages.h"76 77 #include "../il_messages.h"47 #include <net_err.h> 48 #include <net_messages.h> 49 #include <net_modules.h> 50 #include <arp_interface.h> 51 #include <net_byteorder.h> 52 #include <net_checksum.h> 53 #include <net_device.h> 54 #include <icmp_client.h> 55 #include <icmp_codes.h> 56 #include <icmp_interface.h> 57 #include <il_interface.h> 58 #include <in.h> 59 #include <in6.h> 60 #include <inet.h> 61 #include <ip_client.h> 62 #include <ip_interface.h> 63 #include <net_interface.h> 64 #include <nil_interface.h> 65 #include <tl_interface.h> 66 #include <socket_codes.h> 67 #include <socket_errno.h> 68 #include <adt/measured_strings.h> 69 #include <adt/module_map.h> 70 #include <packet/packet_client.h> 71 #include <packet_remote.h> 72 #include <nil_messages.h> 73 #include <il_messages.h> 74 #include <il_local.h> 75 #include <ip_local.h> 78 76 79 77 #include "ip.h" … … 81 79 #include "ip_messages.h" 82 80 #include "ip_module.h" 81 82 /** IP module name. 83 */ 84 #define NAME "ip" 83 85 84 86 /** IP version 4. … … 425 427 } 426 428 427 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){ 428 430 ERROR_DECLARE; 429 431 … … 431 433 ip_route_ref route; 432 434 int index; 433 char * data;434 435 435 436 ip_netif = (ip_netif_ref) malloc(sizeof(ip_netif_t)); … … 455 456 } 456 457 // print the settings 457 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); 458 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 459 462 // TODO ipv6 addresses 460 data = (char *) malloc(INET_ADDRSTRLEN); 461 if(data){ 462 for(index = 0; index < ip_routes_count(&ip_netif->routes); ++ index){ 463 route = ip_routes_get_index(&ip_netif->routes, index); 464 if(route){ 465 printf("\tRouting %d:\n", index); 466 inet_ntop(AF_INET, (uint8_t *) &route->address.s_addr, data, INET_ADDRSTRLEN); 467 printf("\t\taddress\t= %s\n", data); 468 inet_ntop(AF_INET, (uint8_t *) &route->netmask.s_addr, data, INET_ADDRSTRLEN); 469 printf("\t\tnetmask\t= %s\n", data); 470 inet_ntop(AF_INET, (uint8_t *) &route->gateway.s_addr, data, INET_ADDRSTRLEN); 471 printf("\t\tgateway\t= %s\n", data); 472 } 473 } 474 inet_ntop(AF_INET, (uint8_t *) &ip_netif->broadcast.s_addr, data, INET_ADDRSTRLEN); 475 printf("\t\tbroadcast\t= %s\n", data); 476 free(data); 477 } 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 478 482 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 479 483 return EOK; … … 596 600 } 597 601 netif->packet_dimension.content = mtu; 598 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); 599 603 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 600 604 return EOK; … … 612 616 } 613 617 netif->state = state; 614 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); 615 619 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 616 620 return EOK; … … 647 651 return index; 648 652 } 649 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 650 657 fibril_rwlock_write_unlock(&ip_globals.protos_lock); 651 658 return EOK; 652 659 } 653 660 654 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){ 655 662 ERROR_DECLARE; 656 663 … … 778 785 // sleep(1); 779 786 // ERROR_PROPAGATE(arp_translate_req(netif->arp->phone, netif->device_id, SERVICE_IP, &destination, &translation, &data)); 780 pq_release (ip_globals.net_phone, packet_get_id(packet));787 pq_release_remote(ip_globals.net_phone, packet_get_id(packet)); 781 788 return ERROR_CODE; 782 789 } … … 795 802 }else translation = NULL; 796 803 if(ERROR_OCCURRED(ip_prepare_packet(src, dest, packet, translation))){ 797 pq_release (ip_globals.net_phone, packet_get_id(packet));804 pq_release_remote(ip_globals.net_phone, packet_get_id(packet)); 798 805 }else{ 799 806 packet = ip_split_packet(packet, netif->packet_dimension.prefix, netif->packet_dimension.content, netif->packet_dimension.suffix, netif->packet_dimension.addr_len, error); … … 887 894 } 888 895 889 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 { 890 899 ERROR_DECLARE; 891 900 892 901 packet_t packet; 893 struct sockaddr * 902 struct sockaddr *addr; 894 903 size_t addrlen; 895 ip_pseudo_header_ref header; 904 size_t prefix; 905 size_t suffix; 906 size_t content; 907 void *header; 896 908 size_t headerlen; 897 909 device_id_t device_id; 898 910 899 911 *answer_count = 0; 900 switch (IPC_GET_METHOD(*call)){912 switch (IPC_GET_METHOD(*call)) { 901 913 case IPC_M_PHONE_HUNGUP: 902 914 return EOK; 903 915 case NET_IL_DEVICE: 904 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)); 905 918 case IPC_M_CONNECT_TO_ME: 906 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); 907 921 case NET_IL_SEND: 908 ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call))); 909 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)); 910 926 case NET_IL_DEVICE_STATE: 911 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)); 912 929 case NET_IL_RECEIVED: 913 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))); 914 932 return ip_receive_message(IPC_GET_DEVICE(call), packet); 915 933 case NET_IP_RECEIVED_ERROR: 916 ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call))); 917 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)); 918 938 case NET_IP_ADD_ROUTE: 919 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)); 920 941 case NET_IP_SET_GATEWAY: 921 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)); 922 944 case NET_IP_GET_ROUTE: 923 945 ERROR_PROPAGATE(data_receive((void **) &addr, &addrlen)); 924 ERROR_PROPAGATE(ip_get_route_req(0, IP_GET_PROTOCOL(call), addr, (socklen_t) addrlen, 925 &device_id, &header, &headerlen)); 926 *IPC_SET_DEVICE(answer) = device_id; 927 *IP_SET_HEADERLEN(answer) = headerlen; 946 ERROR_PROPAGATE(ip_get_route_req_local(0, IP_GET_PROTOCOL(call), 947 addr, (socklen_t) addrlen, &device_id, &header, &headerlen)); 948 IPC_SET_DEVICE(answer, device_id); 949 IP_SET_HEADERLEN(answer, headerlen); 950 928 951 *answer_count = 2; 929 if(! ERROR_OCCURRED(data_reply(&headerlen, sizeof(headerlen)))){ 952 953 if (!ERROR_OCCURRED(data_reply(&headerlen, sizeof(headerlen)))) 930 954 ERROR_CODE = data_reply(header, headerlen); 931 }955 932 956 free(header); 933 957 return ERROR_CODE; 934 958 case NET_IL_PACKET_SPACE: 935 ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call), IPC_SET_ADDR(answer), IPC_SET_PREFIX(answer), IPC_SET_CONTENT(answer), IPC_SET_SUFFIX(answer))); 936 *answer_count = 3; 959 ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call), 960 &addrlen, &prefix, &content, &suffix)); 961 IPC_SET_ADDR(answer, addrlen); 962 IPC_SET_PREFIX(answer, prefix); 963 IPC_SET_CONTENT(answer, content); 964 IPC_SET_SUFFIX(answer, suffix); 965 *answer_count = 4; 937 966 return EOK; 938 967 case NET_IL_MTU_CHANGED: 939 return ip_mtu_changed_message(IPC_GET_DEVICE(call), IPC_GET_MTU(call)); 940 } 968 return ip_mtu_changed_message(IPC_GET_DEVICE(call), 969 IPC_GET_MTU(call)); 970 } 971 941 972 return ENOTSUP; 942 973 } 943 974 944 int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){ 945 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) 946 979 return EBADMEM; 947 } 948 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); 949 984 } 950 985 … … 992 1027 } 993 1028 994 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){ 995 1030 ip_route_ref route; 996 1031 ip_netif_ref netif; … … 1056 1091 } 1057 1092 1058 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 { 1059 1095 ip_netif_ref netif; 1060 1096 … … 1101 1137 } 1102 1138 }else{ 1103 pq_release (ip_globals.net_phone, packet_get_id(next));1139 pq_release_remote(ip_globals.net_phone, packet_get_id(next)); 1104 1140 } 1105 1141 next = new_packet; … … 1142 1178 } 1143 1179 // create the last fragment 1144 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)); 1145 1181 if(! new_packet){ 1146 1182 return ENOMEM; … … 1166 1202 // create middle framgents 1167 1203 while(IP_TOTAL_LENGTH(header) > length){ 1168 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)); 1169 1205 if(! new_packet){ 1170 1206 return ENOMEM; … … 1346 1382 } 1347 1383 1348 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){ 1349 1398 uint8_t * data; 1350 1399 int offset; … … 1481 1530 next = pq_detach(packet); 1482 1531 if(next){ 1483 pq_release (ip_globals.net_phone, packet_get_id(next));1532 pq_release_remote(ip_globals.net_phone, packet_get_id(next)); 1484 1533 } 1485 1534 if(! header){ … … 1545 1594 1546 1595 int ip_release_and_return(packet_t packet, int result){ 1547 pq_release (ip_globals.net_phone, packet_get_id(packet));1596 pq_release_remote(ip_globals.net_phone, packet_get_id(packet)); 1548 1597 return result; 1549 1598 } 1550 1599 1551 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){ 1552 1601 struct sockaddr_in * address_in; 1553 1602 // struct sockaddr_in6 * address_in6; … … 1613 1662 header_in->protocol = protocol; 1614 1663 header_in->data_length = 0; 1615 *header = (ip_pseudo_header_ref)header_in;1664 *header = header_in; 1616 1665 return EOK; 1617 1666 } 1618 1667 1668 /** Default thread for new connections. 1669 * 1670 * @param[in] iid The initial message identifier. 1671 * @param[in] icall The initial message call structure. 1672 * 1673 */ 1674 static void il_client_connection(ipc_callid_t iid, ipc_call_t * icall) 1675 { 1676 /* 1677 * Accept the connection 1678 * - Answer the first IPC_M_CONNECT_ME_TO call. 1679 */ 1680 ipc_answer_0(iid, EOK); 1681 1682 while(true) { 1683 ipc_call_t answer; 1684 int answer_count; 1685 1686 /* Clear the answer structure */ 1687 refresh_answer(&answer, &answer_count); 1688 1689 /* Fetch the next message */ 1690 ipc_call_t call; 1691 ipc_callid_t callid = async_get_call(&call); 1692 1693 /* Process the message */ 1694 int res = il_module_message_standalone(callid, &call, &answer, 1695 &answer_count); 1696 1697 /* End if said to either by the message or the processing result */ 1698 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)) 1699 return; 1700 1701 /* Answer the message */ 1702 answer_call(callid, res, &answer, answer_count); 1703 } 1704 } 1705 1706 /** Starts the module. 1707 * 1708 * @param argc The count of the command line arguments. Ignored parameter. 1709 * @param argv The command line parameters. Ignored parameter. 1710 * 1711 * @returns EOK on success. 1712 * @returns Other error codes as defined for each specific module start function. 1713 * 1714 */ 1715 int main(int argc, char *argv[]) 1716 { 1717 ERROR_DECLARE; 1718 1719 /* Start the module */ 1720 if (ERROR_OCCURRED(il_module_start_standalone(il_client_connection))) 1721 return ERROR_CODE; 1722 1723 return EOK; 1724 } 1725 1619 1726 /** @} 1620 1727 */
Note:
See TracChangeset
for help on using the changeset viewer.