Changes in uspace/srv/net/tl/udp/udp.c [348c589:609243f4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/udp/udp.c
r348c589 r609243f4 99 99 static int udp_release_and_return(packet_t *packet, int result) 100 100 { 101 pq_release_remote(udp_globals.net_ phone, packet_get_id(packet));101 pq_release_remote(udp_globals.net_sess, packet_get_id(packet)); 102 102 return result; 103 103 } … … 124 124 * ip_client_process_packet() function. 125 125 */ 126 static int udp_process_packet( device_id_t device_id, packet_t *packet,126 static int udp_process_packet(nic_device_id_t device_id, packet_t *packet, 127 127 services_t error) 128 128 { … … 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_ phone,195 udp_globals.icmp_ phone, packet, error) == EOK) {196 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, 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_ phone,253 pq_release_remote(udp_globals.net_sess, 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_ phone,277 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) { 278 278 /* Checksum error ICMP */ 279 279 icmp_parameter_problem_msg( 280 udp_globals.icmp_ phone, ICMP_PARAM_POINTER,280 udp_globals.icmp_sess, 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_ phone,294 rc = tl_get_ip_packet_dimension(udp_globals.ip_sess, 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 async_msg_5(socket->phone, NET_SOCKET_RECEIVED, 302 (sysarg_t) socket->socket_id, packet_dimension->content, 0, 0, 303 (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); 304 306 305 307 return EOK; … … 320 322 * udp_process_packet() function. 321 323 */ 322 static int udp_received_msg( device_id_t device_id, packet_t *packet,324 static int udp_received_msg(nic_device_id_t device_id, packet_t *packet, 323 325 services_t receiver, services_t error) 324 326 { … … 337 339 * @param[in] iid Message identifier. 338 340 * @param[in,out] icall Message parameters. 339 * 340 */ 341 static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall) 341 * @param[in] arg Local argument. 342 * 343 */ 344 static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) 342 345 { 343 346 packet_t *packet; … … 347 350 switch (IPC_GET_IMETHOD(*icall)) { 348 351 case NET_TL_RECEIVED: 349 rc = packet_translate_remote(udp_globals.net_ phone, &packet,352 rc = packet_translate_remote(udp_globals.net_sess, &packet, 350 353 IPC_GET_PACKET(*icall)); 351 354 if (rc == EOK) … … 365 368 /** Initialize the UDP module. 366 369 * 367 * @param[in] net_phone Network module phone.370 * @param[in] sess Network module session. 368 371 * 369 372 * @return EOK on success. … … 371 374 * 372 375 */ 373 int tl_initialize( int net_phone)376 int tl_initialize(async_sess_t *sess) 374 377 { 375 378 measured_string_t names[] = { … … 390 393 fibril_rwlock_write_lock(&udp_globals.lock); 391 394 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; 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; 401 403 } 402 404 403 405 /* Read default packet dimensions */ 404 int rc = ip_packet_size_req(udp_globals.ip_ phone, -1,406 int rc = ip_packet_size_req(udp_globals.ip_sess, -1, 405 407 &udp_globals.packet_dimension); 406 408 if (rc != EOK) { … … 431 433 /* Get configuration */ 432 434 configuration = &names[0]; 433 rc = net_get_conf_req(udp_globals.net_ phone, &configuration, count,435 rc = net_get_conf_req(udp_globals.net_sess, &configuration, count, 434 436 &data); 435 437 if (rc != EOK) { … … 497 499 void *ip_header; 498 500 size_t headerlen; 499 device_id_t device_id;501 nic_device_id_t device_id; 500 502 packet_dimension_t *packet_dimension; 501 503 size_t size; … … 525 527 526 528 if (udp_globals.checksum_computing) { 527 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, 528 530 addrlen, &device_id, &ip_header, &headerlen); 529 531 if (rc != EOK) 530 532 return rc; 531 533 /* Get the device packet dimension */ 532 // rc = tl_get_ip_packet_dimension(udp_globals.ip_ phone,534 // rc = tl_get_ip_packet_dimension(udp_globals.ip_sess, 533 535 // &udp_globals.dimensions, device_id, &packet_dimension); 534 536 // if (rc != EOK) … … 537 539 // } else { 538 540 /* Do not ask all the time */ 539 rc = ip_packet_size_req(udp_globals.ip_ phone, -1,541 rc = ip_packet_size_req(udp_globals.ip_sess, -1, 540 542 &udp_globals.packet_dimension); 541 543 if (rc != EOK) … … 555 557 556 558 /* Read the first packet fragment */ 557 result = tl_socket_read_packet_data(udp_globals.net_ phone, &packet,559 result = tl_socket_read_packet_data(udp_globals.net_sess, &packet, 558 560 UDP_HEADER_SIZE, packet_dimension, addr, addrlen); 559 561 if (result < 0) … … 576 578 /* Read the rest of the packet fragments */ 577 579 for (index = 1; index < fragments; index++) { 578 result = tl_socket_read_packet_data(udp_globals.net_ phone,580 result = tl_socket_read_packet_data(udp_globals.net_sess, 579 581 &next_packet, 0, packet_dimension, addr, addrlen); 580 582 if (result < 0) … … 615 617 htons(flip_checksum(compact_checksum(checksum))); 616 618 free(ip_header); 617 } else { 618 device_id = DEVICE_INVALID_ID; 619 } 619 } else 620 device_id = NIC_DEVICE_INVALID_ID; 620 621 621 622 /* Prepare the first packet fragment */ … … 628 629 629 630 /* Send the packet */ 630 ip_send_msg(udp_globals.ip_ phone, device_id, packet, SERVICE_UDP, 0);631 ip_send_msg(udp_globals.ip_sess, device_id, packet, SERVICE_UDP, 0); 631 632 632 633 return EOK; … … 675 676 return NO_DATA; 676 677 677 rc = packet_translate_remote(udp_globals.net_ phone, &packet, packet_id);678 rc = packet_translate_remote(udp_globals.net_sess, &packet, packet_id); 678 679 if (rc != EOK) { 679 680 (void) dyn_fifo_pop(&socket->received); … … 735 736 } 736 737 737 /** Processes the socket client messages. 738 * 739 * Runs until the client module disconnects. 740 * 741 * @param[in] callid The message identifier. 742 * @param[in] call The message parameters. 743 * @return EOK on success. 744 * 745 * @see socket.h 746 */ 747 static int udp_process_client_messages(ipc_callid_t callid, ipc_call_t call) 738 /** Process the socket client messages. 739 * 740 * Run until the client module disconnects. 741 * 742 * @see socket.h 743 * 744 * @param[in] sess Callback session. 745 * @param[in] callid Message identifier. 746 * @param[in] call Message parameters. 747 * 748 * @return EOK on success. 749 * 750 */ 751 static int udp_process_client_messages(async_sess_t *sess, ipc_callid_t callid, 752 ipc_call_t call) 748 753 { 749 754 int res; 750 bool keep_on_going = true;751 755 socket_cores_t local_sockets; 752 int app_phone = IPC_GET_PHONE(call);753 756 struct sockaddr *addr; 754 757 int socket_id; … … 773 776 socket_cores_initialize(&local_sockets); 774 777 775 while ( keep_on_going) {778 while (true) { 776 779 777 780 /* Answer the call */ … … 785 788 786 789 /* Process the call */ 787 switch (IPC_GET_IMETHOD(call)) { 788 case IPC_M_PHONE_HUNGUP: 789 keep_on_going = false; 790 if (!IPC_GET_IMETHOD(call)) { 790 791 res = EHANGUP; 791 792 break; 792 793 } 794 795 switch (IPC_GET_IMETHOD(call)) { 793 796 case NET_SOCKET: 794 797 socket_id = SOCKET_GET_SOCKET_ID(call); 795 res = socket_create(&local_sockets, app_phone, NULL,798 res = socket_create(&local_sockets, sess, NULL, 796 799 &socket_id); 797 800 SOCKET_SET_SOCKET_ID(answer, socket_id); … … 801 804 802 805 size = MAX_UDP_FRAGMENT_SIZE; 803 if (tl_get_ip_packet_dimension(udp_globals.ip_ phone,804 &udp_globals.dimensions, DEVICE_INVALID_ID,806 if (tl_get_ip_packet_dimension(udp_globals.ip_sess, 807 &udp_globals.dimensions, NIC_DEVICE_INVALID_ID, 805 808 &packet_dimension) == EOK) { 806 809 if (packet_dimension->content < size) … … 865 868 case NET_SOCKET_CLOSE: 866 869 fibril_rwlock_write_lock(&udp_globals.lock); 867 res = socket_destroy(udp_globals.net_ phone,870 res = socket_destroy(udp_globals.net_sess, 868 871 SOCKET_GET_SOCKET_ID(call), &local_sockets, 869 872 &udp_globals.sockets, NULL); … … 879 882 } 880 883 881 /* Release the application phone*/882 async_hangup( app_phone);884 /* Release the application session */ 885 async_hangup(sess); 883 886 884 887 /* Release all local sockets */ 885 socket_cores_release(udp_globals.net_ phone, &local_sockets,888 socket_cores_release(udp_globals.net_sess, &local_sockets, 886 889 &udp_globals.sockets, NULL); 887 890 … … 913 916 { 914 917 *answer_count = 0; 915 916 switch (IPC_GET_IMETHOD(*call)) {917 case IPC_M_CONNECT_TO_ME:918 return udp_process_client_messages(callid, *call);919 }920 918 919 async_sess_t *callback = 920 async_callback_receive_start(EXCHANGE_SERIALIZE, call); 921 if (callback) 922 return udp_process_client_messages(callback, callid, *call); 923 921 924 return ENOTSUP; 922 925 }
Note:
See TracChangeset
for help on using the changeset viewer.