]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the | |
10 | * License may not be used to create, or enable the creation or | |
11 | * redistribution of, unlawful or unlicensed copies of an Apple operating | |
12 | * system, or to circumvent, violate, or enable the circumvention or | |
13 | * violation of, any terms of an Apple operating system software license | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
20 | * The Original Code and all software distributed under the License are | |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | * Copyright (c) 1988, 1989 Apple Computer, Inc. | |
32 | * | |
33 | * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX. | |
34 | */ | |
35 | ||
36 | #ifndef lint | |
37 | /* static char sccsid[] = "@(#)ddp_brt.c: 2.0, 1.7; 10/4/93; Copyright 1988-89, Apple Computer, Inc."; */ | |
38 | #endif /* lint */ | |
39 | ||
40 | /* | |
41 | * Title: ddp_brt.c | |
42 | * | |
43 | * Facility: Best Router Caching. | |
44 | * | |
45 | * Author: Kumar Vora, Creation Date: June-15-1989 | |
46 | * | |
47 | */ | |
48 | ||
49 | #include <sys/errno.h> | |
50 | #include <sys/types.h> | |
51 | #include <sys/param.h> | |
52 | #include <machine/spl.h> | |
53 | #include <sys/systm.h> | |
54 | #include <sys/kernel.h> | |
55 | #include <sys/proc.h> | |
56 | #include <sys/filedesc.h> | |
57 | #include <sys/fcntl.h> | |
58 | #include <sys/mbuf.h> | |
59 | #include <sys/ioctl.h> | |
60 | #include <sys/malloc.h> | |
61 | #include <sys/socket.h> | |
62 | #include <sys/socketvar.h> | |
63 | #include <sys/protosw.h> | |
64 | ||
65 | #include <net/if.h> | |
66 | ||
67 | #include <netat/appletalk.h> | |
68 | #include <netat/sysglue.h> | |
69 | #include <netat/ddp.h> | |
70 | #include <netat/at_pcb.h> | |
71 | #include <netat/at_var.h> | |
72 | #include <netat/at_ddp_brt.h> | |
73 | #include <netat/debug.h> | |
74 | ||
75 | /* Best Router Cache */ | |
76 | ddp_brt_t at_ddp_brt[BRTSIZE]; | |
77 | int ddp_brt_sweep_timer; | |
78 | ||
55e303ae A |
79 | void ddp_brt_sweep(); |
80 | ||
1c79356b A |
81 | void ddp_glean(mp, ifID, src_addr) |
82 | register gbuf_t *mp; | |
83 | register at_ifaddr_t *ifID; | |
84 | struct etalk_addr *src_addr; | |
85 | { | |
86 | register at_net_al src_net; | |
87 | ||
88 | /* NOT assuming that the incoming packet is in one contiguous | |
89 | * buffer. | |
90 | */ | |
91 | ||
92 | { | |
93 | /* The interface is ethertalk, so the message is | |
94 | * of the form {802.3, 802.2, ddp.... }. Extract the | |
95 | * 802.3 source address if necessary. Assuming, | |
96 | * however, that 802.3 and 802.2 headers are in | |
97 | * one contiguous piece. | |
98 | */ | |
99 | { register at_ddp_t *dgp; | |
100 | ||
101 | dgp = (at_ddp_t *)(gbuf_rptr(mp)); | |
102 | src_net = NET_VALUE(dgp->src_net); | |
103 | } | |
104 | if (src_net >= ifID->ifThisCableStart && src_net <= ifID->ifThisCableEnd) | |
105 | /* the packet has come from a net on this cable, | |
106 | * no need to glean router info. | |
107 | */ | |
108 | return; | |
109 | ||
110 | if (src_addr != NULL) | |
111 | { register ddp_brt_t *brt; | |
112 | ||
113 | BRT_LOOK (brt, src_net); | |
114 | if (brt == NULL) { | |
115 | /* There's no BRT entry corresponding to this | |
116 | * net. Allocate a new entry. | |
117 | */ | |
118 | NEW_BRT(brt, src_net); | |
119 | if (brt == NULL) | |
120 | /* No space available in the BRT; | |
121 | * can't glean info. | |
122 | */ | |
123 | return; | |
124 | brt->net = src_net; | |
125 | } | |
126 | /* | |
127 | * update the router info in either case | |
128 | */ | |
129 | brt->et_addr = *src_addr; | |
130 | brt->age_flag = BRT_VALID; | |
131 | brt->ifID = ifID; | |
132 | } | |
133 | } | |
134 | } | |
135 | ||
136 | void ddp_brt_init() | |
137 | { | |
138 | bzero(at_ddp_brt, sizeof(at_ddp_brt)); | |
139 | ddp_brt_sweep_timer = 1; | |
140 | #ifdef NOT_USED | |
91447636 | 141 | timeout(ddp_brt_sweep_locked, (long)0, BRT_SWEEP_INT * SYS_HZ); |
1c79356b A |
142 | #endif |
143 | } | |
144 | ||
145 | void ddp_brt_shutdown() | |
146 | { | |
147 | #ifdef NOT_USED | |
148 | bzero(at_ddp_brt, sizeof(at_ddp_brt)); | |
149 | if (ddp_brt_sweep_timer) | |
91447636 | 150 | untimeout(ddp_brt_sweep_locked, 0); |
1c79356b A |
151 | #endif |
152 | ddp_brt_sweep_timer = 0; | |
153 | } | |
154 | ||
91447636 A |
155 | /* locked version */ |
156 | void ddp_brt_sweep_locked() | |
1c79356b | 157 | { |
91447636 | 158 | atalk_lock(); |
1c79356b | 159 | ddp_brt_sweep(); |
91447636 | 160 | atalk_unlock(); |
1c79356b A |
161 | } |
162 | ||
163 | void ddp_brt_sweep() | |
164 | { | |
165 | register ddp_brt_t *brt; | |
166 | register int i; | |
167 | ||
168 | if (ddp_brt_sweep_timer) | |
169 | if (++ddp_brt_sweep_timer > BRT_SWEEP_INT) { | |
170 | ddp_brt_sweep_timer = 1; | |
171 | ||
172 | brt = at_ddp_brt; | |
173 | for (i = 0; i < BRTSIZE; i++, brt++) { | |
174 | switch (brt->age_flag) { | |
175 | case BRT_EMPTY : | |
176 | break; | |
177 | case BRT_VALID : | |
178 | brt->age_flag = BRT_GETTING_OLD; | |
179 | break; | |
180 | case BRT_GETTING_OLD : | |
181 | bzero(brt, sizeof(ddp_brt_t)); | |
182 | break; | |
183 | default : | |
184 | ATTRACE(AT_MID_DDP,AT_SID_RESOURCE, AT_LV_ERROR, FALSE, | |
185 | "ddp_brt_sweep : corrupt age flag %d", | |
186 | brt->age_flag, 0,0); | |
187 | break; | |
188 | } | |
189 | } | |
190 | } | |
191 | #ifdef NOT_USED | |
192 | /* set up the next sweep... */ | |
91447636 | 193 | timeout(ddp_brt_sweep_locked, (long)0, BRT_SWEEP_INT * SYS_HZ); |
1c79356b A |
194 | #endif |
195 | ||
196 | } | |
197 | ||
198 |