summaryrefslogtreecommitdiffstats
path: root/sys/netinet/raw_ip.c
diff options
context:
space:
mode:
authorjamie <jamie@FreeBSD.org>2009-02-05 14:06:09 +0000
committerjamie <jamie@FreeBSD.org>2009-02-05 14:06:09 +0000
commit12bbe1869f5926ca7e3457f5424afdca31a1189b (patch)
tree71fe0b10296684e7094a545ca78ed6f72789d82d /sys/netinet/raw_ip.c
parent2926f8fa435de3f0b595eb5309b2a0c364703371 (diff)
downloadFreeBSD-src-12bbe1869f5926ca7e3457f5424afdca31a1189b.zip
FreeBSD-src-12bbe1869f5926ca7e3457f5424afdca31a1189b.tar.gz
Standardize the various prison_foo_ip[46] functions and prison_if to
return zero on success and an error code otherwise. The possible errors are EADDRNOTAVAIL if an address being checked for doesn't match the prison, and EAFNOSUPPORT if the prison doesn't have any addresses in that address family. For most callers of these functions, use the returned error code instead of e.g. a hard-coded EADDRNOTAVAIL or EINVAL. Always include a jailed() check in these functions, where a non-jailed cred always returns success (and makes no changes). Remove the explicit jailed() checks that preceded many of the function calls. Approved by: bz (mentor)
Diffstat (limited to 'sys/netinet/raw_ip.c')
-rw-r--r--sys/netinet/raw_ip.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
index 8f6d8ec..27f4b9c 100644
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -276,10 +276,8 @@ rip_input(struct mbuf *m, int off)
continue;
if (inp->inp_faddr.s_addr != ip->ip_src.s_addr)
continue;
- if (jailed(inp->inp_cred)) {
- if (!prison_check_ip4(inp->inp_cred, &ip->ip_dst))
- continue;
- }
+ if (prison_check_ip4(inp->inp_cred, &ip->ip_dst) != 0)
+ continue;
if (last != NULL) {
struct mbuf *n;
@@ -306,10 +304,8 @@ rip_input(struct mbuf *m, int off)
if (inp->inp_faddr.s_addr &&
inp->inp_faddr.s_addr != ip->ip_src.s_addr)
continue;
- if (jailed(inp->inp_cred)) {
- if (!prison_check_ip4(inp->inp_cred, &ip->ip_dst))
- continue;
- }
+ if (prison_check_ip4(inp->inp_cred, &ip->ip_dst) != 0)
+ continue;
if (last != NULL) {
struct mbuf *n;
@@ -370,14 +366,12 @@ rip_output(struct mbuf *m, struct socket *so, u_long dst)
ip->ip_off = 0;
ip->ip_p = inp->inp_ip_p;
ip->ip_len = m->m_pkthdr.len;
- if (jailed(inp->inp_cred)) {
- if (prison_get_ip4(inp->inp_cred, &ip->ip_src) != 0) {
- INP_RUNLOCK(inp);
- m_freem(m);
- return (EPERM);
- }
- } else {
- ip->ip_src = inp->inp_laddr;
+ ip->ip_src = inp->inp_laddr;
+ error = prison_get_ip4(inp->inp_cred, &ip->ip_src);
+ if (error != 0) {
+ INP_RUNLOCK(inp);
+ m_freem(m);
+ return (error);
}
ip->ip_dst.s_addr = dst;
ip->ip_ttl = inp->inp_ip_ttl;
@@ -388,10 +382,11 @@ rip_output(struct mbuf *m, struct socket *so, u_long dst)
}
INP_RLOCK(inp);
ip = mtod(m, struct ip *);
- if (!prison_check_ip4(inp->inp_cred, &ip->ip_src)) {
+ error = prison_check_ip4(inp->inp_cred, &ip->ip_src);
+ if (error != 0) {
INP_RUNLOCK(inp);
m_freem(m);
- return (EPERM);
+ return (error);
}
/*
@@ -803,12 +798,14 @@ rip_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
INIT_VNET_INET(so->so_vnet);
struct sockaddr_in *addr = (struct sockaddr_in *)nam;
struct inpcb *inp;
+ int error;
if (nam->sa_len != sizeof(*addr))
return (EINVAL);
- if (!prison_check_ip4(td->td_ucred, &addr->sin_addr))
- return (EADDRNOTAVAIL);
+ error = prison_check_ip4(td->td_ucred, &addr->sin_addr);
+ if (error != 0)
+ return (error);
if (TAILQ_EMPTY(&V_ifnet) ||
(addr->sin_family != AF_INET && addr->sin_family != AF_IMPLINK) ||
OpenPOWER on IntegriCloud