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