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