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