]>
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
;
73 void ddp_glean(mp
, ifID
, src_addr
)
75 register at_ifaddr_t
*ifID
;
76 struct etalk_addr
*src_addr
;
78 register at_net_al src_net
;
80 /* NOT assuming that the incoming packet is in one contiguous
85 /* The interface is ethertalk, so the message is
86 * of the form {802.3, 802.2, ddp.... }. Extract the
87 * 802.3 source address if necessary. Assuming,
88 * however, that 802.3 and 802.2 headers are in
89 * one contiguous piece.
91 { register at_ddp_t
*dgp
;
93 dgp
= (at_ddp_t
*)(gbuf_rptr(mp
));
94 src_net
= NET_VALUE(dgp
->src_net
);
96 if (src_net
>= ifID
->ifThisCableStart
&& src_net
<= ifID
->ifThisCableEnd
)
97 /* the packet has come from a net on this cable,
98 * no need to glean router info.
102 if (src_addr
!= NULL
)
103 { register ddp_brt_t
*brt
;
105 BRT_LOOK (brt
, src_net
);
107 /* There's no BRT entry corresponding to this
108 * net. Allocate a new entry.
110 NEW_BRT(brt
, src_net
);
112 /* No space available in the BRT;
119 * update the router info in either case
121 brt
->et_addr
= *src_addr
;
122 brt
->age_flag
= BRT_VALID
;
130 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
131 ddp_brt_sweep_timer
= 1;
133 timeout(ddp_brt_sweep_funnel
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);
137 void ddp_brt_shutdown()
140 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
141 if (ddp_brt_sweep_timer
)
142 untimeout(ddp_brt_sweep_funnel
, 0);
144 ddp_brt_sweep_timer
= 0;
147 /* funneled version */
148 void ddp_brt_sweep_funnel()
150 thread_funnel_set(network_flock
, TRUE
);
152 thread_funnel_set(network_flock
, FALSE
);
157 register ddp_brt_t
*brt
;
160 if (ddp_brt_sweep_timer
)
161 if (++ddp_brt_sweep_timer
> BRT_SWEEP_INT
) {
162 ddp_brt_sweep_timer
= 1;
165 for (i
= 0; i
< BRTSIZE
; i
++, brt
++) {
166 switch (brt
->age_flag
) {
170 brt
->age_flag
= BRT_GETTING_OLD
;
172 case BRT_GETTING_OLD
:
173 bzero(brt
, sizeof(ddp_brt_t
));
176 ATTRACE(AT_MID_DDP
,AT_SID_RESOURCE
, AT_LV_ERROR
, FALSE
,
177 "ddp_brt_sweep : corrupt age flag %d",
184 /* set up the next sweep... */
185 timeout(ddp_brt_sweep_funnel
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);