]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/aurp_misc.c
xnu-517.3.15.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_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1996 Apple Computer, Inc.
27 *
28 * Created April 8, 1996 by Tuyen Nguyen
29 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
30 *
31 * File: misc.c
32 */
33 #include <sys/errno.h>
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <machine/spl.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/proc.h>
40 #include <sys/filedesc.h>
41 #include <sys/fcntl.h>
42 #include <sys/mbuf.h>
43 #include <sys/socket.h>
44 #include <sys/socketvar.h>
45 #include <net/if.h>
46
47 #include <netat/sysglue.h>
48 #include <netat/appletalk.h>
49 #include <netat/at_var.h>
50 #include <netat/rtmp.h>
51 #include <netat/routing_tables.h>
52 #include <netat/at_pcb.h>
53 #include <netat/aurp.h>
54 #include <netat/debug.h>
55
56 /* */
57 void AURPiocack(gref, m)
58 gref_t *gref;
59 gbuf_t *m;
60 {
61 /* send ok reply to ioctl command */
62 gbuf_set_type(m, MSG_IOCACK);
63 atalk_putnext(gref, m);
64 }
65
66 void AURPiocnak(gref, m, error)
67 gref_t *gref;
68 gbuf_t *m;
69 int error;
70 {
71 ioc_t *iocbp = (ioc_t *)gbuf_rptr(m);
72
73 /* send error reply to ioctl command */
74 if (gbuf_cont(m)) {
75 gbuf_freem(gbuf_cont(m));
76 gbuf_cont(m) = 0;
77 }
78 iocbp->ioc_error = error;
79 iocbp->ioc_count = 0;
80 iocbp->ioc_rval = -1;
81 gbuf_set_type(m, MSG_IOCNAK);
82 atalk_putnext(gref, m);
83 }
84
85 /* */
86 void AURPupdate(arg)
87 void *arg;
88 {
89 unsigned char node;
90 boolean_t funnel_state;
91 aurp_state_t *state;
92
93 funnel_state = thread_funnel_set(network_flock, TRUE);
94
95 state = (aurp_state_t *)&aurp_state[1];
96
97 if (aurp_gref == 0) {
98 (void) thread_funnel_set(network_flock, FALSE);
99 return;
100 }
101 /*
102 * for every tunnel peer, do the following periodically:
103 * 1. send zone requests to determine zone names of networks
104 * that still do not have asssociated zone names.
105 * 2. send any RI update that are pending
106 */
107 for (node=1; node <= dst_addr_cnt; node++, state++) {
108 AURPsndZReq(state);
109 AURPsndRIUpd(state);
110 }
111
112 /* restart the periodic update timer */
113 timeout(AURPupdate, arg, AURP_UpdateRate*10*HZ);
114 update_tmo = 1;
115
116 (void) thread_funnel_set(network_flock, FALSE);
117 }
118
119 /* */
120 void AURPfreemsg(m)
121 gbuf_t *m;
122 {
123 gbuf_t *tmp_m;
124
125 while ((tmp_m = m) != 0) {
126 m = gbuf_next(m);
127 gbuf_next(tmp_m) = 0;
128 gbuf_freem(tmp_m);
129 }
130 }
131
132 /* */
133 int AURPinit()
134 {
135 unsigned char node;
136 aurp_state_t *state = (aurp_state_t *)&aurp_state[1];
137 short entry_num;
138 RT_entry *entry = (RT_entry *)RT_table;
139
140 /* start the periodic update timer */
141 timeout(AURPupdate, 0, AURP_UpdateRate*10*HZ);
142 update_tmo = 1;
143
144 /* initialize AURP flags for entries in the RT table */
145 for (entry_num=0; entry_num < RT_maxentry; entry_num++,entry++)
146 entry->AURPFlag = 0;
147
148 /* initiate connections to peers */
149 for (node=1; node <= dst_addr_cnt; node++, state++) {
150 bzero((char *)state, sizeof(*state));
151 state->rem_node = node;
152 state->snd_state = AURPSTATE_Unconnected;
153 state->rcv_state = AURPSTATE_Unconnected;
154 dPrintf(D_M_AURP, D_L_STARTUP_INFO,
155 ("AURPinit: sending OpenReq to node %u\n", node));
156 AURPsndOpenReq(state);
157 }
158
159 return 0;
160 }
161
162 /* */
163 void AURPcleanup(state)
164 aurp_state_t *state;
165 {
166 if (state->rsp_m) {
167 gbuf_freem(state->rsp_m);
168 state->rsp_m = 0;
169 }
170
171 if (state->upd_m) {
172 gbuf_freem(state->upd_m);
173 state->upd_m = 0;
174 }
175 }
176
177 /*
178 *
179 */
180 void AURPshutdown()
181 {
182 unsigned char node;
183 aurp_state_t *state = (aurp_state_t *)&aurp_state[1];
184
185 /* cancel the periodic update timer */
186 untimeout(AURPupdate, 0);
187 update_tmo = 0;
188
189 /* notify tunnel peers of router going-down */
190 for (node=1; node <= dst_addr_cnt; node++, state++) {
191 AURPcleanup(state);
192 AURPsndRDReq(state);
193 }
194
195 /* bring down the router */
196 aurp_wakeup(NULL, (caddr_t) AE_SHUTDOWN, 0);
197 }
198
199 void AURPaccess()
200 {
201 unsigned char i;
202 short entry_num;
203 RT_entry *entry;
204
205 entry = (RT_entry *)RT_table;
206 for (entry_num=0; entry_num < RT_maxentry; entry_num++,entry++)
207 entry->AURPFlag = net_export ? AURP_NetHiden : 0;
208
209 for (i=0; i < net_access_cnt; i++) {
210 /* export or hide networks as configured */
211 if ((entry = rt_blookup(net_access[i])) != 0)
212 entry->AURPFlag = net_export ? 0 : AURP_NetHiden;
213 }
214 }