]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_brt.c
xnu-124.8.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 * 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.
11 *
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
18 * under the License.
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
71 void ddp_glean(mp, ifID, src_addr)
72 register gbuf_t *mp;
73 register at_ifaddr_t *ifID;
74 struct etalk_addr *src_addr;
75 {
76 register at_net_al src_net;
77
78 /* NOT assuming that the incoming packet is in one contiguous
79 * buffer.
80 */
81
82 {
83 /* The interface is ethertalk, so the message is
84 * of the form {802.3, 802.2, ddp.... }. Extract the
85 * 802.3 source address if necessary. Assuming,
86 * however, that 802.3 and 802.2 headers are in
87 * one contiguous piece.
88 */
89 { register at_ddp_t *dgp;
90
91 dgp = (at_ddp_t *)(gbuf_rptr(mp));
92 src_net = NET_VALUE(dgp->src_net);
93 }
94 if (src_net >= ifID->ifThisCableStart && src_net <= ifID->ifThisCableEnd)
95 /* the packet has come from a net on this cable,
96 * no need to glean router info.
97 */
98 return;
99
100 if (src_addr != NULL)
101 { register ddp_brt_t *brt;
102
103 BRT_LOOK (brt, src_net);
104 if (brt == NULL) {
105 /* There's no BRT entry corresponding to this
106 * net. Allocate a new entry.
107 */
108 NEW_BRT(brt, src_net);
109 if (brt == NULL)
110 /* No space available in the BRT;
111 * can't glean info.
112 */
113 return;
114 brt->net = src_net;
115 }
116 /*
117 * update the router info in either case
118 */
119 brt->et_addr = *src_addr;
120 brt->age_flag = BRT_VALID;
121 brt->ifID = ifID;
122 }
123 }
124 }
125
126 void ddp_brt_init()
127 {
128 bzero(at_ddp_brt, sizeof(at_ddp_brt));
129 ddp_brt_sweep_timer = 1;
130 #ifdef NOT_USED
131 timeout(ddp_brt_sweep_funnel, (long)0, BRT_SWEEP_INT * SYS_HZ);
132 #endif
133 }
134
135 void ddp_brt_shutdown()
136 {
137 #ifdef NOT_USED
138 bzero(at_ddp_brt, sizeof(at_ddp_brt));
139 if (ddp_brt_sweep_timer)
140 untimeout(ddp_brt_sweep_funnel, 0);
141 #endif
142 ddp_brt_sweep_timer = 0;
143 }
144
145 /* funneled version */
146 void ddp_brt_sweep_funnel()
147 {
148 thread_funnel_set(network_flock, TRUE);
149 ddp_brt_sweep();
150 thread_funnel_set(network_flock, FALSE);
151 }
152
153 void ddp_brt_sweep()
154 {
155 register ddp_brt_t *brt;
156 register int i;
157
158 if (ddp_brt_sweep_timer)
159 if (++ddp_brt_sweep_timer > BRT_SWEEP_INT) {
160 ddp_brt_sweep_timer = 1;
161
162 brt = at_ddp_brt;
163 for (i = 0; i < BRTSIZE; i++, brt++) {
164 switch (brt->age_flag) {
165 case BRT_EMPTY :
166 break;
167 case BRT_VALID :
168 brt->age_flag = BRT_GETTING_OLD;
169 break;
170 case BRT_GETTING_OLD :
171 bzero(brt, sizeof(ddp_brt_t));
172 break;
173 default :
174 ATTRACE(AT_MID_DDP,AT_SID_RESOURCE, AT_LV_ERROR, FALSE,
175 "ddp_brt_sweep : corrupt age flag %d",
176 brt->age_flag, 0,0);
177 break;
178 }
179 }
180 }
181 #ifdef NOT_USED
182 /* set up the next sweep... */
183 timeout(ddp_brt_sweep_funnel, (long)0, BRT_SWEEP_INT * SYS_HZ);
184 #endif
185
186 }
187
188