]>
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
;
78 void ddp_glean(mp
, ifID
, src_addr
)
80 register at_ifaddr_t
*ifID
;
81 struct etalk_addr
*src_addr
;
83 register at_net_al src_net
;
85 /* NOT assuming that the incoming packet is in one contiguous
90 /* The interface is ethertalk, so the message is
91 * of the form {802.3, 802.2, ddp.... }. Extract the
92 * 802.3 source address if necessary. Assuming,
93 * however, that 802.3 and 802.2 headers are in
94 * one contiguous piece.
96 { register at_ddp_t
*dgp
;
98 dgp
= (at_ddp_t
*)(gbuf_rptr(mp
));
99 src_net
= NET_VALUE(dgp
->src_net
);
101 if (src_net
>= ifID
->ifThisCableStart
&& src_net
<= ifID
->ifThisCableEnd
)
102 /* the packet has come from a net on this cable,
103 * no need to glean router info.
107 if (src_addr
!= NULL
)
108 { register ddp_brt_t
*brt
;
110 BRT_LOOK (brt
, src_net
);
112 /* There's no BRT entry corresponding to this
113 * net. Allocate a new entry.
115 NEW_BRT(brt
, src_net
);
117 /* No space available in the BRT;
124 * update the router info in either case
126 brt
->et_addr
= *src_addr
;
127 brt
->age_flag
= BRT_VALID
;
135 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
136 ddp_brt_sweep_timer
= 1;
138 timeout(ddp_brt_sweep_locked
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);
142 void ddp_brt_shutdown()
145 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
146 if (ddp_brt_sweep_timer
)
147 untimeout(ddp_brt_sweep_locked
, 0);
149 ddp_brt_sweep_timer
= 0;
154 void ddp_brt_sweep_locked()
162 void ddp_brt_sweep(void)
164 register ddp_brt_t
*brt
;
167 if (ddp_brt_sweep_timer
)
168 if (++ddp_brt_sweep_timer
> BRT_SWEEP_INT
) {
169 ddp_brt_sweep_timer
= 1;
172 for (i
= 0; i
< BRTSIZE
; i
++, brt
++) {
173 switch (brt
->age_flag
) {
177 brt
->age_flag
= BRT_GETTING_OLD
;
179 case BRT_GETTING_OLD
:
180 bzero(brt
, sizeof(ddp_brt_t
));
183 ATTRACE(AT_MID_DDP
,AT_SID_RESOURCE
, AT_LV_ERROR
, FALSE
,
184 "ddp_brt_sweep : corrupt age flag %d",
191 /* set up the next sweep... */
192 timeout(ddp_brt_sweep_locked
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);