Changeset 01a9ef5 in mainline for uspace/srv/net/net/net.c


Ignore:
Timestamp:
2010-02-16T18:11:00Z (14 years ago)
Author:
Lukas Mejdrech <lukasmejdrech@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
209faf9, bfd7aac
Parents:
80ce111
Message:

+ net configuration files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/net/net.c

    r80ce111 r01a9ef5  
    7070#define NAME    "Networking"
    7171
     72/** File read buffer size.
     73 */
     74#define BUFFER_SIZE     256
     75
    7276/** Prints the module name.
    7377 *  @see NAME
     
    8488int module_start( async_client_conn_t client_connection );
    8589
    86 //int           parse_line( measured_strings_ref configuration, char * line );
     90/** \todo
     91 */
     92int     read_configuration_file( const char * directory, const char * filename, measured_strings_ref configuration );
     93
     94/** \todo
     95 */
     96int     parse_line( measured_strings_ref configuration, char * line );
    8797
    8898/** Reads the networking subsystem global configuration.
     
    274284}
    275285
    276 /*
     286int 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
    277337int parse_line( measured_strings_ref configuration, char * line ){
    278338        ERROR_DECLARE;
    279339
    280340        measured_string_ref     setting;
    281         char *                  name;
    282         char *                  value;
     341        char *                          name;
     342        char *                          value;
    283343
    284344        // from the beginning
    285345        name = line;
     346
     347        // skip comments and blank lines
     348        if(( * name == '#' ) || ( * name == '\0' )){
     349                return EOK;
     350        }
    286351        // skip spaces
    287352        while( isspace( * name )) ++ name;
     353
    288354        // remember the name start
    289355        value = name;
     
    294360                ++ value;
    295361        }
     362
    296363        if( * value == '=' ){
    297364                // terminate the name
     
    306373                if( * value != '=' ) return EINVAL;
    307374        }
     375
    308376        ++ value;
    309377        // skip spaces
    310378        while( isspace( * value )) ++ value;
    311379        // create a bulk measured string till the end
    312         setting = measured_string_create_bulk( value, -1 );
     380        setting = measured_string_create_bulk( value, 0 );
    313381        if( ! setting ) return ENOMEM;
     382
    314383        // add the configuration setting
    315384        if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){
     
    319388        return EOK;
    320389}
    321 */
    322390
    323391int add_configuration( measured_strings_ref configuration, const char * name, const char * value ){
     
    341409
    342410int 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 );
    354413}
    355414
    356415int 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 );
    385418}
    386419
     
    451484        ERROR_DECLARE;
    452485
     486#ifdef CONFIG_NETIF_DP8390
    453487        char *          conf_files[] = { "lo", "ne2k" };
     488#else
     489        char *          conf_files[] = { "lo" };
     490#endif
     491
    454492        int                     count = sizeof( conf_files ) / sizeof( char * );
    455493        int                     index;
Note: See TracChangeset for help on using the changeset viewer.