Changeset 01a9ef5 in mainline for uspace/srv/net/net/net.c
- Timestamp:
- 2010-02-16T18:11:00Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 209faf9, bfd7aac
- Parents:
- 80ce111
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/net/net.c
r80ce111 r01a9ef5 70 70 #define NAME "Networking" 71 71 72 /** File read buffer size. 73 */ 74 #define BUFFER_SIZE 256 75 72 76 /** Prints the module name. 73 77 * @see NAME … … 84 88 int module_start( async_client_conn_t client_connection ); 85 89 86 //int parse_line( measured_strings_ref configuration, char * line ); 90 /** \todo 91 */ 92 int read_configuration_file( const char * directory, const char * filename, measured_strings_ref configuration ); 93 94 /** \todo 95 */ 96 int parse_line( measured_strings_ref configuration, char * line ); 87 97 88 98 /** Reads the networking subsystem global configuration. … … 274 284 } 275 285 276 /* 286 int read_configuration_file( const char * directory, const char * filename, measured_strings_ref configuration ){ 287 ERROR_DECLARE; 288 289 size_t index = 0; 290 char line[ BUFFER_SIZE ]; 291 FILE * cfg; 292 int read; 293 int line_number = 0; 294 295 // construct the full filename 296 printf( "Reading file %s/%s\n", directory, filename ); 297 if( snprintf( line, BUFFER_SIZE, "%s/%s", directory, filename ) > BUFFER_SIZE ){ 298 return EOVERFLOW; 299 } 300 // open the file 301 cfg = fopen( line, "r" ); 302 if( ! cfg ){ 303 return ENOENT; 304 } 305 306 // read the configuration line by line 307 // until an error or the end of file 308 while(( ! ferror( cfg )) && ( ! feof( cfg ))){ 309 read = fgetc( cfg ); 310 if(( read > 0 ) && ( read != '\n' ) && ( read != '\r' )){ 311 if( index >= BUFFER_SIZE ){ 312 line[ BUFFER_SIZE - 1 ] = '\0'; 313 printf( "line %d too long: %s\n", line_number, line ); 314 // no space left in the line buffer 315 return EOVERFLOW; 316 }else{ 317 // append the character 318 line[ index ] = (char) read; 319 ++ index; 320 } 321 }else{ 322 // on error or new line 323 line[ index ] = '\0'; 324 ++ line_number; 325 if( ERROR_OCCURRED( parse_line( configuration, line ))){ 326 printf( "error on line %d: %s\n", line_number, line ); 327 //fclose( cfg ); 328 //return ERROR_CODE; 329 } 330 index = 0; 331 } 332 } 333 fclose( cfg ); 334 return EOK; 335 } 336 277 337 int parse_line( measured_strings_ref configuration, char * line ){ 278 338 ERROR_DECLARE; 279 339 280 340 measured_string_ref setting; 281 char * name;282 char * value;341 char * name; 342 char * value; 283 343 284 344 // from the beginning 285 345 name = line; 346 347 // skip comments and blank lines 348 if(( * name == '#' ) || ( * name == '\0' )){ 349 return EOK; 350 } 286 351 // skip spaces 287 352 while( isspace( * name )) ++ name; 353 288 354 // remember the name start 289 355 value = name; … … 294 360 ++ value; 295 361 } 362 296 363 if( * value == '=' ){ 297 364 // terminate the name … … 306 373 if( * value != '=' ) return EINVAL; 307 374 } 375 308 376 ++ value; 309 377 // skip spaces 310 378 while( isspace( * value )) ++ value; 311 379 // create a bulk measured string till the end 312 setting = measured_string_create_bulk( value, -1);380 setting = measured_string_create_bulk( value, 0 ); 313 381 if( ! setting ) return ENOMEM; 382 314 383 // add the configuration setting 315 384 if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){ … … 319 388 return EOK; 320 389 } 321 */322 390 323 391 int add_configuration( measured_strings_ref configuration, const char * name, const char * value ){ … … 341 409 342 410 int read_configuration( void ){ 343 ERROR_DECLARE; 344 345 // read general configuration 346 ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "IPV", "4" )); 347 ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "IP_ROUTING", "no" )); 348 ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "MTU", "1500" )); 349 ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "ICMP_ERROR_REPORTING", "yes" )); //anything else not starting with 'y' 350 ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "ICMP_ECHO_REPLYING", "yes" )); //anything else not starting with 'y' 351 ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "UDP_CHECKSUM_COMPUTING", "yes" )); //anything else not starting with 'y' 352 ERROR_PROPAGATE( add_configuration( & net_globals.configuration, "UDP_AUTOBINDING", "yes" )); //anything else not starting with 'y' 353 return EOK; 411 // read the general configuration file 412 return read_configuration_file( CONF_DIR, CONF_GENERAL_FILE, & net_globals.configuration ); 354 413 } 355 414 356 415 int read_netif_configuration( char * name, netif_ref netif ){ 357 ERROR_DECLARE; 358 359 if( str_lcmp( name, "lo", 2 ) == 0 ){ 360 ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); 361 ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); 362 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); 363 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); 364 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); 365 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_NETMASK", "255.0.0.0" )); 366 ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "15535" )); 367 }else if( str_lcmp( name, "ne2k", 4 ) == 0 ){ 368 ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); 369 ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); 370 ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_MODE", "DIX" )); //8023_2_LSAP( not supported ), 8023_2_SNAP 371 // ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_DUMMY", "yes" )); //anything else not starting with 'y' 372 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); 373 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); 374 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); 375 ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" )); 376 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); 377 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" )); 378 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ROUTING", "yes" )); 379 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_NETMASK", "255.255.255.240" )); 380 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_BROADCAST", "10.0.2.255" )); 381 ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_GATEWAY", "10.0.2.2" )); 382 ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); 383 } 384 return read_netif_configuration_build( name, netif ); 416 // read the netif configuration file 417 return read_configuration_file( CONF_DIR, name, & netif->configuration ); 385 418 } 386 419 … … 451 484 ERROR_DECLARE; 452 485 486 #ifdef CONFIG_NETIF_DP8390 453 487 char * conf_files[] = { "lo", "ne2k" }; 488 #else 489 char * conf_files[] = { "lo" }; 490 #endif 491 454 492 int count = sizeof( conf_files ) / sizeof( char * ); 455 493 int index;
Note:
See TracChangeset
for help on using the changeset viewer.