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