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