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