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