Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tl/udp/udp.c

    rafe1d1e r6b82009  
    9999static int udp_release_and_return(packet_t *packet, int result)
    100100{
    101         pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
     101        pq_release_remote(udp_globals.net_sess, packet_get_id(packet));
    102102        return result;
    103103}
     
    192192            ntohs(header->destination_port), (uint8_t *) SOCKET_MAP_KEY_LISTENING, 0);
    193193        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,
    197197                            ICMP_PORT_UNREACH, 0, packet);
    198198                }
     
    251251                        while (tmp_packet) {
    252252                                next_packet = pq_detach(tmp_packet);
    253                                 pq_release_remote(udp_globals.net_phone,
     253                                pq_release_remote(udp_globals.net_sess,
    254254                                    packet_get_id(tmp_packet));
    255255                                tmp_packet = next_packet;
     
    274274                if (flip_checksum(compact_checksum(checksum)) !=
    275275                    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) {
    278278                                /* Checksum error ICMP */
    279279                                icmp_parameter_problem_msg(
    280                                     udp_globals.icmp_phone, ICMP_PARAM_POINTER,
     280                                    udp_globals.icmp_sess, ICMP_PARAM_POINTER,
    281281                                    ((size_t) ((void *) &header->checksum)) -
    282282                                    ((size_t) ((void *) header)), packet);
     
    292292                return udp_release_and_return(packet, rc);
    293293               
    294         rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
     294        rc = tl_get_ip_packet_dimension(udp_globals.ip_sess,
    295295            &udp_globals.dimensions, device_id, &packet_dimension);
    296296        if (rc != EOK)
     
    299299        /* Notify the destination socket */
    300300        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);
    304306
    305307        return EOK;
     
    337339 * @param[in]     iid   Message identifier.
    338340 * @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 */
     344static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    342345{
    343346        packet_t *packet;
     
    347350                switch (IPC_GET_IMETHOD(*icall)) {
    348351                case NET_TL_RECEIVED:
    349                         rc = packet_translate_remote(udp_globals.net_phone, &packet,
     352                        rc = packet_translate_remote(udp_globals.net_sess, &packet,
    350353                            IPC_GET_PACKET(*icall));
    351354                        if (rc == EOK)
     
    365368/** Initialize the UDP module.
    366369 *
    367  * @param[in] net_phone Network module phone.
     370 * @param[in] sess Network module session.
    368371 *
    369372 * @return EOK on success.
     
    371374 *
    372375 */
    373 int tl_initialize(int net_phone)
     376int tl_initialize(async_sess_t *sess)
    374377{
    375378        measured_string_t names[] = {
     
    390393        fibril_rwlock_write_lock(&udp_globals.lock);
    391394       
    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;
    401403        }
    402404       
    403405        /* 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,
    405407            &udp_globals.packet_dimension);
    406408        if (rc != EOK) {
     
    417419        rc = packet_dimensions_initialize(&udp_globals.dimensions);
    418420        if (rc != EOK) {
    419                 socket_ports_destroy(&udp_globals.sockets);
     421                socket_ports_destroy(&udp_globals.sockets, free);
    420422                fibril_rwlock_write_unlock(&udp_globals.lock);
    421423                return rc;
     
    431433        /* Get configuration */
    432434        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,
    434436            &data);
    435437        if (rc != EOK) {
    436                 socket_ports_destroy(&udp_globals.sockets);
     438                socket_ports_destroy(&udp_globals.sockets, free);
    437439                fibril_rwlock_write_unlock(&udp_globals.lock);
    438440                return rc;
     
    499501        device_id_t device_id;
    500502        packet_dimension_t *packet_dimension;
     503        size_t size;
    501504        int rc;
     505
     506        /* In case of error, do not update the data fragment size. */
     507        *data_fragment_size = 0;
    502508       
    503509        rc = tl_get_address_port(addr, addrlen, &dest_port);
     
    521527
    522528        if (udp_globals.checksum_computing) {
    523                 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,
    524530                    addrlen, &device_id, &ip_header, &headerlen);
    525531                if (rc != EOK)
    526532                        return rc;
    527533                /* Get the device packet dimension */
    528 //              rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
     534//              rc = tl_get_ip_packet_dimension(udp_globals.ip_sess,
    529535//                  &udp_globals.dimensions, device_id, &packet_dimension);
    530536//              if (rc != EOK)
     
    533539//      } else {
    534540                /* Do not ask all the time */
    535                 rc = ip_packet_size_req(udp_globals.ip_phone, -1,
     541                rc = ip_packet_size_req(udp_globals.ip_sess, -1,
    536542                    &udp_globals.packet_dimension);
    537543                if (rc != EOK)
     
    540546//      }
    541547
     548        /*
     549         * Update the data fragment size based on what the lower layers can
     550         * handle without fragmentation, but not more than the maximum allowed
     551         * for UDP.
     552         */
     553        size = MAX_UDP_FRAGMENT_SIZE;
     554        if (packet_dimension->content < size)
     555            size = packet_dimension->content;
     556        *data_fragment_size = size;
     557
    542558        /* Read the first packet fragment */
    543         result = tl_socket_read_packet_data(udp_globals.net_phone, &packet,
     559        result = tl_socket_read_packet_data(udp_globals.net_sess, &packet,
    544560            UDP_HEADER_SIZE, packet_dimension, addr, addrlen);
    545561        if (result < 0)
     
    562578        /* Read the rest of the packet fragments */
    563579        for (index = 1; index < fragments; index++) {
    564                 result = tl_socket_read_packet_data(udp_globals.net_phone,
     580                result = tl_socket_read_packet_data(udp_globals.net_sess,
    565581                    &next_packet, 0, packet_dimension, addr, addrlen);
    566582                if (result < 0)
     
    614630
    615631        /* Send the packet */
    616         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);
    617633
    618634        return EOK;
     
    661677                return NO_DATA;
    662678       
    663         rc = packet_translate_remote(udp_globals.net_phone, &packet, packet_id);
     679        rc = packet_translate_remote(udp_globals.net_sess, &packet, packet_id);
    664680        if (rc != EOK) {
    665681                (void) dyn_fifo_pop(&socket->received);
     
    721737}
    722738
    723 /** Processes the socket client messages.
    724  *
    725  * Runs until the client module disconnects.
    726  *
    727  * @param[in] callid    The message identifier.
    728  * @param[in] call      The message parameters.
    729  * @return              EOK on success.
    730  *
    731  * @see socket.h
    732  */
    733 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 */
     752static int udp_process_client_messages(async_sess_t *sess, ipc_callid_t callid,
     753    ipc_call_t call)
    734754{
    735755        int res;
    736         bool keep_on_going = true;
    737756        socket_cores_t local_sockets;
    738         int app_phone = IPC_GET_PHONE(call);
    739757        struct sockaddr *addr;
    740758        int socket_id;
    741759        size_t addrlen;
    742         size_t size = 0;
     760        size_t size;
    743761        ipc_call_t answer;
    744762        size_t answer_count;
     
    759777        socket_cores_initialize(&local_sockets);
    760778
    761         while (keep_on_going) {
     779        while (true) {
    762780
    763781                /* Answer the call */
     
    771789
    772790                /* Process the call */
    773                 switch (IPC_GET_IMETHOD(call)) {
    774                 case IPC_M_PHONE_HUNGUP:
    775                         keep_on_going = false;
     791                if (!IPC_GET_IMETHOD(call)) {
    776792                        res = EHANGUP;
    777793                        break;
    778 
     794                }
     795               
     796                switch (IPC_GET_IMETHOD(call)) {
    779797                case NET_SOCKET:
    780798                        socket_id = SOCKET_GET_SOCKET_ID(call);
    781                         res = socket_create(&local_sockets, app_phone, NULL,
     799                        res = socket_create(&local_sockets, sess, NULL,
    782800                            &socket_id);
    783801                        SOCKET_SET_SOCKET_ID(answer, socket_id);
     
    786804                                break;
    787805                       
    788                         if (tl_get_ip_packet_dimension(udp_globals.ip_phone,
     806                        size = MAX_UDP_FRAGMENT_SIZE;
     807                        if (tl_get_ip_packet_dimension(udp_globals.ip_sess,
    789808                            &udp_globals.dimensions, DEVICE_INVALID_ID,
    790809                            &packet_dimension) == EOK) {
    791                                 SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
    792                                     packet_dimension->content);
     810                                if (packet_dimension->content < size)
     811                                        size = packet_dimension->content;
    793812                        }
    794 
    795 //                      SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
    796 //                          MAX_UDP_FRAGMENT_SIZE);
     813                        SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
    797814                        SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE);
    798815                        answer_count = 3;
     
    852869                case NET_SOCKET_CLOSE:
    853870                        fibril_rwlock_write_lock(&udp_globals.lock);
    854                         res = socket_destroy(udp_globals.net_phone,
     871                        res = socket_destroy(udp_globals.net_sess,
    855872                            SOCKET_GET_SOCKET_ID(call), &local_sockets,
    856873                            &udp_globals.sockets, NULL);
     
    866883        }
    867884
    868         /* Release the application phone */
    869         async_hangup(app_phone);
     885        /* Release the application session */
     886        async_hangup(sess);
    870887
    871888        /* Release all local sockets */
    872         socket_cores_release(udp_globals.net_phone, &local_sockets,
     889        socket_cores_release(udp_globals.net_sess, &local_sockets,
    873890            &udp_globals.sockets, NULL);
    874891
     
    900917{
    901918        *answer_count = 0;
    902 
    903         switch (IPC_GET_IMETHOD(*call)) {
    904         case IPC_M_CONNECT_TO_ME:
    905                 return udp_process_client_messages(callid, *call);
    906         }
    907 
     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       
    908925        return ENOTSUP;
    909926}
Note: See TracChangeset for help on using the changeset viewer.