]>
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
;
74 void ddp_glean(mp
, ifID
, src_addr
)
76 register at_ifaddr_t
*ifID
;
77 struct etalk_addr
*src_addr
;
79 register at_net_al src_net
;
81 /* NOT assuming that the incoming packet is in one contiguous
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.
92 { register at_ddp_t
*dgp
;
94 dgp
= (at_ddp_t
*)(gbuf_rptr(mp
));
95 src_net
= NET_VALUE(dgp
->src_net
);
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.
103 if (src_addr
!= NULL
)
104 { register ddp_brt_t
*brt
;
106 BRT_LOOK (brt
, src_net
);
108 /* There's no BRT entry corresponding to this
109 * net. Allocate a new entry.
111 NEW_BRT(brt
, src_net
);
113 /* No space available in the BRT;
120 * update the router info in either case
122 brt
->et_addr
= *src_addr
;
123 brt
->age_flag
= BRT_VALID
;
131 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
132 ddp_brt_sweep_timer
= 1;
134 timeout(ddp_brt_sweep_funnel
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);
138 void ddp_brt_shutdown()
141 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
142 if (ddp_brt_sweep_timer
)
143 untimeout(ddp_brt_sweep_funnel
, 0);
145 ddp_brt_sweep_timer
= 0;
148 /* funneled version */
149 void ddp_brt_sweep_funnel()
151 thread_funnel_set(network_flock
, TRUE
);
153 thread_funnel_set(network_flock
, FALSE
);
158 register ddp_brt_t
*brt
;
161 if (ddp_brt_sweep_timer
)
162 if (++ddp_brt_sweep_timer
> BRT_SWEEP_INT
) {
163 ddp_brt_sweep_timer
= 1;
166 for (i
= 0; i
< BRTSIZE
; i
++, brt
++) {
167 switch (brt
->age_flag
) {
171 brt
->age_flag
= BRT_GETTING_OLD
;
173 case BRT_GETTING_OLD
:
174 bzero(brt
, sizeof(ddp_brt_t
));
177 ATTRACE(AT_MID_DDP
,AT_SID_RESOURCE
, AT_LV_ERROR
, FALSE
,
178 "ddp_brt_sweep : corrupt age flag %d",
185 /* set up the next sweep... */
186 timeout(ddp_brt_sweep_funnel
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);