Changes in uspace/srv/net/udp/assoc.c [a2e3ee6:69a93df7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/assoc.c
ra2e3ee6 r69a93df7 36 36 37 37 #include <adt/list.h> 38 #include < stdbool.h>38 #include <bool.h> 39 39 #include <fibril_synch.h> 40 40 #include <io/log.h> … … 82 82 if (lsock != NULL) 83 83 assoc->ident.local = *lsock; 84 85 84 if (fsock != NULL) 86 85 assoc->ident.foreign = *fsock; … … 105 104 static void udp_assoc_free(udp_assoc_t *assoc) 106 105 { 107 log_msg(L OG_DEFAULT, LVL_DEBUG, "%s: udp_assoc_free(%p)", assoc->name, assoc);106 log_msg(LVL_DEBUG, "%s: udp_assoc_free(%p)", assoc->name, assoc); 108 107 109 108 while (!list_empty(&assoc->rcv_queue)) { … … 128 127 void udp_assoc_addref(udp_assoc_t *assoc) 129 128 { 130 log_msg(L OG_DEFAULT, LVL_DEBUG, "%s: upd_assoc_addref(%p)", assoc->name, assoc);129 log_msg(LVL_DEBUG, "%s: upd_assoc_addref(%p)", assoc->name, assoc); 131 130 atomic_inc(&assoc->refcnt); 132 131 } … … 140 139 void udp_assoc_delref(udp_assoc_t *assoc) 141 140 { 142 log_msg(L OG_DEFAULT, LVL_DEBUG, "%s: udp_assoc_delref(%p)", assoc->name, assoc);141 log_msg(LVL_DEBUG, "%s: udp_assoc_delref(%p)", assoc->name, assoc); 143 142 144 143 if (atomic_predec(&assoc->refcnt) == 0) … … 155 154 void udp_assoc_delete(udp_assoc_t *assoc) 156 155 { 157 log_msg(L OG_DEFAULT, LVL_DEBUG, "%s: udp_assoc_delete(%p)", assoc->name, assoc);156 log_msg(LVL_DEBUG, "%s: udp_assoc_delete(%p)", assoc->name, assoc); 158 157 159 158 assert(assoc->deleted == false); … … 193 192 void udp_assoc_set_foreign(udp_assoc_t *assoc, udp_sock_t *fsock) 194 193 { 195 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_assoc_set_foreign(%p, %p)", assoc, fsock);194 log_msg(LVL_DEBUG, "udp_assoc_set_foreign(%p, %p)", assoc, fsock); 196 195 fibril_mutex_lock(&assoc->lock); 197 196 assoc->ident.foreign = *fsock; … … 201 200 /** Set local socket in association. 202 201 * 203 * @param assoc Association 204 * @param lsock Local socket (deeply copied) 205 * 202 * @param assoc Association 203 * @param fsock Foreign socket (deeply copied) 206 204 */ 207 205 void udp_assoc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock) 208 206 { 209 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %p)", assoc, lsock);207 log_msg(LVL_DEBUG, "udp_assoc_set_local(%p, %p)", assoc, lsock); 210 208 fibril_mutex_lock(&assoc->lock); 211 209 assoc->ident.local = *lsock; 212 fibril_mutex_unlock(&assoc->lock);213 }214 215 /** Set local port in association.216 *217 * @param assoc Association218 * @param lport Local port219 *220 */221 void udp_assoc_set_local_port(udp_assoc_t *assoc, uint16_t lport)222 {223 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %" PRIu16 ")", assoc, lport);224 fibril_mutex_lock(&assoc->lock);225 assoc->ident.local.port = lport;226 210 fibril_mutex_unlock(&assoc->lock); 227 211 } … … 244 228 int rc; 245 229 246 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_assoc_send(%p, %p, %p)",230 log_msg(LVL_DEBUG, "udp_assoc_send(%p, %p, %p)", 247 231 assoc, fsock, msg); 248 232 … … 252 236 sp.foreign = *fsock; 253 237 254 if ((inet_addr_is_any(&sp.foreign.addr)) || 255 (sp.foreign.port == UDP_PORT_ANY)) 238 if (sp.foreign.addr.ipv4 == 0 || sp.foreign.port == 0) 256 239 return EINVAL; 257 240 … … 278 261 udp_rcv_queue_entry_t *rqe; 279 262 280 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_assoc_recv()");263 log_msg(LVL_DEBUG, "udp_assoc_recv()"); 281 264 282 265 fibril_mutex_lock(&assoc->lock); 283 while (list_empty(&assoc->rcv_queue) && !assoc->reset) {284 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_assoc_recv() - waiting");266 while (list_empty(&assoc->rcv_queue)) { 267 log_msg(LVL_DEBUG, "udp_assoc_recv() - waiting"); 285 268 fibril_condvar_wait(&assoc->rcv_queue_cv, &assoc->lock); 286 269 } 287 270 288 if (assoc->reset) { 289 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv() - association was reset"); 290 fibril_mutex_unlock(&assoc->lock); 291 return ECONNABORTED; 292 } 293 294 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_recv() - got a message"); 271 log_msg(LVL_DEBUG, "udp_assoc_recv() - got a message"); 295 272 link = list_first(&assoc->rcv_queue); 296 273 rqe = list_get_instance(link, udp_rcv_queue_entry_t, link); … … 314 291 int rc; 315 292 316 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_assoc_received(%p, %p)", rsp, msg);293 log_msg(LVL_DEBUG, "udp_assoc_received(%p, %p)", rsp, msg); 317 294 318 295 assoc = udp_assoc_find_ref(rsp); 319 296 if (assoc == NULL) { 320 log_msg(L OG_DEFAULT, LVL_DEBUG, "No association found. Message dropped.");297 log_msg(LVL_DEBUG, "No association found. Message dropped."); 321 298 /* XXX Generate ICMP error. */ 322 299 /* XXX Might propagate error directly by error return. */ … … 326 303 rc = udp_assoc_queue_msg(assoc, rsp, msg); 327 304 if (rc != EOK) { 328 log_msg(L OG_DEFAULT, LVL_DEBUG, "Out of memory. Message dropped.");305 log_msg(LVL_DEBUG, "Out of memory. Message dropped."); 329 306 /* XXX Generate ICMP error? */ 330 307 } 331 308 } 332 309 333 /** Reset association.334 *335 * This causes any pendingreceive operations to return immediately with336 * UDP_ERESET.337 */338 void udp_assoc_reset(udp_assoc_t *assoc)339 {340 fibril_mutex_lock(&assoc->lock);341 assoc->reset = true;342 fibril_condvar_broadcast(&assoc->rcv_queue_cv);343 fibril_mutex_unlock(&assoc->lock);344 }345 346 310 static int udp_assoc_queue_msg(udp_assoc_t *assoc, udp_sockpair_t *sp, 347 311 udp_msg_t *msg) … … 349 313 udp_rcv_queue_entry_t *rqe; 350 314 351 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_assoc_queue_msg(%p, %p, %p)",315 log_msg(LVL_DEBUG, "udp_assoc_queue_msg(%p, %p, %p)", 352 316 assoc, sp, msg); 353 317 … … 372 336 static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt) 373 337 { 374 if ((!inet_addr_is_any(&patt->addr)) && 375 (!inet_addr_compare(&patt->addr, &sock->addr))) 338 log_msg(LVL_DEBUG, "udp_socket_match(sock=(%x,%u), pat=(%x,%u))", 339 sock->addr.ipv4, sock->port, patt->addr.ipv4, patt->port); 340 341 if (patt->addr.ipv4 != UDP_IPV4_ANY && 342 patt->addr.ipv4 != sock->addr.ipv4) 376 343 return false; 377 378 if ( (patt->port != UDP_PORT_ANY)&&379 (patt->port != sock->port))344 345 if (patt->port != UDP_PORT_ANY && 346 patt->port != sock->port) 380 347 return false; 381 382 log_msg(L OG_DEFAULT, LVL_DEBUG, " -> match");383 348 349 log_msg(LVL_DEBUG, " -> match"); 350 384 351 return true; 385 352 } … … 388 355 static bool udp_sockpair_match(udp_sockpair_t *sp, udp_sockpair_t *pattern) 389 356 { 390 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_sockpair_match(%p, %p)", sp, pattern);357 log_msg(LVL_DEBUG, "udp_sockpair_match(%p, %p)", sp, pattern); 391 358 392 359 if (!udp_socket_match(&sp->local, &pattern->local)) … … 396 363 return false; 397 364 398 log_msg(L OG_DEFAULT, LVL_DEBUG, "Socket pair matched.");365 log_msg(LVL_DEBUG, "Socket pair matched."); 399 366 return true; 400 367 } … … 412 379 static udp_assoc_t *udp_assoc_find_ref(udp_sockpair_t *sp) 413 380 { 414 log_msg(L OG_DEFAULT, LVL_DEBUG, "udp_assoc_find_ref(%p)", sp);415 381 log_msg(LVL_DEBUG, "udp_assoc_find_ref(%p)", sp); 382 416 383 fibril_mutex_lock(&assoc_list_lock); 417 384 418 385 list_foreach(assoc_list, link) { 419 386 udp_assoc_t *assoc = list_get_instance(link, udp_assoc_t, link); 420 387 udp_sockpair_t *asp = &assoc->ident; 421 388 log_msg(LVL_DEBUG, "compare with assoc (f:(%x,%u), l:(%x,%u))", 389 asp->foreign.addr.ipv4, asp->foreign.port, 390 asp->local.addr.ipv4, asp->local.port); 391 422 392 /* Skip unbound associations */ 423 393 if (asp->local.port == UDP_PORT_ANY) 424 394 continue; 425 395 426 396 if (udp_sockpair_match(sp, asp)) { 427 log_msg(L OG_DEFAULT, LVL_DEBUG, "Returning assoc %p", assoc);397 log_msg(LVL_DEBUG, "Returning assoc %p", assoc); 428 398 udp_assoc_addref(assoc); 429 399 fibril_mutex_unlock(&assoc_list_lock); … … 431 401 } 432 402 } 433 403 434 404 fibril_mutex_unlock(&assoc_list_lock); 435 405 return NULL; 436 406 } 437 407 408 438 409 /** 439 410 * @}
Note:
See TracChangeset
for help on using the changeset viewer.