Changes in uspace/srv/net/il/ip/ip.c [ccca251:00d7e1b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/ip/ip.c
rccca251 r00d7e1b 120 120 GENERIC_FIELD_IMPLEMENT(ip_routes, ip_route_t); 121 121 122 static void ip_receiver(ipc_callid_t, ipc_call_t *); 123 124 /** Releases the packet and returns the result. 125 * 126 * @param[in] packet The packet queue to be released. 127 * @param[in] result The result to be returned. 128 * @return The result parameter. 122 static void ip_receiver(ipc_callid_t, ipc_call_t *, void *); 123 124 /** Release the packet and returns the result. 125 * 126 * @param[in] packet Packet queue to be released. 127 * @param[in] result Result to be returned. 128 * 129 * @return Result parameter. 130 * 129 131 */ 130 132 static int ip_release_and_return(packet_t *packet, int result) 131 133 { 132 pq_release_remote(ip_globals.net_ phone, packet_get_id(packet));134 pq_release_remote(ip_globals.net_sess, packet_get_id(packet)); 133 135 return result; 134 136 } 135 137 136 /** Returns the ICMP phone. 137 * 138 * Searches the registered protocols. 139 * 140 * @return The found ICMP phone. 141 * @return ENOENT if the ICMP is not registered. 142 */ 143 static int ip_get_icmp_phone(void) 144 { 145 ip_proto_t *proto; 146 int phone; 147 138 /** Return the ICMP session. 139 * 140 * Search the registered protocols. 141 * 142 * @return Found ICMP session. 143 * @return NULL if the ICMP is not registered. 144 * 145 */ 146 static async_sess_t *ip_get_icmp_session(void) 147 { 148 148 fibril_rwlock_read_lock(&ip_globals.protos_lock); 149 proto = ip_protos_find(&ip_globals.protos, IPPROTO_ICMP);150 phone = proto ? proto->phone : ENOENT;149 ip_proto_t *proto = ip_protos_find(&ip_globals.protos, IPPROTO_ICMP); 150 async_sess_t *sess = proto ? proto->sess : NULL; 151 151 fibril_rwlock_read_unlock(&ip_globals.protos_lock); 152 return phone; 152 153 return sess; 153 154 } 154 155 … … 179 180 next = pq_detach(packet); 180 181 if (next) 181 pq_release_remote(ip_globals.net_ phone, packet_get_id(next));182 pq_release_remote(ip_globals.net_sess, packet_get_id(next)); 182 183 183 184 if (!header) { … … 201 202 202 203 /* Set the destination address */ 203 switch ( header->version) {204 switch (GET_IP_HEADER_VERSION(header)) { 204 205 case IPVERSION: 205 206 addrlen = sizeof(dest_in); … … 218 219 } 219 220 220 /** Prepare sthe ICMP notification packet.221 * 222 * Release s additional packets and keepsonly the first one.221 /** Prepare the ICMP notification packet. 222 * 223 * Release additional packets and keep only the first one. 223 224 * All packets are released on error. 224 225 * 225 * @param[in] error The packet error service. 226 * @param[in] packet The packet or the packet queue to be reported as faulty. 227 * @param[in] header The first packet IP header. May be NULL. 228 * @return The found ICMP phone. 229 * @return EINVAL if the error parameter is set. 230 * @return EINVAL if the ICMP phone is not found. 231 * @return EINVAL if the ip_prepare_icmp() fails. 232 */ 233 static int 234 ip_prepare_icmp_and_get_phone(services_t error, packet_t *packet, 235 ip_header_t *header) 236 { 237 int phone; 238 239 phone = ip_get_icmp_phone(); 240 if (error || (phone < 0) || ip_prepare_icmp(packet, header)) 241 return ip_release_and_return(packet, EINVAL); 242 return phone; 243 } 244 245 int il_initialize(int net_phone) 226 * @param[in] error Packet error service. 227 * @param[in] packet Packet or the packet queue to be reported as faulty. 228 * @param[in] header First packet IP header. May be NULL. 229 * 230 * @return Found ICMP session. 231 * @return NULL if the error parameter is set. 232 * @return NULL if the ICMP session is not found. 233 * @return NULL if the ip_prepare_icmp() fails. 234 * 235 */ 236 static async_sess_t *ip_prepare_icmp_and_get_session(services_t error, 237 packet_t *packet, ip_header_t *header) 238 { 239 async_sess_t *sess = ip_get_icmp_session(); 240 241 if ((error) || (!sess) || (ip_prepare_icmp(packet, header))) { 242 pq_release_remote(ip_globals.net_sess, packet_get_id(packet)); 243 return NULL; 244 } 245 246 return sess; 247 } 248 249 int il_initialize(async_sess_t *net_sess) 246 250 { 247 251 fibril_rwlock_initialize(&ip_globals.lock); … … 250 254 fibril_rwlock_initialize(&ip_globals.netifs_lock); 251 255 252 ip_globals.net_ phone = net_phone;256 ip_globals.net_sess = net_sess; 253 257 ip_globals.packet_counter = 0; 254 258 ip_globals.gateway.address.s_addr = 0; … … 350 354 ip_netif->routing = NET_DEFAULT_IP_ROUTING; 351 355 configuration = &names[0]; 352 356 353 357 /* Get configuration */ 354 rc = net_get_device_conf_req(ip_globals.net_ phone, ip_netif->device_id,358 rc = net_get_device_conf_req(ip_globals.net_sess, ip_netif->device_id, 355 359 &configuration, count, &data); 356 360 if (rc != EOK) … … 402 406 return ENOTSUP; 403 407 } 404 408 405 409 if (configuration[6].value) { 406 410 ip_netif->arp = get_running_module(&ip_globals.modules, … … 413 417 } 414 418 } 419 415 420 if (configuration[7].value) 416 421 ip_netif->routing = (configuration[7].value[0] == 'y'); 417 422 418 423 net_free_settings(configuration, data); 419 424 } 420 425 421 426 /* Bind netif service which also initializes the device */ 422 ip_netif-> phone= nil_bind_service(ip_netif->service,427 ip_netif->sess = nil_bind_service(ip_netif->service, 423 428 (sysarg_t) ip_netif->device_id, SERVICE_IP, 424 429 ip_receiver); 425 if (ip_netif-> phone < 0) {430 if (ip_netif->sess == NULL) { 426 431 printf("Failed to contact the nil service %d\n", 427 432 ip_netif->service); 428 return ip_netif->phone;429 } 430 433 return ENOENT; 434 } 435 431 436 /* Has to be after the device netif module initialization */ 432 437 if (ip_netif->arp) { … … 435 440 address.length = sizeof(in_addr_t); 436 441 437 rc = arp_device_req(ip_netif->arp-> phone,442 rc = arp_device_req(ip_netif->arp->sess, 438 443 ip_netif->device_id, SERVICE_IP, ip_netif->service, 439 444 &address); … … 444 449 } 445 450 } 446 451 447 452 /* Get packet dimensions */ 448 rc = nil_packet_size_req(ip_netif-> phone, ip_netif->device_id,453 rc = nil_packet_size_req(ip_netif->sess, ip_netif->device_id, 449 454 &ip_netif->packet_dimension); 450 455 if (rc != EOK) … … 457 462 ip_netif->packet_dimension.content = IP_MIN_CONTENT; 458 463 } 459 464 460 465 index = ip_netifs_add(&ip_globals.netifs, ip_netif->device_id, ip_netif); 461 466 if (index < 0) … … 474 479 printf("%s: Default gateway (%s)\n", NAME, defgateway); 475 480 } 476 481 477 482 return EOK; 478 483 } 479 484 480 static int ip_device_req_local(int il_phone, device_id_t device_id, 481 services_t netif) 485 static int ip_device_req_local(nic_device_id_t device_id, services_t netif) 482 486 { 483 487 ip_netif_t *ip_netif; … … 495 499 return rc; 496 500 } 497 501 498 502 ip_netif->device_id = device_id; 499 503 ip_netif->service = netif; 500 ip_netif->state = N ETIF_STOPPED;501 504 ip_netif->state = NIC_STATE_STOPPED; 505 502 506 fibril_rwlock_write_lock(&ip_globals.netifs_lock); 503 507 … … 513 517 514 518 /* Print the settings */ 515 printf("%s: Device registered (id: %d, phone: %d,ipv: %d, conf: %s)\n",516 NAME, ip_netif->device_id, ip_netif-> phone, ip_netif->ipv,519 printf("%s: Device registered (id: %d, ipv: %d, conf: %s)\n", 520 NAME, ip_netif->device_id, ip_netif->ipv, 517 521 ip_netif->dhcp ? "dhcp" : "static"); 518 522 … … 591 595 while (index >= 0) { 592 596 netif = ip_netifs_get_index(&ip_globals.netifs, index); 593 if (netif && (netif->state == N ETIF_ACTIVE)) {597 if (netif && (netif->state == NIC_STATE_ACTIVE)) { 594 598 route = ip_netif_find_route(netif, destination); 595 599 if (route) … … 635 639 636 640 /* Process all IP options */ 637 while (next < first->header_length) {641 while (next < GET_IP_HEADER_LENGTH(first)) { 638 642 option = (ip_option_t *) (((uint8_t *) first) + next); 639 643 /* Skip end or noop */ … … 656 660 if (length % 4) { 657 661 bzero(((uint8_t *) last) + length, 4 - (length % 4)); 658 last->header_length = length / 4 + 1;662 SET_IP_HEADER_LENGTH(last, (length / 4 + 1)); 659 663 } else { 660 last->header_length = length / 4;664 SET_IP_HEADER_LENGTH(last, (length / 4)); 661 665 } 662 666 … … 706 710 return rc; 707 711 708 header->version = IPV4;709 header->fragment_offset_high = 0;712 SET_IP_HEADER_VERSION(header, IPV4); 713 SET_IP_HEADER_FRAGMENT_OFFSET_HIGH(header, 0); 710 714 header->fragment_offset_low = 0; 711 715 header->header_checksum = 0; … … 735 739 memcpy(middle_header, last_header, 736 740 IP_HEADER_LENGTH(last_header)); 737 header->flags |= IPFLAG_MORE_FRAGMENTS; 741 SET_IP_HEADER_FLAGS(header, 742 (GET_IP_HEADER_FLAGS(header) | IPFLAG_MORE_FRAGMENTS)); 738 743 middle_header->total_length = 739 744 htons(packet_get_data_length(next)); 740 middle_header->fragment_offset_high =741 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ;745 SET_IP_HEADER_FRAGMENT_OFFSET_HIGH(middle_header, 746 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length)); 742 747 middle_header->fragment_offset_low = 743 748 IP_COMPUTE_FRAGMENT_OFFSET_LOW(length); … … 768 773 middle_header->total_length = 769 774 htons(packet_get_data_length(next)); 770 middle_header->fragment_offset_high =771 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ;775 SET_IP_HEADER_FRAGMENT_OFFSET_HIGH(middle_header, 776 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length)); 772 777 middle_header->fragment_offset_low = 773 778 IP_COMPUTE_FRAGMENT_OFFSET_LOW(length); … … 785 790 length += packet_get_data_length(next); 786 791 free(last_header); 787 header->flags |= IPFLAG_MORE_FRAGMENTS; 792 SET_IP_HEADER_FLAGS(header, 793 (GET_IP_HEADER_FLAGS(header) | IPFLAG_MORE_FRAGMENTS)); 788 794 } 789 795 … … 834 840 new_header->total_length = htons(IP_HEADER_LENGTH(new_header) + length); 835 841 offset = IP_FRAGMENT_OFFSET(header) + IP_HEADER_DATA_LENGTH(header); 836 new_header->fragment_offset_high =837 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(offset) ;842 SET_IP_HEADER_FRAGMENT_OFFSET_HIGH(new_header, 843 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(offset)); 838 844 new_header->fragment_offset_low = 839 845 IP_COMPUTE_FRAGMENT_OFFSET_LOW(offset); … … 865 871 return NULL; 866 872 memcpy(middle, last, IP_HEADER_LENGTH(last)); 867 middle->flags |= IPFLAG_MORE_FRAGMENTS; 873 SET_IP_HEADER_FLAGS(middle, 874 (GET_IP_HEADER_FLAGS(middle) | IPFLAG_MORE_FRAGMENTS)); 868 875 return middle; 869 876 } … … 922 929 923 930 /* Fragmentation forbidden? */ 924 if( header->flags& IPFLAG_DONT_FRAGMENT)931 if(GET_IP_HEADER_FLAGS(header) & IPFLAG_DONT_FRAGMENT) 925 932 return EPERM; 926 933 927 934 /* Create the last fragment */ 928 new_packet = packet_get_4_remote(ip_globals.net_ phone, prefix, length,935 new_packet = packet_get_4_remote(ip_globals.net_sess, prefix, length, 929 936 suffix, ((addrlen > addr_len) ? addrlen : addr_len)); 930 937 if (!new_packet) … … 958 965 959 966 /* Mark the first as fragmented */ 960 header->flags |= IPFLAG_MORE_FRAGMENTS; 967 SET_IP_HEADER_FLAGS(header, 968 (GET_IP_HEADER_FLAGS(header) | IPFLAG_MORE_FRAGMENTS)); 961 969 962 970 /* Create middle fragments */ 963 971 while (IP_TOTAL_LENGTH(header) > length) { 964 new_packet = packet_get_4_remote(ip_globals.net_ phone, prefix,972 new_packet = packet_get_4_remote(ip_globals.net_sess, prefix, 965 973 length, suffix, 966 974 ((addrlen >= addr_len) ? addrlen : addr_len)); … … 987 995 } 988 996 989 /** Check sthe packet queue lengths and fragments the packets if needed.997 /** Check the packet queue lengths and fragments the packets if needed. 990 998 * 991 999 * The ICMP_FRAG_NEEDED error notification may be sent if the packet needs to 992 1000 * be fragmented and the fragmentation is not allowed. 993 1001 * 994 * @param[in,out] packet The packet or the packet queue to be checked. 995 * @param[in] prefix The minimum prefix size. 996 * @param[in] content The maximum content size. 997 * @param[in] suffix The minimum suffix size. 998 * @param[in] addr_len The minimum address length. 999 * @param[in] error The error module service. 1000 * @return The packet or the packet queue of the allowed length. 1001 * @return NULL if there are no packets left. 1002 */ 1003 static packet_t * 1004 ip_split_packet(packet_t *packet, size_t prefix, size_t content, size_t suffix, 1005 socklen_t addr_len, services_t error) 1002 * @param[in,out] packet Packet or the packet queue to be checked. 1003 * @param[in] prefix Minimum prefix size. 1004 * @param[in] content Maximum content size. 1005 * @param[in] suffix Minimum suffix size. 1006 * @param[in] addr_len Minimum address length. 1007 * @param[in] error Error module service. 1008 * 1009 * @return The packet or the packet queue of the allowed length. 1010 * @return NULL if there are no packets left. 1011 * 1012 */ 1013 static packet_t *ip_split_packet(packet_t *packet, size_t prefix, size_t content, 1014 size_t suffix, socklen_t addr_len, services_t error) 1006 1015 { 1007 1016 size_t length; … … 1009 1018 packet_t *new_packet; 1010 1019 int result; 1011 int phone;1012 1020 async_sess_t *sess; 1021 1013 1022 next = packet; 1014 1023 /* Check all packets */ … … 1032 1041 /* Fragmentation needed? */ 1033 1042 if (result == EPERM) { 1034 phone = ip_prepare_icmp_and_get_phone( 1035 error, next, NULL); 1036 if (phone >= 0) { 1043 sess = ip_prepare_icmp_and_get_session(error, next, NULL); 1044 if (sess) { 1037 1045 /* Fragmentation necessary ICMP */ 1038 icmp_destination_unreachable_msg( phone,1046 icmp_destination_unreachable_msg(sess, 1039 1047 ICMP_FRAG_NEEDED, content, next); 1040 1048 } 1041 1049 } else { 1042 pq_release_remote(ip_globals.net_ phone,1050 pq_release_remote(ip_globals.net_sess, 1043 1051 packet_get_id(next)); 1044 1052 } … … 1054 1062 } 1055 1063 1056 /** Send sthe packet or the packet queue via the specified route.1064 /** Send the packet or the packet queue via the specified route. 1057 1065 * 1058 1066 * The ICMP_HOST_UNREACH error notification may be sent if route hardware 1059 1067 * destination address is found. 1060 1068 * 1061 * @param[in,out] packet The packet to be sent.1062 * @param[in] netif The target network interface.1063 * @param[in] route The target route.1064 * @param[in] src The source address.1065 * @param[in] dest The destination address.1066 * @param[in] error The error module service.1067 * @return EOK on success.1068 * @return Other error codes as defined for the arp_translate_req()1069 * function.1070 * @return Other error codes as defined for the ip_prepare_packet()1071 * function.1069 * @param[in,out] packet Packet to be sent. 1070 * @param[in] netif Target network interface. 1071 * @param[in] route Target route. 1072 * @param[in] src Source address. 1073 * @param[in] dest Destination address. 1074 * @param[in] error Error module service. 1075 * 1076 * @return EOK on success. 1077 * @return Other error codes as defined for arp_translate_req(). 1078 * @return Other error codes as defined for ip_prepare_packet(). 1079 * 1072 1080 */ 1073 1081 static int ip_send_route(packet_t *packet, ip_netif_t *netif, … … 1077 1085 measured_string_t *translation; 1078 1086 uint8_t *data; 1079 int phone;1087 async_sess_t *sess; 1080 1088 int rc; 1081 1089 … … 1086 1094 destination.length = sizeof(dest.s_addr); 1087 1095 1088 rc = arp_translate_req(netif->arp-> phone, netif->device_id,1096 rc = arp_translate_req(netif->arp->sess, netif->device_id, 1089 1097 SERVICE_IP, &destination, &translation, &data); 1090 1098 if (rc != EOK) { 1091 pq_release_remote(ip_globals.net_ phone,1099 pq_release_remote(ip_globals.net_sess, 1092 1100 packet_get_id(packet)); 1093 1101 return rc; … … 1099 1107 free(data); 1100 1108 } 1101 phone = ip_prepare_icmp_and_get_phone(error, packet,1109 sess = ip_prepare_icmp_and_get_session(error, packet, 1102 1110 NULL); 1103 if ( phone >= 0) {1111 if (sess) { 1104 1112 /* Unreachable ICMP if no routing */ 1105 icmp_destination_unreachable_msg( phone,1113 icmp_destination_unreachable_msg(sess, 1106 1114 ICMP_HOST_UNREACH, 0, packet); 1107 1115 } … … 1115 1123 rc = ip_prepare_packet(src, dest, packet, translation); 1116 1124 if (rc != EOK) { 1117 pq_release_remote(ip_globals.net_ phone, packet_get_id(packet));1125 pq_release_remote(ip_globals.net_sess, packet_get_id(packet)); 1118 1126 } else { 1119 1127 packet = ip_split_packet(packet, netif->packet_dimension.prefix, … … 1122 1130 netif->packet_dimension.addr_len, error); 1123 1131 if (packet) { 1124 nil_send_msg(netif-> phone, netif->device_id, packet,1132 nil_send_msg(netif->sess, netif->device_id, packet, 1125 1133 SERVICE_IP); 1126 1134 } … … 1135 1143 } 1136 1144 1137 static int ip_send_msg_local( int il_phone, device_id_t device_id,1138 packet_t *packet,services_t sender, services_t error)1145 static int ip_send_msg_local(nic_device_id_t device_id, packet_t *packet, 1146 services_t sender, services_t error) 1139 1147 { 1140 1148 int addrlen; … … 1145 1153 in_addr_t *dest; 1146 1154 in_addr_t *src; 1147 int phone;1155 async_sess_t *sess; 1148 1156 int rc; 1149 1157 … … 1190 1198 if (!netif || !route) { 1191 1199 fibril_rwlock_read_unlock(&ip_globals.netifs_lock); 1192 phone = ip_prepare_icmp_and_get_phone(error, packet, NULL);1193 if ( phone >= 0) {1200 sess = ip_prepare_icmp_and_get_session(error, packet, NULL); 1201 if (sess) { 1194 1202 /* Unreachable ICMP if no routing */ 1195 icmp_destination_unreachable_msg( phone,1203 icmp_destination_unreachable_msg(sess, 1196 1204 ICMP_NET_UNREACH, 0, packet); 1197 1205 } … … 1221 1229 if (!netif || !route) { 1222 1230 fibril_rwlock_read_unlock(&ip_globals.netifs_lock); 1223 phone = ip_prepare_icmp_and_get_phone(error, packet,1231 sess = ip_prepare_icmp_and_get_session(error, packet, 1224 1232 NULL); 1225 if ( phone >= 0) {1233 if (sess) { 1226 1234 /* Unreachable ICMP if no routing */ 1227 icmp_destination_unreachable_msg( phone,1235 icmp_destination_unreachable_msg(sess, 1228 1236 ICMP_HOST_UNREACH, 0, packet); 1229 1237 } … … 1251 1259 * @return ENOENT if device is not found. 1252 1260 */ 1253 static int ip_device_state_message(device_id_t device_id, device_state_t state) 1261 static int ip_device_state_message(nic_device_id_t device_id, 1262 nic_device_state_t state) 1254 1263 { 1255 1264 ip_netif_t *netif; … … 1265 1274 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 1266 1275 1267 printf("%s: Device %d changed state to %d\n", NAME, device_id, state); 1276 printf("%s: Device %d changed state to '%s'\n", NAME, device_id, 1277 nic_device_state_to_string(state)); 1268 1278 1269 1279 return EOK; … … 1305 1315 * tl_received_msg() function. 1306 1316 */ 1307 static int ip_deliver_local( device_id_t device_id, packet_t *packet,1317 static int ip_deliver_local(nic_device_id_t device_id, packet_t *packet, 1308 1318 ip_header_t *header, services_t error) 1309 1319 { 1310 1320 ip_proto_t *proto; 1311 int phone;1321 async_sess_t *sess; 1312 1322 services_t service; 1313 1323 tl_received_msg_t received_msg; … … 1319 1329 int rc; 1320 1330 1321 if (( header->flags& IPFLAG_MORE_FRAGMENTS) ||1331 if ((GET_IP_HEADER_FLAGS(header) & IPFLAG_MORE_FRAGMENTS) || 1322 1332 IP_FRAGMENT_OFFSET(header)) { 1323 1333 // TODO fragmented … … 1325 1335 } 1326 1336 1327 switch ( header->version) {1337 switch (GET_IP_HEADER_VERSION(header)) { 1328 1338 case IPVERSION: 1329 1339 addrlen = sizeof(src_in); … … 1362 1372 if (!proto) { 1363 1373 fibril_rwlock_read_unlock(&ip_globals.protos_lock); 1364 phone = ip_prepare_icmp_and_get_phone(error, packet, header);1365 if ( phone >= 0) {1374 sess = ip_prepare_icmp_and_get_session(error, packet, header); 1375 if (sess) { 1366 1376 /* Unreachable ICMP */ 1367 icmp_destination_unreachable_msg( phone,1377 icmp_destination_unreachable_msg(sess, 1368 1378 ICMP_PROT_UNREACH, 0, packet); 1369 1379 } … … 1377 1387 rc = received_msg(device_id, packet, service, error); 1378 1388 } else { 1379 rc = tl_received_msg(proto-> phone, device_id, packet,1389 rc = tl_received_msg(proto->sess, device_id, packet, 1380 1390 proto->service, error); 1381 1391 fibril_rwlock_read_unlock(&ip_globals.protos_lock); … … 1406 1416 * is disabled. 1407 1417 */ 1408 static int ip_process_packet( device_id_t device_id, packet_t *packet)1418 static int ip_process_packet(nic_device_id_t device_id, packet_t *packet) 1409 1419 { 1410 1420 ip_header_t *header; 1411 1421 in_addr_t dest; 1412 1422 ip_route_t *route; 1413 int phone;1423 async_sess_t *sess; 1414 1424 struct sockaddr *addr; 1415 1425 struct sockaddr_in addr_in; … … 1424 1434 if ((header->header_checksum) && 1425 1435 (IP_HEADER_CHECKSUM(header) != IP_CHECKSUM_ZERO)) { 1426 phone = ip_prepare_icmp_and_get_phone(0, packet, header);1427 if ( phone >= 0) {1436 sess = ip_prepare_icmp_and_get_session(0, packet, header); 1437 if (sess) { 1428 1438 /* Checksum error ICMP */ 1429 icmp_parameter_problem_msg( phone, ICMP_PARAM_POINTER,1439 icmp_parameter_problem_msg(sess, ICMP_PARAM_POINTER, 1430 1440 ((size_t) ((void *) &header->header_checksum)) - 1431 1441 ((size_t) ((void *) header)), packet); … … 1435 1445 1436 1446 if (header->ttl <= 1) { 1437 phone = ip_prepare_icmp_and_get_phone(0, packet, header);1438 if ( phone >= 0) {1447 sess = ip_prepare_icmp_and_get_session(0, packet, header); 1448 if (sess) { 1439 1449 /* TTL exceeded ICMP */ 1440 icmp_time_exceeded_msg( phone, ICMP_EXC_TTL, packet);1450 icmp_time_exceeded_msg(sess, ICMP_EXC_TTL, packet); 1441 1451 } 1442 1452 return EINVAL; … … 1447 1457 1448 1458 /* Set the destination address */ 1449 switch ( header->version) {1459 switch (GET_IP_HEADER_VERSION(header)) { 1450 1460 case IPVERSION: 1451 1461 addrlen = sizeof(addr_in); … … 1466 1476 route = ip_find_route(dest); 1467 1477 if (!route) { 1468 phone = ip_prepare_icmp_and_get_phone(0, packet, header);1469 if ( phone >= 0) {1478 sess = ip_prepare_icmp_and_get_session(0, packet, header); 1479 if (sess) { 1470 1480 /* Unreachable ICMP */ 1471 icmp_destination_unreachable_msg( phone,1481 icmp_destination_unreachable_msg(sess, 1472 1482 ICMP_HOST_UNREACH, 0, packet); 1473 1483 } … … 1486 1496 } 1487 1497 1488 phone = ip_prepare_icmp_and_get_phone(0, packet, header);1489 if ( phone >= 0) {1498 sess = ip_prepare_icmp_and_get_session(0, packet, header); 1499 if (sess) { 1490 1500 /* Unreachable ICMP if no routing */ 1491 icmp_destination_unreachable_msg( phone, ICMP_HOST_UNREACH, 0,1501 icmp_destination_unreachable_msg(sess, ICMP_HOST_UNREACH, 0, 1492 1502 packet); 1493 1503 } … … 1496 1506 } 1497 1507 1498 /** Return sthe device packet dimensions for sending.1499 * 1500 * @param[in] phone The service module phone.1501 * @param[ in] message The service specific message.1502 * @param[ in] device_id The device identifier.1503 * @param[out] addr_len The minimum reserved address length.1504 * @param[out] prefix The minimum reserved prefix size.1505 * @param[out] content The maximum content size.1506 * @ param[out] suffix The minimum reserved suffix size.1507 * @return EOK on success.1508 */ 1509 static int ip_packet_size_message( device_id_t device_id, size_t *addr_len,1508 /** Return the device packet dimensions for sending. 1509 * 1510 * @param[in] device_id Device identifier. 1511 * @param[out] addr_len Minimum reserved address length. 1512 * @param[out] prefix Minimum reserved prefix size. 1513 * @param[out] content Maximum content size. 1514 * @param[out] suffix Minimum reserved suffix size. 1515 * 1516 * @return EOK on success. 1517 * 1518 */ 1519 static int ip_packet_size_message(nic_device_id_t device_id, size_t *addr_len, 1510 1520 size_t *prefix, size_t *content, size_t *suffix) 1511 1521 { … … 1565 1575 * @return ENOENT if device is not found. 1566 1576 */ 1567 static int ip_mtu_changed_message( device_id_t device_id, size_t mtu)1577 static int ip_mtu_changed_message(nic_device_id_t device_id, size_t mtu) 1568 1578 { 1569 1579 ip_netif_t *netif; … … 1587 1597 * @param[in] iid Message identifier. 1588 1598 * @param[in,out] icall Message parameters. 1589 * 1590 */ 1591 static void ip_receiver(ipc_callid_t iid, ipc_call_t *icall) 1599 * @param[in] arg Local argument. 1600 * 1601 */ 1602 static void ip_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) 1592 1603 { 1593 1604 packet_t *packet; … … 1603 1614 1604 1615 case NET_IL_RECEIVED: 1605 rc = packet_translate_remote(ip_globals.net_ phone, &packet,1616 rc = packet_translate_remote(ip_globals.net_sess, &packet, 1606 1617 IPC_GET_PACKET(*icall)); 1607 1618 if (rc == EOK) { … … 1621 1632 async_answer_0(iid, (sysarg_t) rc); 1622 1633 break; 1623 1634 case NET_IL_ADDR_CHANGED: 1635 async_answer_0(iid, (sysarg_t) EOK); 1636 break; 1637 1624 1638 default: 1625 1639 async_answer_0(iid, (sysarg_t) ENOTSUP); … … 1630 1644 } 1631 1645 1632 /** Register sthe transport layer protocol.1646 /** Register the transport layer protocol. 1633 1647 * 1634 1648 * The traffic of this protocol will be supplied using either the receive 1635 1649 * function or IPC message. 1636 1650 * 1637 * @param[in] protocol The transport layer module protocol. 1638 * @param[in] service The transport layer module service. 1639 * @param[in] phone The transport layer module phone. 1640 * @param[in] received_msg The receiving function. 1641 * @return EOK on success. 1642 * @return EINVAL if the protocol parameter and/or the service 1643 * parameter is zero. 1644 * @return EINVAL if the phone parameter is not a positive number 1645 * and the tl_receive_msg is NULL. 1646 * @return ENOMEM if there is not enough memory left. 1647 */ 1648 static int 1649 ip_register(int protocol, services_t service, int phone, 1651 * @param[in] protocol Transport layer module protocol. 1652 * @param[in] service Transport layer module service. 1653 * @param[in] sess Transport layer module session. 1654 * @param[in] received_msg Receiving function. 1655 * 1656 * @return EOK on success. 1657 * @return EINVAL if the protocol parameter and/or the service 1658 * parameter is zero. 1659 * @return EINVAL if the phone parameter is not a positive number 1660 * and the tl_receive_msg is NULL. 1661 * @return ENOMEM if there is not enough memory left. 1662 * 1663 */ 1664 static int ip_register(int protocol, services_t service, async_sess_t *sess, 1650 1665 tl_received_msg_t received_msg) 1651 1666 { … … 1653 1668 int index; 1654 1669 1655 if ( !protocol || !service || ((phone < 0) && !received_msg))1670 if ((!protocol) || (!service) || ((!sess) && (!received_msg))) 1656 1671 return EINVAL; 1657 1672 1658 1673 proto = (ip_proto_t *) malloc(sizeof(ip_protos_t)); 1659 1674 if (!proto) … … 1662 1677 proto->protocol = protocol; 1663 1678 proto->service = service; 1664 proto-> phone = phone;1679 proto->sess = sess; 1665 1680 proto->received_msg = received_msg; 1666 1681 … … 1674 1689 fibril_rwlock_write_unlock(&ip_globals.protos_lock); 1675 1690 1676 printf("%s: Protocol registered (protocol: %d , phone: %d)\n",1677 NAME, proto->protocol , proto->phone);1691 printf("%s: Protocol registered (protocol: %d)\n", 1692 NAME, proto->protocol); 1678 1693 1679 1694 return EOK; 1680 1695 } 1681 1696 1682 1683 static int 1684 ip_add_route_req_local(int ip_phone, device_id_t device_id, in_addr_t address, 1697 static int ip_add_route_req_local(nic_device_id_t device_id, in_addr_t address, 1685 1698 in_addr_t netmask, in_addr_t gateway) 1686 1699 { … … 1716 1729 } 1717 1730 1718 static int 1719 ip_set_gateway_req_local(int ip_phone, device_id_t device_id,in_addr_t gateway)1731 static int ip_set_gateway_req_local(nic_device_id_t device_id, 1732 in_addr_t gateway) 1720 1733 { 1721 1734 ip_netif_t *netif; … … 1741 1754 /** Notify the IP module about the received error notification packet. 1742 1755 * 1743 * @param[in] ip_phone The IP module phone used for (semi)remote calls. 1744 * @param[in] device_id The device identifier. 1745 * @param[in] packet The received packet or the received packet queue. 1746 * @param[in] target The target internetwork module service to be 1747 * delivered to. 1748 * @param[in] error The packet error reporting service. Prefixes the 1749 * received packet. 1750 * @return EOK on success. 1751 * 1752 */ 1753 static int 1754 ip_received_error_msg_local(int ip_phone, device_id_t device_id, 1756 * @param[in] device_id Device identifier. 1757 * @param[in] packet Received packet or the received packet queue. 1758 * @param[in] target Target internetwork module service to be 1759 * delivered to. 1760 * @param[in] error Packet error reporting service. Prefixes the 1761 * received packet. 1762 * 1763 * @return EOK on success. 1764 * 1765 */ 1766 static int ip_received_error_msg_local(nic_device_id_t device_id, 1755 1767 packet_t *packet, services_t target, services_t error) 1756 1768 { … … 1797 1809 address.value = (uint8_t *) &header->destination_address; 1798 1810 address.length = sizeof(header->destination_address); 1799 arp_clear_address_req(netif->arp-> phone,1811 arp_clear_address_req(netif->arp->sess, 1800 1812 netif->device_id, SERVICE_IP, &address); 1801 1813 } … … 1811 1823 } 1812 1824 1813 static int 1814 ip_get_route_req_local(int ip_phone, ip_protocol_t protocol, 1825 static int ip_get_route_req_local(ip_protocol_t protocol, 1815 1826 const struct sockaddr *destination, socklen_t addrlen, 1816 device_id_t *device_id, void **header, size_t *headerlen)1827 nic_device_id_t *device_id, void **header, size_t *headerlen) 1817 1828 { 1818 1829 struct sockaddr_in *address_in; … … 1905 1916 size_t suffix; 1906 1917 size_t content; 1907 device_id_t device_id;1918 nic_device_id_t device_id; 1908 1919 int rc; 1909 1920 1910 1921 *answer_count = 0; 1922 1923 if (!IPC_GET_IMETHOD(*call)) 1924 return EOK; 1925 1926 async_sess_t *callback = 1927 async_callback_receive_start(EXCHANGE_SERIALIZE, call); 1928 if (callback) 1929 return ip_register(IL_GET_PROTO(*call), IL_GET_SERVICE(*call), 1930 callback, NULL); 1931 1911 1932 switch (IPC_GET_IMETHOD(*call)) { 1912 case IPC_M_PHONE_HUNGUP:1913 return EOK;1914 1915 case IPC_M_CONNECT_TO_ME:1916 return ip_register(IL_GET_PROTO(*call), IL_GET_SERVICE(*call),1917 IPC_GET_PHONE(*call), NULL);1918 1919 1933 case NET_IP_DEVICE: 1920 return ip_device_req_local( 0,IPC_GET_DEVICE(*call),1934 return ip_device_req_local(IPC_GET_DEVICE(*call), 1921 1935 IPC_GET_SERVICE(*call)); 1922 1936 1923 1937 case NET_IP_RECEIVED_ERROR: 1924 rc = packet_translate_remote(ip_globals.net_ phone, &packet,1938 rc = packet_translate_remote(ip_globals.net_sess, &packet, 1925 1939 IPC_GET_PACKET(*call)); 1926 1940 if (rc != EOK) 1927 1941 return rc; 1928 return ip_received_error_msg_local( 0,IPC_GET_DEVICE(*call),1942 return ip_received_error_msg_local(IPC_GET_DEVICE(*call), 1929 1943 packet, IPC_GET_TARGET(*call), IPC_GET_ERROR(*call)); 1930 1944 1931 1945 case NET_IP_ADD_ROUTE: 1932 return ip_add_route_req_local( 0,IPC_GET_DEVICE(*call),1946 return ip_add_route_req_local(IPC_GET_DEVICE(*call), 1933 1947 IP_GET_ADDRESS(*call), IP_GET_NETMASK(*call), 1934 1948 IP_GET_GATEWAY(*call)); 1935 1949 1936 1950 case NET_IP_SET_GATEWAY: 1937 return ip_set_gateway_req_local( 0,IPC_GET_DEVICE(*call),1951 return ip_set_gateway_req_local(IPC_GET_DEVICE(*call), 1938 1952 IP_GET_GATEWAY(*call)); 1939 1953 … … 1944 1958 return rc; 1945 1959 1946 rc = ip_get_route_req_local( 0,IP_GET_PROTOCOL(*call), addr,1960 rc = ip_get_route_req_local(IP_GET_PROTOCOL(*call), addr, 1947 1961 (socklen_t) addrlen, &device_id, &header, &headerlen); 1948 1962 if (rc != EOK) … … 1975 1989 1976 1990 case NET_IP_SEND: 1977 rc = packet_translate_remote(ip_globals.net_ phone, &packet,1991 rc = packet_translate_remote(ip_globals.net_sess, &packet, 1978 1992 IPC_GET_PACKET(*call)); 1979 1993 if (rc != EOK) 1980 1994 return rc; 1981 1995 1982 return ip_send_msg_local( 0,IPC_GET_DEVICE(*call), packet, 0,1996 return ip_send_msg_local(IPC_GET_DEVICE(*call), packet, 0, 1983 1997 IPC_GET_ERROR(*call)); 1984 1998 }
Note:
See TracChangeset
for help on using the changeset viewer.