Changes in uspace/srv/net/tl/tcp/tcp.c [9934f7d:6b82009] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/tcp.c
r9934f7d 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(ICMP_CONNECT_TIMEOUT);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
Note:
See TracChangeset
for help on using the changeset viewer.