]>
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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1988, 1989 Apple Computer, Inc.
25 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
29 /* static char sccsid[] = "@(#)ddp_brt.c: 2.0, 1.7; 10/4/93; Copyright 1988-89, Apple Computer, Inc."; */
35 * Facility: Best Router Caching.
37 * Author: Kumar Vora, Creation Date: June-15-1989
41 #include <sys/errno.h>
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <machine/spl.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
48 #include <sys/filedesc.h>
49 #include <sys/fcntl.h>
51 #include <sys/ioctl.h>
52 #include <sys/malloc.h>
53 #include <sys/socket.h>
54 #include <sys/socketvar.h>
55 #include <sys/protosw.h>
59 #include <netat/appletalk.h>
60 #include <netat/sysglue.h>
61 #include <netat/ddp.h>
62 #include <netat/at_pcb.h>
63 #include <netat/at_var.h>
64 #include <netat/at_ddp_brt.h>
65 #include <netat/debug.h>
67 /* Best Router Cache */
68 ddp_brt_t at_ddp_brt
[BRTSIZE
];
69 int ddp_brt_sweep_timer
;
71 void ddp_glean(mp
, ifID
, src_addr
)
73 register at_ifaddr_t
*ifID
;
74 struct etalk_addr
*src_addr
;
76 register at_net_al src_net
;
78 /* NOT assuming that the incoming packet is in one contiguous
83 /* The interface is ethertalk, so the message is
84 * of the form {802.3, 802.2, ddp.... }. Extract the
85 * 802.3 source address if necessary. Assuming,
86 * however, that 802.3 and 802.2 headers are in
87 * one contiguous piece.
89 { register at_ddp_t
*dgp
;
91 dgp
= (at_ddp_t
*)(gbuf_rptr(mp
));
92 src_net
= NET_VALUE(dgp
->src_net
);
94 if (src_net
>= ifID
->ifThisCableStart
&& src_net
<= ifID
->ifThisCableEnd
)
95 /* the packet has come from a net on this cable,
96 * no need to glean router info.
100 if (src_addr
!= NULL
)
101 { register ddp_brt_t
*brt
;
103 BRT_LOOK (brt
, src_net
);
105 /* There's no BRT entry corresponding to this
106 * net. Allocate a new entry.
108 NEW_BRT(brt
, src_net
);
110 /* No space available in the BRT;
117 * update the router info in either case
119 brt
->et_addr
= *src_addr
;
120 brt
->age_flag
= BRT_VALID
;
128 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
129 ddp_brt_sweep_timer
= 1;
131 timeout(ddp_brt_sweep_funnel
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);
135 void ddp_brt_shutdown()
138 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
139 if (ddp_brt_sweep_timer
)
140 untimeout(ddp_brt_sweep_funnel
, 0);
142 ddp_brt_sweep_timer
= 0;
145 /* funneled version */
146 void ddp_brt_sweep_funnel()
148 thread_funnel_set(network_flock
, TRUE
);
150 thread_funnel_set(network_flock
, FALSE
);
155 register ddp_brt_t
*brt
;
158 if (ddp_brt_sweep_timer
)
159 if (++ddp_brt_sweep_timer
> BRT_SWEEP_INT
) {
160 ddp_brt_sweep_timer
= 1;
163 for (i
= 0; i
< BRTSIZE
; i
++, brt
++) {
164 switch (brt
->age_flag
) {
168 brt
->age_flag
= BRT_GETTING_OLD
;
170 case BRT_GETTING_OLD
:
171 bzero(brt
, sizeof(ddp_brt_t
));
174 ATTRACE(AT_MID_DDP
,AT_SID_RESOURCE
, AT_LV_ERROR
, FALSE
,
175 "ddp_brt_sweep : corrupt age flag %d",
182 /* set up the next sweep... */
183 timeout(ddp_brt_sweep_funnel
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);