* Return 1 if we should do proper source address selection or are not jailed. * We will return 0 if we should bypass source address selection in favour * of the primary jail IPv4 address. Only in this case *ia will be updated and * returned in NBO. * Return EAFNOSUPPORT, in case this jail does not allow IPv4. */
| 217 | * Return EAFNOSUPPORT, in case this jail does not allow IPv4. |
| 218 | */ |
| 219 | int |
| 220 | prison_saddrsel_ip4(struct ucred *cred, struct in_addr *ia) |
| 221 | { |
| 222 | struct prison *pr; |
| 223 | struct in_addr lia; |
| 224 | int error; |
| 225 | |
| 226 | KASSERT(cred != NULL, ("%s: cred is NULL", __func__)); |
| 227 | KASSERT(ia != NULL, ("%s: ia is NULL", __func__)); |
| 228 | |
| 229 | if (!jailed(cred)) |
| 230 | return (1); |
| 231 | |
| 232 | pr = cred->cr_prison; |
| 233 | if (pr->pr_flags & PR_IP4_SADDRSEL) |
| 234 | return (1); |
| 235 | |
| 236 | lia.s_addr = INADDR_ANY; |
| 237 | error = prison_get_ip4(cred, &lia); |
| 238 | if (error) |
| 239 | return (error); |
| 240 | if (lia.s_addr == INADDR_ANY) |
| 241 | return (1); |
| 242 | |
| 243 | ia->s_addr = lia.s_addr; |
| 244 | return (0); |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Return true if pr1 and pr2 have the same IPv4 address restrictions. |
no test coverage detected