| 311 | } |
| 312 | |
| 313 | int |
| 314 | pf_map_addr(sa_family_t af, struct pf_krule *r, struct pf_addr *saddr, |
| 315 | struct pf_addr *naddr, struct pf_addr *init_addr, struct pf_ksrc_node **sn) |
| 316 | { |
| 317 | struct pf_kpool *rpool = &r->rpool; |
| 318 | struct pf_addr *raddr = NULL, *rmask = NULL; |
| 319 | |
| 320 | /* Try to find a src_node if none was given and this |
| 321 | is a sticky-address rule. */ |
| 322 | if (*sn == NULL && r->rpool.opts & PF_POOL_STICKYADDR && |
| 323 | (r->rpool.opts & PF_POOL_TYPEMASK) != PF_POOL_NONE) |
| 324 | *sn = pf_find_src_node(saddr, r, af, 0); |
| 325 | |
| 326 | /* If a src_node was found or explicitly given and it has a non-zero |
| 327 | route address, use this address. A zeroed address is found if the |
| 328 | src node was created just a moment ago in pf_create_state and it |
| 329 | needs to be filled in with routing decision calculated here. */ |
| 330 | if (*sn != NULL && !PF_AZERO(&(*sn)->raddr, af)) { |
| 331 | /* If the supplied address is the same as the current one we've |
| 332 | * been asked before, so tell the caller that there's no other |
| 333 | * address to be had. */ |
| 334 | if (PF_AEQ(naddr, &(*sn)->raddr, af)) |
| 335 | return (1); |
| 336 | |
| 337 | PF_ACPY(naddr, &(*sn)->raddr, af); |
| 338 | if (V_pf_status.debug >= PF_DEBUG_MISC) { |
| 339 | printf("pf_map_addr: src tracking maps "); |
| 340 | pf_print_host(saddr, 0, af); |
| 341 | printf(" to "); |
| 342 | pf_print_host(naddr, 0, af); |
| 343 | printf("\n"); |
| 344 | } |
| 345 | return (0); |
| 346 | } |
| 347 | |
| 348 | /* Find the route using chosen algorithm. Store the found route |
| 349 | in src_node if it was given or found. */ |
| 350 | if (rpool->cur->addr.type == PF_ADDR_NOROUTE) |
| 351 | return (1); |
| 352 | if (rpool->cur->addr.type == PF_ADDR_DYNIFTL) { |
| 353 | switch (af) { |
| 354 | #ifdef INET |
| 355 | case AF_INET: |
| 356 | if (rpool->cur->addr.p.dyn->pfid_acnt4 < 1 && |
| 357 | (rpool->opts & PF_POOL_TYPEMASK) != |
| 358 | PF_POOL_ROUNDROBIN) |
| 359 | return (1); |
| 360 | raddr = &rpool->cur->addr.p.dyn->pfid_addr4; |
| 361 | rmask = &rpool->cur->addr.p.dyn->pfid_mask4; |
| 362 | break; |
| 363 | #endif /* INET */ |
| 364 | #ifdef INET6 |
| 365 | case AF_INET6: |
| 366 | if (rpool->cur->addr.p.dyn->pfid_acnt6 < 1 && |
| 367 | (rpool->opts & PF_POOL_TYPEMASK) != |
| 368 | PF_POOL_ROUNDROBIN) |
| 369 | return (1); |
| 370 | raddr = &rpool->cur->addr.p.dyn->pfid_addr6; |
no test coverage detected