Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/in_jail.c
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | prison_qcmp_v4(const void *ip1, const void *ip2) | ||||
else | else | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Restrict a prison's IP address list with its parent's, possibly replacing | * Restrict a prison's IP address list with its parent's, possibly replacing | ||||
* it. Return true if the replacement buffer was used (or would have been). | * it. Return true if the replacement buffer was used (or would have been). | ||||
*/ | */ | ||||
int | bool | ||||
prison_restrict_ip4(struct prison *pr, struct in_addr *newip4) | prison_restrict_ip4(struct prison *pr, struct in_addr *newip4) | ||||
{ | { | ||||
int ii, ij, used; | int ii, ij; | ||||
bool used; | |||||
struct prison *ppr; | struct prison *ppr; | ||||
ppr = pr->pr_parent; | ppr = pr->pr_parent; | ||||
if (!(pr->pr_flags & PR_IP4_USER)) { | if (!(pr->pr_flags & PR_IP4_USER)) { | ||||
/* This has no user settings, so just copy the parent's list. */ | /* This has no user settings, so just copy the parent's list. */ | ||||
if (pr->pr_ip4s < ppr->pr_ip4s) { | if (pr->pr_ip4s < ppr->pr_ip4s) { | ||||
/* | /* | ||||
* There's no room for the parent's list. Use the | * There's no room for the parent's list. Use the | ||||
* new list buffer, which is assumed to be big enough | * new list buffer, which is assumed to be big enough | ||||
* (if it was passed). If there's no buffer, try to | * (if it was passed). If there's no buffer, try to | ||||
* allocate one. | * allocate one. | ||||
*/ | */ | ||||
used = 1; | used = true; | ||||
if (newip4 == NULL) { | if (newip4 == NULL) { | ||||
newip4 = malloc(ppr->pr_ip4s * sizeof(*newip4), | newip4 = malloc(ppr->pr_ip4s * sizeof(*newip4), | ||||
M_PRISON, M_NOWAIT); | M_PRISON, M_NOWAIT); | ||||
if (newip4 != NULL) | if (newip4 != NULL) | ||||
used = 0; | used = false; | ||||
} | } | ||||
if (newip4 != NULL) { | if (newip4 != NULL) { | ||||
bcopy(ppr->pr_ip4, newip4, | bcopy(ppr->pr_ip4, newip4, | ||||
ppr->pr_ip4s * sizeof(*newip4)); | ppr->pr_ip4s * sizeof(*newip4)); | ||||
free(pr->pr_ip4, M_PRISON); | free(pr->pr_ip4, M_PRISON); | ||||
pr->pr_ip4 = newip4; | pr->pr_ip4 = newip4; | ||||
pr->pr_ip4s = ppr->pr_ip4s; | pr->pr_ip4s = ppr->pr_ip4s; | ||||
} | } | ||||
Show All 39 Lines | for (ij = 1; ii < pr->pr_ip4s; ) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (pr->pr_ip4s == 0) { | if (pr->pr_ip4s == 0) { | ||||
free(pr->pr_ip4, M_PRISON); | free(pr->pr_ip4, M_PRISON); | ||||
pr->pr_ip4 = NULL; | pr->pr_ip4 = NULL; | ||||
} | } | ||||
} | } | ||||
return (0); | return (false); | ||||
} | } | ||||
/* | /* | ||||
* Pass back primary IPv4 address of this jail. | * Pass back primary IPv4 address of this jail. | ||||
* | * | ||||
* If not restricted return success but do not alter the address. Caller has | * If not restricted return success but do not alter the address. Caller has | ||||
* to make sure to initialize it correctly (e.g. INADDR_ANY). | * to make sure to initialize it correctly (e.g. INADDR_ANY). | ||||
* | * | ||||
Show All 22 Lines | prison_get_ip4(struct ucred *cred, struct in_addr *ia) | ||||
} | } | ||||
ia->s_addr = pr->pr_ip4[0].s_addr; | ia->s_addr = pr->pr_ip4[0].s_addr; | ||||
mtx_unlock(&pr->pr_mtx); | mtx_unlock(&pr->pr_mtx); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Return 1 if we should do proper source address selection or are not jailed. | * Return true 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 | * We will return false if we should bypass source address selection in favour | ||||
* of the primary jail IPv4 address. Only in this case *ia will be updated and | * of the primary jail IPv4 address. Only in this case *ia will be updated and | ||||
* returned in NBO. | * returned in NBO. | ||||
* Return EAFNOSUPPORT, in case this jail does not allow IPv4. | * Return true, even in case this jail does not allow IPv4. | ||||
*/ | */ | ||||
int | bool | ||||
freebsd_igalic.co: this is still saying int not bool | |||||
prison_saddrsel_ip4(struct ucred *cred, struct in_addr *ia) | prison_saddrsel_ip4(struct ucred *cred, struct in_addr *ia) | ||||
{ | { | ||||
struct prison *pr; | struct prison *pr; | ||||
struct in_addr lia; | struct in_addr lia; | ||||
int error; | |||||
KASSERT(cred != NULL, ("%s: cred is NULL", __func__)); | KASSERT(cred != NULL, ("%s: cred is NULL", __func__)); | ||||
KASSERT(ia != NULL, ("%s: ia is NULL", __func__)); | KASSERT(ia != NULL, ("%s: ia is NULL", __func__)); | ||||
if (!jailed(cred)) | if (!jailed(cred)) | ||||
return (1); | return (true); | ||||
pr = cred->cr_prison; | pr = cred->cr_prison; | ||||
if (pr->pr_flags & PR_IP4_SADDRSEL) | if (pr->pr_flags & PR_IP4_SADDRSEL) | ||||
return (1); | return (true); | ||||
lia.s_addr = INADDR_ANY; | lia.s_addr = INADDR_ANY; | ||||
error = prison_get_ip4(cred, &lia); | if (prison_get_ip4(cred, &lia)) | ||||
jamieUnsubmitted Done Inline ActionsEven though it's redundant, there should be a "!= 0" here (and in the ip6 version), which makes it clear that prison_get_ip4() isn't boolean itself, hinting that it's a function that normally returns zero. jamie: Even though it's redundant, there should be a "!= 0" here (and in the ip6 version), which makes… | |||||
if (error) | return (true); | ||||
return (error); | |||||
if (lia.s_addr == INADDR_ANY) | if (lia.s_addr == INADDR_ANY) | ||||
return (1); | return (true); | ||||
ia->s_addr = lia.s_addr; | ia->s_addr = lia.s_addr; | ||||
return (0); | return (false); | ||||
} | } | ||||
/* | /* | ||||
* Return true if pr1 and pr2 have the same IPv4 address restrictions. | * Return true if pr1 and pr2 have the same IPv4 address restrictions. | ||||
*/ | */ | ||||
int | bool | ||||
prison_equal_ip4(struct prison *pr1, struct prison *pr2) | prison_equal_ip4(struct prison *pr1, struct prison *pr2) | ||||
{ | { | ||||
if (pr1 == pr2) | if (pr1 == pr2) | ||||
return (1); | return (true); | ||||
/* | /* | ||||
* No need to lock since the PR_IP4_USER flag can't be altered for | * No need to lock since the PR_IP4_USER flag can't be altered for | ||||
* existing prisons. | * existing prisons. | ||||
*/ | */ | ||||
while (pr1 != &prison0 && | while (pr1 != &prison0 && | ||||
#ifdef VIMAGE | #ifdef VIMAGE | ||||
!(pr1->pr_flags & PR_VNET) && | !(pr1->pr_flags & PR_VNET) && | ||||
▲ Show 20 Lines • Show All 168 Lines • Show Last 20 Lines |
this is still saying int not bool