Reduce 'td' argument to 'cred' (struct ucred) argument in those functions:

- in_pcbbind(),
	- in_pcbbind_setup(),
	- in_pcbconnect(),
	- in_pcbconnect_setup(),
	- in6_pcbbind(),
	- in6_pcbconnect(),
	- in6_pcbsetport().
"It should simplify/clarify things a great deal." --rwatson

Requested by:	rwatson
Reviewed by:	rwatson, ume
This commit is contained in:
Pawel Jakub Dawidek 2004-03-27 21:05:46 +00:00
parent 6823b82399
commit b0330ed929
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=127505
11 changed files with 68 additions and 63 deletions

View File

@ -210,10 +210,10 @@ in_pcballoc(so, pcbinfo, type)
}
int
in_pcbbind(inp, nam, td)
in_pcbbind(inp, nam, cred)
register struct inpcb *inp;
struct sockaddr *nam;
struct thread *td;
struct ucred *cred;
{
int anonport, error;
@ -225,7 +225,7 @@ in_pcbbind(inp, nam, td)
anonport = inp->inp_lport == 0 && (nam == NULL ||
((struct sockaddr_in *)nam)->sin_port == 0);
error = in_pcbbind_setup(inp, nam, &inp->inp_laddr.s_addr,
&inp->inp_lport, td);
&inp->inp_lport, cred);
if (error)
return (error);
if (in_pcbinshash(inp) != 0) {
@ -248,12 +248,12 @@ in_pcbbind(inp, nam, td)
* On error, the values of *laddrp and *lportp are not changed.
*/
int
in_pcbbind_setup(inp, nam, laddrp, lportp, td)
in_pcbbind_setup(inp, nam, laddrp, lportp, cred)
struct inpcb *inp;
struct sockaddr *nam;
in_addr_t *laddrp;
u_short *lportp;
struct thread *td;
struct ucred *cred;
{
struct socket *so = inp->inp_socket;
unsigned short *lastport;
@ -287,7 +287,7 @@ in_pcbbind_setup(inp, nam, laddrp, lportp, td)
return (EAFNOSUPPORT);
#endif
if (sin->sin_addr.s_addr != INADDR_ANY)
if (prison_ip(td->td_ucred, 0, &sin->sin_addr.s_addr))
if (prison_ip(cred, 0, &sin->sin_addr.s_addr))
return(EINVAL);
if (sin->sin_port != *lportp) {
/* Don't allow the port to change. */
@ -318,9 +318,9 @@ in_pcbbind_setup(inp, nam, laddrp, lportp, td)
/* GROSS */
if (ntohs(lport) <= ipport_reservedhigh &&
ntohs(lport) >= ipport_reservedlow &&
td && suser_cred(td->td_ucred, PRISON_ROOT))
suser_cred(cred, PRISON_ROOT))
return (EACCES);
if (td && jailed(td->td_ucred))
if (jailed(cred))
prison = 1;
if (so->so_cred->cr_uid != 0 &&
!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
@ -356,8 +356,7 @@ in_pcbbind_setup(inp, nam, laddrp, lportp, td)
return (EADDRINUSE);
}
}
if (prison &&
prison_ip(td->td_ucred, 0, &sin->sin_addr.s_addr))
if (prison && prison_ip(cred, 0, &sin->sin_addr.s_addr))
return (EADDRNOTAVAIL);
t = in_pcblookup_local(pcbinfo, sin->sin_addr,
lport, prison ? 0 : wild);
@ -386,7 +385,7 @@ in_pcbbind_setup(inp, nam, laddrp, lportp, td)
int count;
if (laddr.s_addr != INADDR_ANY)
if (prison_ip(td->td_ucred, 0, &laddr.s_addr))
if (prison_ip(cred, 0, &laddr.s_addr))
return (EINVAL);
if (inp->inp_flags & INP_HIGHPORT) {
@ -394,8 +393,7 @@ in_pcbbind_setup(inp, nam, laddrp, lportp, td)
last = ipport_hilastauto;
lastport = &pcbinfo->lasthi;
} else if (inp->inp_flags & INP_LOWPORT) {
if (td && (error = suser_cred(td->td_ucred,
PRISON_ROOT)) != 0)
if ((error = suser_cred(cred, PRISON_ROOT)) != 0)
return error;
first = ipport_lowfirstauto; /* 1023 */
last = ipport_lowlastauto; /* 600 */
@ -444,7 +442,7 @@ in_pcbbind_setup(inp, nam, laddrp, lportp, td)
wild));
}
}
if (prison_ip(td->td_ucred, 0, &laddr.s_addr))
if (prison_ip(cred, 0, &laddr.s_addr))
return (EINVAL);
*laddrp = laddr.s_addr;
*lportp = lport;
@ -458,10 +456,10 @@ in_pcbbind_setup(inp, nam, laddrp, lportp, td)
* then pick one.
*/
int
in_pcbconnect(inp, nam, td)
in_pcbconnect(inp, nam, cred)
register struct inpcb *inp;
struct sockaddr *nam;
struct thread *td;
struct ucred *cred;
{
u_short lport, fport;
in_addr_t laddr, faddr;
@ -471,7 +469,7 @@ in_pcbconnect(inp, nam, td)
laddr = inp->inp_laddr.s_addr;
anonport = (lport == 0);
error = in_pcbconnect_setup(inp, nam, &laddr, &lport, &faddr, &fport,
NULL, td);
NULL, cred);
if (error)
return (error);
@ -517,7 +515,7 @@ in_pcbconnect(inp, nam, td)
* is set to NULL.
*/
int
in_pcbconnect_setup(inp, nam, laddrp, lportp, faddrp, fportp, oinpp, td)
in_pcbconnect_setup(inp, nam, laddrp, lportp, faddrp, fportp, oinpp, cred)
register struct inpcb *inp;
struct sockaddr *nam;
in_addr_t *laddrp;
@ -525,12 +523,12 @@ in_pcbconnect_setup(inp, nam, laddrp, lportp, faddrp, fportp, oinpp, td)
in_addr_t *faddrp;
u_short *fportp;
struct inpcb **oinpp;
struct thread *td;
struct ucred *cred;
{
struct sockaddr_in *sin = (struct sockaddr_in *)nam;
struct in_ifaddr *ia;
struct sockaddr_in sa;
struct ucred *cred;
struct ucred *socred;
struct inpcb *oinp;
struct in_addr laddr, faddr;
u_short lport, fport;
@ -548,14 +546,14 @@ in_pcbconnect_setup(inp, nam, laddrp, lportp, faddrp, fportp, oinpp, td)
lport = *lportp;
faddr = sin->sin_addr;
fport = sin->sin_port;
cred = inp->inp_socket->so_cred;
if (laddr.s_addr == INADDR_ANY && jailed(cred)) {
socred = inp->inp_socket->so_cred;
if (laddr.s_addr == INADDR_ANY && jailed(socred)) {
bzero(&sa, sizeof(sa));
sa.sin_addr.s_addr = htonl(prison_getip(cred));
sa.sin_addr.s_addr = htonl(prison_getip(socred));
sa.sin_len = sizeof(sa);
sa.sin_family = AF_INET;
error = in_pcbbind_setup(inp, (struct sockaddr *)&sa,
&laddr.s_addr, &lport, td);
&laddr.s_addr, &lport, cred);
if (error)
return (error);
}
@ -646,7 +644,8 @@ in_pcbconnect_setup(inp, nam, laddrp, lportp, faddrp, fportp, oinpp, td)
return (EADDRINUSE);
}
if (lport == 0) {
error = in_pcbbind_setup(inp, NULL, &laddr.s_addr, &lport, td);
error = in_pcbbind_setup(inp, NULL, &laddr.s_addr, &lport,
cred);
if (error)
return (error);
}

