|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
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.
11: *
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
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /*
23: * Copyright (c) 1988, 1989 Apple Computer, Inc.
24: *
25: * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
26: */
27:
28: #ifndef lint
29: /* static char sccsid[] = "@(#)ddp_brt.c: 2.0, 1.7; 10/4/93; Copyright 1988-89, Apple Computer, Inc."; */
30: #endif /* lint */
31:
32: /*
33: * Title: ddp_brt.c
34: *
35: * Facility: Best Router Caching.
36: *
37: * Author: Kumar Vora, Creation Date: June-15-1989
38: *
39: */
40:
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>
47: #include <sys/proc.h>
48: #include <sys/filedesc.h>
49: #include <sys/fcntl.h>
50: #include <sys/mbuf.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>
56:
57: #include <net/if.h>
58:
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>
66:
67: /* Best Router Cache */
68: ddp_brt_t at_ddp_brt[BRTSIZE];
69: int ddp_brt_sweep_timer;
70:
71: void ddp_glean(mp, ifID, src_addr)
72: register gbuf_t *mp;
73: register at_ifaddr_t *ifID;
74: struct etalk_addr *src_addr;
75: {
76: register at_net_al src_net;
77:
78: /* NOT assuming that the incoming packet is in one contiguous
79: * buffer.
80: */
81:
82: {
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.
88: */
89: { register at_ddp_t *dgp;
90:
91: dgp = (at_ddp_t *)(gbuf_rptr(mp));
92: src_net = NET_VALUE(dgp->src_net);
93: }
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.
97: */
98: return;
99:
100: if (src_addr != NULL)
101: { register ddp_brt_t *brt;
102:
103: BRT_LOOK (brt, src_net);
104: if (brt == NULL) {
105: /* There's no BRT entry corresponding to this
106: * net. Allocate a new entry.
107: */
108: NEW_BRT(brt, src_net);
109: if (brt == NULL)
110: /* No space available in the BRT;
111: * can't glean info.
112: */
113: return;
114: brt->net = src_net;
115: }
116: /*
117: * update the router info in either case
118: */
119: brt->et_addr = *src_addr;
120: brt->age_flag = BRT_VALID;
121: brt->ifID = ifID;
122: }
123: }
124: }
125:
126: void ddp_brt_init()
127: {
128: bzero(at_ddp_brt, sizeof(at_ddp_brt));
129: ddp_brt_sweep_timer = 1;
130: #ifdef NOT_USED
131: timeout(ddp_brt_sweep, (long)0, BRT_SWEEP_INT * SYS_HZ);
132: #endif
133: }
134:
135: void ddp_brt_shutdown()
136: {
137: #ifdef NOT_USED
138: bzero(at_ddp_brt, sizeof(at_ddp_brt));
139: if (ddp_brt_sweep_timer)
140: untimeout(ddp_brt_sweep, 0);
141: #endif
142: ddp_brt_sweep_timer = 0;
143: }
144:
145: void ddp_brt_sweep()
146: {
147: register ddp_brt_t *brt;
148: register int i;
149:
150: if (ddp_brt_sweep_timer)
151: if (++ddp_brt_sweep_timer > BRT_SWEEP_INT) {
152: ddp_brt_sweep_timer = 1;
153:
154: brt = at_ddp_brt;
155: for (i = 0; i < BRTSIZE; i++, brt++) {
156: switch (brt->age_flag) {
157: case BRT_EMPTY :
158: break;
159: case BRT_VALID :
160: brt->age_flag = BRT_GETTING_OLD;
161: break;
162: case BRT_GETTING_OLD :
163: bzero(brt, sizeof(ddp_brt_t));
164: break;
165: default :
166: ATTRACE(AT_MID_DDP,AT_SID_RESOURCE, AT_LV_ERROR, FALSE,
167: "ddp_brt_sweep : corrupt age flag %d",
168: brt->age_flag, 0,0);
169: break;
170: }
171: }
172: }
173: #ifdef NOT_USED
174: /* set up the next sweep... */
175: timeout(ddp_brt_sweep, (long)0, BRT_SWEEP_INT * SYS_HZ);
176: #endif
177: }
178:
179:
180:
181:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.