Changes in uspace/srv/net/tl/udp/udp.c [14f1db0:6092b56e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/udp/udp.c
r14f1db0 r6092b56e 40 40 #include <malloc.h> 41 41 #include <stdio.h> 42 42 43 #include <ipc/ipc.h> 43 44 #include <ipc/services.h> 44 45 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> 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" 69 71 70 72 #include "udp.h" 71 73 #include "udp_header.h" 72 74 #include "udp_module.h" 73 74 /** UDP module name.75 */76 #define NAME "UDP protocol"77 75 78 76 /** Default UDP checksum computing. … … 261 259 icmp_type_t type; 262 260 icmp_code_t code; 263 void *ip_header;261 ip_pseudo_header_ref ip_header; 264 262 struct sockaddr * src; 265 263 struct sockaddr * dest; … … 359 357 while(tmp_packet){ 360 358 next_packet = pq_detach(tmp_packet); 361 pq_release _remote(udp_globals.net_phone, packet_get_id(tmp_packet));359 pq_release(udp_globals.net_phone, packet_get_id(tmp_packet)); 362 360 tmp_packet = next_packet; 363 361 } … … 385 383 // queue the received packet 386 384 if(ERROR_OCCURRED(dyn_fifo_push(&socket->received, packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE)) 387 385 || ERROR_OCCURRED(tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, device_id, &packet_dimension))){ 388 386 return udp_release_and_return(packet, ERROR_CODE); 389 387 } … … 395 393 } 396 394 397 int udp_message _standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){395 int udp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 398 396 ERROR_DECLARE; 399 397 … … 403 401 switch(IPC_GET_METHOD(*call)){ 404 402 case NET_TL_RECEIVED: 405 if(! ERROR_OCCURRED(packet_translate _remote(udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){403 if(! ERROR_OCCURRED(packet_translate(udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){ 406 404 ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_UDP, IPC_GET_ERROR(call)); 407 405 } … … 421 419 int socket_id; 422 420 size_t addrlen; 423 size_t size;424 421 ipc_call_t answer; 425 422 int answer_count; … … 457 454 socket_id = SOCKET_GET_SOCKET_ID(call); 458 455 res = socket_create(&local_sockets, app_phone, NULL, &socket_id); 459 SOCKET_SET_SOCKET_ID(answer, socket_id);460 456 *SOCKET_SET_SOCKET_ID(answer) = socket_id; 457 461 458 if(res == EOK){ 462 if 463 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, packet_dimension->content);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; 464 461 } 465 // SOCKET_SET_DATA_FRAGMENT_SIZE(answer, MAX_UDP_FRAGMENT_SIZE);466 SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE);462 // *SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = MAX_UDP_FRAGMENT_SIZE; 463 *SOCKET_SET_HEADER_SIZE(answer) = UDP_HEADER_SIZE; 467 464 answer_count = 3; 468 465 } … … 481 478 if(res == EOK){ 482 479 fibril_rwlock_write_lock(&udp_globals.lock); 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); 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)); 485 481 if(res != EOK){ 486 482 fibril_rwlock_write_unlock(&udp_globals.lock); … … 496 492 fibril_rwlock_write_unlock(&udp_globals.lock); 497 493 if(res > 0){ 498 SOCKET_SET_READ_DATA_LENGTH(answer, res);499 SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);494 *SOCKET_SET_READ_DATA_LENGTH(answer) = res; 495 *SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen; 500 496 answer_count = 3; 501 497 res = EOK; … … 536 532 uint16_t dest_port; 537 533 uint32_t checksum; 538 void *ip_header;534 ip_pseudo_header_ref ip_header; 539 535 size_t headerlen; 540 536 device_id_t device_id; … … 665 661 return NO_DATA; 666 662 } 667 ERROR_PROPAGATE(packet_translate _remote(udp_globals.net_phone, &packet, packet_id));663 ERROR_PROPAGATE(packet_translate(udp_globals.net_phone, &packet, packet_id)); 668 664 // get udp header 669 665 data = packet_get_data(packet); 670 666 if(! data){ 671 pq_release _remote(udp_globals.net_phone, packet_id);667 pq_release(udp_globals.net_phone, packet_id); 672 668 return NO_DATA; 673 669 } … … 677 673 result = packet_get_addr(packet, (uint8_t **) &addr, NULL); 678 674 if(ERROR_OCCURRED(tl_set_address_port(addr, result, ntohs(header->source_port)))){ 679 pq_release _remote(udp_globals.net_phone, packet_id);675 pq_release(udp_globals.net_phone, packet_id); 680 676 return ERROR_CODE; 681 677 } … … 692 688 // release the packet 693 689 dyn_fifo_pop(&socket->received); 694 pq_release _remote(udp_globals.net_phone, packet_get_id(packet));690 pq_release(udp_globals.net_phone, packet_get_id(packet)); 695 691 // return the total length 696 692 return (int) length; … … 698 694 699 695 int udp_release_and_return(packet_t packet, int result){ 700 pq_release _remote(udp_globals.net_phone, packet_get_id(packet));696 pq_release(udp_globals.net_phone, packet_get_id(packet)); 701 697 return result; 702 698 } 703 699 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 connection714 * - 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 762 700 /** @} 763 701 */
Note:
See TracChangeset
for help on using the changeset viewer.