View File

@ -338,13 +338,13 @@ extern int ipport_hilastauto;
void in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *);
int in_pcballoc(struct socket *, struct inpcbinfo *, const char *);
int in_pcbbind(struct inpcb *, struct sockaddr *, struct thread *);
int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
int in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
u_short *, struct thread *);
int in_pcbconnect(struct inpcb *, struct sockaddr *, struct thread *);
u_short *, struct ucred *);
int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
int in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
u_short *, in_addr_t *, u_short *, struct inpcb **,
struct thread *);
struct ucred *);
void in_pcbdetach(struct inpcb *);
void in_pcbdisconnect(struct inpcb *);
int in_pcbinshash(struct inpcb *);

View File

@ -505,7 +505,7 @@ div_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
else {
((struct sockaddr_in *)nam)->sin_addr.s_addr = INADDR_ANY;
INP_LOCK(inp);
error = in_pcbbind(inp, nam, td);
error = in_pcbbind(inp, nam, td->td_ucred);
INP_UNLOCK(inp);
}
INP_INFO_WUNLOCK(&divcbinfo);

View File

@ -632,7 +632,8 @@ syncache_socket(sc, lso, m)
laddr6 = inp->in6p_laddr;
if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
inp->in6p_laddr = sc->sc_inc.inc6_laddr;
if (in6_pcbconnect(inp, (struct sockaddr *)&sin6, &thread0)) {
if (in6_pcbconnect(inp, (struct sockaddr *)&sin6,
thread0.td_ucred)) {
inp->in6p_laddr = laddr6;
goto abort;
}
@ -656,7 +657,8 @@ syncache_socket(sc, lso, m)
laddr = inp->inp_laddr;
if (inp->inp_laddr.s_addr == INADDR_ANY)
inp->inp_laddr = sc->sc_inc.inc_laddr;
if (in_pcbconnect(inp, (struct sockaddr *)&sin, &thread0)) {
if (in_pcbconnect(inp, (struct sockaddr *)&sin,
thread0.td_ucred)) {
inp->inp_laddr = laddr;
goto abort;
}

View File

@ -252,7 +252,7 @@ tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
error = EAFNOSUPPORT;
goto out;
}
error = in_pcbbind(inp, nam, td);
error = in_pcbbind(inp, nam, td->td_ucred);
if (error)
goto out;
COMMON_END(PRU_BIND);
@ -294,11 +294,12 @@ tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
in6_sin6_2_sin(&sin, sin6p);
inp->inp_vflag |= INP_IPV4;
inp->inp_vflag &= ~INP_IPV6;
error = in_pcbbind(inp, (struct sockaddr *)&sin, td);
error = in_pcbbind(inp, (struct sockaddr *)&sin,
td->td_ucred);
goto out;
}
}
error = in6_pcbbind(inp, nam, td);
error = in6_pcbbind(inp, nam, td->td_ucred);
if (error)
goto out;
COMMON_END(PRU_BIND);
@ -319,7 +320,7 @@ tcp_usr_listen(struct socket *so, struct thread *td)
COMMON_START();
if (inp->inp_lport == 0)
error = in_pcbbind(inp, (struct sockaddr *)0, td);
error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
if (error == 0)
tp->t_state = TCPS_LISTEN;
COMMON_END(PRU_LISTEN);
@ -340,7 +341,7 @@ tcp6_usr_listen(struct socket *so, struct thread *td)
inp->inp_vflag &= ~INP_IPV4;
if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
inp->inp_vflag |= INP_IPV4;
error = in6_pcbbind(inp, (struct sockaddr *)0, td);
error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
}
if (error == 0)
tp->t_state = TCPS_LISTEN;
@ -865,7 +866,7 @@ tcp_connect(tp, nam, td)
bzero(&tao, sizeof(tao));
if (inp->inp_lport == 0) {
error = in_pcbbind(inp, (struct sockaddr *)0, td);
error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
if (error)
return error;
}
@ -878,7 +879,7 @@ tcp_connect(tp, nam, td)
laddr = inp->inp_laddr;
lport = inp->inp_lport;
error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
&inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td);
&inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
if (error && oinp == NULL)
return error;
if (oinp) {
@ -949,7 +950,7 @@ tcp6_connect(tp, nam, td)
bzero(&tao, sizeof(tao));
if (inp->inp_lport == 0) {
error = in6_pcbbind(inp, (struct sockaddr *)0, td);
error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
if (error)
return error;
}

View File

@ -795,7 +795,7 @@ udp_output(inp, m, addr, control, td)
goto release;
}
error = in_pcbbind_setup(inp, (struct sockaddr *)&src,
&laddr.s_addr, &lport, td);
&laddr.s_addr, &lport, td->td_ucred);
if (error)
goto release;
}
@ -809,7 +809,7 @@ udp_output(inp, m, addr, control, td)
goto release;
}
error = in_pcbconnect_setup(inp, addr, &laddr.s_addr, &lport,
&faddr.s_addr, &fport, NULL, td);
&faddr.s_addr, &fport, NULL, td->td_ucred);
if (error)
goto release;
@ -970,7 +970,7 @@ udp_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
}
INP_LOCK(inp);
s = splnet();
error = in_pcbbind(inp, nam, td);
error = in_pcbbind(inp, nam, td->td_ucred);
splx(s);
INP_UNLOCK(inp);
INP_INFO_WUNLOCK(&udbinfo);
@ -1000,7 +1000,7 @@ udp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
sin = (struct sockaddr_in *)nam;
if (td && jailed(td->td_ucred))
prison_remote_ip(td->td_ucred, 0, &sin->sin_addr.s_addr);
error = in_pcbconnect(inp, nam, td);
error = in_pcbconnect(inp, nam, td->td_ucred);
splx(s);
if (error == 0)
soisconnected(so);

