X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/d7e50217d7adf6e52786a38bcaa4cd698cb9a79e..bd504ef0e0b883cdd7917b73b3574eb9ce669905:/bsd/netat/aurp_aurpd.c diff --git a/bsd/netat/aurp_aurpd.c b/bsd/netat/aurp_aurpd.c index 02a387be2..1fed65a63 100644 --- a/bsd/netat/aurp_aurpd.c +++ b/bsd/netat/aurp_aurpd.c @@ -1,16 +1,19 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2008 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER @@ -20,7 +23,7 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1996 Apple Computer, Inc. @@ -35,6 +38,7 @@ * Kernel process to implement the AURP daemon: * manage tunnels to remote AURP servers across IP networks */ +#ifdef AURP_SUPPORT #include #include @@ -43,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -51,11 +56,14 @@ #include #include #include +#include +#include #include #include #include #include +#include #include #include #include @@ -65,6 +73,8 @@ #define M_RCVBUF (64 * 1024) #define M_SNDBUF (64 * 1024) +extern lck_mtx_t * atalk_mutex; + static int ip_to_atalk(struct sockaddr_in *fp, register gbuf_t *p_mbuf); static int aurp_bindrp(struct socket *so); @@ -92,7 +102,7 @@ aurpd_start() int maxbuf; struct sockopt sopt; - if (suser(current_proc()->p_ucred, ¤t_proc()->p_acflag) != 0 ) + if (suser(kauth_cred_get(), 0) != 0 ) return(EPERM); /* @@ -101,7 +111,6 @@ aurpd_start() */ bzero((char *)&aurp_global.tunnel, sizeof(aurp_global.tunnel)); /*lock_alloc(&aurp_global.glock, LOCK_ALLOC_PIN, AURP_EVNT_LOCK, -1);*/ - ATLOCKINIT(aurp_global.glock); ATEVENTINIT(aurp_global.event_anchor); /* open udp socket */ @@ -137,12 +146,12 @@ aurpd_start() goto out; } else { maxbuf = M_RCVBUF; - sopt.sopt_val = &maxbuf; + sopt.sopt_val = CAST_USER_ADDR_T(&maxbuf); sopt.sopt_valsize = sizeof(maxbuf); sopt.sopt_level = SOL_SOCKET; sopt.sopt_name = SO_RCVBUF; sopt.sopt_dir = SOPT_SET; - sopt.sopt_p = NULL; + sopt.sopt_p = kernproc; if ((error = sosetopt(so, &sopt)) != 0) goto out; } @@ -157,12 +166,12 @@ aurpd_start() } else { maxbuf = M_SNDBUF; - sopt.sopt_val = &maxbuf; + sopt.sopt_val = CAST_USER_ADDR_T(&maxbuf); sopt.sopt_valsize = sizeof(maxbuf); sopt.sopt_level = SOL_SOCKET; sopt.sopt_name = SO_SNDBUF; sopt.sopt_dir = SOPT_SET; - sopt.sopt_p = NULL; + sopt.sopt_p = kernproc; if ((error = sosetopt(so, &sopt)) != 0) goto out; } @@ -174,8 +183,8 @@ aurpd_start() so->so_snd.sb_flags |=(SB_SEL|SB_NOINTR); out: - sbunlock(&so->so_snd); - sbunlock(&so->so_rcv); + sbunlock(&so->so_snd, 0); + sbunlock(&so->so_rcv, 0); return(error); } @@ -184,7 +193,7 @@ int AURPgetmsg(err) int *err; { register struct socket *so; - register int s, events; + register int events; so = aurp_global.tunnel; *err = 0; @@ -192,7 +201,8 @@ AURPgetmsg(err) for (;;) { gbuf_t *from, *p_mbuf; int flags = MSG_DONTWAIT; - struct uio auio; + uio_t auio; + char uio_buf[ UIO_SIZEOF(0) ]; /* * Wait for a package to arrive. This will be from the @@ -200,15 +210,14 @@ AURPgetmsg(err) * when a packet arrives */ - ATDISABLE(s, aurp_global.glock); events = aurp_global.event; if (((*err == 0) || (*err == EWOULDBLOCK)) && events == 0) { - *err = tsleep(&aurp_global.event_anchor, PSOCK | PCATCH, "AURPgetmsg", 0); + lck_mtx_assert(atalk_mutex, LCK_MTX_ASSERT_OWNED); + *err = msleep(&aurp_global.event_anchor, atalk_mutex, PSOCK | PCATCH, "AURPgetmsg", 0); events = aurp_global.event; aurp_global.event = 0; } - ATENABLE(s, aurp_global.glock); /* * Shut down if we have the AE_SHUTDOWN event or if we got @@ -240,11 +249,8 @@ AURPgetmsg(err) * give it no iov's, point off to non-existant user space, * but make sure the 'resid' count means somehting. */ - - auio.uio_iov = NULL; - auio.uio_iovcnt = 0; - auio.uio_segflg = UIO_SYSSPACE; - auio.uio_offset = 0; /* XXX */ + auio = uio_createwithbuffer(0, 0, UIO_SYSSPACE, UIO_READ, + &uio_buf[0], sizeof(uio_buf)); /* Keep up an even flow... */ for (;;) @@ -256,13 +262,13 @@ AURPgetmsg(err) #define A_LARGE_SIZE 700 flags = MSG_DONTWAIT; - auio.uio_resid = A_LARGE_SIZE; - *err = soreceive(so, (struct sockaddr **)&from, &auio, &p_mbuf, 0, &flags); + uio_setresid(auio, A_LARGE_SIZE); + *err = soreceive(so, (struct sockaddr **)&from, auio, &p_mbuf, 0, &flags); dPrintf(D_M_AURP, D_L_VERBOSE, ("AURPgetmsg: soreceive returned %d, aurp_global.event==0x%x\n", *err, events)); /* soreceive() sets *mp to zero! at start */ if (p_mbuf) - ip_to_atalk(from, p_mbuf); + ip_to_atalk((struct sockaddr_in *)from, p_mbuf); if (*err || (p_mbuf == NULL)) { /* * An error occurred in soreceive(), @@ -281,10 +287,7 @@ AURPgetmsg(err) * which will wake us from the sleep at * the top of the outer loop. */ - int s; - ATDISABLE(s, aurp_global.glock); aurp_global.event &= ~AE_UDPIP; - ATENABLE(s, aurp_global.glock); dPrintf(D_M_AURP, D_L_WARNING, ("AURPgetmsg: spurious soreceive, err==%d, p_mbuf==0x%x\n", *err, (unsigned int) p_mbuf)); break; } @@ -299,15 +302,12 @@ AURPgetmsg(err) * * This conforms to the so_upcall function pointer member of struct sockbuf. */ -void aurp_wakeup(struct socket *so, register caddr_t p, int state) +void aurp_wakeup(__unused struct socket *so, register caddr_t p, __unused int state) { - register int s; register int bit; bit = (int) p; - ATDISABLE(s, aurp_global.glock); aurp_global.event |= bit; - ATENABLE(s, aurp_global.glock); dPrintf(D_M_AURP, D_L_STATE_CHG, ("aurp_wakeup: bit 0x%x, aurp_global.event now 0x%x\n", @@ -325,7 +325,6 @@ aurp_bindrp(struct socket *so) { struct sockaddr_in sin; struct proc *p = current_proc(); - gbuf_t *m; int error; @@ -339,8 +338,8 @@ aurp_bindrp(struct socket *so) sblock(&so->so_snd, M_WAIT); so->so_state |= SS_PRIV; error = (*so->so_proto->pr_usrreqs->pru_bind)(so, (struct sockaddr *) &sin, p); - sbunlock(&so->so_snd); - sbunlock(&so->so_rcv); + sbunlock(&so->so_snd, 0); + sbunlock(&so->so_rcv, 0); return (error); } @@ -412,9 +411,8 @@ atalk_to_ip(register gbuf_t *m) int error; int flags = MSG_DONTWAIT; struct sockaddr_in rem_addr; - int s; - m->m_type = MT_HEADER; + m_mchtype(m, MT_HEADER); m->m_pkthdr.len = gbuf_msgsize(m); m->m_pkthdr.rcvif = 0; @@ -425,14 +423,10 @@ atalk_to_ip(register gbuf_t *m) domain = (aurp_domain_t *)gbuf_rptr(m); *(long *) &rem_addr.sin_addr = domain->dst_address; - ATDISABLE(s, aurp_global.glock); aurp_global.running++; - ATENABLE(s, aurp_global.glock); if (aurp_global.shutdown) { gbuf_freem(m); - ATDISABLE(s, aurp_global.glock); aurp_global.running--; - ATENABLE(s, aurp_global.glock); dPrintf(D_M_AURP, D_L_SHUTDN_INFO, ("atalk_to_ip: detected aurp_global.shutdown state\n")); return; @@ -445,9 +439,8 @@ atalk_to_ip(register gbuf_t *m) error)); } - ATDISABLE(s, aurp_global.glock); aurp_global.running--; - ATENABLE(s, aurp_global.glock); return; } +#endif /* AURP_SUPPORT */