Ignore:
File:
1 edited

Legend:

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

    r409f5fc rd0d1f4f  
    4242#include <ddi.h>
    4343#include <errno.h>
     44#include <err.h>
    4445#include <malloc.h>
    4546#include <stdio.h>
     
    9192    const char *value)
    9293{
    93         int rc;
     94        ERROR_DECLARE;
    9495       
    9596        measured_string_ref setting =
     
    99100       
    100101        /* Add the configuration setting */
    101         rc = measured_strings_add(configuration, name, 0, setting);
    102         if (rc != EOK) {
     102        if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
    103103                free(setting);
    104                 return rc;
     104                return ERROR_CODE;
    105105        }
    106106       
     
    110110/** Generate new system-unique device identifier.
    111111 *
    112  * @returns             The system-unique devic identifier.
     112 * @returns The system-unique devic identifier.
     113 *
    113114 */
    114115static device_id_t generate_new_device_id(void)
     
    119120static int parse_line(measured_strings_ref configuration, char *line)
    120121{
    121         int rc;
     122        ERROR_DECLARE;
    122123       
    123124        /* From the beginning */
     
    169170       
    170171        /* Add the configuration setting */
    171         rc = measured_strings_add(configuration, name, 0, setting);
    172         if (rc != EOK) {
     172        if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
    173173                free(setting);
    174                 return rc;
     174                return ERROR_CODE;
    175175        }
    176176       
     
    181181    measured_strings_ref configuration)
    182182{
     183        ERROR_DECLARE;
     184       
    183185        printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename);
    184186       
     
    204206                        if (index >= BUFFER_SIZE) {
    205207                                line[BUFFER_SIZE - 1] = '\0';
    206                                 fprintf(stderr, "%s: Configuration line %u too "
    207                                     "long: %s\n", NAME, line_number, line);
     208                                fprintf(stderr, "%s: Configuration line %u too long: %s\n",
     209                                    NAME, line_number, line);
    208210                               
    209211                                /* No space left in the line buffer */
    210212                                return EOVERFLOW;
     213                        } else {
     214                                /* Append the character */
     215                                line[index] = (char) read;
     216                                index++;
    211217                        }
    212                         /* Append the character */
    213                         line[index] = (char) read;
    214                         index++;
    215218                } else {
    216219                        /* On error or new line */
    217220                        line[index] = '\0';
    218221                        line_number++;
    219                         if (parse_line(configuration, line) != EOK) {
    220                                 fprintf(stderr, "%s: Configuration error on "
    221                                     "line %u: %s\n", NAME, line_number, line);
    222                         }
     222                        if (ERROR_OCCURRED(parse_line(configuration, line)))
     223                                fprintf(stderr, "%s: Configuration error on line %u: %s\n",
     224                                    NAME, line_number, line);
    223225                       
    224226                        index = 0;
     
    268270static int net_initialize(async_client_conn_t client_connection)
    269271{
    270         int rc;
     272        ERROR_DECLARE;
    271273       
    272274        netifs_initialize(&net_globals.netifs);
     
    276278       
    277279        // TODO: dynamic configuration
    278         rc = read_configuration();
    279         if (rc != EOK)
    280                 return rc;
    281        
    282         rc = add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME,
    283             SERVICE_LO, 0, connect_to_service);
    284         if (rc != EOK)
    285                 return rc;
    286         rc = add_module(NULL, &net_globals.modules, DP8390_NAME,
    287             DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service);
    288         if (rc != EOK)
    289                 return rc;
    290         rc = add_module(NULL, &net_globals.modules, ETHERNET_NAME,
    291             ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
    292         if (rc != EOK)
    293                 return rc;
    294         rc = add_module(NULL, &net_globals.modules, NILDUMMY_NAME,
    295             NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
    296         if (rc != EOK)
    297                 return rc;
     280        ERROR_PROPAGATE(read_configuration());
     281       
     282        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
     283            LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));
     284        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
     285            DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));
     286        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
     287            ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0,
     288            connect_to_service));
     289        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
     290            NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0,
     291            connect_to_service));
    298292       
    299293        /* Build specific initialization */
     
    320314static int net_module_start(async_client_conn_t client_connection)
    321315{
     316        ERROR_DECLARE;
     317       
     318        async_set_client_connection(client_connection);
     319        ERROR_PROPAGATE(pm_init());
     320       
    322321        ipcarg_t phonehash;
    323         int rc;
    324        
    325         async_set_client_connection(client_connection);
    326         rc = pm_init();
    327         if (rc != EOK)
    328                 return rc;
    329        
    330        
    331         rc = net_initialize(client_connection);
    332         if (rc != EOK)
    333                 goto out;
    334        
    335         rc = REGISTER_ME(SERVICE_NETWORKING, &phonehash);
    336         if (rc != EOK)
    337                 goto out;
     322       
     323        if (ERROR_OCCURRED(net_initialize(client_connection)) ||
     324            ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))) {
     325                pm_destroy();
     326                return ERROR_CODE;
     327        }
    338328       
    339329        async_manager();
    340 
    341 out:
     330       
    342331        pm_destroy();
    343         return rc;
     332        return EOK;
    344333}
    345334
     
    426415static int start_device(netif_t *netif)
    427416{
    428         int rc;
     417        ERROR_DECLARE;
    429418       
    430419        /* Mandatory netif */
     
    467456        int io = setting ? strtol(setting->value, NULL, 16) : 0;
    468457       
    469         rc = netif_probe_req_remote(netif->driver->phone, netif->id, irq, io);
    470         if (rc != EOK)
    471                 return rc;
     458        ERROR_PROPAGATE(netif_probe_req_remote(netif->driver->phone, netif->id, irq, io));
    472459       
    473460        /* Network interface layer startup */
     
    481468                int mtu = setting ? strtol(setting->value, NULL, 10) : 0;
    482469               
    483                 rc = nil_device_req(netif->nil->phone, netif->id, mtu,
    484                     netif->driver->service);
    485                 if (rc != EOK)
    486                         return rc;
     470                ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu,
     471                    netif->driver->service));
    487472               
    488473                internet_service = netif->nil->service;
     
    493478        switch (netif->il->service) {
    494479        case SERVICE_IP:
    495                 rc = ip_device_req(netif->il->phone, netif->id,
    496                     internet_service);
    497                 if (rc != EOK)
    498                         return rc;
     480                ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id,
     481                    internet_service));
    499482                break;
    500483        default:
     
    502485        }
    503486       
    504         return netif_start_req_remote(netif->driver->phone, netif->id);
     487        ERROR_PROPAGATE(netif_start_req_remote(netif->driver->phone, netif->id));
     488        return EOK;
    505489}
    506490
     
    520504static int startup(void)
    521505{
     506        ERROR_DECLARE;
     507       
    522508        const char *conf_files[] = {
    523509                "lo",
     
    525511        };
    526512        size_t count = sizeof(conf_files) / sizeof(char *);
    527         int rc;
    528513       
    529514        size_t i;
     
    537522                        return EXDEV;
    538523               
    539                 rc = measured_strings_initialize(&netif->configuration);
    540                 if (rc != EOK)
    541                         return rc;
     524                ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
    542525               
    543526                /* Read configuration files */
    544                 rc = read_netif_configuration(conf_files[i], netif);
    545                 if (rc != EOK) {
     527                if (ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))) {
    546528                        measured_strings_destroy(&netif->configuration);
    547529                        free(netif);
    548                         return rc;
     530                        return ERROR_CODE;
    549531                }
    550532               
     
    572554                 * and needed modules.
    573555                 */
    574                 rc = char_map_add(&net_globals.netif_names, netif->name, 0,
    575                     index);
    576                 if (rc != EOK) {
     556                if ((ERROR_OCCURRED(char_map_add(&net_globals.netif_names,
     557                    netif->name, 0, index))) || (ERROR_OCCURRED(start_device(netif)))) {
    577558                        measured_strings_destroy(&netif->configuration);
    578559                        netifs_exclude_index(&net_globals.netifs, index);
    579                         return rc;
    580                 }
    581                
    582                 rc = start_device(netif);
    583                 if (rc != EOK) {
    584                         measured_strings_destroy(&netif->configuration);
    585                         netifs_exclude_index(&net_globals.netifs, index);
    586                         return rc;
     560                        return ERROR_CODE;
    587561                }
    588562               
     
    620594    int *answer_count)
    621595{
     596        ERROR_DECLARE;
     597       
    622598        measured_string_ref strings;
    623599        char *data;
    624         int rc;
    625600       
    626601        *answer_count = 0;
     
    629604                return EOK;
    630605        case NET_NET_GET_DEVICE_CONF:
    631                 rc = measured_strings_receive(&strings, &data,
    632                     IPC_GET_COUNT(call));
    633                 if (rc != EOK)
    634                         return rc;
     606                ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
     607                    IPC_GET_COUNT(call)));
    635608                net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings,
    636609                    IPC_GET_COUNT(call), NULL);
     
    639612                free(data);
    640613               
    641                 rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
     614                ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
    642615                free(strings);
    643                 return rc;
     616                return ERROR_CODE;
    644617        case NET_NET_GET_CONF:
    645                 rc = measured_strings_receive(&strings, &data,
    646                     IPC_GET_COUNT(call));
    647                 if (rc != EOK)
    648                         return rc;
     618                ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
     619                    IPC_GET_COUNT(call)));
    649620                net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL);
    650621               
     
    652623                free(data);
    653624               
    654                 rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
     625                ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
    655626                free(strings);
    656                 return rc;
     627                return ERROR_CODE;
    657628        case NET_NET_STARTUP:
    658629                return startup();
    659630        }
    660        
    661631        return ENOTSUP;
    662632}
     
    700670int main(int argc, char *argv[])
    701671{
    702         int rc;
    703        
    704         rc = net_module_start(net_client_connection);
    705         if (rc != EOK) {
    706                 fprintf(stderr, "%s: net_module_start error %i\n", NAME, rc);
    707                 return rc;
     672        ERROR_DECLARE;
     673       
     674        if (ERROR_OCCURRED(net_module_start(net_client_connection))) {
     675                fprintf(stderr, "%s: net_module_start error %i\n", NAME, ERROR_CODE);
     676                return ERROR_CODE;
    708677        }
    709678       
Note: See TracChangeset for help on using the changeset viewer.