]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_brt.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1988, 1989 Apple Computer, Inc.
31 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
35 /* static char sccsid[] = "@(#)ddp_brt.c: 2.0, 1.7; 10/4/93; Copyright 1988-89, Apple Computer, Inc."; */
41 * Facility: Best Router Caching.
43 * Author: Kumar Vora, Creation Date: June-15-1989
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>
54 #include <sys/filedesc.h>
55 #include <sys/fcntl.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>
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>
73 /* Best Router Cache */
74 ddp_brt_t at_ddp_brt
[BRTSIZE
];
75 int ddp_brt_sweep_timer
;
79 void ddp_glean(mp
, ifID
, src_addr
)
81 register at_ifaddr_t
*ifID
;
82 struct etalk_addr
*src_addr
;
84 register at_net_al src_net
;
86 /* NOT assuming that the incoming packet is in one contiguous
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.
97 { register at_ddp_t
*dgp
;
99 dgp
= (at_ddp_t
*)(gbuf_rptr(mp
));
100 src_net
= NET_VALUE(dgp
->src_net
);
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.
108 if (src_addr
!= NULL
)
109 { register ddp_brt_t
*brt
;
111 BRT_LOOK (brt
, src_net
);
113 /* There's no BRT entry corresponding to this
114 * net. Allocate a new entry.
116 NEW_BRT(brt
, src_net
);
118 /* No space available in the BRT;
125 * update the router info in either case
127 brt
->et_addr
= *src_addr
;
128 brt
->age_flag
= BRT_VALID
;
136 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
137 ddp_brt_sweep_timer
= 1;
139 timeout(ddp_brt_sweep_locked
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);
143 void ddp_brt_shutdown()
146 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
147 if (ddp_brt_sweep_timer
)
148 untimeout(ddp_brt_sweep_locked
, 0);
150 ddp_brt_sweep_timer
= 0;
154 void ddp_brt_sweep_locked()
163 register ddp_brt_t
*brt
;
166 if (ddp_brt_sweep_timer
)
167 if (++ddp_brt_sweep_timer
> BRT_SWEEP_INT
) {
168 ddp_brt_sweep_timer
= 1;
171 for (i
= 0; i
< BRTSIZE
; i
++, brt
++) {
172 switch (brt
->age_flag
) {
176 brt
->age_flag
= BRT_GETTING_OLD
;
178 case BRT_GETTING_OLD
:
179 bzero(brt
, sizeof(ddp_brt_t
));
182 ATTRACE(AT_MID_DDP
,AT_SID_RESOURCE
, AT_LV_ERROR
, FALSE
,
183 "ddp_brt_sweep : corrupt age flag %d",
190 /* set up the next sweep... */
191 timeout(ddp_brt_sweep_locked
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);