Subversion Repositories HelenOS

Rev

Rev 4738 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4738 Rev 4743
Line 36... Line 36...
36
 */
36
 */
37
 
37
 
38
#include <async.h>
38
#include <async.h>
39
#include <fibril_sync.h>
39
#include <fibril_sync.h>
40
#include <malloc.h>
40
#include <malloc.h>
-
 
41
#include <stdio.h>
41
 
42
 
42
#include <ipc/ipc.h>
43
#include <ipc/ipc.h>
43
#include <ipc/services.h>
44
#include <ipc/services.h>
44
 
45
 
45
#include "../../err.h"
46
#include "../../err.h"
Line 47... Line 48...
47
#include "../../modules.h"
48
#include "../../modules.h"
48
 
49
 
49
#include "../../structures/dynamic_fifo.h"
50
#include "../../structures/dynamic_fifo.h"
50
#include "../../structures/packet/packet_client.h"
51
#include "../../structures/packet/packet_client.h"
51
 
52
 
52
#include "../../include/crc.h"
53
#include "../../include/checksum.h"
53
#include "../../include/in.h"
54
#include "../../include/in.h"
54
#include "../../include/in6.h"
55
#include "../../include/in6.h"
55
#include "../../include/inet.h"
56
#include "../../include/inet.h"
56
#include "../../include/ip_client.h"
57
#include "../../include/ip_client.h"
57
#include "../../include/ip_interface.h"
58
#include "../../include/ip_interface.h"
Line 230... Line 231...
230
int udp_received_msg( device_id_t device_id, packet_t packet, services_t receiver, services_t error ){
231
int udp_received_msg( device_id_t device_id, packet_t packet, services_t receiver, services_t error ){
231
    int result;
232
    int result;
232
 
233
 
233
    fibril_rwlock_write_lock( & udp_globals.lock );
234
    fibril_rwlock_write_lock( & udp_globals.lock );
234
    result = udp_process_packet( packet, error );
235
    result = udp_process_packet( packet, error );
-
 
236
    if( result != EOK ){
235
    fibril_rwlock_write_unlock( & udp_globals.lock );
237
        fibril_rwlock_write_unlock( & udp_globals.lock );
-
 
238
    }
236
 
239
 
237
    return result;
240
    return result;
238
}
241
}
239
 
242
 
240
int udp_process_packet( packet_t packet, services_t error ){
243
int udp_process_packet( packet_t packet, services_t error ){
Line 377... Line 380...
377
    if( ERROR_OCCURRED( dyn_fifo_push( & socket->received, packet_get_id( packet ), SOCKET_MAX_RECEIVED_SIZE ))){
380
    if( ERROR_OCCURRED( dyn_fifo_push( & socket->received, packet_get_id( packet ), SOCKET_MAX_RECEIVED_SIZE ))){
378
        return udp_release_and_return( packet, ERROR_CODE );
381
        return udp_release_and_return( packet, ERROR_CODE );
379
    }
382
    }
380
 
383
 
381
    // notify the destination socket
384
    // notify the destination socket
-
 
385
    fibril_rwlock_write_unlock( & udp_globals.lock );
382
    async_msg_5( socket->phone, NET_SOCKET_RECEIVED, ( ipcarg_t ) socket->socket_id, 0, 0, 0, ( ipcarg_t ) fragments );
386
    async_msg_5( socket->phone, NET_SOCKET_RECEIVED, ( ipcarg_t ) socket->socket_id, 0, 0, 0, ( ipcarg_t ) fragments );
383
    return EOK;
387
    return EOK;
384
}
388
}
385
 
389
 
386
int udp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
390
int udp_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
Line 412... Line 416...
412
    ipc_call_t              answer;
416
    ipc_call_t              answer;
413
    int                     answer_count;
417
    int                     answer_count;
414
 
418
 
415
    /*
419
    /*
416
     * Accept the connection
420
     * Accept the connection
417
     *  - Answer the first IPC_M_CONNECT_ME_TO call.
421
     *  - Answer the first IPC_M_CONNECT_TO_ME call.
418
     */
422
     */
419
    ipc_answer_0( callid, EOK );
423
    ipc_answer_0( callid, EOK );
420
 
424
 
421
    // The client connection is only in one fibril and therefore no additional locks are needed.
425
    // The client connection is only in one fibril and therefore no additional locks are needed.
422
 
426
 
Line 459... Line 463...
459
                res = data_receive(( void ** ) & addr, & addrlen );
463
                res = data_receive(( void ** ) & addr, & addrlen );
460
                if( res == EOK ){
464
                if( res == EOK ){
461
                    fibril_rwlock_read_lock( & lock );
465
                    fibril_rwlock_read_lock( & lock );
462
                    fibril_rwlock_write_lock( & udp_globals.lock );
466
                    fibril_rwlock_write_lock( & udp_globals.lock );
463
                    res = udp_sendto_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_GET_DATA_FRAGMENT_SIZE( call ), SOCKET_GET_FLAGS( call ));
467
                    res = udp_sendto_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_GET_DATA_FRAGMENT_SIZE( call ), SOCKET_GET_FLAGS( call ));
