Changeset 6b82009 in mainline for uspace/srv/net/tl
- Timestamp:
- 2011-06-22T20:41:41Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ef09a7a
- Parents:
- 55091847
- Location:
- uspace/srv/net/tl
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/icmp/icmp.c
r55091847 r6b82009 118 118 119 119 /** Global data */ 120 static int phone_net = -1;121 static int phone_ip = -1;120 static async_sess_t *net_sess = NULL; 121 static async_sess_t *ip_sess = NULL; 122 122 static bool error_reporting = true; 123 123 static bool echo_replying = true; … … 173 173 static void icmp_release(packet_t *packet) 174 174 { 175 pq_release_remote( phone_net, packet_get_id(packet));175 pq_release_remote(net_sess, packet_get_id(packet)); 176 176 } 177 177 … … 225 225 } 226 226 227 return ip_send_msg( phone_ip, -1, packet, SERVICE_ICMP, error);227 return ip_send_msg(ip_sess, -1, packet, SERVICE_ICMP, error); 228 228 } 229 229 … … 297 297 size_t length = (size_t) addrlen; 298 298 299 packet_t *packet = packet_get_4_remote( phone_net, size,299 packet_t *packet = packet_get_4_remote(net_sess, size, 300 300 icmp_dimension.addr_len, ICMP_HEADER_SIZE + icmp_dimension.prefix, 301 301 icmp_dimension.suffix); … … 595 595 case ICMP_SKIP: 596 596 case ICMP_PHOTURIS: 597 ip_received_error_msg( phone_ip, -1, packet,597 ip_received_error_msg(ip_sess, -1, packet, 598 598 SERVICE_IP, SERVICE_ICMP); 599 599 return EOK; … … 609 609 * @param[in,out] icall Message parameters. 610 610 * @param[in] arg Local argument. 611 * 611 612 */ 612 613 static void icmp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) … … 621 622 switch (IPC_GET_IMETHOD(*icall)) { 622 623 case NET_TL_RECEIVED: 623 rc = packet_translate_remote( phone_net, &packet,624 rc = packet_translate_remote(net_sess, &packet, 624 625 IPC_GET_PACKET(*icall)); 625 626 if (rc == EOK) { … … 641 642 /** Initialize the ICMP module. 642 643 * 643 * @param[in] net_phone Network module phone.644 * @param[in] sess Network module session. 644 645 * 645 646 * @return EOK on success. … … 647 648 * 648 649 */ 649 int tl_initialize( int net_phone)650 int tl_initialize(async_sess_t *sess) 650 651 { 651 652 measured_string_t names[] = { … … 669 670 atomic_set(&icmp_client, 0); 670 671 671 phone_net = net_phone;672 phone_ip= ip_bind_service(SERVICE_IP, IPPROTO_ICMP, SERVICE_ICMP,672 net_sess = sess; 673 ip_sess = ip_bind_service(SERVICE_IP, IPPROTO_ICMP, SERVICE_ICMP, 673 674 icmp_receiver); 674 if ( phone_ip < 0)675 return phone_ip;676 677 int rc = ip_packet_size_req( phone_ip, -1, &icmp_dimension);675 if (ip_sess == NULL) 676 return ENOENT; 677 678 int rc = ip_packet_size_req(ip_sess, -1, &icmp_dimension); 678 679 if (rc != EOK) 679 680 return rc; … … 684 685 /* Get configuration */ 685 686 configuration = &names[0]; 686 rc = net_get_conf_req( phone_net, &configuration, count, &data);687 rc = net_get_conf_req(net_sess, &configuration, count, &data); 687 688 if (rc != EOK) 688 689 return rc; … … 762 763 763 764 case NET_ICMP_DEST_UNREACH: 764 rc = packet_translate_remote( phone_net, &packet,765 rc = packet_translate_remote(net_sess, &packet, 765 766 IPC_GET_PACKET(*call)); 766 767 if (rc != EOK) … … 771 772 772 773 case NET_ICMP_SOURCE_QUENCH: 773 rc = packet_translate_remote( phone_net, &packet,774 rc = packet_translate_remote(net_sess, &packet, 774 775 IPC_GET_PACKET(*call)); 775 776 if (rc != EOK) … … 779 780 780 781 case NET_ICMP_TIME_EXCEEDED: 781 rc = packet_translate_remote( phone_net, &packet,782 rc = packet_translate_remote(net_sess, &packet, 782 783 IPC_GET_PACKET(*call)); 783 784 if (rc != EOK) … … 787 788 788 789 case NET_ICMP_PARAMETERPROB: 789 rc = packet_translate_remote( phone_net, &packet,790 rc = packet_translate_remote(net_sess, &packet, 790 791 IPC_GET_PACKET(*call)); 791 792 if (rc != EOK) -
uspace/srv/net/tl/tcp/tcp.c
r55091847 r6b82009 38 38 #include <assert.h> 39 39 #include <async.h> 40 #include <async_obsolete.h>41 40 #include <fibril_synch.h> 42 41 #include <malloc.h> … … 74 73 #include "tcp_header.h" 75 74 76 // FIXME: remove this header77 #include <kernel/ipc/ipc_methods.h>78 79 75 /** TCP module name. */ 80 76 #define NAME "tcp" … … 210 206 211 207 static int tcp_received_msg(device_id_t, packet_t *, services_t, services_t); 212 static int tcp_process_client_messages(ipc_callid_t, ipc_call_t); 208 static int tcp_process_client_messages(async_sess_t *, ipc_callid_t, 209 ipc_call_t); 213 210 214 211 static int tcp_listen_message(socket_cores_t *, int, int); … … 328 325 329 326 if (!socket) { 330 if (tl_prepare_icmp_packet(tcp_globals.net_ phone,331 tcp_globals.icmp_ phone, packet, error) == EOK) {332 icmp_destination_unreachable_msg(tcp_globals.icmp_ phone,327 if (tl_prepare_icmp_packet(tcp_globals.net_sess, 328 tcp_globals.icmp_sess, packet, error) == EOK) { 329 icmp_destination_unreachable_msg(tcp_globals.icmp_sess, 333 330 ICMP_PORT_UNREACH, 0, packet); 334 331 } … … 401 398 fibril_rwlock_write_unlock(socket_data->local_lock); 402 399 403 rc = tl_prepare_icmp_packet(tcp_globals.net_ phone,404 tcp_globals.icmp_ phone, packet, error);400 rc = tl_prepare_icmp_packet(tcp_globals.net_sess, 401 tcp_globals.icmp_sess, packet, error); 405 402 if (rc == EOK) { 406 403 /* Checksum error ICMP */ 407 icmp_parameter_problem_msg(tcp_globals.icmp_ phone,404 icmp_parameter_problem_msg(tcp_globals.icmp_sess, 408 405 ICMP_PARAM_POINTER, 409 406 ((size_t) ((void *) &header->checksum)) - … … 443 440 break; 444 441 default: 445 pq_release_remote(tcp_globals.net_ phone, packet_get_id(packet));442 pq_release_remote(tcp_globals.net_sess, packet_get_id(packet)); 446 443 } 447 444 … … 506 503 /* Release the acknowledged packets */ 507 504 next_packet = pq_next(packet); 508 pq_release_remote(tcp_globals.net_ phone,505 pq_release_remote(tcp_globals.net_sess, 509 506 packet_get_id(packet)); 510 507 packet = next_packet; … … 565 562 next_packet = pq_next(next_packet); 566 563 pq_insert_after(tmp_packet, next_packet); 567 pq_release_remote(tcp_globals.net_ phone,564 pq_release_remote(tcp_globals.net_sess, 568 565 packet_get_id(tmp_packet)); 569 566 } … … 602 599 if (packet == socket_data->incoming) 603 600 socket_data->incoming = next_packet; 604 pq_release_remote(tcp_globals.net_ phone,601 pq_release_remote(tcp_globals.net_sess, 605 602 packet_get_id(packet)); 606 603 packet = next_packet; … … 625 622 if (length <= 0) { 626 623 /* Remove the empty packet */ 627 pq_release_remote(tcp_globals.net_ phone,624 pq_release_remote(tcp_globals.net_sess, 628 625 packet_get_id(packet)); 629 626 packet = next_packet; … … 672 669 } 673 670 /* Remove the duplicit or corrupted packet */ 674 pq_release_remote(tcp_globals.net_ phone,671 pq_release_remote(tcp_globals.net_sess, 675 672 packet_get_id(packet)); 676 673 packet = next_packet; … … 699 696 if (rc != EOK) { 700 697 /* Remove the corrupted packets */ 701 pq_release_remote(tcp_globals.net_ phone,698 pq_release_remote(tcp_globals.net_sess, 702 699 packet_get_id(packet)); 703 pq_release_remote(tcp_globals.net_ phone,700 pq_release_remote(tcp_globals.net_sess, 704 701 packet_get_id(next_packet)); 705 702 } else { … … 712 709 new_sequence_number, length); 713 710 if (rc != EOK) { 714 pq_release_remote(tcp_globals.net_ phone,711 pq_release_remote(tcp_globals.net_sess, 715 712 packet_get_id(next_packet)); 716 713 } 717 714 rc = pq_insert_after(packet, next_packet); 718 715 if (rc != EOK) { 719 pq_release_remote(tcp_globals.net_ phone,716 pq_release_remote(tcp_globals.net_sess, 720 717 packet_get_id(next_packet)); 721 718 } … … 726 723 printf("unexpected\n"); 727 724 /* Release duplicite or restricted */ 728 pq_release_remote(tcp_globals.net_ phone, packet_get_id(packet));725 pq_release_remote(tcp_globals.net_sess, packet_get_id(packet)); 729 726 forced_ack = true; 730 727 } … … 794 791 if (rc != EOK) 795 792 return tcp_release_and_return(packet, rc); 796 rc = tl_get_ip_packet_dimension(tcp_globals.ip_ phone,793 rc = tl_get_ip_packet_dimension(tcp_globals.ip_sess, 797 794 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 798 795 if (rc != EOK) … … 803 800 804 801 /* Notify the destination socket */ 805 async_ obsolete_msg_5(socket->phone, NET_SOCKET_RECEIVED,806 802 async_exch_t *exch = async_exchange_begin(socket->sess); 803 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) socket->socket_id, 807 804 ((packet_dimension->content < socket_data->data_fragment_size) ? 808 805 packet_dimension->content : socket_data->data_fragment_size), 0, 0, 809 806 (sysarg_t) fragments); 807 async_exchange_end(exch); 810 808 811 809 return EOK; … … 824 822 825 823 /* Notify the destination socket */ 826 async_ obsolete_msg_5(socket->phone, NET_SOCKET_RECEIVED,827 828 0, 0, 0, 829 (sysarg_t) 0 /* 0 fragments == no more data */);824 async_exch_t *exch = async_exchange_begin(socket->sess); 825 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) socket->socket_id, 826 0, 0, 0, (sysarg_t) 0 /* 0 fragments == no more data */); 827 async_exchange_end(exch); 830 828 } 831 829 … … 853 851 next_packet = pq_detach(packet); 854 852 if (next_packet) { 855 pq_release_remote(tcp_globals.net_ phone,853 pq_release_remote(tcp_globals.net_sess, 856 854 packet_get_id(next_packet)); 857 855 } … … 940 938 /* Create a socket */ 941 939 socket_id = -1; 942 rc = socket_create(socket_data->local_sockets, listening_socket-> phone,940 rc = socket_create(socket_data->local_sockets, listening_socket->sess, 943 941 socket_data, &socket_id); 944 942 if (rc != EOK) { … … 993 991 fibril_rwlock_write_unlock(&tcp_globals.lock); 994 992 if (rc != EOK) { 995 socket_destroy(tcp_globals.net_ phone, socket->socket_id,993 socket_destroy(tcp_globals.net_sess, socket->socket_id, 996 994 socket_data->local_sockets, &tcp_globals.sockets, 997 995 tcp_free_socket_data); … … 1005 1003 next_packet = pq_detach(packet); 1006 1004 if (next_packet) { 1007 pq_release_remote(tcp_globals.net_ phone,1005 pq_release_remote(tcp_globals.net_sess, 1008 1006 packet_get_id(next_packet)); 1009 1007 } … … 1014 1012 packet_get_data_length(packet) - sizeof(*header)); 1015 1013 if (rc != EOK) { 1016 socket_destroy(tcp_globals.net_ phone, socket->socket_id,1014 socket_destroy(tcp_globals.net_sess, socket->socket_id, 1017 1015 socket_data->local_sockets, &tcp_globals.sockets, 1018 1016 tcp_free_socket_data); … … 1025 1023 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1026 1024 if (rc != EOK) { 1027 socket_destroy(tcp_globals.net_ phone, socket->socket_id,1025 socket_destroy(tcp_globals.net_sess, socket->socket_id, 1028 1026 socket_data->local_sockets, &tcp_globals.sockets, 1029 1027 tcp_free_socket_data); … … 1033 1031 packet = tcp_get_packets_to_send(socket, socket_data); 1034 1032 if (!packet) { 1035 socket_destroy(tcp_globals.net_ phone, socket->socket_id,1033 socket_destroy(tcp_globals.net_sess, socket->socket_id, 1036 1034 socket_data->local_sockets, &tcp_globals.sockets, 1037 1035 tcp_free_socket_data); … … 1068 1066 1069 1067 socket_data->next_incoming = ntohl(header->sequence_number); /* + 1; */ 1070 pq_release_remote(tcp_globals.net_ phone, packet_get_id(packet));1068 pq_release_remote(tcp_globals.net_sess, packet_get_id(packet)); 1071 1069 socket_data->state = TCP_SOCKET_ESTABLISHED; 1072 1070 listening_socket = socket_cores_find(socket_data->local_sockets, … … 1082 1080 if (rc == EOK) { 1083 1081 /* Notify the destination socket */ 1084 async_obsolete_msg_5(socket->phone, NET_SOCKET_ACCEPTED, 1082 async_exch_t *exch = async_exchange_begin(socket->sess); 1083 async_msg_5(exch, NET_SOCKET_ACCEPTED, 1085 1084 (sysarg_t) listening_socket->socket_id, 1086 1085 socket_data->data_fragment_size, TCP_HEADER_SIZE, 1087 1086 0, (sysarg_t) socket->socket_id); 1087 async_exchange_end(exch); 1088 1088 1089 1089 fibril_rwlock_write_unlock(socket_data->local_lock); … … 1181 1181 /* Add to acknowledged or release */ 1182 1182 if (pq_add(&acknowledged, packet, 0, 0) != EOK) 1183 pq_release_remote(tcp_globals.net_ phone,1183 pq_release_remote(tcp_globals.net_sess, 1184 1184 packet_get_id(packet)); 1185 1185 packet = next; … … 1190 1190 /* Release acknowledged */ 1191 1191 if (acknowledged) { 1192 pq_release_remote(tcp_globals.net_ phone,1192 pq_release_remote(tcp_globals.net_sess, 1193 1193 packet_get_id(acknowledged)); 1194 1194 } … … 1234 1234 assert(answer); 1235 1235 assert(answer_count); 1236 1236 1237 1237 *answer_count = 0; 1238 switch (IPC_GET_IMETHOD(*call)) { 1239 case IPC_M_CONNECT_TO_ME: 1240 return tcp_process_client_messages(callid, *call); 1241 } 1242 1238 1239 async_sess_t *callback = 1240 async_callback_receive_start(EXCHANGE_SERIALIZE, call); 1241 if (callback) 1242 return tcp_process_client_messages(callback, callid, *call); 1243 1243 1244 return ENOTSUP; 1244 1245 } … … 1270 1271 } 1271 1272 1272 int tcp_process_client_messages(ipc_callid_t callid, ipc_call_t call) 1273 int tcp_process_client_messages(async_sess_t *sess, ipc_callid_t callid, 1274 ipc_call_t call) 1273 1275 { 1274 1276 int res; 1275 1277 socket_cores_t local_sockets; 1276 int app_phone = IPC_GET_PHONE(call);1277 1278 struct sockaddr *addr; 1278 1279 int socket_id; … … 1325 1326 fibril_rwlock_write_lock(&lock); 1326 1327 socket_id = SOCKET_GET_SOCKET_ID(call); 1327 res = socket_create(&local_sockets, app_phone,1328 res = socket_create(&local_sockets, sess, 1328 1329 socket_data, &socket_id); 1329 1330 SOCKET_SET_SOCKET_ID(answer, socket_id); … … 1333 1334 break; 1334 1335 } 1335 if (tl_get_ip_packet_dimension(tcp_globals.ip_ phone,1336 if (tl_get_ip_packet_dimension(tcp_globals.ip_sess, 1336 1337 &tcp_globals.dimensions, DEVICE_INVALID_ID, 1337 1338 &packet_dimension) == EOK) { … … 1508 1509 } 1509 1510 1510 /* Release the application phone*/1511 async_ obsolete_hangup(app_phone);1511 /* Release the application session */ 1512 async_hangup(sess); 1512 1513 1513 1514 printf("release\n"); 1514 1515 /* Release all local sockets */ 1515 socket_cores_release(tcp_globals.net_ phone, &local_sockets,1516 socket_cores_release(tcp_globals.net_sess, &local_sockets, 1516 1517 &tcp_globals.sockets, tcp_free_socket_data); 1517 1518 … … 1621 1622 local_lock = socket_data->local_lock; 1622 1623 fibril_rwlock_write_lock(local_lock); 1623 socket_destroy(tcp_globals.net_ phone,1624 socket_destroy(tcp_globals.net_sess, 1624 1625 timeout->socket_id, timeout->local_sockets, 1625 1626 &tcp_globals.sockets, tcp_free_socket_data); … … 1754 1755 } 1755 1756 1756 rc = ip_get_route_req(tcp_globals.ip_ phone, IPPROTO_TCP,1757 rc = ip_get_route_req(tcp_globals.ip_sess, IPPROTO_TCP, 1757 1758 addr, addrlen, &socket_data->device_id, 1758 1759 &socket_data->pseudo_header, &socket_data->headerlen); … … 1902 1903 rc = pq_insert_after(previous, copy); 1903 1904 if (rc != EOK) { 1904 pq_release_remote(tcp_globals.net_ phone,1905 pq_release_remote(tcp_globals.net_sess, 1905 1906 packet_get_id(copy)); 1906 1907 return sending; … … 1939 1940 socket_data->headerlen, packet_get_data_length(packet)); 1940 1941 if (rc != EOK) { 1941 pq_release_remote(tcp_globals.net_ phone, packet_get_id(packet));1942 pq_release_remote(tcp_globals.net_sess, packet_get_id(packet)); 1942 1943 return NULL; 1943 1944 } … … 1946 1947 header = (tcp_header_t *) packet_get_data(packet); 1947 1948 if (!header) { 1948 pq_release_remote(tcp_globals.net_ phone, packet_get_id(packet));1949 pq_release_remote(tcp_globals.net_sess, packet_get_id(packet)); 1949 1950 return NULL; 1950 1951 } … … 1971 1972 rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0); 1972 1973 if (rc != EOK) { 1973 pq_release_remote(tcp_globals.net_ phone, packet_get_id(packet));1974 pq_release_remote(tcp_globals.net_sess, packet_get_id(packet)); 1974 1975 return NULL; 1975 1976 } … … 1978 1979 sequence_number, socket_data->state, socket_data->timeout, true); 1979 1980 if (rc != EOK) { 1980 pq_release_remote(tcp_globals.net_ phone, packet_get_id(packet));1981 pq_release_remote(tcp_globals.net_sess, packet_get_id(packet)); 1981 1982 return NULL; 1982 1983 } … … 1995 1996 1996 1997 /* Make a copy of the packet */ 1997 copy = packet_get_copy(tcp_globals.net_ phone, packet);1998 copy = packet_get_copy(tcp_globals.net_sess, packet); 1998 1999 if (!copy) 1999 2000 return NULL; … … 2009 2010 while (packet) { 2010 2011 next = pq_detach(packet); 2011 ip_send_msg(tcp_globals.ip_ phone, device_id, packet,2012 ip_send_msg(tcp_globals.ip_sess, device_id, packet, 2012 2013 SERVICE_TCP, 0); 2013 2014 packet = next; … … 2122 2123 return NO_DATA; 2123 2124 2124 rc = packet_translate_remote(tcp_globals.net_ phone, &packet, packet_id);2125 rc = packet_translate_remote(tcp_globals.net_sess, &packet, packet_id); 2125 2126 if (rc != EOK) 2126 2127 return rc; … … 2133 2134 /* Release the packet */ 2134 2135 dyn_fifo_pop(&socket->received); 2135 pq_release_remote(tcp_globals.net_ phone, packet_get_id(packet));2136 pq_release_remote(tcp_globals.net_sess, packet_get_id(packet)); 2136 2137 2137 2138 /* Return the total length */ … … 2171 2172 return ENOTCONN; 2172 2173 2173 rc = tl_get_ip_packet_dimension(tcp_globals.ip_ phone,2174 rc = tl_get_ip_packet_dimension(tcp_globals.ip_sess, 2174 2175 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2175 2176 if (rc != EOK) … … 2182 2183 for (index = 0; index < fragments; index++) { 2183 2184 /* Read the data fragment */ 2184 result = tl_socket_read_packet_data(tcp_globals.net_ phone,2185 result = tl_socket_read_packet_data(tcp_globals.net_sess, 2185 2186 &packet, TCP_HEADER_SIZE, packet_dimension, 2186 2187 socket_data->addr, socket_data->addrlen); … … 2245 2246 default: 2246 2247 /* Just destroy */ 2247 rc = socket_destroy(tcp_globals.net_ phone, socket_id,2248 rc = socket_destroy(tcp_globals.net_sess, socket_id, 2248 2249 local_sockets, &tcp_globals.sockets, 2249 2250 tcp_free_socket_data); … … 2293 2294 2294 2295 /* Get the device packet dimension */ 2295 rc = tl_get_ip_packet_dimension(tcp_globals.ip_ phone,2296 rc = tl_get_ip_packet_dimension(tcp_globals.ip_sess, 2296 2297 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2297 2298 if (rc != EOK) … … 2299 2300 2300 2301 /* Get a new packet */ 2301 *packet = packet_get_4_remote(tcp_globals.net_ phone, TCP_HEADER_SIZE,2302 *packet = packet_get_4_remote(tcp_globals.net_sess, TCP_HEADER_SIZE, 2302 2303 packet_dimension->addr_len, packet_dimension->prefix, 2303 2304 packet_dimension->suffix); … … 2362 2363 if (rc != EOK) 2363 2364 return rc; 2364 rc = tl_get_ip_packet_dimension(tcp_globals.ip_ phone,2365 rc = tl_get_ip_packet_dimension(tcp_globals.ip_sess, 2365 2366 &tcp_globals.dimensions, socket_data->device_id, 2366 2367 &packet_dimension); … … 2434 2435 int tcp_release_and_return(packet_t *packet, int result) 2435 2436 { 2436 pq_release_remote(tcp_globals.net_ phone, packet_get_id(packet));2437 pq_release_remote(tcp_globals.net_sess, packet_get_id(packet)); 2437 2438 return result; 2438 2439 } … … 2443 2444 * @param[in,out] icall Message parameters. 2444 2445 * @param[in] arg Local argument. 2446 * 2445 2447 */ 2446 2448 static void tcp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) … … 2452 2454 switch (IPC_GET_IMETHOD(*icall)) { 2453 2455 case NET_TL_RECEIVED: 2454 rc = packet_translate_remote(tcp_globals.net_ phone, &packet,2456 rc = packet_translate_remote(tcp_globals.net_sess, &packet, 2455 2457 IPC_GET_PACKET(*icall)); 2456 2458 if (rc == EOK) … … 2470 2472 /** Initialize the TCP module. 2471 2473 * 2472 * @param[in] net_phone Network module phone.2474 * @param[in] sess Network module session. 2473 2475 * 2474 2476 * @return EOK on success. … … 2476 2478 * 2477 2479 */ 2478 int tl_initialize( int net_phone)2480 int tl_initialize(async_sess_t *sess) 2479 2481 { 2480 2482 fibril_rwlock_initialize(&tcp_globals.lock); 2481 2483 fibril_rwlock_write_lock(&tcp_globals.lock); 2482 2484 2483 tcp_globals.net_ phone = net_phone;2485 tcp_globals.net_sess = sess; 2484 2486 2485 tcp_globals.icmp_ phone= icmp_connect_module();2486 tcp_globals.ip_ phone= ip_bind_service(SERVICE_IP, IPPROTO_TCP,2487 tcp_globals.icmp_sess = icmp_connect_module(); 2488 tcp_globals.ip_sess = ip_bind_service(SERVICE_IP, IPPROTO_TCP, 2487 2489 SERVICE_TCP, tcp_receiver); 2488 if (tcp_globals.ip_ phone < 0) {2490 if (tcp_globals.ip_sess == NULL) { 2489 2491 fibril_rwlock_write_unlock(&tcp_globals.lock); 2490 return tcp_globals.ip_phone;2492 return ENOENT; 2491 2493 } 2492 2494 -
uspace/srv/net/tl/tcp/tcp.h
r55091847 r6b82009 38 38 #define NET_TCP_H_ 39 39 40 #include <async.h> 40 41 #include <fibril_synch.h> 41 42 42 #include <net/packet.h> 43 43 #include <net/device.h> … … 284 284 /** TCP global data. */ 285 285 struct tcp_globals { 286 /** Networking module phone. */287 int net_phone;288 /** IP module phone. */289 int ip_phone;290 /** ICMP module phone. */291 int icmp_phone;286 /** Networking module session. */ 287 async_sess_t *net_sess; 288 /** IP module session. */ 289 async_sess_t *ip_sess; 290 /** ICMP module session. */ 291 async_sess_t *icmp_sess; 292 292 /** Last used free port. */ 293 293 int last_used_port; -
uspace/srv/net/tl/udp/udp.c
r55091847 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(); 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 } -
uspace/srv/net/tl/udp/udp.h
r55091847 r6b82009 38 38 #define NET_UDP_H_ 39 39 40 #include <async.h> 40 41 #include <fibril_synch.h> 41 42 #include <socket_core.h> … … 49 50 /** UDP global data. */ 50 51 struct udp_globals { 51 /** Networking module phone. */52 int net_phone;53 /** IP module phone. */54 int ip_phone;55 /** ICMP module phone. */56 int icmp_phone;52 /** Networking module session. */ 53 async_sess_t *net_sess; 54 /** IP module session. */ 55 async_sess_t *ip_sess; 56 /** ICMP module session. */ 57 async_sess_t *icmp_sess; 57 58 /** Packet dimension. */ 58 59 packet_dimension_t packet_dimension;
Note:
See TracChangeset
for help on using the changeset viewer.