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