Changes in / [60ab6c3:71b00dcc] in mainline


Ignore:
Location:
uspace/srv/net
Files:
2 deleted
46 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/Doxyfile

    r60ab6c3 r71b00dcc  
    66DOXYFILE_ENCODING      = UTF-8
    77PROJECT_NAME           = "Networking and TCP/IP stack for HelenOS system"
    8 PROJECT_NUMBER         = ""
     8PROJECT_NUMBER         = "Master thesis 2009"
    99OUTPUT_DIRECTORY       = doc/
    1010CREATE_SUBDIRS         = YES
  • uspace/srv/net/Makefile

    r60ab6c3 r71b00dcc  
    2929include ../../../Makefile.config
    3030
    31 # keep netif drivers before nil modules
    32 # in order to support networking architectures build
    33 
    34 ifeq ($(CONFIG_NETIF_DP8390),y)
    35         DIRS = netif/dp8390
    36 else
    37         DIRS =
    38 endif
    39 
    40 DIRS += \
     31DIRS = \
    4132        netif/lo \
    4233        nil/eth \
     
    5647                tl/udp \
    5748                tl/tcp \
     49
     50ifeq ($(CONFIG_NETIF_DP8390),y)
     51        DIRS += netif/dp8390
     52endif
    5853
    5954DIRS_ALL = $(DIRS) $(DIRS_MODULAR)
  • uspace/srv/net/app/echo/echo.c

    r60ab6c3 r71b00dcc  
    5555#define NAME    "Echo"
    5656
    57 /** Prints the application help.
    58  */
    59 void echo_print_help(void);
    60 
    6157/** Module entry point.
    6258 *  Reads command line parameters and starts listenning.
     
    6662 */
    6763int main(int argc, char * argv[]);
     64
     65/** Prints the application help.
     66 */
     67void echo_print_help(void);
     68
     69/** Translates the character string to the protocol family number.
     70 *  @param[in] name The protocol family name.
     71 *  @returns The corresponding protocol family number.
     72 *  @returns EPFNOSUPPORTED if the protocol family is not supported.
     73 */
     74int echo_parse_protocol_family(const char * name);
     75
     76/** Translates the character string to the socket type number.
     77 *  @param[in] name The socket type name.
     78 *  @returns The corresponding socket type number.
     79 *  @returns ESOCKNOSUPPORTED if the socket type is not supported.
     80 */
     81int echo_parse_socket_type(const char * name);
    6882
    6983void echo_print_help(void){
     
    101115}
    102116
     117int echo_parse_protocol_family(const char * name){
     118        if(str_lcmp(name, "PF_INET", 7) == 0){
     119                return PF_INET;
     120        }else if(str_lcmp(name, "PF_INET6", 8) == 0){
     121                return PF_INET6;
     122        }
     123        return EPFNOSUPPORT;
     124}
     125
     126int echo_parse_socket_type(const char * name){
     127        if(str_lcmp(name, "SOCK_DGRAM", 11) == 0){
     128                return SOCK_DGRAM;
     129        }else if(str_lcmp(name, "SOCK_STREAM", 12) == 0){
     130                return SOCK_STREAM;
     131        }
     132        return ESOCKTNOSUPPORT;
     133}
     134
    103135int main(int argc, char * argv[]){
    104136        ERROR_DECLARE;
     
    106138        size_t size                     = 1024;
    107139        int verbose                     = 0;
    108         char * reply            = NULL;
    109         sock_type_t type        = SOCK_DGRAM;
     140        char * reply                    = NULL;
     141        sock_type_t type                        = SOCK_DGRAM;
    110142        int count                       = -1;
    111143        int family                      = PF_INET;
    112         uint16_t port           = 7;
     144        uint16_t port                   = 7;
    113145        int backlog                     = 3;
    114146
    115         socklen_t max_length                            = sizeof(struct sockaddr_in6);
     147        socklen_t max_length            = sizeof(struct sockaddr_in6);
    116148        uint8_t address_data[max_length];
    117         struct sockaddr * address                       = (struct sockaddr *) address_data;
     149        struct sockaddr * address               = (struct sockaddr *) address_data;
    118150        struct sockaddr_in * address_in         = (struct sockaddr_in *) address;
    119151        struct sockaddr_in6 * address_in6       = (struct sockaddr_in6 *) address;
     
    123155        int socket_id;
    124156        int listening_id;
    125         char * data;
     157        char *                          data;
    126158        size_t length;
    127159        int index;
     
    129161        int value;
    130162
    131         // print the program label
    132163        printf("Task %d - ", task_get_id());
    133164        printf("%s\n", NAME);
    134165
    135         // parse the command line arguments
    136166        for(index = 1; index < argc; ++ index){
    137167                if(argv[index][0] == '-'){
     
    144174                                        break;
    145175                                case 'f':
    146                                         ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
     176                                        ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, echo_parse_protocol_family));
    147177                                        break;
    148178                                case 'h':
     
    162192                                        break;
    163193                                case 't':
    164                                         ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
     194                                        ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, echo_parse_socket_type));
    165195                                        type = (sock_type_t) value;
    166196                                        break;
     
    168198                                        verbose = 1;
    169199                                        break;
    170                                 // long options with the double minus sign ('-')
    171200                                case '-':
    172201                                        if(str_lcmp(argv[index] + 2, "backlog=", 6) == 0){
     
    175204                                                ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "message count", 8));
    176205                                        }else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
    177                                                 ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
     206                                                ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, echo_parse_protocol_family));
    178207                                        }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
    179208                                                echo_print_help();
     
    188217                                                size = (value >= 0) ? (size_t) value : 0;
    189218                                        }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
    190                                                 ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
     219                                                ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, echo_parse_socket_type));
    191220                                                type = (sock_type_t) value;
    192221                                        }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
     
    210239        }
    211240
    212         // check the buffer size
    213241        if(size <= 0){
    214242                fprintf(stderr, "Receive size too small (%d). Using 1024 bytes instead.\n", size);
    215243                size = 1024;
    216244        }
    217         // size plus the terminating null (\0)
     245        // size plus terminating null (\0)
    218246        data = (char *) malloc(size + 1);
    219247        if(! data){
     
    222250        }
    223251
    224         // set the reply size if set
    225252        reply_length = reply ? str_length(reply) : 0;
    226253
    227         // prepare the address buffer
     254        listening_id = socket(family, type, 0);
     255        if(listening_id < 0){
     256                socket_print_error(stderr, listening_id, "Socket create: ", "\n");
     257                return listening_id;
     258        }
     259
    228260        bzero(address_data, max_length);
    229261        switch(family){
     
    243275        }
    244276
    245         // get a listening socket
    246277        listening_id = socket(family, type, 0);
    247278        if(listening_id < 0){
     
    250281        }
    251282
    252         // if the stream socket is used
    253283        if(type == SOCK_STREAM){
    254                 // check the backlog
    255284                if(backlog <= 0){
    256285                        fprintf(stderr, "Accepted sockets queue size too small (%d). Using 3 instead.\n", size);
    257286                        backlog = 3;
    258287                }
    259                 // set the backlog
    260288                if(ERROR_OCCURRED(listen(listening_id, backlog))){
    261289                        socket_print_error(stderr, ERROR_CODE, "Socket listen: ", "\n");
     
    264292        }
    265293
    266         // bind the listenning socket
    267294        if(ERROR_OCCURRED(bind(listening_id, address, addrlen))){
    268295                socket_print_error(stderr, ERROR_CODE, "Socket bind: ", "\n");
     
    276303        socket_id = listening_id;
    277304
    278         // do count times
    279         // or indefinitely if set to a negative value
    280305        while(count){
    281 
    282306                addrlen = max_length;
    283307                if(type == SOCK_STREAM){
    284                         // acceept a socket if the stream socket is used
    285308                        socket_id = accept(listening_id, address, &addrlen);
    286309                        if(socket_id <= 0){
     
    292315                        }
    293316                }
    294 
    295                 // if the datagram socket is used or the stream socked was accepted
    296317                if(socket_id > 0){
    297 
    298                         // receive an echo request
    299318                        value = recvfrom(socket_id, data, size, 0, address, &addrlen);
    300319                        if(value < 0){
     
    303322                                length = (size_t) value;
    304323                                if(verbose){
    305                                         // print the header
    306 
    307                                         // get the source port and prepare the address buffer
    308324                                        address_start = NULL;
    309325                                        switch(address->sa_family){
     
    319335                                                        fprintf(stderr, "Address family %d (0x%X) is not supported.\n", address->sa_family);
    320336                                        }
    321                                         // parse the source address
    322337                                        if(address_start){
    323338                                                if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){
     
    329344                                        }
    330345                                }
    331 
    332                                 // answer the request either with the static reply or the original data
    333346                                if(ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen))){
    334347                                        socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
    335348                                }
    336 
    337                         }
    338 
    339                         // close the accepted stream socket
     349                        }
    340350                        if(type == SOCK_STREAM){
    341351                                if(ERROR_OCCURRED(closesocket(socket_id))){
     
    343353                                }
    344354                        }
    345 
    346                 }
    347 
    348                 // decrease the count if positive
     355                }
    349356                if(count > 0){
    350357                        -- count;
     
    359366        }
    360367
    361         // close the listenning socket
    362368        if(ERROR_OCCURRED(closesocket(listening_id))){
    363369                socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n");
  • uspace/srv/net/app/nettest1/Makefile

    r60ab6c3 r71b00dcc  
    4040SOURCES = \
    4141        $(NAME).c \
    42         $(NET_BASE)app/nettest.c \
    4342        $(NET_BASE)app/parse.c \
    4443        $(NET_BASE)app/print_error.c
  • uspace/srv/net/app/nettest1/nettest1.c

    r60ab6c3 r71b00dcc  
    4848#include "../../err.h"
    4949
    50 #include "../nettest.h"
    5150#include "../parse.h"
    5251#include "../print_error.h"
     
    7069/** Prints the application help.
    7170 */
    72 void nettest1_print_help(void);
     71void print_help(void);
     72
     73/** Translates the character string to the protocol family number.
     74 *  @param[in] name The protocol family name.
     75 *  @returns The corresponding protocol family number.
     76 *  @returns EPFNOSUPPORTED if the protocol family is not supported.
     77 */
     78int parse_protocol_family(const char * name);
     79
     80/** Translates the character string to the socket type number.
     81 *  @param[in] name The socket type name.
     82 *  @returns The corresponding socket type number.
     83 *  @returns ESOCKNOSUPPORTED if the socket type is not supported.
     84 */
     85int parse_socket_type(const char * name);
    7386
    7487/** Refreshes the data.
     
    7790 *  @param[in] size The data block size in bytes.
    7891 */
    79 void nettest1_refresh_data(char * data, size_t size);
    80 
    81 int main(int argc, char * argv[]){
    82         ERROR_DECLARE;
    83 
    84         size_t size                     = 27;
    85         int verbose                     = 0;
    86         sock_type_t type        = SOCK_DGRAM;
    87         int sockets                     = 10;
    88         int messages            = 10;
    89         int family                      = PF_INET;
    90         uint16_t port           = 7;
    91 
    92         socklen_t max_length                            = sizeof(struct sockaddr_in6);
    93         uint8_t address_data[max_length];
    94         struct sockaddr * address                       = (struct sockaddr *) address_data;
    95         struct sockaddr_in * address_in         = (struct sockaddr_in *) address;
    96         struct sockaddr_in6 * address_in6       = (struct sockaddr_in6 *) address;
    97         socklen_t addrlen;
    98 //      char address_string[INET6_ADDRSTRLEN];
    99         uint8_t * address_start;
    100 
    101         int * socket_ids;
    102         char * data;
    103         int value;
    104         int index;
    105         struct timeval time_before;
    106         struct timeval time_after;
    107 
    108         // print the program label
    109         printf("Task %d - ", task_get_id());
    110         printf("%s\n", NAME);
    111 
    112         // parse the command line arguments
    113         // stop before the last argument if it does not start with the minus sign ('-')
    114         for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
    115                 // options should start with the minus sign ('-')
    116                 if(argv[index][0] == '-'){
    117                         switch(argv[index][1]){
    118                                 // short options with only one letter
    119                                 case 'f':
    120                                         ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
    121                                         break;
    122                                 case 'h':
    123                                         nettest1_print_help();
    124                                         return EOK;
    125                                         break;
    126                                 case 'm':
    127                                         ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 0));
    128                                         break;
    129                                 case 'n':
    130                                         ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));
    131                                         break;
    132                                 case 'p':
    133                                         ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
    134                                         port = (uint16_t) value;
    135                                         break;
    136                                 case 's':
    137                                         ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
    138                                         size = (value >= 0) ? (size_t) value : 0;
    139                                         break;
    140                                 case 't':
    141                                         ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
    142                                         type = (sock_type_t) value;
    143                                         break;
    144                                 case 'v':
    145                                         verbose = 1;
    146                                         break;
    147                                 // long options with the double minus sign ('-')
    148                                 case '-':
    149                                         if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
    150                                                 ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
    151                                         }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
    152                                                 nettest1_print_help();
    153                                                 return EOK;
    154                                         }else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
    155                                                 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 8));
    156                                         }else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
    157                                                 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));
    158                                         }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
    159                                                 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
    160                                                 port = (uint16_t) value;
    161                                         }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
    162                                                 ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
    163                                                 type = (sock_type_t) value;
    164                                         }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
    165                                                 verbose = 1;
    166                                         }else{
    167                                                 print_unrecognized(index, argv[index] + 2);
    168                                                 nettest1_print_help();
    169                                                 return EINVAL;
    170                                         }
    171                                         break;
    172                                 default:
    173                                         print_unrecognized(index, argv[index] + 1);
    174                                         nettest1_print_help();
    175                                         return EINVAL;
    176                         }
    177                 }else{
    178                         print_unrecognized(index, argv[index]);
    179                         nettest1_print_help();
    180                         return EINVAL;
    181                 }
    182         }
    183 
    184         // if not before the last argument containing the address
    185         if(index >= argc){
    186                 printf("Command line error: missing address\n");
    187                 nettest1_print_help();
    188                 return EINVAL;
    189         }
    190 
    191         // prepare the address buffer
    192         bzero(address_data, max_length);
    193         switch(family){
    194                 case PF_INET:
    195                         address_in->sin_family = AF_INET;
    196                         address_in->sin_port = htons(port);
    197                         address_start = (uint8_t *) &address_in->sin_addr.s_addr;
    198                         addrlen = sizeof(struct sockaddr_in);
    199                         break;
    200                 case PF_INET6:
    201                         address_in6->sin6_family = AF_INET6;
    202                         address_in6->sin6_port = htons(port);
    203                         address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
    204                         addrlen = sizeof(struct sockaddr_in6);
    205                         break;
    206                 default:
    207                         fprintf(stderr, "Address family is not supported\n");
    208                         return EAFNOSUPPORT;
    209         }
    210 
    211         // parse the last argument which should contain the address
    212         if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
    213                 fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
    214                 return ERROR_CODE;
    215         }
    216 
    217         // check the buffer size
    218         if(size <= 0){
    219                 fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
    220                 size = 1024;
    221         }
    222 
    223         // prepare the buffer
    224         // size plus the terminating null (\0)
    225         data = (char *) malloc(size + 1);
    226         if(! data){
    227                 fprintf(stderr, "Failed to allocate data buffer.\n");
    228                 return ENOMEM;
    229         }
    230         nettest1_refresh_data(data, size);
    231 
    232         // check the socket count
    233         if(sockets <= 0){
    234                 fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
    235                 sockets = 2;
    236         }
    237 
    238         // prepare the socket buffer
    239         // count plus the terminating null (\0)
    240         socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
    241         if(! socket_ids){
    242                 fprintf(stderr, "Failed to allocate receive buffer.\n");
    243                 return ENOMEM;
    244         }
    245         socket_ids[sockets] = NULL;
    246 
    247         if(verbose){
    248                 printf("Starting tests\n");
    249         }
    250 
    251         if(verbose){
    252                 printf("1 socket, 1 message\n");
    253         }
    254 
    255         if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
    256                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    257                 return ERROR_CODE;
    258         }
    259 
    260         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    261         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    262         if(verbose){
    263                 printf("\tOK\n");
    264         }
    265 
    266         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    267         if(type == SOCK_STREAM){
    268                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
    269         }
    270         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
    271         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    272         if(verbose){
    273                 printf("\tOK\n");
    274         }
    275 
    276         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    277         if(type == SOCK_STREAM){
    278                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
    279         }
    280         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, 1));
    281         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
    282         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    283         if(verbose){
    284                 printf("\tOK\n");
    285         }
    286 
    287         if(verbose){
    288                 printf("1 socket, %d messages\n", messages);
    289         }
    290 
    291         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    292         if(type == SOCK_STREAM){
    293                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
    294         }
    295         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
    296         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    297         if(verbose){
    298                 printf("\tOK\n");
    299         }
    300 
    301         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    302         if(type == SOCK_STREAM){
    303                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
    304         }
    305         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, messages));
    306         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
    307         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    308         if(verbose){
    309                 printf("\tOK\n");
    310         }
    311 
    312         if(verbose){
    313                 printf("%d sockets, 1 message\n", sockets);
    314         }
    315 
    316         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    317         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    318         if(verbose){
    319                 printf("\tOK\n");
    320         }
    321 
    322         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    323         if(type == SOCK_STREAM){
    324                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    325         }
    326         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
    327         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    328         if(verbose){
    329                 printf("\tOK\n");
    330         }
    331 
    332         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    333         if(type == SOCK_STREAM){
    334                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    335         }
    336         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, 1));
    337         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
    338         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    339         if(verbose){
    340                 printf("\tOK\n");
    341         }
    342 
    343         if(verbose){
    344                 printf("%d sockets, %d messages\n", sockets, messages);
    345         }
    346 
    347         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    348         if(type == SOCK_STREAM){
    349                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    350         }
    351         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
    352         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    353         if(verbose){
    354                 printf("\tOK\n");
    355         }
    356 
    357         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    358         if(type == SOCK_STREAM){
    359                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    360         }
    361         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
    362         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
    363         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    364 
    365         if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
    366                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    367                 return ERROR_CODE;
    368         }
    369 
    370         if(verbose){
    371                 printf("\tOK\n");
    372         }
    373 
    374         printf("Tested in %d microseconds\n", tv_sub(&time_after, &time_before));
    375 
    376         if(verbose){
    377                 printf("Exiting\n");
    378         }
    379 
    380         return EOK;
    381 }
    382 
    383 void nettest1_print_help(void){
     92void refresh_data(char * data, size_t size);
     93
     94/** Creates new sockets.
     95 *  @param[in] verbose A value indicating whether to print out verbose information.
     96 *  @param[out] socket_ids A field to store the socket identifiers.
     97 *  @param[in] sockets The number of sockets to create. Should be at most the size of the field.
     98 *  @param[in] family The socket address family.
     99 *  @param[in] type The socket type.
     100 *  @returns EOK on success.
     101 *  @returns Other error codes as defined for the socket() function.
     102 */
     103int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type);
     104
     105/** Closes sockets.
     106 *  @param[in] verbose A value indicating whether to print out verbose information.
     107 *  @param[in] socket_ids A field of stored socket identifiers.
     108 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     109 *  @returns EOK on success.
     110 *  @returns Other error codes as defined for the closesocket() function.
     111 */
     112int sockets_close(int verbose, int * socket_ids, int sockets);
     113
     114/** Connects sockets.
     115 *  @param[in] verbose A value indicating whether to print out verbose information.
     116 *  @param[in] socket_ids A field of stored socket identifiers.
     117 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     118 *  @param[in] address The destination host address to connect to.
     119 *  @param[in] addrlen The length of the destination address in bytes.
     120 *  @returns EOK on success.
     121 *  @returns Other error codes as defined for the connect() function.
     122 */
     123int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen);
     124
     125/** Sends data via sockets.
     126 *  @param[in] verbose A value indicating whether to print out verbose information.
     127 *  @param[in] socket_ids A field of stored socket identifiers.
     128 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     129 *  @param[in] address The destination host address to send data to.
     130 *  @param[in] addrlen The length of the destination address in bytes.
     131 *  @param[in] data The data to be sent.
     132 *  @param[in] size The data size in bytes.
     133 *  @param[in] messages The number of datagrams per socket to be sent.
     134 *  @returns EOK on success.
     135 *  @returns Other error codes as defined for the sendto() function.
     136 */
     137int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages);
     138
     139/** Receives data via sockets.
     140 *  @param[in] verbose A value indicating whether to print out verbose information.
     141 *  @param[in] socket_ids A field of stored socket identifiers.
     142 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     143 *  @param[in] address The source host address of received datagrams.
     144 *  @param[in,out] addrlen The maximum length of the source address in bytes. The actual size of the source address is set instead.
     145 *  @param[out] data The received data.
     146 *  @param[in] size The maximum data size in bytes.
     147 *  @param[in] messages The number of datagrams per socket to be received.
     148 *  @returns EOK on success.
     149 *  @returns Other error codes as defined for the recvfrom() function.
     150 */
     151int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
     152
     153/** Sends and receives data via sockets.
     154 *  Each datagram is sent and a reply read consequently.
     155 *  The next datagram is sent after the reply is received.
     156 *  @param[in] verbose A value indicating whether to print out verbose information.
     157 *  @param[in] socket_ids A field of stored socket identifiers.
     158 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     159 *  @param[in,out] address The destination host address to send data to. The source host address of received datagrams is set instead.
     160 *  @param[in] addrlen The length of the destination address in bytes.
     161 *  @param[in,out] data The data to be sent. The received data are set instead.
     162 *  @param[in] size The data size in bytes.
     163 *  @param[in] messages The number of datagrams per socket to be received.
     164 *  @returns EOK on success.
     165 *  @returns Other error codes as defined for the recvfrom() function.
     166 */
     167int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
     168
     169/** Prints a mark.
     170 *  If the index is a multiple of ten, a different mark is printed.
     171 *  @param[in] index The index of the mark to be printed.
     172 */
     173void print_mark(int index);
     174
     175void print_help(void){
    384176        printf(
    385177                "Network Networking test 1 aplication - sockets\n" \
     
    409201}
    410202
    411 void nettest1_refresh_data(char * data, size_t size){
     203int parse_protocol_family(const char * name){
     204        if(str_lcmp(name, "PF_INET", 7) == 0){
     205                return PF_INET;
     206        }else if(str_lcmp(name, "PF_INET6", 8) == 0){
     207                return PF_INET6;
     208        }
     209        return EPFNOSUPPORT;
     210}
     211
     212int parse_socket_type(const char * name){
     213        if(str_lcmp(name, "SOCK_DGRAM", 11) == 0){
     214                return SOCK_DGRAM;
     215        }else if(str_lcmp(name, "SOCK_STREAM", 12) == 0){
     216                return SOCK_STREAM;
     217        }
     218        return ESOCKTNOSUPPORT;
     219}
     220
     221void refresh_data(char * data, size_t size){
    412222        size_t length;
    413223
     
    422232}
    423233
     234int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){
     235        int index;
     236
     237        if(verbose){
     238                printf("Create\t");
     239        }
     240        fflush(stdout);
     241        for(index = 0; index < sockets; ++ index){
     242                socket_ids[index] = socket(family, type, 0);
     243                if(socket_ids[index] < 0){
     244                        printf("Socket %d (%d) error:\n", index, socket_ids[index]);
     245                        socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n");
     246                        return socket_ids[index];
     247                }
     248                if(verbose){
     249                        print_mark(index);
     250                }
     251        }
     252        return EOK;
     253}
     254
     255int sockets_close(int verbose, int * socket_ids, int sockets){
     256        ERROR_DECLARE;
     257
     258        int index;
     259
     260        if(verbose){
     261                printf("\tClose\t");
     262        }
     263        fflush(stdout);
     264        for(index = 0; index < sockets; ++ index){
     265                if(ERROR_OCCURRED(closesocket(socket_ids[index]))){
     266                        printf("Socket %d (%d) error:\n", index, socket_ids[index]);
     267                        socket_print_error(stderr, ERROR_CODE, "Socket close: ", "\n");
     268                        return ERROR_CODE;
     269                }
     270                if(verbose){
     271                        print_mark(index);
     272                }
     273        }
     274        return EOK;
     275}
     276
     277int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen){
     278        ERROR_DECLARE;
     279
     280        int index;
     281
     282        if(verbose){
     283                printf("\tConnect\t");
     284        }
     285        fflush(stdout);
     286        for(index = 0; index < sockets; ++ index){
     287                if(ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))){
     288                        socket_print_error(stderr, ERROR_CODE, "Socket connect: ", "\n");
     289                        return ERROR_CODE;
     290                }
     291                if(verbose){
     292                        print_mark(index);
     293                }
     294        }
     295        return EOK;
     296}
     297
     298int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages){
     299        ERROR_DECLARE;
     300
     301        int index;
     302        int message;
     303
     304        if(verbose){
     305                printf("\tSendto\t");
     306        }
     307        fflush(stdout);
     308        for(index = 0; index < sockets; ++ index){
     309                for(message = 0; message < messages; ++ message){
     310                        if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, addrlen))){
     311                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
     312                                socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
     313                                return ERROR_CODE;
     314                        }
     315                }
     316                if(verbose){
     317                        print_mark(index);
     318                }
     319        }
     320        return EOK;
     321}
     322
     323int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
     324        int value;
     325        int index;
     326        int message;
     327
     328        if(verbose){
     329                printf("\tRecvfrom\t");
     330        }
     331        fflush(stdout);
     332        for(index = 0; index < sockets; ++ index){
     333                for(message = 0; message < messages; ++ message){
     334                        value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
     335                        if(value < 0){
     336                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
     337                                socket_print_error(stderr, value, "Socket receive: ", "\n");
     338                                return value;
     339                        }
     340                }
     341                if(verbose){
     342                        print_mark(index);
     343                }
     344        }
     345        return EOK;
     346}
     347
     348int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
     349        ERROR_DECLARE;
     350
     351        int value;
     352        int index;
     353        int message;
     354
     355        if(verbose){
     356                printf("\tSendto and recvfrom\t");
     357        }
     358        fflush(stdout);
     359        for(index = 0; index < sockets; ++ index){
     360                for(message = 0; message < messages; ++ message){
     361                        if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, * addrlen))){
     362                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
     363                                socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
     364                                return ERROR_CODE;
     365                        }
     366                        value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
     367                        if(value < 0){
     368                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
     369                                socket_print_error(stderr, value, "Socket receive: ", "\n");
     370                                return value;
     371                        }
     372                }
     373                if(verbose){
     374                        print_mark(index);
     375                }
     376        }
     377        return EOK;
     378}
     379
     380void print_mark(int index){
     381        if((index + 1) % 10){
     382                printf("*");
     383        }else{
     384                printf("|");
     385        }
     386        fflush(stdout);
     387}
     388
     389int main(int argc, char * argv[]){
     390        ERROR_DECLARE;
     391
     392        size_t size                     = 27;
     393        int verbose                     = 0;
     394        sock_type_t type                        = SOCK_DGRAM;
     395        int sockets                     = 10;
     396        int messages            = 10;
     397        int family                      = PF_INET;
     398        uint16_t port                   = 7;
     399
     400        socklen_t max_length            = sizeof(struct sockaddr_in6);
     401        uint8_t address_data[max_length];
     402        struct sockaddr * address               = (struct sockaddr *) address_data;
     403        struct sockaddr_in * address_in         = (struct sockaddr_in *) address;
     404        struct sockaddr_in6 * address_in6       = (struct sockaddr_in6 *) address;
     405        socklen_t addrlen;
     406//      char                            address_string[INET6_ADDRSTRLEN];
     407        uint8_t * address_start;
     408
     409        int * socket_ids;
     410        char *                          data;
     411        int value;
     412        int index;
     413        struct timeval time_before;
     414        struct timeval time_after;
     415
     416        printf("Task %d - ", task_get_id());
     417        printf("%s\n", NAME);
     418
     419        if(argc <= 1){
     420                print_help();
     421                return EINVAL;
     422        }
     423
     424        for(index = 1; (index < argc - 1) || ((index == argc) && (argv[index][0] == '-')); ++ index){
     425                if(argv[index][0] == '-'){
     426                        switch(argv[index][1]){
     427                                case 'f':
     428                                        ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
     429                                        break;
     430                                case 'h':
     431                                        print_help();
     432                                        return EOK;
     433                                        break;
     434                                case 'm':
     435                                        ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 0));
     436                                        break;
     437                                case 'n':
     438                                        ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));
     439                                        break;
     440                                case 'p':
     441                                        ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
     442                                        port = (uint16_t) value;
     443                                        break;
     444                                case 's':
     445                                        ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
     446                                        size = (value >= 0) ? (size_t) value : 0;
     447                                        break;
     448                                case 't':
     449                                        ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
     450                                        type = (sock_type_t) value;
     451                                        break;
     452                                case 'v':
     453                                        verbose = 1;
     454                                        break;
     455                                case '-':
     456                                        if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
     457                                                ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
     458                                        }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
     459                                                print_help();
     460                                                return EOK;
     461                                        }else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
     462                                                ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 8));
     463                                        }else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
     464                                                ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));
     465                                        }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
     466                                                ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
     467                                                port = (uint16_t) value;
     468                                        }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
     469                                                ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
     470                                                type = (sock_type_t) value;
     471                                        }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
     472                                                verbose = 1;
     473                                        }else{
     474                                                print_unrecognized(index, argv[index] + 2);
     475                                                print_help();
     476                                                return EINVAL;
     477                                        }
     478                                        break;
     479                                default:
     480                                        print_unrecognized(index, argv[index] + 1);
     481                                        print_help();
     482                                        return EINVAL;
     483                        }
     484                }else{
     485                        print_unrecognized(index, argv[index]);
     486                        print_help();
     487                        return EINVAL;
     488                }
     489        }
     490
     491        bzero(address_data, max_length);
     492        switch(family){
     493                case PF_INET:
     494                        address_in->sin_family = AF_INET;
     495                        address_in->sin_port = htons(port);
     496                        address_start = (uint8_t *) &address_in->sin_addr.s_addr;
     497                        addrlen = sizeof(struct sockaddr_in);
     498                        break;
     499                case PF_INET6:
     500                        address_in6->sin6_family = AF_INET6;
     501                        address_in6->sin6_port = htons(port);
     502                        address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
     503                        addrlen = sizeof(struct sockaddr_in6);
     504                        break;
     505                default:
     506                        fprintf(stderr, "Address family is not supported\n");
     507                        return EAFNOSUPPORT;
     508        }
     509
     510        if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
     511                fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
     512                return ERROR_CODE;
     513        }
     514
     515        if(size <= 0){
     516                fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
     517                size = 1024;
     518        }
     519        // size plus terminating null (\0)
     520        data = (char *) malloc(size + 1);
     521        if(! data){
     522                fprintf(stderr, "Failed to allocate data buffer.\n");
     523                return ENOMEM;
     524        }
     525        refresh_data(data, size);
     526
     527        if(sockets <= 0){
     528                fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
     529                sockets = 2;
     530        }
     531        // count plus terminating null (\0)
     532        socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
     533        if(! socket_ids){
     534                fprintf(stderr, "Failed to allocate receive buffer.\n");
     535                return ENOMEM;
     536        }
     537        socket_ids[sockets] = NULL;
     538
     539        if(verbose){
     540                printf("Starting tests\n");
     541        }
     542
     543        if(verbose){
     544                printf("1 socket, 1 message\n");
     545        }
     546
     547        if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
     548                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     549                return ERROR_CODE;
     550        }
     551
     552        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     553        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     554        if(verbose){
     555                printf("\tOK\n");
     556        }
     557
     558        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     559        if(type == SOCK_STREAM){
     560                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
     561        }
     562        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
     563        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     564        if(verbose){
     565                printf("\tOK\n");
     566        }
     567
     568        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     569        if(type == SOCK_STREAM){
     570                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
     571        }
     572        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, 1));
     573        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
     574        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     575        if(verbose){
     576                printf("\tOK\n");
     577        }
     578
     579        if(verbose){
     580                printf("1 socket, %d messages\n", messages);
     581        }
     582
     583        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     584        if(type == SOCK_STREAM){
     585                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
     586        }
     587        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
     588        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     589        if(verbose){
     590                printf("\tOK\n");
     591        }
     592
     593        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     594        if(type == SOCK_STREAM){
     595                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
     596        }
     597        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, messages));
     598        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
     599        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     600        if(verbose){
     601                printf("\tOK\n");
     602        }
     603
     604        if(verbose){
     605                printf("%d sockets, 1 message\n", sockets);
     606        }
     607
     608        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     609        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     610        if(verbose){
     611                printf("\tOK\n");
     612        }
     613
     614        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     615        if(type == SOCK_STREAM){
     616                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     617        }
     618        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
     619        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     620        if(verbose){
     621                printf("\tOK\n");
     622        }
     623
     624        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     625        if(type == SOCK_STREAM){
     626                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     627        }
     628        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, 1));
     629        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
     630        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     631        if(verbose){
     632                printf("\tOK\n");
     633        }
     634
     635        if(verbose){
     636                printf("%d sockets, %d messages\n", sockets, messages);
     637        }
     638
     639        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     640        if(type == SOCK_STREAM){
     641                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     642        }
     643        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
     644        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     645        if(verbose){
     646                printf("\tOK\n");
     647        }
     648
     649        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     650        if(type == SOCK_STREAM){
     651                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     652        }
     653        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
     654        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
     655        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     656
     657        if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
     658                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     659                return ERROR_CODE;
     660        }
     661
     662        if(verbose){
     663                printf("\tOK\n");
     664        }
     665
     666        printf("Tested in %d microseconds\n", tv_sub(&time_after, &time_before));
     667
     668        if(verbose){
     669                printf("Exiting\n");
     670        }
     671
     672        return EOK;
     673}
     674
    424675/** @}
    425676 */
  • uspace/srv/net/app/nettest2/Makefile

    r60ab6c3 r71b00dcc  
    4040SOURCES = \
    4141        $(NAME).c \
    42         $(NET_BASE)app/nettest.c \
    4342        $(NET_BASE)app/parse.c \
    4443        $(NET_BASE)app/print_error.c
  • uspace/srv/net/app/nettest2/nettest2.c

    r60ab6c3 r71b00dcc  
    4848#include "../../err.h"
    4949
    50 #include "../nettest.h"
    5150#include "../parse.h"
    5251#include "../print_error.h"
     
    7069/** Prints the application help.
    7170 */
    72 void nettest2_print_help(void);
     71void print_help(void);
     72
     73/** Translates the character string to the protocol family number.
     74 *  @param[in] name The protocol family name.
     75 *  @returns The corresponding protocol family number.
     76 *  @returns EPFNOSUPPORTED if the protocol family is not supported.
     77 */
     78int parse_protocol_family(const char * name);
     79
     80/** Translates the character string to the socket type number.
     81 *  @param[in] name The socket type name.
     82 *  @returns The corresponding socket type number.
     83 *  @returns ESOCKNOSUPPORTED if the socket type is not supported.
     84 */
     85int parse_socket_type(const char * name);
    7386
    7487/** Refreshes the data.
     
    7790 *  @param[in] size The data block size in bytes.
    7891 */
    79 void nettest2_refresh_data(char * data, size_t size);
    80 
    81 int main(int argc, char * argv[]){
    82         ERROR_DECLARE;
    83 
    84         size_t size                     = 28;
    85         int verbose                     = 0;
    86         sock_type_t type        = SOCK_DGRAM;
    87         int sockets                     = 10;
    88         int messages            = 10;
    89         int family                      = PF_INET;
    90         uint16_t port           = 7;
    91 
    92         socklen_t max_length                            = sizeof(struct sockaddr_in6);
    93         uint8_t address_data[max_length];
    94         struct sockaddr * address                       = (struct sockaddr *) address_data;
    95         struct sockaddr_in * address_in         = (struct sockaddr_in *) address;
    96         struct sockaddr_in6 * address_in6       = (struct sockaddr_in6 *) address;
    97         socklen_t addrlen;
    98 //      char address_string[INET6_ADDRSTRLEN];
    99         uint8_t * address_start;
    100 
    101         int * socket_ids;
    102         char * data;
    103         int value;
    104         int index;
    105         struct timeval time_before;
    106         struct timeval time_after;
    107 
    108         printf("Task %d - ", task_get_id());
    109         printf("%s\n", NAME);
    110 
    111         // parse the command line arguments
    112         // stop before the last argument if it does not start with the minus sign ('-')
    113         for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
    114                 // options should start with the minus sign ('-')
    115                 if(argv[index][0] == '-'){
    116                         switch(argv[index][1]){
    117                                 // short options with only one letter
    118                                 case 'f':
    119                                         ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
    120                                         break;
    121                                 case 'h':
    122                                         nettest2_print_help();
    123                                         return EOK;
    124                                         break;
    125                                 case 'm':
    126                                         ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 0));
    127                                         break;
    128                                 case 'n':
    129                                         ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));
    130                                         break;
    131                                 case 'p':
    132                                         ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
    133                                         port = (uint16_t) value;
    134                                         break;
    135                                 case 's':
    136                                         ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
    137                                         size = (value >= 0) ? (size_t) value : 0;
    138                                         break;
    139                                 case 't':
    140                                         ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
    141                                         type = (sock_type_t) value;
    142                                         break;
    143                                 case 'v':
    144                                         verbose = 1;
    145                                         break;
    146                                 // long options with the double minus sign ('-')
    147                                 case '-':
    148                                         if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
    149                                                 ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
    150                                         }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
    151                                                 nettest2_print_help();
    152                                                 return EOK;
    153                                         }else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
    154                                                 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 8));
    155                                         }else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
    156                                                 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));
    157                                         }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
    158                                                 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
    159                                                 port = (uint16_t) value;
    160                                         }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
    161                                                 ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
    162                                                 type = (sock_type_t) value;
    163                                         }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
    164                                                 verbose = 1;
    165                                         }else{
    166                                                 print_unrecognized(index, argv[index] + 2);
    167                                                 nettest2_print_help();
    168                                                 return EINVAL;
    169                                         }
    170                                         break;
    171                                 default:
    172                                         print_unrecognized(index, argv[index] + 1);
    173                                         nettest2_print_help();
    174                                         return EINVAL;
    175                         }
    176                 }else{
    177                         print_unrecognized(index, argv[index]);
    178                         nettest2_print_help();
    179                         return EINVAL;
    180                 }
    181         }
    182 
    183         // if not before the last argument containing the address
    184         if(index >= argc){
    185                 printf("Command line error: missing address\n");
    186                 nettest2_print_help();
    187                 return EINVAL;
    188         }
    189 
    190         // prepare the address buffer
    191         bzero(address_data, max_length);
    192         switch(family){
    193                 case PF_INET:
    194                         address_in->sin_family = AF_INET;
    195                         address_in->sin_port = htons(port);
    196                         address_start = (uint8_t *) &address_in->sin_addr.s_addr;
    197                         addrlen = sizeof(struct sockaddr_in);
    198                         break;
    199                 case PF_INET6:
    200                         address_in6->sin6_family = AF_INET6;
    201                         address_in6->sin6_port = htons(port);
    202                         address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
    203                         addrlen = sizeof(struct sockaddr_in6);
    204                         break;
    205                 default:
    206                         fprintf(stderr, "Address family is not supported\n");
    207                         return EAFNOSUPPORT;
    208         }
    209 
    210         // parse the last argument which should contain the address
    211         if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
    212                 fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
    213                 return ERROR_CODE;
    214         }
    215 
    216         // check the buffer size
    217         if(size <= 0){
    218                 fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
    219                 size = 1024;
    220         }
    221 
    222         // prepare the buffer
    223         // size plus terminating null (\0)
    224         data = (char *) malloc(size + 1);
    225         if(! data){
    226                 fprintf(stderr, "Failed to allocate data buffer.\n");
    227                 return ENOMEM;
    228         }
    229         nettest2_refresh_data(data, size);
    230 
    231         // check the socket count
    232         if(sockets <= 0){
    233                 fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
    234                 sockets = 2;
    235         }
    236 
    237         // prepare the socket buffer
    238         // count plus the terminating null (\0)
    239         socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
    240         if(! socket_ids){
    241                 fprintf(stderr, "Failed to allocate receive buffer.\n");
    242                 return ENOMEM;
    243         }
    244         socket_ids[sockets] = NULL;
    245 
    246         if(verbose){
    247                 printf("Starting tests\n");
    248         }
    249 
    250         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    251 
    252         if(type == SOCK_STREAM){
    253                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    254         }
    255 
    256         if(verbose){
    257                 printf("\n");
    258         }
    259 
    260         if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
    261                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    262                 return ERROR_CODE;
    263         }
    264 
    265         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
    266 
    267         if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
    268                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    269                 return ERROR_CODE;
    270         }
    271 
    272         if(verbose){
    273                 printf("\tOK\n");
    274         }
    275 
    276         printf("sendto + recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
    277 
    278         if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
    279                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    280                 return ERROR_CODE;
    281         }
    282 
    283         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
    284         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
    285 
    286         if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
    287                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    288                 return ERROR_CODE;
    289         }
    290 
    291         if(verbose){
    292                 printf("\tOK\n");
    293         }
    294 
    295         printf("sendto, recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
    296 
    297         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    298 
    299         if(verbose){
    300                 printf("\nExiting\n");
    301         }
    302 
    303         return EOK;
    304 }
    305 
    306 void nettest2_print_help(void){
     92void refresh_data(char * data, size_t size);
     93
     94/** Creates new sockets.
     95 *  @param[in] verbose A value indicating whether to print out verbose information.
     96 *  @param[out] socket_ids A field to store the socket identifiers.
     97 *  @param[in] sockets The number of sockets to create. Should be at most the size of the field.
     98 *  @param[in] family The socket address family.
     99 *  @param[in] type The socket type.
     100 *  @returns EOK on success.
     101 *  @returns Other error codes as defined for the socket() function.
     102 */
     103int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type);
     104
     105/** Closes sockets.
     106 *  @param[in] verbose A value indicating whether to print out verbose information.
     107 *  @param[in] socket_ids A field of stored socket identifiers.
     108 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     109 *  @returns EOK on success.
     110 *  @returns Other error codes as defined for the closesocket() function.
     111 */
     112int sockets_close(int verbose, int * socket_ids, int sockets);
     113
     114/** Connects sockets.
     115 *  @param[in] verbose A value indicating whether to print out verbose information.
     116 *  @param[in] socket_ids A field of stored socket identifiers.
     117 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     118 *  @param[in] address The destination host address to connect to.
     119 *  @param[in] addrlen The length of the destination address in bytes.
     120 *  @returns EOK on success.
     121 *  @returns Other error codes as defined for the connect() function.
     122 */
     123int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen);
     124
     125/** Sends data via sockets.
     126 *  @param[in] verbose A value indicating whether to print out verbose information.
     127 *  @param[in] socket_ids A field of stored socket identifiers.
     128 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     129 *  @param[in] address The destination host address to send data to.
     130 *  @param[in] addrlen The length of the destination address in bytes.
     131 *  @param[in] data The data to be sent.
     132 *  @param[in] size The data size in bytes.
     133 *  @param[in] messages The number of datagrams per socket to be sent.
     134 *  @returns EOK on success.
     135 *  @returns Other error codes as defined for the sendto() function.
     136 */
     137int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages);
     138
     139/** Receives data via sockets.
     140 *  @param[in] verbose A value indicating whether to print out verbose information.
     141 *  @param[in] socket_ids A field of stored socket identifiers.
     142 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     143 *  @param[in] address The source host address of received datagrams.
     144 *  @param[in,out] addrlen The maximum length of the source address in bytes. The actual size of the source address is set instead.
     145 *  @param[out] data The received data.
     146 *  @param[in] size The maximum data size in bytes.
     147 *  @param[in] messages The number of datagrams per socket to be received.
     148 *  @returns EOK on success.
     149 *  @returns Other error codes as defined for the recvfrom() function.
     150 */
     151int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
     152
     153/** Sends and receives data via sockets.
     154 *  Each datagram is sent and a reply read consequently.
     155 *  The next datagram is sent after the reply is received.
     156 *  @param[in] verbose A value indicating whether to print out verbose information.
     157 *  @param[in] socket_ids A field of stored socket identifiers.
     158 *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     159 *  @param[in,out] address The destination host address to send data to. The source host address of received datagrams is set instead.
     160 *  @param[in] addrlen The length of the destination address in bytes.
     161 *  @param[in,out] data The data to be sent. The received data are set instead.
     162 *  @param[in] size The data size in bytes.
     163 *  @param[in] messages The number of datagrams per socket to be received.
     164 *  @returns EOK on success.
     165 *  @returns Other error codes as defined for the recvfrom() function.
     166 */
     167int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
     168
     169/** Prints a mark.
     170 *  If the index is a multiple of ten, a different mark is printed.
     171 *  @param[in] index The index of the mark to be printed.
     172 */
     173void print_mark(int index);
     174
     175void print_help(void){
    307176        printf(
    308177                "Network Networking test 2 aplication - UDP transfer\n" \
     
    332201}
    333202
    334 void nettest2_refresh_data(char * data, size_t size){
     203int parse_protocol_family(const char * name){
     204        if(str_lcmp(name, "PF_INET", 7) == 0){
     205                return PF_INET;
     206        }else if(str_lcmp(name, "PF_INET6", 8) == 0){
     207                return PF_INET6;
     208        }
     209        return EPFNOSUPPORT;
     210}
     211
     212int parse_socket_type(const char * name){
     213        if(str_lcmp(name, "SOCK_DGRAM", 11) == 0){
     214                return SOCK_DGRAM;
     215        }else if(str_lcmp(name, "SOCK_STREAM", 12) == 0){
     216                return SOCK_STREAM;
     217        }
     218        return ESOCKTNOSUPPORT;
     219}
     220
     221void refresh_data(char * data, size_t size){
    335222        size_t length;
    336223
     
    345232}
    346233
     234int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){
     235        int index;
     236
     237        if(verbose){
     238                printf("Create\t");
     239        }
     240        fflush(stdout);
     241        for(index = 0; index < sockets; ++ index){
     242                socket_ids[index] = socket(family, type, 0);
     243                if(socket_ids[index] < 0){
     244                        printf("Socket %d (%d) error:\n", index, socket_ids[index]);
     245                        socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n");
     246                        return socket_ids[index];
     247                }
     248                if(verbose){
     249                        print_mark(index);
     250                }
     251        }
     252        return EOK;
     253}
     254
     255int sockets_close(int verbose, int * socket_ids, int sockets){
     256        ERROR_DECLARE;
     257
     258        int index;
     259
     260        if(verbose){
     261                printf("\tClose\t");
     262        }
     263        fflush(stdout);
     264        for(index = 0; index < sockets; ++ index){
     265                if(ERROR_OCCURRED(closesocket(socket_ids[index]))){
     266                        printf("Socket %d (%d) error:\n", index, socket_ids[index]);
     267                        socket_print_error(stderr, ERROR_CODE, "Socket close: ", "\n");
     268                        return ERROR_CODE;
     269                }
     270                if(verbose){
     271                        print_mark(index);
     272                }
     273        }
     274        return EOK;
     275}
     276
     277int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen){
     278        ERROR_DECLARE;
     279
     280        int index;
     281
     282        if(verbose){
     283                printf("\tConnect\t");
     284        }
     285        fflush(stdout);
     286        for(index = 0; index < sockets; ++ index){
     287                if(ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))){
     288                        socket_print_error(stderr, ERROR_CODE, "Socket connect: ", "\n");
     289                        return ERROR_CODE;
     290                }
     291                if(verbose){
     292                        print_mark(index);
     293                }
     294        }
     295        return EOK;
     296}
     297
     298int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages){
     299        ERROR_DECLARE;
     300
     301        int index;
     302        int message;
     303
     304        if(verbose){
     305                printf("\tSendto\t");
     306        }
     307        fflush(stdout);
     308        for(index = 0; index < sockets; ++ index){
     309                for(message = 0; message < messages; ++ message){
     310                        if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, addrlen))){
     311                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
     312                                socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
     313                                return ERROR_CODE;
     314                        }
     315                }
     316                if(verbose){
     317                        print_mark(index);
     318                }
     319        }
     320        return EOK;
     321}
     322
     323int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
     324        int value;
     325        int index;
     326        int message;
     327
     328        if(verbose){
     329                printf("\tRecvfrom\t");
     330        }
     331        fflush(stdout);
     332        for(index = 0; index < sockets; ++ index){
     333                for(message = 0; message < messages; ++ message){
     334                        value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
     335                        if(value < 0){
     336                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
     337                                socket_print_error(stderr, value, "Socket receive: ", "\n");
     338                                return value;
     339                        }
     340                }
     341                if(verbose){
     342                        print_mark(index);
     343                }
     344        }
     345        return EOK;
     346}
     347
     348int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
     349        ERROR_DECLARE;
     350
     351        int value;
     352        int index;
     353        int message;
     354
     355        if(verbose){
     356                printf("\tSendto and recvfrom\t");
     357        }
     358        fflush(stdout);
     359        for(index = 0; index < sockets; ++ index){
     360                for(message = 0; message < messages; ++ message){
     361                        if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, * addrlen))){
     362                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
     363                                socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
     364                                return ERROR_CODE;
     365                        }
     366                        value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
     367                        if(value < 0){
     368                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
     369                                socket_print_error(stderr, value, "Socket receive: ", "\n");
     370                                return value;
     371                        }
     372                }
     373                if(verbose){
     374                        print_mark(index);
     375                }
     376        }
     377        return EOK;
     378}
     379
     380void print_mark(int index){
     381        if((index + 1) % 10){
     382                printf("*");
     383        }else{
     384                printf("|");
     385        }
     386        fflush(stdout);
     387}
     388
     389int main(int argc, char * argv[]){
     390        ERROR_DECLARE;
     391
     392        size_t size                     = 28;
     393        int verbose                     = 0;
     394        sock_type_t type                        = SOCK_DGRAM;
     395        int sockets                     = 10;
     396        int messages            = 10;
     397        int family                      = PF_INET;
     398        uint16_t port                   = 7;
     399
     400        socklen_t max_length            = sizeof(struct sockaddr_in6);
     401        uint8_t address_data[max_length];
     402        struct sockaddr * address               = (struct sockaddr *) address_data;
     403        struct sockaddr_in * address_in         = (struct sockaddr_in *) address;
     404        struct sockaddr_in6 * address_in6       = (struct sockaddr_in6 *) address;
     405        socklen_t addrlen;
     406//      char                            address_string[INET6_ADDRSTRLEN];
     407        uint8_t * address_start;
     408
     409        int * socket_ids;
     410        char *                          data;
     411        int value;
     412        int index;
     413        struct timeval time_before;
     414        struct timeval time_after;
     415
     416        printf("Task %d - ", task_get_id());
     417        printf("%s\n", NAME);
     418
     419        if(argc <= 1){
     420                print_help();
     421                return EINVAL;
     422        }
     423
     424        for(index = 1; (index < argc - 1) || ((index == argc) && (argv[index][0] == '-')); ++ index){
     425                if(argv[index][0] == '-'){
     426                        switch(argv[index][1]){
     427                                case 'f':
     428                                        ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
     429                                        break;
     430                                case 'h':
     431                                        print_help();
     432                                        return EOK;
     433                                        break;
     434                                case 'm':
     435                                        ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 0));
     436                                        break;
     437                                case 'n':
     438                                        ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));
     439                                        break;
     440                                case 'p':
     441                                        ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
     442                                        port = (uint16_t) value;
     443                                        break;
     444                                case 's':
     445                                        ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
     446                                        size = (value >= 0) ? (size_t) value : 0;
     447                                        break;
     448                                case 't':
     449                                        ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
     450                                        type = (sock_type_t) value;
     451                                        break;
     452                                case 'v':
     453                                        verbose = 1;
     454                                        break;
     455                                case '-':
     456                                        if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
     457                                                ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
     458                                        }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
     459                                                print_help();
     460                                                return EOK;
     461                                        }else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
     462                                                ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 8));
     463                                        }else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
     464                                                ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));
     465                                        }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
     466                                                ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
     467                                                port = (uint16_t) value;
     468                                        }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
     469                                                ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
     470                                                type = (sock_type_t) value;
     471                                        }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
     472                                                verbose = 1;
     473                                        }else{
     474                                                print_unrecognized(index, argv[index] + 2);
     475                                                print_help();
     476                                                return EINVAL;
     477                                        }
     478                                        break;
     479                                default:
     480                                        print_unrecognized(index, argv[index] + 1);
     481                                        print_help();
     482                                        return EINVAL;
     483                        }
     484                }else{
     485                        print_unrecognized(index, argv[index]);
     486                        print_help();
     487                        return EINVAL;
     488                }
     489        }
     490
     491        bzero(address_data, max_length);
     492        switch(family){
     493                case PF_INET:
     494                        address_in->sin_family = AF_INET;
     495                        address_in->sin_port = htons(port);
     496                        address_start = (uint8_t *) &address_in->sin_addr.s_addr;
     497                        addrlen = sizeof(struct sockaddr_in);
     498                        break;
     499                case PF_INET6:
     500                        address_in6->sin6_family = AF_INET6;
     501                        address_in6->sin6_port = htons(port);
     502                        address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
     503                        addrlen = sizeof(struct sockaddr_in6);
     504                        break;
     505                default:
     506                        fprintf(stderr, "Address family is not supported\n");
     507                        return EAFNOSUPPORT;
     508        }
     509
     510        if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
     511                fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
     512                return ERROR_CODE;
     513        }
     514
     515        if(size <= 0){
     516                fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
     517                size = 1024;
     518        }
     519        // size plus terminating null (\0)
     520        data = (char *) malloc(size + 1);
     521        if(! data){
     522                fprintf(stderr, "Failed to allocate data buffer.\n");
     523                return ENOMEM;
     524        }
     525        refresh_data(data, size);
     526
     527        if(sockets <= 0){
     528                fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
     529                sockets = 2;
     530        }
     531        // count plus terminating null (\0)
     532        socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
     533        if(! socket_ids){
     534                fprintf(stderr, "Failed to allocate receive buffer.\n");
     535                return ENOMEM;
     536        }
     537        socket_ids[sockets] = NULL;
     538
     539        if(verbose){
     540                printf("Starting tests\n");
     541        }
     542
     543        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     544
     545        if(type == SOCK_STREAM){
     546                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     547        }
     548
     549        if(verbose){
     550                printf("\n");
     551        }
     552
     553        if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
     554                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     555                return ERROR_CODE;
     556        }
     557
     558        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
     559
     560        if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
     561                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     562                return ERROR_CODE;
     563        }
     564
     565        if(verbose){
     566                printf("\tOK\n");
     567        }
     568
     569        printf("sendto + recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
     570
     571        if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
     572                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     573                return ERROR_CODE;
     574        }
     575
     576        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
     577        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
     578
     579        if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
     580                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     581                return ERROR_CODE;
     582        }
     583
     584        if(verbose){
     585                printf("\tOK\n");
     586        }
     587
     588        printf("sendto, recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
     589
     590        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     591
     592        if(verbose){
     593                printf("\nExiting\n");
     594        }
     595
     596        return EOK;
     597}
     598
    347599/** @}
    348600 */
  • uspace/srv/net/app/parse.c

    r60ab6c3 r71b00dcc  
    3838#include <string.h>
    3939
    40 #include "../include/socket.h"
    41 
    4240#include "../err.h"
    4341
    4442#include "parse.h"
    45 
    46 int parse_address_family(const char * name){
    47         if(str_lcmp(name, "AF_INET", 7) == 0){
    48                 return AF_INET;
    49         }else if(str_lcmp(name, "AF_INET6", 8) == 0){
    50                 return AF_INET6;
    51         }
    52         return EAFNOSUPPORT;
    53 }
    5443
    5544int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset){
     
    7261}
    7362
     63int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset){
     64        if(offset){
     65                *value = argv[*index] + offset;
     66        }else if((*index) + 1 < argc){
     67                ++ (*index);
     68                *value = argv[*index];
     69        }else{
     70                fprintf(stderr, "Command line error: missing %s\n", name);
     71                return EINVAL;
     72        }
     73        return EOK;
     74}
     75
    7476int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value)){
    7577        ERROR_DECLARE;
     
    8688}
    8789
    88 int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset){
    89         if(offset){
    90                 *value = argv[*index] + offset;
    91         }else if((*index) + 1 < argc){
    92                 ++ (*index);
    93                 *value = argv[*index];
    94         }else{
    95                 fprintf(stderr, "Command line error: missing %s\n", name);
    96                 return EINVAL;
    97         }
    98         return EOK;
    99 }
    100 
    101 int parse_protocol_family(const char * name){
    102         if(str_lcmp(name, "PF_INET", 7) == 0){
    103                 return PF_INET;
    104         }else if(str_lcmp(name, "PF_INET6", 8) == 0){
    105                 return PF_INET6;
    106         }
    107         return EPFNOSUPPORT;
    108 }
    109 
    110 int parse_socket_type(const char * name){
    111         if(str_lcmp(name, "SOCK_DGRAM", 11) == 0){
    112                 return SOCK_DGRAM;
    113         }else if(str_lcmp(name, "SOCK_STREAM", 12) == 0){
    114                 return SOCK_STREAM;
    115         }
    116         return ESOCKTNOSUPPORT;
    117 }
    118 
    11990void print_unrecognized(int index, const char * parameter){
    120         fprintf(stderr, "Command line error: unrecognized argument (%d: %s)\n", index, parameter);
     91        fprintf(stderr, "Command line error - unrecognized parameter (%d: %s)\n", index, parameter);
    12192}
    12293
  • uspace/srv/net/app/parse.h

    r60ab6c3 r71b00dcc  
    3838#define __NET_APP_PARSE__
    3939
    40 #include "../include/socket.h"
    41 
    42 /** Translates the character string to the address family number.
    43  *  @param[in] name The address family name.
    44  *  @returns The corresponding address family number.
    45  *  @returns EAFNOSUPPORTED if the address family is not supported.
     40/** Prints the parameter unrecognized message and the application help.
     41 *  @param[in] index The index of the parameter.
     42 *  @param[in] parameter The parameter name.
    4643 */
    47 int parse_address_family(const char * name);
     44void print_unrecognized(int index, const char * parameter);
    4845
    4946/** Parses the next parameter as an integral number.
     
    6158 */
    6259int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset);
     60
     61/** Parses the next parameter as a character string.
     62 *  The actual parameter is pointed by the index.
     63 *  Uses the offseted actual parameter value if the offset is set or the next one if not.
     64 *  Increments the actual index by the number of processed parameters.
     65 *  @param[in] argc The total number of the parameters.
     66 *  @param[in] argv The parameters.
     67 *  @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
     68 *  @param[out] value The parsed parameter value.
     69 *  @param[in] name The parameter name to be printed on errors.
     70 *  @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
     71 *  @returns EOK on success.
     72 *  @returns EINVAL if the parameter is missing.
     73 */
     74int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset);
    6375
    6476/** Parses the next named parameter as an integral number.
     
    8092int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value));
    8193
    82 /** Parses the next parameter as a character string.
    83  *  The actual parameter is pointed by the index.
    84  *  Uses the offseted actual parameter value if the offset is set or the next one if not.
    85  *  Increments the actual index by the number of processed parameters.
    86  *  @param[in] argc The total number of the parameters.
    87  *  @param[in] argv The parameters.
    88  *  @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
    89  *  @param[out] value The parsed parameter value.
    90  *  @param[in] name The parameter name to be printed on errors.
    91  *  @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
    92  *  @returns EOK on success.
    93  *  @returns EINVAL if the parameter is missing.
    94  */
    95 int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset);
    96 
    97 /** Translates the character string to the protocol family number.
    98  *  @param[in] name The protocol family name.
    99  *  @returns The corresponding protocol family number.
    100  *  @returns EPFNOSUPPORTED if the protocol family is not supported.
    101  */
    102 int parse_protocol_family(const char * name);
    103 
    104 /** Translates the character string to the socket type number.
    105  *  @param[in] name The socket type name.
    106  *  @returns The corresponding socket type number.
    107  *  @returns ESOCKNOSUPPORTED if the socket type is not supported.
    108  */
    109 int parse_socket_type(const char * name);
    110 
    111 /** Prints the parameter unrecognized message and the application help.
    112  *  @param[in] index The index of the parameter.
    113  *  @param[in] parameter The parameter name.
    114  */
    115 void print_unrecognized(int index, const char * parameter);
    116 
    11794#endif
    11895
  • uspace/srv/net/app/ping/ping.c

    r60ab6c3 r71b00dcc  
    3939#include <task.h>
    4040#include <time.h>
    41 #include <ipc/ipc.h>
    4241#include <ipc/services.h>
    4342
     
    6867/** Prints the application help.
    6968 */
    70 void ping_print_help(void);
     69void print_help(void);
     70
     71/** Translates the character string to the address family number.
     72 *  @param[in] name The address family name.
     73 *  @returns The corresponding address family number.
     74 *  @returns EAFNOSUPPORTED if the address family is not supported.
     75 */
     76int parse_address_family(const char * name);
     77
     78void print_help(void){
     79        printf(
     80                "Network Ping aplication\n" \
     81                "Usage: ping [options] numeric_address\n" \
     82                "Where options are:\n" \
     83                "\n" \
     84                "-c request_count | --count=request_count\n" \
     85                "\tThe number of packets the application sends. The default is three (3).\n" \
     86                "\n" \
     87                "--dont_fragment\n" \
     88                "\tDisable packet fragmentation.\n"
     89                "\n" \
     90                "-f address_family | --family=address_family\n" \
     91                "\tThe given address family. Only the AF_INET and AF_INET6 are supported.\n"
     92                "\n" \
     93                "-h | --help\n" \
     94                "\tShow this application help.\n"
     95                "\n" \
     96                "-s packet_size | --size=packet_size\n" \
     97                "\tThe packet data size the application sends. The default is 38 bytes.\n" \
     98                "\n" \
     99                "-t timeout | --timeout=timeout\n" \
     100                "\tThe number of miliseconds the application waits for a reply. The default is three thousands (3 000).\n" \
     101                "\n" \
     102                "--tos=tos\n" \
     103                "\tThe type of service to be used.\n" \
     104                "\n" \
     105                "--ttl=ttl\n" \
     106                "\tThe time to live to be used.\n" \
     107                "\n" \
     108                "-v | --verbose\n" \
     109                "\tShow all output messages.\n"
     110        );
     111}
     112
     113int parse_address_family(const char * name){
     114        if(str_lcmp(name, "AF_INET", 7) == 0){
     115                return AF_INET;
     116        }else if(str_lcmp(name, "AF_INET6", 8) == 0){
     117                return AF_INET6;
     118        }
     119        return EAFNOSUPPORT;
     120}
    71121
    72122int main(int argc, char * argv[]){
     
    76126        int verbose                     = 0;
    77127        int dont_fragment       = 0;
    78         ip_ttl_t ttl            = 0;
    79         ip_tos_t tos            = 0;
     128        ip_ttl_t ttl                            = 0;
     129        ip_tos_t tos                            = 0;
    80130        int count                       = 3;
    81         suseconds_t timeout     = 3000;
     131        suseconds_t timeout                     = 3000;
    82132        int family                      = AF_INET;
    83133
    84         socklen_t max_length                            = sizeof(struct sockaddr_in6);
     134        socklen_t max_length            = sizeof(struct sockaddr_in6);
    85135        uint8_t address_data[max_length];
    86         struct sockaddr * address                       = (struct sockaddr *) address_data;
     136        struct sockaddr * address               = (struct sockaddr *) address_data;
    87137        struct sockaddr_in * address_in         = (struct sockaddr_in *) address;
    88138        struct sockaddr_in6 * address_in6       = (struct sockaddr_in6 *) address;
     
    97147        int index;
    98148
    99         // print the program label
    100149        printf("Task %d - ", task_get_id());
    101150        printf("%s\n", NAME);
    102151
    103         // parse the command line arguments
    104         // stop before the last argument if it does not start with the minus sign ('-')
    105         for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
    106                 // options should start with the minus sign ('-')
     152        if(argc <= 1){
     153                print_help();
     154                return EINVAL;
     155        }
     156
     157        for(index = 1; (index < argc - 1) || ((index == argc) && (argv[index][0] == '-')); ++ index){
    107158                if(argv[index][0] == '-'){
    108159                        switch(argv[index][1]){
    109                                 // short options with only one letter
    110160                                case 'c':
    111161                                        ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "count", 0));
     
    115165                                        break;
    116166                                case 'h':
    117                                         ping_print_help();
     167                                        print_help();
    118168                                        return EOK;
    119169                                        break;
     
    129179                                        verbose = 1;
    130180                                        break;
    131                                 // long options with the double minus sign ('-')
    132181                                case '-':
    133182                                        if(str_lcmp(argv[index] + 2, "count=", 6) == 0){
     
    138187                                                ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "address family", 9, parse_address_family));
    139188                                        }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
    140                                                 ping_print_help();
     189                                                print_help();
    141190                                                return EOK;
    142191                                        }else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){
     
    156205                                        }else{
    157206                                                print_unrecognized(index, argv[index] + 2);
    158                                                 ping_print_help();
     207                                                print_help();
    159208                                                return EINVAL;
    160209                                        }
     
    162211                                default:
    163212                                        print_unrecognized(index, argv[index] + 1);
    164                                         ping_print_help();
     213                                        print_help();
    165214                                        return EINVAL;
    166215                        }
    167216                }else{
    168217                        print_unrecognized(index, argv[index]);
    169                         ping_print_help();
     218                        print_help();
    170219                        return EINVAL;
    171220                }
    172221        }
    173222
    174         // if not before the last argument containing the address
    175         if(index >= argc){
    176                 printf("Command line error: missing address\n");
    177                 ping_print_help();
    178                 return EINVAL;
    179         }
    180 
    181         // prepare the address buffer
    182223        bzero(address_data, max_length);
    183224        switch(family){
     
    197238        }
    198239
    199         // parse the last argument which should contain the address
    200240        if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
    201241                fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
     
    203243        }
    204244
    205         // connect to the ICMP module
    206245        icmp_phone = icmp_connect_module(SERVICE_ICMP, ICMP_CONNECT_TIMEOUT);
    207246        if(icmp_phone < 0){
     
    210249        }
    211250
    212         // print the ping header
    213251        printf("PING %d bytes of data\n", size);
    214252        if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){
     
    218256        }
    219257
    220         // do count times
    221258        while(count > 0){
    222 
    223                 // get the starting time
    224259                if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
    225260                        fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    226                         // release the ICMP phone
    227                         ipc_hangup(icmp_phone);
    228261                        return ERROR_CODE;
    229262                }
    230 
    231                 // request the ping
    232263                result = icmp_echo_msg(icmp_phone, size, timeout, ttl, tos, dont_fragment, address, addrlen);
    233 
    234                 // get the ending time
    235264                if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
    236265                        fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    237                         // release the ICMP phone
    238                         ipc_hangup(icmp_phone);
    239266                        return ERROR_CODE;
    240267                }
    241 
    242                 // print the result
    243268                switch(result){
    244269                        case ICMP_ECHO:
     
    258283        }
    259284
    260         // release the ICMP phone
    261         ipc_hangup(icmp_phone);
    262 
    263285        return EOK;
    264286}
    265287
    266 void ping_print_help(void){
    267         printf(
    268                 "Network Ping aplication\n" \
    269                 "Usage: ping [options] numeric_address\n" \
    270                 "Where options are:\n" \
    271                 "\n" \
    272                 "-c request_count | --count=request_count\n" \
    273                 "\tThe number of packets the application sends. The default is three (3).\n" \
    274                 "\n" \
    275                 "--dont_fragment\n" \
    276                 "\tDisable packet fragmentation.\n"
    277                 "\n" \
    278                 "-f address_family | --family=address_family\n" \
    279                 "\tThe given address family. Only the AF_INET and AF_INET6 are supported.\n"
    280                 "\n" \
    281                 "-h | --help\n" \
    282                 "\tShow this application help.\n"
    283                 "\n" \
    284                 "-s packet_size | --size=packet_size\n" \
    285                 "\tThe packet data size the application sends. The default is 38 bytes.\n" \
    286                 "\n" \
    287                 "-t timeout | --timeout=timeout\n" \
    288                 "\tThe number of miliseconds the application waits for a reply. The default is three thousands (3 000).\n" \
    289                 "\n" \
    290                 "--tos=tos\n" \
    291                 "\tThe type of service to be used.\n" \
    292                 "\n" \
    293                 "--ttl=ttl\n" \
    294                 "\tThe time to live to be used.\n" \
    295                 "\n" \
    296                 "-v | --verbose\n" \
    297                 "\tShow all output messages.\n"
    298         );
    299 }
    300 
    301288/** @}
    302289 */
  • uspace/srv/net/app/print_error.c

    r60ab6c3 r71b00dcc  
    4141
    4242#include "print_error.h"
     43
     44void print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
     45        if(IS_ICMP_ERROR(error_code)){
     46                icmp_print_error(output, error_code, prefix, suffix);
     47        }else if(IS_SOCKET_ERROR(error_code)){
     48                socket_print_error(output, error_code, prefix, suffix);
     49        }
     50}
    4351
    4452void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
     
    93101}
    94102
    95 void print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
    96         if(IS_ICMP_ERROR(error_code)){
    97                 icmp_print_error(output, error_code, prefix, suffix);
    98         }else if(IS_SOCKET_ERROR(error_code)){
    99                 socket_print_error(output, error_code, prefix, suffix);
    100         }
    101 }
    102 
    103103void socket_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
    104104        if(output){
  • uspace/srv/net/app/print_error.h

    r60ab6c3 r71b00dcc  
    5050#define IS_SOCKET_ERROR(error_code)     ((error_code) < 0)
    5151
    52 /** Prints the specific ICMP error description.
    53  *  @param[in] output The description output stream. May be NULL.
    54  *  @param[in] error_code The ICMP error code.
    55  *  @param[in] prefix The error description prefix. May be NULL.
    56  *  @param[in] suffix The error description suffix. May be NULL.
    57  */
    58 void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
    59 
    6052/** Prints the error description.
    6153 *  Supports ICMP and socket error codes.
     
    6658 */
    6759void print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
     60
     61/** Prints the specific ICMP error description.
     62 *  @param[in] output The description output stream. May be NULL.
     63 *  @param[in] error_code The ICMP error code.
     64 *  @param[in] prefix The error description prefix. May be NULL.
     65 *  @param[in] suffix The error description suffix. May be NULL.
     66 */
     67void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
    6868
    6969/** Prints the specific socket error description.
  • uspace/srv/net/cfg/modular/general

    r60ab6c3 r71b00dcc  
    33IPV=4
    44IP_ROUTING=no
    5 
    65MTU=1500
    7 
    86ICMP_ERROR_REPORTING=yes
    97ICMP_ECHO_REPLYING=yes
    10 
    118UDP_CHECKSUM_COMPUTING=yes
    129UDP_AUTOBINDING=yes
  • uspace/srv/net/cfg/module/general

    r60ab6c3 r71b00dcc  
    33IPV=4
    44IP_ROUTING=no
    5 
    65MTU=1500
    7 
    86ICMP_ERROR_REPORTING=yes
    97ICMP_ECHO_REPLYING=yes
    10 
    118UDP_CHECKSUM_COMPUTING=yes
    129UDP_AUTOBINDING=yes
  • uspace/srv/net/checksum.c

    r60ab6c3 r71b00dcc  
    4747#define CRC_DIVIDER_LE  0xEDB88320
    4848
    49 uint16_t compact_checksum(uint32_t sum){
    50         // shorten to the 16 bits
    51         while(sum >> 16){
    52                 sum = (sum &0xFFFF) + (sum >> 16);
     49uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length){
     50        size_t index;
     51
     52        while(length >= 8){
     53                seed ^= (*data);
     54                for(index = 0; index < 8; ++ index){
     55                        if(seed &1){
     56                                seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
     57                        }else{
     58                                seed >>= 1;
     59                        }
     60                }
     61                ++ data;
     62                length -= 8;
    5363        }
     64        if(length > 0){
     65                seed ^= (*data) >> (8 - length);
     66                for(index = 0; index < length; ++ index){
     67                        if(seed &1){
     68                                seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
     69                        }else{
     70                                seed >>= 1;
     71                        }
     72                }
     73                length -= 8;
     74        }
     75        return seed;
     76}
    5477
    55         return (uint16_t) sum;
     78uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length){
     79        size_t index;
     80
     81        while(length >= 8){
     82                seed ^= (*data) << 24;
     83                for(index = 0; index < 8; ++ index){
     84                        if(seed &0x80000000){
     85                                seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
     86                        }else{
     87                                seed <<= 1;
     88                        }
     89                }
     90                ++ data;
     91                length -= 8;
     92        }
     93        if(length > 0){
     94                seed ^= ((*data) &(0xFF << (8 - length))) << 24;
     95                for(index = 0; index < length; ++ index){
     96                        if(seed &0x80000000){
     97                                seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
     98                        }else{
     99                                seed <<= 1;
     100                        }
     101                }
     102                length -= 8;
     103        }
     104        return seed;
    56105}
    57106
     
    72121}
    73122
    74 uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length){
    75         size_t index;
    76 
    77         // process full bytes
    78         while(length >= 8){
    79                 // add the data
    80                 seed ^= (*data) << 24;
    81                 // for each added bit
    82                 for(index = 0; index < 8; ++ index){
    83                         // if the first bit is set
    84                         if(seed &0x80000000){
    85                                 // shift and divide the checksum
    86                                 seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
    87                         }else{
    88                                 // shift otherwise
    89                                 seed <<= 1;
    90                         }
    91                 }
    92                 // move to the next byte
    93                 ++ data;
    94                 length -= 8;
     123uint16_t compact_checksum(uint32_t sum){
     124        // shorten to the 16 bits
     125        while(sum >> 16){
     126                sum = (sum &0xFFFF) + (sum >> 16);
    95127        }
    96128
    97         // process the odd bits
    98         if(length > 0){
    99                 // add the data with zero padding
    100                 seed ^= ((*data) &(0xFF << (8 - length))) << 24;
    101                 // for each added bit
    102                 for(index = 0; index < length; ++ index){
    103                         // if the first bit is set
    104                         if(seed &0x80000000){
    105                                 // shift and divide the checksum
    106                                 seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
    107                         }else{
    108                                 // shift otherwise
    109                                 seed <<= 1;
    110                         }
    111                 }
    112         }
    113 
    114         return seed;
    115 }
    116 
    117 uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length){
    118         size_t index;
    119 
    120         // process full bytes
    121         while(length >= 8){
    122                 // add the data
    123                 seed ^= (*data);
    124                 // for each added bit
    125                 for(index = 0; index < 8; ++ index){
    126                         // if the last bit is set
    127                         if(seed &1){
    128                                 // shift and divide the checksum
    129                                 seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
    130                         }else{
    131                                 // shift otherwise
    132                                 seed >>= 1;
    133                         }
    134                 }
    135                 // move to the next byte
    136                 ++ data;
    137                 length -= 8;
    138         }
    139 
    140         // process the odd bits
    141         if(length > 0){
    142                 // add the data with zero padding
    143                 seed ^= (*data) >> (8 - length);
    144                 for(index = 0; index < length; ++ index){
    145                         // if the last bit is set
    146                         if(seed &1){
    147                                 // shift and divide the checksum
    148                                 seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
    149                         }else{
    150                                 // shift otherwise
    151                                 seed >>= 1;
    152                         }
    153                 }
    154         }
    155 
    156         return seed;
     129        return (uint16_t) sum;
    157130}
    158131
     
    164137
    165138uint16_t ip_checksum(uint8_t * data, size_t length){
    166         // compute, compact and flip the data checksum
    167139        return flip_checksum(compact_checksum(compute_checksum(0, data, length)));
    168140}
  • uspace/srv/net/configuration.h

    r60ab6c3 r71b00dcc  
    4646/*@{*/
    4747
     48/** Activates the measured strings self test.
     49 *  The NET_SELF_TEST has to be activated.
     50 *  @see measured_strings.h
     51 */
     52#define NET_SELF_TEST_MEASURED_STRINGS  1
     53
    4854/** Activates the char map self test.
    4955 *  The NET_SELF_TEST has to be activated.
     
    5258#define NET_SELF_TEST_CHAR_MAP                  1
    5359
    54 /** Activates the CRC computation self test.
     60/** Activates the integral map self test.
    5561 *  The NET_SELF_TEST has to be activated.
    56  *  @see crc.h
     62 *  @see int_map.h
    5763 */
    58 #define NET_SELF_TEST_CRC                               1
     64#define NET_SELF_TEST_INT_MAP                   1
    5965
    60 /** Activates the dynamic fifo self test.
     66/** Activates the generic field self test.
    6167 *  The NET_SELF_TEST has to be activated.
    62  *  @see dynamic_fifo.h
     68 *  @see generic_field.h
    6369 */
    64 #define NET_SELF_TEST_DYNAMIC_FIFO              1
     70#define NET_SELF_TEST_GENERIC_FIELD             1
    6571
    6672/** Activates the generic char map self test.
     
    7076#define NET_SELF_TEST_GENERIC_CHAR_MAP  1
    7177
    72 /** Activates the generic field self test.
     78/** Activates the CRC computation self test.
    7379 *  The NET_SELF_TEST has to be activated.
    74  *  @see generic_field.h
     80 *  @see crc.h
    7581 */
    76 #define NET_SELF_TEST_GENERIC_FIELD             1
     82#define NET_SELF_TEST_CRC       1
    7783
    78 /** Activates the integral map self test.
     84/** Activates the dynamic fifo self test.
    7985 *  The NET_SELF_TEST has to be activated.
    80  *  @see int_map.h
     86 *  @see dynamic_fifo.h
    8187 */
    82 #define NET_SELF_TEST_INT_MAP                   1
    83 
    84 /** Activates the measured strings self test.
    85  *  The NET_SELF_TEST has to be activated.
    86  *  @see measured_strings.h
    87  */
    88 #define NET_SELF_TEST_MEASURED_STRINGS  1
     88#define NET_SELF_TEST_DYNAMIC_FIFO      1
    8989
    9090/*@}*/
  • uspace/srv/net/err.h

    r60ab6c3 r71b00dcc  
    6262#ifdef CONFIG_DEBUG
    6363
    64 #define ERROR_OCCURRED(value)                                                                                           \
    65         (((ERROR_CODE = (value)) != EOK)                                                                                \
    66         && ({printf("error at %s:%d %d\n", __FILE__, __LINE__, ERROR_CODE); 1;}))
     64#define ERROR_OCCURRED(value)           (((ERROR_CODE = (value)) != EOK) && ({printf("error at %s:%d %d\n", __FILE__, __LINE__, ERROR_CODE); 1;}))
    6765
    6866#else
  • uspace/srv/net/il/arp/arp.c

    r60ab6c3 r71b00dcc  
    7373arp_globals_t   arp_globals;
    7474
    75 /** Clears the device specific data.
    76  *  @param[in] device The device specific data.
    77  */
    78 void arp_clear_device(arp_device_ref device);
    79 
    8075/** Creates new protocol specific data.
    8176 *  Allocates and returns the needed memory block as the proto parameter.
     
    8782 */
    8883int arp_proto_create(arp_proto_ref * proto, services_t service, measured_string_ref address);
     84
     85/** Clears the device specific data.
     86 *  @param[in] device The device specific data.
     87 */
     88void arp_clear_device(arp_device_ref device);
    8989
    9090/** @name Message processing functions
     
    105105int arp_device_message(device_id_t device_id, services_t service, services_t protocol, measured_string_ref address);
    106106
    107 /** Updates the device content length according to the new MTU value.
     107/** Returns the hardware address for the given protocol address.
     108 *  Sends the ARP request packet if the hardware address is not found in the cache.
    108109 *  @param[in] device_id The device identifier.
    109  *  @param[in] mtu The new mtu value.
    110  *  @returns ENOENT if device is not found.
    111  *  @returns EOK on success.
    112  */
    113 int arp_mtu_changed_message(device_id_t device_id, size_t mtu);
     110 *  @param[in] protocol The protocol service.
     111 *  @param[in] target The target protocol address.
     112 *  @returns The hardware address of the target.
     113 *  @returns NULL if the target parameter is NULL.
     114 *  @returns NULL if the device is not found.
     115 *  @returns NULL if the device packet is too small to send a&nbsp;request.
     116 *  @returns NULL if the hardware address is not found in the cache.
     117 */
     118measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target);
    114119
    115120/** Processes the received ARP packet.
     
    128133int arp_receive_message(device_id_t device_id, packet_t packet);
    129134
    130 /** Returns the hardware address for the given protocol address.
    131  *  Sends the ARP request packet if the hardware address is not found in the cache.
     135/** Updates the device content length according to the new MTU value.
    132136 *  @param[in] device_id The device identifier.
    133  *  @param[in] protocol The protocol service.
    134  *  @param[in] target The target protocol address.
    135  *  @returns The hardware address of the target.
    136  *  @returns NULL if the target parameter is NULL.
    137  *  @returns NULL if the device is not found.
    138  *  @returns NULL if the device packet is too small to send a&nbsp;request.
    139  *  @returns NULL if the hardware address is not found in the cache.
    140  */
    141 measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target);
     137 *  @param[in] mtu The new mtu value.
     138 *  @returns ENOENT if device is not found.
     139 *  @returns EOK on success.
     140 */
     141int arp_mtu_changed_message(device_id_t device_id, size_t mtu);
    142142
    143143/*@}*/
     
    148148
    149149GENERIC_CHAR_MAP_IMPLEMENT(arp_addr, measured_string_t)
     150
     151task_id_t arp_task_get_id(void){
     152        return task_get_id();
     153}
     154
     155int arp_clear_device_req(int arp_phone, device_id_t device_id){
     156        arp_device_ref device;
     157
     158        fibril_rwlock_write_lock(&arp_globals.lock);
     159        device = arp_cache_find(&arp_globals.cache, device_id);
     160        if(! device){
     161                fibril_rwlock_write_unlock(&arp_globals.lock);
     162                return ENOENT;
     163        }
     164        arp_clear_device(device);
     165        printf("Device %d cleared\n", device_id);
     166        fibril_rwlock_write_unlock(&arp_globals.lock);
     167        return EOK;
     168}
     169
     170int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address){
     171        arp_device_ref device;
     172        arp_proto_ref proto;
     173
     174        fibril_rwlock_write_lock(&arp_globals.lock);
     175        device = arp_cache_find(&arp_globals.cache, device_id);
     176        if(! device){
     177                fibril_rwlock_write_unlock(&arp_globals.lock);
     178                return ENOENT;
     179        }
     180        proto = arp_protos_find(&device->protos, protocol);
     181        if(! proto){
     182                fibril_rwlock_write_unlock(&arp_globals.lock);
     183                return ENOENT;
     184        }
     185        arp_addr_exclude(&proto->addresses, address->value, address->length);
     186        fibril_rwlock_write_unlock(&arp_globals.lock);
     187        return EOK;
     188}
    150189
    151190int arp_clean_cache_req(int arp_phone){
     
    172211}
    173212
    174 int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address){
    175         arp_device_ref device;
    176         arp_proto_ref proto;
    177 
     213int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
     214        ERROR_DECLARE;
     215
     216        measured_string_ref tmp;
     217
     218        // copy the given address for exclusive use
     219        tmp = measured_string_copy(address);
     220        if(ERROR_OCCURRED(arp_device_message(device_id, netif, protocol, tmp))){
     221                free(tmp->value);
     222                free(tmp);
     223        }
     224        return ERROR_CODE;
     225}
     226
     227int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
     228        measured_string_ref tmp;
     229
     230        fibril_rwlock_read_lock(&arp_globals.lock);
     231        tmp = arp_translate_message(device_id, protocol, address);
     232        if(tmp){
     233                *translation = measured_string_copy(tmp);
     234                fibril_rwlock_read_unlock(&arp_globals.lock);
     235                if(*translation){
     236                        *data = (** translation).value;
     237                        return EOK;
     238                }else{
     239                        return ENOMEM;
     240                }
     241        }else{
     242                fibril_rwlock_read_unlock(&arp_globals.lock);
     243                return ENOENT;
     244        }
     245}
     246
     247int arp_initialize(async_client_conn_t client_connection){
     248        ERROR_DECLARE;
     249
     250        fibril_rwlock_initialize(&arp_globals.lock);
    178251        fibril_rwlock_write_lock(&arp_globals.lock);
    179         device = arp_cache_find(&arp_globals.cache, device_id);
    180         if(! device){
    181                 fibril_rwlock_write_unlock(&arp_globals.lock);
    182                 return ENOENT;
    183         }
    184         proto = arp_protos_find(&device->protos, protocol);
    185         if(! proto){
    186                 fibril_rwlock_write_unlock(&arp_globals.lock);
    187                 return ENOENT;
    188         }
    189         arp_addr_exclude(&proto->addresses, address->value, address->length);
     252        arp_globals.client_connection = client_connection;
     253        ERROR_PROPAGATE(arp_cache_initialize(&arp_globals.cache));
    190254        fibril_rwlock_write_unlock(&arp_globals.lock);
    191255        return EOK;
    192256}
    193257
    194 void arp_clear_device(arp_device_ref device){
    195         int count;
    196         arp_proto_ref proto;
    197 
    198         for(count = arp_protos_count(&device->protos) - 1; count >= 0; -- count){
    199                 proto = arp_protos_get_index(&device->protos, count);
    200                 if(proto){
    201                         if(proto->addr){
    202                                 free(proto->addr);
    203                         }
    204                         if(proto->addr_data){
    205                                 free(proto->addr_data);
    206                         }
    207                         arp_addr_destroy(&proto->addresses);
    208                 }
    209         }
    210         arp_protos_clear(&device->protos);
    211 }
    212 
    213 int arp_clear_device_req(int arp_phone, device_id_t device_id){
    214         arp_device_ref device;
    215 
    216         fibril_rwlock_write_lock(&arp_globals.lock);
    217         device = arp_cache_find(&arp_globals.cache, device_id);
    218         if(! device){
    219                 fibril_rwlock_write_unlock(&arp_globals.lock);
    220                 return ENOENT;
    221         }
    222         arp_clear_device(device);
    223         printf("Device %d cleared\n", device_id);
    224         fibril_rwlock_write_unlock(&arp_globals.lock);
    225         return EOK;
    226 }
    227 
    228 int arp_connect_module(services_t service){
    229         if(service != SERVICE_ARP){
    230                 return EINVAL;
     258int arp_proto_create(arp_proto_ref * proto, services_t service, measured_string_ref address){
     259        ERROR_DECLARE;
     260
     261        *proto = (arp_proto_ref) malloc(sizeof(arp_proto_t));
     262        if(!(*proto)){
     263                return ENOMEM;
     264        }
     265        (** proto).service = service;
     266        (** proto).addr = address;
     267        (** proto).addr_data = address->value;
     268        if(ERROR_OCCURRED(arp_addr_initialize(&(** proto).addresses))){
     269                free(*proto);
     270                return ERROR_CODE;
    231271        }
    232272        return EOK;
     
    343383}
    344384
    345 int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
     385measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target){
     386        arp_device_ref device;
     387        arp_proto_ref proto;
     388        measured_string_ref addr;
     389        size_t length;
     390        packet_t packet;
     391        arp_header_ref header;
     392
     393        if(! target){
     394                return NULL;
     395        }
     396        device = arp_cache_find(&arp_globals.cache, device_id);
     397        if(! device){
     398                return NULL;
     399        }
     400        proto = arp_protos_find(&device->protos, protocol);
     401        if((! proto) || (proto->addr->length != target->length)){
     402                return NULL;
     403        }
     404        addr = arp_addr_find(&proto->addresses, target->value, target->length);
     405        if(addr){
     406                return addr;
     407        }
     408        // ARP packet content size = header + (address + translation) * 2
     409        length = 8 + (CONVERT_SIZE(char, uint8_t, proto->addr->length) + CONVERT_SIZE(char, uint8_t, device->addr->length)) * 2;
     410        if(length > device->packet_dimension.content){
     411                return NULL;
     412        }
     413        packet = packet_get_4(arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix);
     414        if(! packet){
     415                return NULL;
     416        }
     417        header = (arp_header_ref) packet_suffix(packet, length);
     418        if(! header){
     419                pq_release(arp_globals.net_phone, packet_get_id(packet));
     420                return NULL;
     421        }
     422        header->hardware = htons(device->hardware);
     423        header->hardware_length = (uint8_t) device->addr->length;
     424        header->protocol = htons(protocol_map(device->service, protocol));
     425        header->protocol_length = (uint8_t) proto->addr->length;
     426        header->operation = htons(ARPOP_REQUEST);
     427        length = sizeof(arp_header_t);
     428        memcpy(((uint8_t *) header) + length, device->addr->value, device->addr->length);
     429        length += device->addr->length;
     430        memcpy(((uint8_t *) header) + length, proto->addr->value, proto->addr->length);
     431        length += proto->addr->length;
     432        bzero(((uint8_t *) header) + length, device->addr->length);
     433        length += device->addr->length;
     434        memcpy(((uint8_t *) header) + length, target->value, target->length);
     435        if(packet_set_addr(packet, (uint8_t *) device->addr->value, (uint8_t *) device->broadcast_addr->value, CONVERT_SIZE(char, uint8_t, device->addr->length)) != EOK){
     436                pq_release(arp_globals.net_phone, packet_get_id(packet));
     437                return NULL;
     438        }
     439        nil_send_msg(device->phone, device_id, packet, SERVICE_ARP);
     440        return NULL;
     441}
     442
     443int arp_receive_message(device_id_t device_id, packet_t packet){
    346444        ERROR_DECLARE;
    347445
    348         measured_string_ref tmp;
    349 
    350         // copy the given address for exclusive use
    351         tmp = measured_string_copy(address);
    352         if(ERROR_OCCURRED(arp_device_message(device_id, netif, protocol, tmp))){
    353                 free(tmp->value);
    354                 free(tmp);
    355         }
    356         return ERROR_CODE;
    357 }
    358 
    359 int arp_initialize(async_client_conn_t client_connection){
    360         ERROR_DECLARE;
    361 
    362         fibril_rwlock_initialize(&arp_globals.lock);
     446        size_t length;
     447        arp_header_ref header;
     448        arp_device_ref device;
     449        arp_proto_ref proto;
     450        measured_string_ref hw_source;
     451        uint8_t * src_hw;
     452        uint8_t * src_proto;
     453        uint8_t * des_hw;
     454        uint8_t * des_proto;
     455
     456        length = packet_get_data_length(packet);
     457        if(length <= sizeof(arp_header_t)){
     458                return EINVAL;
     459        }
     460        device = arp_cache_find(&arp_globals.cache, device_id);
     461        if(! device){
     462                return ENOENT;
     463        }
     464        header = (arp_header_ref) packet_get_data(packet);
     465        if((ntohs(header->hardware) != device->hardware)
     466                || (length < sizeof(arp_header_t) + header->hardware_length * 2u + header->protocol_length * 2u)){
     467                return EINVAL;
     468        }
     469        proto = arp_protos_find(&device->protos, protocol_unmap(device->service, ntohs(header->protocol)));
     470        if(! proto){
     471                return ENOENT;
     472        }
     473        src_hw = ((uint8_t *) header) + sizeof(arp_header_t);
     474        src_proto = src_hw + header->hardware_length;
     475        des_hw = src_proto + header->protocol_length;
     476        des_proto = des_hw + header->hardware_length;
     477        hw_source = arp_addr_find(&proto->addresses, (char *) src_proto, CONVERT_SIZE(uint8_t, char, header->protocol_length));
     478        // exists?
     479        if(hw_source){
     480                if(hw_source->length != CONVERT_SIZE(uint8_t, char, header->hardware_length)){
     481                        return EINVAL;
     482                }
     483                memcpy(hw_source->value, src_hw, hw_source->length);
     484        }
     485        // is my protocol address?
     486        if(proto->addr->length != CONVERT_SIZE(uint8_t, char, header->protocol_length)){
     487                return EINVAL;
     488        }
     489        if(! str_lcmp(proto->addr->value, (char *) des_proto, proto->addr->length)){
     490                // not already upadted?
     491                if(! hw_source){
     492                        hw_source = measured_string_create_bulk((char *) src_hw, CONVERT_SIZE(uint8_t, char, header->hardware_length));
     493                        if(! hw_source){
     494                                return ENOMEM;
     495                        }
     496                        ERROR_PROPAGATE(arp_addr_add(&proto->addresses, (char *) src_proto, CONVERT_SIZE(uint8_t, char, header->protocol_length), hw_source));
     497                }
     498                if(ntohs(header->operation) == ARPOP_REQUEST){
     499                        header->operation = htons(ARPOP_REPLY);
     500                        memcpy(des_proto, src_proto, header->protocol_length);
     501                        memcpy(src_proto, proto->addr->value, header->protocol_length);
     502                        memcpy(src_hw, device->addr->value, device->packet_dimension.addr_len);
     503                        memcpy(des_hw, hw_source->value, header->hardware_length);
     504                        ERROR_PROPAGATE(packet_set_addr(packet, src_hw, des_hw, header->hardware_length));
     505                        nil_send_msg(device->phone, device_id, packet, SERVICE_ARP);
     506                        return 1;
     507                }
     508        }
     509        return EOK;
     510}
     511
     512void arp_clear_device(arp_device_ref device){
     513        int count;
     514        arp_proto_ref proto;
     515
     516        for(count = arp_protos_count(&device->protos) - 1; count >= 0; -- count){
     517                proto = arp_protos_get_index(&device->protos, count);
     518                if(proto){
     519                        if(proto->addr){
     520                                free(proto->addr);
     521                        }
     522                        if(proto->addr_data){
     523                                free(proto->addr_data);
     524                        }
     525                        arp_addr_destroy(&proto->addresses);
     526                }
     527        }
     528        arp_protos_clear(&device->protos);
     529}
     530
     531int arp_connect_module(services_t service){
     532        if(service != SERVICE_ARP){
     533                return EINVAL;
     534        }
     535        return EOK;
     536}
     537
     538int arp_mtu_changed_message(device_id_t device_id, size_t mtu){
     539        arp_device_ref device;
     540
    363541        fibril_rwlock_write_lock(&arp_globals.lock);
    364         arp_globals.client_connection = client_connection;
    365         ERROR_PROPAGATE(arp_cache_initialize(&arp_globals.cache));
     542        device = arp_cache_find(&arp_globals.cache, device_id);
     543        if(! device){
     544                fibril_rwlock_write_unlock(&arp_globals.lock);
     545                return ENOENT;
     546        }
     547        device->packet_dimension.content = mtu;
     548        printf("arp - device %d changed mtu to %d\n\n", device_id, mtu);
    366549        fibril_rwlock_write_unlock(&arp_globals.lock);
    367550        return EOK;
     
    435618}
    436619
    437 int arp_mtu_changed_message(device_id_t device_id, size_t mtu){
    438         arp_device_ref device;
    439 
    440         fibril_rwlock_write_lock(&arp_globals.lock);
    441         device = arp_cache_find(&arp_globals.cache, device_id);
    442         if(! device){
    443                 fibril_rwlock_write_unlock(&arp_globals.lock);
    444                 return ENOENT;
    445         }
    446         device->packet_dimension.content = mtu;
    447         printf("arp - device %d changed mtu to %d\n\n", device_id, mtu);
    448         fibril_rwlock_write_unlock(&arp_globals.lock);
    449         return EOK;
    450 }
    451 
    452 int arp_proto_create(arp_proto_ref * proto, services_t service, measured_string_ref address){
    453         ERROR_DECLARE;
    454 
    455         *proto = (arp_proto_ref) malloc(sizeof(arp_proto_t));
    456         if(!(*proto)){
    457                 return ENOMEM;
    458         }
    459         (** proto).service = service;
    460         (** proto).addr = address;
    461         (** proto).addr_data = address->value;
    462         if(ERROR_OCCURRED(arp_addr_initialize(&(** proto).addresses))){
    463                 free(*proto);
    464                 return ERROR_CODE;
    465         }
    466         return EOK;
    467 }
    468 
    469 int arp_receive_message(device_id_t device_id, packet_t packet){
    470         ERROR_DECLARE;
    471 
    472         size_t length;
    473         arp_header_ref header;
    474         arp_device_ref device;
    475         arp_proto_ref proto;
    476         measured_string_ref hw_source;
    477         uint8_t * src_hw;
    478         uint8_t * src_proto;
    479         uint8_t * des_hw;
    480         uint8_t * des_proto;
    481 
    482         length = packet_get_data_length(packet);
    483         if(length <= sizeof(arp_header_t)){
    484                 return EINVAL;
    485         }
    486         device = arp_cache_find(&arp_globals.cache, device_id);
    487         if(! device){
    488                 return ENOENT;
    489         }
    490         header = (arp_header_ref) packet_get_data(packet);
    491         if((ntohs(header->hardware) != device->hardware)
    492                 || (length < sizeof(arp_header_t) + header->hardware_length * 2u + header->protocol_length * 2u)){
    493                 return EINVAL;
    494         }
    495         proto = arp_protos_find(&device->protos, protocol_unmap(device->service, ntohs(header->protocol)));
    496         if(! proto){
    497                 return ENOENT;
    498         }
    499         src_hw = ((uint8_t *) header) + sizeof(arp_header_t);
    500         src_proto = src_hw + header->hardware_length;
    501         des_hw = src_proto + header->protocol_length;
    502         des_proto = des_hw + header->hardware_length;
    503         hw_source = arp_addr_find(&proto->addresses, (char *) src_proto, CONVERT_SIZE(uint8_t, char, header->protocol_length));
    504         // exists?
    505         if(hw_source){
    506                 if(hw_source->length != CONVERT_SIZE(uint8_t, char, header->hardware_length)){
    507                         return EINVAL;
    508                 }
    509                 memcpy(hw_source->value, src_hw, hw_source->length);
    510         }
    511         // is my protocol address?
    512         if(proto->addr->length != CONVERT_SIZE(uint8_t, char, header->protocol_length)){
    513                 return EINVAL;
    514         }
    515         if(! str_lcmp(proto->addr->value, (char *) des_proto, proto->addr->length)){
    516                 // not already upadted?
    517                 if(! hw_source){
    518                         hw_source = measured_string_create_bulk((char *) src_hw, CONVERT_SIZE(uint8_t, char, header->hardware_length));
    519                         if(! hw_source){
    520                                 return ENOMEM;
    521                         }
    522                         ERROR_PROPAGATE(arp_addr_add(&proto->addresses, (char *) src_proto, CONVERT_SIZE(uint8_t, char, header->protocol_length), hw_source));
    523                 }
    524                 if(ntohs(header->operation) == ARPOP_REQUEST){
    525                         header->operation = htons(ARPOP_REPLY);
    526                         memcpy(des_proto, src_proto, header->protocol_length);
    527                         memcpy(src_proto, proto->addr->value, header->protocol_length);
    528                         memcpy(src_hw, device->addr->value, device->packet_dimension.addr_len);
    529                         memcpy(des_hw, hw_source->value, header->hardware_length);
    530                         ERROR_PROPAGATE(packet_set_addr(packet, src_hw, des_hw, header->hardware_length));
    531                         nil_send_msg(device->phone, device_id, packet, SERVICE_ARP);
    532                         return 1;
    533                 }
    534         }
    535         return EOK;
    536 }
    537 
    538 task_id_t arp_task_get_id(void){
    539         return task_get_id();
    540 }
    541 
    542 measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target){
    543         arp_device_ref device;
    544         arp_proto_ref proto;
    545         measured_string_ref addr;
    546         size_t length;
    547         packet_t packet;
    548         arp_header_ref header;
    549 
    550         if(! target){
    551                 return NULL;
    552         }
    553         device = arp_cache_find(&arp_globals.cache, device_id);
    554         if(! device){
    555                 return NULL;
    556         }
    557         proto = arp_protos_find(&device->protos, protocol);
    558         if((! proto) || (proto->addr->length != target->length)){
    559                 return NULL;
    560         }
    561         addr = arp_addr_find(&proto->addresses, target->value, target->length);
    562         if(addr){
    563                 return addr;
    564         }
    565         // ARP packet content size = header + (address + translation) * 2
    566         length = 8 + (CONVERT_SIZE(char, uint8_t, proto->addr->length) + CONVERT_SIZE(char, uint8_t, device->addr->length)) * 2;
    567         if(length > device->packet_dimension.content){
    568                 return NULL;
    569         }
    570         packet = packet_get_4(arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix);
    571         if(! packet){
    572                 return NULL;
    573         }
    574         header = (arp_header_ref) packet_suffix(packet, length);
    575         if(! header){
    576                 pq_release(arp_globals.net_phone, packet_get_id(packet));
    577                 return NULL;
    578         }
    579         header->hardware = htons(device->hardware);
    580         header->hardware_length = (uint8_t) device->addr->length;
    581         header->protocol = htons(protocol_map(device->service, protocol));
    582         header->protocol_length = (uint8_t) proto->addr->length;
    583         header->operation = htons(ARPOP_REQUEST);
    584         length = sizeof(arp_header_t);
    585         memcpy(((uint8_t *) header) + length, device->addr->value, device->addr->length);
    586         length += device->addr->length;
    587         memcpy(((uint8_t *) header) + length, proto->addr->value, proto->addr->length);
    588         length += proto->addr->length;
    589         bzero(((uint8_t *) header) + length, device->addr->length);
    590         length += device->addr->length;
    591         memcpy(((uint8_t *) header) + length, target->value, target->length);
    592         if(packet_set_addr(packet, (uint8_t *) device->addr->value, (uint8_t *) device->broadcast_addr->value, CONVERT_SIZE(char, uint8_t, device->addr->length)) != EOK){
    593                 pq_release(arp_globals.net_phone, packet_get_id(packet));
    594                 return NULL;
    595         }
    596         nil_send_msg(device->phone, device_id, packet, SERVICE_ARP);
    597         return NULL;
    598 }
    599 
    600 int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
    601         measured_string_ref tmp;
    602 
    603         fibril_rwlock_read_lock(&arp_globals.lock);
    604         tmp = arp_translate_message(device_id, protocol, address);
    605         if(tmp){
    606                 *translation = measured_string_copy(tmp);
    607                 fibril_rwlock_read_unlock(&arp_globals.lock);
    608                 if(*translation){
    609                         *data = (** translation).value;
    610                         return EOK;
    611                 }else{
    612                         return ENOMEM;
    613                 }
    614         }else{
    615                 fibril_rwlock_read_unlock(&arp_globals.lock);
    616                 return ENOENT;
    617         }
    618 }
    619 
    620620/** @}
    621621 */
  • uspace/srv/net/il/arp/arp.h

    r60ab6c3 r71b00dcc  
    5151
    5252
     53/** Type definition of the ARP global data.
     54 *  @see arp_globals
     55 */
     56typedef struct arp_globals      arp_globals_t;
     57
    5358/** Type definition of the ARP device specific data.
    5459 *  @see arp_device
     
    6166typedef arp_device_t *          arp_device_ref;
    6267
    63 /** Type definition of the ARP global data.
    64  *  @see arp_globals
    65  */
    66 typedef struct arp_globals      arp_globals_t;
    67 
    6868/** Type definition of the ARP protocol specific data.
    6969 *  @see arp_proto
     
    7575 */
    7676typedef arp_proto_t *           arp_proto_ref;
    77 
    78 /** ARP address map.
    79  *  Translates addresses.
    80  *  @see generic_char_map.h
    81  */
    82 GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t)
    8377
    8478/** ARP address cache.
     
    9488INT_MAP_DECLARE(arp_protos, arp_proto_t)
    9589
     90/** ARP address map.
     91 *  Translates addresses.
     92 *  @see generic_char_map.h
     93 */
     94GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t)
     95
    9696/** ARP device specific data.
    9797 */
    9898struct arp_device{
     99        /** Device identifier.
     100         */
     101        device_id_t device_id;
     102        /** Hardware type.
     103         */
     104        hw_type_t hardware;
     105        /** Packet dimension.
     106         */
     107        packet_dimension_t packet_dimension;
    99108        /** Actual device hardware address.
    100109         */
     
    109118         */
    110119        char * broadcast_data;
    111         /** Device identifier.
     120        /** Device module service.
    112121         */
    113         device_id_t device_id;
    114         /** Hardware type.
    115          */
    116         hw_type_t hardware;
    117         /** Packet dimension.
    118          */
    119         packet_dimension_t packet_dimension;
     122        services_t service;
    120123        /** Device module phone.
    121124         */
     
    125128         */
    126129        arp_protos_t protos;
    127         /** Device module service.
    128          */
    129         services_t service;
    130 };
    131 
    132 /** ARP global data.
    133  */
    134 struct  arp_globals{
    135         /** ARP address cache.
    136          */
    137         arp_cache_t cache;
    138         /** The client connection processing function.
    139          *  The module skeleton propagates its own one.
    140          */
    141         async_client_conn_t client_connection;
    142         /** Networking module phone.
    143          */
    144         int net_phone;
    145         /** Safety lock.
    146          */
    147         fibril_rwlock_t lock;
    148130};
    149131
     
    151133 */
    152134struct arp_proto{
     135        /** Protocol service.
     136         */
     137        services_t service;
    153138        /** Actual device protocol address.
    154139         */
     
    160145         */
    161146        arp_addr_t addresses;
    162         /** Protocol service.
     147};
     148
     149/** ARP global data.
     150 */
     151struct  arp_globals{
     152        /** Networking module phone.
    163153         */
    164         services_t service;
     154        int net_phone;
     155        /** Safety lock.
     156         */
     157        fibril_rwlock_t lock;
     158        /** ARP address cache.
     159         */
     160        arp_cache_t cache;
     161        /** The client connection processing function.
     162         *  The module skeleton propagates its own one.
     163         */
     164        async_client_conn_t client_connection;
    165165};
    166166
  • uspace/srv/net/il/arp/arp_messages.h

    r60ab6c3 r71b00dcc  
    4646 */
    4747typedef enum{
    48         /** Clean cache message.
    49          *  @see arp_clean_cache()
     48        /** New device message.
     49         *  @see arp_device_req()
    5050         */
    51         NET_ARP_CLEAN_CACHE = NET_ARP_FIRST,
     51        NET_ARP_DEVICE = NET_ARP_FIRST,
     52        /** Address translation message.
     53         *  @see arp_translate_req()
     54         */
     55        NET_ARP_TRANSLATE,
     56        /** Clear device cache message.
     57         *  @see arp_clear_device_req()
     58         */
     59        NET_ARP_CLEAR_DEVICE,
    5260        /** Clear address cache message.
    5361         *  @see arp_clear_address_msg()
    5462         */
    5563        NET_ARP_CLEAR_ADDRESS,
    56         /** Clear device cache message.
    57          *  @see arp_clear_device_req()
     64        /** Clean cache message.
     65         *  @see arp_clean_cache()
    5866         */
    59         NET_ARP_CLEAR_DEVICE,
    60         /** New device message.
    61          *  @see arp_device_req()
    62          */
    63         NET_ARP_DEVICE,
    64         /** Address translation message.
    65          *  @see arp_translate_req()
    66          */
    67         NET_ARP_TRANSLATE
     67        NET_ARP_CLEAN_CACHE,
    6868} arp_messages;
    6969
  • uspace/srv/net/il/arp/arp_module.c

    r60ab6c3 r71b00dcc  
    5858#define NAME    "ARP protocol"
    5959
    60 /** ARP module global data.
    61  */
    62 extern arp_globals_t    arp_globals;
    63 
    64 /** Processes the ARP message.
    65  *  @param[in] callid The message identifier.
    66  *  @param[in] call The message parameters.
    67  *  @param[out] answer The message answer parameters.
    68  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    69  *  @returns EOK on success.
    70  *  @returns Other error codes as defined for the arp_message() function.
    71  */
    72 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
    73 
    7460/** Prints the module name.
    7561 *  @see NAME
     
    8672int module_start(async_client_conn_t client_connection);
    8773
    88 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    89         return arp_message(callid, call, answer, answer_count);
    90 }
     74/** Processes the ARP message.
     75 *  @param[in] callid The message identifier.
     76 *  @param[in] call The message parameters.
     77 *  @param[out] answer The message answer parameters.
     78 *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
     79 *  @returns EOK on success.
     80 *  @returns Other error codes as defined for the arp_message() function.
     81 */
     82int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
     83
     84/** ARP module global data.
     85 */
     86extern arp_globals_t    arp_globals;
    9187
    9288void module_print_name(void){
     
    114110}
    115111
     112int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     113        return arp_message(callid, call, answer, answer_count);
     114}
     115
    116116/** @}
    117117 */
  • uspace/srv/net/il/arp/arp_oc.h

    r60ab6c3 r71b00dcc  
    4444/** REQUEST operation code.
    4545 */
    46 #define ARPOP_REQUEST                                   1
     46#define ARPOP_REQUEST           1
    4747
    4848/** REPLY operation code.
    4949 */
    50 #define ARPOP_REPLY                                             2
     50#define ARPOP_REPLY             2
    5151
    5252/** Reverse request operation code.
    5353 */
    54 #define ARPOP_RREQUEST                                  3
     54#define ARPOP_RREQUEST          3
    5555
    5656/** Reverse reply operation code.
    5757 */
    58 #define ARPOP_RREPLY                                    4
     58#define ARPOP_RREPLY            4
    5959
    6060/** DRARP-Request operation code.
    6161 */
    62 #define ARPOP_DRARP_Request                             5
     62#define ARPOP_DRARP_Request             5
    6363
    6464/** DRARP-Reply operation code.
    6565 */
    66 #define ARPOP_DRARP_Reply                               6
     66#define ARPOP_DRARP_Reply               6
    6767
    6868/** DRARP-Error operation code.
    6969 */
    70 #define ARPOP_DRARP_Error                               7
     70#define ARPOP_DRARP_Error               7
    7171
    7272/** InARP-Request operation code.
    7373 */
    74 #define ARPOP_InREQUEST                                 8
     74#define ARPOP_InREQUEST         8
    7575
    7676/** InARP-Reply operation code.
    7777 */
    78 #define ARPOP_InREPLY                                   9
     78#define ARPOP_InREPLY           9
    7979
    8080/** ARP-NAK operation code.
    8181 */
    82 #define ARPOP_NAK                                               10
     82#define ARPOP_NAK               10
    8383
    8484/** MARS-Request operation code.
    8585 */
    86 #define ARPOP_MARS_Request                              11
     86#define ARPOP_MARS_Request              11
    8787
    8888/** MARS-Multi operation code.
    8989 */
    90 #define ARPOP_MARS_Multi                                12
     90#define ARPOP_MARS_Multi                12
    9191
    9292/** MARS-MServ operation code.
    9393 */
    94 #define ARPOP_MARS_MServ                                13
     94#define ARPOP_MARS_MServ                13
    9595
    9696/** MARS-Join operation code.
    9797 */
    98 #define ARPOP_MARS_Join                                 14
     98#define ARPOP_MARS_Join         14
    9999
    100100/** MARS-Leave operation code.
    101101 */
    102 #define ARPOP_MARS_Leave                                15
     102#define ARPOP_MARS_Leave                15
    103103
    104104/** MARS-NAK operation code.
    105105 */
    106 #define ARPOP_MARS_NAK                                  16
     106#define ARPOP_MARS_NAK          16
    107107
    108108/** MARS-Unserv operation code.
    109109 */
    110 #define ARPOP_MARS_Unserv                               17
     110#define ARPOP_MARS_Unserv               17
    111111
    112112/** MARS-SJoin operation code.
    113113 */
    114 #define ARPOP_MARS_SJoin                                18
     114#define ARPOP_MARS_SJoin                18
    115115
    116116/** MARS-SLeave operation code.
    117117 */
    118 #define ARPOP_MARS_SLeave                               19
     118#define ARPOP_MARS_SLeave               19
    119119
    120120/** MARS-Grouplist-Request operation code.
    121121 */
    122 #define ARPOP_MARS_Grouplist_Request    20
     122#define ARPOP_MARS_Grouplist_Request            20
    123123
    124124/** MARS-Grouplist-Reply operation code.
     
    128128/** MARS-Redirect-Map operation code.
    129129 */
    130 #define ARPOP_MARS_Redirect_Map                 22
     130#define ARPOP_MARS_Redirect_Map         22
    131131
    132132/** MAPOS-UNARP operation code.
    133133 */
    134 #define ARPOP_MAPOS_UNARP                               23
     134#define ARPOP_MAPOS_UNARP               23
    135135
    136136/*@}*/
  • uspace/srv/net/il/arp/arp_remote.c

    r60ab6c3 r71b00dcc  
    5252#include "arp_messages.h"
    5353
    54 int arp_connect_module(services_t service){
    55         if(service != SERVICE_ARP){
    56                 return EINVAL;
    57         }
    58         return connect_to_service(SERVICE_ARP);
     54int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
     55        aid_t message_id;
     56        ipcarg_t result;
     57
     58        message_id = async_send_3(arp_phone, NET_ARP_DEVICE, (ipcarg_t) device_id, protocol, netif, NULL);
     59        measured_strings_send(arp_phone, address, 1);
     60        async_wait_for(message_id, &result);
     61        return (int) result;
    5962}
    6063
    61 int arp_clean_cache_req(int arp_phone){
    62         return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE);
     64int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
     65        return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data);
     66}
     67
     68int arp_clear_device_req(int arp_phone, device_id_t device_id){
     69        return (int) async_req_1_0(arp_phone, NET_ARP_CLEAR_DEVICE, (ipcarg_t) device_id);
    6370}
    6471
     
    7380}
    7481
    75 int arp_clear_device_req(int arp_phone, device_id_t device_id){
    76         return (int) async_req_1_0(arp_phone, NET_ARP_CLEAR_DEVICE, (ipcarg_t) device_id);
     82int arp_clean_cache_req(int arp_phone){
     83        return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE);
    7784}
    7885
    79 int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
    80         aid_t message_id;
    81         ipcarg_t result;
    82 
    83         message_id = async_send_3(arp_phone, NET_ARP_DEVICE, (ipcarg_t) device_id, protocol, netif, NULL);
    84         measured_strings_send(arp_phone, address, 1);
    85         async_wait_for(message_id, &result);
    86         return (int) result;
     86int arp_connect_module(services_t service){
     87        if(service != SERVICE_ARP){
     88                return EINVAL;
     89        }
     90        return connect_to_service(SERVICE_ARP);
    8791}
    8892
     
    9195}
    9296
    93 int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
    94         return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data);
    95 }
    96 
    9797/** @}
    9898 */
  • uspace/srv/net/il/il_messages.h

    r60ab6c3 r71b00dcc  
    5353         */
    5454        NET_IL_DEVICE_STATE,
    55         /** Device MTU changed message.
    56          *  @see il_mtu_changed_msg()
    57          */
    58         NET_IL_MTU_CHANGED,
    59         /** Packet size message.
    60          *  @see il_packet_size_req()
    61          */
    62         NET_IL_PACKET_SPACE,
    6355        /** Packet received message.
    6456         *  @see il_received_msg()
     
    6860         *  @see il_send_msg()
    6961         */
    70         NET_IL_SEND
     62        NET_IL_SEND,
     63        /** Packet size message.
     64         *  @see il_packet_size_req()
     65         */
     66        NET_IL_PACKET_SPACE,
     67        /** Device MTU changed message.
     68         *  @see il_mtu_changed_msg()
     69         */
     70        NET_IL_MTU_CHANGED
    7171} il_messages;
    7272
     
    8383 *  @param[in] call The message call structure.
    8484 */
    85 #define IL_GET_SERVICE(call)    (services_t) IPC_GET_ARG2(*call)
     85#define IL_GET_SERVICE(call)            (services_t) IPC_GET_ARG2(*call)
    8686
    8787/*@}*/
  • uspace/srv/net/il/ip/ip.h

    r60ab6c3 r71b00dcc  
    106106 */
    107107struct  ip_netif{
     108        /** Device identifier.
     109         */
     110        device_id_t device_id;
     111        /** Netif module service.
     112         */
     113        services_t service;
     114        /** Netif module phone.
     115         */
     116        int phone;
    108117        /** ARP module.
    109118         *  Assigned if using ARP.
    110119         */
    111120        module_ref arp;
     121        /** IP version.
     122         */
     123        int ipv;
     124        /** Indicates whether using DHCP.
     125         */
     126        int dhcp;
     127        /** Indicates whether IP routing is enabled.
     128         */
     129        int routing;
     130        /** Device state.
     131         */
     132        device_state_t state;
    112133        /** Broadcast address.
    113134         */
    114135        in_addr_t broadcast;
    115         /** Device identifier.
    116          */
    117         device_id_t device_id;
    118         /** Indicates whether using DHCP.
    119          */
    120         int dhcp;
    121         /** IP version.
    122          */
    123         int ipv;
     136        /** Routing table.
     137         */
     138        ip_routes_t routes;
    124139        /** Packet dimension.
    125140         */
    126141        packet_dimension_t packet_dimension;
    127         /** Netif module phone.
     142};
     143
     144/** IP protocol specific data.
     145 */
     146struct ip_proto{
     147        /** Protocol number.
     148         */
     149        int protocol;
     150        /** Protocol module service.
     151         */
     152        services_t service;
     153        /** Protocol module phone.
    128154         */
    129155        int phone;
    130         /** Routing table.
    131          */
    132         ip_routes_t routes;
    133         /** Indicates whether IP routing is enabled.
    134          */
    135         int routing;
    136         /** Netif module service.
    137          */
    138         services_t service;
    139         /** Device state.
    140          */
    141         device_state_t state;
    142 };
    143 
    144 /** IP protocol specific data.
    145  */
    146 struct ip_proto{
    147         /** Protocol module phone.
    148          */
    149         int phone;
    150         /** Protocol number.
    151          */
    152         int protocol;
    153156        /** Protocol packet receiving function.
    154157         */
    155158        tl_received_msg_t received_msg;
    156         /** Protocol module service.
    157          */
    158         services_t service;
    159159};
    160160
     
    165165         */
    166166        in_addr_t address;
     167        /** Target network mask.
     168         */
     169        in_addr_t netmask;
    167170        /** Gateway.
    168171         */
     
    171174         */
    172175        ip_netif_ref netif;
    173         /** Target network mask.
    174          */
    175         in_addr_t netmask;
    176176};
    177177
     
    179179 */
    180180struct  ip_globals{
    181         /** Default client connection function for support modules.
    182          */
    183         async_client_conn_t client_connection;
    184         /** Default gateway.
    185          */
    186         ip_route_t gateway;
    187         /** Safety lock.
    188          */
    189         fibril_rwlock_t lock;
    190         /** Known support modules.
    191          */
    192         modules_t modules;
    193181        /** Networking module phone.
    194182         */
     
    200188         */
    201189        fibril_rwlock_t netifs_lock;
    202         /** Packet counter.
    203          */
    204         uint16_t packet_counter;
    205190        /** Registered protocols.
    206191         */
     
    209194         */
    210195        fibril_rwlock_t protos_lock;
     196        /** Default gateway.
     197         */
     198        ip_route_t gateway;
     199        /** Known support modules.
     200         */
     201        modules_t modules;
     202        /** Default client connection function for support modules.
     203         */
     204        async_client_conn_t client_connection;
     205        /** Packet counter.
     206         */
     207        uint16_t packet_counter;
     208        /** Safety lock.
     209         */
     210        fibril_rwlock_t lock;
    211211};
    212212
  • uspace/srv/net/il/ip/ip_client.c

    r60ab6c3 r71b00dcc  
    4848#include "ip_header.h"
    4949
     50int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){
     51        ip_header_ref header;
     52        uint8_t * data;
     53        size_t padding;
     54
     55        padding =  ipopt_length % 4;
     56        if(padding){
     57                padding = 4 - padding;
     58                ipopt_length += padding;
     59        }
     60        data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);
     61        if(! data){
     62                return ENOMEM;
     63        }
     64        while(padding --){
     65                data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;
     66        }
     67        header = (ip_header_ref) data;
     68        header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length);
     69        header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL;
     70        header->tos = tos;
     71        header->protocol = protocol;
     72        if(dont_fragment){
     73                header->flags = IPFLAG_DONT_FRAGMENT;
     74        }
     75        return EOK;
     76}
     77
     78int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){
     79        ip_header_ref header;
     80
     81        header = (ip_header_ref) packet_get_data(packet);
     82        if((! header)
     83                || (packet_get_data_length(packet) < sizeof(ip_header_t))){
     84                return ENOMEM;
     85        }
     86        if(protocol){
     87                *protocol = header->protocol;
     88        }
     89        if(ttl){
     90                *ttl = header->ttl;
     91        }
     92        if(tos){
     93                *tos = header->tos;
     94        }
     95        if(dont_fragment){
     96                *dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT;
     97        }
     98        if(ipopt_length){
     99                *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t);
     100                return sizeof(ip_header_t);
     101        }else{
     102                return IP_HEADER_LENGTH(header);
     103        }
     104}
     105
    50106size_t ip_client_header_length(packet_t packet){
    51107        ip_header_ref header;
     
    57113        }
    58114        return IP_HEADER_LENGTH(header);
     115}
     116
     117int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){
     118        ipv4_pseudo_header_ref header_in;
     119
     120        if(! header){
     121                return EBADMEM;
     122        }
     123        if(headerlen == sizeof(ipv4_pseudo_header_t)){
     124                header_in = (ipv4_pseudo_header_ref) header;
     125                header_in->data_length = htons(data_length);
     126                return EOK;
     127        }else{
     128                return EINVAL;
     129        }
    59130}
    60131
     
    69140                return EINVAL;
    70141        }
    71 
    72142        switch(src->sa_family){
    73143                case AF_INET:
     
    101171}
    102172
    103 int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){
    104         ip_header_ref header;
    105         uint8_t * data;
    106         size_t padding;
    107 
    108         // compute the padding if IP options are set
    109         // multiple of 4 bytes
    110         padding =  ipopt_length % 4;
    111         if(padding){
    112                 padding = 4 - padding;
    113                 ipopt_length += padding;
    114         }
    115 
    116         // prefix the header
    117         data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);
    118         if(! data){
    119                 return ENOMEM;
    120         }
    121 
    122         // add the padding
    123         while(padding --){
    124                 data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;
    125         }
    126 
    127         // set the header
    128         header = (ip_header_ref) data;
    129         header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length);
    130         header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL;
    131         header->tos = tos;
    132         header->protocol = protocol;
    133 
    134         if(dont_fragment){
    135                 header->flags = IPFLAG_DONT_FRAGMENT;
    136         }
    137         return EOK;
    138 }
    139 
    140 int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){
    141         ip_header_ref header;
    142 
    143         header = (ip_header_ref) packet_get_data(packet);
    144         if((! header)
    145                 || (packet_get_data_length(packet) < sizeof(ip_header_t))){
    146                 return ENOMEM;
    147         }
    148 
    149         if(protocol){
    150                 *protocol = header->protocol;
    151         }
    152         if(ttl){
    153                 *ttl = header->ttl;
    154         }
    155         if(tos){
    156                 *tos = header->tos;
    157         }
    158         if(dont_fragment){
    159                 *dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT;
    160         }
    161         if(ipopt_length){
    162                 *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t);
    163                 return sizeof(ip_header_t);
    164         }else{
    165                 return IP_HEADER_LENGTH(header);
    166         }
    167 }
    168 
    169 int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){
    170         ipv4_pseudo_header_ref header_in;
    171 
    172         if(! header){
    173                 return EBADMEM;
    174         }
    175 
    176         if(headerlen == sizeof(ipv4_pseudo_header_t)){
    177                 header_in = (ipv4_pseudo_header_ref) header;
    178                 header_in->data_length = htons(data_length);
    179                 return EOK;
    180         // TODO IPv6
    181         }else{
    182                 return EINVAL;
    183         }
    184 }
    185 
    186173/** @}
    187174 */
  • uspace/srv/net/il/ip/ip_header.h

    r60ab6c3 r71b00dcc  
    4242#include <sys/types.h>
    4343
     44/** Returns the actual IP header length in bytes.
     45 *  @param[in] header The IP packet header.
     46 */
     47#define IP_HEADER_LENGTH(header)                ((header)->header_length * 4u)
     48
     49/** Returns the IP header length.
     50 *  @param[in] length The IP header length in bytes.
     51 */
     52#define IP_COMPUTE_HEADER_LENGTH(length)                ((uint8_t) ((length) / 4u))
     53
     54/** Returns the actual IP packet total length.
     55 *  @param[in] header The IP packet header.
     56 */
     57#define IP_TOTAL_LENGTH(header)         ntohs((header)->total_length)
     58
     59/** Returns the actual IP packet data length.
     60 *  @param[in] header The IP packet header.
     61 */
     62#define IP_HEADER_DATA_LENGTH(header)   (IP_TOTAL_LENGTH(header) - IP_HEADER_LENGTH(header))
     63
     64/** Returns the IP packet header checksum.
     65 *  @param[in] header The IP packet header.
     66 */
     67#define IP_HEADER_CHECKSUM(header)      (htons(ip_checksum((uint8_t *)(header), IP_HEADER_LENGTH(header))))
     68
     69/** Returns the fragment offest.
     70 *  @param[in] header The IP packet header.
     71 */
     72#define IP_FRAGMENT_OFFSET(header) ((((header)->fragment_offset_high << 8) + (header)->fragment_offset_low) * 8u)
     73
    4474/** Returns the fragment offest high bits.
    4575 *  @param[in] length The prefixed data total length.
     
    5282#define IP_COMPUTE_FRAGMENT_OFFSET_LOW(length) (((length) / 8u) &0xFF)
    5383
    54 /** Returns the IP header length.
    55  *  @param[in] length The IP header length in bytes.
    56  */
    57 #define IP_COMPUTE_HEADER_LENGTH(length)                ((uint8_t) ((length) / 4u))
    58 
    59 /** Returns the fragment offest.
    60  *  @param[in] header The IP packet header.
    61  */
    62 #define IP_FRAGMENT_OFFSET(header) ((((header)->fragment_offset_high << 8) + (header)->fragment_offset_low) * 8u)
    63 
    64 /** Returns the IP packet header checksum.
    65  *  @param[in] header The IP packet header.
    66  */
    67 #define IP_HEADER_CHECKSUM(header)      (htons(ip_checksum((uint8_t *)(header), IP_HEADER_LENGTH(header))))
    68 
    69 /** Returns the actual IP packet data length.
    70  *  @param[in] header The IP packet header.
    71  */
    72 #define IP_HEADER_DATA_LENGTH(header)   (IP_TOTAL_LENGTH(header) - IP_HEADER_LENGTH(header))
    73 
    74 /** Returns the actual IP header length in bytes.
    75  *  @param[in] header The IP packet header.
    76  */
    77 #define IP_HEADER_LENGTH(header)                ((header)->header_length * 4u)
    78 
    79 /** Returns the actual IP packet total length.
    80  *  @param[in] header The IP packet header.
    81  */
    82 #define IP_TOTAL_LENGTH(header)         ntohs((header)->total_length)
    83 
    84 /** @name IP flags definitions
    85  */
    86 /*@{*/
    87 
    88 /** Fragment flag field shift.
    89  */
    90 #define IPFLAG_FRAGMENT_SHIFT           1
    91 
    92 /** Fragmented flag field shift.
    93  */
    94 #define IPFLAG_FRAGMENTED_SHIFT         0
    95 
    96 /** Don't fragment flag value.
    97  *  Permits the packet fragmentation.
    98  */
    99 #define IPFLAG_DONT_FRAGMENT            (0x1 << IPFLAG_FRAGMENT_SHIFT)
    100 
    101 /** Last fragment flag value.
    102  *  Indicates the last packet fragment.
    103  */
    104 #define IPFLAG_LAST_FRAGMENT            (0x0 << IPFLAG_FRAGMENTED_SHIFT)
    105 
    106 /** May fragment flag value.
    107  *  Allows the packet fragmentation.
    108  */
    109 #define IPFLAG_MAY_FRAGMENT                     (0x0 << IPFLAG_FRAGMENT_SHIFT)
    110 
    111 /** More fragments flag value.
    112  *  Indicates that more packet fragments follow.
    113  */
    114 #define IPFLAG_MORE_FRAGMENTS           (0x1 << IPFLAG_FRAGMENTED_SHIFT)
    115 
    116 /*@}*/
    117 
    11884/** Type definition of the internet header.
    11985 *  @see ip_header
     
    12591 */
    12692typedef ip_header_t *           ip_header_ref;
    127 
    128 /** Type definition of the internet option header.
    129  *  @see ip_header
    130  */
    131 typedef struct ip_option        ip_option_t;
    132 
    133 /** Type definition of the internet option header pointer.
    134  *  @see ip_header
    135  */
    136 typedef ip_option_t *           ip_option_ref;
    137 
    138 /** Type definition of the internet version 4 pseudo header.
    139  *  @see ipv4_pseudo_header
    140  */
    141 typedef struct ipv4_pseudo_header       ipv4_pseudo_header_t;
    142 
    143 /** Type definition of the internet version 4 pseudo header pointer.
    144  *  @see ipv4_pseudo_header
    145  */
    146 typedef ipv4_pseudo_header_t *          ipv4_pseudo_header_ref;
    14793
    14894/** Internet header.
     
    225171} __attribute__ ((packed));
    226172
     173/** Type definition of the internet option header.
     174 *  @see ip_header
     175 */
     176typedef struct ip_option        ip_option_t;
     177
     178/** Type definition of the internet option header pointer.
     179 *  @see ip_header
     180 */
     181typedef ip_option_t *           ip_option_ref;
     182
    227183/** Internet option header.
    228184 *  Only type field is always valid.
     
    256212} __attribute__ ((packed));
    257213
     214/** @name IP flags definitions
     215 */
     216/*@{*/
     217
     218/** Fragment flag field shift.
     219 */
     220#define IPFLAG_FRAGMENT_SHIFT           1
     221
     222/** Fragmented flag field shift.
     223 */
     224#define IPFLAG_FRAGMENTED_SHIFT         0
     225
     226/** May fragment flag value.
     227 *  Allows the packet fragmentation.
     228 */
     229#define IPFLAG_MAY_FRAGMENT                     (0x0 << IPFLAG_FRAGMENT_SHIFT)
     230
     231/** Don't fragment flag value.
     232 *  Permits the packet fragmentation.
     233 */
     234#define IPFLAG_DONT_FRAGMENT            (0x1 << IPFLAG_FRAGMENT_SHIFT)
     235
     236/** Last fragment flag value.
     237 *  Indicates the last packet fragment.
     238 */
     239#define IPFLAG_LAST_FRAGMENT            (0x0 << IPFLAG_FRAGMENTED_SHIFT)
     240
     241/** More fragments flag value.
     242 *  Indicates that more packet fragments follow.
     243 */
     244#define IPFLAG_MORE_FRAGMENTS           (0x1 << IPFLAG_FRAGMENTED_SHIFT)
     245
     246/*@}*/
     247
     248/** Type definition of the internet version 4 pseudo header.
     249 *  @see ipv4_pseudo_header
     250 */
     251typedef struct ipv4_pseudo_header       ipv4_pseudo_header_t;
     252
     253/** Type definition of the internet version 4 pseudo header pointer.
     254 *  @see ipv4_pseudo_header
     255 */
     256typedef ipv4_pseudo_header_t *          ipv4_pseudo_header_ref;
     257
    258258/** Internet version 4 pseudo header.
    259259 */
  • uspace/srv/net/il/ip/ip_messages.h

    r60ab6c3 r71b00dcc  
    5151         */
    5252        NET_IP_ADD_ROUTE = NET_IP_FIRST,
    53         /** Gets the actual route information.
    54          *  @see ip_get_route()
     53        /** Sets the default gateway.
     54         *  @see ip_set_default_gateway()
    5555         */
    56         NET_IP_GET_ROUTE,
     56        NET_IP_SET_GATEWAY,
    5757        /** Processes the received error notification.
    5858         *  @see ip_received_error_msg()
    5959         */
    6060        NET_IP_RECEIVED_ERROR,
    61         /** Sets the default gateway.
    62          *  @see ip_set_default_gateway()
     61        /** Gets the actual route information.
     62         *  @see ip_get_route()
    6363         */
    64         NET_IP_SET_GATEWAY
     64        NET_IP_GET_ROUTE
    6565} ip_messages;
    6666
     
    6969/*@{*/
    7070
    71 /** Returns the address message parameter.
    72  *  @param[in] call The message call structure.
    73  */
    74 #define IP_GET_ADDRESS(call)            ({in_addr_t addr; addr.s_addr = IPC_GET_ARG3(*call); addr;})
    75 
    7671/** Returns the gateway message parameter.
    7772 *  @param[in] call The message call structure.
     
    7974#define IP_GET_GATEWAY(call)            ({in_addr_t addr; addr.s_addr = IPC_GET_ARG2(*call); addr;})
    8075
    81 /** Sets the header length in the message answer.
    82  *  @param[out] answer The message answer structure.
     76/** Returns the address message parameter.
     77 *  @param[in] call The message call structure.
    8378 */
    84 #define IP_SET_HEADERLEN(answer)        ((size_t *) &IPC_GET_ARG2(*answer))
     79#define IP_GET_ADDRESS(call)            ({in_addr_t addr; addr.s_addr = IPC_GET_ARG3(*call); addr;})
    8580
    8681/** Returns the network mask message parameter.
     
    9489#define IP_GET_PROTOCOL(call)           ((ip_protocol_t) IPC_GET_ARG1(*call))
    9590
     91/** Sets the header length in the message answer.
     92 *  @param[out] answer The message answer structure.
     93 */
     94#define IP_SET_HEADERLEN(answer)        ((size_t *) &IPC_GET_ARG2(*answer))
     95
    9696/*@}*/
    9797
  • uspace/srv/net/il/ip/ip_module.c

    r60ab6c3 r71b00dcc  
    5858#define NAME    "IP protocol"
    5959
    60 /** IP module global data.
    61  */
    62 extern ip_globals_t     ip_globals;
    63 
    64 /** Processes the IP message.
    65  *  @param[in] callid The message identifier.
    66  *  @param[in] call The message parameters.
    67  *  @param[out] answer The message answer parameters.
    68  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    69  *  @returns EOK on success.
    70  *  @returns Other error codes as defined for the ip_message() function.
    71  */
    72 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
    73 
    7460/** Prints the module name.
    7561 *  @see NAME
     
    8672int module_start(async_client_conn_t client_connection);
    8773
    88 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    89         return ip_message(callid, call, answer, answer_count);
    90 }
     74/** Processes the IP message.
     75 *  @param[in] callid The message identifier.
     76 *  @param[in] call The message parameters.
     77 *  @param[out] answer The message answer parameters.
     78 *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
     79 *  @returns EOK on success.
     80 *  @returns Other error codes as defined for the ip_message() function.
     81 */
     82int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
     83
     84/** IP module global data.
     85 */
     86extern ip_globals_t     ip_globals;
    9187
    9288void module_print_name(void){
     
    114110}
    115111
     112int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     113        return ip_message(callid, call, answer, answer_count);
     114}
     115
    116116/** @}
    117117 */
  • uspace/srv/net/il/ip/ip_remote.c

    r60ab6c3 r71b00dcc  
    5252#include "ip_messages.h"
    5353
     54int ip_device_req(int ip_phone, device_id_t device_id, services_t service){
     55        return generic_device_req(ip_phone, NET_IL_DEVICE, device_id, 0, service);
     56}
     57
     58int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
     59        return generic_send_msg(ip_phone, NET_IL_SEND, device_id, packet_get_id(packet), sender, error);
     60}
     61
     62int ip_connect_module(services_t service){
     63        return connect_to_service(SERVICE_IP);
     64}
     65
    5466int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){
    5567        return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr, (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr);
     68}
     69
     70int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){
     71        return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr);
     72}
     73
     74int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){
     75        return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, packet_dimension);
    5676}
    5777
     
    6080}
    6181
    62 int ip_connect_module(services_t service){
    63         return connect_to_service(SERVICE_IP);
    64 }
    65 
    66 int ip_device_req(int ip_phone, device_id_t device_id, services_t service){
    67         return generic_device_req(ip_phone, NET_IL_DEVICE, device_id, 0, service);
     82int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
     83        return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, packet_get_id(packet), target, error);
    6884}
    6985
     
    7995                return EBADMEM;
    8096        }
    81 
    8297        *header = NULL;
    8398        message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, (ipcarg_t) protocol, &answer);
     
    93108        }
    94109        async_wait_for(message_id, &result);
    95 
    96110        if((result != EOK) && (*header)){
    97111                free(*header);
     
    102116}
    103117
    104 int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){
    105         return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, packet_dimension);
    106 }
    107 
    108 int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
    109         return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, packet_get_id(packet), target, error);
    110 }
    111 
    112 int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
    113         return generic_send_msg(ip_phone, NET_IL_SEND, device_id, packet_get_id(packet), sender, error);
    114 }
    115 
    116 int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){
    117         return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr);
    118 }
    119 
    120118/** @}
    121119 */
  • uspace/srv/net/inet.c

    r60ab6c3 r71b00dcc  
    4545#include "include/socket_codes.h"
    4646
    47 int inet_ntop(uint16_t family, const uint8_t * data, char * address, size_t length){
    48         if((! data) || (! address)){
    49                 return EINVAL;
    50         }
    51 
    52         switch(family){
    53                 case AF_INET:
    54                         // check the output buffer size
    55                         if(length < INET_ADDRSTRLEN){
    56                                 return ENOMEM;
    57                         }
    58                         // fill the buffer with the IPv4 address
    59                         snprintf(address, length, "%hhu.%hhu.%hhu.%hhu", data[0], data[1], data[2], data[3]);
    60                         return EOK;
    61                 case AF_INET6:
    62                         // check the output buffer size
    63                         if(length < INET6_ADDRSTRLEN){
    64                                 return ENOMEM;
    65                         }
    66                         // fill the buffer with the IPv6 address
    67                         snprintf(address, length, "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15]);
    68                         return EOK;
    69                 default:
    70                         return ENOTSUP;
    71         }
    72 }
    73 
    7447int inet_pton(uint16_t family, const char * address, uint8_t * data){
    75         /** The base number of the values.
    76          */
    77         int base;
    78         /** The number of bytes per a section.
    79          */
    80         size_t bytes;
    81         /** The number of bytes of the address data.
    82          */
    83         int count;
    84 
    8548        const char * next;
    8649        char * last;
    8750        int index;
     51        int count;
     52        int base;
     53        size_t bytes;
    8854        size_t shift;
    8955        unsigned long value;
     
    9258                return EINVAL;
    9359        }
    94 
    95         // set the processing parameters
    9660        switch(family){
    9761                case AF_INET:
     
    10872                        return ENOTSUP;
    10973        }
    110 
    111         // erase if no address
    11274        if(! address){
    11375                bzero(data, count);
    11476                return ENOENT;
    11577        }
    116 
    117         // process the string from the beginning
    11878        next = address;
    11979        index = 0;
    12080        do{
    121                 // if the actual character is set
    12281                if(next && (*next)){
    123 
    124                         // if not on the first character
    12582                        if(index){
    126                                 // move to the next character
    12783                                ++ next;
    12884                        }
    129 
    130                         // parse the actual integral value
    13185                        value = strtoul(next, &last, base);
    132                         // remember the last problematic character
    133                         // should be either '.' or ':' but is ignored to be more generic
    13486                        next = last;
    135 
    136                         // fill the address data byte by byte
    13787                        shift = bytes - 1;
    13888                        do{
     
    14191                                value >>= 8;
    14292                        }while(shift --);
    143 
    14493                        index += bytes;
    14594                }else{
    146                         // erase the rest of the address
    14795                        bzero(data + index, count - index);
    14896                        return EOK;
    14997                }
    15098        }while(index < count);
     99        return EOK;
     100}
    151101
    152         return EOK;
     102int inet_ntop(uint16_t family, const uint8_t * data, char * address, size_t length){
     103        if((! data) || (! address)){
     104                return EINVAL;
     105        }
     106        switch(family){
     107                case AF_INET:
     108                        if(length < INET_ADDRSTRLEN){
     109                                return ENOMEM;
     110                        }
     111                        snprintf(address, length, "%hhu.%hhu.%hhu.%hhu", data[0], data[1], data[2], data[3]);
     112                        return EOK;
     113                case AF_INET6:
     114                        if(length < INET6_ADDRSTRLEN){
     115                                return ENOMEM;
     116                        }
     117                        snprintf(address, length, "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15]);
     118                        return EOK;
     119                default:
     120                        return ENOTSUP;
     121        }
    153122}
    154123
  • uspace/srv/net/messages.h

    r60ab6c3 r71b00dcc  
    4848#include "structures/packet/packet.h"
    4949
     50/** @name Networking message counts
     51 */
     52/*@{*/
     53
     54/** The number of network interface driver messages.
     55 */
     56#define NET_NETIF_COUNT         6
     57
     58/** The number of general networking messages.
     59 */
     60#define NET_NET_COUNT           3
     61
     62/** The number of network interface layer messages.
     63 */
     64#define NET_NIL_COUNT           7
     65
     66/** The number of Ethernet messages.
     67 */
     68#define NET_ETH_COUNT           0
     69
     70/** The number of inter-network messages.
     71 */
     72#define NET_IL_COUNT            6
     73
     74/** The number of IP messages.
     75 */
     76#define NET_IP_COUNT            4
     77
     78/** The number of ARP messages.
     79 */
     80#define NET_ARP_COUNT           5
     81
     82/** The number of ICMP messages.
     83 */
     84#define NET_ICMP_COUNT          6
     85
     86/** The number of transport layer messages.
     87 */
     88#define NET_TL_COUNT            1
     89
     90/** The number of UDP messages.
     91 */
     92#define NET_UDP_COUNT           0
     93
     94/** The number of TCP messages.
     95 */
     96#define NET_TCP_COUNT           0
     97
     98/** The number of packet management system messages.
     99 */
     100#define NET_PACKET_COUNT        5
     101
     102/** The number of socket messages.
     103 */
     104#define NET_SOCKET_COUNT        14
     105
     106/*@}*/
     107
     108/** @name Networking message intervals
     109 */
     110/*@{*/
     111
     112/** The first networking message.
     113 */
     114#define NET_FIRST                       2000
     115
     116/** The first network interface layer message.
     117 */
     118#define NET_NETIF_FIRST         NET_FIRST
     119
     120/** The last network interface layer message.
     121 */
     122#define NET_NETIF_LAST          (NET_NETIF_FIRST + NET_NETIF_COUNT)
     123
     124/** The first general networking message.
     125 */
     126#define NET_NET_FIRST           (NET_NETIF_LAST + 0)
     127
     128/** The last general networking message.
     129 */
     130#define NET_NET_LAST            (NET_NET_FIRST + NET_NET_COUNT)
     131
     132/** The first network interface layer message.
     133 */
     134#define NET_NIL_FIRST           (NET_NET_LAST + 0)
     135
     136/** The last network interface layer message.
     137 */
     138#define NET_NIL_LAST            (NET_NIL_FIRST + NET_NIL_COUNT)
     139
     140/** The first Ethernet message.
     141 */
     142#define NET_ETH_FIRST           (NET_NIL_LAST + 0)
     143
     144/** The last Ethernet message.
     145 */
     146#define NET_ETH_LAST            (NET_ETH_FIRST + NET_ETH_COUNT)
     147
     148/** The first inter-network message.
     149 */
     150#define NET_IL_FIRST            (NET_ETH_LAST + 0)
     151
     152/** The last inter-network message.
     153 */
     154#define NET_IL_LAST                     (NET_IL_FIRST + NET_IL_COUNT)
     155
     156/** The first IP message.
     157 */
     158#define NET_IP_FIRST            (NET_IL_LAST + 0)
     159
     160/** The last IP message.
     161 */
     162#define NET_IP_LAST                     (NET_IP_FIRST + NET_IP_COUNT)
     163
     164/** The first ARP message.
     165 */
     166#define NET_ARP_FIRST           (NET_IP_LAST + 0)
     167
     168/** The last ARP message.
     169 */
     170#define NET_ARP_LAST            (NET_ARP_FIRST + NET_ARP_COUNT)
     171
     172/** The first ICMP message.
     173 */
     174#define NET_ICMP_FIRST          (NET_ARP_LAST + 0)
     175
     176/** The last ICMP message.
     177 */
     178#define NET_ICMP_LAST           (NET_ICMP_FIRST + NET_ICMP_COUNT)
     179
     180/** The first ICMP message.
     181 */
     182#define NET_TL_FIRST            (NET_ICMP_LAST + 0)
     183
     184/** The last ICMP message.
     185 */
     186#define NET_TL_LAST                     (NET_TL_FIRST + NET_TL_COUNT)
     187
     188/** The first UDP message.
     189 */
     190#define NET_UDP_FIRST           (NET_TL_LAST + 0)
     191
     192/** The last UDP message.
     193 */
     194#define NET_UDP_LAST            (NET_UDP_FIRST + NET_UDP_COUNT)
     195
     196/** The first TCP message.
     197 */
     198#define NET_TCP_FIRST           (NET_UDP_LAST + 0)
     199
     200/** The last TCP message.
     201 */
     202#define NET_TCP_LAST            (NET_TCP_FIRST + NET_TCP_COUNT)
     203
     204/** The first socket message.
     205 */
     206#define NET_SOCKET_FIRST        (NET_TCP_LAST + 0)
     207
     208/** The last socket message.
     209 */
     210#define NET_SOCKET_LAST         (NET_SOCKET_FIRST + NET_SOCKET_COUNT)
     211
     212/** The first packet management system message.
     213 */
     214#define NET_PACKET_FIRST        (NET_SOCKET_LAST + 0)
     215
     216/** The last packet management system message.
     217 */
     218#define NET_PACKET_LAST         (NET_PACKET_FIRST + NET_PACKET_COUNT)
     219
     220/** The last networking message.
     221 */
     222#define NET_LAST                        NET_PACKET_LAST
     223
     224/** The number of networking messages.
     225 */
     226#define NET_COUNT                       (NET_LAST - NET_FIRST)
     227
    50228/** Returns a value indicating whether the value is in the interval.
    51229 *  @param[in] item The value to be checked.
     
    55233#define IS_IN_INTERVAL(item, first_inclusive, last_exclusive)   (((item) >= (first_inclusive)) && ((item) < (last_exclusive)))
    56234
    57 /** @name Networking message counts
     235/** Returns a value indicating whether the IPC call is a generic networking message.
     236 *  @param[in] call The IPC call to be checked.
     237 */
     238#define IS_NET_MESSAGE(call)                    IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_FIRST, NET_LAST)
     239
     240/** Returns a value indicating whether the IPC call is a generic networking message.
     241 *  @param[in] call The IPC call to be checked.
     242 */
     243#define IS_NET_NET_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_NET_FIRST, NET_NET_LAST)
     244
     245/** Returns a value indicating whether the IPC call is a network interface layer message.
     246 *  @param[in] call The IPC call to be checked.
     247 */
     248#define IS_NET_NIL_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_NIL_FIRST, NET_NIL_LAST)
     249
     250/** Returns a value indicating whether the IPC call is an Ethernet message.
     251 *  @param[in] call The IPC call to be checked.
     252 */
     253#define IS_NET_ETH_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ETH_FIRST, NET_ETH_LAST)
     254
     255/** Returns a value indicating whether the IPC call is an inter-network layer message.
     256 *  @param[in] call The IPC call to be checked.
     257 */
     258#define IS_NET_IL_MESSAGE(call)         IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_IL_FIRST, NET_IL_LAST)
     259
     260/** Returns a value indicating whether the IPC call is an IP message.
     261 *  @param[in] call The IPC call to be checked.
     262 */
     263#define IS_NET_IP_MESSAGE(call)         IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_IP_FIRST, NET_IP_LAST)
     264
     265/** Returns a value indicating whether the IPC call is an ARP message.
     266 *  @param[in] call The IPC call to be checked.
     267 */
     268#define IS_NET_ARP_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ARP_FIRST, NET_ARP_LAST)
     269
     270/** Returns a value indicating whether the IPC call is an ICMP message.
     271 *  @param[in] call The IPC call to be checked.
     272 */
     273#define IS_NET_ICMP_MESSAGE(call)               IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ICMP_FIRST, NET_ICMP_LAST)
     274
     275/** Returns a value indicating whether the IPC call is a transport layer message.
     276 *  @param[in] call The IPC call to be checked.
     277 */
     278#define IS_NET_TL_MESSAGE(call)         IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_TL_FIRST, NET_TL_LAST)
     279
     280/** Returns a value indicating whether the IPC call is a UDP message.
     281 *  @param[in] call The IPC call to be checked.
     282 */
     283#define IS_NET_UDP_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_UDP_FIRST, NET_UDP_LAST)
     284
     285/** Returns a value indicating whether the IPC call is a TCP message.
     286 *  @param[in] call The IPC call to be checked.
     287 */
     288#define IS_NET_TCP_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_TCP_FIRST, NET_TCP_LAST)
     289
     290/** Returns a value indicating whether the IPC call is a socket message.
     291 *  @param[in] call The IPC call to be checked.
     292 */
     293#define IS_NET_SOCKET_MESSAGE(call)     IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_SOCKET_FIRST, NET_SOCKET_LAST)
     294
     295/** Returns a value indicating whether the IPC call is a packet manaagement system message.
     296 *  @param[in] call The IPC call to be checked.
     297 */
     298#define IS_NET_PACKET_MESSAGE(call)     IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_PACKET_FIRST, NET_PACKET_LAST)
     299
     300/*@}*/
     301
     302/** @name Networking specific message parameters definitions
    58303 */
    59304/*@{*/
    60305
    61 /** The number of ARP messages.
    62  */
    63 #define NET_ARP_COUNT           5
    64 
    65 /** The number of Ethernet messages.
    66  */
    67 #define NET_ETH_COUNT           0
    68 
    69 /** The number of ICMP messages.
    70  */
    71 #define NET_ICMP_COUNT          6
    72 
    73 /** The number of inter-network messages.
    74  */
    75 #define NET_IL_COUNT            6
    76 
    77 /** The number of IP messages.
    78  */
    79 #define NET_IP_COUNT            4
    80 
    81 /** The number of general networking messages.
    82  */
    83 #define NET_NET_COUNT           3
    84 
    85 /** The number of network interface driver messages.
    86  */
    87 #define NET_NETIF_COUNT         6
    88 
    89 /** The number of network interface layer messages.
    90  */
    91 #define NET_NIL_COUNT           7
    92 
    93 /** The number of packet management system messages.
    94  */
    95 #define NET_PACKET_COUNT        5
    96 
    97 /** The number of socket messages.
    98  */
    99 #define NET_SOCKET_COUNT        14
    100 
    101 /** The number of TCP messages.
    102  */
    103 #define NET_TCP_COUNT           0
    104 
    105 /** The number of transport layer messages.
    106  */
    107 #define NET_TL_COUNT            1
    108 
    109 /** The number of UDP messages.
    110  */
    111 #define NET_UDP_COUNT           0
    112 
    113 /*@}*/
    114 
    115 /** @name Networking message intervals
    116  */
    117 /*@{*/
    118 
    119 /** The first networking message.
    120  */
    121 #define NET_FIRST                       2000
    122 
    123 /** The first network interface layer message.
    124  */
    125 #define NET_NETIF_FIRST         NET_FIRST
    126 
    127 /** The last network interface layer message.
    128  */
    129 #define NET_NETIF_LAST          (NET_NETIF_FIRST + NET_NETIF_COUNT)
    130 
    131 /** The first general networking message.
    132  */
    133 #define NET_NET_FIRST           (NET_NETIF_LAST + 0)
    134 
    135 /** The last general networking message.
    136  */
    137 #define NET_NET_LAST            (NET_NET_FIRST + NET_NET_COUNT)
    138 
    139 /** The first network interface layer message.
    140  */
    141 #define NET_NIL_FIRST           (NET_NET_LAST + 0)
    142 
    143 /** The last network interface layer message.
    144  */
    145 #define NET_NIL_LAST            (NET_NIL_FIRST + NET_NIL_COUNT)
    146 
    147 /** The first Ethernet message.
    148  */
    149 #define NET_ETH_FIRST           (NET_NIL_LAST + 0)
    150 
    151 /** The last Ethernet message.
    152  */
    153 #define NET_ETH_LAST            (NET_ETH_FIRST + NET_ETH_COUNT)
    154 
    155 /** The first inter-network message.
    156  */
    157 #define NET_IL_FIRST            (NET_ETH_LAST + 0)
    158 
    159 /** The last inter-network message.
    160  */
    161 #define NET_IL_LAST                     (NET_IL_FIRST + NET_IL_COUNT)
    162 
    163 /** The first IP message.
    164  */
    165 #define NET_IP_FIRST            (NET_IL_LAST + 0)
    166 
    167 /** The last IP message.
    168  */
    169 #define NET_IP_LAST                     (NET_IP_FIRST + NET_IP_COUNT)
    170 
    171 /** The first ARP message.
    172  */
    173 #define NET_ARP_FIRST           (NET_IP_LAST + 0)
    174 
    175 /** The last ARP message.
    176  */
    177 #define NET_ARP_LAST            (NET_ARP_FIRST + NET_ARP_COUNT)
    178 
    179 /** The first ICMP message.
    180  */
    181 #define NET_ICMP_FIRST          (NET_ARP_LAST + 0)
    182 
    183 /** The last ICMP message.
    184  */
    185 #define NET_ICMP_LAST           (NET_ICMP_FIRST + NET_ICMP_COUNT)
    186 
    187 /** The first ICMP message.
    188  */
    189 #define NET_TL_FIRST            (NET_ICMP_LAST + 0)
    190 
    191 /** The last ICMP message.
    192  */
    193 #define NET_TL_LAST                     (NET_TL_FIRST + NET_TL_COUNT)
    194 
    195 /** The first UDP message.
    196  */
    197 #define NET_UDP_FIRST           (NET_TL_LAST + 0)
    198 
    199 /** The last UDP message.
    200  */
    201 #define NET_UDP_LAST            (NET_UDP_FIRST + NET_UDP_COUNT)
    202 
    203 /** The first TCP message.
    204  */
    205 #define NET_TCP_FIRST           (NET_UDP_LAST + 0)
    206 
    207 /** The last TCP message.
    208  */
    209 #define NET_TCP_LAST            (NET_TCP_FIRST + NET_TCP_COUNT)
    210 
    211 /** The first socket message.
    212  */
    213 #define NET_SOCKET_FIRST        (NET_TCP_LAST + 0)
    214 
    215 /** The last socket message.
    216  */
    217 #define NET_SOCKET_LAST         (NET_SOCKET_FIRST + NET_SOCKET_COUNT)
    218 
    219 /** The first packet management system message.
    220  */
    221 #define NET_PACKET_FIRST        (NET_SOCKET_LAST + 0)
    222 
    223 /** The last packet management system message.
    224  */
    225 #define NET_PACKET_LAST         (NET_PACKET_FIRST + NET_PACKET_COUNT)
    226 
    227 /** The last networking message.
    228  */
    229 #define NET_LAST                        NET_PACKET_LAST
    230 
    231 /** The number of networking messages.
    232  */
    233 #define NET_COUNT                       (NET_LAST - NET_FIRST)
    234 
    235 /** Returns a value indicating whether the IPC call is a generic networking message.
    236  *  @param[in] call The IPC call to be checked.
    237  */
    238 #define IS_NET_MESSAGE(call)                    IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_FIRST, NET_LAST)
    239 
    240 /** Returns a value indicating whether the IPC call is an ARP message.
    241  *  @param[in] call The IPC call to be checked.
    242  */
    243 #define IS_NET_ARP_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ARP_FIRST, NET_ARP_LAST)
    244 
    245 /** Returns a value indicating whether the IPC call is an Ethernet message.
    246  *  @param[in] call The IPC call to be checked.
    247  */
    248 #define IS_NET_ETH_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ETH_FIRST, NET_ETH_LAST)
    249 
    250 /** Returns a value indicating whether the IPC call is an ICMP message.
    251  *  @param[in] call The IPC call to be checked.
    252  */
    253 #define IS_NET_ICMP_MESSAGE(call)               IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ICMP_FIRST, NET_ICMP_LAST)
    254 
    255 /** Returns a value indicating whether the IPC call is an inter-network layer message.
    256  *  @param[in] call The IPC call to be checked.
    257  */
    258 #define IS_NET_IL_MESSAGE(call)         IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_IL_FIRST, NET_IL_LAST)
    259 
    260 /** Returns a value indicating whether the IPC call is an IP message.
    261  *  @param[in] call The IPC call to be checked.
    262  */
    263 #define IS_NET_IP_MESSAGE(call)         IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_IP_FIRST, NET_IP_LAST)
    264 
    265 /** Returns a value indicating whether the IPC call is a generic networking message.
    266  *  @param[in] call The IPC call to be checked.
    267  */
    268 #define IS_NET_NET_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_NET_FIRST, NET_NET_LAST)
    269 
    270 /** Returns a value indicating whether the IPC call is a network interface layer message.
    271  *  @param[in] call The IPC call to be checked.
    272  */
    273 #define IS_NET_NIL_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_NIL_FIRST, NET_NIL_LAST)
    274 
    275 /** Returns a value indicating whether the IPC call is a packet manaagement system message.
    276  *  @param[in] call The IPC call to be checked.
    277  */
    278 #define IS_NET_PACKET_MESSAGE(call)     IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_PACKET_FIRST, NET_PACKET_LAST)
    279 
    280 /** Returns a value indicating whether the IPC call is a socket message.
    281  *  @param[in] call The IPC call to be checked.
    282  */
    283 #define IS_NET_SOCKET_MESSAGE(call)     IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_SOCKET_FIRST, NET_SOCKET_LAST)
    284 
    285 /** Returns a value indicating whether the IPC call is a TCP message.
    286  *  @param[in] call The IPC call to be checked.
    287  */
    288 #define IS_NET_TCP_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_TCP_FIRST, NET_TCP_LAST)
    289 
    290 /** Returns a value indicating whether the IPC call is a transport layer message.
    291  *  @param[in] call The IPC call to be checked.
    292  */
    293 #define IS_NET_TL_MESSAGE(call)         IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_TL_FIRST, NET_TL_LAST)
    294 
    295 /** Returns a value indicating whether the IPC call is a UDP message.
    296  *  @param[in] call The IPC call to be checked.
    297  */
    298 #define IS_NET_UDP_MESSAGE(call)                IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_UDP_FIRST, NET_UDP_LAST)
    299 
    300 /*@}*/
    301 
    302 /** @name Networking specific message arguments definitions
    303  */
    304 /*@{*/
    305 
    306 /** @name First arguments
    307  */
    308 /*@{*/
    309 
    310 /** Returns the device identifier message argument.
     306/** Returns the device identifier message parameter.
    311307 *  @param[in] call The message call structure.
    312308 */
    313309#define IPC_GET_DEVICE(call)            (device_id_t) IPC_GET_ARG1(*call)
    314310
    315 /*@}*/
    316 
    317 /** @name Second arguments
    318  */
    319 /*@{*/
    320 
    321 /** Returns the packet identifier message argument.
     311/** Returns the packet identifier message parameter.
    322312 *  @param[in] call The message call structure.
    323313 */
    324314#define IPC_GET_PACKET(call)            (packet_id_t) IPC_GET_ARG2(*call)
    325315
    326 /** Returns the count message argument.
     316/** Returns the count message parameter.
    327317 *  @param[in] call The message call structure.
    328318 */
    329319#define IPC_GET_COUNT(call)             (size_t) IPC_GET_ARG2(*call)
    330320
    331 /** Returns the device state message argument.
     321/** Returns the device state message parameter.
    332322 *  @param[in] call The message call structure.
    333323 */
    334324#define IPC_GET_STATE(call)             (device_state_t) IPC_GET_ARG2(*call)
    335325
    336 /** Returns the maximum transmission unit message argument.
     326/** Returns the maximum transmission unit message parameter.
    337327 *  @param[in] call The message call structure.
    338328 */
    339329#define IPC_GET_MTU(call)                       (size_t) IPC_GET_ARG2(*call)
    340330
    341 /*@}*/
    342 
    343 /** @name Third arguments
    344  */
    345 /*@{*/
    346 
    347 /** Returns the device driver service message argument.
     331/** Returns the device driver service message parameter.
    348332 *  @param[in] call The message call structure.
    349333 */
    350334#define IPC_GET_SERVICE(call)           (services_t) IPC_GET_ARG3(*call)
    351335
    352 /** Returns the target service message argument.
     336/** Returns the target service message parameter.
    353337 *  @param[in] call The message call structure.
    354338 */
    355339#define IPC_GET_TARGET(call)            (services_t) IPC_GET_ARG3(*call)
    356340
    357 /** Returns the sender service message argument.
     341/** Returns the sender service message parameter.
    358342 *  @param[in] call The message call structure.
    359343 */
    360344#define IPC_GET_SENDER(call)            (services_t) IPC_GET_ARG3(*call)
    361345
    362 /*@}*/
    363 
    364 /** @name Fourth arguments
    365  */
    366 /*@{*/
    367 
    368 /** Returns the error service message argument.
     346/** Returns the error service message parameter.
    369347 *  @param[in] call The message call structure.
    370348 */
    371349#define IPC_GET_ERROR(call)             (services_t) IPC_GET_ARG4(*call)
    372350
    373 /*@}*/
    374 
    375 /** @name Fifth arguments
    376  */
    377 /*@{*/
    378 
    379 /** Returns the phone message argument.
     351/** Returns the phone message parameter.
    380352 *  @param[in] call The message call structure.
    381353 */
    382354#define IPC_GET_PHONE(call)             (int) IPC_GET_ARG5(*call)
    383 
    384 /*@}*/
    385 
    386 /** @name First answers
    387  */
    388 /*@{*/
    389355
    390356/** Sets the device identifier in the message answer.
     
    398364#define IPC_SET_ADDR(answer)            ((size_t *) &IPC_GET_ARG1(*answer))
    399365
    400 /*@}*/
    401 
    402 /** @name Second answers
    403  */
    404 /*@{*/
    405 
    406366/** Sets the minimum prefix size in the message answer.
    407367 *  @param[out] answer The message answer structure.
     
    409369#define IPC_SET_PREFIX(answer)  ((size_t *) &IPC_GET_ARG2(*answer))
    410370
    411 /*@}*/
    412 
    413 /** @name Third answers
    414  */
    415 /*@{*/
    416 
    417371/** Sets the maximum content size in the message answer.
    418372 *  @param[out] answer The message answer structure.
     
    420374#define IPC_SET_CONTENT(answer) ((size_t *) &IPC_GET_ARG3(*answer))
    421375
    422 /*@}*/
    423 
    424 /** @name Fourth answers
    425  */
    426 /*@{*/
    427 
    428376/** Sets the minimum suffix size in the message answer.
    429377 *  @param[out] answer The message answer structure.
     
    432380
    433381/*@}*/
    434 
    435 /*@}*/
    436 
    437 /** Notifies the module about the device state change.
    438  *  @param[in] phone The service module phone.
    439  *  @param[in] message The service specific message.
    440  *  @param[in] device_id The device identifier.
    441  *  @param[in] state The new device state.
    442  *  @param[in] target The target module service.
    443  *  @returns EOK on success.
    444  */
    445 static inline int generic_device_state_msg(int phone, int message, device_id_t device_id, int state, services_t target){
    446         async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) state, target);
    447         return EOK;
    448 }
    449 
    450 /** Notifies a module about the device.
    451  *  @param[in] phone The service module phone.
    452  *  @param[in] message The service specific message.
    453  *  @param[in] device_id The device identifier.
    454  *  @param[in] arg2 The second argument of the message.
    455  *  @param[in] service The device module service.
    456  *  @returns EOK on success.
    457  *  @returns Other error codes as defined for the specific service message.
    458  */
    459 static inline int generic_device_req(int phone, int message, device_id_t device_id, int arg2, services_t service){
    460         return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) arg2, (ipcarg_t) service);
    461 }
    462382
    463383/** Returns the address.
     
    479399                return EBADMEM;
    480400        }
    481 
    482         // request the address
    483401        message_id = async_send_1(phone, (ipcarg_t) message, (ipcarg_t) device_id, NULL);
    484402        string = measured_strings_return(phone, address, data, 1);
    485403        async_wait_for(message_id, &result);
    486 
    487         // if not successful
    488404        if((string == EOK) && (result != EOK)){
    489                 // clear the data
    490405                free(*address);
    491406                free(*data);
    492407        }
    493408        return (int) result;
     409}
     410
     411/** Translates the given strings.
     412 *  Allocates and returns the needed memory block as the data parameter.
     413 *  @param[in] phone The service module phone.
     414 *  @param[in] message The service specific message.
     415 *  @param[in] device_id The device identifier.
     416 *  @param[in] service The module service.
     417 *  @param[in] configuration The key strings.
     418 *  @param[in] count The number of configuration keys.
     419 *  @param[out] translation The translated values.
     420 *  @param[out] data The translation data container.
     421 *  @returns EOK on success.
     422 *  @returns EINVAL if the configuration parameter is NULL.
     423 *  @returns EINVAL if the count parameter is zero (0).
     424 *  @returns EBADMEM if the translation or the data parameters are NULL.
     425 *  @returns Other error codes as defined for the specific service message.
     426 */
     427static inline int generic_translate_req(int phone, int message, device_id_t device_id, services_t service, measured_string_ref configuration, size_t count, measured_string_ref * translation, char ** data){
     428        aid_t message_id;
     429        ipcarg_t result;
     430        int string;
     431
     432        if(!(configuration && (count > 0))){
     433                return EINVAL;
     434        }
     435        if(!(translation && data)){
     436                return EBADMEM;
     437        }
     438        message_id = async_send_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) count, (ipcarg_t) service, NULL);
     439        measured_strings_send(phone, configuration, count);
     440        string = measured_strings_return(phone, translation, data, count);
     441        async_wait_for(message_id, &result);
     442        if((string == EOK) && (result != EOK)){
     443                free(*translation);
     444                free(*data);
     445        }
     446        return (int) result;
     447}
     448
     449/** Sends the packet queue.
     450 *  @param[in] phone The service module phone.
     451 *  @param[in] message The service specific message.
     452 *  @param[in] device_id The device identifier.
     453 *  @param[in] packet_id The packet or the packet queue identifier.
     454 *  @param[in] sender The sending module service.
     455 *  @param[in] error The error module service.
     456 *  @returns EOK on success.
     457 */
     458static inline int generic_send_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t sender, services_t error){
     459        if(error){
     460                async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error);
     461        }else{
     462                async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender);
     463        }
     464        return EOK;
    494465}
    495466
     
    521492}
    522493
     494/** Notifies the module about the device state change.
     495 *  @param[in] phone The service module phone.
     496 *  @param[in] message The service specific message.
     497 *  @param[in] device_id The device identifier.
     498 *  @param[in] state The new device state.
     499 *  @param[in] target The target module service.
     500 *  @returns EOK on success.
     501 */
     502static inline int generic_device_state_msg(int phone, int message, device_id_t device_id, int state, services_t target){
     503        async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) state, target);
     504        return EOK;
     505}
     506
    523507/** Passes the packet queue to the module.
    524508 *  @param[in] phone The service module phone.
     
    539523}
    540524
    541 /** Sends the packet queue.
    542  *  @param[in] phone The service module phone.
    543  *  @param[in] message The service specific message.
    544  *  @param[in] device_id The device identifier.
    545  *  @param[in] packet_id The packet or the packet queue identifier.
    546  *  @param[in] sender The sending module service.
    547  *  @param[in] error The error module service.
    548  *  @returns EOK on success.
    549  */
    550 static inline int generic_send_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t sender, services_t error){
    551         if(error){
    552                 async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error);
    553         }else{
    554                 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender);
    555         }
    556         return EOK;
    557 }
    558 
    559 /** Translates the given strings.
    560  *  Allocates and returns the needed memory block as the data parameter.
    561  *  @param[in] phone The service module phone.
    562  *  @param[in] message The service specific message.
    563  *  @param[in] device_id The device identifier.
    564  *  @param[in] service The module service.
    565  *  @param[in] configuration The key strings.
    566  *  @param[in] count The number of configuration keys.
    567  *  @param[out] translation The translated values.
    568  *  @param[out] data The translation data container.
    569  *  @returns EOK on success.
    570  *  @returns EINVAL if the configuration parameter is NULL.
    571  *  @returns EINVAL if the count parameter is zero (0).
    572  *  @returns EBADMEM if the translation or the data parameters are NULL.
     525/** Notifies a module about the device.
     526 *  @param[in] phone The service module phone.
     527 *  @param[in] message The service specific message.
     528 *  @param[in] device_id The device identifier.
     529 *  @param[in] arg2 The second argument of the message.
     530 *  @param[in] service The device module service.
     531 *  @returns EOK on success.
    573532 *  @returns Other error codes as defined for the specific service message.
    574533 */
    575 static inline int generic_translate_req(int phone, int message, device_id_t device_id, services_t service, measured_string_ref configuration, size_t count, measured_string_ref * translation, char ** data){
    576         aid_t message_id;
    577         ipcarg_t result;
    578         int string;
    579 
    580         if(!(configuration && (count > 0))){
    581                 return EINVAL;
    582         }
    583         if(!(translation && data)){
    584                 return EBADMEM;
    585         }
    586 
    587         // request the translation
    588         message_id = async_send_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) count, (ipcarg_t) service, NULL);
    589         measured_strings_send(phone, configuration, count);
    590         string = measured_strings_return(phone, translation, data, count);
    591         async_wait_for(message_id, &result);
    592 
    593         // if not successful
    594         if((string == EOK) && (result != EOK)){
    595                 // clear the data
    596                 free(*translation);
    597                 free(*data);
    598         }
    599 
    600         return (int) result;
     534static inline int generic_device_req(int phone, int message, device_id_t device_id, int arg2, services_t service){
     535        return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) arg2, (ipcarg_t) service);
    601536}
    602537
  • uspace/srv/net/module.c

    r60ab6c3 r71b00dcc  
    104104        ipc_answer_0(iid, EOK);
    105105
    106         // process additional messages
    107106        while(true){
    108 
    109                 // clear the answer structure
    110107                refresh_answer(&answer, &answer_count);
    111108
    112                 // fetch the next message
    113109                callid = async_get_call(&call);
    114 
    115                 // process the message
    116110                res = module_message(callid, &call, &answer, &answer_count);
    117111
    118                 // end if said to either by the message or the processing result
    119112                if((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)){
    120113                        return;
    121114                }
    122115
    123                 // answer the message
    124116                answer_call(callid, res, &answer, answer_count);
    125117        }
     
    129121        ERROR_DECLARE;
    130122
    131         // print the module label
    132123        printf("Task %d - ", task_get_id());
    133124        module_print_name();
    134125        printf("\n");
    135 
    136         // start the module
    137126        if(ERROR_OCCURRED(module_start(client_connection))){
    138127                printf(" - ERROR %i\n", ERROR_CODE);
    139128                return ERROR_CODE;
    140129        }
    141 
    142130        return EOK;
    143131}
  • uspace/srv/net/modules.c

    r60ab6c3 r71b00dcc  
    5151
    5252void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count){
    53         // choose the most efficient answer function
    5453        if(answer || (! answer_count)){
    5554                switch(answer_count){
     
    8786        ipcarg_t phonehash;
    8887
    89         // connect to the needed service
    9088        phone = connect_to_service_timeout(need, timeout);
    91         // if connected
    9289        if(phone >= 0){
    93                 // request the bidirectional connection
    9490                if(ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash))){
    9591                        ipc_hangup(phone);
     
    106102
    107103int connect_to_service_timeout(services_t need, suseconds_t timeout){
    108         int phone;
     104        if (timeout <= 0)
     105                return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
     106       
     107        while(true){
     108                int phone;
    109109
    110         // if no timeout is set
    111         if (timeout <= 0){
    112                 return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
    113         }
    114 
    115         while(true){
    116110                phone = async_connect_me_to(PHONE_NS, need, 0, 0);
    117                 if((phone >= 0) || (phone != ENOENT)){
     111                if((phone >= 0) || (phone != ENOENT))
    118112                        return phone;
    119                 }
    120 
    121                 // end if no time is left
     113       
     114                timeout -= MODULE_WAIT_TIME;
    122115                if(timeout <= 0){
    123116                        return ETIMEOUT;
    124117                }
    125118
    126                 // wait the minimum of the module wait time and the timeout
    127                 usleep((timeout <= MODULE_WAIT_TIME) ? timeout : MODULE_WAIT_TIME);
    128                 timeout -= MODULE_WAIT_TIME;
     119                usleep(MODULE_WAIT_TIME);
    129120        }
    130121}
     
    138129                return EBADMEM;
    139130        }
    140 
    141         // fetch the request
    142131        if(! async_data_write_receive(&callid, length)){
    143132                return EINVAL;
    144133        }
    145 
    146         // allocate the buffer
    147134        *data = malloc(*length);
    148135        if(!(*data)){
    149136                return ENOMEM;
    150137        }
    151 
    152         // fetch the data
    153138        if(ERROR_OCCURRED(async_data_write_finalize(callid, * data, * length))){
    154139                free(data);
     
    162147        ipc_callid_t callid;
    163148
    164         // fetch the request
    165149        if(! async_data_read_receive(&callid, &length)){
    166150                return EINVAL;
    167151        }
    168 
    169         // check the requested data size
    170152        if(length < data_length){
    171153                async_data_read_finalize(callid, data, length);
    172154                return EOVERFLOW;
    173155        }
    174 
    175         // send the data
    176156        return async_data_read_finalize(callid, data, data_length);
    177157}
    178158
    179159void refresh_answer(ipc_call_t * answer, int * answer_count){
    180 
    181160        if(answer_count){
    182161                *answer_count = 0;
    183162        }
    184 
    185163        if(answer){
    186164                IPC_SET_RETVAL(*answer, 0);
  • uspace/srv/net/net/net.c

    r60ab6c3 r71b00dcc  
    6666#include "net_messages.h"
    6767
     68/** Networking module name.
     69 */
     70#define NAME    "Networking"
     71
    6872/** File read buffer size.
    6973 */
    7074#define BUFFER_SIZE     256
    71 
    72 /** Networking module name.
    73  */
    74 #define NAME    "Networking"
    75 
    76 /** Networking module global data.
    77  */
    78 net_globals_t   net_globals;
    79 
    80 /** Generates new system-unique device identifier.
    81  *  @returns The system-unique devic identifier.
    82  */
    83 device_id_t generate_new_device_id(void);
    8475
    8576/** Prints the module name.
     
    9788int module_start(async_client_conn_t client_connection);
    9889
    99 /** Returns the configured values.
    100  *  The network interface configuration is searched first.
    101  *  @param[in] netif_conf The network interface configuration setting.
    102  *  @param[out] configuration The found configured values.
    103  *  @param[in] count The desired settings count.
    104  *  @param[out] data The found configuration settings data.
    105  *  @returns EOK.
    106  */
    107 int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data);
    108 
    109 /** Initializes the networking module.
    110  *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
    111  *  @returns EOK on success.
    112  *  @returns ENOMEM if there is not enough memory left.
    113  */
    114 int net_initialize(async_client_conn_t client_connection);
     90/** \todo
     91 */
     92int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration);
    11593
    11694/** \todo
     
    123101 */
    124102int read_configuration(void);
    125 
    126 /** \todo
    127  */
    128 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration);
    129 
    130 /** Reads the network interface specific configuration.
    131  *  @param[in] name The network interface name.
    132  *  @param[in,out] netif The network interface structure.
    133  *  @returns EOK on success.
    134  *  @returns Other error codes as defined for the add_configuration() function.
    135  */
    136 int read_netif_configuration(const char * name, netif_ref netif);
    137103
    138104/** Starts the network interface according to its configuration.
     
    160126int startup(void);
    161127
     128/** Generates new system-unique device identifier.
     129 *  @returns The system-unique devic identifier.
     130 */
     131device_id_t generate_new_device_id(void);
     132
     133/** Returns the configured values.
     134 *  The network interface configuration is searched first.
     135 *  @param[in] netif_conf The network interface configuration setting.
     136 *  @param[out] configuration The found configured values.
     137 *  @param[in] count The desired settings count.
     138 *  @param[out] data The found configuration settings data.
     139 *  @returns EOK.
     140 */
     141int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data);
     142
     143/** Initializes the networking module.
     144 *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
     145 *  @returns EOK on success.
     146 *  @returns ENOMEM if there is not enough memory left.
     147 */
     148int net_initialize(async_client_conn_t client_connection);
     149
     150/** Reads the network interface specific configuration.
     151 *  @param[in] name The network interface name.
     152 *  @param[in,out] netif The network interface structure.
     153 *  @returns EOK on success.
     154 *  @returns Other error codes as defined for the add_configuration() function.
     155 */
     156int read_netif_configuration(const char * name, netif_ref netif);
     157
     158/** Networking module global data.
     159 */
     160net_globals_t   net_globals;
     161
     162DEVICE_MAP_IMPLEMENT(netifs, netif_t)
     163
    162164GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t)
    163 
    164 DEVICE_MAP_IMPLEMENT(netifs, netif_t)
    165 
    166 int add_configuration(measured_strings_ref configuration, const char * name, const char * value){
    167         ERROR_DECLARE;
    168 
    169         measured_string_ref setting;
    170 
    171         setting = measured_string_create_bulk(value, 0);
    172         if(! setting){
    173                 return ENOMEM;
    174         }
    175         // add the configuration setting
    176         if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
    177                 free(setting);
    178                 return ERROR_CODE;
    179         }
    180         return EOK;
    181 }
    182 
    183 device_id_t generate_new_device_id(void){
    184         return device_assign_devno();
    185 }
    186165
    187166void module_print_name(void){
     
    208187}
    209188
    210 int net_connect_module(services_t service){
    211         return EOK;
    212 }
    213 
    214 void net_free_settings(measured_string_ref settings, char * data){
     189int 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
     197        // TODO dynamic configuration
     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
     205        // build specific initialization
     206        return net_initialize_build(client_connection);
     207}
     208
     209int 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);
     218        }else{
     219                return net_get_conf(NULL, * configuration, count, data);
     220        }
     221}
     222
     223int 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);
    215228}
    216229
     
    222235                *data = NULL;
    223236        }
    224 
    225237        for(index = 0; index < count; ++ index){
    226238                setting = measured_strings_find(netif_conf, configuration[index].value, 0);
     
    239251}
    240252
    241 int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
    242         if(!(configuration && (count > 0))){
    243                 return EINVAL;
    244         }
    245 
    246         return net_get_conf(NULL, * configuration, count, data);
    247 }
    248 
    249 int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
    250         netif_ref netif;
    251 
    252         if(!(configuration && (count > 0))){
    253                 return EINVAL;
    254         }
    255 
    256         netif = netifs_find(&net_globals.netifs, device_id);
    257         if(netif){
    258                 return net_get_conf(&netif->configuration, * configuration, count, data);
    259         }else{
    260                 return net_get_conf(NULL, * configuration, count, data);
    261         }
    262 }
    263 
    264 int net_initialize(async_client_conn_t client_connection){
    265         ERROR_DECLARE;
    266 
    267         netifs_initialize(&net_globals.netifs);
    268         char_map_initialize(&net_globals.netif_names);
    269         modules_initialize(&net_globals.modules);
    270         measured_strings_initialize(&net_globals.configuration);
    271 
    272         // TODO dynamic configuration
    273         ERROR_PROPAGATE(read_configuration());
    274 
    275         ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));
    276         ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));
    277         ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service));
    278         ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service));
    279 
    280         // build specific initialization
    281         return net_initialize_build(client_connection);
     253void net_free_settings(measured_string_ref settings, char * data){
     254}
     255
     256int net_connect_module(services_t service){
     257        return EOK;
    282258}
    283259
     
    312288        }
    313289        return ENOTSUP;
    314 }
    315 
    316 int parse_line(measured_strings_ref configuration, char * line){
    317         ERROR_DECLARE;
    318 
    319         measured_string_ref setting;
    320         char * name;
    321         char * value;
    322 
    323         // from the beginning
    324         name = line;
    325 
    326         // skip comments and blank lines
    327         if((*name == '#') || (*name == '\0')){
    328                 return EOK;
    329         }
    330         // skip spaces
    331         while(isspace(*name)){
    332                 ++ name;
    333         }
    334 
    335         // remember the name start
    336         value = name;
    337         // skip the name
    338         while(isalnum(*value) || (*value == '_')){
    339                 // make uppercase
    340 //              *value = toupper(*value);
    341                 ++ value;
    342         }
    343 
    344         if(*value == '='){
    345                 // terminate the name
    346                 *value = '\0';
    347         }else{
    348                 // terminate the name
    349                 *value = '\0';
    350                 // skip until '='
    351                 ++ value;
    352                 while((*value) && (*value != '=')){
    353                         ++ value;
    354                 }
    355                 // not found?
    356                 if(*value != '='){
    357                         return EINVAL;
    358                 }
    359         }
    360 
    361         ++ value;
    362         // skip spaces
    363         while(isspace(*value)){
    364                 ++ value;
    365         }
    366         // create a bulk measured string till the end
    367         setting = measured_string_create_bulk(value, 0);
    368         if(! setting){
    369                 return ENOMEM;
    370         }
    371 
    372         // add the configuration setting
    373         if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
    374                 free(setting);
    375                 return ERROR_CODE;
    376         }
    377         return EOK;
    378 }
    379 
    380 int read_configuration(void){
    381         // read the general configuration file
    382         return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
    383290}
    384291
     
    434341}
    435342
     343int parse_line(measured_strings_ref configuration, char * line){
     344        ERROR_DECLARE;
     345
     346        measured_string_ref setting;
     347        char * name;
     348        char * value;
     349
     350        // from the beginning
     351        name = line;
     352
     353        // skip comments and blank lines
     354        if((*name == '#') || (*name == '\0')){
     355                return EOK;
     356        }
     357        // skip spaces
     358        while(isspace(*name)){
     359                ++ name;
     360        }
     361
     362        // remember the name start
     363        value = name;
     364        // skip the name
     365        while(isalnum(*value) || (*value == '_')){
     366                // make uppercase
     367//              *value = toupper(*value);
     368                ++ value;
     369        }
     370
     371        if(*value == '='){
     372                // terminate the name
     373                *value = '\0';
     374        }else{
     375                // terminate the name
     376                *value = '\0';
     377                // skip until '='
     378                ++ value;
     379                while((*value) && (*value != '=')){
     380                        ++ value;
     381                }
     382                // not found?
     383                if(*value != '='){
     384                        return EINVAL;
     385                }
     386        }
     387
     388        ++ value;
     389        // skip spaces
     390        while(isspace(*value)){
     391                ++ value;
     392        }
     393        // create a bulk measured string till the end
     394        setting = measured_string_create_bulk(value, 0);
     395        if(! setting){
     396                return ENOMEM;
     397        }
     398
     399        // add the configuration setting
     400        if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
     401                free(setting);
     402                return ERROR_CODE;
     403        }
     404        return EOK;
     405}
     406
     407int 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        }
     416        // add the configuration setting
     417        if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
     418                free(setting);
     419                return ERROR_CODE;
     420        }
     421        return EOK;
     422}
     423
     424device_id_t generate_new_device_id(void){
     425        return device_assign_devno();
     426}
     427
     428int read_configuration(void){
     429        // read the general configuration file
     430        return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
     431}
     432
    436433int read_netif_configuration(const char * name, netif_ref netif){
    437434        // read the netif configuration file
     
    455452                return EINVAL;
    456453        }
    457 
    458454        // optional network interface layer
    459455        setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
     
    467463                netif->nil = NULL;
    468464        }
    469 
    470465        // mandatory internet layer
    471466        setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
     
    475470                return EINVAL;
    476471        }
    477 
    478         // hardware configuration
     472        // end of the static loopback initialization
     473        // startup the loopback interface
    479474        setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);
    480475        irq = setting ? strtol(setting->value, NULL, 10) : 0;
     
    482477        io = setting ? strtol(setting->value, NULL, 16) : 0;
    483478        ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io));
    484 
    485         // network interface layer startup
    486479        if(netif->nil){
    487480                setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
     
    495488                internet_service = netif->driver->service;
    496489        }
    497 
    498         // inter-network layer startup
    499490        switch(netif->il->service){
    500491                case SERVICE_IP:
     
    534525                }
    535526                ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
    536 
    537527                // read configuration files
    538528                if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){
     
    541531                        return ERROR_CODE;
    542532                }
    543 
    544533                // mandatory name
    545534                setting = measured_strings_find(&netif->configuration, CONF_NAME, 0);
     
    551540                }
    552541                netif->name = setting->value;
    553 
    554542                // add to the netifs map
    555543                index = netifs_add(&net_globals.netifs, netif->id, netif);
     
    559547                        return index;
    560548                }
    561 
    562549                // add to the netif names map
    563550                if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index))
     
    568555                        return ERROR_CODE;
    569556                }
    570 
    571557                // increment modules' usage
    572558                ++ netif->driver->usage;
  • uspace/srv/net/net/net.h

    r60ab6c3 r71b00dcc  
    5252/*@{*/
    5353
     54/** Loopback network interface module name.
     55 */
     56#define LO_NAME                         "lo"
     57
     58/** Loopback network interface module full path filename.
     59 */
     60#define LO_FILENAME                     "/srv/lo"
     61
     62/** DP8390 network interface module name.
     63 */
     64#define DP8390_NAME                     "dp8390"
     65
    5466/** DP8390 network interface module full path filename.
    5567 */
    5668#define DP8390_FILENAME         "/srv/dp8390"
    5769
    58 /** DP8390 network interface module name.
    59  */
    60 #define DP8390_NAME                     "dp8390"
     70/** Ethernet module name.
     71 */
     72#define ETHERNET_NAME           "ethernet"
    6173
    6274/** Ethernet module full path filename.
     
    6678/** Ethernet module name.
    6779 */
    68 #define ETHERNET_NAME           "ethernet"
     80#define NILDUMMY_NAME           "nildummy"
     81
     82/** Ethernet module full path filename.
     83 */
     84#define NILDUMMY_FILENAME       "/srv/nildummy"
     85
     86/** IP module name.
     87 */
     88#define IP_NAME                         "ip"
    6989
    7090/** IP module full path filename.
     
    7292#define IP_FILENAME                     "/srv/ip"
    7393
    74 /** IP module name.
    75  */
    76 #define IP_NAME                         "ip"
    77 
    78 /** Loopback network interface module full path filename.
    79  */
    80 #define LO_FILENAME                     "/srv/lo"
    81 
    82 /** Loopback network interface module name.
    83  */
    84 #define LO_NAME                         "lo"
    85 
    86 /** Ethernet module full path filename.
    87  */
    88 #define NILDUMMY_FILENAME       "/srv/nildummy"
    89 
    90 /** Ethernet module name.
    91  */
    92 #define NILDUMMY_NAME           "nildummy"
    93 
    9494/*@}*/
    9595
     
    9898/*@{*/
    9999
     100/** Network interface name configuration label.
     101 */
     102#define CONF_NAME                       "NAME"
     103
     104/** Network interface module name configuration label.
     105 */
     106#define CONF_NETIF                      "NETIF"
     107
     108/** Network interface layer module name configuration label.
     109 */
     110#define CONF_NIL                        "NIL"
     111
    100112/** Internet protocol module name configuration label.
    101113 */
    102114#define CONF_IL                         "IL"
    103115
     116/** Interrupt number configuration label.
     117 */
     118#define CONF_IRQ                        "IRQ"
     119
    104120/** Device input/output address configuration label.
    105121 */
    106122#define CONF_IO                         "IO"
    107123
    108 /** Interrupt number configuration label.
    109  */
    110 #define CONF_IRQ                        "IRQ"
    111 
    112124/** Maximum transmission unit configuration label.
    113125 */
    114126#define CONF_MTU                        "MTU"
    115127
    116 /** Network interface name configuration label.
    117  */
    118 #define CONF_NAME                       "NAME"
    119 
    120 /** Network interface module name configuration label.
    121  */
    122 #define CONF_NETIF                      "NETIF"
    123 
    124 /** Network interface layer module name configuration label.
    125  */
    126 #define CONF_NIL                        "NIL"
    127 
    128128/*@}*/
    129129
     
    135135 */
    136136#define CONF_GENERAL_FILE       "general"
     137
     138/** Type definition of the network interface specific data.
     139 *  @see netif
     140 */
     141typedef struct netif    netif_t;
     142
     143/** Type definition of the network interface specific data pointer.
     144 *  @see netif
     145 */
     146typedef netif_t *               netif_ref;
    137147
    138148/** Type definition of the networking module global data.
     
    141151typedef struct net_globals      net_globals_t;
    142152
    143 /** Type definition of the network interface specific data.
    144  *  @see netif
    145  */
    146 typedef struct netif    netif_t;
    147 
    148 /** Type definition of the network interface specific data pointer.
    149  *  @see netif
    150  */
    151 typedef netif_t *               netif_ref;
     153/** Present network interfaces.
     154 *  Maps devices to the networking device specific data.
     155 *  @see device.h
     156 */
     157DEVICE_MAP_DECLARE(netifs, netif_t)
    152158
    153159/** Configuration settings.
     
    157163GENERIC_CHAR_MAP_DECLARE(measured_strings, measured_string_t)
    158164
    159 /** Present network interfaces.
    160  *  Maps devices to the networking device specific data.
    161  *  @see device.h
    162  */
    163 DEVICE_MAP_DECLARE(netifs, netif_t)
    164 
    165 /** Networking module global variables.
    166  */
    167 struct net_globals{
    168         /** Global configuration.
    169          */
    170         measured_strings_t configuration;
    171         /** Available modules.
    172          */
    173         modules_t modules;
    174         /** Network interface structure indices by names.
    175          */
    176         char_map_t netif_names;
    177         /** Present network interfaces.
    178          */
    179         netifs_t netifs;
    180 };
    181 
    182165/** Present network interface device.
    183166 */
    184167struct netif{
    185         /** Configuration.
    186          */
    187         measured_strings_t configuration;
     168        /** System-unique network interface identifier.
     169         */
     170        device_id_t id;
    188171        /** Serving network interface driver module index.
    189172         */
    190173        module_ref driver;
    191         /** System-unique network interface identifier.
    192          */
    193         device_id_t id;
     174        /** Serving link layer module index.
     175         */
     176        module_ref nil;
    194177        /** Serving internet layer module index.
    195178         */
     
    198181         */
    199182        char * name;
    200         /** Serving link layer module index.
    201          */
    202         module_ref nil;
     183        /** Configuration.
     184         */
     185        measured_strings_t configuration;
     186};
     187
     188/** Networking module global variables.
     189 */
     190struct net_globals{
     191        /** Present network interfaces.
     192         */
     193        netifs_t netifs;
     194        /** Network interface structure indices by names.
     195         */
     196        char_map_t netif_names;
     197        /** Available modules.
     198         */
     199        modules_t modules;
     200        /** Global configuration.
     201         */
     202        measured_strings_t configuration;
    203203};
    204204
     
    211211 */
    212212int add_configuration(measured_strings_ref configuration, const char * name, const char * value);
     213
     214/** Processes the networking message.
     215 *  @param[in] callid The message identifier.
     216 *  @param[in] call The message parameters.
     217 *  @param[out] answer The message answer parameters.
     218 *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
     219 *  @returns EOK on success.
     220 *  @returns ENOTSUP if the message is not known.
     221 *  @see net_interface.h
     222 *  @see IS_NET_NET_MESSAGE()
     223 */
     224int net_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
     225
     226/** Initializes the networking module for the chosen subsystem build type.
     227 *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
     228 *  @returns EOK on success.
     229 *  @returns ENOMEM if there is not enough memory left.
     230 */
     231int net_initialize_build(async_client_conn_t client_connection);
    213232
    214233/** Processes the module message.
     
    224243int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
    225244
    226 /** Initializes the networking module for the chosen subsystem build type.
    227  *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
    228  *  @returns EOK on success.
    229  *  @returns ENOMEM if there is not enough memory left.
    230  */
    231 int net_initialize_build(async_client_conn_t client_connection);
    232 
    233 /** Processes the networking message.
    234  *  @param[in] callid The message identifier.
    235  *  @param[in] call The message parameters.
    236  *  @param[out] answer The message answer parameters.
    237  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    238  *  @returns EOK on success.
    239  *  @returns ENOTSUP if the message is not known.
    240  *  @see net_interface.h
    241  *  @see IS_NET_NET_MESSAGE()
    242  */
    243 int net_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
    244 
    245245#endif
    246246
  • uspace/srv/net/net/net_bundle.c

    r60ab6c3 r71b00dcc  
    6060extern net_globals_t    net_globals;
    6161
    62 int net_initialize_build(async_client_conn_t client_connection){
    63         ERROR_DECLARE;
    64 
    65         ipcarg_t phonehash;
    66 
    67         ERROR_PROPAGATE(REGISTER_ME(SERVICE_IP, &phonehash));
    68         ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id(), ip_connect_module));
    69         ERROR_PROPAGATE(ip_initialize(client_connection));
    70         ERROR_PROPAGATE(REGISTER_ME(SERVICE_ARP, &phonehash));
    71         ERROR_PROPAGATE(arp_initialize(client_connection));
    72         ERROR_PROPAGATE(REGISTER_ME(SERVICE_ICMP, &phonehash));
    73         ERROR_PROPAGATE(icmp_initialize(client_connection));
    74         ERROR_PROPAGATE(REGISTER_ME(SERVICE_UDP, &phonehash));
    75         ERROR_PROPAGATE(udp_initialize(client_connection));
    76         ERROR_PROPAGATE(REGISTER_ME(SERVICE_TCP, &phonehash));
    77         ERROR_PROPAGATE(tcp_initialize(client_connection));
    78         return EOK;
    79 }
    80 
    8162int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    8263        if((IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)
     
    11798}
    11899
     100int net_initialize_build(async_client_conn_t client_connection){
     101        ERROR_DECLARE;
     102
     103        ipcarg_t phonehash;
     104
     105        ERROR_PROPAGATE(REGISTER_ME(SERVICE_IP, &phonehash));
     106        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id(), ip_connect_module));
     107        ERROR_PROPAGATE(ip_initialize(client_connection));
     108        ERROR_PROPAGATE(REGISTER_ME(SERVICE_ARP, &phonehash));
     109        ERROR_PROPAGATE(arp_initialize(client_connection));
     110        ERROR_PROPAGATE(REGISTER_ME(SERVICE_ICMP, &phonehash));
     111        ERROR_PROPAGATE(icmp_initialize(client_connection));
     112        ERROR_PROPAGATE(REGISTER_ME(SERVICE_UDP, &phonehash));
     113        ERROR_PROPAGATE(udp_initialize(client_connection));
     114        ERROR_PROPAGATE(REGISTER_ME(SERVICE_TCP, &phonehash));
     115        ERROR_PROPAGATE(tcp_initialize(client_connection));
     116        return EOK;
     117}
     118
    119119/** @}
    120120 */
  • uspace/srv/net/net/net_remote.c

    r60ab6c3 r71b00dcc  
    5050#include "net_messages.h"
    5151
    52 int net_connect_module(services_t service){
    53         return connect_to_service(SERVICE_NETWORKING);
     52int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
     53        return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, device_id, 0, * configuration, count, configuration, data);
     54}
     55
     56int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
     57        return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, 0, 0, * configuration, count, configuration, data);
    5458}
    5559
     
    6367}
    6468
    65 int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
    66         return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, 0, 0, * configuration, count, configuration, data);
    67 }
    68 
    69 int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
    70         return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, device_id, 0, * configuration, count, configuration, data);
     69int net_connect_module(services_t service){
     70        return connect_to_service(SERVICE_NETWORKING);
    7171}
    7272
  • uspace/srv/net/net/net_standalone.c

    r60ab6c3 r71b00dcc  
    5353extern net_globals_t    net_globals;
    5454
     55int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     56        if(IS_NET_PACKET_MESSAGE(call)){
     57                return packet_server_message(callid, call, answer, answer_count);
     58        }else{
     59                return net_message(callid, call, answer, answer_count);
     60        }
     61}
     62
    5563int net_initialize_build(async_client_conn_t client_connection){
    5664        ERROR_DECLARE;
     
    7583}
    7684
    77 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    78         if(IS_NET_PACKET_MESSAGE(call)){
    79                 return packet_server_message(callid, call, answer, answer_count);
    80         }else{
    81                 return net_message(callid, call, answer, answer_count);
    82         }
    83 }
    84 
    8585/** @}
    8686 */
  • uspace/srv/net/net/start/netstart.c

    r60ab6c3 r71b00dcc  
    7676        int net_phone;
    7777
    78         // print the module label
    7978        printf("Task %d - ", task_get_id());
    8079        printf("%s\n", NAME);
    81 
    8280        // run self tests
    8381        ERROR_PROPAGATE(self_test());
    84 
    85         // start the networking service
     82        // start net service
    8683        if(! spawn("/srv/net")){
    8784                fprintf(stderr, "Could not spawn net\n");
    8885                return EINVAL;
    8986        }
    90 
    91         // start the networking
     87        // start net
    9288        net_phone = connect_to_service(SERVICE_NETWORKING);
    9389        if(ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))){
  • uspace/srv/net/netif/dp8390/dp8390_module.c

    r60ab6c3 r71b00dcc  
    193193        dep->de_int_pending = 0;
    194194//      remove debug print:
    195 #ifdef CONFIG_DEBUG
    196195        printf("I%d: 0x%x\n", device_id, IPC_GET_ISR(call));
    197 #endif
    198196        dp_check_ints(dep, IPC_GET_ISR(call));
    199197        if(dep->received_queue){
     
    204202                fibril_rwlock_write_unlock(&netif_globals.lock);
    205203//      remove debug dump:
    206 #ifdef CONFIG_DEBUG
    207204        uint8_t * data;
    208205        data = packet_get_data(received);
    209206        printf("Receiving packet:\n\tid\t= %d\n\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX\n\t\t%.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", packet_get_id(received), packet_get_data_length(received), data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], data[23], data[24], data[25], data[26], data[27], data[28], data[29], data[30], data[31], data[32], data[33], data[34], data[35], data[36], data[37], data[38], data[39], data[40], data[41], data[42], data[43], data[44], data[45], data[46], data[47], data[48], data[49], data[50], data[51], data[52], data[53], data[54], data[55], data[56], data[57], data[58], data[59]);
    210 #endif
    211207                nil_received_msg(phone, device_id, received, NULL);
    212208        }else{
     
    271267                next = pq_detach(packet);
    272268//              remove debug dump:
    273 #ifdef CONFIG_DEBUG
    274269                uint8_t * data;
    275270                data = packet_get_data(packet);
    276271                printf("Sending packet:\n\tid\t= %d\n\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX\n\t\t%.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", packet_get_id(packet), packet_get_data_length(packet), data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], data[23], data[24], data[25], data[26], data[27], data[28], data[29], data[30], data[31], data[32], data[33], data[34], data[35], data[36], data[37], data[38], data[39], data[40], data[41], data[42], data[43], data[44], data[45], data[46], data[47], data[48], data[49], data[50], data[51], data[52], data[53], data[54], data[55], data[56], data[57], data[58], data[59]);
    277 #endif
     272
    278273                if(do_pwrite(dep, packet, FALSE) != EBUSY){
    279274                        netif_pq_release(packet_get_id(packet));
  • uspace/srv/net/self_test.c

    r60ab6c3 r71b00dcc  
    5757 *  @param[in] result The expected result.
    5858 */
    59 #define TEST(name, function_call, result);      {                                                               \
    60         printf("\n\t%s", (name));                                                                                               \
    61         if((function_call) != (result)){                                                                                \
    62                 printf("\tERROR\n");                                                                                            \
    63                 error = 1;                                                                                                                      \
    64         }else{                                                                                                                                  \
    65                 printf("\tOK\n");                                                                                                       \
    66         }                                                                                                                                               \
     59#define TEST(name, function_call, result);      {       \
     60        printf("\n\t%s", (name));                                       \
     61        if((function_call) != (result)){                        \
     62                printf("\tERROR\n");                                            \
     63                error = 1;                                                                      \
     64        }else{                                                                                  \
     65                printf("\tOK\n");                                                       \
     66        }                                                                                               \
    6767}
    6868
     69#if NET_SELF_TEST_INT_MAP
     70
     71        INT_MAP_DECLARE(int_map, int);
     72
     73        INT_MAP_IMPLEMENT(int_map, int);
     74
     75#endif
     76
     77#if NET_SELF_TEST_GENERIC_FIELD
     78
     79        GENERIC_FIELD_DECLARE(int_field, int)
     80
     81        GENERIC_FIELD_IMPLEMENT(int_field, int)
     82
     83#endif
     84
    6985#if NET_SELF_TEST_GENERIC_CHAR_MAP
    7086
     
    7288
    7389        GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int)
    74 
    75 #endif
    76 
    77 #if NET_SELF_TEST_GENERIC_FIELD
    78 
    79         GENERIC_FIELD_DECLARE(int_field, int)
    80 
    81         GENERIC_FIELD_IMPLEMENT(int_field, int)
    82 
    83 #endif
    84 
    85 #if NET_SELF_TEST_INT_MAP
    86 
    87         INT_MAP_DECLARE(int_map, int);
    88 
    89         INT_MAP_IMPLEMENT(int_map, int);
    9090
    9191#endif
     
    101101
    102102        error = 0;
     103
     104#if NET_SELF_TEST_MEASURED_STRINGS
     105        measured_string_ref string;
     106
     107        printf("\nMeasured strings test");
     108        string = measured_string_create_bulk("I am a measured string!", 0);
     109        printf("\n%x, %s at %x of %d", string, string->value, string->value, string->length);
     110        printf("\nOK");
     111#endif
    103112
    104113#if NET_SELF_TEST_CHAR_MAP
     
    151160#endif
    152161
    153 #if NET_SELF_TEST_CRC
    154         uint32_t value;
    155 
    156         printf("\nCRC computation test");
    157         value = ~ compute_crc32(~ 0, "123456789", 8 * 9);
    158         TEST("123456789", value, 0xCBF43926);
    159         printf("\t=> %X", value);
    160         value = ~ compute_crc32(~ 0, "1", 8);
    161         TEST("1", value, 0x83DCEFB7);
    162         printf("\t=> %X", value);
    163         value = ~ compute_crc32(~ 0, "12", 8 * 2);
    164         TEST("12", value, 0x4F5344CD);
    165         printf("\t=> %X", value);
    166         value = ~ compute_crc32(~ 0, "123", 8 * 3);
    167         TEST("123", value, 0x884863D2);
    168         printf("\t=> %X", value);
    169         value = ~ compute_crc32(~ 0, "1234", 8 * 4);
    170         TEST("1234", value, 0x9BE3E0A3);
    171         printf("\t=> %X", value);
    172         value = ~ compute_crc32(~ 0, "12345678", 8 * 8);
    173         TEST("12345678", value, 0x9AE0DAAF);
    174         printf("\t=> %X", value);
    175         value = ~ compute_crc32(~ 0, "ahoj pane", 8 * 9);
    176         TEST("ahoj pane", value, 0x5FC3D706);
    177         printf("\t=> %X", value);
    178 
    179         if(error){
    180                 return EINVAL;
    181         }
    182 
    183 #endif
    184 
    185 #if NET_SELF_TEST_DYNAMIC_FIFO
    186         dyn_fifo_t fifo;
    187 
    188         printf("\nDynamic fifo test");
    189         TEST("add 1 einval", dyn_fifo_push(&fifo, 1, 0), EINVAL);
    190         TEST("initialize", dyn_fifo_initialize(&fifo, 1), EOK);
    191         TEST("add 1 eok", dyn_fifo_push(&fifo, 1, 0), EOK);
    192         TEST("pop 1", dyn_fifo_pop(&fifo), 1);
    193         TEST("pop enoent", dyn_fifo_pop(&fifo), ENOENT);
    194         TEST("add 2 eok", dyn_fifo_push(&fifo, 2, 1), EOK);
    195         TEST("add 3 enomem", dyn_fifo_push(&fifo, 3, 1), ENOMEM);
    196         TEST("add 3 eok", dyn_fifo_push(&fifo, 3, 0), EOK);
    197         TEST("pop 2", dyn_fifo_pop(&fifo), 2);
    198         TEST("pop 3", dyn_fifo_pop(&fifo), 3);
    199         TEST("add 4 eok", dyn_fifo_push(&fifo, 4, 2), EOK);
    200         TEST("add 5 eok", dyn_fifo_push(&fifo, 5, 2), EOK);
    201         TEST("add 6 enomem", dyn_fifo_push(&fifo, 6, 2), ENOMEM);
    202         TEST("add 6 eok", dyn_fifo_push(&fifo, 6, 5), EOK);
    203         TEST("add 7 eok", dyn_fifo_push(&fifo, 7, 5), EOK);
    204         TEST("pop 4", dyn_fifo_pop(&fifo), 4);
    205         TEST("pop 5", dyn_fifo_pop(&fifo), 5);
    206         TEST("add 8 eok", dyn_fifo_push(&fifo, 8, 5), EOK);
    207         TEST("add 9 eok", dyn_fifo_push(&fifo, 9, 5), EOK);
    208         TEST("add 10 eok", dyn_fifo_push(&fifo, 10, 6), EOK);
    209         TEST("add 11 eok", dyn_fifo_push(&fifo, 11, 6), EOK);
    210         TEST("pop 6", dyn_fifo_pop(&fifo), 6);
    211         TEST("pop 7", dyn_fifo_pop(&fifo), 7);
    212         TEST("add 12 eok", dyn_fifo_push(&fifo, 12, 6), EOK);
    213         TEST("add 13 eok", dyn_fifo_push(&fifo, 13, 6), EOK);
    214         TEST("add 14 enomem", dyn_fifo_push(&fifo, 14, 6), ENOMEM);
    215         TEST("add 14 eok", dyn_fifo_push(&fifo, 14, 8), EOK);
    216         TEST("pop 8", dyn_fifo_pop(&fifo), 8);
    217         TEST("pop 9", dyn_fifo_pop(&fifo), 9);
    218         TEST("pop 10", dyn_fifo_pop(&fifo), 10);
    219         TEST("pop 11", dyn_fifo_pop(&fifo), 11);
    220         TEST("pop 12", dyn_fifo_pop(&fifo), 12);
    221         TEST("pop 13", dyn_fifo_pop(&fifo), 13);
    222         TEST("pop 14", dyn_fifo_pop(&fifo), 14);
    223         TEST("destroy", dyn_fifo_destroy(&fifo), EOK);
    224         TEST("add 15 einval", dyn_fifo_push(&fifo, 1, 0), EINVAL);
    225         if(error){
    226                 return EINVAL;
    227         }
    228 
    229 #endif
    230 
    231 #if NET_SELF_TEST_GENERIC_CHAR_MAP
    232         int_char_map_t icm;
    233 
    234         x = (int *) malloc(sizeof(int));
    235         y = (int *) malloc(sizeof(int));
    236         z = (int *) malloc(sizeof(int));
    237         u = (int *) malloc(sizeof(int));
    238         v = (int *) malloc(sizeof(int));
    239         w = (int *) malloc(sizeof(int));
    240 
    241         icm.magic = 0;
    242         printf("\nGeneric char map test");
    243         TEST("add ucho z einval", int_char_map_add(&icm, "ucho", 0, z), EINVAL);
    244         TEST("initialize", int_char_map_initialize(&icm), EOK);
    245         printf("\n\texclude bla null");
    246         int_char_map_exclude(&icm, "bla", 0);
    247         TEST("find bla null", int_char_map_find(&icm, "bla", 0), NULL);
    248         TEST("add bla x eok", int_char_map_add(&icm, "bla", 0, x), EOK);
    249         TEST("find bla x", int_char_map_find(&icm, "bla", 0), x);
    250         TEST("add bla y eexists", int_char_map_add(&icm, "bla", 0, y), EEXISTS);
    251         printf("\n\texclude bla y");
    252         int_char_map_exclude(&icm, "bla", 0);
    253         printf("\n\texclude bla null");
    254         int_char_map_exclude(&icm, "bla", 0);
    255         TEST("add blabla v eok", int_char_map_add(&icm, "blabla", 0, v), EOK);
    256         TEST("find blabla v", int_char_map_find(&icm, "blabla", 0), v);
    257         TEST("add bla w eok", int_char_map_add(&icm, "bla", 0, w), EOK);
    258         TEST("find bla w", int_char_map_find(&icm, "bla", 0), w);
    259         printf("\n\texclude bla");
    260         int_char_map_exclude(&icm, "bla", 0);
    261         TEST("find bla null", int_char_map_find(&icm, "bla", 0), NULL);
    262         TEST("find blabla v", int_char_map_find(&icm, "blabla", 0), v);
    263         TEST("add auto u eok", int_char_map_add(&icm, "auto", 0, u), EOK);
    264         TEST("find auto u", int_char_map_find(&icm, "auto", 0), u);
    265         printf("\n\tdestroy");
    266         int_char_map_destroy(&icm);
    267         TEST("add ucho z einval", int_char_map_add(&icm, "ucho", 0, z), EINVAL);
    268         printf("\nOK");
    269 
    270         if(error){
    271                 return EINVAL;
    272         }
    273 
    274 #endif
    275 
    276 #if NET_SELF_TEST_GENERIC_FIELD
    277         int_field_t gf;
    278 
    279         x = (int *) malloc(sizeof(int));
    280         y = (int *) malloc(sizeof(int));
    281         z = (int *) malloc(sizeof(int));
    282         u = (int *) malloc(sizeof(int));
    283         v = (int *) malloc(sizeof(int));
    284         w = (int *) malloc(sizeof(int));
    285 
    286         gf.magic = 0;
    287         printf("\nGeneric field test");
    288         TEST("add x einval", int_field_add(&gf, x), EINVAL);
    289         TEST("count -1", int_field_count(&gf), -1);
    290         TEST("initialize", int_field_initialize(&gf), EOK);
    291         TEST("count 0", int_field_count(&gf), 0);
    292         TEST("get 1 null", int_field_get_index(&gf, 1), NULL);
    293         TEST("add x 0", int_field_add(&gf, x), 0);
    294         TEST("get 0 x", int_field_get_index(&gf, 0), x);
    295         int_field_exclude_index(&gf, 0);
    296         TEST("get 0 null", int_field_get_index(&gf, 0), NULL);
    297         TEST("add y 1", int_field_add(&gf, y), 1);
    298         TEST("get 1 y", int_field_get_index(&gf, 1), y);
    299         TEST("add z 2", int_field_add(&gf, z), 2);
    300         TEST("get 2 z", int_field_get_index(&gf, 2), z);
    301         TEST("get 1 y", int_field_get_index(&gf, 1), y);
    302         TEST("count 3", int_field_count(&gf), 3);
    303         TEST("add u 3", int_field_add(&gf, u), 3);
    304         TEST("get 3 u", int_field_get_index(&gf, 3), u);
    305         TEST("add v 4", int_field_add(&gf, v), 4);
    306         TEST("get 4 v", int_field_get_index(&gf, 4), v);
    307         TEST("add w 5", int_field_add(&gf, w), 5);
    308         TEST("get 5 w", int_field_get_index(&gf, 5), w);
    309         TEST("count 6", int_field_count(&gf), 6);
    310         int_field_exclude_index(&gf, 1);
    311         TEST("get 1 null", int_field_get_index(&gf, 1), NULL);
    312         TEST("get 3 u", int_field_get_index(&gf, 3), u);
    313         int_field_exclude_index(&gf, 7);
    314         TEST("get 3 u", int_field_get_index(&gf, 3), u);
    315         TEST("get 5 w", int_field_get_index(&gf, 5), w);
    316         int_field_exclude_index(&gf, 4);
    317         TEST("get 4 null", int_field_get_index(&gf, 4), NULL);
    318         printf("\n\tdestroy");
    319         int_field_destroy(&gf);
    320         TEST("count -1", int_field_count(&gf), -1);
    321         printf("\nOK");
    322 
    323         if(error){
    324                 return EINVAL;
    325         }
    326 
    327 #endif
    328 
    329162#if NET_SELF_TEST_INT_MAP
    330163        int_map_t im;
     
    383216#endif
    384217
    385 #if NET_SELF_TEST_MEASURED_STRINGS
    386         measured_string_ref string;
    387 
    388         printf("\nMeasured strings test");
    389         string = measured_string_create_bulk("I am a measured string!", 0);
    390         printf("\n%x, %s at %x of %d", string, string->value, string->value, string->length);
     218#if NET_SELF_TEST_GENERIC_FIELD
     219        int_field_t gf;
     220
     221        x = (int *) malloc(sizeof(int));
     222        y = (int *) malloc(sizeof(int));
     223        z = (int *) malloc(sizeof(int));
     224        u = (int *) malloc(sizeof(int));
     225        v = (int *) malloc(sizeof(int));
     226        w = (int *) malloc(sizeof(int));
     227
     228        gf.magic = 0;
     229        printf("\nGeneric field test");
     230        TEST("add x einval", int_field_add(&gf, x), EINVAL);
     231        TEST("count -1", int_field_count(&gf), -1);
     232        TEST("initialize", int_field_initialize(&gf), EOK);
     233        TEST("count 0", int_field_count(&gf), 0);
     234        TEST("get 1 null", int_field_get_index(&gf, 1), NULL);
     235        TEST("add x 0", int_field_add(&gf, x), 0);
     236        TEST("get 0 x", int_field_get_index(&gf, 0), x);
     237        int_field_exclude_index(&gf, 0);
     238        TEST("get 0 null", int_field_get_index(&gf, 0), NULL);
     239        TEST("add y 1", int_field_add(&gf, y), 1);
     240        TEST("get 1 y", int_field_get_index(&gf, 1), y);
     241        TEST("add z 2", int_field_add(&gf, z), 2);
     242        TEST("get 2 z", int_field_get_index(&gf, 2), z);
     243        TEST("get 1 y", int_field_get_index(&gf, 1), y);
     244        TEST("count 3", int_field_count(&gf), 3);
     245        TEST("add u 3", int_field_add(&gf, u), 3);
     246        TEST("get 3 u", int_field_get_index(&gf, 3), u);
     247        TEST("add v 4", int_field_add(&gf, v), 4);
     248        TEST("get 4 v", int_field_get_index(&gf, 4), v);
     249        TEST("add w 5", int_field_add(&gf, w), 5);
     250        TEST("get 5 w", int_field_get_index(&gf, 5), w);
     251        TEST("count 6", int_field_count(&gf), 6);
     252        int_field_exclude_index(&gf, 1);
     253        TEST("get 1 null", int_field_get_index(&gf, 1), NULL);
     254        TEST("get 3 u", int_field_get_index(&gf, 3), u);
     255        int_field_exclude_index(&gf, 7);
     256        TEST("get 3 u", int_field_get_index(&gf, 3), u);
     257        TEST("get 5 w", int_field_get_index(&gf, 5), w);
     258        int_field_exclude_index(&gf, 4);
     259        TEST("get 4 null", int_field_get_index(&gf, 4), NULL);
     260        printf("\n\tdestroy");
     261        int_field_destroy(&gf);
     262        TEST("count -1", int_field_count(&gf), -1);
    391263        printf("\nOK");
     264
     265        if(error){
     266                return EINVAL;
     267        }
     268
     269#endif
     270
     271#if NET_SELF_TEST_GENERIC_CHAR_MAP
     272        int_char_map_t icm;
     273
     274        x = (int *) malloc(sizeof(int));
     275        y = (int *) malloc(sizeof(int));
     276        z = (int *) malloc(sizeof(int));
     277        u = (int *) malloc(sizeof(int));
     278        v = (int *) malloc(sizeof(int));
     279        w = (int *) malloc(sizeof(int));
     280
     281        icm.magic = 0;
     282        printf("\nGeneric char map test");
     283        TEST("add ucho z einval", int_char_map_add(&icm, "ucho", 0, z), EINVAL);
     284        TEST("initialize", int_char_map_initialize(&icm), EOK);
     285        printf("\n\texclude bla null");
     286        int_char_map_exclude(&icm, "bla", 0);
     287        TEST("find bla null", int_char_map_find(&icm, "bla", 0), NULL);
     288        TEST("add bla x eok", int_char_map_add(&icm, "bla", 0, x), EOK);
     289        TEST("find bla x", int_char_map_find(&icm, "bla", 0), x);
     290        TEST("add bla y eexists", int_char_map_add(&icm, "bla", 0, y), EEXISTS);
     291        printf("\n\texclude bla y");
     292        int_char_map_exclude(&icm, "bla", 0);
     293        printf("\n\texclude bla null");
     294        int_char_map_exclude(&icm, "bla", 0);
     295        TEST("add blabla v eok", int_char_map_add(&icm, "blabla", 0, v), EOK);
     296        TEST("find blabla v", int_char_map_find(&icm, "blabla", 0), v);
     297        TEST("add bla w eok", int_char_map_add(&icm, "bla", 0, w), EOK);
     298        TEST("find bla w", int_char_map_find(&icm, "bla", 0), w);
     299        printf("\n\texclude bla");
     300        int_char_map_exclude(&icm, "bla", 0);
     301        TEST("find bla null", int_char_map_find(&icm, "bla", 0), NULL);
     302        TEST("find blabla v", int_char_map_find(&icm, "blabla", 0), v);
     303        TEST("add auto u eok", int_char_map_add(&icm, "auto", 0, u), EOK);
     304        TEST("find auto u", int_char_map_find(&icm, "auto", 0), u);
     305        printf("\n\tdestroy");
     306        int_char_map_destroy(&icm);
     307        TEST("add ucho z einval", int_char_map_add(&icm, "ucho", 0, z), EINVAL);
     308        printf("\nOK");
     309
     310        if(error){
     311                return EINVAL;
     312        }
     313
     314#endif
     315
     316#if NET_SELF_TEST_CRC
     317        uint32_t value;
     318
     319        printf("\nCRC computation test");
     320        value = ~ compute_crc32(~ 0, "123456789", 8 * 9);
     321        TEST("123456789", value, 0xCBF43926);
     322        printf("\t=> %X", value);
     323        value = ~ compute_crc32(~ 0, "1", 8);
     324        TEST("1", value, 0x83DCEFB7);
     325        printf("\t=> %X", value);
     326        value = ~ compute_crc32(~ 0, "12", 8 * 2);
     327        TEST("12", value, 0x4F5344CD);
     328        printf("\t=> %X", value);
     329        value = ~ compute_crc32(~ 0, "123", 8 * 3);
     330        TEST("123", value, 0x884863D2);
     331        printf("\t=> %X", value);
     332        value = ~ compute_crc32(~ 0, "1234", 8 * 4);
     333        TEST("1234", value, 0x9BE3E0A3);
     334        printf("\t=> %X", value);
     335        value = ~ compute_crc32(~ 0, "12345678", 8 * 8);
     336        TEST("12345678", value, 0x9AE0DAAF);
     337        printf("\t=> %X", value);
     338        value = ~ compute_crc32(~ 0, "ahoj pane", 8 * 9);
     339        TEST("ahoj pane", value, 0x5FC3D706);
     340        printf("\t=> %X", value);
     341
     342        if(error){
     343                return EINVAL;
     344        }
     345
     346#endif
     347
     348#if NET_SELF_TEST_DYNAMIC_FIFO
     349        dyn_fifo_t fifo;
     350
     351        printf("\nDynamic fifo test");
     352        TEST("add 1 einval", dyn_fifo_push(&fifo, 1, 0), EINVAL);
     353        TEST("initialize", dyn_fifo_initialize(&fifo, 1), EOK);
     354        TEST("add 1 eok", dyn_fifo_push(&fifo, 1, 0), EOK);
     355        TEST("pop 1", dyn_fifo_pop(&fifo), 1);
     356        TEST("pop enoent", dyn_fifo_pop(&fifo), ENOENT);
     357        TEST("add 2 eok", dyn_fifo_push(&fifo, 2, 1), EOK);
     358        TEST("add 3 enomem", dyn_fifo_push(&fifo, 3, 1), ENOMEM);
     359        TEST("add 3 eok", dyn_fifo_push(&fifo, 3, 0), EOK);
     360        TEST("pop 2", dyn_fifo_pop(&fifo), 2);
     361        TEST("pop 3", dyn_fifo_pop(&fifo), 3);
     362        TEST("add 4 eok", dyn_fifo_push(&fifo, 4, 2), EOK);
     363        TEST("add 5 eok", dyn_fifo_push(&fifo, 5, 2), EOK);
     364        TEST("add 6 enomem", dyn_fifo_push(&fifo, 6, 2), ENOMEM);
     365        TEST("add 6 eok", dyn_fifo_push(&fifo, 6, 5), EOK);
     366        TEST("add 7 eok", dyn_fifo_push(&fifo, 7, 5), EOK);
     367        TEST("pop 4", dyn_fifo_pop(&fifo), 4);
     368        TEST("pop 5", dyn_fifo_pop(&fifo), 5);
     369        TEST("add 8 eok", dyn_fifo_push(&fifo, 8, 5), EOK);
     370        TEST("add 9 eok", dyn_fifo_push(&fifo, 9, 5), EOK);
     371        TEST("add 10 eok", dyn_fifo_push(&fifo, 10, 6), EOK);
     372        TEST("add 11 eok", dyn_fifo_push(&fifo, 11, 6), EOK);
     373        TEST("pop 6", dyn_fifo_pop(&fifo), 6);
     374        TEST("pop 7", dyn_fifo_pop(&fifo), 7);
     375        TEST("add 12 eok", dyn_fifo_push(&fifo, 12, 6), EOK);
     376        TEST("add 13 eok", dyn_fifo_push(&fifo, 13, 6), EOK);
     377        TEST("add 14 enomem", dyn_fifo_push(&fifo, 14, 6), ENOMEM);
     378        TEST("add 14 eok", dyn_fifo_push(&fifo, 14, 8), EOK);
     379        TEST("pop 8", dyn_fifo_pop(&fifo), 8);
     380        TEST("pop 9", dyn_fifo_pop(&fifo), 9);
     381        TEST("pop 10", dyn_fifo_pop(&fifo), 10);
     382        TEST("pop 11", dyn_fifo_pop(&fifo), 11);
     383        TEST("pop 12", dyn_fifo_pop(&fifo), 12);
     384        TEST("pop 13", dyn_fifo_pop(&fifo), 13);
     385        TEST("pop 14", dyn_fifo_pop(&fifo), 14);
     386        TEST("destroy", dyn_fifo_destroy(&fifo), EOK);
     387        TEST("add 15 einval", dyn_fifo_push(&fifo, 1, 0), EINVAL);
     388        if(error){
     389                return EINVAL;
     390        }
     391
    392392#endif
    393393
  • uspace/srv/net/tl/icmp/icmp.c

    r60ab6c3 r71b00dcc  
    4141#include <fibril_synch.h>
    4242#include <stdint.h>
    43 #include <string.h>
    4443
    4544#include <ipc/ipc.h>
  • uspace/srv/net/tl/icmp/icmp_client.c

    r60ab6c3 r71b00dcc  
    3737
    3838#include <errno.h>
    39 
    40 #ifdef CONFIG_DEBUG
    41         #include <stdio.h>
    42 #endif
     39//#include <stdio.h>
    4340
    4441#include <sys/types.h>
     
    7370        }
    7471        // remove debug dump
    75 #ifdef CONFIG_DEBUG
    76         printf("ICMP error %d (%d) in packet %d\n", header->type, header->code, packet_get_id(packet));
    77 #endif
     72//      printf("ICMP error %d (%d) in packet %d\n", header->type, header->code, packet_get_id(packet));
    7873        return sizeof(icmp_header_t);
    7974}
  • uspace/srv/net/tl/tcp/tcp.c

    r60ab6c3 r71b00dcc  
    12411241        }
    12421242
    1243         // release the application phone
    1244         ipc_hangup(app_phone);
    1245 
    12461243        printf("release\n");
    12471244        // release all local sockets
     
    12801277                                        // TODO release as connection lost
    12811278                                        //tcp_refresh_socket_data(socket_data);
    1282                                         fibril_rwlock_write_unlock(socket_data->local_lock);
    12831279                                }else{
    12841280                                        // retransmit
    1285 //                                      tcp_retransmit_packet(socket, socket_data, timeout->sequence_number);
    1286                                         fibril_rwlock_write_unlock(socket_data->local_lock);
    1287                                 }
     1281                                        tcp_retransmit_packet(socket, socket_data, timeout->sequence_number);
     1282                                }
     1283                                fibril_rwlock_write_unlock(socket_data->local_lock);
    12881284                        }else{
    12891285                                fibril_mutex_lock(&socket_data->operation.mutex);
  • uspace/srv/net/tl/udp/udp.c

    r60ab6c3 r71b00dcc  
    508508        }
    509509
    510         // release the application phone
    511         ipc_hangup(app_phone);
    512 
    513510        // release all local sockets
    514511        socket_cores_release(udp_globals.net_phone, &local_sockets, &udp_globals.sockets, NULL);
Note: See TracChangeset for help on using the changeset viewer.