X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/d7e50217d7adf6e52786a38bcaa4cd698cb9a79e..ff6e181ae92fc6f1e89841290f461d1f2f9badd9:/bsd/netinet/in_bootp.c diff --git a/bsd/netinet/in_bootp.c b/bsd/netinet/in_bootp.c index 041d9e5ca..a9a900f42 100644 --- a/bsd/netinet/in_bootp.c +++ b/bsd/netinet/in_bootp.c @@ -1,10 +1,8 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * * 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 @@ -52,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -69,11 +68,21 @@ #include #include +#include +#include + #ifdef BOOTP_DEBUG #define dprintf(x) printf x; -#else BOOTP_DEBUG +#else /* !BOOTP_DEBUG */ #define dprintf(x) -#endif BOOTP_DEBUG +#endif /* BOOTP_DEBUG */ + +int bootp(struct ifnet * ifp, struct in_addr * iaddr_p, int max_try, + struct in_addr * netmask_p, struct in_addr * router_p, + struct proc * procp); +struct mbuf * ip_pkt_to_mbuf(caddr_t pkt, int pktsize); +int receive_packet(struct socket * so, caddr_t pp, int psize, int * actual_size); + /* ip address formatting macros */ #define IP_FORMAT "%d.%d.%d.%d" @@ -88,7 +97,7 @@ blank_sin() } static __inline__ void -print_reply(struct bootp *bp, int bp_len) +print_reply(struct bootp *bp, __unused int bp_len) { int i, j, len; @@ -133,7 +142,7 @@ print_reply(struct bootp *bp, int bp_len) } static __inline__ void -print_reply_short(struct bootp *bp, int bp_len) +print_reply_short(struct bootp *bp, __unused int bp_len) { printf("bp_yiaddr = " IP_FORMAT "\n", IP_LIST(&bp->bp_yiaddr)); printf("bp_sname = %s\n", bp->bp_sname); @@ -228,7 +237,7 @@ link_print(struct sockaddr_dl * dl_p) " slen %d addr ", dl_p->sdl_len, dl_p->sdl_index, dl_p->sdl_family, dl_p->sdl_type, dl_p->sdl_nlen, dl_p->sdl_alen, dl_p->sdl_slen); -#endif 0 +#endif for (i = 0; i < dl_p->sdl_alen; i++) printf("%s%x", i ? ":" : "", (link_address(dl_p))[i]); @@ -243,13 +252,16 @@ link_from_ifnet(struct ifnet * ifp) /* for (addr = ifp->if_addrlist; addr; addr = addr->ifa_next) */ + ifnet_lock_shared(ifp); TAILQ_FOREACH(addr, &ifp->if_addrhead, ifa_link) { if (addr->ifa_addr->sa_family == AF_LINK) { struct sockaddr_dl * dl_p = (struct sockaddr_dl *)(addr->ifa_addr); + ifnet_lock_done(ifp); return (dl_p); } } + ifnet_lock_done(ifp); return (NULL); } @@ -260,7 +272,7 @@ link_from_ifnet(struct ifnet * ifp) * bypassing routing code. */ static int -send_bootp_request(struct ifnet * ifp, struct socket * so, +send_bootp_request(struct ifnet * ifp, __unused struct socket * so, struct bootp_packet * pkt) { struct mbuf * m; @@ -272,7 +284,7 @@ send_bootp_request(struct ifnet * ifp, struct socket * so, sin.sin_addr.s_addr = INADDR_BROADCAST; m = ip_pkt_to_mbuf((caddr_t)pkt, sizeof(*pkt)); - return (dlil_output(ifp->if_data.default_proto, m, 0, (struct sockaddr *)&sin, 0)); + return dlil_output(ifp, PF_INET, m, 0, (struct sockaddr *)&sin, 0); } /* @@ -283,23 +295,18 @@ send_bootp_request(struct ifnet * ifp, struct socket * so, int receive_packet(struct socket * so, caddr_t pp, int psize, int * actual_size) { - struct iovec aiov; - struct uio auio; + uio_t auio; int rcvflg; int error; + char uio_buf[ UIO_SIZEOF(1) ]; - aiov.iov_base = pp; - aiov.iov_len = psize; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_segflg = UIO_SYSSPACE; - auio.uio_offset = 0; - auio.uio_resid = psize; - auio.uio_rw = UIO_READ; + auio = uio_createwithbuffer(1, 0, UIO_SYSSPACE, UIO_READ, + &uio_buf[0], sizeof(uio_buf)); + uio_addiov(auio, CAST_USER_ADDR_T(pp), psize); rcvflg = MSG_WAITALL; - error = soreceive(so, (struct sockaddr **) 0, &auio, 0, 0, &rcvflg); - *actual_size = psize - auio.uio_resid; + error = soreceive(so, (struct sockaddr **) 0, auio, 0, 0, &rcvflg); + *actual_size = psize - uio_resid(auio); return (error); } @@ -313,14 +320,13 @@ bootp_timeout(void * arg) { struct socket * * socketflag = (struct socket * *)arg; struct socket * so = *socketflag; - boolean_t funnel_state; dprintf(("bootp: timeout\n")); - funnel_state = thread_funnel_set(network_flock,TRUE); *socketflag = NULL; + socket_lock(so, 1); sowakeup(so, &so->so_rcv); - (void) thread_funnel_set(network_flock, FALSE); + socket_unlock(so, 1); return; } @@ -334,7 +340,7 @@ bootp_timeout(void * arg) */ #define GOOD_RATING 3 static __inline__ int -rate_packet(struct bootp * pkt, int pkt_size, dhcpol_t * options_p) +rate_packet(__unused struct bootp * pkt, __unused int pkt_size, dhcpol_t * options_p) { int len; int rating = 1; @@ -451,7 +457,7 @@ bootp_loop(struct socket * so, struct ifnet * ifp, int max_try, #ifdef BOOTP_DEBUG print_reply_short(reply, n); -#endif BOOTP_DEBUG +#endif /* BOOTP_DEBUG */ (void)dhcpol_parse_packet(&options, (struct dhcp *)reply, n, NULL); rating = rate_packet(reply, n, &options); @@ -504,8 +510,11 @@ bootp_loop(struct socket * so, struct ifnet * ifp, int max_try, } break; /* retry */ } - else - sbwait(&so->so_rcv); + else { + socket_lock(so, 1); + error = sbwait(&so->so_rcv); + socket_unlock(so, 1); + } } if (error && (error != EWOULDBLOCK)) { dprintf(("bootp: failed to receive packets: %d\n", error)); @@ -526,9 +535,9 @@ bootp_loop(struct socket * so, struct ifnet * ifp, int max_try, cleanup: if (request) - kfree((caddr_t)request, sizeof (*request)); + kfree(request, sizeof (*request)); if (reply) - kfree((caddr_t)reply, reply_size); + kfree(reply, reply_size); return (error); } @@ -586,7 +595,9 @@ int bootp(struct ifnet * ifp, struct in_addr * iaddr_p, int max_try, dprintf(("bootp: sobind failed, %d\n", error)); goto cleanup; } + socket_lock(so, 1); so->so_state |= SS_NBIO; + socket_unlock(so, 1); } /* do the protocol */ error = bootp_loop(so, ifp, max_try, iaddr_p, netmask_p, router_p);