]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
6601e61a | 4 | * @APPLE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
6601e61a A |
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. | |
8f6c56a5 | 11 | * |
6601e61a A |
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 | |
8f6c56a5 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6601e61a A |
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. | |
8f6c56a5 | 19 | * |
6601e61a | 20 | * @APPLE_LICENSE_HEADER_END@ |
1c79356b A |
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; | |
1c79356b A |
87 | aurp_state_t *state; |
88 | ||
91447636 | 89 | atalk_lock(); |
1c79356b A |
90 | |
91 | state = (aurp_state_t *)&aurp_state[1]; | |
92 | ||
93 | if (aurp_gref == 0) { | |
91447636 | 94 | atalk_unlock(); |
1c79356b A |
95 | return; |
96 | } | |
97 | /* | |
98 | * for every tunnel peer, do the following periodically: | |
99 | * 1. send zone requests to determine zone names of networks | |
100 | * that still do not have asssociated zone names. | |
101 | * 2. send any RI update that are pending | |
102 | */ | |
103 | for (node=1; node <= dst_addr_cnt; node++, state++) { | |
104 | AURPsndZReq(state); | |
105 | AURPsndRIUpd(state); | |
106 | } | |
107 | ||
108 | /* restart the periodic update timer */ | |
109 | timeout(AURPupdate, arg, AURP_UpdateRate*10*HZ); | |
110 | update_tmo = 1; | |
111 | ||
91447636 | 112 | atalk_unlock(); |
1c79356b A |
113 | } |
114 | ||
115 | /* */ | |
116 | void AURPfreemsg(m) | |
117 | gbuf_t *m; | |
118 | { | |
119 | gbuf_t *tmp_m; | |
120 | ||
121 | while ((tmp_m = m) != 0) { | |
122 | m = gbuf_next(m); | |
123 | gbuf_next(tmp_m) = 0; | |
124 | gbuf_freem(tmp_m); | |
125 | } | |
126 | } | |
127 | ||
128 | /* */ | |
129 | int AURPinit() | |
130 | { | |
131 | unsigned char node; | |
132 | aurp_state_t *state = (aurp_state_t *)&aurp_state[1]; | |
133 | short entry_num; | |
134 | RT_entry *entry = (RT_entry *)RT_table; | |
135 | ||
136 | /* start the periodic update timer */ | |
137 | timeout(AURPupdate, 0, AURP_UpdateRate*10*HZ); | |
138 | update_tmo = 1; | |
139 | ||
140 | /* initialize AURP flags for entries in the RT table */ | |
141 | for (entry_num=0; entry_num < RT_maxentry; entry_num++,entry++) | |
142 | entry->AURPFlag = 0; | |
143 | ||
144 | /* initiate connections to peers */ | |
145 | for (node=1; node <= dst_addr_cnt; node++, state++) { | |
146 | bzero((char *)state, sizeof(*state)); | |
147 | state->rem_node = node; | |
148 | state->snd_state = AURPSTATE_Unconnected; | |
149 | state->rcv_state = AURPSTATE_Unconnected; | |
150 | dPrintf(D_M_AURP, D_L_STARTUP_INFO, | |
151 | ("AURPinit: sending OpenReq to node %u\n", node)); | |
152 | AURPsndOpenReq(state); | |
153 | } | |
154 | ||
155 | return 0; | |
156 | } | |
157 | ||
158 | /* */ | |
159 | void AURPcleanup(state) | |
160 | aurp_state_t *state; | |
161 | { | |
162 | if (state->rsp_m) { | |
163 | gbuf_freem(state->rsp_m); | |
164 | state->rsp_m = 0; | |
165 | } | |
166 | ||
167 | if (state->upd_m) { | |
168 | gbuf_freem(state->upd_m); | |
169 | state->upd_m = 0; | |
170 | } | |
171 | } | |
172 | ||
173 | /* | |
174 | * | |
175 | */ | |
176 | void AURPshutdown() | |
177 | { | |
178 | unsigned char node; | |
179 | aurp_state_t *state = (aurp_state_t *)&aurp_state[1]; | |
180 | ||
181 | /* cancel the periodic update timer */ | |
182 | untimeout(AURPupdate, 0); | |
183 | update_tmo = 0; | |
184 | ||
185 | /* notify tunnel peers of router going-down */ | |
186 | for (node=1; node <= dst_addr_cnt; node++, state++) { | |
187 | AURPcleanup(state); | |
188 | AURPsndRDReq(state); | |
189 | } | |
190 | ||
191 | /* bring down the router */ | |
192 | aurp_wakeup(NULL, (caddr_t) AE_SHUTDOWN, 0); | |
193 | } | |
194 | ||
195 | void AURPaccess() | |
196 | { | |
197 | unsigned char i; | |
198 | short entry_num; | |
199 | RT_entry *entry; | |
200 | ||
201 | entry = (RT_entry *)RT_table; | |
202 | for (entry_num=0; entry_num < RT_maxentry; entry_num++,entry++) | |
203 | entry->AURPFlag = net_export ? AURP_NetHiden : 0; | |
204 | ||
205 | for (i=0; i < net_access_cnt; i++) { | |
206 | /* export or hide networks as configured */ | |
207 | if ((entry = rt_blookup(net_access[i])) != 0) | |
208 | entry->AURPFlag = net_export ? 0 : AURP_NetHiden; | |
209 | } | |
210 | } |