Subversion Repositories HelenOS

Rev

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

Rev 4735 Rev 4743
Line 51... Line 51...
51
#include "../../messages.h"
51
#include "../../messages.h"
52
#include "../../modules.h"
52
#include "../../modules.h"
53
 
53
 
54
#include "../../include/arp_interface.h"
54
#include "../../include/arp_interface.h"
55
#include "../../include/byteorder.h"
55
#include "../../include/byteorder.h"
56
#include "../../include/crc.h"
56
#include "../../include/checksum.h"
57
#include "../../include/device.h"
57
#include "../../include/device.h"
58
#include "../../include/icmp_client.h"
58
#include "../../include/icmp_client.h"
59
#include "../../include/icmp_codes.h"
59
#include "../../include/icmp_codes.h"
60
#include "../../include/icmp_interface.h"
60
#include "../../include/icmp_interface.h"
61
#include "../../include/il_interface.h"
61
#include "../../include/il_interface.h"
Line 269... Line 269...
269
                inet_ntop( AF_INET, ( uint8_t * ) & route->gateway.s_addr, data, INET_ADDRSTRLEN );
269
                inet_ntop( AF_INET, ( uint8_t * ) & route->gateway.s_addr, data, INET_ADDRSTRLEN );
270
                printf( "\t\tgateway\t= %s\n", data );
270
                printf( "\t\tgateway\t= %s\n", data );
271
            }
271
            }
272
        }
272
        }
273
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast.s_addr, data, INET_ADDRSTRLEN );
273
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast.s_addr, data, INET_ADDRSTRLEN );
274
        printf( "\tbroadcast\t= %s\n", data );
274
        printf( "\t\tbroadcast\t= %s\n", data );
275
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN );
-
 
276
        printf( "\tdns1\t= %s\n", data );
-
 
277
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN );
-
 
278
        printf( "\tdns2\t= %s\n", data );
-
 
279
        free( data );
275
        free( data );
280
    }
276
    }
281
    fibril_rwlock_write_unlock( & ip_globals.netifs_lock );
277
    fibril_rwlock_write_unlock( & ip_globals.netifs_lock );
282
    return EOK;
278
    return EOK;
283
}
279
}
284
 
280
 
285
int ip_netif_initialize( ip_netif_ref ip_netif ){
281
int ip_netif_initialize( ip_netif_ref ip_netif ){
286
    ERROR_DECLARE;
282
    ERROR_DECLARE;
287
 
283
 
288
    measured_string_t   names[] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }, { "IP_ROUTING", 10 }};
284
    measured_string_t   names[] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "IP_NETMASK", 10 }, { "IP_GATEWAY", 10 }, { "IP_BROADCAST", 12 }, { "ARP", 3 }, { "IP_ROUTING", 10 }};
289
    measured_string_ref configuration;
285
    measured_string_ref configuration;
290
    size_t              count = sizeof( names ) / sizeof( measured_string_t );
286
    size_t              count = sizeof( names ) / sizeof( measured_string_t );
291
    char *              data;
287
    char *              data;
292
    measured_string_t   address;
288
    measured_string_t   address;
293
    int                 index;
289
    int                 index;
Line 328... Line 324...
328
                return index;
324
                return index;
329
            }
325
            }
330
            if( ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 2 ].value, ( uint8_t * ) & route->address.s_addr ))
326
            if( ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 2 ].value, ( uint8_t * ) & route->address.s_addr ))
331
            || ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 3 ].value, ( uint8_t * ) & route->netmask.s_addr ))
327
            || ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 3 ].value, ( uint8_t * ) & route->netmask.s_addr ))
332
            || ( inet_pton( AF_INET, configuration[ 4 ].value, ( uint8_t * ) & gateway.s_addr ) == EINVAL )
328
            || ( inet_pton( AF_INET, configuration[ 4 ].value, ( uint8_t * ) & gateway.s_addr ) == EINVAL )
