Changes in uspace/srv/net/tl/udp/udp.c [6b82009:9934f7d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/udp/udp.c
r6b82009 r9934f7d 37 37 38 38 #include <async.h> 39 #include <async_obsolete.h> 39 40 #include <fibril_synch.h> 40 41 #include <malloc.h> … … 70 71 #include "udp_header.h" 71 72 73 // FIXME: remove this header 74 #include <kernel/ipc/ipc_methods.h> 75 72 76 /** UDP module name. */ 73 77 #define NAME "udp" … … 99 103 static int udp_release_and_return(packet_t *packet, int result) 100 104 { 101 pq_release_remote(udp_globals.net_ sess, packet_get_id(packet));105 pq_release_remote(udp_globals.net_phone, packet_get_id(packet)); 102 106 return result; 103 107 } … … 192 196 ntohs(header->destination_port), (uint8_t *) SOCKET_MAP_KEY_LISTENING, 0); 193 197 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,198 if (tl_prepare_icmp_packet(udp_globals.net_phone, 199 udp_globals.icmp_phone, packet, error) == EOK) { 200 icmp_destination_unreachable_msg(udp_globals.icmp_phone, 197 201 ICMP_PORT_UNREACH, 0, packet); 198 202 } … … 251 255 while (tmp_packet) { 252 256 next_packet = pq_detach(tmp_packet); 253 pq_release_remote(udp_globals.net_ sess,257 pq_release_remote(udp_globals.net_phone, 254 258 packet_get_id(tmp_packet)); 255 259 tmp_packet = next_packet; … … 274 278 if (flip_checksum(compact_checksum(checksum)) != 275 279 IP_CHECKSUM_ZERO) { 276 if (tl_prepare_icmp_packet(udp_globals.net_ sess,277 udp_globals.icmp_ sess, packet, error) == EOK) {280 if (tl_prepare_icmp_packet(udp_globals.net_phone, 281 udp_globals.icmp_phone, packet, error) == EOK) { 278 282 /* Checksum error ICMP */ 279 283 icmp_parameter_problem_msg( 280 udp_globals.icmp_ sess, ICMP_PARAM_POINTER,284 udp_globals.icmp_phone, ICMP_PARAM_POINTER, 281 285 ((size_t) ((void *) &header->checksum)) - 282 286 ((size_t) ((void *) header)), packet); … … 292 296 return udp_release_and_return(packet, rc); 293 297 294 rc = tl_get_ip_packet_dimension(udp_globals.ip_ sess,298 rc = tl_get_ip_packet_dimension(udp_globals.ip_phone, 295 299 &udp_globals.dimensions, device_id, &packet_dimension); 296 300 if (rc != EOK) … … 299 303 /* Notify the destination socket */ 300 304 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); 305 async_obsolete_msg_5(socket->phone, NET_SOCKET_RECEIVED, 306 (sysarg_t) socket->socket_id, packet_dimension->content, 0, 0, 307 (sysarg_t) fragments); 306 308 307 309 return EOK; … … 340 342 * @param[in,out] icall Message parameters. 341 343 * @param[in] arg Local argument. 342 *343 344 */ 344 345 static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) … … 350 351 switch (IPC_GET_IMETHOD(*icall)) { 351 352 case NET_TL_RECEIVED: 352 rc = packet_translate_remote(udp_globals.net_ sess, &packet,353 rc = packet_translate_remote(udp_globals.net_phone, &packet, 353 354 IPC_GET_PACKET(*icall)); 354 355 if (rc == EOK) … … 368 369 /** Initialize the UDP module. 369 370 * 370 * @param[in] sess Network module session.371 * @param[in] net_phone Network module phone. 371 372 * 372 373 * @return EOK on success. … … 374 375 * 375 376 */ 376 int tl_initialize( async_sess_t *sess)377 int tl_initialize(int net_phone) 377 378 { 378 379 measured_string_t names[] = { … … 393 394 fibril_rwlock_write_lock(&udp_globals.lock); 394 395 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; 396 udp_globals.net_phone = net_phone; 397 398 udp_globals.icmp_phone = icmp_connect_module(ICMP_CONNECT_TIMEOUT); 399 400 udp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_UDP, 401 SERVICE_UDP, udp_receiver); 402 if (udp_globals.ip_phone < 0) { 403 fibril_rwlock_write_unlock(&udp_globals.lock); 404 return udp_globals.ip_phone; 403 405 } 404 406 405 407 /* Read default packet dimensions */ 406 int rc = ip_packet_size_req(udp_globals.ip_ sess, -1,408 int rc = ip_packet_size_req(udp_globals.ip_phone, -1, 407 409 &udp_globals.packet_dimension); 408 410 if (rc != EOK) { … … 433 435 /* Get configuration */ 434 436 configuration = &names[0]; 435 rc = net_get_conf_req(udp_globals.net_ sess, &configuration, count,437 rc = net_get_conf_req(udp_globals.net_phone, &configuration, count, 436 438 &data); 437 439 if (rc != EOK) { … … 527 529 528 530 if (udp_globals.checksum_computing) { 529 rc = ip_get_route_req(udp_globals.ip_ sess, IPPROTO_UDP, addr,531 rc = ip_get_route_req(udp_globals.ip_phone, IPPROTO_UDP, addr, 530 532 addrlen, &device_id, &ip_header, &headerlen); 531 533 if (rc != EOK) 532 534 return rc; 533 535 /* Get the device packet dimension */ 534 // rc = tl_get_ip_packet_dimension(udp_globals.ip_ sess,536 // rc = tl_get_ip_packet_dimension(udp_globals.ip_phone, 535 537 // &udp_globals.dimensions, device_id, &packet_dimension); 536 538 // if (rc != EOK) … … 539 541 // } else { 540 542 /* Do not ask all the time */ 541 rc = ip_packet_size_req(udp_globals.ip_ sess, -1,543 rc = ip_packet_size_req(udp_globals.ip_phone, -1, 542 544 &udp_globals.packet_dimension); 543 545 if (rc != EOK) … … 557 559 558 560 /* Read the first packet fragment */ 559 result = tl_socket_read_packet_data(udp_globals.net_ sess, &packet,561 result = tl_socket_read_packet_data(udp_globals.net_phone, &packet, 560 562 UDP_HEADER_SIZE, packet_dimension, addr, addrlen); 561 563 if (result < 0) … … 578 580 /* Read the rest of the packet fragments */ 579 581 for (index = 1; index < fragments; index++) { 580 result = tl_socket_read_packet_data(udp_globals.net_ sess,582 result = tl_socket_read_packet_data(udp_globals.net_phone, 581 583 &next_packet, 0, packet_dimension, addr, addrlen); 582 584 if (result < 0) … … 630 632 631 633 /* Send the packet */ 632 ip_send_msg(udp_globals.ip_ sess, device_id, packet, SERVICE_UDP, 0);634 ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0); 633 635 634 636 return EOK; … … 677 679 return NO_DATA; 678 680 679 rc = packet_translate_remote(udp_globals.net_ sess, &packet, packet_id);681 rc = packet_translate_remote(udp_globals.net_phone, &packet, packet_id); 680 682 if (rc != EOK) { 681 683 (void) dyn_fifo_pop(&socket->received); … … 737 739 } 738 740 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) 741 /** Processes the socket client messages. 742 * 743 * Runs until the client module disconnects. 744 * 745 * @param[in] callid The message identifier. 746 * @param[in] call The message parameters. 747 * @return EOK on success. 748 * 749 * @see socket.h 750 */ 751 static int udp_process_client_messages(ipc_callid_t callid, ipc_call_t call) 754 752 { 755 753 int res; 756 754 socket_cores_t local_sockets; 755 int app_phone = IPC_GET_PHONE(call); 757 756 struct sockaddr *addr; 758 757 int socket_id; … … 787 786 /* Get the next call */ 788 787 callid = async_get_call(&call); 789 790 /* Process the call */ 788 791 789 if (!IPC_GET_IMETHOD(call)) { 792 790 res = EHANGUP; 793 791 break; 794 792 } 795 793 794 /* Process the call */ 796 795 switch (IPC_GET_IMETHOD(call)) { 797 796 case NET_SOCKET: 798 797 socket_id = SOCKET_GET_SOCKET_ID(call); 799 res = socket_create(&local_sockets, sess, NULL,798 res = socket_create(&local_sockets, app_phone, NULL, 800 799 &socket_id); 801 800 SOCKET_SET_SOCKET_ID(answer, socket_id); … … 805 804 806 805 size = MAX_UDP_FRAGMENT_SIZE; 807 if (tl_get_ip_packet_dimension(udp_globals.ip_ sess,806 if (tl_get_ip_packet_dimension(udp_globals.ip_phone, 808 807 &udp_globals.dimensions, DEVICE_INVALID_ID, 809 808 &packet_dimension) == EOK) { … … 869 868 case NET_SOCKET_CLOSE: 870 869 fibril_rwlock_write_lock(&udp_globals.lock); 871 res = socket_destroy(udp_globals.net_ sess,870 res = socket_destroy(udp_globals.net_phone, 872 871 SOCKET_GET_SOCKET_ID(call), &local_sockets, 873 872 &udp_globals.sockets, NULL); … … 883 882 } 884 883 885 /* Release the application session*/886 async_ hangup(sess);884 /* Release the application phone */ 885 async_obsolete_hangup(app_phone); 887 886 888 887 /* Release all local sockets */ 889 socket_cores_release(udp_globals.net_ sess, &local_sockets,888 socket_cores_release(udp_globals.net_phone, &local_sockets, 890 889 &udp_globals.sockets, NULL); 891 890 … … 917 916 { 918 917 *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 918 919 switch (IPC_GET_IMETHOD(*call)) { 920 case IPC_M_CONNECT_TO_ME: 921 return udp_process_client_messages(callid, *call); 922 } 923 925 924 return ENOTSUP; 926 925 }
Note:
See TracChangeset
for help on using the changeset viewer.