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