Changes in uspace/srv/net/tl/udp/udp.c [6092b56e:14f1db0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/udp/udp.c
r6092b56e r14f1db0 40 40 #include <malloc.h> 41 41 #include <stdio.h> 42 43 42 #include <ipc/ipc.h> 44 43 #include <ipc/services.h> 45 44 46 #include "../../err.h" 47 #include "../../messages.h" 48 #include "../../modules.h" 49 50 #include "../../structures/dynamic_fifo.h" 51 #include "../../structures/packet/packet_client.h" 52 53 #include "../../include/checksum.h" 54 #include "../../include/in.h" 55 #include "../../include/in6.h" 56 #include "../../include/inet.h" 57 #include "../../include/ip_client.h" 58 #include "../../include/ip_interface.h" 59 #include "../../include/ip_protocols.h" 60 #include "../../include/icmp_client.h" 61 #include "../../include/icmp_interface.h" 62 #include "../../include/net_interface.h" 63 #include "../../include/socket_codes.h" 64 #include "../../include/socket_errno.h" 65 66 #include "../../socket/socket_core.h" 67 #include "../../socket/socket_messages.h" 68 69 #include "../tl_common.h" 70 #include "../tl_messages.h" 45 #include <net_err.h> 46 #include <net_messages.h> 47 #include <net_modules.h> 48 #include <adt/dynamic_fifo.h> 49 #include <packet/packet_client.h> 50 #include <packet_remote.h> 51 #include <net_checksum.h> 52 #include <in.h> 53 #include <in6.h> 54 #include <inet.h> 55 #include <ip_client.h> 56 #include <ip_interface.h> 57 #include <ip_protocols.h> 58 #include <icmp_client.h> 59 #include <icmp_interface.h> 60 #include <net_interface.h> 61 #include <socket_codes.h> 62 #include <socket_errno.h> 63 #include <socket_core.h> 64 #include <socket_messages.h> 65 #include <tl_common.h> 66 #include <tl_local.h> 67 #include <tl_interface.h> 68 #include <tl_messages.h> 71 69 72 70 #include "udp.h" 73 71 #include "udp_header.h" 74 72 #include "udp_module.h" 73 74 /** UDP module name. 75 */ 76 #define NAME "UDP protocol" 75 77 76 78 /** Default UDP checksum computing. … … 259 261 icmp_type_t type; 260 262 icmp_code_t code; 261 ip_pseudo_header_refip_header;263 void *ip_header; 262 264 struct sockaddr * src; 263 265 struct sockaddr * dest; … … 357 359 while(tmp_packet){ 358 360 next_packet = pq_detach(tmp_packet); 359 pq_release (udp_globals.net_phone, packet_get_id(tmp_packet));361 pq_release_remote(udp_globals.net_phone, packet_get_id(tmp_packet)); 360 362 tmp_packet = next_packet; 361 363 } … … 383 385 // queue the received packet 384 386 if(ERROR_OCCURRED(dyn_fifo_push(&socket->received, packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE)) 385 387 || ERROR_OCCURRED(tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, device_id, &packet_dimension))){ 386 388 return udp_release_and_return(packet, ERROR_CODE); 387 389 } … … 393 395 } 394 396 395 int udp_message (ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){397 int udp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 396 398 ERROR_DECLARE; 397 399 … … 401 403 switch(IPC_GET_METHOD(*call)){ 402 404 case NET_TL_RECEIVED: 403 if(! ERROR_OCCURRED(packet_translate (udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){405 if(! ERROR_OCCURRED(packet_translate_remote(udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){ 404 406 ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_UDP, IPC_GET_ERROR(call)); 405 407 } … … 419 421 int socket_id; 420 422 size_t addrlen; 423 size_t size; 421 424 ipc_call_t answer; 422 425 int answer_count; … … 454 457 socket_id = SOCKET_GET_SOCKET_ID(call); 455 458 res = socket_create(&local_sockets, app_phone, NULL, &socket_id); 456 *SOCKET_SET_SOCKET_ID(answer) = socket_id;457 459 SOCKET_SET_SOCKET_ID(answer, socket_id); 460 458 461 if(res == EOK){ 459 if (tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){460 *SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = packet_dimension->content;462 if (tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){ 463 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, packet_dimension->content); 461 464 } 462 // *SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = MAX_UDP_FRAGMENT_SIZE;463 *SOCKET_SET_HEADER_SIZE(answer) = UDP_HEADER_SIZE;465 // SOCKET_SET_DATA_FRAGMENT_SIZE(answer, MAX_UDP_FRAGMENT_SIZE); 466 SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE); 464 467 answer_count = 3; 465 468 } … … 478 481 if(res == EOK){ 479 482 fibril_rwlock_write_lock(&udp_globals.lock); 480 res = udp_sendto_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_SET_DATA_FRAGMENT_SIZE(answer), SOCKET_GET_FLAGS(call)); 483 res = udp_sendto_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS(call), &size, SOCKET_GET_FLAGS(call)); 484 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size); 481 485 if(res != EOK){ 482 486 fibril_rwlock_write_unlock(&udp_globals.lock); … … 492 496 fibril_rwlock_write_unlock(&udp_globals.lock); 493 497 if(res > 0){ 494 *SOCKET_SET_READ_DATA_LENGTH(answer) = res;495 *SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;498 SOCKET_SET_READ_DATA_LENGTH(answer, res); 499 SOCKET_SET_ADDRESS_LENGTH(answer, addrlen); 496 500 answer_count = 3; 497 501 res = EOK; … … 532 536 uint16_t dest_port; 533 537 uint32_t checksum; 534 ip_pseudo_header_refip_header;538 void *ip_header; 535 539 size_t headerlen; 536 540 device_id_t device_id; … … 661 665 return NO_DATA; 662 666 } 663 ERROR_PROPAGATE(packet_translate (udp_globals.net_phone, &packet, packet_id));667 ERROR_PROPAGATE(packet_translate_remote(udp_globals.net_phone, &packet, packet_id)); 664 668 // get udp header 665 669 data = packet_get_data(packet); 666 670 if(! data){ 667 pq_release (udp_globals.net_phone, packet_id);671 pq_release_remote(udp_globals.net_phone, packet_id); 668 672 return NO_DATA; 669 673 } … … 673 677 result = packet_get_addr(packet, (uint8_t **) &addr, NULL); 674 678 if(ERROR_OCCURRED(tl_set_address_port(addr, result, ntohs(header->source_port)))){ 675 pq_release (udp_globals.net_phone, packet_id);679 pq_release_remote(udp_globals.net_phone, packet_id); 676 680 return ERROR_CODE; 677 681 } … … 688 692 // release the packet 689 693 dyn_fifo_pop(&socket->received); 690 pq_release (udp_globals.net_phone, packet_get_id(packet));694 pq_release_remote(udp_globals.net_phone, packet_get_id(packet)); 691 695 // return the total length 692 696 return (int) length; … … 694 698 695 699 int udp_release_and_return(packet_t packet, int result){ 696 pq_release (udp_globals.net_phone, packet_get_id(packet));700 pq_release_remote(udp_globals.net_phone, packet_get_id(packet)); 697 701 return result; 698 702 } 699 703 704 /** Default thread for new connections. 705 * 706 * @param[in] iid The initial message identifier. 707 * @param[in] icall The initial message call structure. 708 * 709 */ 710 static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall) 711 { 712 /* 713 * Accept the connection 714 * - Answer the first IPC_M_CONNECT_ME_TO call. 715 */ 716 ipc_answer_0(iid, EOK); 717 718 while(true) { 719 ipc_call_t answer; 720 int answer_count; 721 722 /* Clear the answer structure */ 723 refresh_answer(&answer, &answer_count); 724 725 /* Fetch the next message */ 726 ipc_call_t call; 727 ipc_callid_t callid = async_get_call(&call); 728 729 /* Process the message */ 730 int res = tl_module_message_standalone(callid, &call, &answer, 731 &answer_count); 732 733 /* End if said to either by the message or the processing result */ 734 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)) 735 return; 736 737 /* Answer the message */ 738 answer_call(callid, res, &answer, answer_count); 739 } 740 } 741 742 /** Starts the module. 743 * 744 * @param argc The count of the command line arguments. Ignored parameter. 745 * @param argv The command line parameters. Ignored parameter. 746 * 747 * @returns EOK on success. 748 * @returns Other error codes as defined for each specific module start function. 749 * 750 */ 751 int main(int argc, char *argv[]) 752 { 753 ERROR_DECLARE; 754 755 /* Start the module */ 756 if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection))) 757 return ERROR_CODE; 758 759 return EOK; 760 } 761 700 762 /** @} 701 763 */
Note:
See TracChangeset
for help on using the changeset viewer.