]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netiso/tuba_table.c
3d8a005c2651a7af57614d2a98f8923dd7f2a5f8
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1992, 1993
24 * The Regents of the University of California. All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * @(#)tuba_table.c 8.2 (Berkeley) 11/15/93
56 #include <sys/param.h>
57 #include <sys/systm.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
62 #include <sys/domain.h>
63 #include <sys/protosw.h>
64 #include <sys/ioctl.h>
66 #include <sys/kernel.h>
69 #include <net/radix.h>
71 #include <netiso/iso.h>
72 #include <netiso/tuba_table.h>
75 struct tuba_cache
**tuba_table
;
76 struct radix_node_head
*tuba_tree
;
77 extern int arpt_keep
, arpt_prune
; /* use same values as arp cache */
84 register struct tuba_cache
*tc
;
85 long timelimit
= time
.tv_sec
- arpt_keep
;
87 timeout(tuba_timer
, (caddr_t
)0, arpt_prune
* hz
);
88 for (i
= tuba_table_size
; i
> 0; i
--)
89 if ((tc
= tuba_table
[i
]) && (tc
->tc_refcnt
== 0) &&
90 (tc
->tc_time
< timelimit
)) {
92 rn_delete(&tc
->tc_siso
.siso_addr
, NULL
, tuba_tree
);
93 FREE((caddr_t
)tc
, M_RTABLE
);
100 rn_inithead((void **)&tuba_tree
, 40);
101 timeout(tuba_timer
, (caddr_t
)0, arpt_prune
* hz
);
105 tuba_lookup(siso
, wait
)
106 register struct sockaddr_iso
*siso
;
108 struct radix_node
*rn
, *rn_match();
109 register struct tuba_cache
*tc
;
110 struct tuba_cache
**new;
111 int dupentry
= 0, sum_a
= 0, sum_b
= 0, old_size
, i
;
113 if ((rn
= rn_match((caddr_t
)&siso
->siso_addr
, tuba_tree
->rnh_treetop
))
114 && ((rn
->rn_flags
& RNF_ROOT
) == 0)) {
115 tc
= (struct tuba_cache
*)rn
;
116 tc
->tc_time
= time
.tv_sec
;
117 return (tc
->tc_index
);
119 // if ((tc = (struct tuba_cache *)malloc(sizeof(*tc), M_RTABLE, wait))
121 if (wait
== M_DONTWAIT
)
122 MALLOC(tc
, struct tuba_cache
*, sizeof(*tc
), M_RTABLE
, M_NOWAIT
);
124 MALLOC(tc
, struct tuba_cache
*, sizeof(*tc
), M_RTABLE
, M_WAITOK
);
127 bzero((caddr_t
)tc
, sizeof (*tc
));
128 bcopy(siso
->siso_data
, tc
->tc_siso
.siso_data
,
129 tc
->tc_siso
.siso_nlen
= siso
->siso_nlen
);
130 rn_insert(&tc
->tc_siso
.siso_addr
, tuba_tree
, &dupentry
, tc
->tc_nodes
);
132 panic("tuba_lookup 1");
133 tc
->tc_siso
.siso_family
= AF_ISO
;
134 tc
->tc_siso
.siso_len
= sizeof(tc
->tc_siso
);
135 tc
->tc_time
= time
.tv_sec
;
136 for (i
= sum_a
= tc
->tc_siso
.siso_nlen
; --i
>= 0; )
137 (i
& 1 ? sum_a
: sum_b
) += (u_char
)tc
->tc_siso
.siso_data
[i
];
138 REDUCE(tc
->tc_sum
, (sum_a
<< 8) + sum_b
);
140 SWAB(tc
->tc_ssum
, tc
->tc_sum
);
141 for (i
= tuba_table_size
; i
> 0; i
--)
142 if (tuba_table
[i
] == 0)
144 old_size
= tuba_table_size
;
145 if (tuba_table_size
== 0)
146 tuba_table_size
= 15;
147 if (tuba_table_size
> 0x7fff)
149 tuba_table_size
= 1 + 2 * tuba_table_size
;
150 i
= (tuba_table_size
+ 1) * sizeof(tc
);
151 // new = (struct tuba_cache **)malloc((unsigned)i, M_RTABLE, wait);
152 if (wait
== M_DONTWAIT
)
153 MALLOC(new, struct tuba_cache
**, i
, M_RTABLE
, M_NOWAIT
);
155 MALLOC(new, struct tuba_cache
**, i
, M_RTABLE
, M_WAITOK
);
157 tuba_table_size
= old_size
;
158 rn_delete(&tc
->tc_siso
.siso_addr
, NULL
, tuba_tree
);
159 FREE((caddr_t
)tc
, M_RTABLE
);
162 bzero((caddr_t
)new, (unsigned)i
);
164 bcopy((caddr_t
)tuba_table
, (caddr_t
)new, i
>> 1);
165 FREE((caddr_t
)tuba_table
, M_RTABLE
);
172 return (tc
->tc_index
);