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