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 | * | |
7cfe65b5 | 7 | * @(#)tuba_table.c 7.9 (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; | |
8c53a772 | 46 | rn_delete((caddr_t)&tc->tc_siso.siso_addr, (caddr_t)0, |
77db2796 | 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 | |
7cfe65b5 KS |
60 | tuba_lookup(siso, wait) |
61 | register struct sockaddr_iso *siso; | |
1067fd0f | 62 | { |
21715d8e | 63 | struct radix_node *rn, *rn_match(); |
1067fd0f | 64 | register struct tuba_cache *tc; |
21715d8e | 65 | struct tuba_cache **new; |
77db2796 | 66 | int dupentry = 0, sum_a = 0, sum_b = 0, old_size, i; |
1067fd0f | 67 | |
7cfe65b5 KS |
68 | if ((rn = rn_match((caddr_t)&siso->siso_addr, tuba_tree->rnh_treetop)) |
69 | && ((rn->rn_flags & RNF_ROOT) == 0)) { | |
1067fd0f KS |
70 | tc = (struct tuba_cache *)rn; |
71 | tc->tc_time = time.tv_sec; | |
72 | return (tc->tc_index); | |
73 | } | |
74 | if ((tc = (struct tuba_cache *)malloc(sizeof(*tc), M_RTABLE, wait)) | |
75 | == NULL) | |
76 | return (0); | |
21715d8e | 77 | bzero((caddr_t)tc, sizeof (*tc)); |
7cfe65b5 KS |
78 | bcopy(siso->siso_data, tc->tc_siso.siso_data, |
79 | tc->tc_siso.siso_nlen = siso->siso_nlen); | |
8c53a772 KS |
80 | rn_insert((caddr_t)&tc->tc_siso.siso_addr, |
81 | tuba_tree->rnh_treetop, &dupentry, tc->tc_nodes); | |
82 | if (dupentry) | |
83 | panic("tuba_lookup 1"); | |
ff38aee7 KS |
84 | tc->tc_siso.siso_family = AF_ISO; |
85 | tc->tc_siso.siso_len = sizeof(tc->tc_siso); | |
1067fd0f | 86 | tc->tc_time = time.tv_sec; |
7cfe65b5 | 87 | for (i = sum_a = tc->tc_siso.siso_nlen; --i >= 0; ) |
8c53a772 KS |
88 | (i & 1 ? sum_a : sum_b) += tc->tc_siso.siso_data[i]; |
89 | REDUCE(tc->tc_sum, (sum_a << 8) + sum_b); | |
90 | HTONS(tc->tc_sum); | |
315cfecc | 91 | SWAB(tc->tc_ssum, tc->tc_sum); |
1067fd0f KS |
92 | for (i = tuba_table_size; i > 0; i--) |
93 | if (tuba_table[i] == 0) | |
8c53a772 | 94 | goto fixup; |
77db2796 | 95 | old_size = tuba_table_size; |
1067fd0f KS |
96 | if (tuba_table_size == 0) |
97 | tuba_table_size = 15; | |
98 | if (tuba_table_size > 0x7fff) | |
99 | return (0); | |
100 | tuba_table_size = 1 + 2 * tuba_table_size; | |
101 | i = (tuba_table_size + 1) * sizeof(tc); | |
102 | new = (struct tuba_cache **)malloc((unsigned)i, M_RTABLE, wait); | |
103 | if (new == 0) { | |
104 | tuba_table_size = old_size; | |
8c53a772 | 105 | rn_delete((caddr_t)&tc->tc_siso.siso_addr, |
7cfe65b5 | 106 | (caddr_t)0, tuba_tree->rnh_treetop); |
1067fd0f KS |
107 | free((caddr_t)tc, M_RTABLE); |
108 | return (0); | |
109 | } | |
110 | bzero((caddr_t)new, (unsigned)i); | |
77db2796 | 111 | if (tuba_table) { |
1067fd0f | 112 | bcopy((caddr_t)tuba_table, (caddr_t)new, i >> 1); |
77db2796 KS |
113 | free((caddr_t)tuba_table, M_RTABLE); |
114 | } | |
115 | tuba_table = new; | |
8c53a772 KS |
116 | i = tuba_table_size; |
117 | fixup: | |
118 | tuba_table[i] = tc; | |
119 | tc->tc_index = i; | |
1067fd0f KS |
120 | return (tc->tc_index); |
121 | } |