Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4191 → Rev 4192

/branches/network/uspace/srv/net/il/ip/ip.c
48,6 → 48,7
#include "../../include/socket.h"
#include "../../netif/device.h"
#include "../../structures/measured_strings.h"
#include "../../structures/module_map.h"
#include "../../structures/packet/packet_client.h"
 
#include "ip.h"
56,6 → 57,9
 
#define DEFAULT_IPV 4
 
#define ARP_NAME "arp"
#define ARP_FILENAME "/srv/arp"
 
#define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call )
#define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG1( * call )
#define IPC_GET_PROTO( call ) ( int ) IPC_GET_ARG1( * call )
76,8 → 80,12
/** Initializes the module.
*/
int ip_initialize( void ){
ip_netifs_initialize( & ip_globals.netifs );
ip_protos_initialize( & ip_globals.protos );
ERROR_DECLARE;
 
ERROR_PROPAGATE( ip_netifs_initialize( & ip_globals.netifs ));
ERROR_PROPAGATE( ip_protos_initialize( & ip_globals.protos ));
ERROR_PROPAGATE( modules_initialize( & ip_globals.modules ));
ERROR_PROPAGATE( add_module( NULL, & ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, 0 ));
return EOK;
}
 
93,7 → 101,7
int ip_device_message( device_id_t device_id, services_t service ){
ERROR_DECLARE;
 
ip_netif_ref ip_netif;
ip_netif_ref ip_netif;
aid_t message;
ipc_call_t answer;
measured_string_t configuration[ 9 ] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }};
100,6 → 108,8
int count = 9;
measured_string_ref settings;
char * data;
ipcarg_t result;
int index;
 
ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t ));
if( ! ip_netif ) return ENOMEM;
111,8 → 121,18
if( ERROR_OCCURRED( measured_strings_send( ip_globals.networking_phone, configuration, count ))
|| ERROR_OCCURRED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){
async_wait_for( message, NULL );
free( ip_netif );
return ERROR_CODE;
}
async_wait_for( message, & result );
if( ERROR_OCCURRED( result )){
if( settings ){
free( settings );
free( data );
};
free( ip_netif );
return ERROR_CODE;
}
if( settings ){
if( settings[ 0 ].value ){
ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 );
119,9 → 139,11
}else{
ip_netif->ipv = DEFAULT_IPV;
}
ip_netif->dhcp = ! strcmp( settings[ 1 ].value, "DHCP" );
ip_netif->dhcp = ! strncmp( settings[ 1 ].value, "dhcp", 4 );
if( ip_netif->dhcp ){
// TODO dhcp
free( settings );
free( data );
free( ip_netif );
return ENOTSUP;
}else if( ip_netif->ipv == 4 ){
131,27 → 153,64
|| ( inet_pton( AF_INET, settings[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL )
|| ( inet_pton( AF_INET, settings[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL )
|| ( inet_pton( AF_INET, settings[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){
free( settings );
free( data );
free( ip_netif );
return EINVAL;
}
}else{
// TODO ipv6
free( settings );
free( data );
free( ip_netif );
return ENOTSUP;
}
// TODO ARP module
if( settings[ 8 ].value ){
ip_netif->arp = get_running_module( & ip_globals.modules, settings[ 8 ].value );
if( ! ip_netif->arp ){
printf( "\nFailed to start the arp %s", settings[ 8 ].value );
free( settings );
free( data );
free( ip_netif );
return EINVAL;
}
}else{
ip_netif->arp = NULL;
}
free( settings );
free( data );
}
// TODO arp module
// TODO register
free( settings );
free( data );
// end request
// TODO mapping
async_wait_for( message, NULL );
ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver );
if( ip_netif->phone < 0 ){
printf( "\nFailed to contact the nil service %d", service );
free( ip_netif );
return ip_netif->phone;
}
if( ip_netif->arp ){
message = async_send_3( ip_netif->arp->phone, NET_ARP_DEVICE, ip_netif->device_id, SERVICE_IP, service, & answer );
configuration[ 0 ].value = ( char * ) & ip_netif->address;
configuration[ 0 ].length = CONVERT_SIZE( in_addr_t, char, 1 );
if( ERROR_OCCURRED( measured_strings_send( ip_netif->arp->phone, & configuration[ 0 ], 1 ))){
free( ip_netif );
return ERROR_CODE;
}
async_wait_for( message, & result );
if( ERROR_OCCURRED( result )){
free( ip_netif );
return ERROR_CODE;
}
}
index = ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif );
if( index < 0 ){
free( ip_netif );
return index;
}
if( ip_netif->arp ) ++ ip_netif->arp->usage;
// print the settings
printf( "\nNew device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d", ip_netif->device_id, ip_netif->phone, ip_netif->ipv );
printf( "\n\tconfiguration\t= %s", ip_netif->dhcp ? "dhcp" : "static" );
// TODO ipv6
// TODO ipv6 addresses
data = malloc( INET_ADDRSTRLEN );
if( data ){
inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN );
168,12 → 227,6
printf( "\n\tdns2\t= %s", data );
free( data );
}
// TODO mapping
ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver );
if( ERROR_OCCURRED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){
free( ip_netif );
return ERROR_CODE;
}
return EOK;
}
 
229,17 → 282,17
}
 
int ip_register_message( int protocol, int phone ){
ERROR_DECLARE;
 
ip_proto_ref proto;
int index;
 
proto = ( ip_proto_ref ) malloc( sizeof( ip_protos_t ));
if( ! proto ) return ENOMEM;
proto->protocol = protocol;
proto->phone = phone;
if( ERROR_OCCURRED( ip_protos_add( & ip_globals.protos, proto->protocol, proto ))){
index = ip_protos_add( & ip_globals.protos, proto->protocol, proto );
if( index < 0 ){
free( proto );
return ERROR_CODE;
return index;
}
printf( "\nNew protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d", proto->protocol, proto->phone );
return EOK;
248,7 → 301,7
int ip_send_message( device_id_t device_id, packet_t packet ){
// TODO send packet
printf( "Packet to send via %d: %s", device_id, packet_get_data( packet ));
packet_release( ip_globals.networking_phone, packet_get_id( packet ));
pq_release( ip_globals.networking_phone, packet_get_id( packet ));
return EOK;
}
 
269,10 → 322,7
case IPC_M_CONNECT_TO_ME:
return ip_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call ));
case NET_IP_SEND:
if( ERROR_OCCURRED( packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( call )))){
printf( "\nIP send E %d", ERROR_CODE );
return ERROR_CODE;
}
ERROR_PROPAGATE( packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( call )));
return ip_send_message( IPC_GET_DEVICE( call ), packet );
}
return ENOTSUP;