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