]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/netat/aurp_misc.c
xnu-517.12.7.tar.gz
[apple/xnu.git] / bsd / netat / aurp_misc.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
19 *
20 * @APPLE_LICENSE_HEADER_END@
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/* */
54void 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
63void 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/* */
83void AURPupdate(arg)
84 void *arg;
85{
86 unsigned char node;
87 boolean_t funnel_state;
88 aurp_state_t *state;
89
90 funnel_state = thread_funnel_set(network_flock, TRUE);
91
92 state = (aurp_state_t *)&aurp_state[1];
93
94 if (aurp_gref == 0) {
95 (void) thread_funnel_set(network_flock, FALSE);
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
113 (void) thread_funnel_set(network_flock, FALSE);
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}