summaryrefslogtreecommitdiffstats
path: root/sys/netinet/in_pcb.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/netinet/in_pcb.c')
-rw-r--r--sys/netinet/in_pcb.c57
1 files changed, 28 insertions, 29 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index 4a7e4f9..25494cf 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -325,8 +325,9 @@ in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp,
if (sin->sin_family != AF_INET)
return (EAFNOSUPPORT);
#endif
- if (prison_local_ip4(cred, &sin->sin_addr))
- return (EINVAL);
+ error = prison_local_ip4(cred, &sin->sin_addr);
+ if (error)
+ return (error);
if (sin->sin_port != *lportp) {
/* Don't allow the port to change. */
if (*lportp != 0)
@@ -391,8 +392,9 @@ in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp,
t->inp_cred->cr_uid))
return (EADDRINUSE);
}
- if (prison_local_ip4(cred, &sin->sin_addr))
- return (EADDRNOTAVAIL);
+ error = prison_local_ip4(cred, &sin->sin_addr);
+ if (error)
+ return (error);
t = in_pcblookup_local(pcbinfo, sin->sin_addr,
lport, wild, cred);
if (t && (t->inp_vflag & INP_TIMEWAIT)) {
@@ -426,8 +428,9 @@ in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp,
u_short first, last, aux;
int count;
- if (prison_local_ip4(cred, &laddr))
- return (EINVAL);
+ error = prison_local_ip4(cred, &laddr);
+ if (error)
+ return (error);
if (inp->inp_flags & INP_HIGHPORT) {
first = V_ipport_hifirstauto; /* sysctl */
@@ -493,8 +496,9 @@ in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp,
} while (in_pcblookup_local(pcbinfo, laddr,
lport, wild, cred));
}
- if (prison_local_ip4(cred, &laddr))
- return (EINVAL);
+ error = prison_local_ip4(cred, &laddr);
+ if (error)
+ return (error);
*laddrp = laddr.s_addr;
*lportp = lport;
return (0);
@@ -614,7 +618,7 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr,
if (sa->sa_family != AF_INET)
continue;
sin = (struct sockaddr_in *)sa;
- if (prison_check_ip4(cred, &sin->sin_addr)) {
+ if (prison_check_ip4(cred, &sin->sin_addr) == 0) {
ia = (struct in_ifaddr *)ifa;
break;
}
@@ -625,8 +629,7 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr,
}
/* 3. As a last resort return the 'default' jail address. */
- if (prison_get_ip4(cred, laddr) != 0)
- error = EADDRNOTAVAIL;
+ error = prison_get_ip4(cred, laddr);
goto done;
}
@@ -651,7 +654,7 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr,
/* Jailed. */
/* 1. Check if the iface address belongs to the jail. */
sin = (struct sockaddr_in *)sro.ro_rt->rt_ifa->ifa_addr;
- if (prison_check_ip4(cred, &sin->sin_addr)) {
+ if (prison_check_ip4(cred, &sin->sin_addr) == 0) {
ia = (struct in_ifaddr *)sro.ro_rt->rt_ifa;
laddr->s_addr = ia->ia_addr.sin_addr.s_addr;
goto done;
@@ -667,7 +670,7 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr,
if (sa->sa_family != AF_INET)
continue;
sin = (struct sockaddr_in *)sa;
- if (prison_check_ip4(cred, &sin->sin_addr)) {
+ if (prison_check_ip4(cred, &sin->sin_addr) == 0) {
ia = (struct in_ifaddr *)ifa;
break;
}
@@ -678,8 +681,7 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr,
}
/* 3. As a last resort return the 'default' jail address. */
- if (prison_get_ip4(cred, laddr) != 0)
- error = EADDRNOTAVAIL;
+ error = prison_get_ip4(cred, laddr);
goto done;
}
@@ -729,7 +731,8 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr,
if (sa->sa_family != AF_INET)
continue;
sin = (struct sockaddr_in *)sa;
- if (prison_check_ip4(cred, &sin->sin_addr)) {
+ if (prison_check_ip4(cred,
+ &sin->sin_addr) == 0) {
ia = (struct in_ifaddr *)ifa;
break;
}
@@ -741,8 +744,7 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr,
}
/* 3. As a last resort return the 'default' jail address. */
- if (prison_get_ip4(cred, laddr) != 0)
- error = EADDRNOTAVAIL;
+ error = prison_get_ip4(cred, laddr);
goto done;
}
@@ -776,7 +778,7 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam,
struct sockaddr_in *sin = (struct sockaddr_in *)nam;
struct in_ifaddr *ia;
struct inpcb *oinp;
- struct in_addr laddr, faddr, jailia;
+ struct in_addr laddr, faddr;
u_short lport, fport;
int error;
@@ -809,15 +811,11 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam,
* choose the broadcast address for that interface.
*/
if (faddr.s_addr == INADDR_ANY) {
- if (cred != NULL && jailed(cred)) {
- if (prison_get_ip4(cred, &jailia) != 0)
- return (EADDRNOTAVAIL);
- faddr.s_addr = jailia.s_addr;
- } else {
- faddr =
- IA_SIN(TAILQ_FIRST(&V_in_ifaddrhead))->
- sin_addr;
- }
+ faddr =
+ IA_SIN(TAILQ_FIRST(&V_in_ifaddrhead))->sin_addr;
+ if (cred != NULL &&
+ (error = prison_get_ip4(cred, &faddr)) != 0)
+ return (error);
} else if (faddr.s_addr == (u_long)INADDR_BROADCAST &&
(TAILQ_FIRST(&V_in_ifaddrhead)->ia_ifp->if_flags &
IFF_BROADCAST))
@@ -1375,7 +1373,8 @@ in_pcblookup_hash(struct inpcbinfo *pcbinfo, struct in_addr faddr,
injail = jailed(inp->inp_cred);
if (injail) {
- if (!prison_check_ip4(inp->inp_cred, &laddr))
+ if (prison_check_ip4(inp->inp_cred,
+ &laddr) != 0)
continue;
} else {
if (local_exact != NULL)
OpenPOWER on IntegriCloud