1 /* 2 * Copyright (c) 1992 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)tuba_table.c 7.2 (Berkeley) 10/09/92 8 */ 9 #include "param.h" 10 #include "systm.h" 11 #include "proc.h" 12 #include "mbuf.h" 13 #include "socket.h" 14 #include "socketvar.h" 15 #include "domain.h" 16 #include "protosw.h" 17 #include "ioctl.h" 18 19 #include "net/if.h" 20 #include "net/af.h" 21 #include "net/radix.h" 22 23 #include "netiso/iso.h" 24 #include "tuba_addr.h" 25 26 int tuba_table_size; 27 struct tuba_cache **tuba_table; 28 struct radix_node_head *tuba_tree; 29 extern int arpt_keep, arpt_prune; /* use same values as arp cache */ 30 31 void 32 tuba_timer() 33 { 34 int s = splnet(); 35 int i; 36 register struct tuba_cache **tc; 37 long timelimit = time.tv_sec - arpt_keep; 38 39 timeout(tuba_timer, (caddr_t)0, arpt_prune * hz); 40 for (i = tuba_table_size; i > 0; i--) 41 if ((tc = tuba_table[i]) && (tc->tc_refcnt == 0) && 42 (tc->tc_time < timelimit)) { 43 tuba_table[i] = 0; 44 rn_delete((caddr_t)&tc->tc_addr, (caddr_t)0, tuba_tree); 45 free((caddr_t)tc, M_RTABLE); 46 } 47 splx(s); 48 } 49 50 tuba_timer_init() 51 { 52 rn_inithead((void **)&tuba_tree, 40); 53 timeout(tuba_timer, (caddr_t)0, arpt_prune * hz); 54 } 55 56 int 57 tuba_lookup(isoa, flags, wait) 58 register struct iso_addr *isoa; 59 int flags; 60 { 61 struct radix_node *rn; 62 register struct tuba_cache *tc; 63 int dupentry = 0, sum_even = 0, sum_odd = 0, delta, i; 64 65 if (rn = rn_match(tuba_tree, (caddr_t)isoa)) { 66 tc = (struct tuba_cache *)rn; 67 tc->tc_time = time.tv_sec; 68 return (tc->tc_index); 69 } 70 if ((tc = (struct tuba_cache *)malloc(sizeof(*tc), M_RTABLE, wait)) 71 == NULL) 72 return (0); 73 bzero((caddr_t)tc, sizeof (*tc)) 74 bcopy((caddr_t)isoa, (caddr_t)&tc->tc_addr, 1 + isoa->isoa_len); 75 rn_insert((caddr_t)&tc->tc_addr, tuba_tree, &dupentry, tc->tc_nodes); 76 if (dupentry) 77 panic("tuba_lookup 1"); 78 tc->tc_time = time.tv_sec; 79 tc->tc_flags = flags; 80 sum_even = isoa->isoa_len; 81 for (i = sum_even; --i >= 0; ) { 82 delta = isoa->isoa_genaddr[i]; 83 i & 1 ? sum_even += delta : sum_odd += delta; 84 } 85 ICKSUM(tc->tc_sum_in, (sum_even << 8) + sum_odd); 86 ICKSUM(tc->tc_sum_out, tc->sum_in + 0x1fffe - tc->tc_index); 87 for (i = tuba_table_size; i > 0; i--) 88 if (tuba_table[i] == 0) 89 break; 90 if (i) { 91 tc->tc_index = 1; 92 tuba_table[i] = tc; 93 return (i); 94 } 95 if (tuba_table_size == 0) 96 tuba_table_size = 15; 97 if (tuba_table_size > 0x7fff) 98 return (0); 99 tuba_table_size = 1 + 2 * tuba_table_size; 100 i = (tuba_table_size + 1) * sizeof(tc); 101 new = (struct tuba_cache **)malloc((unsigned)i, M_RTABLE, wait); 102 if (new == 0) { 103 tuba_table_size = old_size; 104 rn_delete((caddr_t)&tc->tc_addr, (caddr_t)0, tuba_tree); 105 free((caddr_t)tc, M_RTABLE); 106 return (0); 107 } 108 bzero((caddr_t)new, (unsigned)i); 109 if (tuba_table) 110 bcopy((caddr_t)tuba_table, (caddr_t)new, i >> 1); 111 tuba_table[tc->tc_index = tuba_table_size] = tc; 112 return (tc->tc_index); 113 } 114