]>
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_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1988, 1989 Apple Computer, Inc.
28 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
32 /* static char sccsid[] = "@(#)ddp_brt.c: 2.0, 1.7; 10/4/93; Copyright 1988-89, Apple Computer, Inc."; */
38 * Facility: Best Router Caching.
40 * Author: Kumar Vora, Creation Date: June-15-1989
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>
51 #include <sys/filedesc.h>
52 #include <sys/fcntl.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>
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>
70 /* Best Router Cache */
71 ddp_brt_t at_ddp_brt
[BRTSIZE
];
72 int ddp_brt_sweep_timer
;
76 void ddp_glean(mp
, ifID
, src_addr
)
78 register at_ifaddr_t
*ifID
;
79 struct etalk_addr
*src_addr
;
81 register at_net_al src_net
;
83 /* NOT assuming that the incoming packet is in one contiguous
88 /* The interface is ethertalk, so the message is
89 * of the form {802.3, 802.2, ddp.... }. Extract the
90 * 802.3 source address if necessary. Assuming,
91 * however, that 802.3 and 802.2 headers are in
92 * one contiguous piece.
94 { register at_ddp_t
*dgp
;
96 dgp
= (at_ddp_t
*)(gbuf_rptr(mp
));
97 src_net
= NET_VALUE(dgp
->src_net
);
99 if (src_net
>= ifID
->ifThisCableStart
&& src_net
<= ifID
->ifThisCableEnd
)
100 /* the packet has come from a net on this cable,
101 * no need to glean router info.
105 if (src_addr
!= NULL
)
106 { register ddp_brt_t
*brt
;
108 BRT_LOOK (brt
, src_net
);
110 /* There's no BRT entry corresponding to this
111 * net. Allocate a new entry.
113 NEW_BRT(brt
, src_net
);
115 /* No space available in the BRT;
122 * update the router info in either case
124 brt
->et_addr
= *src_addr
;
125 brt
->age_flag
= BRT_VALID
;
133 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
134 ddp_brt_sweep_timer
= 1;
136 timeout(ddp_brt_sweep_funnel
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);
140 void ddp_brt_shutdown()
143 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
144 if (ddp_brt_sweep_timer
)
145 untimeout(ddp_brt_sweep_funnel
, 0);
147 ddp_brt_sweep_timer
= 0;
150 /* funneled version */
151 void ddp_brt_sweep_funnel()
153 thread_funnel_set(network_flock
, TRUE
);
155 thread_funnel_set(network_flock
, FALSE
);
160 register ddp_brt_t
*brt
;
163 if (ddp_brt_sweep_timer
)
164 if (++ddp_brt_sweep_timer
> BRT_SWEEP_INT
) {
165 ddp_brt_sweep_timer
= 1;
168 for (i
= 0; i
< BRTSIZE
; i
++, brt
++) {
169 switch (brt
->age_flag
) {
173 brt
->age_flag
= BRT_GETTING_OLD
;
175 case BRT_GETTING_OLD
:
176 bzero(brt
, sizeof(ddp_brt_t
));
179 ATTRACE(AT_MID_DDP
,AT_SID_RESOURCE
, AT_LV_ERROR
, FALSE
,
180 "ddp_brt_sweep : corrupt age flag %d",
187 /* set up the next sweep... */
188 timeout(ddp_brt_sweep_funnel
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);