|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* ! 26: * Copyright (c) 1992, 1993 ! 27: * The Regents of the University of California. All rights reserved. ! 28: * ! 29: * Redistribution and use in source and binary forms, with or without ! 30: * modification, are permitted provided that the following conditions ! 31: * are met: ! 32: * 1. Redistributions of source code must retain the above copyright ! 33: * notice, this list of conditions and the following disclaimer. ! 34: * 2. Redistributions in binary form must reproduce the above copyright ! 35: * notice, this list of conditions and the following disclaimer in the ! 36: * documentation and/or other materials provided with the distribution. ! 37: * 3. All advertising materials mentioning features or use of this software ! 38: * must display the following acknowledgement: ! 39: * This product includes software developed by the University of ! 40: * California, Berkeley and its contributors. ! 41: * 4. Neither the name of the University nor the names of its contributors ! 42: * may be used to endorse or promote products derived from this software ! 43: * without specific prior written permission. ! 44: * ! 45: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 46: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 47: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 48: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 49: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 50: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 51: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 52: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 53: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 54: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 55: * SUCH DAMAGE. ! 56: * ! 57: * @(#)tuba_table.c 8.2 (Berkeley) 11/15/93 ! 58: */ ! 59: #include <sys/param.h> ! 60: #include <sys/systm.h> ! 61: #include <sys/proc.h> ! 62: #include <sys/mbuf.h> ! 63: #include <sys/socket.h> ! 64: #include <sys/socketvar.h> ! 65: #include <sys/domain.h> ! 66: #include <sys/protosw.h> ! 67: #include <sys/ioctl.h> ! 68: #include <sys/time.h> ! 69: #include <sys/kernel.h> ! 70: ! 71: #include <net/if.h> ! 72: #include <net/radix.h> ! 73: ! 74: #include <netiso/iso.h> ! 75: #include <netiso/tuba_table.h> ! 76: ! 77: int tuba_table_size; ! 78: struct tuba_cache **tuba_table; ! 79: struct radix_node_head *tuba_tree; ! 80: extern int arpt_keep, arpt_prune; /* use same values as arp cache */ ! 81: ! 82: void ! 83: tuba_timer() ! 84: { ! 85: int s = splnet(); ! 86: int i; ! 87: register struct tuba_cache *tc; ! 88: long timelimit = time.tv_sec - arpt_keep; ! 89: ! 90: timeout(tuba_timer, (caddr_t)0, arpt_prune * hz); ! 91: for (i = tuba_table_size; i > 0; i--) ! 92: if ((tc = tuba_table[i]) && (tc->tc_refcnt == 0) && ! 93: (tc->tc_time < timelimit)) { ! 94: tuba_table[i] = 0; ! 95: rn_delete(&tc->tc_siso.siso_addr, NULL, tuba_tree); ! 96: free((caddr_t)tc, M_RTABLE); ! 97: } ! 98: splx(s); ! 99: } ! 100: ! 101: tuba_table_init() ! 102: { ! 103: rn_inithead((void **)&tuba_tree, 40); ! 104: timeout(tuba_timer, (caddr_t)0, arpt_prune * hz); ! 105: } ! 106: ! 107: int ! 108: tuba_lookup(siso, wait) ! 109: register struct sockaddr_iso *siso; ! 110: { ! 111: struct radix_node *rn, *rn_match(); ! 112: register struct tuba_cache *tc; ! 113: struct tuba_cache **new; ! 114: int dupentry = 0, sum_a = 0, sum_b = 0, old_size, i; ! 115: ! 116: if ((rn = rn_match((caddr_t)&siso->siso_addr, tuba_tree->rnh_treetop)) ! 117: && ((rn->rn_flags & RNF_ROOT) == 0)) { ! 118: tc = (struct tuba_cache *)rn; ! 119: tc->tc_time = time.tv_sec; ! 120: return (tc->tc_index); ! 121: } ! 122: // if ((tc = (struct tuba_cache *)malloc(sizeof(*tc), M_RTABLE, wait)) ! 123: // == NULL) ! 124: if (wait == M_DONTWAIT) ! 125: MALLOC(tc, struct tuba_cache *, sizeof(*tc), M_RTABLE, M_NOWAIT); ! 126: else ! 127: MALLOC(tc, struct tuba_cache *, sizeof(*tc), M_RTABLE, M_WAITOK); ! 128: if (tc == NULL) ! 129: return (0); ! 130: bzero((caddr_t)tc, sizeof (*tc)); ! 131: bcopy(siso->siso_data, tc->tc_siso.siso_data, ! 132: tc->tc_siso.siso_nlen = siso->siso_nlen); ! 133: rn_insert(&tc->tc_siso.siso_addr, tuba_tree, &dupentry, tc->tc_nodes); ! 134: if (dupentry) ! 135: panic("tuba_lookup 1"); ! 136: tc->tc_siso.siso_family = AF_ISO; ! 137: tc->tc_siso.siso_len = sizeof(tc->tc_siso); ! 138: tc->tc_time = time.tv_sec; ! 139: for (i = sum_a = tc->tc_siso.siso_nlen; --i >= 0; ) ! 140: (i & 1 ? sum_a : sum_b) += (u_char)tc->tc_siso.siso_data[i]; ! 141: REDUCE(tc->tc_sum, (sum_a << 8) + sum_b); ! 142: HTONS(tc->tc_sum); ! 143: SWAB(tc->tc_ssum, tc->tc_sum); ! 144: for (i = tuba_table_size; i > 0; i--) ! 145: if (tuba_table[i] == 0) ! 146: goto fixup; ! 147: old_size = tuba_table_size; ! 148: if (tuba_table_size == 0) ! 149: tuba_table_size = 15; ! 150: if (tuba_table_size > 0x7fff) ! 151: return (0); ! 152: tuba_table_size = 1 + 2 * tuba_table_size; ! 153: i = (tuba_table_size + 1) * sizeof(tc); ! 154: // new = (struct tuba_cache **)malloc((unsigned)i, M_RTABLE, wait); ! 155: if (wait == M_DONTWAIT) ! 156: MALLOC(new, struct tuba_cache **, i, M_RTABLE, M_NOWAIT); ! 157: else ! 158: MALLOC(new, struct tuba_cache **, i, M_RTABLE, M_WAITOK); ! 159: if (new == 0) { ! 160: tuba_table_size = old_size; ! 161: rn_delete(&tc->tc_siso.siso_addr, NULL, tuba_tree); ! 162: free((caddr_t)tc, M_RTABLE); ! 163: return (0); ! 164: } ! 165: bzero((caddr_t)new, (unsigned)i); ! 166: if (tuba_table) { ! 167: bcopy((caddr_t)tuba_table, (caddr_t)new, i >> 1); ! 168: free((caddr_t)tuba_table, M_RTABLE); ! 169: } ! 170: tuba_table = new; ! 171: i = tuba_table_size; ! 172: fixup: ! 173: tuba_table[i] = tc; ! 174: tc->tc_index = i; ! 175: return (tc->tc_index); ! 176: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.