Changes in uspace/srv/net/tl/tcp/tcp.c [6b82009:9934f7d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/tcp.c
r6b82009 r9934f7d 38 38 #include <assert.h> 39 39 #include <async.h> 40 #include <async_obsolete.h> 40 41 #include <fibril_synch.h> 41 42 #include <malloc.h> … … 73 74 #include "tcp_header.h" 74 75 76 // FIXME: remove this header 77 #include <kernel/ipc/ipc_methods.h> 78 75 79 /** TCP module name. */ 76 80 #define NAME "tcp" … … 206 210 207 211 static int tcp_received_msg(device_id_t, packet_t *, services_t, services_t); 208 static int tcp_process_client_messages(async_sess_t *, ipc_callid_t, 209 ipc_call_t); 212 static int tcp_process_client_messages(ipc_callid_t, ipc_call_t); 210 213 211 214 static int tcp_listen_message(socket_cores_t *, int, int); … … 325 328 326 329 if (!socket) { 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,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, 330 333 ICMP_PORT_UNREACH, 0, packet); 331 334 } … … 398 401 fibril_rwlock_write_unlock(socket_data->local_lock); 399 402 400 rc = tl_prepare_icmp_packet(tcp_globals.net_ sess,401 tcp_globals.icmp_ sess, packet, error);403 rc = tl_prepare_icmp_packet(tcp_globals.net_phone, 404 tcp_globals.icmp_phone, packet, error); 402 405 if (rc == EOK) { 403 406 /* Checksum error ICMP */ 404 icmp_parameter_problem_msg(tcp_globals.icmp_ sess,407 icmp_parameter_problem_msg(tcp_globals.icmp_phone, 405 408 ICMP_PARAM_POINTER, 406 409 ((size_t) ((void *) &header->checksum)) - … … 440 443 break; 441 444 default: 442 pq_release_remote(tcp_globals.net_ sess, packet_get_id(packet));445 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 443 446 } 444 447 … … 503 506 /* Release the acknowledged packets */ 504 507 next_packet = pq_next(packet); 505 pq_release_remote(tcp_globals.net_ sess,508 pq_release_remote(tcp_globals.net_phone, 506 509 packet_get_id(packet)); 507 510 packet = next_packet; … … 562 565 next_packet = pq_next(next_packet); 563 566 pq_insert_after(tmp_packet, next_packet); 564 pq_release_remote(tcp_globals.net_ sess,567 pq_release_remote(tcp_globals.net_phone, 565 568 packet_get_id(tmp_packet)); 566 569 } … … 599 602 if (packet == socket_data->incoming) 600 603 socket_data->incoming = next_packet; 601 pq_release_remote(tcp_globals.net_ sess,604 pq_release_remote(tcp_globals.net_phone, 602 605 packet_get_id(packet)); 603 606 packet = next_packet; … … 622 625 if (length <= 0) { 623 626 /* Remove the empty packet */ 624 pq_release_remote(tcp_globals.net_ sess,627 pq_release_remote(tcp_globals.net_phone, 625 628 packet_get_id(packet)); 626 629 packet = next_packet; … … 669 672 } 670 673 /* Remove the duplicit or corrupted packet */ 671 pq_release_remote(tcp_globals.net_ sess,674 pq_release_remote(tcp_globals.net_phone, 672 675 packet_get_id(packet)); 673 676 packet = next_packet; … … 696 699 if (rc != EOK) { 697 700 /* Remove the corrupted packets */ 698 pq_release_remote(tcp_globals.net_ sess,701 pq_release_remote(tcp_globals.net_phone, 699 702 packet_get_id(packet)); 700 pq_release_remote(tcp_globals.net_ sess,703 pq_release_remote(tcp_globals.net_phone, 701 704 packet_get_id(next_packet)); 702 705 } else { … … 709 712 new_sequence_number, length); 710 713 if (rc != EOK) { 711 pq_release_remote(tcp_globals.net_ sess,714 pq_release_remote(tcp_globals.net_phone, 712 715 packet_get_id(next_packet)); 713 716 } 714 717 rc = pq_insert_after(packet, next_packet); 715 718 if (rc != EOK) { 716 pq_release_remote(tcp_globals.net_ sess,719 pq_release_remote(tcp_globals.net_phone, 717 720 packet_get_id(next_packet)); 718 721 } … … 723 726 printf("unexpected\n"); 724 727 /* Release duplicite or restricted */ 725 pq_release_remote(tcp_globals.net_ sess, packet_get_id(packet));728 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 726 729 forced_ack = true; 727 730 } … … 791 794 if (rc != EOK) 792 795 return tcp_release_and_return(packet, rc); 793 rc = tl_get_ip_packet_dimension(tcp_globals.ip_ sess,796 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 794 797 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 795 798 if (rc != EOK) … … 800 803 801 804 /* Notify the destination socket */ 802 async_ exch_t *exch = async_exchange_begin(socket->sess);803 async_msg_5(exch, NET_SOCKET_RECEIVED,(sysarg_t) socket->socket_id,805 async_obsolete_msg_5(socket->phone, NET_SOCKET_RECEIVED, 806 (sysarg_t) socket->socket_id, 804 807 ((packet_dimension->content < socket_data->data_fragment_size) ? 805 808 packet_dimension->content : socket_data->data_fragment_size), 0, 0, 806 809 (sysarg_t) fragments); 807 async_exchange_end(exch);808 810 809 811 return EOK; … … 822 824 823 825 /* Notify the destination socket */ 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);826 async_obsolete_msg_5(socket->phone, NET_SOCKET_RECEIVED, 827 (sysarg_t) socket->socket_id, 828 0, 0, 0, 829 (sysarg_t) 0 /* 0 fragments == no more data */); 828 830 } 829 831 … … 851 853 next_packet = pq_detach(packet); 852 854 if (next_packet) { 853 pq_release_remote(tcp_globals.net_ sess,855 pq_release_remote(tcp_globals.net_phone, 854 856 packet_get_id(next_packet)); 855 857 } … … 938 940 /* Create a socket */ 939 941 socket_id = -1; 940 rc = socket_create(socket_data->local_sockets, listening_socket-> sess,942 rc = socket_create(socket_data->local_sockets, listening_socket->phone, 941 943 socket_data, &socket_id); 942 944 if (rc != EOK) { … … 991 993 fibril_rwlock_write_unlock(&tcp_globals.lock); 992 994 if (rc != EOK) { 993 socket_destroy(tcp_globals.net_ sess, socket->socket_id,995 socket_destroy(tcp_globals.net_phone, socket->socket_id, 994 996 socket_data->local_sockets, &tcp_globals.sockets, 995 997 tcp_free_socket_data); … … 1003 1005 next_packet = pq_detach(packet); 1004 1006 if (next_packet) { 1005 pq_release_remote(tcp_globals.net_ sess,1007 pq_release_remote(tcp_globals.net_phone, 1006 1008 packet_get_id(next_packet)); 1007 1009 } … … 1012 1014 packet_get_data_length(packet) - sizeof(*header)); 1013 1015 if (rc != EOK) { 1014 socket_destroy(tcp_globals.net_ sess, socket->socket_id,1016 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1015 1017 socket_data->local_sockets, &tcp_globals.sockets, 1016 1018 tcp_free_socket_data); … … 1023 1025 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1024 1026 if (rc != EOK) { 1025 socket_destroy(tcp_globals.net_ sess, socket->socket_id,1027 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1026 1028 socket_data->local_sockets, &tcp_globals.sockets, 1027 1029 tcp_free_socket_data); … … 1031 1033 packet = tcp_get_packets_to_send(socket, socket_data); 1032 1034 if (!packet) { 1033 socket_destroy(tcp_globals.net_ sess, socket->socket_id,1035 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1034 1036 socket_data->local_sockets, &tcp_globals.sockets, 1035 1037 tcp_free_socket_data); … … 1066 1068 1067 1069 socket_data->next_incoming = ntohl(header->sequence_number); /* + 1; */ 1068 pq_release_remote(tcp_globals.net_ sess, packet_get_id(packet));1070 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1069 1071 socket_data->state = TCP_SOCKET_ESTABLISHED; 1070 1072 listening_socket = socket_cores_find(socket_data->local_sockets, … … 1080 1082 if (rc == EOK) { 1081 1083 /* Notify the destination socket */ 1082 async_exch_t *exch = async_exchange_begin(socket->sess); 1083 async_msg_5(exch, NET_SOCKET_ACCEPTED, 1084 async_obsolete_msg_5(socket->phone, NET_SOCKET_ACCEPTED, 1084 1085 (sysarg_t) listening_socket->socket_id, 1085 1086 socket_data->data_fragment_size, TCP_HEADER_SIZE, 1086 1087 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_ sess,1183 pq_release_remote(tcp_globals.net_phone, 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_ sess,1192 pq_release_remote(tcp_globals.net_phone, 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 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 1238 switch (IPC_GET_IMETHOD(*call)) { 1239 case IPC_M_CONNECT_TO_ME: 1240 return tcp_process_client_messages(callid, *call); 1241 } 1242 1244 1243 return ENOTSUP; 1245 1244 } … … 1271 1270 } 1272 1271 1273 int tcp_process_client_messages(async_sess_t *sess, ipc_callid_t callid, 1274 ipc_call_t call) 1272 int tcp_process_client_messages(ipc_callid_t callid, ipc_call_t call) 1275 1273 { 1276 1274 int res; 1277 1275 socket_cores_t local_sockets; 1276 int app_phone = IPC_GET_PHONE(call); 1278 1277 struct sockaddr *addr; 1279 1278 int socket_id; … … 1326 1325 fibril_rwlock_write_lock(&lock); 1327 1326 socket_id = SOCKET_GET_SOCKET_ID(call); 1328 res = socket_create(&local_sockets, sess,1327 res = socket_create(&local_sockets, app_phone, 1329 1328 socket_data, &socket_id); 1330 1329 SOCKET_SET_SOCKET_ID(answer, socket_id); … … 1334 1333 break; 1335 1334 } 1336 if (tl_get_ip_packet_dimension(tcp_globals.ip_ sess,1335 if (tl_get_ip_packet_dimension(tcp_globals.ip_phone, 1337 1336 &tcp_globals.dimensions, DEVICE_INVALID_ID, 1338 1337 &packet_dimension) == EOK) { … … 1509 1508 } 1510 1509 1511 /* Release the application session*/1512 async_ hangup(sess);1510 /* Release the application phone */ 1511 async_obsolete_hangup(app_phone); 1513 1512 1514 1513 printf("release\n"); 1515 1514 /* Release all local sockets */ 1516 socket_cores_release(tcp_globals.net_ sess, &local_sockets,1515 socket_cores_release(tcp_globals.net_phone, &local_sockets, 1517 1516 &tcp_globals.sockets, tcp_free_socket_data); 1518 1517 … … 1622 1621 local_lock = socket_data->local_lock; 1623 1622 fibril_rwlock_write_lock(local_lock); 1624 socket_destroy(tcp_globals.net_ sess,1623 socket_destroy(tcp_globals.net_phone, 1625 1624 timeout->socket_id, timeout->local_sockets, 1626 1625 &tcp_globals.sockets, tcp_free_socket_data); … … 1755 1754 } 1756 1755 1757 rc = ip_get_route_req(tcp_globals.ip_ sess, IPPROTO_TCP,1756 rc = ip_get_route_req(tcp_globals.ip_phone, IPPROTO_TCP, 1758 1757 addr, addrlen, &socket_data->device_id, 1759 1758 &socket_data->pseudo_header, &socket_data->headerlen); … … 1903 1902 rc = pq_insert_after(previous, copy); 1904 1903 if (rc != EOK) { 1905 pq_release_remote(tcp_globals.net_ sess,1904 pq_release_remote(tcp_globals.net_phone, 1906 1905 packet_get_id(copy)); 1907 1906 return sending; … … 1940 1939 socket_data->headerlen, packet_get_data_length(packet)); 1941 1940 if (rc != EOK) { 1942 pq_release_remote(tcp_globals.net_ sess, packet_get_id(packet));1941 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1943 1942 return NULL; 1944 1943 } … … 1947 1946 header = (tcp_header_t *) packet_get_data(packet); 1948 1947 if (!header) { 1949 pq_release_remote(tcp_globals.net_ sess, packet_get_id(packet));1948 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1950 1949 return NULL; 1951 1950 } … … 1972 1971 rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0); 1973 1972 if (rc != EOK) { 1974 pq_release_remote(tcp_globals.net_ sess, packet_get_id(packet));1973 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1975 1974 return NULL; 1976 1975 } … … 1979 1978 sequence_number, socket_data->state, socket_data->timeout, true); 1980 1979 if (rc != EOK) { 1981 pq_release_remote(tcp_globals.net_ sess, packet_get_id(packet));1980 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1982 1981 return NULL; 1983 1982 } … … 1996 1995 1997 1996 /* Make a copy of the packet */ 1998 copy = packet_get_copy(tcp_globals.net_ sess, packet);1997 copy = packet_get_copy(tcp_globals.net_phone, packet); 1999 1998 if (!copy) 2000 1999 return NULL; … … 2010 2009 while (packet) { 2011 2010 next = pq_detach(packet); 2012 ip_send_msg(tcp_globals.ip_ sess, device_id, packet,2011 ip_send_msg(tcp_globals.ip_phone, device_id, packet, 2013 2012 SERVICE_TCP, 0); 2014 2013 packet = next; … … 2123 2122 return NO_DATA; 2124 2123 2125 rc = packet_translate_remote(tcp_globals.net_ sess, &packet, packet_id);2124 rc = packet_translate_remote(tcp_globals.net_phone, &packet, packet_id); 2126 2125 if (rc != EOK) 2127 2126 return rc; … … 2134 2133 /* Release the packet */ 2135 2134 dyn_fifo_pop(&socket->received); 2136 pq_release_remote(tcp_globals.net_ sess, packet_get_id(packet));2135 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 2137 2136 2138 2137 /* Return the total length */ … … 2172 2171 return ENOTCONN; 2173 2172 2174 rc = tl_get_ip_packet_dimension(tcp_globals.ip_ sess,2173 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2175 2174 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2176 2175 if (rc != EOK) … … 2183 2182 for (index = 0; index < fragments; index++) { 2184 2183 /* Read the data fragment */ 2185 result = tl_socket_read_packet_data(tcp_globals.net_ sess,2184 result = tl_socket_read_packet_data(tcp_globals.net_phone, 2186 2185 &packet, TCP_HEADER_SIZE, packet_dimension, 2187 2186 socket_data->addr, socket_data->addrlen); … … 2246 2245 default: 2247 2246 /* Just destroy */ 2248 rc = socket_destroy(tcp_globals.net_ sess, socket_id,2247 rc = socket_destroy(tcp_globals.net_phone, socket_id, 2249 2248 local_sockets, &tcp_globals.sockets, 2250 2249 tcp_free_socket_data); … … 2294 2293 2295 2294 /* Get the device packet dimension */ 2296 rc = tl_get_ip_packet_dimension(tcp_globals.ip_ sess,2295 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2297 2296 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2298 2297 if (rc != EOK) … … 2300 2299 2301 2300 /* Get a new packet */ 2302 *packet = packet_get_4_remote(tcp_globals.net_ sess, TCP_HEADER_SIZE,2301 *packet = packet_get_4_remote(tcp_globals.net_phone, TCP_HEADER_SIZE, 2303 2302 packet_dimension->addr_len, packet_dimension->prefix, 2304 2303 packet_dimension->suffix); … … 2363 2362 if (rc != EOK) 2364 2363 return rc; 2365 rc = tl_get_ip_packet_dimension(tcp_globals.ip_ sess,2364 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2366 2365 &tcp_globals.dimensions, socket_data->device_id, 2367 2366 &packet_dimension); … … 2435 2434 int tcp_release_and_return(packet_t *packet, int result) 2436 2435 { 2437 pq_release_remote(tcp_globals.net_ sess, packet_get_id(packet));2436 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 2438 2437 return result; 2439 2438 } … … 2444 2443 * @param[in,out] icall Message parameters. 2445 2444 * @param[in] arg Local argument. 2446 *2447 2445 */ 2448 2446 static void tcp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) … … 2454 2452 switch (IPC_GET_IMETHOD(*icall)) { 2455 2453 case NET_TL_RECEIVED: 2456 rc = packet_translate_remote(tcp_globals.net_ sess, &packet,2454 rc = packet_translate_remote(tcp_globals.net_phone, &packet, 2457 2455 IPC_GET_PACKET(*icall)); 2458 2456 if (rc == EOK) … … 2472 2470 /** Initialize the TCP module. 2473 2471 * 2474 * @param[in] sess Network module session.2472 * @param[in] net_phone Network module phone. 2475 2473 * 2476 2474 * @return EOK on success. … … 2478 2476 * 2479 2477 */ 2480 int tl_initialize( async_sess_t *sess)2478 int tl_initialize(int net_phone) 2481 2479 { 2482 2480 fibril_rwlock_initialize(&tcp_globals.lock); 2483 2481 fibril_rwlock_write_lock(&tcp_globals.lock); 2484 2482 2485 tcp_globals.net_ sess = sess;2483 tcp_globals.net_phone = net_phone; 2486 2484 2487 tcp_globals.icmp_ sess = icmp_connect_module();2488 tcp_globals.ip_ sess= ip_bind_service(SERVICE_IP, IPPROTO_TCP,2485 tcp_globals.icmp_phone = icmp_connect_module(ICMP_CONNECT_TIMEOUT); 2486 tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP, 2489 2487 SERVICE_TCP, tcp_receiver); 2490 if (tcp_globals.ip_ sess == NULL) {2488 if (tcp_globals.ip_phone < 0) { 2491 2489 fibril_rwlock_write_unlock(&tcp_globals.lock); 2492 return ENOENT;2490 return tcp_globals.ip_phone; 2493 2491 } 2494 2492
Note:
See TracChangeset
for help on using the changeset viewer.