Changes in uspace/srv/net/net/net.c [a000878c:aadf01e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/net/net.c
ra000878c raadf01e 77 77 * @see NAME 78 78 */ 79 void module_print_name( void);79 void module_print_name(void); 80 80 81 81 /** Starts the networking module. … … 86 86 * @returns Other error codes as defined for the REGISTER_ME() macro function. 87 87 */ 88 int module_start( async_client_conn_t client_connection);88 int module_start(async_client_conn_t client_connection); 89 89 90 90 /** \todo 91 91 */ 92 int read_configuration_file( const char * directory, const char * filename, measured_strings_ref configuration);92 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration); 93 93 94 94 /** \todo 95 95 */ 96 int parse_line( measured_strings_ref configuration, char * line);96 int parse_line(measured_strings_ref configuration, char * line); 97 97 98 98 /** Reads the networking subsystem global configuration. … … 100 100 * @returns Other error codes as defined for the add_configuration() function. 101 101 */ 102 int read_configuration( void);102 int read_configuration(void); 103 103 104 104 /** Starts the network interface according to its configuration. … … 113 113 * @returns Other error codes as defined for the needed internet layer registering function. 114 114 */ 115 int start_device( netif_ref netif);115 int start_device(netif_ref netif); 116 116 117 117 /** Reads the configuration and starts all network interfaces. … … 124 124 * @returns Other error codes as defined for the start_device() function. 125 125 */ 126 int startup( void);126 int startup(void); 127 127 128 128 /** Generates new system-unique device identifier. 129 129 * @returns The system-unique devic identifier. 130 130 */ 131 device_id_t generate_new_device_id( void);131 device_id_t generate_new_device_id(void); 132 132 133 133 /** Returns the configured values. … … 139 139 * @returns EOK. 140 140 */ 141 int net_get_conf( measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data);141 int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data); 142 142 143 143 /** Initializes the networking module. … … 146 146 * @returns ENOMEM if there is not enough memory left. 147 147 */ 148 int net_initialize( async_client_conn_t client_connection);148 int net_initialize(async_client_conn_t client_connection); 149 149 150 150 /** Reads the network interface specific configuration. … … 154 154 * @returns Other error codes as defined for the add_configuration() function. 155 155 */ 156 int read_netif_configuration( const char * name, netif_ref netif);156 int read_netif_configuration(const char * name, netif_ref netif); 157 157 158 158 /** Networking module global data. … … 160 160 net_globals_t net_globals; 161 161 162 DEVICE_MAP_IMPLEMENT( netifs, netif_t)163 164 GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t)165 166 void module_print_name( void){167 printf( "%s", NAME);168 } 169 170 int module_start( async_client_conn_t client_connection){171 ERROR_DECLARE; 172 173 ipcarg_t 174 175 async_set_client_connection( client_connection);176 ERROR_PROPAGATE( 177 if( ERROR_OCCURRED( net_initialize( client_connection))178 || ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash))){162 DEVICE_MAP_IMPLEMENT(netifs, netif_t) 163 164 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t) 165 166 void module_print_name(void){ 167 printf("%s", NAME); 168 } 169 170 int module_start(async_client_conn_t client_connection){ 171 ERROR_DECLARE; 172 173 ipcarg_t phonehash; 174 175 async_set_client_connection(client_connection); 176 ERROR_PROPAGATE(pm_init()); 177 if(ERROR_OCCURRED(net_initialize(client_connection)) 178 || ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))){ 179 179 pm_destroy(); 180 180 return ERROR_CODE; … … 187 187 } 188 188 189 int net_initialize( async_client_conn_t client_connection){190 ERROR_DECLARE; 191 192 netifs_initialize( & net_globals.netifs);193 char_map_initialize( & net_globals.netif_names);194 modules_initialize( & net_globals.modules);195 measured_strings_initialize( & net_globals.configuration);189 int net_initialize(async_client_conn_t client_connection){ 190 ERROR_DECLARE; 191 192 netifs_initialize(&net_globals.netifs); 193 char_map_initialize(&net_globals.netif_names); 194 modules_initialize(&net_globals.modules); 195 measured_strings_initialize(&net_globals.configuration); 196 196 197 197 // TODO dynamic configuration 198 ERROR_PROPAGATE( 199 200 ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));201 ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));202 ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service));203 ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service));198 ERROR_PROPAGATE(read_configuration()); 199 200 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service)); 201 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service)); 202 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service)); 203 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service)); 204 204 205 205 // build specific initialization 206 return net_initialize_build( client_connection ); 207 } 208 209 int net_get_device_conf_req( int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data ){ 210 netif_ref netif; 211 212 if( !( configuration && ( count > 0 ))) return EINVAL; 213 netif = netifs_find( & net_globals.netifs, device_id ); 214 if( netif ){ 215 return net_get_conf( & netif->configuration, * configuration, count, data ); 206 return net_initialize_build(client_connection); 207 } 208 209 int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){ 210 netif_ref netif; 211 212 if(!(configuration && (count > 0))){ 213 return EINVAL; 214 } 215 netif = netifs_find(&net_globals.netifs, device_id); 216 if(netif){ 217 return net_get_conf(&netif->configuration, * configuration, count, data); 216 218 }else{ 217 return net_get_conf( NULL, * configuration, count, data ); 218 } 219 } 220 221 int net_get_conf_req( int net_phone, measured_string_ref * configuration, size_t count, char ** data ){ 222 if( !( configuration && ( count > 0 ))) return EINVAL; 223 return net_get_conf( NULL, * configuration, count, data ); 224 } 225 226 int net_get_conf( measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data ){ 227 measured_string_ref setting; 228 size_t index; 229 230 if( data ) * data = NULL; 231 for( index = 0; index < count; ++ index ){ 232 setting = measured_strings_find( netif_conf, configuration[ index ].value, 0 ); 233 if( ! setting ){ 234 setting = measured_strings_find( & net_globals.configuration, configuration[ index ].value, 0 ); 235 } 236 if( setting ){ 237 configuration[ index ].length = setting->length; 238 configuration[ index ].value = setting->value; 219 return net_get_conf(NULL, * configuration, count, data); 220 } 221 } 222 223 int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){ 224 if(!(configuration && (count > 0))){ 225 return EINVAL; 226 } 227 return net_get_conf(NULL, * configuration, count, data); 228 } 229 230 int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data){ 231 measured_string_ref setting; 232 size_t index; 233 234 if(data){ 235 *data = NULL; 236 } 237 for(index = 0; index < count; ++ index){ 238 setting = measured_strings_find(netif_conf, configuration[index].value, 0); 239 if(! setting){ 240 setting = measured_strings_find(&net_globals.configuration, configuration[index].value, 0); 241 } 242 if(setting){ 243 configuration[index].length = setting->length; 244 configuration[index].value = setting->value; 239 245 }else{ 240 configuration[ index].length = 0;241 configuration[ index].value = NULL;242 } 243 } 244 return EOK; 245 } 246 247 void net_free_settings( measured_string_ref settings, char * data){248 } 249 250 int net_connect_module( services_t service){251 return EOK; 252 } 253 254 int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){255 ERROR_DECLARE; 256 257 measured_string_ref 258 char * 259 260 * 261 switch( IPC_GET_METHOD( * call)){246 configuration[index].length = 0; 247 configuration[index].value = NULL; 248 } 249 } 250 return EOK; 251 } 252 253 void net_free_settings(measured_string_ref settings, char * data){ 254 } 255 256 int net_connect_module(services_t service){ 257 return EOK; 258 } 259 260 int net_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 261 ERROR_DECLARE; 262 263 measured_string_ref strings; 264 char * data; 265 266 *answer_count = 0; 267 switch(IPC_GET_METHOD(*call)){ 262 268 case IPC_M_PHONE_HUNGUP: 263 269 return EOK; 264 270 case NET_NET_GET_DEVICE_CONF: 265 ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call)));266 net_get_device_conf_req( 0, IPC_GET_DEVICE( call ), & strings, IPC_GET_COUNT( call ), NULL);271 ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call))); 272 net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings, IPC_GET_COUNT(call), NULL); 267 273 // strings should not contain received data anymore 268 free( data);269 ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call));270 free( strings);274 free(data); 275 ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call)); 276 free(strings); 271 277 return ERROR_CODE; 272 278 case NET_NET_GET_CONF: 273 ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call)));274 net_get_conf_req( 0, & strings, IPC_GET_COUNT( call ), NULL);279 ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call))); 280 net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL); 275 281 // strings should not contain received data anymore 276 free( data);277 ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call));278 free( strings);282 free(data); 283 ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call)); 284 free(strings); 279 285 return ERROR_CODE; 280 286 case NET_NET_STARTUP: … … 284 290 } 285 291 286 int read_configuration_file( const char * directory, const char * filename, measured_strings_ref configuration){287 ERROR_DECLARE; 288 289 size_t 290 char line[ BUFFER_SIZE];291 FILE * 292 int 293 int 292 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration){ 293 ERROR_DECLARE; 294 295 size_t index = 0; 296 char line[BUFFER_SIZE]; 297 FILE * cfg; 298 int read; 299 int line_number = 0; 294 300 295 301 // 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){302 printf("Reading file %s/%s\n", directory, filename); 303 if(snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE){ 298 304 return EOVERFLOW; 299 305 } 300 306 // open the file 301 cfg = fopen( line, "r");302 if( ! cfg){307 cfg = fopen(line, "r"); 308 if(! cfg){ 303 309 return ENOENT; 304 310 } … … 306 312 // read the configuration line by line 307 313 // 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 while((! ferror(cfg)) && (! feof(cfg))){ 315 read = fgetc(cfg); 316 if((read > 0) && (read != '\n') && (read != '\r')){ 317 if(index >= BUFFER_SIZE){ 318 line[BUFFER_SIZE - 1] = '\0'; 319 printf("line %d too long: %s\n", line_number, line); 314 320 // no space left in the line buffer 315 321 return EOVERFLOW; 316 322 }else{ 317 323 // append the character 318 line[ index] = (char) read;324 line[index] = (char) read; 319 325 ++ index; 320 326 } 321 327 }else{ 322 328 // on error or new line 323 line[ index] = '\0';329 line[index] = '\0'; 324 330 ++ line_number; 325 if( ERROR_OCCURRED( parse_line( configuration, line))){326 printf( "error on line %d: %s\n", line_number, line);327 //fclose( cfg);331 if(ERROR_OCCURRED(parse_line(configuration, line))){ 332 printf("error on line %d: %s\n", line_number, line); 333 //fclose(cfg); 328 334 //return ERROR_CODE; 329 335 } … … 331 337 } 332 338 } 333 fclose( cfg);334 return EOK; 335 } 336 337 int parse_line( measured_strings_ref configuration, char * line){338 ERROR_DECLARE; 339 340 measured_string_ref 341 char * 342 char * 339 fclose(cfg); 340 return EOK; 341 } 342 343 int parse_line(measured_strings_ref configuration, char * line){ 344 ERROR_DECLARE; 345 346 measured_string_ref setting; 347 char * name; 348 char * value; 343 349 344 350 // from the beginning … … 346 352 347 353 // skip comments and blank lines 348 if(( * name == '#' ) || ( * name == '\0')){354 if((*name == '#') || (*name == '\0')){ 349 355 return EOK; 350 356 } 351 357 // skip spaces 352 while( isspace( * name )) ++ name; 358 while(isspace(*name)){ 359 ++ name; 360 } 353 361 354 362 // remember the name start 355 363 value = name; 356 364 // skip the name 357 while( isalnum( * value ) || ( * value == '_')){365 while(isalnum(*value) || (*value == '_')){ 358 366 // make uppercase 359 // * value = toupper( * value);367 // *value = toupper(*value); 360 368 ++ value; 361 369 } 362 370 363 if( * value == '='){371 if(*value == '='){ 364 372 // terminate the name 365 * 373 *value = '\0'; 366 374 }else{ 367 375 // terminate the name 368 * 376 *value = '\0'; 369 377 // skip until '=' 370 378 ++ value; 371 while(( * value ) && ( * value != '=' )) ++ value; 379 while((*value) && (*value != '=')){ 380 ++ value; 381 } 372 382 // not found? 373 if( * value != '=' ) return EINVAL; 383 if(*value != '='){ 384 return EINVAL; 385 } 374 386 } 375 387 376 388 ++ value; 377 389 // skip spaces 378 while( isspace( * value )) ++ value; 390 while(isspace(*value)){ 391 ++ value; 392 } 379 393 // create a bulk measured string till the end 380 setting = measured_string_create_bulk( value, 0 ); 381 if( ! setting ) return ENOMEM; 394 setting = measured_string_create_bulk(value, 0); 395 if(! setting){ 396 return ENOMEM; 397 } 382 398 383 399 // add the configuration setting 384 if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting))){385 free( setting);400 if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){ 401 free(setting); 386 402 return ERROR_CODE; 387 403 } … … 389 405 } 390 406 391 int add_configuration( measured_strings_ref configuration, const char * name, const char * value ){ 392 ERROR_DECLARE; 393 394 measured_string_ref setting; 395 396 setting = measured_string_create_bulk( value, 0 ); 397 if( ! setting ) return ENOMEM; 407 int add_configuration(measured_strings_ref configuration, const char * name, const char * value){ 408 ERROR_DECLARE; 409 410 measured_string_ref setting; 411 412 setting = measured_string_create_bulk(value, 0); 413 if(! setting){ 414 return ENOMEM; 415 } 398 416 // add the configuration setting 399 if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting))){400 free( setting);417 if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){ 418 free(setting); 401 419 return ERROR_CODE; 402 420 } … … 404 422 } 405 423 406 device_id_t generate_new_device_id( void){424 device_id_t generate_new_device_id(void){ 407 425 return device_assign_devno(); 408 426 } 409 427 410 int read_configuration( void){428 int read_configuration(void){ 411 429 // read the general configuration file 412 return read_configuration_file( CONF_DIR, CONF_GENERAL_FILE, & net_globals.configuration);413 } 414 415 int read_netif_configuration( const char * name, netif_ref netif){430 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration); 431 } 432 433 int read_netif_configuration(const char * name, netif_ref netif){ 416 434 // read the netif configuration file 417 return read_configuration_file( CONF_DIR, name, & netif->configuration);418 } 419 420 int start_device( netif_ref netif){421 ERROR_DECLARE; 422 423 measured_string_ref 424 services_t 425 int 426 int 427 int 435 return read_configuration_file(CONF_DIR, name, &netif->configuration); 436 } 437 438 int start_device(netif_ref netif){ 439 ERROR_DECLARE; 440 441 measured_string_ref setting; 442 services_t internet_service; 443 int irq; 444 int io; 445 int mtu; 428 446 429 447 // mandatory netif 430 setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0);431 netif->driver = get_running_module( & net_globals.modules, setting->value);432 if( ! netif->driver){433 printf( "Failed to start the network interface driver %s\n", setting->value);448 setting = measured_strings_find(&netif->configuration, CONF_NETIF, 0); 449 netif->driver = get_running_module(&net_globals.modules, setting->value); 450 if(! netif->driver){ 451 printf("Failed to start the network interface driver %s\n", setting->value); 434 452 return EINVAL; 435 453 } 436 454 // optional network interface layer 437 setting = measured_strings_find( & netif->configuration, CONF_NIL, 0);438 if( setting){439 netif->nil = get_running_module( & net_globals.modules, setting->value);440 if( ! netif->nil){441 printf( "Failed to start the network interface layer %s\n", setting->value);455 setting = measured_strings_find(&netif->configuration, CONF_NIL, 0); 456 if(setting){ 457 netif->nil = get_running_module(&net_globals.modules, setting->value); 458 if(! netif->nil){ 459 printf("Failed to start the network interface layer %s\n", setting->value); 442 460 return EINVAL; 443 461 } … … 446 464 } 447 465 // mandatory internet layer 448 setting = measured_strings_find( & netif->configuration, CONF_IL, 0);449 netif->il = get_running_module( & net_globals.modules, setting->value);450 if( ! netif->il){451 printf( "Failed to start the internet layer %s\n", setting->value);466 setting = measured_strings_find(&netif->configuration, CONF_IL, 0); 467 netif->il = get_running_module(&net_globals.modules, setting->value); 468 if(! netif->il){ 469 printf("Failed to start the internet layer %s\n", setting->value); 452 470 return EINVAL; 453 471 } 454 472 // end of the static loopback initialization 455 473 // startup the loopback interface 456 setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0);457 irq = setting ? strtol( setting->value, NULL, 10) : 0;458 setting = measured_strings_find( & netif->configuration, CONF_IO, 0);459 io = setting ? strtol( setting->value, NULL, 16) : 0;460 ERROR_PROPAGATE( netif_probe_req( netif->driver->phone, netif->id, irq, io));461 if( netif->nil){462 setting = measured_strings_find( & netif->configuration, CONF_MTU, 0);463 if( ! setting){464 setting = measured_strings_find( & net_globals.configuration, CONF_MTU, 0);465 } 466 mtu = setting ? strtol( setting->value, NULL, 10) : 0;467 ERROR_PROPAGATE( nil_device_req( netif->nil->phone, netif->id, mtu, netif->driver->service));474 setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0); 475 irq = setting ? strtol(setting->value, NULL, 10) : 0; 476 setting = measured_strings_find(&netif->configuration, CONF_IO, 0); 477 io = setting ? strtol(setting->value, NULL, 16) : 0; 478 ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io)); 479 if(netif->nil){ 480 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0); 481 if(! setting){ 482 setting = measured_strings_find(&net_globals.configuration, CONF_MTU, 0); 483 } 484 mtu = setting ? strtol(setting->value, NULL, 10) : 0; 485 ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu, netif->driver->service)); 468 486 internet_service = netif->nil->service; 469 487 }else{ 470 488 internet_service = netif->driver->service; 471 489 } 472 switch( netif->il->service){490 switch(netif->il->service){ 473 491 case SERVICE_IP: 474 ERROR_PROPAGATE( ip_device_req( netif->il->phone, netif->id, internet_service));492 ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id, internet_service)); 475 493 break; 476 494 default: 477 495 return ENOENT; 478 496 } 479 ERROR_PROPAGATE( netif_start_req( netif->driver->phone, netif->id));480 return EOK; 481 } 482 483 int startup( void){497 ERROR_PROPAGATE(netif_start_req(netif->driver->phone, netif->id)); 498 return EOK; 499 } 500 501 int startup(void){ 484 502 ERROR_DECLARE; 485 503 486 504 #ifdef CONFIG_NETIF_DP8390 487 const char * conf_files[] = { "lo", "ne2k"};505 const char * conf_files[] = {"lo", "ne2k"}; 488 506 #else 489 const char * conf_files[] = { "lo"};507 const char * conf_files[] = {"lo"}; 490 508 #endif 491 509 492 int count = sizeof( conf_files ) / sizeof( char * ); 493 int index; 494 netif_ref netif; 495 int i; 496 measured_string_ref setting; 497 498 for( i = 0; i < count; ++ i ){ 499 netif = ( netif_ref ) malloc( sizeof( netif_t )); 500 if( ! netif ) return ENOMEM; 510 int count = sizeof(conf_files) / sizeof(char *); 511 int index; 512 netif_ref netif; 513 int i; 514 measured_string_ref setting; 515 516 for(i = 0; i < count; ++ i){ 517 netif = (netif_ref) malloc(sizeof(netif_t)); 518 if(! netif){ 519 return ENOMEM; 520 } 501 521 502 522 netif->id = generate_new_device_id(); 503 if( ! netif->id ) return EXDEV; 504 ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration )); 523 if(! netif->id){ 524 return EXDEV; 525 } 526 ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration)); 505 527 // read configuration files 506 if( ERROR_OCCURRED( read_netif_configuration( conf_files[ i ], netif))){507 measured_strings_destroy( & netif->configuration);508 free( netif);528 if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){ 529 measured_strings_destroy(&netif->configuration); 530 free(netif); 509 531 return ERROR_CODE; 510 532 } 511 533 // mandatory name 512 setting = measured_strings_find( & netif->configuration, CONF_NAME, 0);513 if( ! setting){514 printf( "The name is missing\n");515 measured_strings_destroy( & netif->configuration);516 free( netif);534 setting = measured_strings_find(&netif->configuration, CONF_NAME, 0); 535 if(! setting){ 536 printf("The name is missing\n"); 537 measured_strings_destroy(&netif->configuration); 538 free(netif); 517 539 return EINVAL; 518 540 } 519 541 netif->name = setting->value; 520 542 // add to the netifs map 521 index = netifs_add( & net_globals.netifs, netif->id, netif);522 if( index < 0){523 measured_strings_destroy( & netif->configuration);524 free( netif);543 index = netifs_add(&net_globals.netifs, netif->id, netif); 544 if(index < 0){ 545 measured_strings_destroy(&netif->configuration); 546 free(netif); 525 547 return index; 526 548 } 527 549 // add to the netif names map 528 if( ERROR_OCCURRED( char_map_add( & net_globals.netif_names, netif->name, 0, index))550 if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index)) 529 551 // start network interfaces and needed modules 530 || ERROR_OCCURRED( start_device( netif))){531 measured_strings_destroy( & netif->configuration);532 netifs_exclude_index( & net_globals.netifs, index);552 || ERROR_OCCURRED(start_device(netif))){ 553 measured_strings_destroy(&netif->configuration); 554 netifs_exclude_index(&net_globals.netifs, index); 533 555 return ERROR_CODE; 534 556 } 535 557 // increment modules' usage 536 558 ++ netif->driver->usage; 537 if( netif->nil ) ++ netif->nil->usage; 559 if(netif->nil){ 560 ++ netif->nil->usage; 561 } 538 562 ++ netif->il->usage; 539 printf( "New network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s\n", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name);563 printf("New network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s\n", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name); 540 564 } 541 565 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.