* Pass back primary IPv4 address of this jail. * * If not restricted return success but do not alter the address. Caller has * to make sure to initialize it correctly (e.g. INADDR_ANY). * * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv4. * Address returned in NBO. */
| 184 | * Address returned in NBO. |
| 185 | */ |
| 186 | int |
| 187 | prison_get_ip4(struct ucred *cred, struct in_addr *ia) |
| 188 | { |
| 189 | struct prison *pr; |
| 190 | |
| 191 | KASSERT(cred != NULL, ("%s: cred is NULL", __func__)); |
| 192 | KASSERT(ia != NULL, ("%s: ia is NULL", __func__)); |
| 193 | |
| 194 | pr = cred->cr_prison; |
| 195 | if (!(pr->pr_flags & PR_IP4)) |
| 196 | return (0); |
| 197 | mtx_lock(&pr->pr_mtx); |
| 198 | if (!(pr->pr_flags & PR_IP4)) { |
| 199 | mtx_unlock(&pr->pr_mtx); |
| 200 | return (0); |
| 201 | } |
| 202 | if (pr->pr_ip4 == NULL) { |
| 203 | mtx_unlock(&pr->pr_mtx); |
| 204 | return (EAFNOSUPPORT); |
| 205 | } |
| 206 | |
| 207 | ia->s_addr = pr->pr_ip4[0].s_addr; |
| 208 | mtx_unlock(&pr->pr_mtx); |
| 209 | return (0); |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * Return 1 if we should do proper source address selection or are not jailed. |
no test coverage detected