-
 
468
                    if( res != EOK ){
464
                    fibril_rwlock_write_unlock( & udp_globals.lock );
469
                        fibril_rwlock_write_unlock( & udp_globals.lock );
-
 
470
                    }
465
                    fibril_rwlock_read_unlock( & lock );
471
                    fibril_rwlock_read_unlock( & lock );
466
                    free( addr );
472
                    free( addr );
467
                }
473
                }
468
                break;
474
                break;
469
            case NET_SOCKET_RECVFROM:
475
            case NET_SOCKET_RECVFROM:
Line 525... Line 531...
525
    socket = socket_cores_find( local_sockets, socket_id );
531
    socket = socket_cores_find( local_sockets, socket_id );
526
    if( ! socket ) return ENOTSOCK;
532
    if( ! socket ) return ENOTSOCK;
527
 
533
 
528
    if(( socket->port <= 0 ) && udp_globals.autobinding ){
534
    if(( socket->port <= 0 ) && udp_globals.autobinding ){
529
        // bind the socket to a random free port if not bound
535
        // bind the socket to a random free port if not bound
530
        do{
536
//      do{
531
            // try to find a free port
537
            // try to find a free port
532
//          fibril_rwlock_read_unlock( & udp_globals.lock );
538
//          fibril_rwlock_read_unlock( & udp_globals.lock );
533
//          fibril_rwlock_write_lock( & udp_globals.lock );
539
//          fibril_rwlock_write_lock( & udp_globals.lock );
534
            // might be changed in the meantime
540
            // might be changed in the meantime
535
            if( socket->port <= 0 ){
541
//          if( socket->port <= 0 ){
536
                if( ERROR_OCCURRED( socket_bind_free_port( & udp_globals.sockets, socket, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, udp_globals.last_used_port ))){
542
                if( ERROR_OCCURRED( socket_bind_free_port( & udp_globals.sockets, socket, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, udp_globals.last_used_port ))){
537
                    fibril_rwlock_write_unlock( & udp_globals.lock );
543
//                  fibril_rwlock_write_unlock( & udp_globals.lock );
538
                    fibril_rwlock_read_lock( & udp_globals.lock );
544
//                  fibril_rwlock_read_lock( & udp_globals.lock );
539
                    return ERROR_CODE;
545
                    return ERROR_CODE;
540
                }
546
                }
541
                // set the next port as the search starting port number
547
                // set the next port as the search starting port number
542
                udp_globals.last_used_port = socket->port;
548
                udp_globals.last_used_port = socket->port;
543
            }
549
//          }
544
//          fibril_rwlock_write_unlock( & udp_globals.lock );
550
//          fibril_rwlock_write_unlock( & udp_globals.lock );
545
//          fibril_rwlock_read_lock( & udp_globals.lock );
551
//          fibril_rwlock_read_lock( & udp_globals.lock );
546
            // might be changed in the meantime
552
            // might be changed in the meantime
547
        }while( socket->port <= 0 );
553
//      }while( socket->port <= 0 );
548
    }
554
    }
549
 
555
 
550
    // TODO do not ask all the time
556
    // TODO do not ask all the time
551
    ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension.addr_len, & udp_globals.packet_dimension.prefix, & udp_globals.packet_dimension.content, & udp_globals.packet_dimension.suffix ));
557
    ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension.addr_len, & udp_globals.packet_dimension.prefix, & udp_globals.packet_dimension.content, & udp_globals.packet_dimension.suffix ));
552
 
558
 
Line 600... Line 606...
600
    // prepare the first packet fragment
606
    // prepare the first packet fragment
601
    if( ERROR_OCCURRED( ip_client_prepare_packet( packet, IPPROTO_UDP, 0, 0, 0, 0 ))){
607
    if( ERROR_OCCURRED( ip_client_prepare_packet( packet, IPPROTO_UDP, 0, 0, 0, 0 ))){
602
        return udp_release_and_return( packet, ERROR_CODE );
608
        return udp_release_and_return( packet, ERROR_CODE );
603
    }
609
    }
604
    // send the packet
610
    // send the packet
-
 
611
    fibril_rwlock_write_unlock( & udp_globals.lock );
605
    return ip_send_msg( udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0 );
612
    ip_send_msg( udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0 );
-
 
613
    return EOK;
606
}
614
}
607
 
615
 
608
int udp_recvfrom_message( socket_cores_ref local_sockets, int socket_id, int flags, size_t * addrlen ){
616
int udp_recvfrom_message( socket_cores_ref local_sockets, int socket_id, int flags, size_t * addrlen ){
609
    ERROR_DECLARE;
617
    ERROR_DECLARE;
610
 
618