]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/aurp_misc.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / netat / aurp_misc.c
CommitLineData
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 */
0c530ab8
A
30
31#ifdef AURP_SUPPORT
32
1c79356b
A
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/* */
57void 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
66void 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/* */
86void AURPupdate(arg)
87 void *arg;
88{
89 unsigned char node;
1c79356b
A
90 aurp_state_t *state;
91
91447636 92 atalk_lock();
1c79356b
A
93
94 state = (aurp_state_t *)&aurp_state[1];
95
96 if (aurp_gref == 0) {
91447636 97 atalk_unlock();
1c79356b
A
98 return;
99 }
100 /*
101 * for every tunnel peer, do the following periodically:
102 * 1. send zone requests to determine zone names of networks
103 * that still do not have asssociated zone names.
104 * 2. send any RI update that are pending
105 */
106 for (node=1; node <= dst_addr_cnt; node++, state++) {
107 AURPsndZReq(state);
108 AURPsndRIUpd(state);
109 }
110
111 /* restart the periodic update timer */
112 timeout(AURPupdate, arg, AURP_UpdateRate*10*HZ);
113 update_tmo = 1;
114
91447636 115 atalk_unlock();
1c79356b
A
116}
117
118/* */
119void AURPfreemsg(m)
120 gbuf_t *m;
121{
122 gbuf_t *tmp_m;
123
124 while ((tmp_m = m) != 0) {
125 m = gbuf_next(m);
126 gbuf_next(tmp_m) = 0;
127 gbuf_freem(tmp_m);
128 }
129}
130
131/* */
132int AURPinit()
133{
134 unsigned char node;
135 aurp_state_t *state = (aurp_state_t *)&aurp_state[1];
136 short entry_num;
137 RT_entry *entry = (RT_entry *)RT_table;
138
139 /* start the periodic update timer */
140 timeout(AURPupdate, 0, AURP_UpdateRate*10*HZ);
141 update_tmo = 1;
142
143 /* initialize AURP flags for entries in the RT table */
144 for (entry_num=0; entry_num < RT_maxentry; entry_num++,entry++)
145 entry->AURPFlag = 0;
146
147 /* initiate connections to peers */
148 for (node=1; node <= dst_addr_cnt; node++, state++) {
149 bzero((char *)state, sizeof(*state));
150 state->rem_node = node;
151 state->snd_state = AURPSTATE_Unconnected;
152 state->rcv_state = AURPSTATE_Unconnected;
153 dPrintf(D_M_AURP, D_L_STARTUP_INFO,
154 ("AURPinit: sending OpenReq to node %u\n", node));
155 AURPsndOpenReq(state);
156 }
157
158 return 0;
159}
160
161/* */
162void AURPcleanup(state)
163 aurp_state_t *state;
164{
165 if (state->rsp_m) {
166 gbuf_freem(state->rsp_m);
167 state->rsp_m = 0;
168 }
169
170 if (state->upd_m) {
171 gbuf_freem(state->upd_m);
172 state->upd_m = 0;
173 }
174}
175
176/*
177 *
178 */
179void AURPshutdown()
180{
181 unsigned char node;
182 aurp_state_t *state = (aurp_state_t *)&aurp_state[1];
183
184 /* cancel the periodic update timer */
185 untimeout(AURPupdate, 0);
186 update_tmo = 0;
187
188 /* notify tunnel peers of router going-down */
189 for (node=1; node <= dst_addr_cnt; node++, state++) {
190 AURPcleanup(state);
191 AURPsndRDReq(state);
192 }
193
194 /* bring down the router */
195 aurp_wakeup(NULL, (caddr_t) AE_SHUTDOWN, 0);
196}
197
198void AURPaccess()
199{
200 unsigned char i;
201 short entry_num;
202 RT_entry *entry;
203
204 entry = (RT_entry *)RT_table;
205 for (entry_num=0; entry_num < RT_maxentry; entry_num++,entry++)
206 entry->AURPFlag = net_export ? AURP_NetHiden : 0;
207
208 for (i=0; i < net_access_cnt; i++) {
209 /* export or hide networks as configured */
210 if ((entry = rt_blookup(net_access[i])) != 0)
211 entry->AURPFlag = net_export ? 0 : AURP_NetHiden;
212 }
213}
0c530ab8 214