Rename dup_sockaddr() to sodupsockaddr() for consistency with other
functions in kern_socket.c. Rename the "canwait" field to "mflags" and pass M_WAITOK and M_NOWAIT in from the caller context rather than "1" or "0". Correct mflags pass into mac_init_socket() from previous commit to not include M_ZERO. Submitted by: sam
This commit is contained in:
parent
540d46e681
commit
52c4eeabc0
@ -199,7 +199,8 @@ portal_connect(so, so2)
|
||||
unp3 = sotounpcb(so3);
|
||||
if (unp2->unp_addr)
|
||||
unp3->unp_addr = (struct sockaddr_un *)
|
||||
dup_sockaddr((struct sockaddr *)unp2->unp_addr, 0);
|
||||
sodupsockaddr((struct sockaddr *)unp2->unp_addr,
|
||||
M_NOWAIT);
|
||||
so2 = so3;
|
||||
|
||||
return (unp_connect2(so, so2));
|
||||
|
@ -1061,14 +1061,11 @@ pru_sosetlabel_null(struct socket *so)
|
||||
* Make a copy of a sockaddr in a malloced buffer of type M_SONAME.
|
||||
*/
|
||||
struct sockaddr *
|
||||
dup_sockaddr(sa, canwait)
|
||||
struct sockaddr *sa;
|
||||
int canwait;
|
||||
sodupsockaddr(const struct sockaddr *sa, int mflags)
|
||||
{
|
||||
struct sockaddr *sa2;
|
||||
|
||||
MALLOC(sa2, struct sockaddr *, sa->sa_len, M_SONAME,
|
||||
canwait ? M_WAITOK : M_NOWAIT);
|
||||
sa2 = malloc(sa->sa_len, M_SONAME, mflags);
|
||||
if (sa2)
|
||||
bcopy(sa, sa2, sa->sa_len);
|
||||
return sa2;
|
||||
|
@ -138,7 +138,7 @@ soalloc(int mflags)
|
||||
so = uma_zalloc(socket_zone, mflags | M_ZERO);
|
||||
if (so) {
|
||||
#ifdef MAC
|
||||
error = mac_init_socket(so, mflags | M_ZERO);
|
||||
error = mac_init_socket(so, mflags);
|
||||
if (error != 0) {
|
||||
uma_zfree(socket_zone, so);
|
||||
so = NULL;
|
||||
@ -908,8 +908,8 @@ soreceive(so, psa, uio, mp0, controlp, flagsp)
|
||||
("m->m_type == %d", m->m_type));
|
||||
orig_resid = 0;
|
||||
if (psa)
|
||||
*psa = dup_sockaddr(mtod(m, struct sockaddr *),
|
||||
mp0 == 0);
|
||||
*psa = sodupsockaddr(mtod(m, struct sockaddr *),
|
||||
mp0 == NULL ? M_WAITOK : M_NOWAIT);
|
||||
if (flags & MSG_PEEK) {
|
||||
m = m->m_next;
|
||||
} else {
|
||||
|
@ -1061,14 +1061,11 @@ pru_sosetlabel_null(struct socket *so)
|
||||
* Make a copy of a sockaddr in a malloced buffer of type M_SONAME.
|
||||
*/
|
||||
struct sockaddr *
|
||||
dup_sockaddr(sa, canwait)
|
||||
struct sockaddr *sa;
|
||||
int canwait;
|
||||
sodupsockaddr(const struct sockaddr *sa, int mflags)
|
||||
{
|
||||
struct sockaddr *sa2;
|
||||
|
||||
MALLOC(sa2, struct sockaddr *, sa->sa_len, M_SONAME,
|
||||
canwait ? M_WAITOK : M_NOWAIT);
|
||||
sa2 = malloc(sa->sa_len, M_SONAME, mflags);
|
||||
if (sa2)
|
||||
bcopy(sa, sa2, sa->sa_len);
|
||||
return sa2;
|
||||
|
@ -127,10 +127,11 @@ uipc_accept(struct socket *so, struct sockaddr **nam)
|
||||
* (our peer may have closed already!).
|
||||
*/
|
||||
if (unp->unp_conn && unp->unp_conn->unp_addr) {
|
||||
*nam = dup_sockaddr((struct sockaddr *)unp->unp_conn->unp_addr,
|
||||
1);
|
||||
*nam = sodupsockaddr(
|
||||
(struct sockaddr *)unp->unp_conn->unp_addr, M_WAITOK);
|
||||
} else {
|
||||
*nam = dup_sockaddr((struct sockaddr *)&sun_noname, 1);
|
||||
*nam = sodupsockaddr((struct sockaddr *)&sun_noname,
|
||||
M_WAITOK);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@ -220,15 +221,16 @@ uipc_peeraddr(struct socket *so, struct sockaddr **nam)
|
||||
if (unp == 0)
|
||||
return (EINVAL);
|
||||
if (unp->unp_conn && unp->unp_conn->unp_addr)
|
||||
*nam = dup_sockaddr((struct sockaddr *)unp->unp_conn->unp_addr,
|
||||
1);
|
||||
*nam = sodupsockaddr(
|
||||
(struct sockaddr *)unp->unp_conn->unp_addr, M_WAITOK);
|
||||
else {
|
||||
/*
|
||||
* XXX: It seems that this test always fails even when
|
||||
* connection is established. So, this else clause is
|
||||
* added as workaround to return PF_LOCAL sockaddr.
|
||||
*/
|
||||
*nam = dup_sockaddr((struct sockaddr *)&sun_noname, 1);
|
||||
*nam = sodupsockaddr((struct sockaddr *)&sun_noname,
|
||||
M_WAITOK);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@ -441,9 +443,11 @@ uipc_sockaddr(struct socket *so, struct sockaddr **nam)
|
||||
if (unp == 0)
|
||||
return (EINVAL);
|
||||
if (unp->unp_addr)
|
||||
*nam = dup_sockaddr((struct sockaddr *)unp->unp_addr, 1);
|
||||
*nam = sodupsockaddr((struct sockaddr *)unp->unp_addr,
|
||||
M_WAITOK);
|
||||
else
|
||||
*nam = dup_sockaddr((struct sockaddr *)&sun_noname, 1);
|
||||
*nam = sodupsockaddr((struct sockaddr *)&sun_noname,
|
||||
M_WAITOK);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -665,7 +669,7 @@ unp_bind(unp, nam, td)
|
||||
vp = nd.ni_vp;
|
||||
vp->v_socket = unp->unp_socket;
|
||||
unp->unp_vnode = vp;
|
||||
unp->unp_addr = (struct sockaddr_un *)dup_sockaddr(nam, 1);
|
||||
unp->unp_addr = (struct sockaddr_un *)sodupsockaddr(nam, M_WAITOK);
|
||||
VOP_UNLOCK(vp, 0, td);
|
||||
vn_finished_write(mp);
|
||||
free(buf, M_TEMP);
|
||||
@ -724,8 +728,8 @@ unp_connect(so, nam, td)
|
||||
unp3 = sotounpcb(so3);
|
||||
if (unp2->unp_addr)
|
||||
unp3->unp_addr = (struct sockaddr_un *)
|
||||
dup_sockaddr((struct sockaddr *)
|
||||
unp2->unp_addr, 1);
|
||||
sodupsockaddr((struct sockaddr *)unp2->unp_addr,
|
||||
M_WAITOK);
|
||||
|
||||
/*
|
||||
* unp_peercred management:
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/signalvar.h>
|
||||
@ -216,7 +217,7 @@ raw_upeeraddr(struct socket *so, struct sockaddr **nam)
|
||||
if (rp->rcb_faddr == 0) {
|
||||
return ENOTCONN;
|
||||
}
|
||||
*nam = dup_sockaddr(rp->rcb_faddr, 1);
|
||||
*nam = sodupsockaddr(rp->rcb_faddr, M_WAITOK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -286,7 +287,7 @@ raw_usockaddr(struct socket *so, struct sockaddr **nam)
|
||||
return EINVAL;
|
||||
if (rp->rcb_laddr == 0)
|
||||
return EINVAL;
|
||||
*nam = dup_sockaddr(rp->rcb_laddr, 1);
|
||||
*nam = sodupsockaddr(rp->rcb_laddr, M_WAITOK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ ddp_abort(struct socket *so)
|
||||
static void
|
||||
at_sockaddr(struct ddpcb *ddp, struct sockaddr **addr)
|
||||
{
|
||||
*addr = dup_sockaddr((struct sockaddr *)&ddp->ddp_lsat, 0);
|
||||
*addr = sodupsockaddr((struct sockaddr *)&ddp->ddp_lsat, M_NOWAIT);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -216,7 +216,7 @@ ddp_abort(struct socket *so)
|
||||
static void
|
||||
at_sockaddr(struct ddpcb *ddp, struct sockaddr **addr)
|
||||
{
|
||||
*addr = dup_sockaddr((struct sockaddr *)&ddp->ddp_lsat, 0);
|
||||
*addr = sodupsockaddr((struct sockaddr *)&ddp->ddp_lsat, M_NOWAIT);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1560,7 +1560,7 @@ ng_btsocket_hci_raw_sockaddr(struct socket *so, struct sockaddr **nam)
|
||||
sa.hci_family = AF_BLUETOOTH;
|
||||
strlcpy(sa.hci_node, pcb->addr.hci_node, sizeof(sa.hci_node));
|
||||
|
||||
*nam = dup_sockaddr((struct sockaddr *) &sa, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *) &sa, M_NOWAIT);
|
||||
|
||||
return ((*nam == NULL)? ENOMEM : 0);
|
||||
} /* ng_btsocket_hci_raw_sockaddr */
|
||||
|
@ -2435,7 +2435,7 @@ ng_btsocket_l2cap_peeraddr(struct socket *so, struct sockaddr **nam)
|
||||
sa.l2cap_len = sizeof(sa);
|
||||
sa.l2cap_family = AF_BLUETOOTH;
|
||||
|
||||
*nam = dup_sockaddr((struct sockaddr *) &sa, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *) &sa, M_NOWAIT);
|
||||
|
||||
return ((*nam == NULL)? ENOMEM : 0);
|
||||
} /* ng_btsocket_l2cap_peeraddr */
|
||||
@ -2588,7 +2588,7 @@ ng_btsocket_l2cap_sockaddr(struct socket *so, struct sockaddr **nam)
|
||||
sa.l2cap_len = sizeof(sa);
|
||||
sa.l2cap_family = AF_BLUETOOTH;
|
||||
|
||||
*nam = dup_sockaddr((struct sockaddr *) &sa, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *) &sa, M_NOWAIT);
|
||||
|
||||
return ((*nam == NULL)? ENOMEM : 0);
|
||||
} /* ng_btsocket_l2cap_sockaddr */
|
||||
|
@ -1180,7 +1180,7 @@ ng_btsocket_l2cap_raw_peeraddr(struct socket *so, struct sockaddr **nam)
|
||||
sa.l2cap_len = sizeof(sa);
|
||||
sa.l2cap_family = AF_BLUETOOTH;
|
||||
|
||||
*nam = dup_sockaddr((struct sockaddr *) &sa, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *) &sa, M_NOWAIT);
|
||||
|
||||
return ((*nam == NULL)? ENOMEM : 0);
|
||||
} /* ng_btsocket_l2cap_raw_peeraddr */
|
||||
@ -1219,7 +1219,7 @@ ng_btsocket_l2cap_raw_sockaddr(struct socket *so, struct sockaddr **nam)
|
||||
sa.l2cap_len = sizeof(sa);
|
||||
sa.l2cap_family = AF_BLUETOOTH;
|
||||
|
||||
*nam = dup_sockaddr((struct sockaddr *) &sa, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *) &sa, M_NOWAIT);
|
||||
|
||||
return ((*nam == NULL)? ENOMEM : 0);
|
||||
} /* ng_btsocket_l2cap_raw_sockaddr */
|
||||
|
@ -879,7 +879,7 @@ ng_btsocket_rfcomm_peeraddr(struct socket *so, struct sockaddr **nam)
|
||||
sa.rfcomm_len = sizeof(sa);
|
||||
sa.rfcomm_family = AF_BLUETOOTH;
|
||||
|
||||
*nam = dup_sockaddr((struct sockaddr *) &sa, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *) &sa, M_NOWAIT);
|
||||
|
||||
return ((*nam == NULL)? ENOMEM : 0);
|
||||
} /* ng_btsocket_rfcomm_peeraddr */
|
||||
@ -945,7 +945,7 @@ ng_btsocket_rfcomm_sockaddr(struct socket *so, struct sockaddr **nam)
|
||||
sa.rfcomm_len = sizeof(sa);
|
||||
sa.rfcomm_family = AF_BLUETOOTH;
|
||||
|
||||
*nam = dup_sockaddr((struct sockaddr *) &sa, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *) &sa, M_NOWAIT);
|
||||
|
||||
return ((*nam == NULL)? ENOMEM : 0);
|
||||
} /* ng_btsocket_rfcomm_sockaddr */
|
||||
|
@ -288,7 +288,7 @@ ipx_setsockaddr(ipxp, nam)
|
||||
sipx->sipx_len = sizeof(*sipx);
|
||||
sipx->sipx_family = AF_IPX;
|
||||
sipx->sipx_addr = ipxp->ipxp_laddr;
|
||||
*nam = dup_sockaddr((struct sockaddr *)sipx, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *)sipx, M_NOWAIT);
|
||||
}
|
||||
|
||||
void
|
||||
@ -303,7 +303,7 @@ ipx_setpeeraddr(ipxp, nam)
|
||||
sipx->sipx_len = sizeof(*sipx);
|
||||
sipx->sipx_family = AF_IPX;
|
||||
sipx->sipx_addr = ipxp->ipxp_faddr;
|
||||
*nam = dup_sockaddr((struct sockaddr *)sipx, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *)sipx, M_NOWAIT);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1302,7 +1302,7 @@ spx_accept(so, nam)
|
||||
sipx->sipx_len = sizeof *sipx;
|
||||
sipx->sipx_family = AF_IPX;
|
||||
sipx->sipx_addr = ipxp->ipxp_faddr;
|
||||
*nam = dup_sockaddr((struct sockaddr *)sipx, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *)sipx, M_NOWAIT);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ natm_usr_peeraddr(struct socket *so, struct sockaddr **nam)
|
||||
sizeof(snatm->snatm_if));
|
||||
snatm->snatm_vci = npcb->npcb_vci;
|
||||
snatm->snatm_vpi = npcb->npcb_vpi;
|
||||
*nam = dup_sockaddr((struct sockaddr *)snatm, 0);
|
||||
*nam = sodupsockaddr((struct sockaddr *)snatm, M_NOWAIT);
|
||||
|
||||
out:
|
||||
splx(s);
|
||||
|
@ -419,10 +419,10 @@ smb_vc_create(struct smb_vcspec *vcspec,
|
||||
smb_sl_init(&vcp->vc_stlock, "vcstlock");
|
||||
error = ENOMEM;
|
||||
|
||||
vcp->vc_paddr = dup_sockaddr(vcspec->sap, 1);
|
||||
vcp->vc_paddr = sodupsockaddr(vcspec->sap, M_WAITOK);
|
||||
if (vcp->vc_paddr == NULL)
|
||||
goto fail;
|
||||
vcp->vc_laddr = dup_sockaddr(vcspec->lap, 1);
|
||||
vcp->vc_laddr = sodupsockaddr(vcspec->lap, M_WAITOK);
|
||||
if (vcp->vc_laddr == NULL)
|
||||
goto fail;
|
||||
vcp->vc_pass = smb_strdup(vcspec->pass);
|
||||
|
@ -564,7 +564,7 @@ smb_nbst_bind(struct smb_vc *vcp, struct sockaddr *sap, struct thread *td)
|
||||
slen = sap->sa_len;
|
||||
if (slen < NB_MINSALEN)
|
||||
break;
|
||||
snb = (struct sockaddr_nb*)dup_sockaddr(sap, 1);
|
||||
snb = (struct sockaddr_nb*)sodupsockaddr(sap, M_WAITOK);
|
||||
if (snb == NULL) {
|
||||
error = ENOMEM;
|
||||
break;
|
||||
@ -597,7 +597,7 @@ smb_nbst_connect(struct smb_vc *vcp, struct sockaddr *sap, struct thread *td)
|
||||
free(nbp->nbp_paddr, M_SONAME);
|
||||
nbp->nbp_paddr = NULL;
|
||||
}
|
||||
snb = (struct sockaddr_nb*)dup_sockaddr(sap, 1);
|
||||
snb = (struct sockaddr_nb*)sodupsockaddr(sap, M_WAITOK);
|
||||
if (snb == NULL)
|
||||
return ENOMEM;
|
||||
nbp->nbp_paddr = snb;
|
||||
|
@ -503,7 +503,7 @@ nfs_mountdiskless(char *path, char *which, int mountflag,
|
||||
|
||||
mp->mnt_kern_flag = 0;
|
||||
mp->mnt_flag = mountflag;
|
||||
nam = dup_sockaddr((struct sockaddr *)sin, 1);
|
||||
nam = sodupsockaddr((struct sockaddr *)sin, M_WAITOK);
|
||||
if ((error = mountnfs(args, mp, nam, which, path, vpp,
|
||||
td->td_ucred)) != 0) {
|
||||
printf("nfs_mountroot: mount %s on %s: %d", path, which, error);
|
||||
|
@ -50,7 +50,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/systm.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socketvar.h> /* for dup_sockaddr */
|
||||
#include <sys/socketvar.h> /* for sodupsockaddr */
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <nfs/rpcv2.h>
|
||||
@ -244,7 +244,7 @@ nfsrv_getcache(struct nfsrv_descript *nd, struct mbuf **repp)
|
||||
/* case AF_ISO: */
|
||||
default:
|
||||
rp->rc_flag |= RC_NAM;
|
||||
rp->rc_nam = dup_sockaddr(nd->nd_nam, 1);
|
||||
rp->rc_nam = sodupsockaddr(nd->nd_nam, M_WAITOK);
|
||||
break;
|
||||
};
|
||||
rp->rc_proc = nd->nd_procnum;
|
||||
|
@ -352,7 +352,6 @@ struct uio;
|
||||
/*
|
||||
* From uipc_socket and friends
|
||||
*/
|
||||
struct sockaddr *dup_sockaddr(struct sockaddr *sa, int canwait);
|
||||
int sockargs(struct mbuf **mp, caddr_t buf, int buflen, int type);
|
||||
int getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len);
|
||||
void sbappend(struct sockbuf *sb, struct mbuf *m);
|
||||
@ -391,6 +390,7 @@ int socreate(int dom, struct socket **aso, int type, int proto,
|
||||
struct ucred *cred, struct thread *td);
|
||||
void sodealloc(struct socket *so);
|
||||
int sodisconnect(struct socket *so);
|
||||
struct sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
|
||||
void sofree(struct socket *so);
|
||||
int sogetopt(struct socket *so, struct sockopt *sopt);
|
||||
void sohasoutofband(struct socket *so);
|
||||
|
Loading…
Reference in New Issue
Block a user