|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * The contents of this file constitute Original Code as defined in and ! 7: * are subject to the Apple Public Source License Version 1.1 (the ! 8: * "License"). You may not use this file except in compliance with the ! 9: * License. Please obtain a copy of the License at ! 10: * http://www.apple.com/publicsource and read it before using this file. ! 11: * ! 12: * This Original Code and all software distributed under the License are ! 13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 17: * License for the specific language governing rights and limitations ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: ! 23: /* ! 24: * Copyright (c) 1997-1999 Apple Computer, Inc. ! 25: * All Rights Reserved. ! 26: */ ! 27: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ ! 28: /* ! 29: * Copyright (c) 1982, 1986, 1991, 1993 ! 30: * The Regents of the University of California. All rights reserved. ! 31: * ! 32: * Redistribution and use in source and binary forms, with or without ! 33: * modification, are permitted provided that the following conditions ! 34: * are met: ! 35: * 1. Redistributions of source code must retain the above copyright ! 36: * notice, this list of conditions and the following disclaimer. ! 37: * 2. Redistributions in binary form must reproduce the above copyright ! 38: * notice, this list of conditions and the following disclaimer in the ! 39: * documentation and/or other materials provided with the distribution. ! 40: * 3. All advertising materials mentioning features or use of this software ! 41: * must display the following acknowledgement: ! 42: * This product includes software developed by the University of ! 43: * California, Berkeley and its contributors. ! 44: * 4. Neither the name of the University nor the names of its contributors ! 45: * may be used to endorse or promote products derived from this software ! 46: * without specific prior written permission. ! 47: * ! 48: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 49: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 50: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 51: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 52: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 53: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 54: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 55: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 56: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 57: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 58: * SUCH DAMAGE. ! 59: * ! 60: * @(#)at_pcb.c 8.2 (Berkeley) 1/4/94 ! 61: */ ! 62: ! 63: #include <sys/param.h> ! 64: #include <sys/systm.h> ! 65: #include <sys/malloc.h> ! 66: #include <sys/mbuf.h> ! 67: #include <sys/protosw.h> ! 68: #include <sys/socket.h> ! 69: #include <sys/socketvar.h> ! 70: #include <sys/ioctl.h> ! 71: #include <sys/errno.h> ! 72: #include <sys/time.h> ! 73: #include <sys/proc.h> ! 74: #include <kern/kern_types.h> ! 75: #include <kern/zalloc.h> ! 76: #include <kern/queue.h> ! 77: ! 78: #include <net/if.h> ! 79: ! 80: #include <netat/sysglue.h> ! 81: #include <netat/appletalk.h> ! 82: #include <netat/ddp.h> ! 83: #include <netat/at_pcb.h> ! 84: #include <netat/debug.h> ! 85: #include <netat/at_var.h> ! 86: #include <netat/adsp.h> ! 87: #include <netat/adsp_internal.h> ! 88: ! 89: extern struct atpcb ddp_head; ! 90: extern struct atpcb *atp_inputQ[]; ! 91: extern CCB *adsp_inputQ[]; ! 92: extern int xpatcnt; ! 93: extern struct { ! 94: void (*func)(); ! 95: } ddp_handler[]; ! 96: ! 97: ! 98: zone_t atpcb_zone; ! 99: ! 100: void at_memzone_init() ! 101: { ! 102: vm_size_t str_size; ! 103: ! 104: str_size = (vm_size_t)sizeof(struct atpcb); ! 105: atpcb_zone = (zone_t)zinit(str_size, 1000*str_size, 8192, "atpcb zone"); ! 106: } ! 107: ! 108: int at_pcballoc(so, head) ! 109: struct socket *so; ! 110: struct atpcb *head; ! 111: { ! 112: register struct atpcb *pcb; ! 113: ! 114: pcb = (struct atpcb *)zalloc(atpcb_zone); ! 115: if (pcb == NULL) ! 116: return (ENOBUFS); ! 117: bzero((caddr_t)pcb, sizeof(*pcb)); ! 118: ! 119: pcb->atpcb_head = head; ! 120: pcb->atpcb_socket = so; ! 121: if (head) ! 122: insque((queue_t)pcb, (queue_t)head); ! 123: so->so_pcb = (caddr_t)pcb; ! 124: ! 125: return (0); ! 126: } ! 127: ! 128: int at_pcbdetach(pcb) ! 129: struct atpcb *pcb; ! 130: { ! 131: struct socket *so = pcb->atpcb_socket; ! 132: ! 133: /* Notify NBP that we are closing this DDP socket */ ! 134: if (pcb->lport) { ! 135: ddp_notify_nbp(pcb->lport, pcb->pid, pcb->ddptype); ! 136: pcb->lport = 0; ! 137: } ! 138: ! 139: so->so_pcb = 0; ! 140: if ((pcb->atpcb_next) && (pcb->atpcb_prev)) ! 141: remque((queue_t)pcb); ! 142: zfree(atpcb_zone, (vm_offset_t)pcb); ! 143: sofree(so); ! 144: return(0); ! 145: } ! 146: ! 147: int ddp_socket_inuse(ddpsock, proto) ! 148: u_char ddpsock, proto; ! 149: { ! 150: struct atpcb *pcb; ! 151: ! 152: if ((proto == DDP_ATP) && atp_inputQ[ddpsock]) ! 153: return TRUE; ! 154: if ((proto == DDP_ADSP) && adsp_inputQ[ddpsock]) ! 155: return TRUE; ! 156: if (ddp_handler[ddpsock].func) ! 157: return TRUE; ! 158: for (pcb = ddp_head.atpcb_next; pcb != &ddp_head; ! 159: pcb = pcb->atpcb_next) { ! 160: if (pcb->lport == ddpsock && ! 161: pcb->ddptype == proto) ! 162: return TRUE; ! 163: } ! 164: return FALSE; ! 165: } ! 166: ! 167: int at_pcbbind(pcb, nam) ! 168: register struct atpcb *pcb; ! 169: struct sockaddr *nam; ! 170: { ! 171: register struct socket *so = pcb->atpcb_socket; ! 172: register struct sockaddr_at *local = (struct sockaddr_at *) nam; ! 173: u_char ddpsock = local->sat_port; ! 174: ! 175: if ((xpatcnt == 0) || ! 176: (local->sat_family != AF_APPLETALK)) ! 177: return(EADDRNOTAVAIL); ! 178: ! 179: /* Request for dynamic socket? */ ! 180: if (ddpsock == 0) { ! 181: /* Search table for free one */ ! 182: /* *** borrow IP algorithm, instead? *** */ ! 183: for (ddpsock = DDP_SOCKET_LAST; ! 184: ddpsock >= (DDP_SOCKET_1st_DYNAMIC + 1); ! 185: /* sip has 1st */ ! 186: ddpsock--) { ! 187: if (! ddp_socket_inuse(ddpsock, pcb->ddptype)) ! 188: break; ! 189: } ! 190: if (ddpsock < (DDP_SOCKET_1st_DYNAMIC + 1)) ! 191: return(EADDRNOTAVAIL); /* Error if no free sockets */ ! 192: } else { ! 193: /* Asking to open a socket by its number. ! 194: Check if its legal & free. */ ! 195: if (ddpsock > DDP_SOCKET_LAST) ! 196: return(EINVAL); ! 197: if (ddp_socket_inuse(ddpsock, pcb->ddptype)) ! 198: return(EADDRNOTAVAIL); ! 199: } ! 200: ! 201: pcb->lport = ddpsock; ! 202: /* if address is specified, make sure address matches one of the ! 203: interfaces configured for AppleTalk */ ! 204: if (MULTIHOME_MODE && ! 205: (local->sat_addr.s_net || local->sat_addr.s_node)) { ! 206: at_ifaddr_t *ifID; ! 207: TAILQ_FOREACH(ifID, &at_ifQueueHd, aa_link) { ! 208: if (ifID->ifThisNode.s_net == local->sat_addr.s_net && ! 209: ifID->ifThisNode.s_node == local->sat_addr.s_node) { ! 210: pcb->laddr = local->sat_addr; ! 211: return(0); ! 212: } ! 213: } ! 214: return(EINVAL); ! 215: } ! 216: return(0); ! 217: } ! 218: ! 219: void at_setsockaddr(pcb, nam) ! 220: register struct atpcb *pcb; ! 221: struct sockaddr *nam; ! 222: { ! 223: register struct sockaddr_at *sat; ! 224: ! 225: sat = (struct sockaddr_at *) nam; ! 226: bzero((caddr_t)sat, sizeof (*sat)); ! 227: sat->sat_family = AF_APPLETALK; ! 228: sat->sat_len = sizeof(*sat); ! 229: sat->sat_port = pcb->lport; ! 230: sat->sat_addr = pcb->laddr; ! 231: } ! 232: ! 233: void at_setpeeraddr(pcb, nam) ! 234: struct atpcb *pcb; ! 235: struct sockaddr *nam; ! 236: { ! 237: register struct sockaddr_at *sat; ! 238: ! 239: sat = (struct sockaddr_at *) nam; ! 240: bzero((caddr_t)sat, sizeof (*sat)); ! 241: sat->sat_family = AF_APPLETALK; ! 242: sat->sat_len = sizeof(*sat); ! 243: sat->sat_port = pcb->rport; ! 244: sat->sat_addr = pcb->raddr; ! 245: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.