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