|
|
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) 1996 Apple Computer, Inc.
24: *
25: * Created April 8, 1996 by Tuyen Nguyen
26: * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
27: *
28: * File: misc.c
29: */
30: #include <sys/errno.h>
31: #include <sys/types.h>
32: #include <sys/param.h>
33: #include <machine/spl.h>
34: #include <sys/systm.h>
35: #include <sys/kernel.h>
36: #include <sys/proc.h>
37: #include <sys/filedesc.h>
38: #include <sys/fcntl.h>
39: #include <sys/mbuf.h>
40: #include <sys/socket.h>
41: #include <sys/socketvar.h>
42: #include <net/if.h>
43:
44: #include <netat/sysglue.h>
45: #include <netat/appletalk.h>
46: #include <netat/at_var.h>
47: #include <netat/rtmp.h>
48: #include <netat/routing_tables.h>
49: #include <netat/at_pcb.h>
50: #include <netat/aurp.h>
51: #include <netat/debug.h>
52:
53: /* */
54: void AURPiocack(gref, m)
55: gref_t *gref;
56: gbuf_t *m;
57: {
58: /* send ok reply to ioctl command */
59: gbuf_set_type(m, MSG_IOCACK);
60: atalk_putnext(gref, m);
61: }
62:
63: void AURPiocnak(gref, m, error)
64: gref_t *gref;
65: gbuf_t *m;
66: int error;
67: {
68: ioc_t *iocbp = (ioc_t *)gbuf_rptr(m);
69:
70: /* send error reply to ioctl command */
71: if (gbuf_cont(m)) {
72: gbuf_freem(gbuf_cont(m));
73: gbuf_cont(m) = 0;
74: }
75: iocbp->ioc_error = error;
76: iocbp->ioc_count = 0;
77: iocbp->ioc_rval = -1;
78: gbuf_set_type(m, MSG_IOCNAK);
79: atalk_putnext(gref, m);
80: }
81:
82: /* */
83: void AURPupdate(arg)
84: void *arg;
85: {
86: unsigned char node;
87: aurp_state_t *state = (aurp_state_t *)&aurp_state[1];
88:
89: if (aurp_gref == 0)
90: return;
91:
92: /*
93: * for every tunnel peer, do the following periodically:
94: * 1. send zone requests to determine zone names of networks
95: * that still do not have asssociated zone names.
96: * 2. send any RI update that are pending
97: */
98: for (node=1; node <= dst_addr_cnt; node++, state++) {
99: AURPsndZReq(state);
100: AURPsndRIUpd(state);
101: }
102:
103: /* restart the periodic update timer */
104: timeout(AURPupdate, arg, AURP_UpdateRate*10*HZ);
105: update_tmo = 1;
106: }
107:
108: /* */
109: void AURPfreemsg(m)
110: gbuf_t *m;
111: {
112: gbuf_t *tmp_m;
113:
114: while ((tmp_m = m) != 0) {
115: m = gbuf_next(m);
116: gbuf_next(tmp_m) = 0;
117: gbuf_freem(tmp_m);
118: }
119: }
120:
121: /* */
122: int AURPinit()
123: {
124: unsigned char node;
125: aurp_state_t *state = (aurp_state_t *)&aurp_state[1];
126: short entry_num;
127: RT_entry *entry = (RT_entry *)RT_table;
128:
129: /* start the periodic update timer */
130: timeout(AURPupdate, 0, AURP_UpdateRate*10*HZ);
131: update_tmo = 1;
132:
133: /* initialize AURP flags for entries in the RT table */
134: for (entry_num=0; entry_num < RT_maxentry; entry_num++,entry++)
135: entry->AURPFlag = 0;
136:
137: /* initiate connections to peers */
138: for (node=1; node <= dst_addr_cnt; node++, state++) {
139: bzero((char *)state, sizeof(*state));
140: state->rem_node = node;
141: state->snd_state = AURPSTATE_Unconnected;
142: state->rcv_state = AURPSTATE_Unconnected;
143: dPrintf(D_M_AURP, D_L_STARTUP_INFO,
144: ("AURPinit: sending OpenReq to node %u\n", node));
145: AURPsndOpenReq(state);
146: }
147:
148: return 0;
149: }
150:
151: /* */
152: void AURPcleanup(state)
153: aurp_state_t *state;
154: {
155: if (state->rsp_m) {
156: gbuf_freem(state->rsp_m);
157: state->rsp_m = 0;
158: }
159:
160: if (state->upd_m) {
161: gbuf_freem(state->upd_m);
162: state->upd_m = 0;
163: }
164: }
165:
166: /*
167: *
168: */
169: void AURPshutdown()
170: {
171: unsigned char node;
172: aurp_state_t *state = (aurp_state_t *)&aurp_state[1];
173:
174: /* cancel the periodic update timer */
175: untimeout(AURPupdate, 0);
176: update_tmo = 0;
177:
178: /* notify tunnel peers of router going-down */
179: for (node=1; node <= dst_addr_cnt; node++, state++) {
180: AURPcleanup(state);
181: AURPsndRDReq(state);
182: }
183:
184: /* bring down the router */
185: aurp_wakeup(NULL, (caddr_t) AE_SHUTDOWN, 0);
186: }
187:
188: void AURPaccess()
189: {
190: unsigned char i;
191: short entry_num;
192: RT_entry *entry;
193:
194: entry = (RT_entry *)RT_table;
195: for (entry_num=0; entry_num < RT_maxentry; entry_num++,entry++)
196: entry->AURPFlag = net_export ? AURP_NetHiden : 0;
197:
198: for (i=0; i < net_access_cnt; i++) {
199: /* export or hide networks as configured */
200: if ((entry = rt_blookup(net_access[i])) != 0)
201: entry->AURPFlag = net_export ? 0 : AURP_NetHiden;
202: }
203: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.