Changes in uspace/lib/nettl/src/amap.c [8a637a4:c3f7d37] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/nettl/src/amap.c
r8a637a4 rc3f7d37 36 36 * Manages allocations of endpoints / endpoint pairs (corresponding to 37 37 * UDP associations, TCP listeners and TCP connections) 38 *39 * An association map contains different types of entries, based on which40 * set of attributes (key) they specify. In order from most specific to the41 * least specific one:42 *43 * - repla (remote endpoint, local address)44 * - laddr (local address)45 * - llink (local link)46 * - unspec (unspecified)47 *48 * In the unspecified case only the local port is known and the entry matches49 * all remote and local addresses.50 38 */ 51 39 … … 59 47 #include <stdlib.h> 60 48 61 /** Create association map.62 *63 * @param rmap Place to store pointer to new association map64 * @return EOk on success, ENOMEM if out of memory65 */66 49 int amap_create(amap_t **rmap) 67 50 { … … 90 73 } 91 74 92 /** Destroy association map.93 *94 * @param map Association map95 */96 75 void amap_destroy(amap_t *map) 97 76 { … … 100 79 } 101 80 102 /** Find exact repla. 103 * 104 * Find repla (remote endpoint, local address) entry by exact match. 105 * 106 * @param map Association map 107 * @param rep Remote endpoint 108 * @param la Local address 109 * @param rrepla Place to store pointer to repla 110 * 111 * @return EOK on success, ENOENT if not found 112 */ 81 /** Find exact repla */ 113 82 static int amap_repla_find(amap_t *map, inet_ep_t *rep, inet_addr_t *la, 114 83 amap_repla_t **rrepla) … … 144 113 } 145 114 146 /** Insert repla.147 *148 * Insert new repla (remote endpoint, local address) entry to association map.149 *150 * @param amap Association map151 * @param rep Remote endpoint152 * @param la Local address153 * @param rrepla Place to store pointer to new repla154 *155 * @return EOK on success, ENOMEM if out of memory156 */157 115 static int amap_repla_insert(amap_t *map, inet_ep_t *rep, inet_addr_t *la, 158 116 amap_repla_t **rrepla) … … 181 139 } 182 140 183 /** Remove repla from association map.184 *185 * Remove repla (remote endpoint, local address) from association map.186 *187 * @param map Association map188 * @param repla Repla189 */190 141 static void amap_repla_remove(amap_t *map, amap_repla_t *repla) 191 142 { … … 195 146 } 196 147 197 /** Find exact laddr. 198 * 199 * Find laddr (local address) entry by exact match. 200 * 201 * @param map Association map 202 * @param addr Address 203 * @param rladdr Place to store pointer to laddr entry 204 * 205 * @return EOK on success, ENOENT if not found. 206 */ 148 /** Find exact laddr */ 207 149 static int amap_laddr_find(amap_t *map, inet_addr_t *addr, 208 150 amap_laddr_t **rladdr) … … 219 161 } 220 162 221 /** Insert laddr.222 *223 * Insert new laddr (local address) entry to association map.224 *225 * @param addr Local address226 * @param rladdr Place to store pointer to new laddr227 *228 * @return EOK on success, ENOMEM if out of memory229 */230 163 static int amap_laddr_insert(amap_t *map, inet_addr_t *addr, 231 164 amap_laddr_t **rladdr) … … 253 186 } 254 187 255 /** Remove laddr from association map.256 *257 * Remove laddr (local address) entry from association map.258 *259 * @param map Association map260 * @param laddr Laddr entry261 */262 188 static void amap_laddr_remove(amap_t *map, amap_laddr_t *laddr) 263 189 { … … 267 193 } 268 194 269 /** Find exact llink. 270 * 271 * Find llink (local link) entry by exact match. 272 * 273 * @param map Association map 274 * @param link_id Local link ID 275 * @param rllink Place to store pointer to llink entry 276 * 277 * @return EOK on success, ENOENT if not found. 278 */ 195 /** Find exact llink */ 279 196 static int amap_llink_find(amap_t *map, sysarg_t link_id, 280 197 amap_llink_t **rllink) … … 291 208 } 292 209 293 /** Insert llink.294 *295 * Insert new llink (local link) entry to association map.296 *297 * @param link_id Local link298 * @param rllink Place to store pointer to new llink299 *300 * @return EOK on success, ENOMEM if out of memory301 */302 210 static int amap_llink_insert(amap_t *map, sysarg_t link_id, 303 211 amap_llink_t **rllink) … … 325 233 } 326 234 327 /** Remove llink from association map.328 *329 * Remove llink (local link) entry from association map.330 *331 * @param map Association map332 * @param llink Llink entry333 */334 235 static void amap_llink_remove(amap_t *map, amap_llink_t *llink) 335 236 { … … 339 240 } 340 241 341 /** Insert endpoint pair into map with repla as key.342 *343 * If local port number is not specified, it is allocated.344 *345 * @param map Association map346 * @param epp Endpoint pair, possibly with local port inet_port_any347 * @param arg arg User value348 * @param flags Flags349 * @param aepp Place to store actual endpoint pair, possibly with allocated port350 *351 * @return EOK on success, EEXIST if conflicting epp exists,352 * ENOMEM if out of memory353 */354 242 static int amap_insert_repla(amap_t *map, inet_ep2_t *epp, void *arg, 355 243 amap_flags_t flags, inet_ep2_t *aepp) … … 384 272 } 385 273 386 /** Insert endpoint pair into map with laddr as key. 387 * 388 * If local port number is not specified, it is allocated. 274 static int amap_insert_laddr(amap_t *map, inet_ep2_t *epp, void *arg, 275 amap_flags_t flags, inet_ep2_t *aepp) 276 { 277 amap_laddr_t *laddr; 278 inet_ep2_t mepp; 279 int rc; 280 281 log_msg(LOG_DEFAULT, LVL_DEBUG2, "amap_insert_laddr()"); 282 283 rc = amap_laddr_find(map, &epp->local.addr, &laddr); 284 if (rc != EOK) { 285 /* New laddr */ 286 rc = amap_laddr_insert(map, &epp->local.addr, &laddr); 287 if (rc != EOK) { 288 assert(rc == ENOMEM); 289 return rc; 290 } 291 } 292 293 mepp = *epp; 294 295 rc = portrng_alloc(laddr->portrng, epp->local.port, arg, flags, 296 &mepp.local.port); 297 if (rc != EOK) { 298 return rc; 299 } 300 301 *aepp = mepp; 302 return EOK; 303 } 304 305 static int amap_insert_llink(amap_t *map, inet_ep2_t *epp, void *arg, 306 amap_flags_t flags, inet_ep2_t *aepp) 307 { 308 amap_llink_t *llink; 309 inet_ep2_t mepp; 310 int rc; 311 312 log_msg(LOG_DEFAULT, LVL_DEBUG2, "amap_insert_llink()"); 313 314 rc = amap_llink_find(map, epp->local_link, &llink); 315 if (rc != EOK) { 316 /* New llink */ 317 rc = amap_llink_insert(map, epp->local_link, &llink); 318 if (rc != EOK) { 319 assert(rc == ENOMEM); 320 return rc; 321 } 322 } 323 324 mepp = *epp; 325 326 rc = portrng_alloc(llink->portrng, epp->local.port, arg, flags, 327 &mepp.local.port); 328 if (rc != EOK) { 329 return rc; 330 } 331 332 *aepp = mepp; 333 return EOK; 334 } 335 336 static int amap_insert_unspec(amap_t *map, inet_ep2_t *epp, void *arg, 337 amap_flags_t flags, inet_ep2_t *aepp) 338 { 339 inet_ep2_t mepp; 340 int rc; 341 342 log_msg(LOG_DEFAULT, LVL_DEBUG2, "amap_insert_unspec()"); 343 mepp = *epp; 344 345 rc = portrng_alloc(map->unspec, epp->local.port, arg, flags, 346 &mepp.local.port); 347 if (rc != EOK) { 348 return rc; 349 } 350 351 *aepp = mepp; 352 return EOK; 353 } 354 355 /** Insert endpoint pair into map. 356 * 357 * If local endpoint is not fully specified, it is filled in (determine 358 * source address, allocate port number). Checks for conflicting endpoint pair. 389 359 * 390 360 * @param map Association map … … 394 364 * @param aepp Place to store actual endpoint pair, possibly with allocated port 395 365 * 396 * @return EOK on success, EEXIST if conflicting epp exists, 397 * ENOMEM if out of memory 398 */ 399 static int amap_insert_laddr(amap_t *map, inet_ep2_t *epp, void *arg, 400 amap_flags_t flags, inet_ep2_t *aepp) 401 { 402 amap_laddr_t *laddr; 403 inet_ep2_t mepp; 404 int rc; 405 406 log_msg(LOG_DEFAULT, LVL_DEBUG2, "amap_insert_laddr()"); 407 408 rc = amap_laddr_find(map, &epp->local.addr, &laddr); 409 if (rc != EOK) { 410 /* New laddr */ 411 rc = amap_laddr_insert(map, &epp->local.addr, &laddr); 412 if (rc != EOK) { 413 assert(rc == ENOMEM); 414 return rc; 415 } 416 } 417 418 mepp = *epp; 419 420 rc = portrng_alloc(laddr->portrng, epp->local.port, arg, flags, 421 &mepp.local.port); 422 if (rc != EOK) { 423 return rc; 424 } 425 426 *aepp = mepp; 427 return EOK; 428 } 429 430 /** Insert endpoint pair into map with llink as key. 431 * 432 * If local port number is not specified, it is allocated. 433 * 434 * @param map Association map 435 * @param epp Endpoint pair, possibly with local port inet_port_any 436 * @param arg arg User value 437 * @param flags Flags 438 * @param aepp Place to store actual endpoint pair, possibly with allocated port 439 * 440 * @return EOK on success, EEXIST if conflicting epp exists, 441 * ENOMEM if out of memory 442 */ 443 static int amap_insert_llink(amap_t *map, inet_ep2_t *epp, void *arg, 444 amap_flags_t flags, inet_ep2_t *aepp) 445 { 446 amap_llink_t *llink; 447 inet_ep2_t mepp; 448 int rc; 449 450 log_msg(LOG_DEFAULT, LVL_DEBUG2, "amap_insert_llink()"); 451 452 rc = amap_llink_find(map, epp->local_link, &llink); 453 if (rc != EOK) { 454 /* New llink */ 455 rc = amap_llink_insert(map, epp->local_link, &llink); 456 if (rc != EOK) { 457 assert(rc == ENOMEM); 458 return rc; 459 } 460 } 461 462 mepp = *epp; 463 464 rc = portrng_alloc(llink->portrng, epp->local.port, arg, flags, 465 &mepp.local.port); 466 if (rc != EOK) { 467 return rc; 468 } 469 470 *aepp = mepp; 471 return EOK; 472 } 473 474 /** Insert endpoint pair into map with unspec as key. 475 * 476 * If local port number is not specified, it is allocated. 477 * 478 * @param map Association map 479 * @param epp Endpoint pair, possibly with local port inet_port_any 480 * @param arg arg User value 481 * @param flags Flags 482 * @param aepp Place to store actual endpoint pair, possibly with allocated port 483 * 484 * @return EOK on success, EEXIST if conflicting epp exists, 485 * ENOMEM if out of memory 486 */ 487 static int amap_insert_unspec(amap_t *map, inet_ep2_t *epp, void *arg, 488 amap_flags_t flags, inet_ep2_t *aepp) 489 { 490 inet_ep2_t mepp; 491 int rc; 492 493 log_msg(LOG_DEFAULT, LVL_DEBUG2, "amap_insert_unspec()"); 494 mepp = *epp; 495 496 rc = portrng_alloc(map->unspec, epp->local.port, arg, flags, 497 &mepp.local.port); 498 if (rc != EOK) { 499 return rc; 500 } 501 502 *aepp = mepp; 503 return EOK; 504 } 505 506 /** Insert endpoint pair into map. 507 * 508 * If local endpoint is not fully specified, it is filled in (determine 509 * source address, allocate port number). Checks for conflicting endpoint pair. 510 * 511 * @param map Association map 512 * @param epp Endpoint pair, possibly with local port inet_port_any 513 * @param arg arg User value 514 * @param flags Flags 515 * @param aepp Place to store actual endpoint pair, possibly with allocated port 516 * 517 * @return EOK on success, EEXIST if conflicting epp exists, 366 * @return EOK on success, EEXISTS if conflicting epp exists, 518 367 * ENOMEM if out of memory 519 368 */ … … 568 417 } 569 418 570 /** Remove endpoint pair using repla as key from map.571 *572 * The endpoint pair must be present in the map, otherwise behavior573 * is unspecified.574 *575 * @param map Association map576 * @param epp Endpoint pair577 */578 419 static void amap_remove_repla(amap_t *map, inet_ep2_t *epp) 579 420 { … … 593 434 } 594 435 595 /** Remove endpoint pair using laddr as key from map.596 *597 * The endpoint pair must be present in the map, otherwise behavior598 * is unspecified.599 *600 * @param map Association map601 * @param epp Endpoint pair602 */603 436 static void amap_remove_laddr(amap_t *map, inet_ep2_t *epp) 604 437 { … … 618 451 } 619 452 620 /** Remove endpoint pair using llink as key from map.621 *622 * The endpoint pair must be present in the map, otherwise behavior623 * is unspecified.624 *625 * @param map Association map626 * @param epp Endpoint pair627 */628 453 static void amap_remove_llink(amap_t *map, inet_ep2_t *epp) 629 454 { … … 643 468 } 644 469 645 /** Remove endpoint pair using unspec as key from map.646 *647 * The endpoint pair must be present in the map, otherwise behavior648 * is unspecified.649 *650 * @param map Association map651 * @param epp Endpoint pair652 */653 470 static void amap_remove_unspec(amap_t *map, inet_ep2_t *epp) 654 471 { … … 656 473 } 657 474 658 /** Remove endpoint pair from map.659 *660 * The endpoint pair must be present in the map, otherwise behavior661 * is unspecified.662 *663 * @param map Association map664 * @param epp Endpoint pair665 */666 475 void amap_remove(amap_t *map, inet_ep2_t *epp) 667 476 {
Note:
See TracChangeset
for help on using the changeset viewer.