Changes in / [60ab6c3:71b00dcc] in mainline
- Location:
- uspace/srv/net
- Files:
-
- 2 deleted
- 46 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/Doxyfile
r60ab6c3 r71b00dcc 6 6 DOXYFILE_ENCODING = UTF-8 7 7 PROJECT_NAME = "Networking and TCP/IP stack for HelenOS system" 8 PROJECT_NUMBER = " "8 PROJECT_NUMBER = "Master thesis 2009" 9 9 OUTPUT_DIRECTORY = doc/ 10 10 CREATE_SUBDIRS = YES -
uspace/srv/net/Makefile
r60ab6c3 r71b00dcc 29 29 include ../../../Makefile.config 30 30 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 += \ 31 DIRS = \ 41 32 netif/lo \ 42 33 nil/eth \ … … 56 47 tl/udp \ 57 48 tl/tcp \ 49 50 ifeq ($(CONFIG_NETIF_DP8390),y) 51 DIRS += netif/dp8390 52 endif 58 53 59 54 DIRS_ALL = $(DIRS) $(DIRS_MODULAR) -
uspace/srv/net/app/echo/echo.c
r60ab6c3 r71b00dcc 55 55 #define NAME "Echo" 56 56 57 /** Prints the application help.58 */59 void echo_print_help(void);60 61 57 /** Module entry point. 62 58 * Reads command line parameters and starts listenning. … … 66 62 */ 67 63 int main(int argc, char * argv[]); 64 65 /** Prints the application help. 66 */ 67 void 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 */ 74 int 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 */ 81 int echo_parse_socket_type(const char * name); 68 82 69 83 void echo_print_help(void){ … … 101 115 } 102 116 117 int 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 126 int 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 103 135 int main(int argc, char * argv[]){ 104 136 ERROR_DECLARE; … … 106 138 size_t size = 1024; 107 139 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; 110 142 int count = -1; 111 143 int family = PF_INET; 112 uint16_t port = 7;144 uint16_t port = 7; 113 145 int backlog = 3; 114 146 115 socklen_t max_length 147 socklen_t max_length = sizeof(struct sockaddr_in6); 116 148 uint8_t address_data[max_length]; 117 struct sockaddr * address 149 struct sockaddr * address = (struct sockaddr *) address_data; 118 150 struct sockaddr_in * address_in = (struct sockaddr_in *) address; 119 151 struct sockaddr_in6 * address_in6 = (struct sockaddr_in6 *) address; … … 123 155 int socket_id; 124 156 int listening_id; 125 char * data;157 char * data; 126 158 size_t length; 127 159 int index; … … 129 161 int value; 130 162 131 // print the program label132 163 printf("Task %d - ", task_get_id()); 133 164 printf("%s\n", NAME); 134 165 135 // parse the command line arguments136 166 for(index = 1; index < argc; ++ index){ 137 167 if(argv[index][0] == '-'){ … … 144 174 break; 145 175 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)); 147 177 break; 148 178 case 'h': … … 162 192 break; 163 193 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)); 165 195 type = (sock_type_t) value; 166 196 break; … … 168 198 verbose = 1; 169 199 break; 170 // long options with the double minus sign ('-')171 200 case '-': 172 201 if(str_lcmp(argv[index] + 2, "backlog=", 6) == 0){ … … 175 204 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "message count", 8)); 176 205 }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)); 178 207 }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){ 179 208 echo_print_help(); … … 188 217 size = (value >= 0) ? (size_t) value : 0; 189 218 }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)); 191 220 type = (sock_type_t) value; 192 221 }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){ … … 210 239 } 211 240 212 // check the buffer size213 241 if(size <= 0){ 214 242 fprintf(stderr, "Receive size too small (%d). Using 1024 bytes instead.\n", size); 215 243 size = 1024; 216 244 } 217 // size plus t he terminating null (\0)245 // size plus terminating null (\0) 218 246 data = (char *) malloc(size + 1); 219 247 if(! data){ … … 222 250 } 223 251 224 // set the reply size if set225 252 reply_length = reply ? str_length(reply) : 0; 226 253 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 228 260 bzero(address_data, max_length); 229 261 switch(family){ … … 243 275 } 244 276 245 // get a listening socket246 277 listening_id = socket(family, type, 0); 247 278 if(listening_id < 0){ … … 250 281 } 251 282 252 // if the stream socket is used253 283 if(type == SOCK_STREAM){ 254 // check the backlog255 284 if(backlog <= 0){ 256 285 fprintf(stderr, "Accepted sockets queue size too small (%d). Using 3 instead.\n", size); 257 286 backlog = 3; 258 287 } 259 // set the backlog260 288 if(ERROR_OCCURRED(listen(listening_id, backlog))){ 261 289 socket_print_error(stderr, ERROR_CODE, "Socket listen: ", "\n"); … … 264 292 } 265 293 266 // bind the listenning socket267 294 if(ERROR_OCCURRED(bind(listening_id, address, addrlen))){ 268 295 socket_print_error(stderr, ERROR_CODE, "Socket bind: ", "\n"); … … 276 303 socket_id = listening_id; 277 304 278 // do count times279 // or indefinitely if set to a negative value280 305 while(count){ 281 282 306 addrlen = max_length; 283 307 if(type == SOCK_STREAM){ 284 // acceept a socket if the stream socket is used285 308 socket_id = accept(listening_id, address, &addrlen); 286 309 if(socket_id <= 0){ … … 292 315 } 293 316 } 294 295 // if the datagram socket is used or the stream socked was accepted296 317 if(socket_id > 0){ 297 298 // receive an echo request299 318 value = recvfrom(socket_id, data, size, 0, address, &addrlen); 300 319 if(value < 0){ … … 303 322 length = (size_t) value; 304 323 if(verbose){ 305 // print the header306 307 // get the source port and prepare the address buffer308 324 address_start = NULL; 309 325 switch(address->sa_family){ … … 319 335 fprintf(stderr, "Address family %d (0x%X) is not supported.\n", address->sa_family); 320 336 } 321 // parse the source address322 337 if(address_start){ 323 338 if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){ … … 329 344 } 330 345 } 331 332 // answer the request either with the static reply or the original data333 346 if(ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen))){ 334 347 socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n"); 335 348 } 336 337 } 338 339 // close the accepted stream socket 349 } 340 350 if(type == SOCK_STREAM){ 341 351 if(ERROR_OCCURRED(closesocket(socket_id))){ … … 343 353 } 344 354 } 345 346 } 347 348 // decrease the count if positive 355 } 349 356 if(count > 0){ 350 357 -- count; … … 359 366 } 360 367 361 // close the listenning socket362 368 if(ERROR_OCCURRED(closesocket(listening_id))){ 363 369 socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n"); -
uspace/srv/net/app/nettest1/Makefile
r60ab6c3 r71b00dcc 40 40 SOURCES = \ 41 41 $(NAME).c \ 42 $(NET_BASE)app/nettest.c \43 42 $(NET_BASE)app/parse.c \ 44 43 $(NET_BASE)app/print_error.c -
uspace/srv/net/app/nettest1/nettest1.c
r60ab6c3 r71b00dcc 48 48 #include "../../err.h" 49 49 50 #include "../nettest.h"51 50 #include "../parse.h" 52 51 #include "../print_error.h" … … 70 69 /** Prints the application help. 71 70 */ 72 void nettest1_print_help(void); 71 void 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 */ 78 int 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 */ 85 int parse_socket_type(const char * name); 73 86 74 87 /** Refreshes the data. … … 77 90 * @param[in] size The data block size in bytes. 78 91 */ 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){ 92 void 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 */ 103 int 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 */ 112 int 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 */ 123 int 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 */ 137 int 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 */ 151 int 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 */ 167 int 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 */ 173 void print_mark(int index); 174 175 void print_help(void){ 384 176 printf( 385 177 "Network Networking test 1 aplication - sockets\n" \ … … 409 201 } 410 202 411 void nettest1_refresh_data(char * data, size_t size){ 203 int 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 212 int 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 221 void refresh_data(char * data, size_t size){ 412 222 size_t length; 413 223 … … 422 232 } 423 233 234 int 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 255 int 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 277 int 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 298 int 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 323 int 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 348 int 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 380 void print_mark(int index){ 381 if((index + 1) % 10){ 382 printf("*"); 383 }else{ 384 printf("|"); 385 } 386 fflush(stdout); 387 } 388 389 int 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 424 675 /** @} 425 676 */ -
uspace/srv/net/app/nettest2/Makefile
r60ab6c3 r71b00dcc 40 40 SOURCES = \ 41 41 $(NAME).c \ 42 $(NET_BASE)app/nettest.c \43 42 $(NET_BASE)app/parse.c \ 44 43 $(NET_BASE)app/print_error.c -
uspace/srv/net/app/nettest2/nettest2.c
r60ab6c3 r71b00dcc 48 48 #include "../../err.h" 49 49 50 #include "../nettest.h"51 50 #include "../parse.h" 52 51 #include "../print_error.h" … … 70 69 /** Prints the application help. 71 70 */ 72 void nettest2_print_help(void); 71 void 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 */ 78 int 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 */ 85 int parse_socket_type(const char * name); 73 86 74 87 /** Refreshes the data. … … 77 90 * @param[in] size The data block size in bytes. 78 91 */ 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){ 92 void 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 */ 103 int 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 */ 112 int 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 */ 123 int 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 */ 137 int 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 */ 151 int 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 */ 167 int 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 */ 173 void print_mark(int index); 174 175 void print_help(void){ 307 176 printf( 308 177 "Network Networking test 2 aplication - UDP transfer\n" \ … … 332 201 } 333 202 334 void nettest2_refresh_data(char * data, size_t size){ 203 int 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 212 int 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 221 void refresh_data(char * data, size_t size){ 335 222 size_t length; 336 223 … … 345 232 } 346 233 234 int 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 255 int 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 277 int 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 298 int 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 323 int 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 348 int 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 380 void print_mark(int index){ 381 if((index + 1) % 10){ 382 printf("*"); 383 }else{ 384 printf("|"); 385 } 386 fflush(stdout); 387 } 388 389 int 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 347 599 /** @} 348 600 */ -
uspace/srv/net/app/parse.c
r60ab6c3 r71b00dcc 38 38 #include <string.h> 39 39 40 #include "../include/socket.h"41 42 40 #include "../err.h" 43 41 44 42 #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 }54 43 55 44 int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset){ … … 72 61 } 73 62 63 int 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 74 76 int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value)){ 75 77 ERROR_DECLARE; … … 86 88 } 87 89 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 119 90 void 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); 121 92 } 122 93 -
uspace/srv/net/app/parse.h
r60ab6c3 r71b00dcc 38 38 #define __NET_APP_PARSE__ 39 39 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. 46 43 */ 47 int parse_address_family(const char * name);44 void print_unrecognized(int index, const char * parameter); 48 45 49 46 /** Parses the next parameter as an integral number. … … 61 58 */ 62 59 int 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 */ 74 int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset); 63 75 64 76 /** Parses the next named parameter as an integral number. … … 80 92 int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value)); 81 93 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 117 94 #endif 118 95 -
uspace/srv/net/app/ping/ping.c
r60ab6c3 r71b00dcc 39 39 #include <task.h> 40 40 #include <time.h> 41 #include <ipc/ipc.h>42 41 #include <ipc/services.h> 43 42 … … 68 67 /** Prints the application help. 69 68 */ 70 void ping_print_help(void); 69 void 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 */ 76 int parse_address_family(const char * name); 77 78 void 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 113 int 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 } 71 121 72 122 int main(int argc, char * argv[]){ … … 76 126 int verbose = 0; 77 127 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; 80 130 int count = 3; 81 suseconds_t timeout = 3000;131 suseconds_t timeout = 3000; 82 132 int family = AF_INET; 83 133 84 socklen_t max_length 134 socklen_t max_length = sizeof(struct sockaddr_in6); 85 135 uint8_t address_data[max_length]; 86 struct sockaddr * address 136 struct sockaddr * address = (struct sockaddr *) address_data; 87 137 struct sockaddr_in * address_in = (struct sockaddr_in *) address; 88 138 struct sockaddr_in6 * address_in6 = (struct sockaddr_in6 *) address; … … 97 147 int index; 98 148 99 // print the program label100 149 printf("Task %d - ", task_get_id()); 101 150 printf("%s\n", NAME); 102 151 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){ 107 158 if(argv[index][0] == '-'){ 108 159 switch(argv[index][1]){ 109 // short options with only one letter110 160 case 'c': 111 161 ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "count", 0)); … … 115 165 break; 116 166 case 'h': 117 p ing_print_help();167 print_help(); 118 168 return EOK; 119 169 break; … … 129 179 verbose = 1; 130 180 break; 131 // long options with the double minus sign ('-')132 181 case '-': 133 182 if(str_lcmp(argv[index] + 2, "count=", 6) == 0){ … … 138 187 ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "address family", 9, parse_address_family)); 139 188 }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){ 140 p ing_print_help();189 print_help(); 141 190 return EOK; 142 191 }else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){ … … 156 205 }else{ 157 206 print_unrecognized(index, argv[index] + 2); 158 p ing_print_help();207 print_help(); 159 208 return EINVAL; 160 209 } … … 162 211 default: 163 212 print_unrecognized(index, argv[index] + 1); 164 p ing_print_help();213 print_help(); 165 214 return EINVAL; 166 215 } 167 216 }else{ 168 217 print_unrecognized(index, argv[index]); 169 p ing_print_help();218 print_help(); 170 219 return EINVAL; 171 220 } 172 221 } 173 222 174 // if not before the last argument containing the address175 if(index >= argc){176 printf("Command line error: missing address\n");177 ping_print_help();178 return EINVAL;179 }180 181 // prepare the address buffer182 223 bzero(address_data, max_length); 183 224 switch(family){ … … 197 238 } 198 239 199 // parse the last argument which should contain the address200 240 if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){ 201 241 fprintf(stderr, "Address parse error %d\n", ERROR_CODE); … … 203 243 } 204 244 205 // connect to the ICMP module206 245 icmp_phone = icmp_connect_module(SERVICE_ICMP, ICMP_CONNECT_TIMEOUT); 207 246 if(icmp_phone < 0){ … … 210 249 } 211 250 212 // print the ping header213 251 printf("PING %d bytes of data\n", size); 214 252 if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){ … … 218 256 } 219 257 220 // do count times221 258 while(count > 0){ 222 223 // get the starting time224 259 if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){ 225 260 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE); 226 // release the ICMP phone227 ipc_hangup(icmp_phone);228 261 return ERROR_CODE; 229 262 } 230 231 // request the ping232 263 result = icmp_echo_msg(icmp_phone, size, timeout, ttl, tos, dont_fragment, address, addrlen); 233 234 // get the ending time235 264 if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){ 236 265 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE); 237 // release the ICMP phone238 ipc_hangup(icmp_phone);239 266 return ERROR_CODE; 240 267 } 241 242 // print the result243 268 switch(result){ 244 269 case ICMP_ECHO: … … 258 283 } 259 284 260 // release the ICMP phone261 ipc_hangup(icmp_phone);262 263 285 return EOK; 264 286 } 265 287 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 301 288 /** @} 302 289 */ -
uspace/srv/net/app/print_error.c
r60ab6c3 r71b00dcc 41 41 42 42 #include "print_error.h" 43 44 void 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 } 43 51 44 52 void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){ … … 93 101 } 94 102 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 103 103 void socket_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){ 104 104 if(output){ -
uspace/srv/net/app/print_error.h
r60ab6c3 r71b00dcc 50 50 #define IS_SOCKET_ERROR(error_code) ((error_code) < 0) 51 51 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 60 52 /** Prints the error description. 61 53 * Supports ICMP and socket error codes. … … 66 58 */ 67 59 void 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 */ 67 void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix); 68 68 69 69 /** Prints the specific socket error description. -
uspace/srv/net/cfg/modular/general
r60ab6c3 r71b00dcc 3 3 IPV=4 4 4 IP_ROUTING=no 5 6 5 MTU=1500 7 8 6 ICMP_ERROR_REPORTING=yes 9 7 ICMP_ECHO_REPLYING=yes 10 11 8 UDP_CHECKSUM_COMPUTING=yes 12 9 UDP_AUTOBINDING=yes -
uspace/srv/net/cfg/module/general
r60ab6c3 r71b00dcc 3 3 IPV=4 4 4 IP_ROUTING=no 5 6 5 MTU=1500 7 8 6 ICMP_ERROR_REPORTING=yes 9 7 ICMP_ECHO_REPLYING=yes 10 11 8 UDP_CHECKSUM_COMPUTING=yes 12 9 UDP_AUTOBINDING=yes -
uspace/srv/net/checksum.c
r60ab6c3 r71b00dcc 47 47 #define CRC_DIVIDER_LE 0xEDB88320 48 48 49 uint16_t compact_checksum(uint32_t sum){ 50 // shorten to the 16 bits 51 while(sum >> 16){ 52 sum = (sum &0xFFFF) + (sum >> 16); 49 uint32_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; 53 63 } 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 } 54 77 55 return (uint16_t) sum; 78 uint32_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; 56 105 } 57 106 … … 72 121 } 73 122 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; 123 uint16_t compact_checksum(uint32_t sum){ 124 // shorten to the 16 bits 125 while(sum >> 16){ 126 sum = (sum &0xFFFF) + (sum >> 16); 95 127 } 96 128 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; 157 130 } 158 131 … … 164 137 165 138 uint16_t ip_checksum(uint8_t * data, size_t length){ 166 // compute, compact and flip the data checksum167 139 return flip_checksum(compact_checksum(compute_checksum(0, data, length))); 168 140 } -
uspace/srv/net/configuration.h
r60ab6c3 r71b00dcc 46 46 /*@{*/ 47 47 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 48 54 /** Activates the char map self test. 49 55 * The NET_SELF_TEST has to be activated. … … 52 58 #define NET_SELF_TEST_CHAR_MAP 1 53 59 54 /** Activates the CRC computationself test.60 /** Activates the integral map self test. 55 61 * The NET_SELF_TEST has to be activated. 56 * @see crc.h62 * @see int_map.h 57 63 */ 58 #define NET_SELF_TEST_ CRC164 #define NET_SELF_TEST_INT_MAP 1 59 65 60 /** Activates the dynamic fifoself test.66 /** Activates the generic field self test. 61 67 * The NET_SELF_TEST has to be activated. 62 * @see dynamic_fifo.h68 * @see generic_field.h 63 69 */ 64 #define NET_SELF_TEST_ DYNAMIC_FIFO170 #define NET_SELF_TEST_GENERIC_FIELD 1 65 71 66 72 /** Activates the generic char map self test. … … 70 76 #define NET_SELF_TEST_GENERIC_CHAR_MAP 1 71 77 72 /** Activates the generic fieldself test.78 /** Activates the CRC computation self test. 73 79 * The NET_SELF_TEST has to be activated. 74 * @see generic_field.h80 * @see crc.h 75 81 */ 76 #define NET_SELF_TEST_ GENERIC_FIELD182 #define NET_SELF_TEST_CRC 1 77 83 78 /** Activates the integral mapself test.84 /** Activates the dynamic fifo self test. 79 85 * The NET_SELF_TEST has to be activated. 80 * @see int_map.h86 * @see dynamic_fifo.h 81 87 */ 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 89 89 90 90 /*@}*/ -
uspace/srv/net/err.h
r60ab6c3 r71b00dcc 62 62 #ifdef CONFIG_DEBUG 63 63 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;})) 67 65 68 66 #else -
uspace/srv/net/il/arp/arp.c
r60ab6c3 r71b00dcc 73 73 arp_globals_t arp_globals; 74 74 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 80 75 /** Creates new protocol specific data. 81 76 * Allocates and returns the needed memory block as the proto parameter. … … 87 82 */ 88 83 int 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 */ 88 void arp_clear_device(arp_device_ref device); 89 89 90 90 /** @name Message processing functions … … 105 105 int arp_device_message(device_id_t device_id, services_t service, services_t protocol, measured_string_ref address); 106 106 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. 108 109 * @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 request. 116 * @returns NULL if the hardware address is not found in the cache. 117 */ 118 measured_string_ref arp_translate_message(device_id_t device_id, services_t protocol, measured_string_ref target); 114 119 115 120 /** Processes the received ARP packet. … … 128 133 int arp_receive_message(device_id_t device_id, packet_t packet); 129 134 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. 132 136 * @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 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 */ 141 int arp_mtu_changed_message(device_id_t device_id, size_t mtu); 142 142 143 143 /*@}*/ … … 148 148 149 149 GENERIC_CHAR_MAP_IMPLEMENT(arp_addr, measured_string_t) 150 151 task_id_t arp_task_get_id(void){ 152 return task_get_id(); 153 } 154 155 int 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 170 int 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 } 150 189 151 190 int arp_clean_cache_req(int arp_phone){ … … 172 211 } 173 212 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 213 int 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 227 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){ 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 247 int arp_initialize(async_client_conn_t client_connection){ 248 ERROR_DECLARE; 249 250 fibril_rwlock_initialize(&arp_globals.lock); 178 251 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)); 190 254 fibril_rwlock_write_unlock(&arp_globals.lock); 191 255 return EOK; 192 256 } 193 257 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; 258 int 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; 231 271 } 232 272 return EOK; … … 343 383 } 344 384 345 int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){ 385 measured_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 443 int arp_receive_message(device_id_t device_id, packet_t packet){ 346 444 ERROR_DECLARE; 347 445 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 512 void 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 531 int arp_connect_module(services_t service){ 532 if(service != SERVICE_ARP){ 533 return EINVAL; 534 } 535 return EOK; 536 } 537 538 int arp_mtu_changed_message(device_id_t device_id, size_t mtu){ 539 arp_device_ref device; 540 363 541 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); 366 549 fibril_rwlock_write_unlock(&arp_globals.lock); 367 550 return EOK; … … 435 618 } 436 619 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) * 2566 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 620 620 /** @} 621 621 */ -
uspace/srv/net/il/arp/arp.h
r60ab6c3 r71b00dcc 51 51 52 52 53 /** Type definition of the ARP global data. 54 * @see arp_globals 55 */ 56 typedef struct arp_globals arp_globals_t; 57 53 58 /** Type definition of the ARP device specific data. 54 59 * @see arp_device … … 61 66 typedef arp_device_t * arp_device_ref; 62 67 63 /** Type definition of the ARP global data.64 * @see arp_globals65 */66 typedef struct arp_globals arp_globals_t;67 68 68 /** Type definition of the ARP protocol specific data. 69 69 * @see arp_proto … … 75 75 */ 76 76 typedef arp_proto_t * arp_proto_ref; 77 78 /** ARP address map.79 * Translates addresses.80 * @see generic_char_map.h81 */82 GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t)83 77 84 78 /** ARP address cache. … … 94 88 INT_MAP_DECLARE(arp_protos, arp_proto_t) 95 89 90 /** ARP address map. 91 * Translates addresses. 92 * @see generic_char_map.h 93 */ 94 GENERIC_CHAR_MAP_DECLARE(arp_addr, measured_string_t) 95 96 96 /** ARP device specific data. 97 97 */ 98 98 struct 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; 99 108 /** Actual device hardware address. 100 109 */ … … 109 118 */ 110 119 char * broadcast_data; 111 /** Device identifier.120 /** Device module service. 112 121 */ 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; 120 123 /** Device module phone. 121 124 */ … … 125 128 */ 126 129 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;148 130 }; 149 131 … … 151 133 */ 152 134 struct arp_proto{ 135 /** Protocol service. 136 */ 137 services_t service; 153 138 /** Actual device protocol address. 154 139 */ … … 160 145 */ 161 146 arp_addr_t addresses; 162 /** Protocol service. 147 }; 148 149 /** ARP global data. 150 */ 151 struct arp_globals{ 152 /** Networking module phone. 163 153 */ 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; 165 165 }; 166 166 -
uspace/srv/net/il/arp/arp_messages.h
r60ab6c3 r71b00dcc 46 46 */ 47 47 typedef enum{ 48 /** Clean cache message.49 * @see arp_ clean_cache()48 /** New device message. 49 * @see arp_device_req() 50 50 */ 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, 52 60 /** Clear address cache message. 53 61 * @see arp_clear_address_msg() 54 62 */ 55 63 NET_ARP_CLEAR_ADDRESS, 56 /** Clea r devicecache message.57 * @see arp_clea r_device_req()64 /** Clean cache message. 65 * @see arp_clean_cache() 58 66 */ 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, 68 68 } arp_messages; 69 69 -
uspace/srv/net/il/arp/arp_module.c
r60ab6c3 r71b00dcc 58 58 #define NAME "ARP protocol" 59 59 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 74 60 /** Prints the module name. 75 61 * @see NAME … … 86 72 int module_start(async_client_conn_t client_connection); 87 73 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 */ 82 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 83 84 /** ARP module global data. 85 */ 86 extern arp_globals_t arp_globals; 91 87 92 88 void module_print_name(void){ … … 114 110 } 115 111 112 int 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 116 116 /** @} 117 117 */ -
uspace/srv/net/il/arp/arp_oc.h
r60ab6c3 r71b00dcc 44 44 /** REQUEST operation code. 45 45 */ 46 #define ARPOP_REQUEST 46 #define ARPOP_REQUEST 1 47 47 48 48 /** REPLY operation code. 49 49 */ 50 #define ARPOP_REPLY 50 #define ARPOP_REPLY 2 51 51 52 52 /** Reverse request operation code. 53 53 */ 54 #define ARPOP_RREQUEST 54 #define ARPOP_RREQUEST 3 55 55 56 56 /** Reverse reply operation code. 57 57 */ 58 #define ARPOP_RREPLY 58 #define ARPOP_RREPLY 4 59 59 60 60 /** DRARP-Request operation code. 61 61 */ 62 #define ARPOP_DRARP_Request 62 #define ARPOP_DRARP_Request 5 63 63 64 64 /** DRARP-Reply operation code. 65 65 */ 66 #define ARPOP_DRARP_Reply 66 #define ARPOP_DRARP_Reply 6 67 67 68 68 /** DRARP-Error operation code. 69 69 */ 70 #define ARPOP_DRARP_Error 70 #define ARPOP_DRARP_Error 7 71 71 72 72 /** InARP-Request operation code. 73 73 */ 74 #define ARPOP_InREQUEST 74 #define ARPOP_InREQUEST 8 75 75 76 76 /** InARP-Reply operation code. 77 77 */ 78 #define ARPOP_InREPLY 78 #define ARPOP_InREPLY 9 79 79 80 80 /** ARP-NAK operation code. 81 81 */ 82 #define ARPOP_NAK 82 #define ARPOP_NAK 10 83 83 84 84 /** MARS-Request operation code. 85 85 */ 86 #define ARPOP_MARS_Request 86 #define ARPOP_MARS_Request 11 87 87 88 88 /** MARS-Multi operation code. 89 89 */ 90 #define ARPOP_MARS_Multi 90 #define ARPOP_MARS_Multi 12 91 91 92 92 /** MARS-MServ operation code. 93 93 */ 94 #define ARPOP_MARS_MServ 94 #define ARPOP_MARS_MServ 13 95 95 96 96 /** MARS-Join operation code. 97 97 */ 98 #define ARPOP_MARS_Join 98 #define ARPOP_MARS_Join 14 99 99 100 100 /** MARS-Leave operation code. 101 101 */ 102 #define ARPOP_MARS_Leave 102 #define ARPOP_MARS_Leave 15 103 103 104 104 /** MARS-NAK operation code. 105 105 */ 106 #define ARPOP_MARS_NAK 106 #define ARPOP_MARS_NAK 16 107 107 108 108 /** MARS-Unserv operation code. 109 109 */ 110 #define ARPOP_MARS_Unserv 110 #define ARPOP_MARS_Unserv 17 111 111 112 112 /** MARS-SJoin operation code. 113 113 */ 114 #define ARPOP_MARS_SJoin 114 #define ARPOP_MARS_SJoin 18 115 115 116 116 /** MARS-SLeave operation code. 117 117 */ 118 #define ARPOP_MARS_SLeave 118 #define ARPOP_MARS_SLeave 19 119 119 120 120 /** MARS-Grouplist-Request operation code. 121 121 */ 122 #define ARPOP_MARS_Grouplist_Request 20122 #define ARPOP_MARS_Grouplist_Request 20 123 123 124 124 /** MARS-Grouplist-Reply operation code. … … 128 128 /** MARS-Redirect-Map operation code. 129 129 */ 130 #define ARPOP_MARS_Redirect_Map 130 #define ARPOP_MARS_Redirect_Map 22 131 131 132 132 /** MAPOS-UNARP operation code. 133 133 */ 134 #define ARPOP_MAPOS_UNARP 134 #define ARPOP_MAPOS_UNARP 23 135 135 136 136 /*@}*/ -
uspace/srv/net/il/arp/arp_remote.c
r60ab6c3 r71b00dcc 52 52 #include "arp_messages.h" 53 53 54 int arp_connect_module(services_t service){ 55 if(service != SERVICE_ARP){ 56 return EINVAL; 57 } 58 return connect_to_service(SERVICE_ARP); 54 int 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; 59 62 } 60 63 61 int arp_clean_cache_req(int arp_phone){ 62 return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE); 64 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){ 65 return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data); 66 } 67 68 int 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); 63 70 } 64 71 … … 73 80 } 74 81 75 int arp_clea r_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);82 int arp_clean_cache_req(int arp_phone){ 83 return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE); 77 84 } 78 85 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; 86 int arp_connect_module(services_t service){ 87 if(service != SERVICE_ARP){ 88 return EINVAL; 89 } 90 return connect_to_service(SERVICE_ARP); 87 91 } 88 92 … … 91 95 } 92 96 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 97 97 /** @} 98 98 */ -
uspace/srv/net/il/il_messages.h
r60ab6c3 r71b00dcc 53 53 */ 54 54 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,63 55 /** Packet received message. 64 56 * @see il_received_msg() … … 68 60 * @see il_send_msg() 69 61 */ 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 71 71 } il_messages; 72 72 … … 83 83 * @param[in] call The message call structure. 84 84 */ 85 #define IL_GET_SERVICE(call) (services_t) IPC_GET_ARG2(*call)85 #define IL_GET_SERVICE(call) (services_t) IPC_GET_ARG2(*call) 86 86 87 87 /*@}*/ -
uspace/srv/net/il/ip/ip.h
r60ab6c3 r71b00dcc 106 106 */ 107 107 struct 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; 108 117 /** ARP module. 109 118 * Assigned if using ARP. 110 119 */ 111 120 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; 112 133 /** Broadcast address. 113 134 */ 114 135 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; 124 139 /** Packet dimension. 125 140 */ 126 141 packet_dimension_t packet_dimension; 127 /** Netif module phone. 142 }; 143 144 /** IP protocol specific data. 145 */ 146 struct ip_proto{ 147 /** Protocol number. 148 */ 149 int protocol; 150 /** Protocol module service. 151 */ 152 services_t service; 153 /** Protocol module phone. 128 154 */ 129 155 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;153 156 /** Protocol packet receiving function. 154 157 */ 155 158 tl_received_msg_t received_msg; 156 /** Protocol module service.157 */158 services_t service;159 159 }; 160 160 … … 165 165 */ 166 166 in_addr_t address; 167 /** Target network mask. 168 */ 169 in_addr_t netmask; 167 170 /** Gateway. 168 171 */ … … 171 174 */ 172 175 ip_netif_ref netif; 173 /** Target network mask.174 */175 in_addr_t netmask;176 176 }; 177 177 … … 179 179 */ 180 180 struct 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;193 181 /** Networking module phone. 194 182 */ … … 200 188 */ 201 189 fibril_rwlock_t netifs_lock; 202 /** Packet counter.203 */204 uint16_t packet_counter;205 190 /** Registered protocols. 206 191 */ … … 209 194 */ 210 195 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; 211 211 }; 212 212 -
uspace/srv/net/il/ip/ip_client.c
r60ab6c3 r71b00dcc 48 48 #include "ip_header.h" 49 49 50 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){ 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 78 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){ 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 50 106 size_t ip_client_header_length(packet_t packet){ 51 107 ip_header_ref header; … … 57 113 } 58 114 return IP_HEADER_LENGTH(header); 115 } 116 117 int 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 } 59 130 } 60 131 … … 69 140 return EINVAL; 70 141 } 71 72 142 switch(src->sa_family){ 73 143 case AF_INET: … … 101 171 } 102 172 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 set109 // multiple of 4 bytes110 padding = ipopt_length % 4;111 if(padding){112 padding = 4 - padding;113 ipopt_length += padding;114 }115 116 // prefix the header117 data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);118 if(! data){119 return ENOMEM;120 }121 122 // add the padding123 while(padding --){124 data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;125 }126 127 // set the header128 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 IPv6181 }else{182 return EINVAL;183 }184 }185 186 173 /** @} 187 174 */ -
uspace/srv/net/il/ip/ip_header.h
r60ab6c3 r71b00dcc 42 42 #include <sys/types.h> 43 43 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 44 74 /** Returns the fragment offest high bits. 45 75 * @param[in] length The prefixed data total length. … … 52 82 #define IP_COMPUTE_FRAGMENT_OFFSET_LOW(length) (((length) / 8u) &0xFF) 53 83 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 definitions85 */86 /*@{*/87 88 /** Fragment flag field shift.89 */90 #define IPFLAG_FRAGMENT_SHIFT 191 92 /** Fragmented flag field shift.93 */94 #define IPFLAG_FRAGMENTED_SHIFT 095 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 118 84 /** Type definition of the internet header. 119 85 * @see ip_header … … 125 91 */ 126 92 typedef ip_header_t * ip_header_ref; 127 128 /** Type definition of the internet option header.129 * @see ip_header130 */131 typedef struct ip_option ip_option_t;132 133 /** Type definition of the internet option header pointer.134 * @see ip_header135 */136 typedef ip_option_t * ip_option_ref;137 138 /** Type definition of the internet version 4 pseudo header.139 * @see ipv4_pseudo_header140 */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_header145 */146 typedef ipv4_pseudo_header_t * ipv4_pseudo_header_ref;147 93 148 94 /** Internet header. … … 225 171 } __attribute__ ((packed)); 226 172 173 /** Type definition of the internet option header. 174 * @see ip_header 175 */ 176 typedef struct ip_option ip_option_t; 177 178 /** Type definition of the internet option header pointer. 179 * @see ip_header 180 */ 181 typedef ip_option_t * ip_option_ref; 182 227 183 /** Internet option header. 228 184 * Only type field is always valid. … … 256 212 } __attribute__ ((packed)); 257 213 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 */ 251 typedef 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 */ 256 typedef ipv4_pseudo_header_t * ipv4_pseudo_header_ref; 257 258 258 /** Internet version 4 pseudo header. 259 259 */ -
uspace/srv/net/il/ip/ip_messages.h
r60ab6c3 r71b00dcc 51 51 */ 52 52 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() 55 55 */ 56 NET_IP_ GET_ROUTE,56 NET_IP_SET_GATEWAY, 57 57 /** Processes the received error notification. 58 58 * @see ip_received_error_msg() 59 59 */ 60 60 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() 63 63 */ 64 NET_IP_ SET_GATEWAY64 NET_IP_GET_ROUTE 65 65 } ip_messages; 66 66 … … 69 69 /*@{*/ 70 70 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 76 71 /** Returns the gateway message parameter. 77 72 * @param[in] call The message call structure. … … 79 74 #define IP_GET_GATEWAY(call) ({in_addr_t addr; addr.s_addr = IPC_GET_ARG2(*call); addr;}) 80 75 81 /** Sets the header length in the message answer.82 * @param[ out] answer The message answerstructure.76 /** Returns the address message parameter. 77 * @param[in] call The message call structure. 83 78 */ 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;}) 85 80 86 81 /** Returns the network mask message parameter. … … 94 89 #define IP_GET_PROTOCOL(call) ((ip_protocol_t) IPC_GET_ARG1(*call)) 95 90 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 96 96 /*@}*/ 97 97 -
uspace/srv/net/il/ip/ip_module.c
r60ab6c3 r71b00dcc 58 58 #define NAME "IP protocol" 59 59 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 74 60 /** Prints the module name. 75 61 * @see NAME … … 86 72 int module_start(async_client_conn_t client_connection); 87 73 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 */ 82 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 83 84 /** IP module global data. 85 */ 86 extern ip_globals_t ip_globals; 91 87 92 88 void module_print_name(void){ … … 114 110 } 115 111 112 int 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 116 116 /** @} 117 117 */ -
uspace/srv/net/il/ip/ip_remote.c
r60ab6c3 r71b00dcc 52 52 #include "ip_messages.h" 53 53 54 int 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 58 int 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 62 int ip_connect_module(services_t service){ 63 return connect_to_service(SERVICE_IP); 64 } 65 54 66 int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){ 55 67 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 70 int 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 74 int 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); 56 76 } 57 77 … … 60 80 } 61 81 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); 82 int 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); 68 84 } 69 85 … … 79 95 return EBADMEM; 80 96 } 81 82 97 *header = NULL; 83 98 message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, (ipcarg_t) protocol, &answer); … … 93 108 } 94 109 async_wait_for(message_id, &result); 95 96 110 if((result != EOK) && (*header)){ 97 111 free(*header); … … 102 116 } 103 117 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 120 118 /** @} 121 119 */ -
uspace/srv/net/inet.c
r60ab6c3 r71b00dcc 45 45 #include "include/socket_codes.h" 46 46 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 size55 if(length < INET_ADDRSTRLEN){56 return ENOMEM;57 }58 // fill the buffer with the IPv4 address59 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 size63 if(length < INET6_ADDRSTRLEN){64 return ENOMEM;65 }66 // fill the buffer with the IPv6 address67 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 74 47 int 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 85 48 const char * next; 86 49 char * last; 87 50 int index; 51 int count; 52 int base; 53 size_t bytes; 88 54 size_t shift; 89 55 unsigned long value; … … 92 58 return EINVAL; 93 59 } 94 95 // set the processing parameters96 60 switch(family){ 97 61 case AF_INET: … … 108 72 return ENOTSUP; 109 73 } 110 111 // erase if no address112 74 if(! address){ 113 75 bzero(data, count); 114 76 return ENOENT; 115 77 } 116 117 // process the string from the beginning118 78 next = address; 119 79 index = 0; 120 80 do{ 121 // if the actual character is set122 81 if(next && (*next)){ 123 124 // if not on the first character125 82 if(index){ 126 // move to the next character127 83 ++ next; 128 84 } 129 130 // parse the actual integral value131 85 value = strtoul(next, &last, base); 132 // remember the last problematic character133 // should be either '.' or ':' but is ignored to be more generic134 86 next = last; 135 136 // fill the address data byte by byte137 87 shift = bytes - 1; 138 88 do{ … … 141 91 value >>= 8; 142 92 }while(shift --); 143 144 93 index += bytes; 145 94 }else{ 146 // erase the rest of the address147 95 bzero(data + index, count - index); 148 96 return EOK; 149 97 } 150 98 }while(index < count); 99 return EOK; 100 } 151 101 152 return EOK; 102 int 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 } 153 122 } 154 123 -
uspace/srv/net/messages.h
r60ab6c3 r71b00dcc 48 48 #include "structures/packet/packet.h" 49 49 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 50 228 /** Returns a value indicating whether the value is in the interval. 51 229 * @param[in] item The value to be checked. … … 55 233 #define IS_IN_INTERVAL(item, first_inclusive, last_exclusive) (((item) >= (first_inclusive)) && ((item) < (last_exclusive))) 56 234 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 58 303 */ 59 304 /*@{*/ 60 305 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. 311 307 * @param[in] call The message call structure. 312 308 */ 313 309 #define IPC_GET_DEVICE(call) (device_id_t) IPC_GET_ARG1(*call) 314 310 315 /*@}*/ 316 317 /** @name Second arguments 318 */ 319 /*@{*/ 320 321 /** Returns the packet identifier message argument. 311 /** Returns the packet identifier message parameter. 322 312 * @param[in] call The message call structure. 323 313 */ 324 314 #define IPC_GET_PACKET(call) (packet_id_t) IPC_GET_ARG2(*call) 325 315 326 /** Returns the count message argument.316 /** Returns the count message parameter. 327 317 * @param[in] call The message call structure. 328 318 */ 329 319 #define IPC_GET_COUNT(call) (size_t) IPC_GET_ARG2(*call) 330 320 331 /** Returns the device state message argument.321 /** Returns the device state message parameter. 332 322 * @param[in] call The message call structure. 333 323 */ 334 324 #define IPC_GET_STATE(call) (device_state_t) IPC_GET_ARG2(*call) 335 325 336 /** Returns the maximum transmission unit message argument.326 /** Returns the maximum transmission unit message parameter. 337 327 * @param[in] call The message call structure. 338 328 */ 339 329 #define IPC_GET_MTU(call) (size_t) IPC_GET_ARG2(*call) 340 330 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. 348 332 * @param[in] call The message call structure. 349 333 */ 350 334 #define IPC_GET_SERVICE(call) (services_t) IPC_GET_ARG3(*call) 351 335 352 /** Returns the target service message argument.336 /** Returns the target service message parameter. 353 337 * @param[in] call The message call structure. 354 338 */ 355 339 #define IPC_GET_TARGET(call) (services_t) IPC_GET_ARG3(*call) 356 340 357 /** Returns the sender service message argument.341 /** Returns the sender service message parameter. 358 342 * @param[in] call The message call structure. 359 343 */ 360 344 #define IPC_GET_SENDER(call) (services_t) IPC_GET_ARG3(*call) 361 345 362 /*@}*/ 363 364 /** @name Fourth arguments 365 */ 366 /*@{*/ 367 368 /** Returns the error service message argument. 346 /** Returns the error service message parameter. 369 347 * @param[in] call The message call structure. 370 348 */ 371 349 #define IPC_GET_ERROR(call) (services_t) IPC_GET_ARG4(*call) 372 350 373 /*@}*/ 374 375 /** @name Fifth arguments 376 */ 377 /*@{*/ 378 379 /** Returns the phone message argument. 351 /** Returns the phone message parameter. 380 352 * @param[in] call The message call structure. 381 353 */ 382 354 #define IPC_GET_PHONE(call) (int) IPC_GET_ARG5(*call) 383 384 /*@}*/385 386 /** @name First answers387 */388 /*@{*/389 355 390 356 /** Sets the device identifier in the message answer. … … 398 364 #define IPC_SET_ADDR(answer) ((size_t *) &IPC_GET_ARG1(*answer)) 399 365 400 /*@}*/401 402 /** @name Second answers403 */404 /*@{*/405 406 366 /** Sets the minimum prefix size in the message answer. 407 367 * @param[out] answer The message answer structure. … … 409 369 #define IPC_SET_PREFIX(answer) ((size_t *) &IPC_GET_ARG2(*answer)) 410 370 411 /*@}*/412 413 /** @name Third answers414 */415 /*@{*/416 417 371 /** Sets the maximum content size in the message answer. 418 372 * @param[out] answer The message answer structure. … … 420 374 #define IPC_SET_CONTENT(answer) ((size_t *) &IPC_GET_ARG3(*answer)) 421 375 422 /*@}*/423 424 /** @name Fourth answers425 */426 /*@{*/427 428 376 /** Sets the minimum suffix size in the message answer. 429 377 * @param[out] answer The message answer structure. … … 432 380 433 381 /*@}*/ 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 }462 382 463 383 /** Returns the address. … … 479 399 return EBADMEM; 480 400 } 481 482 // request the address483 401 message_id = async_send_1(phone, (ipcarg_t) message, (ipcarg_t) device_id, NULL); 484 402 string = measured_strings_return(phone, address, data, 1); 485 403 async_wait_for(message_id, &result); 486 487 // if not successful488 404 if((string == EOK) && (result != EOK)){ 489 // clear the data490 405 free(*address); 491 406 free(*data); 492 407 } 493 408 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 */ 427 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){ 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 */ 458 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){ 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; 494 465 } 495 466 … … 521 492 } 522 493 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 */ 502 static 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 523 507 /** Passes the packet queue to the module. 524 508 * @param[in] phone The service module phone. … … 539 523 } 540 524 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. 573 532 * @returns Other error codes as defined for the specific service message. 574 533 */ 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; 534 static 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); 601 536 } 602 537 -
uspace/srv/net/module.c
r60ab6c3 r71b00dcc 104 104 ipc_answer_0(iid, EOK); 105 105 106 // process additional messages107 106 while(true){ 108 109 // clear the answer structure110 107 refresh_answer(&answer, &answer_count); 111 108 112 // fetch the next message113 109 callid = async_get_call(&call); 114 115 // process the message116 110 res = module_message(callid, &call, &answer, &answer_count); 117 111 118 // end if said to either by the message or the processing result119 112 if((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)){ 120 113 return; 121 114 } 122 115 123 // answer the message124 116 answer_call(callid, res, &answer, answer_count); 125 117 } … … 129 121 ERROR_DECLARE; 130 122 131 // print the module label132 123 printf("Task %d - ", task_get_id()); 133 124 module_print_name(); 134 125 printf("\n"); 135 136 // start the module137 126 if(ERROR_OCCURRED(module_start(client_connection))){ 138 127 printf(" - ERROR %i\n", ERROR_CODE); 139 128 return ERROR_CODE; 140 129 } 141 142 130 return EOK; 143 131 } -
uspace/srv/net/modules.c
r60ab6c3 r71b00dcc 51 51 52 52 void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count){ 53 // choose the most efficient answer function54 53 if(answer || (! answer_count)){ 55 54 switch(answer_count){ … … 87 86 ipcarg_t phonehash; 88 87 89 // connect to the needed service90 88 phone = connect_to_service_timeout(need, timeout); 91 // if connected92 89 if(phone >= 0){ 93 // request the bidirectional connection94 90 if(ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash))){ 95 91 ipc_hangup(phone); … … 106 102 107 103 int 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; 109 109 110 // if no timeout is set111 if (timeout <= 0){112 return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);113 }114 115 while(true){116 110 phone = async_connect_me_to(PHONE_NS, need, 0, 0); 117 if((phone >= 0) || (phone != ENOENT)) {111 if((phone >= 0) || (phone != ENOENT)) 118 112 return phone; 119 } 120 121 // end if no time is left 113 114 timeout -= MODULE_WAIT_TIME; 122 115 if(timeout <= 0){ 123 116 return ETIMEOUT; 124 117 } 125 118 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); 129 120 } 130 121 } … … 138 129 return EBADMEM; 139 130 } 140 141 // fetch the request142 131 if(! async_data_write_receive(&callid, length)){ 143 132 return EINVAL; 144 133 } 145 146 // allocate the buffer147 134 *data = malloc(*length); 148 135 if(!(*data)){ 149 136 return ENOMEM; 150 137 } 151 152 // fetch the data153 138 if(ERROR_OCCURRED(async_data_write_finalize(callid, * data, * length))){ 154 139 free(data); … … 162 147 ipc_callid_t callid; 163 148 164 // fetch the request165 149 if(! async_data_read_receive(&callid, &length)){ 166 150 return EINVAL; 167 151 } 168 169 // check the requested data size170 152 if(length < data_length){ 171 153 async_data_read_finalize(callid, data, length); 172 154 return EOVERFLOW; 173 155 } 174 175 // send the data176 156 return async_data_read_finalize(callid, data, data_length); 177 157 } 178 158 179 159 void refresh_answer(ipc_call_t * answer, int * answer_count){ 180 181 160 if(answer_count){ 182 161 *answer_count = 0; 183 162 } 184 185 163 if(answer){ 186 164 IPC_SET_RETVAL(*answer, 0); -
uspace/srv/net/net/net.c
r60ab6c3 r71b00dcc 66 66 #include "net_messages.h" 67 67 68 /** Networking module name. 69 */ 70 #define NAME "Networking" 71 68 72 /** File read buffer size. 69 73 */ 70 74 #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);84 75 85 76 /** Prints the module name. … … 97 88 int module_start(async_client_conn_t client_connection); 98 89 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 */ 92 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration); 115 93 116 94 /** \todo … … 123 101 */ 124 102 int read_configuration(void); 125 126 /** \todo127 */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);137 103 138 104 /** Starts the network interface according to its configuration. … … 160 126 int startup(void); 161 127 128 /** Generates new system-unique device identifier. 129 * @returns The system-unique devic identifier. 130 */ 131 device_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 */ 141 int 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 */ 148 int 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 */ 156 int read_netif_configuration(const char * name, netif_ref netif); 157 158 /** Networking module global data. 159 */ 160 net_globals_t net_globals; 161 162 DEVICE_MAP_IMPLEMENT(netifs, netif_t) 163 162 164 GENERIC_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 setting176 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 }186 165 187 166 void module_print_name(void){ … … 208 187 } 209 188 210 int net_connect_module(services_t service){ 211 return EOK; 212 } 213 214 void net_free_settings(measured_string_ref settings, char * data){ 189 int net_initialize(async_client_conn_t client_connection){ 190 ERROR_DECLARE; 191 192 netifs_initialize(&net_globals.netifs); 193 char_map_initialize(&net_globals.netif_names); 194 modules_initialize(&net_globals.modules); 195 measured_strings_initialize(&net_globals.configuration); 196 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 209 int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){ 210 netif_ref netif; 211 212 if(!(configuration && (count > 0))){ 213 return EINVAL; 214 } 215 netif = netifs_find(&net_globals.netifs, device_id); 216 if(netif){ 217 return net_get_conf(&netif->configuration, * configuration, count, data); 218 }else{ 219 return net_get_conf(NULL, * configuration, count, data); 220 } 221 } 222 223 int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){ 224 if(!(configuration && (count > 0))){ 225 return EINVAL; 226 } 227 return net_get_conf(NULL, * configuration, count, data); 215 228 } 216 229 … … 222 235 *data = NULL; 223 236 } 224 225 237 for(index = 0; index < count; ++ index){ 226 238 setting = measured_strings_find(netif_conf, configuration[index].value, 0); … … 239 251 } 240 252 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); 253 void net_free_settings(measured_string_ref settings, char * data){ 254 } 255 256 int net_connect_module(services_t service){ 257 return EOK; 282 258 } 283 259 … … 312 288 } 313 289 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 beginning324 name = line;325 326 // skip comments and blank lines327 if((*name == '#') || (*name == '\0')){328 return EOK;329 }330 // skip spaces331 while(isspace(*name)){332 ++ name;333 }334 335 // remember the name start336 value = name;337 // skip the name338 while(isalnum(*value) || (*value == '_')){339 // make uppercase340 // *value = toupper(*value);341 ++ value;342 }343 344 if(*value == '='){345 // terminate the name346 *value = '\0';347 }else{348 // terminate the name349 *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 spaces363 while(isspace(*value)){364 ++ value;365 }366 // create a bulk measured string till the end367 setting = measured_string_create_bulk(value, 0);368 if(! setting){369 return ENOMEM;370 }371 372 // add the configuration setting373 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 file382 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);383 290 } 384 291 … … 434 341 } 435 342 343 int parse_line(measured_strings_ref configuration, char * line){ 344 ERROR_DECLARE; 345 346 measured_string_ref setting; 347 char * name; 348 char * value; 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 407 int add_configuration(measured_strings_ref configuration, const char * name, const char * value){ 408 ERROR_DECLARE; 409 410 measured_string_ref setting; 411 412 setting = measured_string_create_bulk(value, 0); 413 if(! setting){ 414 return ENOMEM; 415 } 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 424 device_id_t generate_new_device_id(void){ 425 return device_assign_devno(); 426 } 427 428 int read_configuration(void){ 429 // read the general configuration file 430 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration); 431 } 432 436 433 int read_netif_configuration(const char * name, netif_ref netif){ 437 434 // read the netif configuration file … … 455 452 return EINVAL; 456 453 } 457 458 454 // optional network interface layer 459 455 setting = measured_strings_find(&netif->configuration, CONF_NIL, 0); … … 467 463 netif->nil = NULL; 468 464 } 469 470 465 // mandatory internet layer 471 466 setting = measured_strings_find(&netif->configuration, CONF_IL, 0); … … 475 470 return EINVAL; 476 471 } 477 478 // hardware configuration472 // end of the static loopback initialization 473 // startup the loopback interface 479 474 setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0); 480 475 irq = setting ? strtol(setting->value, NULL, 10) : 0; … … 482 477 io = setting ? strtol(setting->value, NULL, 16) : 0; 483 478 ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io)); 484 485 // network interface layer startup486 479 if(netif->nil){ 487 480 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0); … … 495 488 internet_service = netif->driver->service; 496 489 } 497 498 // inter-network layer startup499 490 switch(netif->il->service){ 500 491 case SERVICE_IP: … … 534 525 } 535 526 ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration)); 536 537 527 // read configuration files 538 528 if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){ … … 541 531 return ERROR_CODE; 542 532 } 543 544 533 // mandatory name 545 534 setting = measured_strings_find(&netif->configuration, CONF_NAME, 0); … … 551 540 } 552 541 netif->name = setting->value; 553 554 542 // add to the netifs map 555 543 index = netifs_add(&net_globals.netifs, netif->id, netif); … … 559 547 return index; 560 548 } 561 562 549 // add to the netif names map 563 550 if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index)) … … 568 555 return ERROR_CODE; 569 556 } 570 571 557 // increment modules' usage 572 558 ++ netif->driver->usage; -
uspace/srv/net/net/net.h
r60ab6c3 r71b00dcc 52 52 /*@{*/ 53 53 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 54 66 /** DP8390 network interface module full path filename. 55 67 */ 56 68 #define DP8390_FILENAME "/srv/dp8390" 57 69 58 /** DP8390 network interfacemodule name.59 */ 60 #define DP8390_NAME "dp8390"70 /** Ethernet module name. 71 */ 72 #define ETHERNET_NAME "ethernet" 61 73 62 74 /** Ethernet module full path filename. … … 66 78 /** Ethernet module name. 67 79 */ 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" 69 89 70 90 /** IP module full path filename. … … 72 92 #define IP_FILENAME "/srv/ip" 73 93 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 94 94 /*@}*/ 95 95 … … 98 98 /*@{*/ 99 99 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 100 112 /** Internet protocol module name configuration label. 101 113 */ 102 114 #define CONF_IL "IL" 103 115 116 /** Interrupt number configuration label. 117 */ 118 #define CONF_IRQ "IRQ" 119 104 120 /** Device input/output address configuration label. 105 121 */ 106 122 #define CONF_IO "IO" 107 123 108 /** Interrupt number configuration label.109 */110 #define CONF_IRQ "IRQ"111 112 124 /** Maximum transmission unit configuration label. 113 125 */ 114 126 #define CONF_MTU "MTU" 115 127 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 128 128 /*@}*/ 129 129 … … 135 135 */ 136 136 #define CONF_GENERAL_FILE "general" 137 138 /** Type definition of the network interface specific data. 139 * @see netif 140 */ 141 typedef struct netif netif_t; 142 143 /** Type definition of the network interface specific data pointer. 144 * @see netif 145 */ 146 typedef netif_t * netif_ref; 137 147 138 148 /** Type definition of the networking module global data. … … 141 151 typedef struct net_globals net_globals_t; 142 152 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 */ 157 DEVICE_MAP_DECLARE(netifs, netif_t) 152 158 153 159 /** Configuration settings. … … 157 163 GENERIC_CHAR_MAP_DECLARE(measured_strings, measured_string_t) 158 164 159 /** Present network interfaces.160 * Maps devices to the networking device specific data.161 * @see device.h162 */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 182 165 /** Present network interface device. 183 166 */ 184 167 struct netif{ 185 /** Configuration.186 */ 187 measured_strings_t configuration;168 /** System-unique network interface identifier. 169 */ 170 device_id_t id; 188 171 /** Serving network interface driver module index. 189 172 */ 190 173 module_ref driver; 191 /** S ystem-unique network interface identifier.192 */ 193 device_id_t id;174 /** Serving link layer module index. 175 */ 176 module_ref nil; 194 177 /** Serving internet layer module index. 195 178 */ … … 198 181 */ 199 182 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 */ 190 struct 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; 203 203 }; 204 204 … … 211 211 */ 212 212 int 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 */ 224 int 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 */ 231 int net_initialize_build(async_client_conn_t client_connection); 213 232 214 233 /** Processes the module message. … … 224 243 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 225 244 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.h241 * @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 245 245 #endif 246 246 -
uspace/srv/net/net/net_bundle.c
r60ab6c3 r71b00dcc 60 60 extern net_globals_t net_globals; 61 61 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 81 62 int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 82 63 if((IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME) … … 117 98 } 118 99 100 int 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 119 119 /** @} 120 120 */ -
uspace/srv/net/net/net_remote.c
r60ab6c3 r71b00dcc 50 50 #include "net_messages.h" 51 51 52 int net_connect_module(services_t service){ 53 return connect_to_service(SERVICE_NETWORKING); 52 int 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 56 int 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); 54 58 } 55 59 … … 63 67 } 64 68 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); 69 int net_connect_module(services_t service){ 70 return connect_to_service(SERVICE_NETWORKING); 71 71 } 72 72 -
uspace/srv/net/net/net_standalone.c
r60ab6c3 r71b00dcc 53 53 extern net_globals_t net_globals; 54 54 55 int 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 55 63 int net_initialize_build(async_client_conn_t client_connection){ 56 64 ERROR_DECLARE; … … 75 83 } 76 84 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 85 85 /** @} 86 86 */ -
uspace/srv/net/net/start/netstart.c
r60ab6c3 r71b00dcc 76 76 int net_phone; 77 77 78 // print the module label79 78 printf("Task %d - ", task_get_id()); 80 79 printf("%s\n", NAME); 81 82 80 // run self tests 83 81 ERROR_PROPAGATE(self_test()); 84 85 // start the networking service 82 // start net service 86 83 if(! spawn("/srv/net")){ 87 84 fprintf(stderr, "Could not spawn net\n"); 88 85 return EINVAL; 89 86 } 90 91 // start the networking 87 // start net 92 88 net_phone = connect_to_service(SERVICE_NETWORKING); 93 89 if(ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))){ -
uspace/srv/net/netif/dp8390/dp8390_module.c
r60ab6c3 r71b00dcc 193 193 dep->de_int_pending = 0; 194 194 // remove debug print: 195 #ifdef CONFIG_DEBUG196 195 printf("I%d: 0x%x\n", device_id, IPC_GET_ISR(call)); 197 #endif198 196 dp_check_ints(dep, IPC_GET_ISR(call)); 199 197 if(dep->received_queue){ … … 204 202 fibril_rwlock_write_unlock(&netif_globals.lock); 205 203 // remove debug dump: 206 #ifdef CONFIG_DEBUG207 204 uint8_t * data; 208 205 data = packet_get_data(received); 209 206 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 #endif211 207 nil_received_msg(phone, device_id, received, NULL); 212 208 }else{ … … 271 267 next = pq_detach(packet); 272 268 // remove debug dump: 273 #ifdef CONFIG_DEBUG274 269 uint8_t * data; 275 270 data = packet_get_data(packet); 276 271 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 278 273 if(do_pwrite(dep, packet, FALSE) != EBUSY){ 279 274 netif_pq_release(packet_get_id(packet)); -
uspace/srv/net/self_test.c
r60ab6c3 r71b00dcc 57 57 * @param[in] result The expected result. 58 58 */ 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 } \ 67 67 } 68 68 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 69 85 #if NET_SELF_TEST_GENERIC_CHAR_MAP 70 86 … … 72 88 73 89 GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int) 74 75 #endif76 77 #if NET_SELF_TEST_GENERIC_FIELD78 79 GENERIC_FIELD_DECLARE(int_field, int)80 81 GENERIC_FIELD_IMPLEMENT(int_field, int)82 83 #endif84 85 #if NET_SELF_TEST_INT_MAP86 87 INT_MAP_DECLARE(int_map, int);88 89 INT_MAP_IMPLEMENT(int_map, int);90 90 91 91 #endif … … 101 101 102 102 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 103 112 104 113 #if NET_SELF_TEST_CHAR_MAP … … 151 160 #endif 152 161 153 #if NET_SELF_TEST_CRC154 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 #endif184 185 #if NET_SELF_TEST_DYNAMIC_FIFO186 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 #endif230 231 #if NET_SELF_TEST_GENERIC_CHAR_MAP232 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 #endif275 276 #if NET_SELF_TEST_GENERIC_FIELD277 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 #endif328 329 162 #if NET_SELF_TEST_INT_MAP 330 163 int_map_t im; … … 383 216 #endif 384 217 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); 391 263 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 392 392 #endif 393 393 -
uspace/srv/net/tl/icmp/icmp.c
r60ab6c3 r71b00dcc 41 41 #include <fibril_synch.h> 42 42 #include <stdint.h> 43 #include <string.h>44 43 45 44 #include <ipc/ipc.h> -
uspace/srv/net/tl/icmp/icmp_client.c
r60ab6c3 r71b00dcc 37 37 38 38 #include <errno.h> 39 40 #ifdef CONFIG_DEBUG 41 #include <stdio.h> 42 #endif 39 //#include <stdio.h> 43 40 44 41 #include <sys/types.h> … … 73 70 } 74 71 // 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)); 78 73 return sizeof(icmp_header_t); 79 74 } -
uspace/srv/net/tl/tcp/tcp.c
r60ab6c3 r71b00dcc 1241 1241 } 1242 1242 1243 // release the application phone1244 ipc_hangup(app_phone);1245 1246 1243 printf("release\n"); 1247 1244 // release all local sockets … … 1280 1277 // TODO release as connection lost 1281 1278 //tcp_refresh_socket_data(socket_data); 1282 fibril_rwlock_write_unlock(socket_data->local_lock);1283 1279 }else{ 1284 1280 // 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); 1288 1284 }else{ 1289 1285 fibril_mutex_lock(&socket_data->operation.mutex); -
uspace/srv/net/tl/udp/udp.c
r60ab6c3 r71b00dcc 508 508 } 509 509 510 // release the application phone511 ipc_hangup(app_phone);512 513 510 // release all local sockets 514 511 socket_cores_release(udp_globals.net_phone, &local_sockets, &udp_globals.sockets, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.