Subversion Repositories HelenOS

Rev

Rev 4197 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2009 Lukas Mejdrech
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup net
  30.  *  @{
  31.  */
  32.  
  33. /** @file
  34.  */
  35.  
  36. #include <async.h>
  37. #include <ctype.h>
  38. #include <ddi.h>
  39. #include <errno.h>
  40. #include <malloc.h>
  41. #include <stdio.h>
  42.  
  43. #include <ipc/ipc.h>
  44. #include <ipc/services.h>
  45.  
  46. #include "../err.h"
  47. #include "../messages.h"
  48. #include "../modules.h"
  49. //#include "../self_test.h"
  50.  
  51. #include "../structures/char_map.h"
  52. #include "../structures/generic_char_map.h"
  53. #include "../structures/measured_strings.h"
  54. #include "../structures/module_map.h"
  55. #include "../structures/packet/packet.h"
  56. #include "../structures/packet/packet_server.h"
  57.  
  58. #include "../il/ip/ip_messages.h"
  59. #include "../include/device.h"
  60. #include "../include/netif_messages.h"
  61.  
  62. #if IP_BUNDLE
  63.  
  64.     #include "../ip/ip_module.h"
  65.  
  66. #endif
  67.  
  68. #if TCP_BUNDLE
  69.  
  70.     #include "../tcp/tcp_module.h"
  71.  
  72. #endif
  73.  
  74. #define NAME    "Networking"
  75.  
  76. #define LO_NAME             "lo"
  77. #define LO_FILENAME         "/srv/lo"
  78. #define DP8390_NAME         "dp8390"
  79. #define DP8390_FILENAME     "/srv/dp8390"
  80. #define ETHERNET_NAME       "ethernet"
  81. #define ETHERNET_FILENAME   "/srv/eth"
  82. #define IP_NAME             "ip"
  83. #define IP_FILENAME         "/srv/ip"
  84.  
  85. #define CONF_NAME           "NAME"
  86. #define CONF_NETIF          "NETIF"
  87. #define CONF_NIL            "NIL"
  88. #define CONF_IL             "IL"
  89. #define CONF_IRQ            "IRQ"
  90. #define CONF_IO             "IO"
  91. #define CONF_MTU            "MTU"
  92.  
  93. #define IPC_GET_DEVICE( call )  ( device_id_t ) IPC_GET_ARG1( * call )
  94. #define IPC_GET_COUNT( call )   ( int ) IPC_GET_ARG2( * call )
  95.  
  96. typedef struct netif        netif_t;
  97. typedef netif_t *       netif_ref;
  98.  
  99. typedef struct networking_globals   networking_globals_t;
  100.  
  101. DEVICE_MAP_DECLARE( netifs, netif_t )
  102.  
  103. GENERIC_CHAR_MAP_DECLARE( measured_strings, measured_string_t )
  104.  
  105. /** A present network interface device.
  106.  */
  107. struct netif{
  108.     /** A system-unique network interface identifier.
  109.      */
  110.     device_id_t     id;
  111.     /** A serving network interface driver module index.
  112.      */
  113.     module_ref      driver;
  114.     /** A serving link layer module index.
  115.      */
  116.     module_ref      nil;
  117.     /** A serving internet layer module index.
  118.      */
  119.     module_ref      il;
  120.     /** A system-unique network interface name.
  121.      */
  122.     char *          name;
  123.     /** Configuration.
  124.      */
  125.     measured_strings_t  configuration;
  126. };
  127.  
  128. /** A networking module global variables.
  129.  */
  130. struct networking_globals{
  131.     /** Present network interfaces.
  132.      */
  133.     netifs_t        netifs;
  134.     /** Network interface structure indices by names.
  135.      */
  136.     char_map_t      netif_names;
  137.     /** Available modules.
  138.      */
  139.     modules_t       modules;
  140.     /** Global configuration.
  141.      */
  142.     measured_strings_t  configuration;
  143. };
  144.  
  145. void    networking_print_name( void );
  146. measured_string_ref configuration_find( measured_strings_ref configuration, const char * name );
  147. int networking_start_module( async_client_conn_t client_connection );
  148. int     networking_initialize( void );
  149. int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
  150. int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
  151. //int       parse_line( measured_strings_ref configuration, char * line );
  152. int     add_configuration( measured_strings_ref configuration, const char * name, const char * value );
  153. int     read_configuration( void );
  154. int     read_netif_configuration( char * name, netif_ref netif );
  155. int     start_device( netif_ref netif );
  156. int     startup( void );
  157. device_id_t generate_new_device_id( void );
  158.  
  159. static networking_globals_t networking_globals;
  160.  
  161. DEVICE_MAP_IMPLEMENT( netifs, netif_t )
  162.  
  163. GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t )
  164.  
  165. void networking_print_name( void ){
  166.     printf( "%s", NAME );
  167. }
  168.  
  169. int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
  170. #ifdef NETWORKING_module
  171.         //TODO map to *_message
  172.         if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){
  173.             return ip_message( callid, call, answer, answer_count );
  174. /*      }else if( IS_NET_ARP_MESSAGE( call )){
  175.             return arp_message( callid, call, answer, answer_count );
  176. *//*        }else if( IS_NET_RARP_MESSAGE( call )){
  177.             return rarp_message( callid, call, answer, answer_count );
  178. *//*        }else if( IS_NET_ICMP_MESSAGE( call )){
  179.             return icmp_message( callid, call, answer, answer_count );
  180. *//*        }else if( IS_NET_UDP_MESSAGE( call )){
  181.             return udp_message( callid, call, answer, answer_count );
  182. */      }else if( IS_NET_TCP_MESSAGE( call )){
  183.             return tcp_message( callid, call, answer, answer_count );
  184. /*      }else if( IS_NET_SOCKET_MESSAGE( call )){
  185.             return socket_message( callid, call, answer, answer_count );
  186. *//*        }else if( IS_NET_NIL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){
  187.             return ethernet_message( callid, call, answer, answer_count );
  188. */      }else{
  189. #endif
  190.             if( IS_NET_PACKET_MESSAGE( call )){
  191.                 return packet_server_message( callid, call, answer, answer_count );
  192.             }else{
  193.                 return net_message( callid, call, answer, answer_count );
  194.             }
  195. #ifdef NETWORKING_module
  196.         }
  197. #endif
  198. }
  199.  
  200. int networking_start_module( async_client_conn_t client_connection ){
  201.     ERROR_DECLARE;
  202.  
  203.     ipcarg_t    phonehash;
  204.  
  205.     async_set_client_connection( client_connection );
  206.     ERROR_PROPAGATE( pm_init());
  207.     if( ERROR_OCCURRED( networking_initialize())
  208.     || ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){
  209.         pm_destroy();
  210.         return ERROR_CODE;
  211.     }
  212.  
  213.     async_manager();
  214.  
  215.     pm_destroy();
  216.     return EOK;
  217. }
  218.  
  219. int networking_initialize( void ){
  220.     ERROR_DECLARE;
  221.  
  222.     task_id_t   task_id;
  223.  
  224.     netifs_initialize( & networking_globals.netifs );
  225.     char_map_initialize( & networking_globals.netif_names );
  226.     modules_initialize( & networking_globals.modules );
  227.     measured_strings_initialize( & networking_globals.configuration );
  228.  
  229.     // run self tests
  230. //  ERROR_PROPAGATE( self_test());
  231.  
  232.     ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0 ));
  233.     ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0 ));
  234.     ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0 ));
  235.  
  236. #ifdef NETWORKING_modular
  237.     task_id = spawn( "/srv/ip" );
  238.     if( ! task_id ) return EINVAL;
  239.     ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id ));
  240. //  if( ! spawn( "/srv/udp" )) return EINVAL;
  241. //  if( ! spawn( "/srv/tcp" )) return EINVAL;
  242. //  if( ! spawn( "/srv/socket" )) return EINVAL;
  243. //  not always necesssary
  244. //  if( ! spawn( "/srv/arp" )) return EINVAL;
  245. //  if( ! spawn( "/srv/rarp" )) return EINVAL;
  246. //  if( ! spawn( "/srv/icmp" )) return EINVAL;
  247.  
  248. #else
  249. #ifdef NETWORKING_module
  250.     ipcarg_t    phonehash;
  251.  
  252.     ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
  253.     ERROR_PROPAGATE( add_module( NULL, & networking_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id()));
  254.     ERROR_PROPAGATE( ip_initialize());
  255. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash ));
  256. //  ERROR_PROPAGATE( arp_initialize());
  257. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash ));
  258. //  ERROR_PROPAGATE( rarp_initialize());
  259. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash ));
  260. //  ERROR_PROPAGATE( icmp_initialize());
  261. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash ));
  262. //  ERROR_PROPAGATE( udp_initialize());
  263.     ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash ));
  264.     ERROR_PROPAGATE( tcp_initialize());
  265. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash ));
  266. //  ERROR_PROPAGATE( socket_initialize());
  267. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash ));
  268. //  ERROR_PROPAGATE( ethernet_initialize());
  269. #endif
  270. #endif
  271.  
  272.     return EOK;
  273. }
  274.  
  275. //TODO as ip.c
  276. int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
  277.     ERROR_DECLARE;
  278.  
  279.     measured_string_ref strings;
  280.     char *          data;
  281.     int         index;
  282.     measured_string_ref setting;
  283.     measured_strings_ref    configuration;
  284.     netif_ref       netif;
  285.  
  286.     * answer_count = 0;
  287.     switch( IPC_GET_METHOD( * call )){
  288.         case IPC_M_PHONE_HUNGUP:
  289.             return EOK;
  290.         case NET_NET_DEVICE:
  291.             // TODO configure, register
  292.             printf( "\nNetworking: new netif %d", IPC_GET_DEVICE( call ));
  293.             return EOK;
  294.         case NET_NET_GET_DEVICE_CONF:
  295.             ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
  296.             netif = netifs_find( & networking_globals.netifs, IPC_GET_DEVICE( call ));
  297.             if( netif ){
  298.                 configuration = & netif->configuration;
  299.             }else{
  300.                 configuration = NULL;
  301.             }
  302.             for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
  303.                 setting = measured_strings_find( configuration, strings[ index ].value, 0 );
  304.                 if( ! setting ){
  305.                     setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
  306.                 }
  307.                 if( setting ){
  308.                     strings[ index ].length = setting->length;
  309.                     strings[ index ].value = setting->value;
  310.                 }else{
  311.                     strings[ index ].length = 0;
  312.                     strings[ index ].value = NULL;
  313.                 }
  314.             }
  315.             // strings should not contain received data anymore
  316.             free( data );
  317.             ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
  318.             free( strings );
  319.             return ERROR_CODE;
  320.         case NET_NET_GET_CONF:
  321.             // arg1 = count
  322.             ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
  323.             for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
  324.                 setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
  325.                 if( setting ){
  326.                     strings[ index ].length = setting->length;
  327.                     strings[ index ].value = setting->value;
  328.                 }else{
  329.                     strings[ index ].length = 0;
  330.                     strings[ index ].value = NULL;
  331.                 }
  332.             }
  333.             // strings should not contain received data anymore
  334.             free( data );
  335.             ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
  336.             free( strings );
  337.             return ERROR_CODE;
  338.         case NET_NET_STARTUP:
  339.             return startup();
  340.     }
  341.     return ENOTSUP;
  342. }
  343.  
  344. /*
  345. int parse_line( measured_strings_ref configuration, char * line ){
  346.     ERROR_DECLARE;
  347.  
  348.     measured_string_ref setting;
  349.     char *          name;
  350.     char *          value;
  351.  
  352.     // from the beginning
  353.     name = line;
  354.     // skip spaces
  355.     while( isspace( * name )) ++ name;
  356.     // remember the name start
  357.     value = name;
  358.     // skip the name
  359.     while( isalnum( * value ) || ( * value == '_' )){
  360.         // make uppercase
  361. //      * value = toupper( * value );
  362.         ++ value;
  363.     }
  364.     if( * value == '=' ){
  365.         // terminate the name
  366.         * value = '\0';
  367.     }else{
  368.         // terminate the name
  369.         * value = '\0';
  370.         // skip until '='
  371.         ++ value;
  372.         while(( * value ) && ( * value != '=' )) ++ value;
  373.         // not found?
  374.         if( * value != '=' ) return EINVAL;
  375.     }
  376.     ++ value;
  377.     // skip spaces
  378.     while( isspace( * value )) ++ value;
  379.     // create a bulk measured string till the end
  380.     setting = measured_string_create_bulk( value, -1 );
  381.     if( ! setting ) return ENOMEM;
  382.     // add the configuration setting
  383.     if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){
  384.         free( setting );
  385.         return ERROR_CODE;
  386.     }
  387.     return EOK;
  388. }
  389. */
  390.  
  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;
  398.     // add the configuration setting
  399.     if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){
  400.         free( setting );
  401.         return ERROR_CODE;
  402.     }
  403.     return EOK;
  404. }
  405.  
  406. device_id_t generate_new_device_id( void ){
  407.     return device_assign_devno();
  408. }
  409.  
  410. int read_configuration( void ){
  411.     ERROR_DECLARE;
  412.  
  413.     // read general configuration
  414.     ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "IPV", "4" ));
  415.     ERROR_PROPAGATE( add_configuration( & networking_globals.configuration, "MTU", "1500" ));
  416.     return EOK;
  417. }
  418.  
  419. int read_netif_configuration( char * name, netif_ref netif ){
  420.     ERROR_DECLARE;
  421.  
  422.     if( strncmp( name, "lo", 2 ) == 0 ){
  423.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME ));
  424.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME ));
  425.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME ));
  426.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" ));
  427.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" ));
  428.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ));
  429.     }else if( strncmp( name, "ne2k", 4 ) == 0 ){
  430.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" ));
  431.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME ));
  432.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME ));
  433.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME ));
  434.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" ));
  435.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" ));
  436.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" ));
  437.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" ));
  438.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.5" ));
  439.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.0" ));
  440.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" ));
  441.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" ));
  442.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" ));
  443.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" ));
  444.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" ));
  445.     }
  446.     return EOK;
  447. }
  448.  
  449. int start_device( netif_ref netif ){
  450.     ERROR_DECLARE;
  451.  
  452.     measured_string_ref setting;
  453.     services_t          internet_service;
  454.     int                 irq;
  455.     int                 io;
  456.     int                 mtu;
  457.  
  458.     // mandatory netif
  459.     setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0 );
  460.     netif->driver = get_running_module( & networking_globals.modules, setting->value );
  461.     if( ! netif->driver ){
  462.         printf( "\nFailed to start the network interface driver %s", setting->value );
  463.         return EINVAL;
  464.     }
  465.     // optional network interface layer
  466.     setting = measured_strings_find( & netif->configuration, CONF_NIL, 0 );
  467.     if( setting ){
  468.         netif->nil = get_running_module( & networking_globals.modules, setting->value );
  469.         if( ! netif->nil ){
  470.             printf( "\nFailed to start the network interface layer %s", setting->value );
  471.             return EINVAL;
  472.         }
  473.     }else{
  474.         netif->nil = NULL;
  475.     }
  476.     // mandatory internet layer
  477.     setting = measured_strings_find( & netif->configuration, CONF_IL, 0 );
  478.     netif->il = get_running_module( & networking_globals.modules, setting->value );
  479.     if( ! netif->il ){
  480.         printf( "\nFailed to start the internet layer %s", setting->value );
  481.         return EINVAL;
  482.     }
  483.     // end of the static loopback initialization
  484.     // startup the loopback interface
  485.     setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0 );
  486.     irq = setting ? strtol( setting->value, NULL, 10 ) : 0;
  487.     setting = measured_strings_find( & netif->configuration, CONF_IO, 0 );
  488.     io = setting ? strtol( setting->value, NULL, 16 ) : 0;
  489.     ERROR_PROPAGATE( netif_probe_req( netif->driver->phone, netif->id, irq, io ));
  490.     if( netif->nil ){
  491.         setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 );
  492.         if( ! setting ){
  493.             setting = measured_strings_find( & networking_globals.configuration, CONF_MTU, 0 );
  494.         }
  495.         mtu = setting ? strtol( setting->value, NULL, 10 ) : 0;
  496.         ERROR_PROPAGATE( async_req_3_0( netif->nil->phone, NET_NIL_DEVICE, netif->id, mtu, netif->driver->service ));
  497.         internet_service = netif->nil->service;
  498.     }else{
  499.         internet_service = netif->driver->service;
  500.     }
  501.     // TODO IL_BUNDLE
  502.     ERROR_PROPAGATE( async_req_2_0( netif->il->phone, NET_IL_DEVICE, netif->id, internet_service ));
  503.     ERROR_PROPAGATE( netif_start_req( netif->driver->phone, netif->id ));
  504.     return EOK;
  505. }
  506.  
  507. int startup( void ){
  508.     ERROR_DECLARE;
  509.  
  510.     char *      conf_files[] = { "lo", "ne2k" };
  511.     int         count = sizeof( conf_files ) / sizeof( char * );
  512.     int         index;
  513.     netif_ref   netif;
  514.     int         i;
  515.     measured_string_ref setting;
  516.  
  517.     // TODO dynamic configuration
  518.     ERROR_PROPAGATE( read_configuration());
  519.  
  520.     for( i = 0; i < count; ++ i ){
  521.         netif = ( netif_ref ) malloc( sizeof( netif_t ));
  522.         if( ! netif ) return ENOMEM;
  523.  
  524.         netif->id = generate_new_device_id();
  525.         if( ! netif->id ) return EXDEV;
  526.         ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration ));
  527.         // read configuration files
  528.         if( ERROR_OCCURRED( read_netif_configuration( conf_files[ i ], netif ))){
  529.             measured_strings_destroy( & netif->configuration );
  530.             free( netif );
  531.             return ERROR_CODE;
  532.         }
  533.         // mandatory name
  534.         setting = measured_strings_find( & netif->configuration, CONF_NAME, 0 );
  535.         if( ! setting ){
  536.             printf( "\nThe name is missing" );
  537.             measured_strings_destroy( & netif->configuration );
  538.             free( netif );
  539.             return EINVAL;
  540.         }
  541.         netif->name = setting->value;
  542.         // add to the netifs map
  543.         index = netifs_add( & networking_globals.netifs, netif->id, netif );
  544.         if( index < 0 ){
  545.             measured_strings_destroy( & netif->configuration );
  546.             free( netif );
  547.             return index;
  548.         }
  549.         // add to the netif names map
  550.         if( ERROR_OCCURRED( char_map_add( & networking_globals.netif_names, netif->name, 0, index ))
  551.         // start network interfaces and needed modules
  552.         || ERROR_OCCURRED( start_device( netif ))){
  553.             measured_strings_destroy( & netif->configuration );
  554.             netifs_exclude_index( & networking_globals.netifs, index );
  555.             return ERROR_CODE;
  556.         }
  557.         // increment modules' usage
  558.         ++ netif->driver->usage;
  559.         if( netif->nil ) ++ netif->nil->usage;
  560.         ++ netif->il->usage;
  561.         printf( "\nNew network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name );
  562.     }
  563.     return EOK;
  564. }
  565.  
  566. /** @}
  567.  */
  568.