333
            || ( inet_pton( AF_INET, configuration[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast.s_addr ) == EINVAL )
329
            || ( inet_pton( AF_INET, configuration[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast.s_addr ) == EINVAL )){
334
            || ( inet_pton( AF_INET, configuration[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL )
-
 
335
            || ( inet_pton( AF_INET, configuration[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){
-
 
336
                net_free_settings( configuration, data );
330
                net_free_settings( configuration, data );
337
                return EINVAL;
331
                return EINVAL;
338
            }
332
            }
339
        }else{
333
        }else{
340
            // TODO ipv6 in separate module
334
            // TODO ipv6 in separate module
341
            net_free_settings( configuration, data );
335
            net_free_settings( configuration, data );
342
            return ENOTSUP;
336
            return ENOTSUP;
343
        }
337
        }
344
        if( configuration[ 8 ].value ){
338
        if( configuration[ 6 ].value ){
345
            ip_netif->arp = get_running_module( & ip_globals.modules, configuration[ 8 ].value );
339
            ip_netif->arp = get_running_module( & ip_globals.modules, configuration[ 6 ].value );
346
            if( ! ip_netif->arp ){
340
            if( ! ip_netif->arp ){
347
                printf( "Failed to start the arp %s\n", configuration[ 8 ].value );
341
                printf( "Failed to start the arp %s\n", configuration[ 6 ].value );
348
                net_free_settings( configuration, data );
342
                net_free_settings( configuration, data );
349
                return EINVAL;
343
                return EINVAL;
350
            }
344
            }
351
        }
345
        }
352
        if( configuration[ 9 ].value ){
346
        if( configuration[ 7 ].value ){
353
            ip_netif->routing = ( configuration[ 9 ].value[ 0 ] == 'y' );
347
            ip_netif->routing = ( configuration[ 7 ].value[ 0 ] == 'y' );
354
        }
348
        }
355
        net_free_settings( configuration, data );
349
        net_free_settings( configuration, data );
356
    }
350
    }
357
    // binds the netif service which also initializes the device
351
    // binds the netif service which also initializes the device
358
    ip_netif->phone = bind_service( ip_netif->service, ( ipcarg_t ) ip_netif->device_id, SERVICE_IP, 0, ip_globals.client_connection );
352
    ip_netif->phone = nil_bind_service( ip_netif->service, ( ipcarg_t ) ip_netif->device_id, SERVICE_IP, ip_globals.client_connection );
359
    if( ip_netif->phone < 0 ){
353
    if( ip_netif->phone < 0 ){
360
        printf( "Failed to contact the nil service %d\n", ip_netif->service );
354
        printf( "Failed to contact the nil service %d\n", ip_netif->service );
361
        return ip_netif->phone;
355
        return ip_netif->phone;
362
    }
356
    }
363
    // has to be after the device netif module initialization
357
    // has to be after the device netif module initialization
Line 467... Line 461...
467
    // should be the next hop address or the target destination address
461
    // should be the next hop address or the target destination address
468
    addrlen = packet_get_addr( packet, NULL, ( uint8_t ** ) & addr );
462
    addrlen = packet_get_addr( packet, NULL, ( uint8_t ** ) & addr );
469
    if( addrlen < 0 ){
463
    if( addrlen < 0 ){
470
        return ip_release_and_return( packet, addrlen );
464
        return ip_release_and_return( packet, addrlen );
471
    }
465
    }
472
    if( addrlen < sizeof( struct sockaddr )){
466
    if(( size_t ) addrlen < sizeof( struct sockaddr )){
473
        return ip_release_and_return( packet, EINVAL );
467
        return ip_release_and_return( packet, EINVAL );
474
    }
468
    }
475
    switch( addr->sa_family ){
469
    switch( addr->sa_family ){
476
        case AF_INET:
470
        case AF_INET:
477
            if( addrlen != sizeof( struct sockaddr_in )){
471
            if( addrlen != sizeof( struct sockaddr_in )){
Line 1288... Line 1282...
1288
    ip_route_ref            route;
1282
    ip_route_ref            route;
1289
    ipv4_pseudo_header_ref  header_in;
1283
    ipv4_pseudo_header_ref  header_in;
1290
 
1284
 
1291
    if( !( destination && ( addrlen > 0 ))) return EINVAL;
1285
    if( !( destination && ( addrlen > 0 ))) return EINVAL;
1292
    if( !( device_id && header && headerlen )) return EBADMEM;
1286
    if( !( device_id && header && headerlen )) return EBADMEM;
1293
    if( addrlen < sizeof( struct sockaddr )){
1287
    if(( size_t ) addrlen < sizeof( struct sockaddr )){
1294
        return EINVAL;
1288
        return EINVAL;
1295
    }
1289
    }
1296
    switch( destination->sa_family ){
1290
    switch( destination->sa_family ){
1297
        case AF_INET:
1291
        case AF_INET:
1298
            if( addrlen != sizeof( struct sockaddr_in )){
1292
            if( addrlen != sizeof( struct sockaddr_in )){