* Rewrite destination address in case we will connect to loopback address. * * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv6. */
| 319 | * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv6. |
| 320 | */ |
| 321 | int |
| 322 | prison_remote_ip6(struct ucred *cred, struct in6_addr *ia6) |
| 323 | { |
| 324 | struct prison *pr; |
| 325 | |
| 326 | KASSERT(cred != NULL, ("%s: cred is NULL", __func__)); |
| 327 | KASSERT(ia6 != NULL, ("%s: ia6 is NULL", __func__)); |
| 328 | |
| 329 | pr = cred->cr_prison; |
| 330 | if (!(pr->pr_flags & PR_IP6)) |
| 331 | return (0); |
| 332 | mtx_lock(&pr->pr_mtx); |
| 333 | if (!(pr->pr_flags & PR_IP6)) { |
| 334 | mtx_unlock(&pr->pr_mtx); |
| 335 | return (0); |
| 336 | } |
| 337 | if (pr->pr_ip6 == NULL) { |
| 338 | mtx_unlock(&pr->pr_mtx); |
| 339 | return (EAFNOSUPPORT); |
| 340 | } |
| 341 | |
| 342 | if (IN6_IS_ADDR_LOOPBACK(ia6) && |
| 343 | prison_check_ip6_locked(pr, ia6) == EADDRNOTAVAIL) { |
| 344 | bcopy(&pr->pr_ip6[0], ia6, sizeof(struct in6_addr)); |
| 345 | mtx_unlock(&pr->pr_mtx); |
| 346 | return (0); |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | * Return success because nothing had to be changed. |
| 351 | */ |
| 352 | mtx_unlock(&pr->pr_mtx); |
| 353 | return (0); |
| 354 | } |
| 355 | |
| 356 | /* |
| 357 | * Check if given address belongs to the jail referenced by cred/prison. |
no test coverage detected