]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_brt.c
0a3e83a1307e0fade2a8e64596be10791b6993a1
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1988, 1989 Apple Computer, Inc.
33 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
37 /* static char sccsid[] = "@(#)ddp_brt.c: 2.0, 1.7; 10/4/93; Copyright 1988-89, Apple Computer, Inc."; */
43 * Facility: Best Router Caching.
45 * Author: Kumar Vora, Creation Date: June-15-1989
49 #include <sys/errno.h>
50 #include <sys/types.h>
51 #include <sys/param.h>
52 #include <machine/spl.h>
53 #include <sys/systm.h>
54 #include <sys/kernel.h>
56 #include <sys/filedesc.h>
57 #include <sys/fcntl.h>
59 #include <sys/ioctl.h>
60 #include <sys/malloc.h>
61 #include <sys/socket.h>
62 #include <sys/socketvar.h>
63 #include <sys/protosw.h>
67 #include <netat/appletalk.h>
68 #include <netat/sysglue.h>
69 #include <netat/ddp.h>
70 #include <netat/at_pcb.h>
71 #include <netat/at_var.h>
72 #include <netat/at_ddp_brt.h>
73 #include <netat/debug.h>
75 /* Best Router Cache */
76 ddp_brt_t at_ddp_brt
[BRTSIZE
];
77 int ddp_brt_sweep_timer
;
81 void ddp_glean(mp
, ifID
, src_addr
)
83 register at_ifaddr_t
*ifID
;
84 struct etalk_addr
*src_addr
;
86 register at_net_al src_net
;
88 /* NOT assuming that the incoming packet is in one contiguous
93 /* The interface is ethertalk, so the message is
94 * of the form {802.3, 802.2, ddp.... }. Extract the
95 * 802.3 source address if necessary. Assuming,
96 * however, that 802.3 and 802.2 headers are in
97 * one contiguous piece.
99 { register at_ddp_t
*dgp
;
101 dgp
= (at_ddp_t
*)(gbuf_rptr(mp
));
102 src_net
= NET_VALUE(dgp
->src_net
);
104 if (src_net
>= ifID
->ifThisCableStart
&& src_net
<= ifID
->ifThisCableEnd
)
105 /* the packet has come from a net on this cable,
106 * no need to glean router info.
110 if (src_addr
!= NULL
)
111 { register ddp_brt_t
*brt
;
113 BRT_LOOK (brt
, src_net
);
115 /* There's no BRT entry corresponding to this
116 * net. Allocate a new entry.
118 NEW_BRT(brt
, src_net
);
120 /* No space available in the BRT;
127 * update the router info in either case
129 brt
->et_addr
= *src_addr
;
130 brt
->age_flag
= BRT_VALID
;
138 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
139 ddp_brt_sweep_timer
= 1;
141 timeout(ddp_brt_sweep_locked
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);
145 void ddp_brt_shutdown()
148 bzero(at_ddp_brt
, sizeof(at_ddp_brt
));
149 if (ddp_brt_sweep_timer
)
150 untimeout(ddp_brt_sweep_locked
, 0);
152 ddp_brt_sweep_timer
= 0;
156 void ddp_brt_sweep_locked()
165 register ddp_brt_t
*brt
;
168 if (ddp_brt_sweep_timer
)
169 if (++ddp_brt_sweep_timer
> BRT_SWEEP_INT
) {
170 ddp_brt_sweep_timer
= 1;
173 for (i
= 0; i
< BRTSIZE
; i
++, brt
++) {
174 switch (brt
->age_flag
) {
178 brt
->age_flag
= BRT_GETTING_OLD
;
180 case BRT_GETTING_OLD
:
181 bzero(brt
, sizeof(ddp_brt_t
));
184 ATTRACE(AT_MID_DDP
,AT_SID_RESOURCE
, AT_LV_ERROR
, FALSE
,
185 "ddp_brt_sweep : corrupt age flag %d",
192 /* set up the next sweep... */
193 timeout(ddp_brt_sweep_locked
, (long)0, BRT_SWEEP_INT
* SYS_HZ
);