1/* 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 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 License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28/* 29 * Copyright (c) 1988, 1989 Apple Computer, Inc. 30 * 31 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX. 32 */ 33 34#ifndef lint 35/* static char sccsid[] = "@(#)ddp_brt.c: 2.0, 1.7; 10/4/93; Copyright 1988-89, Apple Computer, Inc."; */ 36#endif /* lint */ 37 38/* 39 * Title: ddp_brt.c 40 * 41 * Facility: Best Router Caching. 42 * 43 * Author: Kumar Vora, Creation Date: June-15-1989 44 * 45 */ 46 47#include <sys/errno.h> 48#include <sys/types.h> 49#include <sys/param.h> 50#include <machine/spl.h> 51#include <sys/systm.h> 52#include <sys/kernel.h> 53#include <sys/proc.h> 54#include <sys/filedesc.h> 55#include <sys/fcntl.h> 56#include <sys/mbuf.h> 57#include <sys/ioctl.h> 58#include <sys/malloc.h> 59#include <sys/socket.h> 60#include <sys/socketvar.h> 61#include <sys/protosw.h> 62 63#include <net/if.h> 64 65#include <netat/appletalk.h> 66#include <netat/sysglue.h> 67#include <netat/ddp.h> 68#include <netat/at_pcb.h> 69#include <netat/at_var.h> 70#include <netat/at_ddp_brt.h> 71#include <netat/debug.h> 72 73/* Best Router Cache */ 74ddp_brt_t at_ddp_brt[BRTSIZE]; 75int ddp_brt_sweep_timer; 76 77 78void ddp_glean(mp, ifID, src_addr) 79 register gbuf_t *mp; 80 register at_ifaddr_t *ifID; 81 struct etalk_addr *src_addr; 82{ 83 register at_net_al src_net; 84 85 /* NOT assuming that the incoming packet is in one contiguous 86 * buffer. 87 */ 88 89 { 90 /* The interface is ethertalk, so the message is 91 * of the form {802.3, 802.2, ddp.... }. Extract the 92 * 802.3 source address if necessary. Assuming, 93 * however, that 802.3 and 802.2 headers are in 94 * one contiguous piece. 95 */ 96 { register at_ddp_t *dgp; 97 98 dgp = (at_ddp_t *)(gbuf_rptr(mp)); 99 src_net = NET_VALUE(dgp->src_net); 100 } 101 if (src_net >= ifID->ifThisCableStart && src_net <= ifID->ifThisCableEnd) 102 /* the packet has come from a net on this cable, 103 * no need to glean router info. 104 */ 105 return; 106 107 if (src_addr != NULL) 108 { register ddp_brt_t *brt; 109 110 BRT_LOOK (brt, src_net); 111 if (brt == NULL) { 112 /* There's no BRT entry corresponding to this 113 * net. Allocate a new entry. 114 */ 115 NEW_BRT(brt, src_net); 116 if (brt == NULL) 117 /* No space available in the BRT; 118 * can't glean info. 119 */ 120 return; 121 brt->net = src_net; 122 } 123 /* 124 * update the router info in either case 125 */ 126 brt->et_addr = *src_addr; 127 brt->age_flag = BRT_VALID; 128 brt->ifID = ifID; 129 } 130 } 131} 132 133void ddp_brt_init() 134{ 135 bzero(at_ddp_brt, sizeof(at_ddp_brt)); 136 ddp_brt_sweep_timer = 1; 137#ifdef NOT_USED 138 timeout(ddp_brt_sweep_locked, (long)0, BRT_SWEEP_INT * SYS_HZ); 139#endif 140} 141 142void ddp_brt_shutdown() 143{ 144#ifdef NOT_USED 145 bzero(at_ddp_brt, sizeof(at_ddp_brt)); 146 if (ddp_brt_sweep_timer) 147 untimeout(ddp_brt_sweep_locked, 0); 148#endif 149 ddp_brt_sweep_timer = 0; 150} 151 152/* locked version */ 153#ifdef NOT_USED 154void ddp_brt_sweep_locked() 155{ 156 atalk_lock(); 157 ddp_brt_sweep(); 158 atalk_unlock(); 159} 160#endif 161 162void ddp_brt_sweep(void) 163{ 164 register ddp_brt_t *brt; 165 register int i; 166 167 if (ddp_brt_sweep_timer) 168 if (++ddp_brt_sweep_timer > BRT_SWEEP_INT) { 169 ddp_brt_sweep_timer = 1; 170 171 brt = at_ddp_brt; 172 for (i = 0; i < BRTSIZE; i++, brt++) { 173 switch (brt->age_flag) { 174 case BRT_EMPTY : 175 break; 176 case BRT_VALID : 177 brt->age_flag = BRT_GETTING_OLD; 178 break; 179 case BRT_GETTING_OLD : 180 bzero(brt, sizeof(ddp_brt_t)); 181 break; 182 default : 183 ATTRACE(AT_MID_DDP,AT_SID_RESOURCE, AT_LV_ERROR, FALSE, 184 "ddp_brt_sweep : corrupt age flag %d", 185 brt->age_flag, 0,0); 186 break; 187 } 188 } 189 } 190#ifdef NOT_USED 191 /* set up the next sweep... */ 192 timeout(ddp_brt_sweep_locked, (long)0, BRT_SWEEP_INT * SYS_HZ); 193#endif 194 195} 196 197 198