Changeset fab2746 in mainline for uspace/srv/net/udp
- Timestamp:
- 2015-04-08T21:25:30Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 99ea91b2
- Parents:
- ba0eac5
- Location:
- uspace/srv/net/udp
- Files:
-
- 1 added
- 1 deleted
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/Makefile
rba0eac5 rfab2746 28 28 29 29 USPACE_PREFIX = ../../.. 30 LIBS = $(LIBNET_PREFIX)/libnet.a31 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include32 30 BINARY = udp 33 31 … … 35 33 assoc.c \ 36 34 msg.c \ 37 sock.c \38 35 pdu.c \ 36 service.c \ 39 37 ucall.c \ 40 38 udp.c \ -
uspace/srv/net/udp/assoc.c
rba0eac5 rfab2746 36 36 37 37 #include <adt/list.h> 38 #include <errno.h> 38 39 #include <stdbool.h> 39 40 #include <fibril_synch.h> … … 62 63 * @return New association or NULL 63 64 */ 64 udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock) 65 udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock, 66 udp_assoc_cb_t *cb, void *cb_arg) 65 67 { 66 68 udp_assoc_t *assoc = NULL; … … 82 84 if (lsock != NULL) 83 85 assoc->ident.local = *lsock; 84 86 85 87 if (fsock != NULL) 86 88 assoc->ident.foreign = *fsock; 87 89 90 assoc->cb = cb; 91 assoc->cb_arg = cb_arg; 88 92 return assoc; 89 93 error: … … 258 262 int rc; 259 263 260 log_msg(LOG_DEFAULT, LVL_ DEBUG, "udp_assoc_send(%p, %p, %p)",264 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send(%p, %p, %p)", 261 265 assoc, fsock, msg); 262 266 … … 266 270 sp.foreign = *fsock; 267 271 272 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check addr any"); 273 268 274 if ((inet_addr_is_any(&sp.foreign.addr)) || 269 275 (sp.foreign.port == UDP_PORT_ANY)) 270 276 return EINVAL; 271 277 278 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - check version"); 279 280 if (sp.foreign.addr.version != sp.local.addr.version) 281 return EINVAL; 282 283 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - encode pdu"); 284 272 285 rc = udp_pdu_encode(&sp, msg, &pdu); 273 286 if (rc != EOK) 274 287 return ENOMEM; 275 288 289 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - transmit"); 290 276 291 rc = udp_transmit_pdu(pdu); 277 292 udp_pdu_delete(pdu); … … 280 295 return EIO; 281 296 297 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_send - success"); 282 298 return EOK; 283 299 } … … 292 308 udp_rcv_queue_entry_t *rqe; 293 309 294 log_msg(LOG_DEFAULT, LVL_ DEBUG, "udp_assoc_recv()");310 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_recv()"); 295 311 296 312 fibril_mutex_lock(&assoc->lock); … … 303 319 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv() - association was reset"); 304 320 fibril_mutex_unlock(&assoc->lock); 305 return E CONNABORTED;321 return ENXIO; 306 322 } 307 323 308 log_msg(LOG_DEFAULT, LVL_ DEBUG, "udp_assoc_recv() - got a message");324 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_recv() - got a message"); 309 325 link = list_first(&assoc->rcv_queue); 310 326 rqe = list_get_instance(link, udp_rcv_queue_entry_t, link); … … 328 344 int rc; 329 345 330 log_msg(LOG_DEFAULT, LVL_ DEBUG, "udp_assoc_received(%p, %p)", rsp, msg);346 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_received(%p, %p)", rsp, msg); 331 347 332 348 assoc = udp_assoc_find_ref(rsp); 333 349 if (assoc == NULL) { 334 log_msg(LOG_DEFAULT, LVL_ DEBUG, "No association found. Message dropped.");350 log_msg(LOG_DEFAULT, LVL_NOTE, "No association found. Message dropped."); 335 351 /* XXX Generate ICMP error. */ 336 352 /* XXX Might propagate error directly by error return. */ … … 339 355 } 340 356 341 rc = udp_assoc_queue_msg(assoc, rsp, msg); 342 if (rc != EOK) { 343 log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped."); 357 if (0) { 358 rc = udp_assoc_queue_msg(assoc, rsp, msg); 359 if (rc != EOK) { 360 log_msg(LOG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped."); 344 361 /* XXX Generate ICMP error? */ 362 } 345 363 } 364 365 log_msg(LOG_DEFAULT, LVL_NOTE, "call assoc->cb->recv_msg"); 366 assoc->cb->recv_msg(assoc->cb_arg, rsp, msg); 346 367 } 347 368 … … 387 408 static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt) 388 409 { 389 log_msg(LOG_DEFAULT, LVL_DEBUG, 390 "udp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port); 410 char *sa, *pa; 411 412 sa = pa = (char *)"?"; 413 (void) inet_addr_format(&sock->addr, &sa); 414 (void) inet_addr_format(&patt->addr, &pa); 415 416 log_msg(LOG_DEFAULT, LVL_NOTE, 417 "udp_socket_match(sock=(%s,%u), pat=(%s,%u))", 418 sa, sock->port, pa, patt->port); 391 419 392 420 if ((!inet_addr_is_any(&patt->addr)) && … … 394 422 return false; 395 423 424 log_msg(LOG_DEFAULT, LVL_NOTE, "addr OK"); 425 396 426 if ((patt->port != UDP_PORT_ANY) && 397 427 (patt->port != sock->port)) 398 428 return false; 399 429 400 log_msg(LOG_DEFAULT, LVL_ DEBUG, " -> match");430 log_msg(LOG_DEFAULT, LVL_NOTE, " -> match"); 401 431 402 432 return true; … … 430 460 static udp_assoc_t *udp_assoc_find_ref(udp_sockpair_t *sp) 431 461 { 432 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_find_ref(%p)", sp); 462 char *la, *ra; 463 464 log_msg(LOG_DEFAULT, LVL_NOTE, "udp_assoc_find_ref(%p)", sp); 433 465 434 466 fibril_mutex_lock(&assoc_list_lock); 435 467 468 log_msg(LOG_DEFAULT, LVL_NOTE, "associations:"); 436 469 list_foreach(assoc_list, link, udp_assoc_t, assoc) { 437 470 udp_sockpair_t *asp = &assoc->ident; 438 471 472 la = ra = NULL; 473 474 (void) inet_addr_format(&asp->local.addr, &la); 475 (void) inet_addr_format(&asp->foreign.addr, &ra); 476 477 log_msg(LOG_DEFAULT, LVL_NOTE, "find_ref:asp=%p la=%s ra=%s", 478 asp, la, ra); 439 479 /* Skip unbound associations */ 440 if (asp->local.port == UDP_PORT_ANY) 480 if (asp->local.port == UDP_PORT_ANY) { 481 log_msg(LOG_DEFAULT, LVL_NOTE, "skip unbound"); 441 482 continue; 483 } 442 484 443 485 if (udp_sockpair_match(sp, asp)) { … … 446 488 fibril_mutex_unlock(&assoc_list_lock); 447 489 return assoc; 490 } else { 491 log_msg(LOG_DEFAULT, LVL_NOTE, "not matched"); 448 492 } 449 493 } 450 494 495 log_msg(LOG_DEFAULT, LVL_NOTE, "associations END"); 451 496 fibril_mutex_unlock(&assoc_list_lock); 452 497 return NULL; -
uspace/srv/net/udp/assoc.h
rba0eac5 rfab2746 40 40 #include "udp_type.h" 41 41 42 extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *); 42 extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *, udp_assoc_cb_t *, 43 void *); 43 44 extern void udp_assoc_delete(udp_assoc_t *); 44 45 extern void udp_assoc_add(udp_assoc_t *); -
uspace/srv/net/udp/pdu.c
rba0eac5 rfab2746 41 41 #include <stdlib.h> 42 42 #include <inet/addr.h> 43 #include <net/socket_codes.h>44 43 #include "msg.h" 45 44 #include "pdu.h" -
uspace/srv/net/udp/service.h
rba0eac5 rfab2746 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 30 30 * @{ 31 31 */ 32 /** @file Socket provider32 /** @file HelenOS service implementation 33 33 */ 34 34 35 #ifndef S OCK_H36 #define S OCK_H35 #ifndef SERVICE_H 36 #define SERVICE_H 37 37 38 #include <async.h> 39 40 extern int udp_sock_init(void); 38 extern int udp_service_init(void); 41 39 42 40 #endif -
uspace/srv/net/udp/ucall.c
rba0eac5 rfab2746 35 35 */ 36 36 37 #include <errno.h> 37 38 #include <io/log.h> 38 39 #include <macros.h> 40 #include <mem.h> 39 41 40 42 #include "assoc.h" … … 48 50 49 51 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_create()"); 50 nassoc = udp_assoc_new(NULL, NULL );52 nassoc = udp_assoc_new(NULL, NULL, NULL, NULL); 51 53 if (nassoc == NULL) 52 54 return UDP_ENORES; … … 125 127 case EOK: 126 128 break; 127 case E CONNABORTED:129 case ENXIO: 128 130 return UDP_ERESET; 129 131 default: -
uspace/srv/net/udp/udp.c
rba0eac5 rfab2746 41 41 #include <task.h> 42 42 43 #include "service.h" 43 44 #include "udp_inet.h" 44 #include "sock.h"45 45 46 46 #define NAME "udp" … … 58 58 } 59 59 60 rc = udp_s ock_init();60 rc = udp_service_init(); 61 61 if (rc != EOK) { 62 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing socketservice.");62 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing UDP service."); 63 63 return ENOENT; 64 64 } -
uspace/srv/net/udp/udp_type.h
rba0eac5 rfab2746 36 36 #define UDP_TYPE_H 37 37 38 #include <async.h> 38 39 #include <fibril.h> 39 40 #include <fibril_synch.h> 40 41 #include <ipc/loc.h> 41 #include <socket_core.h>42 42 #include <sys/types.h> 43 43 #include <inet/addr.h> … … 99 99 100 100 typedef struct { 101 async_sess_t *sess; 102 socket_cores_t sockets; 103 } udp_client_t; 101 void (*recv_msg)(void *, udp_sockpair_t *, udp_msg_t *); 102 } udp_assoc_cb_t; 104 103 105 104 /** UDP association … … 131 130 /** Receive queue CV. Broadcast when new datagram is inserted */ 132 131 fibril_condvar_t rcv_queue_cv; 132 133 udp_assoc_cb_t *cb; 134 void *cb_arg; 133 135 } udp_assoc_t; 134 136 135 137 typedef struct { 136 138 } udp_assoc_status_t; 137 138 typedef struct udp_sockdata {139 /** Lock */140 fibril_mutex_t lock;141 /** Socket core */142 socket_core_t *sock_core;143 /** Client */144 udp_client_t *client;145 /** Connection */146 udp_assoc_t *assoc;147 /** User-configured IP link */148 service_id_t iplink;149 /** Receiving fibril */150 fid_t recv_fibril;151 uint8_t recv_buffer[UDP_FRAGMENT_SIZE];152 size_t recv_buffer_used;153 udp_sock_t recv_fsock;154 fibril_mutex_t recv_buffer_lock;155 fibril_condvar_t recv_buffer_cv;156 udp_error_t recv_error;157 } udp_sockdata_t;158 139 159 140 typedef struct { … … 166 147 } udp_rcv_queue_entry_t; 167 148 149 typedef struct udp_cassoc { 150 /** Association */ 151 udp_assoc_t *assoc; 152 /** Association ID for the client */ 153 sysarg_t id; 154 /** Client */ 155 struct udp_client *client; 156 link_t lclient; 157 } udp_cassoc_t; 158 159 typedef struct { 160 /** Link to receive queue */ 161 link_t link; 162 /** Socket pair */ 163 udp_sockpair_t sp; 164 /** Message */ 165 udp_msg_t *msg; 166 /** Client association */ 167 udp_cassoc_t *cassoc; 168 } udp_crcv_queue_entry_t; 169 170 typedef struct udp_client { 171 /** Client callback session */ 172 async_sess_t *sess; 173 /** Client assocations */ 174 list_t cassoc; /* of udp_cassoc_t */ 175 /** Client receive queue */ 176 list_t crcv_queue; 177 } udp_client_t; 178 168 179 #endif 169 180
Note:
See TracChangeset
for help on using the changeset viewer.