X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/e5568f75972dfc723778653c11cb6b4dc825716a..8ad349bb6ed4a0be06e34c92be0d98b92e078db4:/bsd/netat/at.c?ds=inline diff --git a/bsd/netat/at.c b/bsd/netat/at.c index 089fd3889..47ec0810a 100644 --- a/bsd/netat/at.c +++ b/bsd/netat/at.c @@ -1,23 +1,31 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ * - * @APPLE_LICENSE_HEADER_END@ + * 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. 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 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ */ /* * Copyright (c) 1998 Apple Computer, Inc. @@ -34,6 +42,7 @@ #include #include #include +#include #include #include @@ -124,7 +133,8 @@ static int set_zones(ifz) * ifp is 0 if not an interface-specific ioctl. */ -int at_control(so, cmd, data, ifp) +int +at_control(so, cmd, data, ifp) struct socket *so; u_long cmd; caddr_t data; @@ -137,15 +147,18 @@ int at_control(so, cmd, data, ifp) struct ifaddr *ifa; struct sockaddr_dl *sdl; - if (cmd == 0x2000ff99) { + if ((cmd & 0xffff) == 0xff99) { + u_long fixed_command; + char ioctl_buffer[32]; /* *** this is a temporary hack to get at_send_to_dev() to work with BSD-style sockets instead of the special purpose system calls, ATsocket() and ATioctl(). *** */ - if ((error = at_ioctl((struct atpcb *)so->so_pcb, cmd, data, 0))) { + fixed_command = _IOW(0, 0xff99, user_addr_t); + if ((error = at_ioctl((struct atpcb *)so->so_pcb, fixed_command, data, 0))) { if (((struct atpcb *)so->so_pcb)->proto != ATPROTO_LAP) { ((struct atpcb *)so->so_pcb)->proto = ATPROTO_LAP; - error = at_ioctl((struct atpcb *)so->so_pcb, cmd, data, 0); + error = at_ioctl((struct atpcb *)so->so_pcb, fixed_command, data , 0); } } return(error); @@ -216,7 +229,7 @@ int at_control(so, cmd, data, ifp) at_def_zone_t *defzonep = (at_def_zone_t *)data; /* check for root access */ - if (error = suser(p->p_ucred, &p->p_acflag)) + if (error = suser(kauth_cred_get(), 0)) return(EACCES); ifID = 0; @@ -326,7 +339,7 @@ int at_control(so, cmd, data, ifp) { at_nbp_reg_t *nbpP = (at_nbp_reg_t *)data; nve_entry_t nve; - int error; + int error2; if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) return(ENOTREADY); @@ -382,14 +395,14 @@ int at_control(so, cmd, data, ifp) * this tuple in the registry and return ok response. */ ATDISABLE(nve_lock, NVE_LOCK); - if ((error = nbp_new_nve_entry(&nve, ifID)) == 0) { + if ((error2 = nbp_new_nve_entry(&nve, ifID)) == 0) { nbpP->addr.net = ifID->ifThisNode.s_net; nbpP->addr.node = ifID->ifThisNode.s_node; nbpP->unique_nbp_id = nve.unique_nbp_id; } ATENABLE(nve_lock, NVE_LOCK); - return(error); + return(error2); break; } @@ -463,7 +476,7 @@ int at_control(so, cmd, data, ifp) at_router_params_t *rt = (at_router_params_t *)data; /* check for root access */ - if (error = suser(p->p_ucred, &p->p_acflag)) + if (error = suser(kauth_cred_get(), 0)) return(EACCES); /* when in routing/multihome mode the AIOCSETROUTER IOCTL @@ -503,7 +516,7 @@ int at_control(so, cmd, data, ifp) at_kern_err_t *keP = (at_kern_err_t *)data; /* check for root access */ - if (suser(p->p_ucred, &p->p_acflag)) + if (suser(kauth_cred_get(), 0)) return(EACCES); if (!(at_state.flags & AT_ST_STARTED)) @@ -534,7 +547,7 @@ int at_control(so, cmd, data, ifp) ret; /* check for root access */ - if (error = suser(p->p_ucred, &p->p_acflag)) + if (error = suser(kauth_cred_get(), 0)) return(EACCES); ret = ddp_shutdown(*count_only); @@ -561,7 +574,7 @@ int at_control(so, cmd, data, ifp) case SIOCSIFADDR: /* check for root access */ - if (error = suser(p->p_ucred, &p->p_acflag)) + if (error = suser(kauth_cred_get(), 0)) error = EACCES; else if (ifID) error = EEXIST; @@ -579,6 +592,7 @@ int at_control(so, cmd, data, ifp) ifID->aa_ifp = ifp; ifa = &ifID->aa_ifa; + ifnet_lock_exclusive(ifp); TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) && (sdl->sdl_family == AF_LINK)) { @@ -599,14 +613,14 @@ int at_control(so, cmd, data, ifp) ifID->ifNodeAddress.sat_family = AF_APPLETALK; /* the address itself will be filled in when ifThisNode is set */ - s = splnet(); - TAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link); - splx(s); + if_attach_ifa(ifp, ifa); + ifnet_lock_done(ifp); switch (ifp->if_type) { case IFT_ETHER: - ether_attach_at(ifp, &ifID->at_dl_tag, - &ifID->aarp_dl_tag); + case IFT_L2VLAN: + case IFT_IEEE8023ADLAG: /* bonded ethernet */ + ether_attach_at(ifp); error = 0; ifID->cable_multicast_addr = etalk_multicast_addr; @@ -649,7 +663,7 @@ int at_control(so, cmd, data, ifp) deletion of interfaces *** */ case SIOCDIFADDR: /* check for root access */ - if (error = suser(p->p_ucred, &p->p_acflag)) + if (error = suser(kauth_cred_get(), 0)) error = EACCES; else if (!ifID) error = EINVAL; @@ -669,13 +683,11 @@ int at_control(so, cmd, data, ifp) /* let's make sure it's either -1 or a valid file descriptor */ if (cloned_fd != -1) { struct socket *cloned_so; - struct file *cloned_fp; - error = getsock(p->p_fd, cloned_fd, &cloned_fp); + error = file_socket(cloned_fd, &cloned_so); if (error){ splx(s); /* XXX */ break; } - cloned_so = (struct socket *)cloned_fp->f_data; clonedat_pcb = sotoatpcb(cloned_so); } else { clonedat_pcb = NULL; @@ -687,6 +699,7 @@ int at_control(so, cmd, data, ifp) at_pcb->ddp_flags = clonedat_pcb->ddp_flags; } splx(s); /* XXX */ + file_drop(cloned_fd); break; }