Changes in uspace/srv/net/tl/udp/udp.c [6b82009:afe1d1e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/udp/udp.c
r6b82009 rafe1d1e 99 99 static int udp_release_and_return(packet_t *packet, int result) 100 100 { 101 pq_release_remote(udp_globals.net_ sess, packet_get_id(packet));101 pq_release_remote(udp_globals.net_phone, packet_get_id(packet)); 102 102 return result; 103 103 } … … 192 192 ntohs(header->destination_port), (uint8_t *) SOCKET_MAP_KEY_LISTENING, 0); 193 193 if (!socket) { 194 if (tl_prepare_icmp_packet(udp_globals.net_ sess,195 udp_globals.icmp_ sess, packet, error) == EOK) {196 icmp_destination_unreachable_msg(udp_globals.icmp_ sess,194 if (tl_prepare_icmp_packet(udp_globals.net_phone, 195 udp_globals.icmp_phone, packet, error) == EOK) { 196 icmp_destination_unreachable_msg(udp_globals.icmp_phone, 197 197 ICMP_PORT_UNREACH, 0, packet); 198 198 } … … 251 251 while (tmp_packet) { 252 252 next_packet = pq_detach(tmp_packet); 253 pq_release_remote(udp_globals.net_ sess,253 pq_release_remote(udp_globals.net_phone, 254 254 packet_get_id(tmp_packet)); 255 255 tmp_packet = next_packet; … … 274 274 if (flip_checksum(compact_checksum(checksum)) != 275 275 IP_CHECKSUM_ZERO) { 276 if (tl_prepare_icmp_packet(udp_globals.net_ sess,277 udp_globals.icmp_ sess, packet, error) == EOK) {276 if (tl_prepare_icmp_packet(udp_globals.net_phone, 277 udp_globals.icmp_phone, packet, error) == EOK) { 278 278 /* Checksum error ICMP */ 279 279 icmp_parameter_problem_msg( 280 udp_globals.icmp_ sess, ICMP_PARAM_POINTER,280 udp_globals.icmp_phone, ICMP_PARAM_POINTER, 281 281 ((size_t) ((void *) &header->checksum)) - 282 282 ((size_t) ((void *) header)), packet); … … 292 292 return udp_release_and_return(packet, rc); 293 293 294 rc = tl_get_ip_packet_dimension(udp_globals.ip_ sess,294 rc = tl_get_ip_packet_dimension(udp_globals.ip_phone, 295 295 &udp_globals.dimensions, device_id, &packet_dimension); 296 296 if (rc != EOK) … … 299 299 /* Notify the destination socket */ 300 300 fibril_rwlock_write_unlock(&udp_globals.lock); 301 302 async_exch_t *exch = async_exchange_begin(socket->sess); 303 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) socket->socket_id, 304 packet_dimension->content, 0, 0, (sysarg_t) fragments); 305 async_exchange_end(exch); 301 async_msg_5(socket->phone, NET_SOCKET_RECEIVED, 302 (sysarg_t) socket->socket_id, packet_dimension->content, 0, 0, 303 (sysarg_t) fragments); 306 304 307 305 return EOK; … … 339 337 * @param[in] iid Message identifier. 340 338 * @param[in,out] icall Message parameters. 341 * @param[in] arg Local argument. 342 * 343 */ 344 static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) 339 * 340 */ 341 static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall) 345 342 { 346 343 packet_t *packet; … … 350 347 switch (IPC_GET_IMETHOD(*icall)) { 351 348 case NET_TL_RECEIVED: 352 rc = packet_translate_remote(udp_globals.net_ sess, &packet,349 rc = packet_translate_remote(udp_globals.net_phone, &packet, 353 350 IPC_GET_PACKET(*icall)); 354 351 if (rc == EOK) … … 368 365 /** Initialize the UDP module. 369 366 * 370 * @param[in] sess Network module session.367 * @param[in] net_phone Network module phone. 371 368 * 372 369 * @return EOK on success. … … 374 371 * 375 372 */ 376 int tl_initialize( async_sess_t *sess)373 int tl_initialize(int net_phone) 377 374 { 378 375 measured_string_t names[] = { … … 393 390 fibril_rwlock_write_lock(&udp_globals.lock); 394 391 395 udp_globals.net_sess = sess; 396 udp_globals.icmp_sess = icmp_connect_module(); 397 398 udp_globals.ip_sess = ip_bind_service(SERVICE_IP, IPPROTO_UDP, 399 SERVICE_UDP, udp_receiver); 400 if (udp_globals.ip_sess == NULL) { 401 fibril_rwlock_write_unlock(&udp_globals.lock); 402 return ENOENT; 392 udp_globals.net_phone = net_phone; 393 394 udp_globals.icmp_phone = icmp_connect_module(ICMP_CONNECT_TIMEOUT); 395 396 udp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_UDP, 397 SERVICE_UDP, udp_receiver); 398 if (udp_globals.ip_phone < 0) { 399 fibril_rwlock_write_unlock(&udp_globals.lock); 400 return udp_globals.ip_phone; 403 401 } 404 402 405 403 /* Read default packet dimensions */ 406 int rc = ip_packet_size_req(udp_globals.ip_ sess, -1,404 int rc = ip_packet_size_req(udp_globals.ip_phone, -1, 407 405 &udp_globals.packet_dimension); 408 406 if (rc != EOK) { … … 419 417 rc = packet_dimensions_initialize(&udp_globals.dimensions); 420 418 if (rc != EOK) { 421 socket_ports_destroy(&udp_globals.sockets , free);419 socket_ports_destroy(&udp_globals.sockets); 422 420 fibril_rwlock_write_unlock(&udp_globals.lock); 423 421 return rc; … … 433 431 /* Get configuration */ 434 432 configuration = &names[0]; 435 rc = net_get_conf_req(udp_globals.net_ sess, &configuration, count,433 rc = net_get_conf_req(udp_globals.net_phone, &configuration, count, 436 434 &data); 437 435 if (rc != EOK) { 438 socket_ports_destroy(&udp_globals.sockets , free);436 socket_ports_destroy(&udp_globals.sockets); 439 437 fibril_rwlock_write_unlock(&udp_globals.lock); 440 438 return rc; … … 501 499 device_id_t device_id; 502 500 packet_dimension_t *packet_dimension; 503 size_t size;504 501 int rc; 505 506 /* In case of error, do not update the data fragment size. */507 *data_fragment_size = 0;508 502 509 503 rc = tl_get_address_port(addr, addrlen, &dest_port); … … 527 521 528 522 if (udp_globals.checksum_computing) { 529 rc = ip_get_route_req(udp_globals.ip_ sess, IPPROTO_UDP, addr,523 rc = ip_get_route_req(udp_globals.ip_phone, IPPROTO_UDP, addr, 530 524 addrlen, &device_id, &ip_header, &headerlen); 531 525 if (rc != EOK) 532 526 return rc; 533 527 /* Get the device packet dimension */ 534 // rc = tl_get_ip_packet_dimension(udp_globals.ip_ sess,528 // rc = tl_get_ip_packet_dimension(udp_globals.ip_phone, 535 529 // &udp_globals.dimensions, device_id, &packet_dimension); 536 530 // if (rc != EOK) … … 539 533 // } else { 540 534 /* Do not ask all the time */ 541 rc = ip_packet_size_req(udp_globals.ip_ sess, -1,535 rc = ip_packet_size_req(udp_globals.ip_phone, -1, 542 536 &udp_globals.packet_dimension); 543 537 if (rc != EOK) … … 546 540 // } 547 541 548 /*549 * Update the data fragment size based on what the lower layers can550 * handle without fragmentation, but not more than the maximum allowed551 * for UDP.552 */553 size = MAX_UDP_FRAGMENT_SIZE;554 if (packet_dimension->content < size)555 size = packet_dimension->content;556 *data_fragment_size = size;557 558 542 /* Read the first packet fragment */ 559 result = tl_socket_read_packet_data(udp_globals.net_ sess, &packet,543 result = tl_socket_read_packet_data(udp_globals.net_phone, &packet, 560 544 UDP_HEADER_SIZE, packet_dimension, addr, addrlen); 561 545 if (result < 0) … … 578 562 /* Read the rest of the packet fragments */ 579 563 for (index = 1; index < fragments; index++) { 580 result = tl_socket_read_packet_data(udp_globals.net_ sess,564 result = tl_socket_read_packet_data(udp_globals.net_phone, 581 565 &next_packet, 0, packet_dimension, addr, addrlen); 582 566 if (result < 0) … … 630 614 631 615 /* Send the packet */ 632 ip_send_msg(udp_globals.ip_ sess, device_id, packet, SERVICE_UDP, 0);616 ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0); 633 617 634 618 return EOK; … … 677 661 return NO_DATA; 678 662 679 rc = packet_translate_remote(udp_globals.net_ sess, &packet, packet_id);663 rc = packet_translate_remote(udp_globals.net_phone, &packet, packet_id); 680 664 if (rc != EOK) { 681 665 (void) dyn_fifo_pop(&socket->received); … … 737 721 } 738 722 739 /** Process the socket client messages. 740 * 741 * Run until the client module disconnects. 742 * 743 * @see socket.h 744 * 745 * @param[in] sess Callback session. 746 * @param[in] callid Message identifier. 747 * @param[in] call Message parameters. 748 * 749 * @return EOK on success. 750 * 751 */ 752 static int udp_process_client_messages(async_sess_t *sess, ipc_callid_t callid, 753 ipc_call_t call) 723 /** Processes the socket client messages. 724 * 725 * Runs until the client module disconnects. 726 * 727 * @param[in] callid The message identifier. 728 * @param[in] call The message parameters. 729 * @return EOK on success. 730 * 731 * @see socket.h 732 */ 733 static int udp_process_client_messages(ipc_callid_t callid, ipc_call_t call) 754 734 { 755 735 int res; 736 bool keep_on_going = true; 756 737 socket_cores_t local_sockets; 738 int app_phone = IPC_GET_PHONE(call); 757 739 struct sockaddr *addr; 758 740 int socket_id; 759 741 size_t addrlen; 760 size_t size ;742 size_t size = 0; 761 743 ipc_call_t answer; 762 744 size_t answer_count; … … 777 759 socket_cores_initialize(&local_sockets); 778 760 779 while ( true) {761 while (keep_on_going) { 780 762 781 763 /* Answer the call */ … … 789 771 790 772 /* Process the call */ 791 if (!IPC_GET_IMETHOD(call)) { 773 switch (IPC_GET_IMETHOD(call)) { 774 case IPC_M_PHONE_HUNGUP: 775 keep_on_going = false; 792 776 res = EHANGUP; 793 777 break; 794 } 795 796 switch (IPC_GET_IMETHOD(call)) { 778 797 779 case NET_SOCKET: 798 780 socket_id = SOCKET_GET_SOCKET_ID(call); 799 res = socket_create(&local_sockets, sess, NULL,781 res = socket_create(&local_sockets, app_phone, NULL, 800 782 &socket_id); 801 783 SOCKET_SET_SOCKET_ID(answer, socket_id); … … 804 786 break; 805 787 806 size = MAX_UDP_FRAGMENT_SIZE; 807 if (tl_get_ip_packet_dimension(udp_globals.ip_sess, 788 if (tl_get_ip_packet_dimension(udp_globals.ip_phone, 808 789 &udp_globals.dimensions, DEVICE_INVALID_ID, 809 790 &packet_dimension) == EOK) { 810 if (packet_dimension->content < size)811 size = packet_dimension->content;791 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, 792 packet_dimension->content); 812 793 } 813 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size); 794 795 // SOCKET_SET_DATA_FRAGMENT_SIZE(answer, 796 // MAX_UDP_FRAGMENT_SIZE); 814 797 SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE); 815 798 answer_count = 3; … … 869 852 case NET_SOCKET_CLOSE: 870 853 fibril_rwlock_write_lock(&udp_globals.lock); 871 res = socket_destroy(udp_globals.net_ sess,854 res = socket_destroy(udp_globals.net_phone, 872 855 SOCKET_GET_SOCKET_ID(call), &local_sockets, 873 856 &udp_globals.sockets, NULL); … … 883 866 } 884 867 885 /* Release the application session*/886 async_hangup( sess);868 /* Release the application phone */ 869 async_hangup(app_phone); 887 870 888 871 /* Release all local sockets */ 889 socket_cores_release(udp_globals.net_ sess, &local_sockets,872 socket_cores_release(udp_globals.net_phone, &local_sockets, 890 873 &udp_globals.sockets, NULL); 891 874 … … 917 900 { 918 901 *answer_count = 0; 919 920 async_sess_t *callback =921 async_callback_receive_start(EXCHANGE_SERIALIZE, call);922 if (callback)923 return udp_process_client_messages(callback, callid, *call);924 902 903 switch (IPC_GET_IMETHOD(*call)) { 904 case IPC_M_CONNECT_TO_ME: 905 return udp_process_client_messages(callid, *call); 906 } 907 925 908 return ENOTSUP; 926 909 }
Note:
See TracChangeset
for help on using the changeset viewer.