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