View File

@ -123,10 +123,10 @@
struct in6_addr zeroin6_addr;
int
in6_pcbbind(inp, nam, td)
in6_pcbbind(inp, nam, cred)
register struct inpcb *inp;
struct sockaddr *nam;
struct thread *td;
struct ucred *cred;
{
struct socket *so = inp->inp_socket;
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)NULL;
@ -190,8 +190,8 @@ in6_pcbbind(inp, nam, td)
struct inpcb *t;
/* GROSS */
if (ntohs(lport) < IPV6PORT_RESERVED && td &&
suser_cred(td->td_ucred, PRISON_ROOT))
if (ntohs(lport) < IPV6PORT_RESERVED &&
suser_cred(cred, PRISON_ROOT))
return (EACCES);
if (so->so_cred->cr_uid != 0 &&
!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
@ -274,7 +274,7 @@ in6_pcbbind(inp, nam, td)
}
if (lport == 0) {
int e;
if ((e = in6_pcbsetport(&inp->in6p_laddr, inp, td)) != 0)
if ((e = in6_pcbsetport(&inp->in6p_laddr, inp, cred)) != 0)
return (e);
}
else {
@ -360,10 +360,10 @@ in6_pcbladdr(inp, nam, plocal_addr6)
* then pick one.
*/
int
in6_pcbconnect(inp, nam, td)
in6_pcbconnect(inp, nam, cred)
register struct inpcb *inp;
struct sockaddr *nam;
struct thread *td;
struct ucred *cred;
{
struct in6_addr *addr6;
register struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
@ -385,7 +385,7 @@ in6_pcbconnect(inp, nam, td)
}
if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) {
if (inp->inp_lport == 0) {
error = in6_pcbbind(inp, (struct sockaddr *)0, td);
error = in6_pcbbind(inp, (struct sockaddr *)0, cred);
if (error)
return (error);
}

View File

@ -76,8 +76,8 @@
void in6_pcbpurgeif0 __P((struct in6pcb *, struct ifnet *));
void in6_losing __P((struct inpcb *));
int in6_pcbbind __P((struct inpcb *, struct sockaddr *, struct thread *));
int in6_pcbconnect __P((struct inpcb *, struct sockaddr *, struct thread *));
int in6_pcbbind __P((struct inpcb *, struct sockaddr *, struct ucred *));
int in6_pcbconnect __P((struct inpcb *, struct sockaddr *, struct ucred *));
void in6_pcbdetach __P((struct inpcb *));
void in6_pcbdisconnect __P((struct inpcb *));
int in6_pcbladdr __P((struct inpcb *, struct sockaddr *,
@ -103,7 +103,7 @@ int in6_setsockaddr __P((struct socket *so, struct sockaddr **nam));
int in6_mapped_sockaddr __P((struct socket *so, struct sockaddr **nam));
int in6_mapped_peeraddr __P((struct socket *so, struct sockaddr **nam));
int in6_selecthlim __P((struct in6pcb *, struct ifnet *));
int in6_pcbsetport __P((struct in6_addr *, struct inpcb *, struct thread *));
int in6_pcbsetport __P((struct in6_addr *, struct inpcb *, struct ucred *));
void init_sin6 __P((struct sockaddr_in6 *sin6, struct mbuf *m));
#endif /* _KERNEL */

View File

@ -742,10 +742,10 @@ in6_selecthlim(in6p, ifp)
* share this function by all *bsd*...
*/
int
in6_pcbsetport(laddr, inp, td)
in6_pcbsetport(laddr, inp, cred)
struct in6_addr *laddr;
struct inpcb *inp;
struct thread *td;
struct ucred *cred;
{
struct socket *so = inp->inp_socket;
u_int16_t lport = 0, first, last, *lastport;
@ -763,7 +763,7 @@ in6_pcbsetport(laddr, inp, td)
last = ipport_hilastauto;
lastport = &pcbinfo->lasthi;
} else if (inp->inp_flags & INP_LOWPORT) {
if (td && (error = suser(td)))
if ((error = suser_cred(cred, 0)))
return error;
first = ipport_lowfirstauto; /* 1023 */
last = ipport_lowlastauto; /* 600 */

View File

@ -70,6 +70,7 @@
#include "opt_inet6.h"
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/protosw.h>
@ -213,7 +214,7 @@ udp6_output(in6p, m, addr6, control, td)
goto release;
}
if (in6p->in6p_lport == 0 &&
(error = in6_pcbsetport(laddr, in6p, td)) != 0)
(error = in6_pcbsetport(laddr, in6p, td->td_ucred)) != 0)
goto release;
} else {
if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {

View File

@ -572,14 +572,15 @@ udp6_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
inp->inp_vflag |= INP_IPV4;
inp->inp_vflag &= ~INP_IPV6;
s = splnet();
error = in_pcbbind(inp, (struct sockaddr *)&sin, td);
error = in_pcbbind(inp, (struct sockaddr *)&sin,
td->td_ucred);
splx(s);
return error;
}
}
s = splnet();
error = in6_pcbbind(inp, nam, td);
error = in6_pcbbind(inp, nam, td->td_ucred);
splx(s);
return error;
}
@ -605,7 +606,8 @@ udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
return EISCONN;
in6_sin6_2_sin(&sin, sin6_p);
s = splnet();
error = in_pcbconnect(inp, (struct sockaddr *)&sin, td);
error = in_pcbconnect(inp, (struct sockaddr *)&sin,
td->td_ucred);
splx(s);
if (error == 0) {
inp->inp_vflag |= INP_IPV4;
@ -618,7 +620,7 @@ udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr))
return EISCONN;
s = splnet();
error = in6_pcbconnect(inp, nam, td);
error = in6_pcbconnect(inp, nam, td->td_ucred);
splx(s);
if (error == 0) {
if (!ip6_v6only) { /* should be non mapped addr */