Changeset fb04cba8 in mainline
- Timestamp:
- 2010-11-14T14:07:05Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9e2e715
- Parents:
- c9ebbe71
- Location:
- uspace/srv/net
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/arp/arp.c
rc9ebbe71 rfb04cba8 125 125 } 126 126 127 static int 128 arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, 129 measured_string_ref address) 127 static int arp_clear_address_req(int arp_phone, device_id_t device_id, 128 services_t protocol, measured_string_ref address) 130 129 { 131 130 arp_device_ref device; … … 175 174 * @returns ENOMEM if there is not enough memory left. 176 175 */ 177 static int 178 arp_proto_create(arp_proto_ref *proto, services_t service, 176 static int arp_proto_create(arp_proto_ref *proto, services_t service, 179 177 measured_string_ref address) 180 178 { … … 214 212 * measured_strings_return() function. 215 213 */ 216 static int 217 arp_device_message(device_id_t device_id, services_t service, 214 static int arp_device_message(device_id_t device_id, services_t service, 218 215 services_t protocol, measured_string_ref address) 219 216 { … … 225 222 226 223 fibril_rwlock_write_lock(&arp_globals.lock); 227 // an existing device? 224 225 /* An existing device? */ 228 226 device = arp_cache_find(&arp_globals.cache, device_id); 227 229 228 if (device) { 230 229 if (device->service != service) { … … 260 259 return ENOENT; 261 260 262 / / create a new device261 /* Create a new device */ 263 262 device = (arp_device_ref) malloc(sizeof(arp_device_t)); 264 263 if (!device) { … … 289 288 device->service = service; 290 289 291 / / bind the new one290 /* Bind the new one */ 292 291 device->phone = nil_bind_service(device->service, 293 292 (ipcarg_t) device->device_id, SERVICE_ARP, … … 300 299 } 301 300 302 / / get packet dimensions301 /* Get packet dimensions */ 303 302 rc = nil_packet_size_req(device->phone, device_id, 304 303 &device->packet_dimension); … … 310 309 } 311 310 312 / / get hardware address311 /* Get hardware address */ 313 312 rc = nil_get_addr_req(device->phone, device_id, &device->addr, 314 313 &device->addr_data); … … 320 319 } 321 320 322 / / get broadcast address321 /* Get broadcast address */ 323 322 rc = nil_get_broadcast_addr_req(device->phone, device_id, 324 323 &device->broadcast_addr, &device->broadcast_data); … … 455 454 hw_source = arp_addr_find(&proto->addresses, (char *) src_proto, 456 455 CONVERT_SIZE(uint8_t, char, header->protocol_length)); 457 / / exists?456 /* Exists? */ 458 457 if (hw_source) { 459 458 if (hw_source->length != CONVERT_SIZE(uint8_t, char, … … 463 462 memcpy(hw_source->value, src_hw, hw_source->length); 464 463 } 465 / / is my protocol address?464 /* Is my protocol address? */ 466 465 if (proto->addr->length != CONVERT_SIZE(uint8_t, char, 467 466 header->protocol_length)) { … … 470 469 if (!str_lcmp(proto->addr->value, (char *) des_proto, 471 470 proto->addr->length)) { 472 / / not already upadted?471 /* Not already updated? */ 473 472 if (!hw_source) { 474 473 hw_source = measured_string_create_bulk((char *) src_hw, … … 550 549 return addr; 551 550 552 / / ARP packet content size = header + (address + translation) * 2551 /* ARP packet content size = header + (address + translation) * 2 */ 553 552 length = 8 + 2 * (CONVERT_SIZE(char, uint8_t, proto->addr->length) + 554 553 CONVERT_SIZE(char, uint8_t, device->addr->length)); … … 674 673 675 674 case NET_IL_DEVICE_STATE: 676 / / do nothing - keep the cache675 /* Do nothing - keep the cache */ 677 676 return EOK; 678 677 -
uspace/srv/net/il/arp/arp_module.c
rc9ebbe71 rfb04cba8 57 57 extern arp_globals_t arp_globals; 58 58 59 int 60 il_module_message_standalone(ipc_callid_t callid, ipc_call_t *call, 59 int il_module_message_standalone(ipc_callid_t callid, ipc_call_t *call, 61 60 ipc_call_t *answer, int *answer_count) 62 61 { -
uspace/srv/net/net/net.c
rc9ebbe71 rfb04cba8 275 275 measured_strings_initialize(&net_globals.configuration); 276 276 277 / / TODO: dynamic configuration277 /* TODO: dynamic configuration */ 278 278 rc = read_configuration(); 279 279 if (rc != EOK) … … 347 347 * 348 348 * The network interface configuration is searched first. 349 &349 * 350 350 * @param[in] netif_conf The network interface configuration setting. 351 351 * @param[out] configuration The found configured values. -
uspace/srv/net/netif/lo/lo.c
rc9ebbe71 rfb04cba8 64 64 netif_globals_t netif_globals; 65 65 66 int 67 netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 66 int netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 68 67 ipc_call_t *answer, int *answer_count) 69 68 { … … 75 74 if (!address) 76 75 return EBADMEM; 76 77 77 address->value = str_dup(DEFAULT_ADDR); 78 78 address->length = DEFAULT_ADDR_LEN; 79 79 80 return EOK; 80 81 } … … 87 88 if (!stats) 88 89 return EBADMEM; 90 89 91 rc = find_device(device_id, &device); 90 92 if (rc != EOK) 91 93 return rc; 94 92 95 memcpy(stats, (device_stats_ref) device->specific, 93 96 sizeof(device_stats_t)); 97 94 98 return EOK; 95 99 } … … 134 138 if (!*device) 135 139 return ENOMEM; 140 136 141 (*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t)); 137 142 if (!(*device)->specific) { … … 139 144 return ENOMEM; 140 145 } 146 141 147 null_device_stats((device_stats_ref) (*device)->specific); 142 148 (*device)->device_id = device_id; … … 145 151 index = netif_device_map_add(&netif_globals.device_map, 146 152 (*device)->device_id, *device); 153 147 154 if (index < 0) { 148 155 free(*device); … … 167 174 int rc; 168 175 169 / / create a new device176 /* Create a new device */ 170 177 rc = create(device_id, &device); 171 178 if (rc != EOK) 172 179 return rc; 173 // print the settings 180 181 /* Print the settings */ 174 182 printf("%s: Device created (id: %d)\n", NAME, device->device_id); 183 175 184 return EOK; 176 185 } … … 187 196 if (rc != EOK) 188 197 return EOK; 198 189 199 if (device->state != NETIF_ACTIVE) { 190 200 netif_pq_release(packet_get_id(packet)); 191 201 return EFORWARD; 192 202 } 203 193 204 next = packet; 194 205 do { … … 200 211 next = pq_next(next); 201 212 } while(next); 213 202 214 phone = device->nil_phone; 203 215 fibril_rwlock_write_unlock(&netif_globals.lock); -
uspace/srv/net/nil/eth/eth.c
rc9ebbe71 rfb04cba8 204 204 fibril_rwlock_write_lock(ð_globals.protos_lock); 205 205 eth_globals.net_phone = net_phone; 206 206 207 eth_globals.broadcast_addr = 207 208 measured_string_create_bulk("\xFF\xFF\xFF\xFF\xFF\xFF", … … 211 212 goto out; 212 213 } 214 213 215 rc = eth_devices_initialize(ð_globals.devices); 214 216 if (rc != EOK) { … … 216 218 goto out; 217 219 } 220 218 221 rc = eth_protos_initialize(ð_globals.protos); 219 222 if (rc != EOK) { … … 280 283 * netif_get_addr_req() function. 281 284 */ 282 static int 283 eth_device_message(device_id_t device_id, services_t service,size_t mtu)285 static int eth_device_message(device_id_t device_id, services_t service, 286 size_t mtu) 284 287 { 285 288 eth_device_ref device; … … 302 305 303 306 fibril_rwlock_write_lock(ð_globals.devices_lock); 304 / / an existing device?307 /* An existing device? */ 305 308 device = eth_devices_find(ð_globals.devices, device_id); 306 309 if (device) { … … 311 314 } 312 315 313 / / update mtu316 /* Update mtu */ 314 317 if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))) 315 318 device->mtu = mtu; … … 321 324 fibril_rwlock_write_unlock(ð_globals.devices_lock); 322 325 323 / / notify all upper layer modules326 /* Notify all upper layer modules */ 324 327 fibril_rwlock_read_lock(ð_globals.protos_lock); 325 328 for (index = 0; index < eth_protos_count(ð_globals.protos); … … 333 336 } 334 337 } 338 335 339 fibril_rwlock_read_unlock(ð_globals.protos_lock); 336 340 return EOK; 337 341 } 338 342 339 / / create a new device343 /* Create a new device */ 340 344 device = (eth_device_ref) malloc(sizeof(eth_device_t)); 341 345 if (!device) … … 358 362 return rc; 359 363 } 364 360 365 if (configuration) { 361 366 if (!str_lcmp(configuration[0].value, "DIX", … … 378 383 } 379 384 380 / / bind the device driver385 /* Bind the device driver */ 381 386 device->phone = netif_bind_service(device->service, device->device_id, 382 387 SERVICE_ETHERNET, eth_receiver); … … 387 392 } 388 393 389 / / get hardware address394 /* Get hardware address */ 390 395 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr, 391 396 &device->addr_data); … … 396 401 } 397 402 398 / / add to the cache403 /* Add to the cache */ 399 404 index = eth_devices_add(ð_globals.devices, device->device_id, 400 405 device); … … 453 458 454 459 if (type >= ETH_MIN_PROTO) { 455 / / DIX Ethernet460 /* DIX Ethernet */ 456 461 prefix = sizeof(eth_header_t); 457 462 suffix = 0; … … 459 464 length -= sizeof(eth_fcs_t); 460 465 } else if(type <= ETH_MAX_CONTENT) { 461 / / translate "LSAP" values466 /* Translate "LSAP" values */ 462 467 if ((header->lsap.dsap == ETH_LSAP_GLSAP) && 463 468 (header->lsap.ssap == ETH_LSAP_GLSAP)) { 464 // raw packet 465 // discard 469 /* Raw packet -- discard */ 466 470 return NULL; 467 471 } else if((header->lsap.dsap == ETH_LSAP_SNAP) && 468 472 (header->lsap.ssap == ETH_LSAP_SNAP)) { 469 // IEEE 802.3 + 802.2 + LSAP + SNAP 470 // organization code not supported 473 /* 474 * IEEE 802.3 + 802.2 + LSAP + SNAP 475 * organization code not supported 476 */ 471 477 type = ntohs(header->snap.ethertype); 472 478 prefix = sizeof(eth_header_t) + … … 474 480 sizeof(eth_header_snap_t); 475 481 } else { 476 / / IEEE 802.3 + 802.2 LSAP482 /* IEEE 802.3 + 802.2 LSAP */ 477 483 type = lsap_map(header->lsap.dsap); 478 484 prefix = sizeof(eth_header_t) + 479 485 sizeof(eth_header_lsap_t); 480 486 } 487 481 488 suffix = (type < ETH_MIN_CONTENT) ? ETH_MIN_CONTENT - type : 0U; 482 489 fcs = (eth_fcs_ref) data + prefix + type + suffix; … … 484 491 length = prefix + type + suffix; 485 492 } else { 486 / / invalid length/type, should not occurr493 /* Invalid length/type, should not occur */ 487 494 return NULL; 488 495 } … … 506 513 } 507 514 508 int 509 nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, 510 services_t target) 515 int nil_received_msg_local(int nil_phone, device_id_t device_id, 516 packet_t packet, services_t target) 511 517 { 512 518 eth_proto_ref proto; … … 521 527 return ENOENT; 522 528 } 529 523 530 flags = device->flags; 524 531 fibril_rwlock_read_unlock(ð_globals.devices_lock); … … 538 545 packet = next; 539 546 } while(packet); 547 540 548 fibril_rwlock_read_unlock(ð_globals.protos_lock); 541 542 549 return EOK; 543 550 } … … 554 561 * @returns ENOENT if there is no such device. 555 562 */ 556 static int 557 eth_packet_space_message(device_id_t device_id, size_t *addr_len, 563 static int eth_packet_space_message(device_id_t device_id, size_t *addr_len, 558 564 size_t *prefix, size_t *content, size_t *suffix) 559 565 { … … 569 575 return ENOENT; 570 576 } 577 571 578 *content = device->mtu; 572 579 fibril_rwlock_read_unlock(ð_globals.devices_lock); … … 575 582 *prefix = ETH_PREFIX; 576 583 *suffix = ETH_MIN_CONTENT + ETH_SUFFIX; 584 577 585 return EOK; 578 586 } … … 587 595 * @returns ENOENT if there no such device. 588 596 */ 589 static int 590 eth_addr_message(device_id_t device_id, eth_addr_type_t type, 597 static int eth_addr_message(device_id_t device_id, eth_addr_type_t type, 591 598 measured_string_ref *address) 592 599 { … … 644 651 return ENOMEM; 645 652 } 653 646 654 proto->service = service; 647 655 proto->protocol = protocol; 648 656 proto->phone = phone; 657 649 658 index = eth_protos_add(ð_globals.protos, protocol, proto); 650 659 if (index < 0) { … … 705 714 if (!padding) 706 715 return ENOMEM; 716 707 717 bzero(padding, ETH_MIN_TAGGED_CONTENT(flags) - length); 708 718 } … … 782 792 * @returns EINVAL if the service parameter is not known. 783 793 */ 784 static int 785 eth_send_message(device_id_t device_id, packet_t packet,services_t sender)794 static int eth_send_message(device_id_t device_id, packet_t packet, 795 services_t sender) 786 796 { 787 797 eth_device_ref device; … … 804 814 } 805 815 806 / / process packet queue816 /* Process packet queue */ 807 817 next = packet; 808 818 do { … … 810 820 (uint8_t *) device->addr->value, ethertype, device->mtu); 811 821 if (rc != EOK) { 812 / / release invalid packet822 /* Release invalid packet */ 813 823 tmp = pq_detach(next); 814 824 if (next == packet) … … 822 832 } while(next); 823 833 824 / / send packet queue834 /* Send packet queue */ 825 835 if (packet) { 826 836 netif_send_msg(device->phone, device_id, packet, 827 837 SERVICE_ETHERNET); 828 838 } 839 829 840 fibril_rwlock_read_unlock(ð_globals.devices_lock); 830 831 841 return EOK; 832 842 } 833 843 834 int 835 nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call, 836 ipc_call_t *answer, int *answer_count) 844 int nil_message_standalone(const char *name, ipc_callid_t callid, 845 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 837 846 { 838 847 measured_string_ref address; … … 894 903 * @param[in] iid The initial message identifier. 895 904 * @param[in] icall The initial message call structure. 896 *897 905 */ 898 906 static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall) -
uspace/srv/net/nil/eth/eth_module.c
rc9ebbe71 rfb04cba8 77 77 } 78 78 79 int 80 nil_module_message_standalone(const char *name, ipc_callid_t callid, 79 int nil_module_message_standalone(const char *name, ipc_callid_t callid, 81 80 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 82 81 { -
uspace/srv/net/nil/nildummy/nildummy.c
rc9ebbe71 rfb04cba8 150 150 * netif_get_addr_req() function. 151 151 */ 152 static int 153 nildummy_device_message(device_id_t device_id, services_t service,size_t mtu)152 static int nildummy_device_message(device_id_t device_id, services_t service, 153 size_t mtu) 154 154 { 155 155 nildummy_device_ref device; … … 159 159 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); 160 160 161 / / an existing device?161 /* An existing device? */ 162 162 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 163 163 if (device) { … … 169 169 } 170 170 171 / / update mtu171 /* Update MTU */ 172 172 if (mtu > 0) 173 173 device->mtu = mtu; … … 179 179 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 180 180 181 / / notify the upper layer module181 /* Notify the upper layer module */ 182 182 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 183 183 if (nildummy_globals.proto.phone) { … … 191 191 } 192 192 193 / / create a new device193 /* Create a new device */ 194 194 device = (nildummy_device_ref) malloc(sizeof(nildummy_device_t)); 195 195 if (!device) … … 203 203 device->mtu = NET_DEFAULT_MTU; 204 204 205 / / bind the device driver205 /* Bind the device driver */ 206 206 device->phone = netif_bind_service(device->service, device->device_id, 207 207 SERVICE_ETHERNET, nildummy_receiver); … … 212 212 } 213 213 214 / / get hardware address214 /* Get hardware address */ 215 215 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr, 216 216 &device->addr_data); … … 221 221 } 222 222 223 / / add to the cache223 /* Add to the cache */ 224 224 index = nildummy_devices_add(&nildummy_globals.devices, 225 225 device->device_id, device); … … 247 247 * 248 248 */ 249 static int 250 nildummy_addr_message(device_id_t device_id,measured_string_ref *address)249 static int nildummy_addr_message(device_id_t device_id, 250 measured_string_ref *address) 251 251 { 252 252 nildummy_device_ref device; … … 279 279 * 280 280 */ 281 static int 282 nildummy_packet_space_message(device_id_t device_id, size_t *addr_len, 281 static int nildummy_packet_space_message(device_id_t device_id, size_t *addr_len, 283 282 size_t *prefix, size_t *content, size_t *suffix) 284 283 { … … 294 293 return ENOENT; 295 294 } 295 296 296 *content = device->mtu; 297 297 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); … … 303 303 } 304 304 305 int 306 nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, 307 services_t target) 305 int nil_received_msg_local(int nil_phone, device_id_t device_id, 306 packet_t packet, services_t target) 308 307 { 309 308 packet_t next; … … 355 354 * @return EINVAL if the service parameter is not known. 356 355 */ 357 static int 358 nildummy_send_message(device_id_t device_id, packet_t packet,services_t sender)356 static int nildummy_send_message(device_id_t device_id, packet_t packet, 357 services_t sender) 359 358 { 360 359 nildummy_device_ref device; … … 366 365 return ENOENT; 367 366 } 368 // send packet queue 367 368 /* Send packet queue */ 369 369 if (packet) 370 370 netif_send_msg(device->phone, device_id, packet, … … 374 374 } 375 375 376 int 377 nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call, 378 ipc_call_t *answer, int *answer_count) 376 int nil_message_standalone(const char *name, ipc_callid_t callid, 377 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 379 378 { 380 379 measured_string_ref address; -
uspace/srv/net/nil/nildummy/nildummy_module.c
rc9ebbe71 rfb04cba8 78 78 } 79 79 80 int 81 nil_module_message_standalone(const char *name, ipc_callid_t callid, 80 int nil_module_message_standalone(const char *name, ipc_callid_t callid, 82 81 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 83 82 { -
uspace/srv/net/tl/icmp/icmp.c
rc9ebbe71 rfb04cba8 155 155 * @returns EPERM if the error message is not allowed. 156 156 */ 157 static int 158 icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet, 157 static int icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet, 159 158 icmp_header_ref header, services_t error, ip_ttl_t ttl, ip_tos_t tos, 160 159 int dont_fragment) … … 162 161 int rc; 163 162 164 / / do not send an error if disabled163 /* Do not send an error if disabled */ 165 164 if (error && !icmp_globals.error_reporting) 166 165 return icmp_release_and_return(packet, EPERM); … … 204 203 return NULL; 205 204 206 / / truncate if longer than 64 bits (without the IP header)205 /* Truncate if longer than 64 bits (without the IP header) */ 207 206 if ((total_length > header_length + ICMP_KEEP_LENGTH) && 208 207 (packet_trim(packet, 0, … … 244 243 * @returns EPARTY if there was an internal error. 245 244 */ 246 static int 247 icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size, 245 static int icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size, 248 246 mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, 249 247 const struct sockaddr * addr, socklen_t addrlen) … … 262 260 263 261 length = (size_t) addrlen; 264 / / TODO do not ask all the time262 /* TODO do not ask all the time */ 265 263 rc = ip_packet_size_req(icmp_globals.ip_phone, -1, 266 264 &icmp_globals.packet_dimension); … … 275 273 return ENOMEM; 276 274 277 // prepare the requesting packet 278 // set the destination address 275 /* Prepare the requesting packet, set the destination address. */ 279 276 rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length); 280 277 if (rc != EOK) 281 278 return icmp_release_and_return(packet, rc); 282 279 283 / / allocate space in the packet280 /* Allocate space in the packet */ 284 281 data = (uint8_t *) packet_suffix(packet, size); 285 282 if (!data) 286 283 return icmp_release_and_return(packet, ENOMEM); 287 284 288 / / fill the data285 /* Fill the data */ 289 286 length = 0; 290 287 while (size > length + sizeof(ICMP_ECHO_TEXT)) { … … 294 291 memcpy(data + length, ICMP_ECHO_TEXT, size - length); 295 292 296 / / prefix the header293 /* Prefix the header */ 297 294 header = PACKET_PREFIX(packet, icmp_header_t); 298 295 if (!header) … … 303 300 header->un.echo.sequence_number = sequence; 304 301 305 / / prepare the reply structure302 /* Prepare the reply structure */ 306 303 reply = malloc(sizeof(*reply)); 307 304 if (!reply) … … 319 316 } 320 317 321 / / unlock the globals so that we can wait for the reply318 /* Unlock the globals so that we can wait for the reply */ 322 319 fibril_rwlock_write_unlock(&icmp_globals.lock); 323 320 324 / / send the request321 /* Send the request */ 325 322 icmp_send_packet(ICMP_ECHO, 0, packet, header, 0, ttl, tos, 326 323 dont_fragment); 327 324 328 // wait for the reply 329 // timeout in microseconds 325 /* Wait for the reply. Timeout in microseconds. */ 330 326 rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex, 331 327 timeout * 1000); … … 333 329 rc = reply->result; 334 330 335 / / drop the reply mutex before locking the globals again331 /* Drop the reply mutex before locking the globals again */ 336 332 fibril_mutex_unlock(&reply->mutex); 337 333 fibril_rwlock_write_lock(&icmp_globals.lock); 338 334 339 / / destroy the reply structure335 /* Destroy the reply structure */ 340 336 icmp_replies_exclude_index(&icmp_globals.replies, index); 341 337 … … 343 339 } 344 340 345 static int 346 icmp_destination_unreachable_msg_local(int icmp_phone, icmp_code_t code, 347 icmp_param_t mtu, packet_t packet) 341 static int icmp_destination_unreachable_msg_local(int icmp_phone, 342 icmp_code_t code, icmp_param_t mtu, packet_t packet) 348 343 { 349 344 icmp_header_ref header; … … 372 367 } 373 368 374 static int 375 icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code,packet_t packet)369 static int icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code, 370 packet_t packet) 376 371 { 377 372 icmp_header_ref header; … … 385 380 } 386 381 387 static int 388 icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code, 382 static int icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code, 389 383 icmp_param_t pointer, packet_t packet) 390 384 { … … 449 443 icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING; 450 444 451 / / get configuration445 /* Get configuration */ 452 446 configuration = &names[0]; 453 447 rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count, … … 485 479 * @param[in] code The received reply message code. 486 480 */ 487 static void 488 icmp_process_echo_reply(packet_t packet, icmp_header_ref header, 481 static void icmp_process_echo_reply(packet_t packet, icmp_header_ref header, 489 482 icmp_type_t type, icmp_code_t code) 490 483 { … … 492 485 icmp_reply_ref reply; 493 486 494 / / compute the reply key487 /* Compute the reply key */ 495 488 reply_key = ICMP_GET_REPLY_KEY(header->un.echo.identifier, 496 489 header->un.echo.sequence_number); 497 490 pq_release_remote(icmp_globals.net_phone, packet_get_id(packet)); 498 491 492 /* Find the pending reply */ 499 493 fibril_rwlock_write_lock(&icmp_globals.lock); 500 // find the pending reply501 494 reply = icmp_replies_find(&icmp_globals.replies, reply_key); 502 495 if (reply) { … … 541 534 break; 542 535 case SERVICE_ICMP: 543 / / process error536 /* Process error */ 544 537 result = icmp_client_process_packet(packet, &type, &code, NULL, 545 538 NULL); … … 547 540 return result; 548 541 length = (size_t) result; 549 / / remove the error header542 /* Remove the error header */ 550 543 rc = packet_trim(packet, length, 0); 551 544 if (rc != EOK) … … 556 549 } 557 550 558 / / get rid of the ip header551 /* Get rid of the IP header */ 559 552 length = ip_client_header_length(packet); 560 553 rc = packet_trim(packet, length, 0); … … 573 566 return EINVAL; 574 567 575 / / get icmp header568 /* Get ICMP header */ 576 569 header = (icmp_header_ref) data; 577 570 578 571 if (header->checksum) { 579 572 while (ICMP_CHECKSUM(header, length) != IP_CHECKSUM_ZERO) { 580 // set the original message type on error notification 581 // type swap observed in Qemu 573 /* 574 * Set the original message type on error notification. 575 * Type swap observed in Qemu. 576 */ 582 577 if (error) { 583 578 switch (header->type) { … … 606 601 } 607 602 608 / / do not send a reply if disabled603 /* Do not send a reply if disabled */ 609 604 if (icmp_globals.echo_replying) { 610 605 addrlen = packet_get_addr(packet, &src, NULL); 611 606 612 // set both addresses to the source one (avoids the 613 // source address deletion before setting the 614 // destination one) 607 /* 608 * Set both addresses to the source one (avoids the 609 * source address deletion before setting the 610 * destination one). 611 */ 615 612 if ((addrlen > 0) && (packet_set_addr(packet, src, src, 616 613 (size_t) addrlen) == EOK)) { 617 / / send the reply614 /* Send the reply */ 618 615 icmp_send_packet(ICMP_ECHOREPLY, 0, packet, 619 616 header, 0, 0, 0, 0); … … 661 658 * icmp_process_packet() function. 662 659 */ 663 static int 664 icmp_received_msg_local(device_id_t device_id, packet_t packet, 660 static int icmp_received_msg_local(device_id_t device_id, packet_t packet, 665 661 services_t receiver, services_t error) 666 662 { … … 746 742 return EBADMEM; 747 743 748 / / from the last used one744 /* From the last used one */ 749 745 index = icmp_globals.last_used_id; 750 746 do { 751 747 index++; 752 / / til the range end748 /* til the range end */ 753 749 if (index >= ICMP_FREE_IDS_END) { 754 / / start from the range beginning750 /* start from the range beginning */ 755 751 index = ICMP_FREE_IDS_START - 1; 756 752 do { 757 753 index++; 758 / / til the last used one754 /* til the last used one */ 759 755 if (index >= icmp_globals.last_used_id) { 760 / / none found756 /* none found */ 761 757 return ENOTCONN; 762 758 } … … 764 760 index) != NULL); 765 761 766 / / found, break immediately762 /* Found, break immediately */ 767 763 break; 768 764 } … … 808 804 return ENOMEM; 809 805 810 / / assign a new identifier806 /* Assign a new identifier */ 811 807 fibril_rwlock_write_lock(&icmp_globals.lock); 812 808 rc = icmp_bind_free_id(echo_data); … … 818 814 819 815 while (keep_on_going) { 820 / / answer the call816 /* Answer the call */ 821 817 answer_call(callid, rc, &answer, answer_count); 822 818 823 / / refresh data819 /* Refresh data */ 824 820 refresh_answer(&answer, &answer_count); 825 821 826 / / get the next call822 /* Get the next call */ 827 823 callid = async_get_call(&call); 828 824 829 / / process the call825 /* Process the call */ 830 826 switch (IPC_GET_METHOD(call)) { 831 827 case IPC_M_PHONE_HUNGUP: … … 876 872 } 877 873 878 / / release the identifier874 /* Release the identifier */ 879 875 fibril_rwlock_write_lock(&icmp_globals.lock); 880 876 icmp_echo_data_exclude(&icmp_globals.echo_data, echo_data->identifier); … … 897 893 * @see IS_NET_ICMP_MESSAGE() 898 894 */ 899 int 900 icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 895 int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 901 896 ipc_call_t *answer, int *answer_count) 902 897 { -
uspace/srv/net/tl/icmp/icmp_module.c
rc9ebbe71 rfb04cba8 85 85 } 86 86 87 int 88 tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call, 87 int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call, 89 88 ipc_call_t *answer, int *answer_count) 90 89 { -
uspace/srv/net/tl/tcp/tcp.c
rc9ebbe71 rfb04cba8 44 44 #include <fibril_synch.h> 45 45 #include <malloc.h> 46 / /TODO remove stdio46 /* TODO remove stdio */ 47 47 #include <stdio.h> 48 48 #include <errno.h> … … 267 267 } 268 268 269 int 270 tcp_received_msg(device_id_t device_id, packet_t packet, services_t receiver, 271 services_t error) 269 int tcp_received_msg(device_id_t device_id, packet_t packet, 270 services_t receiver, services_t error) 272 271 { 273 272 int rc; … … 309 308 break; 310 309 case SERVICE_ICMP: 311 / / process error310 /* Process error */ 312 311 result = icmp_client_process_packet(packet, &type, &code, NULL, 313 312 NULL); … … 324 323 } 325 324 326 / / TODO process received ipopts?325 /* TODO process received ipopts? */ 327 326 result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL); 328 327 if (result < 0) … … 338 337 return tcp_release_and_return(packet, NO_DATA); 339 338 340 / / trim all but TCP header339 /* Trim all but TCP header */ 341 340 rc = packet_trim(packet, offset, 0); 342 341 if (rc != EOK) 343 342 return tcp_release_and_return(packet, rc); 344 343 345 / / get tcp header344 /* Get tcp header */ 346 345 header = (tcp_header_ref) packet_get_data(packet); 347 346 if (!header) … … 361 360 return tcp_release_and_return(packet, rc); 362 361 363 / / find the destination socket362 /* Find the destination socket */ 364 363 socket = socket_port_find(&tcp_globals.sockets, 365 364 ntohs(header->destination_port), (const char *) src, addrlen); 366 365 if (!socket) { 367 / / find the listening destination socket366 /* Find the listening destination socket */ 368 367 socket = socket_port_find(&tcp_globals.sockets, 369 368 ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING, 370 369 0); 371 370 } 371 372 372 if (!socket) { 373 373 if (tl_prepare_icmp_packet(tcp_globals.net_phone, … … 383 383 assert(socket_data); 384 384 385 / / some data received, clear the timeout counter385 /* Some data received, clear the timeout counter */ 386 386 socket_data->timeout_count = 0; 387 387 388 / / count the received packet fragments388 /* Count the received packet fragments */ 389 389 next_packet = packet; 390 390 fragments = 0; … … 399 399 total_length += length; 400 400 401 / / add partial checksum if set401 /* Add partial checksum if set */ 402 402 if (!error) { 403 403 checksum = compute_checksum(checksum, … … 447 447 tcp_globals.icmp_phone, packet, error); 448 448 if (rc == EOK) { 449 / / checksum error ICMP449 /* Checksum error ICMP */ 450 450 icmp_parameter_problem_msg(tcp_globals.icmp_phone, 451 451 ICMP_PARAM_POINTER, … … 460 460 fibril_rwlock_read_unlock(&tcp_globals.lock); 461 461 462 / / TODO error reporting/handling462 /* TODO error reporting/handling */ 463 463 switch (socket_data->state) { 464 464 case TCP_SOCKET_LISTEN: … … 474 474 break; 475 475 case TCP_SOCKET_FIN_WAIT_1: 476 / / ack changing the state to FIN_WAIT_2 gets processed later476 /* ack changing the state to FIN_WAIT_2 gets processed later */ 477 477 case TCP_SOCKET_FIN_WAIT_2: 478 / / fin changing state to LAST_ACK gets processed later478 /* fin changing state to LAST_ACK gets processed later */ 479 479 case TCP_SOCKET_LAST_ACK: 480 / / ack releasing the socket get processed later480 /* ack releasing the socket get processed later */ 481 481 case TCP_SOCKET_CLOSING: 482 / / ack releasing the socket gets processed later482 /* ack releasing the socket gets processed later */ 483 483 case TCP_SOCKET_ESTABLISHED: 484 484 rc = tcp_process_established(socket, socket_data, header, … … 497 497 } 498 498 499 int 500 tcp_process_established(socket_core_ref socket, tcp_socket_data_ref socket_data,501 tcp_header_ref header, packet_t packet, int fragments,size_t total_length)499 int tcp_process_established(socket_core_ref socket, tcp_socket_data_ref 500 socket_data, tcp_header_ref header, packet_t packet, int fragments, 501 size_t total_length) 502 502 { 503 503 packet_t next_packet; … … 523 523 socket_data->fin_incoming = new_sequence_number; 524 524 525 / / trim begining if containing expected data525 /* Trim begining if containing expected data */ 526 526 if (IS_IN_INTERVAL_OVERFLOW(new_sequence_number, 527 527 socket_data->next_incoming, new_sequence_number + total_length)) { 528 528 529 / / get the acknowledged offset529 /* Get the acknowledged offset */ 530 530 if (socket_data->next_incoming < new_sequence_number) { 531 531 offset = new_sequence_number - … … 539 539 total_length -= offset; 540 540 length = packet_get_data_length(packet); 541 // trim the acknowledged data 541 542 /* Trim the acknowledged data */ 542 543 while (length <= offset) { 543 / / release the acknowledged packets544 /* Release the acknowledged packets */ 544 545 next_packet = pq_next(packet); 545 546 pq_release_remote(tcp_globals.net_phone, … … 559 560 } 560 561 561 / / release if overflowing the window562 /* Release if overflowing the window */ 562 563 /* 563 564 if (IS_IN_INTERVAL_OVERFLOW(socket_data->next_incoming + … … 609 610 } 610 611 */ 611 / / the expected one arrived?612 /* The expected one arrived? */ 612 613 if (new_sequence_number == socket_data->next_incoming) { 613 614 printf("expected\n"); 614 / / process acknowledgement615 /* Process acknowledgement */ 615 616 tcp_process_acknowledgement(socket, socket_data, header); 616 617 617 / / remove the header618 /* Remove the header */ 618 619 total_length -= TCP_HEADER_LENGTH(header); 619 620 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); … … 635 636 rc = pq_get_order(socket_data->incoming, &order, NULL); 636 637 if (rc != EOK) { 637 / / remove the corrupted packet638 /* Remove the corrupted packet */ 638 639 next_packet = pq_detach(packet); 639 640 if (packet == socket_data->incoming) … … 648 649 if (IS_IN_INTERVAL_OVERFLOW(sequence_number, 649 650 old_incoming, socket_data->next_incoming)) { 650 / / move to the next651 /* Move to the next */ 651 652 packet = pq_next(packet); 652 / / coninual data?653 /* Coninual data? */ 653 654 } else if (IS_IN_INTERVAL_OVERFLOW(old_incoming, 654 655 sequence_number, socket_data->next_incoming)) { 655 / / detach the packet656 /* Detach the packet */ 656 657 next_packet = pq_detach(packet); 657 658 if (packet == socket_data->incoming) 658 659 socket_data->incoming = next_packet; 659 / / get data length660 /* Get data length */ 660 661 length = packet_get_data_length(packet); 661 662 new_sequence_number = sequence_number + length; 662 663 if (length <= 0) { 663 / / remove the empty packet664 /* Remove the empty packet */ 664 665 pq_release_remote(tcp_globals.net_phone, 665 666 packet_get_id(packet)); … … 667 668 continue; 668 669 } 669 / / exactly following670 /* Exactly following */ 670 671 if (sequence_number == 671 672 socket_data->next_incoming) { 672 / / queue received data673 /* Queue received data */ 673 674 rc = tcp_queue_received_packet(socket, 674 675 socket_data, packet, 1, … … 680 681 packet = next_packet; 681 682 continue; 682 / / at least partly following data?683 /* At least partly following data? */ 683 684 } 684 685 if (IS_IN_INTERVAL_OVERFLOW(sequence_number, … … 695 696 rc = packet_trim(packet,length, 0); 696 697 if (rc == EOK) { 697 / / queue received data698 /* Queue received data */ 698 699 rc = tcp_queue_received_packet( 699 700 socket, socket_data, packet, … … 708 709 } 709 710 } 710 / / remove the duplicit or corrupted packet711 /* Remove the duplicit or corrupted packet */ 711 712 pq_release_remote(tcp_globals.net_phone, 712 713 packet_get_id(packet)); … … 721 722 socket_data->next_incoming + socket_data->window)) { 722 723 printf("in window\n"); 723 / / process acknowledgement724 /* Process acknowledgement */ 724 725 tcp_process_acknowledgement(socket, socket_data, header); 725 726 726 / / remove the header727 /* Remove the header */ 727 728 total_length -= TCP_HEADER_LENGTH(header); 728 729 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); … … 735 736 length); 736 737 if (rc != EOK) { 737 / / remove the corrupted packets738 /* Remove the corrupted packets */ 738 739 pq_release_remote(tcp_globals.net_phone, 739 740 packet_get_id(packet)); … … 762 763 } else { 763 764 printf("unexpected\n"); 764 / / release duplicite or restricted765 /* Release duplicite or restricted */ 765 766 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 766 767 } 767 768 768 / / change state according to the acknowledging incoming fin769 /* Change state according to the acknowledging incoming fin */ 769 770 if (IS_IN_INTERVAL_OVERFLOW(old_incoming, socket_data->fin_incoming, 770 771 socket_data->next_incoming)) { … … 775 776 socket_data->state = TCP_SOCKET_CLOSING; 776 777 break; 777 //case TCP_ESTABLISHED:778 /*case TCP_ESTABLISHED:*/ 778 779 default: 779 780 socket_data->state = TCP_SOCKET_CLOSE_WAIT; … … 784 785 packet = tcp_get_packets_to_send(socket, socket_data); 785 786 if (!packet) { 786 / / create the notification packet787 /* Create the notification packet */ 787 788 rc = tcp_create_notification_packet(&packet, socket, 788 789 socket_data, 0, 0); … … 798 799 fibril_rwlock_write_unlock(socket_data->local_lock); 799 800 800 / / send the packet801 /* Send the packet */ 801 802 tcp_send_packets(socket_data->device_id, packet); 802 803 … … 804 805 } 805 806 806 int 807 tcp_queue_received_packet(socket_core_ref socket, 807 int tcp_queue_received_packet(socket_core_ref socket, 808 808 tcp_socket_data_ref socket_data, packet_t packet, int fragments, 809 809 size_t total_length) … … 819 819 assert(socket_data->window > total_length); 820 820 821 / / queue the received packet821 /* Queue the received packet */ 822 822 rc = dyn_fifo_push(&socket->received, packet_get_id(packet), 823 823 SOCKET_MAX_RECEIVED_SIZE); … … 829 829 return tcp_release_and_return(packet, rc); 830 830 831 / / decrease the window size831 /* Decrease the window size */ 832 832 socket_data->window -= total_length; 833 833 834 / / notify the destination socket834 /* Notify the destination socket */ 835 835 async_msg_5(socket->phone, NET_SOCKET_RECEIVED, 836 836 (ipcarg_t) socket->socket_id, … … 842 842 } 843 843 844 int 845 tcp_process_syn_sent(socket_core_ref socket, tcp_socket_data_ref socket_data, 846 tcp_header_ref header, packet_t packet) 844 int tcp_process_syn_sent(socket_core_ref socket, tcp_socket_data_ref 845 socket_data, tcp_header_ref header, packet_t packet) 847 846 { 848 847 packet_t next_packet; … … 858 857 return tcp_release_and_return(packet, EINVAL); 859 858 860 / / process acknowledgement859 /* Process acknowledgement */ 861 860 tcp_process_acknowledgement(socket, socket_data, header); 862 861 863 862 socket_data->next_incoming = ntohl(header->sequence_number) + 1; 864 // release additional packets 863 864 /* Release additional packets */ 865 865 next_packet = pq_detach(packet); 866 866 if (next_packet) { … … 868 868 packet_get_id(next_packet)); 869 869 } 870 // trim if longer than the header 870 871 /* Trim if longer than the header */ 871 872 if (packet_get_data_length(packet) > sizeof(*header)) { 872 873 rc = packet_trim(packet, 0, … … 875 876 return tcp_release_and_return(packet, rc); 876 877 } 878 877 879 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); 878 880 fibril_mutex_lock(&socket_data->operation.mutex); 879 881 socket_data->operation.result = tcp_queue_packet(socket, socket_data, 880 882 packet, 1); 883 881 884 if (socket_data->operation.result == EOK) { 882 885 socket_data->state = TCP_SOCKET_ESTABLISHED; … … 884 887 if (packet) { 885 888 fibril_rwlock_write_unlock( socket_data->local_lock); 886 / / send the packet889 /* Send the packet */ 887 890 tcp_send_packets(socket_data->device_id, packet); 888 / / signal the result891 /* Signal the result */ 889 892 fibril_condvar_signal( &socket_data->operation.condvar); 890 893 fibril_mutex_unlock( &socket_data->operation.mutex); … … 892 895 } 893 896 } 897 894 898 fibril_mutex_unlock(&socket_data->operation.mutex); 895 899 return tcp_release_and_return(packet, EINVAL); 896 900 } 897 901 898 int 899 tcp_process_listen(socket_core_ref listening_socket, 902 int tcp_process_listen(socket_core_ref listening_socket, 900 903 tcp_socket_data_ref listening_socket_data, tcp_header_ref header, 901 904 packet_t packet, struct sockaddr *src, struct sockaddr *dest, … … 936 939 return tcp_release_and_return(packet, ENOMEM); 937 940 } 941 938 942 memcpy(socket_data->addr, src, socket_data->addrlen); 939 943 socket_data->dest_port = ntohs(header->source_port); … … 946 950 } 947 951 948 / / create a socket952 /* Create a socket */ 949 953 socket_id = -1; 950 954 rc = socket_create(socket_data->local_sockets, listening_socket->phone, … … 965 969 fibril_rwlock_write_lock(&tcp_globals.lock); 966 970 967 / / find the destination socket971 /* Find the destination socket */ 968 972 listening_socket = socket_port_find(&tcp_globals.sockets, 969 973 listening_port, SOCKET_MAP_KEY_LISTENING, 0); … … 971 975 (listening_socket->socket_id != listening_socket_id)) { 972 976 fibril_rwlock_write_unlock(&tcp_globals.lock); 973 / / a shadow may remain until app hangs up977 /* A shadow may remain until app hangs up */ 974 978 return tcp_release_and_return(packet, EOK /*ENOTSOCK*/); 975 979 } … … 983 987 socket_id); 984 988 if (!socket) { 985 / / where is the socket?!?989 /* Where is the socket?!? */ 986 990 fibril_rwlock_write_unlock(&tcp_globals.lock); 987 991 return ENOTSOCK; … … 1010 1014 socket_data->next_incoming = ntohl(header->sequence_number) + 1; 1011 1015 1012 / / release additional packets1016 /* Release additional packets */ 1013 1017 next_packet = pq_detach(packet); 1014 1018 if (next_packet) { … … 1017 1021 } 1018 1022 1019 / / trim if longer than the header1023 /* Trim if longer than the header */ 1020 1024 if (packet_get_data_length(packet) > sizeof(*header)) { 1021 1025 rc = packet_trim(packet, 0, … … 1050 1054 fibril_rwlock_write_unlock(socket_data->local_lock); 1051 1055 1052 / / send the packet1056 /* Send the packet */ 1053 1057 tcp_send_packets(socket_data->device_id, packet); 1054 1058 … … 1056 1060 } 1057 1061 1058 int 1059 tcp_process_syn_received(socket_core_ref socket, 1062 int tcp_process_syn_received(socket_core_ref socket, 1060 1063 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet) 1061 1064 { … … 1073 1076 return tcp_release_and_return(packet, EINVAL); 1074 1077 1075 / / process acknowledgement1078 /* Process acknowledgement */ 1076 1079 tcp_process_acknowledgement(socket, socket_data, header); 1077 1080 … … 1086 1089 assert(listening_socket_data); 1087 1090 1088 / / queue the received packet1091 /* Queue the received packet */ 1089 1092 rc = dyn_fifo_push(&listening_socket->accepted, 1090 1093 (-1 * socket->socket_id), listening_socket_data->backlog); 1091 1094 if (rc == EOK) { 1092 / / notify the destination socket1095 /* Notify the destination socket */ 1093 1096 async_msg_5(socket->phone, NET_SOCKET_ACCEPTED, 1094 1097 (ipcarg_t) listening_socket->socket_id, … … 1100 1103 } 1101 1104 } 1102 / / send FIN1105 /* Send FIN */ 1103 1106 socket_data->state = TCP_SOCKET_FIN_WAIT_1; 1104 1107 1105 / / create the notification packet1108 /* Create the notification packet */ 1106 1109 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 1107 1110 if (rc != EOK) 1108 1111 return rc; 1109 1112 1110 / / send the packet1113 /* Send the packet */ 1111 1114 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1112 1115 if (rc != EOK) 1113 1116 return rc; 1114 1117 1115 / / flush packets1118 /* Flush packets */ 1116 1119 packet = tcp_get_packets_to_send(socket, socket_data); 1117 1120 fibril_rwlock_write_unlock(socket_data->local_lock); 1118 1121 if (packet) { 1119 / / send the packet1122 /* Send the packet */ 1120 1123 tcp_send_packets(socket_data->device_id, packet); 1121 1124 } … … 1124 1127 } 1125 1128 1126 void 1127 tcp_process_acknowledgement(socket_core_ref socket, 1129 void tcp_process_acknowledgement(socket_core_ref socket, 1128 1130 tcp_socket_data_ref socket_data, tcp_header_ref header) 1129 1131 { … … 1144 1146 1145 1147 number = ntohl(header->acknowledgement_number); 1146 // if more data acknowledged 1148 1149 /* If more data acknowledged */ 1147 1150 if (number != socket_data->expected) { 1148 1151 old = socket_data->expected; … … 1155 1158 case TCP_SOCKET_LAST_ACK: 1156 1159 case TCP_SOCKET_CLOSING: 1157 // fin acknowledged - release the socket in 1158 // another fibril 1160 /* 1161 * FIN acknowledged - release the socket in 1162 * another fibril. 1163 */ 1159 1164 tcp_prepare_timeout(tcp_release_after_timeout, 1160 1165 socket, socket_data, 0, … … 1166 1171 } 1167 1172 } 1168 // update the treshold if higher than set 1173 1174 /* Update the treshold if higher than set */ 1169 1175 if (number + ntohs(header->window) > 1170 1176 socket_data->expected + socket_data->treshold) { … … 1172 1178 socket_data->expected; 1173 1179 } 1174 // set new expected sequence number 1180 1181 /* Set new expected sequence number */ 1175 1182 socket_data->expected = number; 1176 1183 socket_data->expected_count = 1; … … 1184 1191 socket_data->outgoing = next; 1185 1192 1186 / / add to acknowledged or release1193 /* Add to acknowledged or release */ 1187 1194 if (pq_add(&acknowledged, packet, 0, 0) != EOK) 1188 1195 pq_release_remote(tcp_globals.net_phone, … … 1192 1199 break; 1193 1200 } 1194 // release acknowledged 1201 1202 /* Release acknowledged */ 1195 1203 if (acknowledged) { 1196 1204 pq_release_remote(tcp_globals.net_phone, … … 1198 1206 } 1199 1207 return; 1200 // if the same as the previous time 1201 } 1208 /* If the same as the previous time */ 1209 } 1210 1202 1211 if (number == socket_data->expected) { 1203 / / increase the counter1212 /* Increase the counter */ 1204 1213 socket_data->expected_count++; 1205 1214 if (socket_data->expected_count == TCP_FAST_RETRANSMIT_COUNT) { 1206 1215 socket_data->expected_count = 1; 1207 / / TODO retransmit lock1216 /* TODO retransmit lock */ 1208 1217 //tcp_retransmit_packet(socket, socket_data, number); 1209 1218 } … … 1311 1320 while (keep_on_going) { 1312 1321 1313 / / answer the call1322 /* Answer the call */ 1314 1323 answer_call(callid, res, &answer, answer_count); 1315 / / refresh data1324 /* Refresh data */ 1316 1325 refresh_answer(&answer, &answer_count); 1317 / / get the next call1326 /* Get the next call */ 1318 1327 callid = async_get_call(&call); 1319 1328 1320 / / process the call1329 /* Process the call */ 1321 1330 switch (IPC_GET_METHOD(call)) { 1322 1331 case IPC_M_PHONE_HUNGUP: … … 1401 1410 if (res != EOK) 1402 1411 break; 1403 // the global lock may be released in the 1404 // tcp_connect_message() function 1412 /* 1413 * The global lock may be released in the 1414 * tcp_connect_message() function. 1415 */ 1405 1416 fibril_rwlock_write_lock(&tcp_globals.lock); 1406 1417 fibril_rwlock_write_lock(&lock); … … 1516 1527 } 1517 1528 1518 / / release the application phone1529 /* Release the application phone */ 1519 1530 ipc_hangup(app_phone); 1520 1531 1521 1532 printf("release\n"); 1522 / / release all local sockets1533 /* Release all local sockets */ 1523 1534 socket_cores_release(tcp_globals.net_phone, &local_sockets, 1524 1535 &tcp_globals.sockets, tcp_free_socket_data); … … 1536 1547 assert(timeout); 1537 1548 1538 / / sleep the given timeout1549 /* Sleep the given timeout */ 1539 1550 async_usleep(timeout->timeout); 1540 / / lock the globals1551 /* Lock the globals */ 1541 1552 if (timeout->globals_read_only) 1542 1553 fibril_rwlock_read_lock(&tcp_globals.lock); … … 1544 1555 fibril_rwlock_write_lock(&tcp_globals.lock); 1545 1556 1546 / / find the pending operation socket1557 /* Find the pending operation socket */ 1547 1558 socket = socket_port_find(&tcp_globals.sockets, timeout->port, 1548 1559 timeout->key, timeout->key_length); … … 1557 1568 fibril_rwlock_write_lock(socket_data->local_lock); 1558 1569 if (timeout->sequence_number) { 1559 / / increase the timeout counter;1570 /* Increase the timeout counter */ 1560 1571 socket_data->timeout_count++; 1561 1572 if (socket_data->timeout_count == TCP_MAX_TIMEOUTS) { 1562 / / TODO release as connection lost1573 /* TODO release as connection lost */ 1563 1574 //tcp_refresh_socket_data(socket_data); 1564 1575 fibril_rwlock_write_unlock(socket_data->local_lock); 1565 1576 } else { 1566 / / retransmit1577 /* Retransmit */ 1567 1578 // tcp_retransmit_packet(socket, 1568 1579 // socket_data, timeout->sequence_number); … … 1571 1582 } else { 1572 1583 fibril_mutex_lock(&socket_data->operation.mutex); 1573 // set the timeout operation result if state not 1574 // changed 1584 /* Set the timeout operation result if state not changed */ 1575 1585 if (socket_data->state == timeout->state) { 1576 1586 socket_data->operation.result = ETIMEOUT; 1577 // notify the main fibril 1587 1588 /* Notify the main fibril */ 1578 1589 fibril_condvar_signal(&socket_data->operation.condvar); 1579 // keep the global write lock 1590 1591 /* Keep the global write lock */ 1580 1592 keep_write_lock = true; 1581 1593 } else { 1582 // operation is ok, do nothing 1583 // unlocking from now on, so the unlocki 1584 // order does not matter... 1594 /* 1595 * Operation is ok, do nothing. 1596 * Unlocking from now on, so the unlocking 1597 * order does not matter. 1598 */ 1585 1599 fibril_rwlock_write_unlock(socket_data->local_lock); 1586 1600 } … … 1589 1603 1590 1604 out: 1591 / / unlock only if no socket1605 /* Unlock only if no socket */ 1592 1606 if (timeout->globals_read_only) 1593 1607 fibril_rwlock_read_unlock(&tcp_globals.lock); 1594 1608 else if (!keep_write_lock) 1595 / / release if not desired1609 /* Release if not desired */ 1596 1610 fibril_rwlock_write_unlock(&tcp_globals.lock); 1597 1611 1598 / / release the timeout structure1612 /* Release the timeout structure */ 1599 1613 free(timeout); 1600 1614 return EOK; … … 1610 1624 assert(timeout); 1611 1625 1612 / / sleep the given timeout1626 /* Sleep the given timeout */ 1613 1627 async_usleep(timeout->timeout); 1614 // lock the globals 1628 1629 /* Lock the globals */ 1615 1630 fibril_rwlock_write_lock(&tcp_globals.lock); 1616 // find the pending operation socket 1631 1632 /* Find the pending operation socket */ 1617 1633 socket = socket_port_find(&tcp_globals.sockets, timeout->port, 1618 1634 timeout->key, timeout->key_length); 1635 1619 1636 if (socket && (socket->socket_id == timeout->socket_id)) { 1620 1637 socket_data = (tcp_socket_data_ref) socket->specific_data; … … 1629 1646 } 1630 1647 } 1631 // unlock the globals 1648 1649 /* Unlock the globals */ 1632 1650 fibril_rwlock_write_unlock(&tcp_globals.lock); 1633 // release the timeout structure 1651 1652 /* Release the timeout structure */ 1634 1653 free(timeout); 1654 1635 1655 return EOK; 1636 1656 } 1637 1657 1638 void 1639 tcp_retransmit_packet(socket_core_ref socket, tcp_socket_data_ref socket_data, 1640 size_t sequence_number) 1658 void tcp_retransmit_packet(socket_core_ref socket, tcp_socket_data_ref 1659 socket_data, size_t sequence_number) 1641 1660 { 1642 1661 packet_t packet; … … 1648 1667 assert(socket->specific_data == socket_data); 1649 1668 1650 / / sent packet?1669 /* Sent packet? */ 1651 1670 packet = pq_find(socket_data->outgoing, sequence_number); 1652 1671 printf("retransmit %d\n", packet_get_id(packet)); … … 1664 1683 } 1665 1684 1666 int 1667 tcp_listen_message(socket_cores_ref local_sockets, int socket_id,int backlog)1685 int tcp_listen_message(socket_cores_ref local_sockets, int socket_id, 1686 int backlog) 1668 1687 { 1669 1688 socket_core_ref socket; … … 1675 1694 return EINVAL; 1676 1695 1677 / / find the socket1696 /* Find the socket */ 1678 1697 socket = socket_cores_find(local_sockets, socket_id); 1679 1698 if (!socket) 1680 1699 return ENOTSOCK; 1681 1700 1682 / / get the socket specific data1701 /* Get the socket specific data */ 1683 1702 socket_data = (tcp_socket_data_ref) socket->specific_data; 1684 1703 assert(socket_data); 1685 // set the backlog 1704 1705 /* Set the backlog */ 1686 1706 socket_data->backlog = backlog; 1687 1707 … … 1689 1709 } 1690 1710 1691 int 1692 tcp_connect_message(socket_cores_ref local_sockets, int socket_id, 1711 int tcp_connect_message(socket_cores_ref local_sockets, int socket_id, 1693 1712 struct sockaddr *addr, socklen_t addrlen) 1694 1713 { … … 1700 1719 assert(addrlen > 0); 1701 1720 1702 / / find the socket1721 /* Find the socket */ 1703 1722 socket = socket_cores_find(local_sockets, socket_id); 1704 1723 if (!socket) … … 1708 1727 if (rc != EOK) { 1709 1728 tcp_free_socket_data(socket); 1710 / / unbind if bound1729 /* Unbind if bound */ 1711 1730 if (socket->port > 0) { 1712 1731 socket_ports_exclude(&tcp_globals.sockets, … … 1718 1737 } 1719 1738 1720 int 1721 tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets, 1739 int tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets, 1722 1740 struct sockaddr *addr, socklen_t addrlen) 1723 1741 { … … 1730 1748 assert(addrlen > 0); 1731 1749 1732 / / get the socket specific data1750 /* Get the socket specific data */ 1733 1751 socket_data = (tcp_socket_data_ref) socket->specific_data; 1734 1752 assert(socket_data); … … 1739 1757 return EINVAL; 1740 1758 1741 / / get the destination port1759 /* Get the destination port */ 1742 1760 rc = tl_get_address_port(addr, addrlen, &socket_data->dest_port); 1743 1761 if (rc != EOK) … … 1745 1763 1746 1764 if (socket->port <= 0) { 1747 / / try to find a free port1765 /* Try to find a free port */ 1748 1766 rc = socket_bind_free_port(&tcp_globals.sockets, socket, 1749 1767 TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, … … 1751 1769 if (rc != EOK) 1752 1770 return rc; 1753 / / set the next port as the search starting port number1771 /* Set the next port as the search starting port number */ 1754 1772 tcp_globals.last_used_port = socket->port; 1755 1773 } … … 1761 1779 return rc; 1762 1780 1763 / / create the notification packet1781 /* Create the notification packet */ 1764 1782 rc = tcp_create_notification_packet(&packet, socket, socket_data, 1, 0); 1765 1783 if (rc != EOK) 1766 1784 return rc; 1767 1785 1768 / / unlock the globals and wait for an operation1786 /* Unlock the globals and wait for an operation */ 1769 1787 fibril_rwlock_write_unlock(&tcp_globals.lock); 1770 1788 1771 1789 socket_data->addr = addr; 1772 1790 socket_data->addrlen = addrlen; 1773 // send the packet 1791 1792 /* Send the packet */ 1774 1793 1775 1794 if (((rc = tcp_queue_packet(socket, socket_data, packet, 1)) != EOK) || … … 1785 1804 fibril_mutex_lock(&socket_data->operation.mutex); 1786 1805 fibril_rwlock_write_unlock(socket_data->local_lock); 1787 // send the packet 1806 1807 /* Send the packet */ 1788 1808 printf("connecting %d\n", packet_get_id(packet)); 1789 1809 tcp_send_packets(socket_data->device_id, packet); 1790 1810 1791 / / wait for a reply1811 /* Wait for a reply */ 1792 1812 fibril_condvar_wait(&socket_data->operation.condvar, 1793 1813 &socket_data->operation.mutex); … … 1805 1825 1806 1826 fibril_mutex_unlock(&socket_data->operation.mutex); 1807 1808 // return the result1809 1827 return rc; 1810 1828 } 1811 1829 1812 int 1813 tcp_queue_prepare_packet(socket_core_ref socket, 1830 int tcp_queue_prepare_packet(socket_core_ref socket, 1814 1831 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length) 1815 1832 { … … 1821 1838 assert(socket->specific_data == socket_data); 1822 1839 1823 / / get tcp header1840 /* Get TCP header */ 1824 1841 header = (tcp_header_ref) packet_get_data(packet); 1825 1842 if (!header) … … 1835 1852 return tcp_release_and_return(packet, EINVAL); 1836 1853 1837 / / remember the outgoing FIN1854 /* Remember the outgoing FIN */ 1838 1855 if (header->finalize) 1839 1856 socket_data->fin_outgoing = socket_data->next_outgoing; … … 1842 1859 } 1843 1860 1844 int 1845 tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data, 1861 int tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data, 1846 1862 packet_t packet, size_t data_length) 1847 1863 { … … 1865 1881 } 1866 1882 1867 packet_t 1868 tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_refsocket_data)1883 packet_t tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref 1884 socket_data) 1869 1885 { 1870 1886 packet_t packet; … … 1883 1899 pq_get_order(packet, NULL, &data_length); 1884 1900 1885 // send only if fits into the window 1886 // respecting the possible overflow 1901 /* 1902 * Send only if fits into the window, respecting the possible 1903 * overflow. 1904 */ 1887 1905 if (!IS_IN_INTERVAL_OVERFLOW( 1888 1906 (uint32_t) socket_data->last_outgoing, … … 1909 1927 previous = copy; 1910 1928 packet = pq_next(packet); 1911 // overflow occurred ? 1929 1930 /* Overflow occurred? */ 1912 1931 if (!packet && 1913 1932 (socket_data->last_outgoing > socket_data->next_outgoing)) { 1914 1933 printf("gpts overflow\n"); 1915 / / continue from the beginning1934 /* Continue from the beginning */ 1916 1935 packet = socket_data->outgoing; 1917 1936 } … … 1922 1941 } 1923 1942 1924 packet_t 1925 tcp_send_prepare_packet(socket_core_ref socket, tcp_socket_data_ref socket_data, 1926 packet_t packet, size_t data_length, size_t sequence_number) 1943 packet_t tcp_send_prepare_packet(socket_core_ref socket, tcp_socket_data_ref 1944 socket_data, packet_t packet, size_t data_length, size_t sequence_number) 1927 1945 { 1928 1946 tcp_header_ref header; … … 1934 1952 assert(socket->specific_data == socket_data); 1935 1953 1936 / / adjust the pseudo header1954 /* Adjust the pseudo header */ 1937 1955 rc = ip_client_set_pseudo_header_data_length(socket_data->pseudo_header, 1938 1956 socket_data->headerlen, packet_get_data_length(packet)); … … 1942 1960 } 1943 1961 1944 / / get the header1962 /* Get the header */ 1945 1963 header = (tcp_header_ref) packet_get_data(packet); 1946 1964 if (!header) { … … 1950 1968 assert(ntohl(header->sequence_number) == sequence_number); 1951 1969 1952 / / adjust the header1970 /* Adjust the header */ 1953 1971 if (socket_data->next_incoming) { 1954 1972 header->acknowledgement_number = … … 1958 1976 header->window = htons(socket_data->window); 1959 1977 1960 / / checksum1978 /* Checksum */ 1961 1979 header->checksum = 0; 1962 1980 checksum = compute_checksum(0, socket_data->pseudo_header, … … 1967 1985 header->checksum = htons(flip_checksum(compact_checksum(checksum))); 1968 1986 1969 / / prepare the packet1987 /* Prepare the packet */ 1970 1988 rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0); 1971 1989 if (rc != EOK) { … … 1973 1991 return NULL; 1974 1992 } 1993 1975 1994 rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data, 1976 1995 sequence_number, socket_data->state, socket_data->timeout, true); … … 1983 2002 } 1984 2003 1985 packet_t 1986 tcp_prepare_copy(socket_core_ref socket, tcp_socket_data_ref socket_data, 1987 packet_t packet, size_t data_length, size_t sequence_number) 2004 packet_t tcp_prepare_copy(socket_core_ref socket, tcp_socket_data_ref 2005 socket_data, packet_t packet, size_t data_length, size_t sequence_number) 1988 2006 { 1989 2007 packet_t copy; … … 1993 2011 assert(socket->specific_data == socket_data); 1994 2012 1995 / / make a copy of the packet2013 /* Make a copy of the packet */ 1996 2014 copy = packet_get_copy(tcp_globals.net_phone, packet); 1997 2015 if (!copy) … … 2014 2032 } 2015 2033 2016 void 2017 tcp_prepare_operation_header(socket_core_ref socket, 2034 void tcp_prepare_operation_header(socket_core_ref socket, 2018 2035 tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize, 2019 2036 int finalize) … … 2032 2049 } 2033 2050 2034 int 2035 tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t), 2051 int tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t), 2036 2052 socket_core_ref socket, tcp_socket_data_ref socket_data, 2037 2053 size_t sequence_number, tcp_socket_state_t state, suseconds_t timeout, … … 2045 2061 assert(socket->specific_data == socket_data); 2046 2062 2047 / / prepare the timeout with key bundle structure2063 /* Prepare the timeout with key bundle structure */ 2048 2064 operation_timeout = malloc(sizeof(*operation_timeout) + 2049 2065 socket->key_length + 1); … … 2060 2076 operation_timeout->state = state; 2061 2077 2062 / / copy the key2078 /* Copy the key */ 2063 2079 operation_timeout->key = ((char *) operation_timeout) + 2064 2080 sizeof(*operation_timeout); … … 2067 2083 operation_timeout->key[operation_timeout->key_length] = '\0'; 2068 2084 2069 / / prepare the timeouting thread2085 /* Prepare the timeouting thread */ 2070 2086 fibril = fibril_create(timeout_function, operation_timeout); 2071 2087 if (!fibril) { … … 2074 2090 } 2075 2091 // fibril_mutex_lock(&socket_data->operation.mutex); 2076 / / start the timeouting fibril2092 /* Start the timeout fibril */ 2077 2093 fibril_add_ready(fibril); 2078 2094 //socket_data->state = state; … … 2080 2096 } 2081 2097 2082 int 2083 tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags, 2084 size_t *addrlen) 2098 int tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, 2099 int flags, size_t *addrlen) 2085 2100 { 2086 2101 socket_core_ref socket; … … 2093 2108 assert(local_sockets); 2094 2109 2095 / / find the socket2110 /* Find the socket */ 2096 2111 socket = socket_cores_find(local_sockets, socket_id); 2097 2112 if (!socket) 2098 2113 return ENOTSOCK; 2099 2114 2100 / / get the socket specific data2115 /* Get the socket specific data */ 2101 2116 if (!socket->specific_data) 2102 2117 return NO_DATA; … … 2104 2119 socket_data = (tcp_socket_data_ref) socket->specific_data; 2105 2120 2106 / / check state2121 /* Check state */ 2107 2122 if ((socket_data->state != TCP_SOCKET_ESTABLISHED) && 2108 2123 (socket_data->state != TCP_SOCKET_CLOSE_WAIT)) 2109 2124 return ENOTCONN; 2110 2125 2111 / / send the source address if desired2126 /* Send the source address if desired */ 2112 2127 if (addrlen) { 2113 2128 rc = data_reply(socket_data->addr, socket_data->addrlen); … … 2117 2132 } 2118 2133 2119 / / get the next received packet2134 /* Get the next received packet */ 2120 2135 packet_id = dyn_fifo_value(&socket->received); 2121 2136 if (packet_id < 0) … … 2126 2141 return rc; 2127 2142 2128 / / reply the packets2143 /* Reply the packets */ 2129 2144 rc = socket_reply_packets(packet, &length); 2130 2145 if (rc != EOK) 2131 2146 return rc; 2132 2147 2133 / / release the packet2148 /* Release the packet */ 2134 2149 dyn_fifo_pop(&socket->received); 2135 2150 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 2136 // return the total length 2151 2152 /* Return the total length */ 2137 2153 return (int) length; 2138 2154 } 2139 2155 2140 int 2141 tcp_send_message(socket_cores_ref local_sockets, int socket_id, int fragments, 2142 size_t *data_fragment_size, int flags) 2156 int tcp_send_message(socket_cores_ref local_sockets, int socket_id, 2157 int fragments, size_t *data_fragment_size, int flags) 2143 2158 { 2144 2159 socket_core_ref socket; … … 2155 2170 assert(data_fragment_size); 2156 2171 2157 / / find the socket2172 /* Find the socket */ 2158 2173 socket = socket_cores_find(local_sockets, socket_id); 2159 2174 if (!socket) 2160 2175 return ENOTSOCK; 2161 2176 2162 / / get the socket specific data2177 /* Get the socket specific data */ 2163 2178 if (!socket->specific_data) 2164 2179 return NO_DATA; … … 2166 2181 socket_data = (tcp_socket_data_ref) socket->specific_data; 2167 2182 2168 / / check state2183 /* Check state */ 2169 2184 if ((socket_data->state != TCP_SOCKET_ESTABLISHED) && 2170 2185 (socket_data->state != TCP_SOCKET_CLOSE_WAIT)) … … 2181 2196 2182 2197 for (index = 0; index < fragments; index++) { 2183 / / read the data fragment2198 /* Read the data fragment */ 2184 2199 result = tl_socket_read_packet_data(tcp_globals.net_phone, 2185 2200 &packet, TCP_HEADER_SIZE, packet_dimension, … … 2189 2204 2190 2205 total_length = (size_t) result; 2191 // prefix the tcp header 2206 2207 /* Prefix the TCP header */ 2192 2208 header = PACKET_PREFIX(packet, tcp_header_t); 2193 2209 if (!header) … … 2200 2216 } 2201 2217 2202 / / flush packets2218 /* Flush packets */ 2203 2219 packet = tcp_get_packets_to_send(socket, socket_data); 2204 2220 fibril_rwlock_write_unlock(socket_data->local_lock); … … 2206 2222 2207 2223 if (packet) { 2208 / / send the packet2224 /* Send the packet */ 2209 2225 tcp_send_packets(socket_data->device_id, packet); 2210 2226 } … … 2221 2237 int rc; 2222 2238 2223 / / find the socket2239 /* Find the socket */ 2224 2240 socket = socket_cores_find(local_sockets, socket_id); 2225 2241 if (!socket) 2226 2242 return ENOTSOCK; 2227 2243 2228 / / get the socket specific data2244 /* Get the socket specific data */ 2229 2245 socket_data = (tcp_socket_data_ref) socket->specific_data; 2230 2246 assert(socket_data); 2231 2247 2232 / / check state2248 /* Check state */ 2233 2249 switch (socket_data->state) { 2234 2250 case TCP_SOCKET_ESTABLISHED: … … 2243 2259 2244 2260 default: 2245 / / just destroy2261 /* Just destroy */ 2246 2262 rc = socket_destroy(tcp_globals.net_phone, socket_id, 2247 2263 local_sockets, &tcp_globals.sockets, … … 2254 2270 } 2255 2271 2256 // send FIN 2257 // TODO should I wait to complete? 2258 2259 // create the notification packet 2272 /* 2273 * Send FIN. 2274 * TODO should I wait to complete? 2275 */ 2276 2277 /* Create the notification packet */ 2260 2278 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 2261 2279 if (rc != EOK) 2262 2280 return rc; 2263 2281 2264 / / send the packet2282 /* Send the packet */ 2265 2283 rc = tcp_queue_packet(socket, socket_data, packet, 1); 2266 2284 if (rc != EOK) 2267 2285 return rc; 2268 2286 2269 / / flush packets2287 /* Flush packets */ 2270 2288 packet = tcp_get_packets_to_send(socket, socket_data); 2271 2289 fibril_rwlock_write_unlock(socket_data->local_lock); … … 2273 2291 2274 2292 if (packet) { 2275 / / send the packet2293 /* Send the packet */ 2276 2294 tcp_send_packets(socket_data->device_id, packet); 2277 2295 } … … 2280 2298 } 2281 2299 2282 int 2283 tcp_create_notification_packet(packet_t *packet, socket_core_ref socket, 2300 int tcp_create_notification_packet(packet_t *packet, socket_core_ref socket, 2284 2301 tcp_socket_data_ref socket_data, int synchronize, int finalize) 2285 2302 { … … 2290 2307 assert(packet); 2291 2308 2292 / / get the device packet dimension2309 /* Get the device packet dimension */ 2293 2310 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2294 2311 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); … … 2296 2313 return rc; 2297 2314 2298 / / get a new packet2315 /* Get a new packet */ 2299 2316 *packet = packet_get_4_remote(tcp_globals.net_phone, TCP_HEADER_SIZE, 2300 2317 packet_dimension->addr_len, packet_dimension->prefix, … … 2304 2321 return ENOMEM; 2305 2322 2306 / / allocate space in the packet2323 /* Allocate space in the packet */ 2307 2324 header = PACKET_SUFFIX(*packet, tcp_header_t); 2308 2325 if (!header) … … 2315 2332 } 2316 2333 2317 int 2318 tcp_accept_message(socket_cores_ref local_sockets, int socket_id, 2334 int tcp_accept_message(socket_cores_ref local_sockets, int socket_id, 2319 2335 int new_socket_id, size_t *data_fragment_size, size_t *addrlen) 2320 2336 { … … 2329 2345 assert(addrlen); 2330 2346 2331 / / find the socket2347 /* Find the socket */ 2332 2348 socket = socket_cores_find(local_sockets, socket_id); 2333 2349 if (!socket) 2334 2350 return ENOTSOCK; 2335 2351 2336 / / get the socket specific data2352 /* Get the socket specific data */ 2337 2353 socket_data = (tcp_socket_data_ref) socket->specific_data; 2338 2354 assert(socket_data); 2339 2355 2340 / / check state2356 /* Check state */ 2341 2357 if (socket_data->state != TCP_SOCKET_LISTEN) 2342 2358 return EINVAL; … … 2352 2368 return ENOTSOCK; 2353 2369 2354 / / get the socket specific data2370 /* Get the socket specific data */ 2355 2371 socket_data = (tcp_socket_data_ref) accepted->specific_data; 2356 2372 assert(socket_data); 2357 / / TODO can it be in another state?2373 /* TODO can it be in another state? */ 2358 2374 if (socket_data->state == TCP_SOCKET_ESTABLISHED) { 2359 2375 rc = data_reply(socket_data->addr, … … 2389 2405 } 2390 2406 2391 void 2392 tcp_free_socket_data(socket_core_ref socket) 2407 void tcp_free_socket_data(socket_core_ref socket) 2393 2408 { 2394 2409 tcp_socket_data_ref socket_data; … … 2398 2413 printf("destroy_socket %d\n", socket->socket_id); 2399 2414 2400 / / get the socket specific data2415 /* Get the socket specific data */ 2401 2416 socket_data = (tcp_socket_data_ref) socket->specific_data; 2402 2417 assert(socket_data); 2403 //free the pseudo header 2418 2419 /* Free the pseudo header */ 2404 2420 if (socket_data->pseudo_header) { 2405 2421 if (socket_data->headerlen) { … … 2410 2426 socket_data->pseudo_header = NULL; 2411 2427 } 2428 2412 2429 socket_data->headerlen = 0; 2413 // free the address 2430 2431 /* Free the address */ 2414 2432 if (socket_data->addr) { 2415 2433 if (socket_data->addrlen) { … … 2473 2491 2474 2492 /* 2475 2493 * Answer the message 2476 2494 */ 2477 2495 answer_call(callid, res, &answer, answer_count); -
uspace/srv/net/tl/tcp/tcp_module.c
rc9ebbe71 rfb04cba8 86 86 } 87 87 88 int 89 tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call, 88 int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call, 90 89 ipc_call_t *answer, int *answer_count) 91 90 { -
uspace/srv/net/tl/udp/udp.c
rc9ebbe71 rfb04cba8 130 130 } 131 131 132 / / read default packet dimensions132 /* Read default packet dimensions */ 133 133 rc = ip_packet_size_req(udp_globals.ip_phone, -1, 134 134 &udp_globals.packet_dimension); … … 158 158 udp_globals.autobinding = NET_DEFAULT_UDP_AUTOBINDING; 159 159 160 / / get configuration160 /* Get configuration */ 161 161 configuration = &names[0]; 162 162 rc = net_get_conf_req(udp_globals.net_phone, &configuration, count, … … 217 217 * ip_client_process_packet() function. 218 218 */ 219 static int 220 udp_process_packet(device_id_t device_id, packet_t packet,services_t error)219 static int udp_process_packet(device_id_t device_id, packet_t packet, 220 services_t error) 221 221 { 222 222 size_t length; … … 242 242 break; 243 243 case SERVICE_ICMP: 244 / / ignore error244 /* Ignore error */ 245 245 // length = icmp_client_header_length(packet); 246 // process error 246 247 /* Process error */ 247 248 result = icmp_client_process_packet(packet, &type, 248 249 &code, NULL, NULL); … … 258 259 } 259 260 260 / / TODO process received ipopts?261 /* TODO process received ipopts? */ 261 262 result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL); 262 263 if (result < 0) … … 270 271 return udp_release_and_return(packet, NO_DATA); 271 272 272 / / trim all but UDP header273 /* Trim all but UDP header */ 273 274 rc = packet_trim(packet, offset, 0); 274 275 if (rc != EOK) 275 276 return udp_release_and_return(packet, rc); 276 277 277 / / get udp header278 /* Get UDP header */ 278 279 header = (udp_header_ref) packet_get_data(packet); 279 280 if (!header) 280 281 return udp_release_and_return(packet, NO_DATA); 281 282 282 / / find the destination socket283 /* Find the destination socket */ 283 284 socket = socket_port_find(&udp_globals.sockets, 284 285 ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING, 0); … … 292 293 } 293 294 294 / / count the received packet fragments295 /* Count the received packet fragments */ 295 296 next_packet = packet; 296 297 fragments = 0; 297 298 total_length = ntohs(header->total_length); 298 299 299 / / compute header checksum if set300 /* Compute header checksum if set */ 300 301 if (header->checksum && !error) { 301 302 result = packet_get_addr(packet, (uint8_t **) &src, … … 310 311 } else { 311 312 checksum = compute_checksum(0, ip_header, length); 312 // the udp header checksum will be added with the first 313 // fragment later 313 /* 314 * The udp header checksum will be added with the first 315 * fragment later. 316 */ 314 317 free(ip_header); 315 318 } … … 330 333 return udp_release_and_return(packet, rc); 331 334 332 / / add partial checksum if set335 /* Add partial checksum if set */ 333 336 if (header->checksum) { 334 337 checksum = compute_checksum(checksum, … … 337 340 } 338 341 339 / / relese the rest of the packet fragments342 /* Relese the rest of the packet fragments */ 340 343 tmp_packet = pq_next(next_packet); 341 344 while (tmp_packet) { … … 346 349 } 347 350 348 / / exit the loop351 /* Exit the loop */ 349 352 break; 350 353 } 351 354 total_length -= length; 352 355 353 / / add partial checksum if set356 /* Add partial checksum if set */ 354 357 if (header->checksum) { 355 358 checksum = compute_checksum(checksum, … … 360 363 } while ((next_packet = pq_next(next_packet)) && (total_length > 0)); 361 364 362 / / check checksum365 /* Verify checksum */ 363 366 if (header->checksum) { 364 367 if (flip_checksum(compact_checksum(checksum)) != … … 366 369 if (tl_prepare_icmp_packet(udp_globals.net_phone, 367 370 udp_globals.icmp_phone, packet, error) == EOK) { 368 / / checksum error ICMP371 /* Checksum error ICMP */ 369 372 icmp_parameter_problem_msg( 370 373 udp_globals.icmp_phone, ICMP_PARAM_POINTER, … … 376 379 } 377 380 378 / / queue the received packet381 /* Queue the received packet */ 379 382 rc = dyn_fifo_push(&socket->received, packet_get_id(packet), 380 383 SOCKET_MAX_RECEIVED_SIZE); … … 387 390 return udp_release_and_return(packet, rc); 388 391 389 / / notify the destination socket392 /* Notify the destination socket */ 390 393 fibril_rwlock_write_unlock(&udp_globals.lock); 391 394 async_msg_5(socket->phone, NET_SOCKET_RECEIVED, … … 410 413 * udp_process_packet() function. 411 414 */ 412 static int 413 udp_received_msg(device_id_t device_id, packet_t packet, services_t receiver, 414 services_t error) 415 static int udp_received_msg(device_id_t device_id, packet_t packet, 416 services_t receiver, services_t error) 415 417 { 416 418 int result; … … 451 453 * function. 452 454 */ 453 static int 454 udp_sendto_message(socket_cores_ref local_sockets, int socket_id, 455 static int udp_sendto_message(socket_cores_ref local_sockets, int socket_id, 455 456 const struct sockaddr *addr, socklen_t addrlen, int fragments, 456 457 size_t *data_fragment_size, int flags) … … 480 481 481 482 if ((socket->port <= 0) && udp_globals.autobinding) { 482 / / bind the socket to a random free port if not bound483 /* Bind the socket to a random free port if not bound */ 483 484 rc = socket_bind_free_port(&udp_globals.sockets, socket, 484 485 UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, … … 486 487 if (rc != EOK) 487 488 return rc; 488 / / set the next port as the search starting port number489 /* Set the next port as the search starting port number */ 489 490 udp_globals.last_used_port = socket->port; 490 491 } … … 495 496 if (rc != EOK) 496 497 return rc; 497 / / get the device packet dimension498 /* Get the device packet dimension */ 498 499 // rc = tl_get_ip_packet_dimension(udp_globals.ip_phone, 499 500 // &udp_globals.dimensions, device_id, &packet_dimension); … … 502 503 } 503 504 // } else { 504 / / do not ask all the time505 /* Do not ask all the time */ 505 506 rc = ip_packet_size_req(udp_globals.ip_phone, -1, 506 507 &udp_globals.packet_dimension); … … 510 511 // } 511 512 512 / / read the first packet fragment513 /* Read the first packet fragment */ 513 514 result = tl_socket_read_packet_data(udp_globals.net_phone, &packet, 514 515 UDP_HEADER_SIZE, packet_dimension, addr, addrlen); … … 523 524 checksum = 0; 524 525 525 / / prefix the udp header526 /* Prefix the UDP header */ 526 527 header = PACKET_PREFIX(packet, udp_header_t); 527 528 if (!header) … … 529 530 530 531 bzero(header, sizeof(*header)); 531 // read the rest of the packet fragments 532 533 /* Read the rest of the packet fragments */ 532 534 for (index = 1; index < fragments; index++) { 533 535 result = tl_socket_read_packet_data(udp_globals.net_phone, … … 548 550 } 549 551 550 / / set the udp header552 /* Set the UDP header */ 551 553 header->source_port = htons((socket->port > 0) ? socket->port : 0); 552 554 header->destination_port = htons(dest_port); 553 555 header->total_length = htons(total_length + sizeof(*header)); 554 556 header->checksum = 0; 557 555 558 if (udp_globals.checksum_computing) { 556 / / update the pseudo header559 /* Update the pseudo header */ 557 560 rc = ip_client_set_pseudo_header_data_length(ip_header, 558 561 headerlen, total_length + UDP_HEADER_SIZE); … … 562 565 } 563 566 564 / / finish the checksum computation567 /* Finish the checksum computation */ 565 568 checksum = compute_checksum(checksum, ip_header, headerlen); 566 569 checksum = compute_checksum(checksum, (uint8_t *) header, … … 573 576 } 574 577 575 / / prepare the first packet fragment578 /* Prepare the first packet fragment */ 576 579 rc = ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 0, 0); 577 580 if (rc != EOK) … … 581 584 fibril_rwlock_write_unlock(&udp_globals.lock); 582 585 583 / / send the packet586 /* Send the packet */ 584 587 ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0); 585 588 … … 606 609 * function. 607 610 */ 608 static int 609 udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags, 610 size_t *addrlen) 611 static int udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, 612 int flags, size_t *addrlen) 611 613 { 612 614 socket_core_ref socket; … … 620 622 int rc; 621 623 622 / / find the socket624 /* Find the socket */ 623 625 socket = socket_cores_find(local_sockets, socket_id); 624 626 if (!socket) 625 627 return ENOTSOCK; 626 628 627 / / get the next received packet629 /* Get the next received packet */ 628 630 packet_id = dyn_fifo_value(&socket->received); 629 631 if (packet_id < 0) … … 636 638 } 637 639 638 / / get udp header640 /* Get UDP header */ 639 641 data = packet_get_data(packet); 640 642 if (!data) { … … 644 646 header = (udp_header_ref) data; 645 647 646 / / set the source address port648 /* Set the source address port */ 647 649 result = packet_get_addr(packet, (uint8_t **) &addr, NULL); 648 650 rc = tl_set_address_port(addr, result, ntohs(header->source_port)); … … 653 655 *addrlen = (size_t) result; 654 656 655 / / send the source address657 /* Send the source address */ 656 658 rc = data_reply(addr, *addrlen); 657 659 switch (rc) { … … 665 667 } 666 668 667 / / trim the header669 /* Trim the header */ 668 670 rc = packet_trim(packet, UDP_HEADER_SIZE, 0); 669 671 if (rc != EOK) { … … 672 674 } 673 675 674 / / reply the packets676 /* Reply the packets */ 675 677 rc = socket_reply_packets(packet, &length); 676 678 switch (rc) { … … 686 688 (void) dyn_fifo_pop(&socket->received); 687 689 688 / / release the packet and return the total length690 /* Release the packet and return the total length */ 689 691 return udp_release_and_return(packet, (int) length); 690 692 } … … 721 723 answer_count = 0; 722 724 723 // The client connection is only in one fibril and therefore no 724 // additional locks are needed. 725 /* 726 * The client connection is only in one fibril and therefore no 727 * additional locks are needed. 728 */ 725 729 726 730 socket_cores_initialize(&local_sockets); … … 728 732 while (keep_on_going) { 729 733 730 / / answer the call734 /* Answer the call */ 731 735 answer_call(callid, res, &answer, answer_count); 732 736 733 / / refresh data737 /* Refresh data */ 734 738 refresh_answer(&answer, &answer_count); 735 739 736 / / get the next call740 /* Get the next call */ 737 741 callid = async_get_call(&call); 738 742 739 / / process the call743 /* Process the call */ 740 744 switch (IPC_GET_METHOD(call)) { 741 745 case IPC_M_PHONE_HUNGUP: … … 831 835 } 832 836 833 / / release the application phone837 /* Release the application phone */ 834 838 ipc_hangup(app_phone); 835 839 836 / / release all local sockets840 /* Release all local sockets */ 837 841 socket_cores_release(udp_globals.net_phone, &local_sockets, 838 842 &udp_globals.sockets, NULL); … … 854 858 * @see IS_NET_UDP_MESSAGE() 855 859 */ 856 int 857 udp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 860 int udp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 858 861 ipc_call_t *answer, int *answer_count) 859 862 { -
uspace/srv/net/tl/udp/udp_module.c
rc9ebbe71 rfb04cba8 86 86 } 87 87 88 int 89 tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call, 88 int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call, 90 89 ipc_call_t *answer, int *answer_count) 91 90 {
Note:
See TracChangeset
for help on using the changeset viewer.