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