rsrr.c revision 1.5 1 1.5 wiz /* $NetBSD: rsrr.c,v 1.5 2002/07/14 16:30:42 wiz Exp $ */
2 1.2 thorpej
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1993 by the University of Southern California
5 1.1 mycroft * All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * Permission to use, copy, modify, and distribute this software and its
8 1.1 mycroft * documentation in source and binary forms for non-commercial purposes
9 1.1 mycroft * and without fee is hereby granted, provided that the above copyright
10 1.1 mycroft * notice appear in all copies and that both the copyright notice and
11 1.1 mycroft * this permission notice appear in supporting documentation. and that
12 1.1 mycroft * any documentation, advertising materials, and other materials related
13 1.1 mycroft * to such distribution and use acknowledge that the software was
14 1.1 mycroft * developed by the University of Southern California, Information
15 1.1 mycroft * Sciences Institute. The name of the University may not be used to
16 1.1 mycroft * endorse or promote products derived from this software without
17 1.1 mycroft * specific prior written permission.
18 1.1 mycroft *
19 1.1 mycroft * THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
20 1.1 mycroft * the suitability of this software for any purpose. THIS SOFTWARE IS
21 1.1 mycroft * PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
22 1.1 mycroft * INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
23 1.1 mycroft * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 1.1 mycroft *
25 1.1 mycroft * Other copyrights might apply to parts of this software and are so
26 1.1 mycroft * noted when applicable.
27 1.1 mycroft */
28 1.1 mycroft
29 1.1 mycroft /* RSRR code written by Daniel Zappala, USC Information Sciences Institute,
30 1.1 mycroft * April 1995.
31 1.1 mycroft */
32 1.1 mycroft
33 1.3 mycroft /* May 1995 -- Added support for Route Change Notification */
34 1.3 mycroft
35 1.1 mycroft #ifdef RSRR
36 1.1 mycroft
37 1.1 mycroft #include "defs.h"
38 1.3 mycroft #include <sys/param.h>
39 1.3 mycroft #if (defined(BSD) && (BSD >= 199103))
40 1.3 mycroft #include <stddef.h>
41 1.3 mycroft #endif
42 1.1 mycroft
43 1.1 mycroft /* Taken from prune.c */
44 1.1 mycroft /*
45 1.1 mycroft * checks for scoped multicast addresses
46 1.1 mycroft */
47 1.1 mycroft #define GET_SCOPE(gt) { \
48 1.5 wiz int _i; \
49 1.1 mycroft if (((gt)->gt_mcastgrp & 0xff000000) == 0xef000000) \
50 1.1 mycroft for (_i = 0; _i < numvifs; _i++) \
51 1.1 mycroft if (scoped_addr(_i, (gt)->gt_mcastgrp)) \
52 1.1 mycroft VIFM_SET(_i, (gt)->gt_scope); \
53 1.1 mycroft }
54 1.1 mycroft
55 1.1 mycroft /*
56 1.1 mycroft * Exported variables.
57 1.1 mycroft */
58 1.1 mycroft int rsrr_socket; /* interface to reservation protocol */
59 1.1 mycroft
60 1.1 mycroft /*
61 1.1 mycroft * Global RSRR variables.
62 1.1 mycroft */
63 1.1 mycroft char rsrr_recv_buf[RSRR_MAX_LEN]; /* RSRR receive buffer */
64 1.1 mycroft char rsrr_send_buf[RSRR_MAX_LEN]; /* RSRR send buffer */
65 1.1 mycroft
66 1.3 mycroft struct sockaddr_un client_addr;
67 1.3 mycroft int client_length = sizeof(client_addr);
68 1.3 mycroft
69 1.3 mycroft
70 1.1 mycroft /*
71 1.1 mycroft * Procedure definitions needed internally.
72 1.1 mycroft */
73 1.5 wiz static void rsrr_accept(int recvlen);
74 1.5 wiz static void rsrr_accept_iq(void);
75 1.5 wiz static int rsrr_accept_rq(struct rsrr_rq *route_query, int flags,
76 1.5 wiz struct gtable *gt_notify);
77 1.5 wiz static int rsrr_send(int sendlen);
78 1.5 wiz static void rsrr_cache(struct gtable *gt, struct rsrr_rq *route_query);
79 1.1 mycroft
80 1.1 mycroft /* Initialize RSRR socket */
81 1.1 mycroft void
82 1.1 mycroft rsrr_init()
83 1.1 mycroft {
84 1.1 mycroft int servlen;
85 1.1 mycroft struct sockaddr_un serv_addr;
86 1.1 mycroft
87 1.4 lukem if ((rsrr_socket = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)
88 1.1 mycroft log(LOG_ERR, errno, "Can't create RSRR socket");
89 1.1 mycroft
90 1.1 mycroft unlink(RSRR_SERV_PATH);
91 1.1 mycroft bzero((char *) &serv_addr, sizeof(serv_addr));
92 1.4 lukem serv_addr.sun_family = AF_LOCAL;
93 1.1 mycroft strcpy(serv_addr.sun_path, RSRR_SERV_PATH);
94 1.3 mycroft #if (defined(BSD) && (BSD >= 199103))
95 1.3 mycroft servlen = offsetof(struct sockaddr_un, sun_path) +
96 1.3 mycroft strlen(serv_addr.sun_path);
97 1.3 mycroft serv_addr.sun_len = servlen;
98 1.3 mycroft #else
99 1.1 mycroft servlen = sizeof(serv_addr.sun_family) + strlen(serv_addr.sun_path);
100 1.3 mycroft #endif
101 1.1 mycroft
102 1.1 mycroft if (bind(rsrr_socket, (struct sockaddr *) &serv_addr, servlen) < 0)
103 1.1 mycroft log(LOG_ERR, errno, "Can't bind RSRR socket");
104 1.1 mycroft
105 1.1 mycroft if (register_input_handler(rsrr_socket,rsrr_read) < 0)
106 1.1 mycroft log(LOG_WARNING, 0, "Couldn't register RSRR as an input handler");
107 1.1 mycroft }
108 1.1 mycroft
109 1.1 mycroft /* Read a message from the RSRR socket */
110 1.1 mycroft void
111 1.3 mycroft rsrr_read(f, rfd)
112 1.3 mycroft int f;
113 1.3 mycroft fd_set *rfd;
114 1.1 mycroft {
115 1.5 wiz int rsrr_recvlen;
116 1.5 wiz int omask;
117 1.1 mycroft
118 1.1 mycroft bzero((char *) &client_addr, sizeof(client_addr));
119 1.1 mycroft rsrr_recvlen = recvfrom(rsrr_socket, rsrr_recv_buf, sizeof(rsrr_recv_buf),
120 1.3 mycroft 0, (struct sockaddr *)&client_addr, &client_length);
121 1.1 mycroft if (rsrr_recvlen < 0) {
122 1.1 mycroft if (errno != EINTR)
123 1.1 mycroft log(LOG_ERR, errno, "RSRR recvfrom");
124 1.1 mycroft return;
125 1.1 mycroft }
126 1.1 mycroft /* Use of omask taken from main() */
127 1.1 mycroft omask = sigblock(sigmask(SIGALRM));
128 1.3 mycroft rsrr_accept(rsrr_recvlen);
129 1.1 mycroft (void)sigsetmask(omask);
130 1.1 mycroft }
131 1.1 mycroft
132 1.1 mycroft /* Accept a message from the reservation protocol and take
133 1.1 mycroft * appropriate action.
134 1.1 mycroft */
135 1.3 mycroft static void
136 1.3 mycroft rsrr_accept(recvlen)
137 1.1 mycroft int recvlen;
138 1.1 mycroft {
139 1.1 mycroft struct rsrr_header *rsrr;
140 1.1 mycroft struct rsrr_rq *route_query;
141 1.1 mycroft
142 1.1 mycroft if (recvlen < RSRR_HEADER_LEN) {
143 1.1 mycroft log(LOG_WARNING, 0,
144 1.1 mycroft "Received RSRR packet of %d bytes, which is less than min size",
145 1.1 mycroft recvlen);
146 1.1 mycroft return;
147 1.1 mycroft }
148 1.1 mycroft
149 1.1 mycroft rsrr = (struct rsrr_header *) rsrr_recv_buf;
150 1.1 mycroft
151 1.1 mycroft if (rsrr->version > RSRR_MAX_VERSION) {
152 1.1 mycroft log(LOG_WARNING, 0,
153 1.1 mycroft "Received RSRR packet version %d, which I don't understand",
154 1.1 mycroft rsrr->version);
155 1.1 mycroft return;
156 1.1 mycroft }
157 1.1 mycroft
158 1.1 mycroft switch (rsrr->version) {
159 1.1 mycroft case 1:
160 1.1 mycroft switch (rsrr->type) {
161 1.1 mycroft case RSRR_INITIAL_QUERY:
162 1.1 mycroft /* Send Initial Reply to client */
163 1.1 mycroft log(LOG_INFO, 0, "Received Initial Query\n");
164 1.3 mycroft rsrr_accept_iq();
165 1.1 mycroft break;
166 1.1 mycroft case RSRR_ROUTE_QUERY:
167 1.1 mycroft /* Check size */
168 1.1 mycroft if (recvlen < RSRR_RQ_LEN) {
169 1.1 mycroft log(LOG_WARNING, 0,
170 1.1 mycroft "Received Route Query of %d bytes, which is too small",
171 1.1 mycroft recvlen);
172 1.1 mycroft break;
173 1.1 mycroft }
174 1.1 mycroft /* Get the query */
175 1.1 mycroft route_query = (struct rsrr_rq *) (rsrr_recv_buf + RSRR_HEADER_LEN);
176 1.1 mycroft log(LOG_INFO, 0,
177 1.1 mycroft "Received Route Query for src %s grp %s notification %d",
178 1.1 mycroft inet_fmt(route_query->source_addr.s_addr, s1),
179 1.1 mycroft inet_fmt(route_query->dest_addr.s_addr,s2),
180 1.1 mycroft BIT_TST(rsrr->flags,RSRR_NOTIFICATION_BIT));
181 1.1 mycroft /* Send Route Reply to client */
182 1.3 mycroft rsrr_accept_rq(route_query,rsrr->flags,NULL);
183 1.1 mycroft break;
184 1.1 mycroft default:
185 1.1 mycroft log(LOG_WARNING, 0,
186 1.1 mycroft "Received RSRR packet type %d, which I don't handle",
187 1.1 mycroft rsrr->type);
188 1.1 mycroft break;
189 1.1 mycroft }
190 1.1 mycroft break;
191 1.1 mycroft
192 1.1 mycroft default:
193 1.1 mycroft log(LOG_WARNING, 0,
194 1.1 mycroft "Received RSRR packet version %d, which I don't understand",
195 1.1 mycroft rsrr->version);
196 1.1 mycroft break;
197 1.1 mycroft }
198 1.1 mycroft }
199 1.1 mycroft
200 1.1 mycroft /* Send an Initial Reply to the reservation protocol. */
201 1.3 mycroft static void
202 1.3 mycroft rsrr_accept_iq()
203 1.1 mycroft {
204 1.1 mycroft struct rsrr_header *rsrr;
205 1.1 mycroft struct rsrr_vif *vif_list;
206 1.1 mycroft struct uvif *v;
207 1.1 mycroft int vifi, sendlen;
208 1.1 mycroft
209 1.1 mycroft /* Check for space. There should be room for plenty of vifs,
210 1.1 mycroft * but we should check anyway.
211 1.1 mycroft */
212 1.1 mycroft if (numvifs > RSRR_MAX_VIFS) {
213 1.1 mycroft log(LOG_WARNING, 0,
214 1.1 mycroft "Can't send RSRR Route Reply because %d is too many vifs %d",
215 1.1 mycroft numvifs);
216 1.1 mycroft return;
217 1.1 mycroft }
218 1.1 mycroft
219 1.1 mycroft /* Set up message */
220 1.1 mycroft rsrr = (struct rsrr_header *) rsrr_send_buf;
221 1.1 mycroft rsrr->version = 1;
222 1.1 mycroft rsrr->type = RSRR_INITIAL_REPLY;
223 1.1 mycroft rsrr->flags = 0;
224 1.1 mycroft rsrr->num = numvifs;
225 1.1 mycroft
226 1.1 mycroft vif_list = (struct rsrr_vif *) (rsrr_send_buf + RSRR_HEADER_LEN);
227 1.1 mycroft
228 1.1 mycroft /* Include the vif list. */
229 1.1 mycroft for (vifi=0, v = uvifs; vifi < numvifs; vifi++, v++) {
230 1.1 mycroft vif_list[vifi].id = vifi;
231 1.1 mycroft vif_list[vifi].status = 0;
232 1.1 mycroft if (v->uv_flags & VIFF_DISABLED)
233 1.1 mycroft BIT_SET(vif_list[vifi].status,RSRR_DISABLED_BIT);
234 1.1 mycroft vif_list[vifi].threshold = v->uv_threshold;
235 1.1 mycroft vif_list[vifi].local_addr.s_addr = v->uv_lcl_addr;
236 1.1 mycroft }
237 1.1 mycroft
238 1.1 mycroft /* Get the size. */
239 1.1 mycroft sendlen = RSRR_HEADER_LEN + numvifs*RSRR_VIF_LEN;
240 1.1 mycroft
241 1.1 mycroft /* Send it. */
242 1.1 mycroft log(LOG_INFO, 0, "Send RSRR Initial Reply");
243 1.3 mycroft rsrr_send(sendlen);
244 1.1 mycroft }
245 1.1 mycroft
246 1.3 mycroft /* Send a Route Reply to the reservation protocol. The Route Query
247 1.3 mycroft * contains the query to which we are responding. The flags contain
248 1.3 mycroft * the incoming flags from the query or, for route change
249 1.3 mycroft * notification, the flags that should be set for the reply. The
250 1.3 mycroft * kernel table entry contains the routing info to use for a route
251 1.3 mycroft * change notification.
252 1.3 mycroft */
253 1.3 mycroft static int
254 1.3 mycroft rsrr_accept_rq(route_query,flags,gt_notify)
255 1.3 mycroft struct rsrr_rq *route_query;
256 1.3 mycroft int flags;
257 1.3 mycroft struct gtable *gt_notify;
258 1.1 mycroft {
259 1.1 mycroft struct rsrr_header *rsrr;
260 1.1 mycroft struct rsrr_rr *route_reply;
261 1.1 mycroft struct gtable *gt,local_g;
262 1.1 mycroft struct rtentry *r;
263 1.1 mycroft int sendlen,i;
264 1.1 mycroft u_long mcastgrp;
265 1.1 mycroft
266 1.1 mycroft /* Set up message */
267 1.1 mycroft rsrr = (struct rsrr_header *) rsrr_send_buf;
268 1.1 mycroft rsrr->version = 1;
269 1.1 mycroft rsrr->type = RSRR_ROUTE_REPLY;
270 1.3 mycroft rsrr->flags = 0;
271 1.1 mycroft rsrr->num = 0;
272 1.1 mycroft
273 1.1 mycroft route_reply = (struct rsrr_rr *) (rsrr_send_buf + RSRR_HEADER_LEN);
274 1.1 mycroft route_reply->dest_addr.s_addr = route_query->dest_addr.s_addr;
275 1.1 mycroft route_reply->source_addr.s_addr = route_query->source_addr.s_addr;
276 1.1 mycroft route_reply->query_id = route_query->query_id;
277 1.1 mycroft
278 1.1 mycroft /* Blank routing entry for error. */
279 1.1 mycroft route_reply->in_vif = 0;
280 1.1 mycroft route_reply->reserved = 0;
281 1.1 mycroft route_reply->out_vif_bm = 0;
282 1.1 mycroft
283 1.3 mycroft /* Get the size. */
284 1.3 mycroft sendlen = RSRR_RR_LEN;
285 1.3 mycroft
286 1.3 mycroft /* If kernel table entry is defined, then we are sending a Route Reply
287 1.3 mycroft * due to a Route Change Notification event. Use the kernel table entry
288 1.3 mycroft * to supply the routing info.
289 1.3 mycroft */
290 1.3 mycroft if (gt_notify) {
291 1.3 mycroft /* Set flags */
292 1.3 mycroft rsrr->flags = flags;
293 1.3 mycroft /* Include the routing entry. */
294 1.3 mycroft route_reply->in_vif = gt_notify->gt_route->rt_parent;
295 1.3 mycroft route_reply->out_vif_bm = gt_notify->gt_grpmems;
296 1.3 mycroft
297 1.3 mycroft } else if (find_src_grp(route_query->source_addr.s_addr, 0,
298 1.3 mycroft route_query->dest_addr.s_addr)) {
299 1.3 mycroft
300 1.3 mycroft /* Found kernel entry. Code taken from add_table_entry() */
301 1.1 mycroft gt = gtp ? gtp->gt_gnext : kernel_table;
302 1.1 mycroft
303 1.1 mycroft /* Include the routing entry. */
304 1.1 mycroft route_reply->in_vif = gt->gt_route->rt_parent;
305 1.1 mycroft route_reply->out_vif_bm = gt->gt_grpmems;
306 1.3 mycroft
307 1.3 mycroft /* Cache reply if using route change notification. */
308 1.3 mycroft if BIT_TST(flags,RSRR_NOTIFICATION_BIT) {
309 1.3 mycroft rsrr_cache(gt,route_query);
310 1.3 mycroft BIT_SET(rsrr->flags,RSRR_NOTIFICATION_BIT);
311 1.3 mycroft }
312 1.1 mycroft
313 1.1 mycroft } else {
314 1.1 mycroft /* No kernel entry; use routing table. */
315 1.1 mycroft r = determine_route(route_query->source_addr.s_addr);
316 1.1 mycroft
317 1.1 mycroft if (r != NULL) {
318 1.1 mycroft /* We need to mimic what will happen if a data packet
319 1.1 mycroft * is forwarded by multicast routing -- the kernel will
320 1.1 mycroft * make an upcall and mrouted will install a route in the kernel.
321 1.1 mycroft * Our outgoing vif bitmap should reflect what that table
322 1.1 mycroft * will look like. Grab code from add_table_entry().
323 1.1 mycroft * This is gross, but it's probably better to be accurate.
324 1.1 mycroft */
325 1.1 mycroft
326 1.1 mycroft gt = &local_g;
327 1.1 mycroft mcastgrp = route_query->dest_addr.s_addr;
328 1.1 mycroft
329 1.1 mycroft gt->gt_mcastgrp = mcastgrp;
330 1.1 mycroft gt->gt_grpmems = 0;
331 1.1 mycroft gt->gt_scope = 0;
332 1.1 mycroft gt->gt_route = r;
333 1.1 mycroft
334 1.1 mycroft /* obtain the multicast group membership list */
335 1.1 mycroft for (i = 0; i < numvifs; i++) {
336 1.1 mycroft if (VIFM_ISSET(i, r->rt_children) &&
337 1.1 mycroft !(VIFM_ISSET(i, r->rt_leaves)))
338 1.1 mycroft VIFM_SET(i, gt->gt_grpmems);
339 1.1 mycroft
340 1.1 mycroft if (VIFM_ISSET(i, r->rt_leaves) && grplst_mem(i, mcastgrp))
341 1.1 mycroft VIFM_SET(i, gt->gt_grpmems);
342 1.1 mycroft }
343 1.1 mycroft
344 1.1 mycroft GET_SCOPE(gt);
345 1.1 mycroft gt->gt_grpmems &= ~gt->gt_scope;
346 1.1 mycroft
347 1.1 mycroft /* Include the routing entry. */
348 1.1 mycroft route_reply->in_vif = gt->gt_route->rt_parent;
349 1.1 mycroft route_reply->out_vif_bm = gt->gt_grpmems;
350 1.1 mycroft
351 1.1 mycroft } else {
352 1.1 mycroft /* Set error bit. */
353 1.1 mycroft BIT_SET(rsrr->flags,RSRR_ERROR_BIT);
354 1.1 mycroft }
355 1.1 mycroft }
356 1.1 mycroft
357 1.3 mycroft if (gt_notify)
358 1.3 mycroft log(LOG_INFO, 0, "Route Change: Send RSRR Route Reply");
359 1.3 mycroft
360 1.3 mycroft else
361 1.3 mycroft log(LOG_INFO, 0, "Send RSRR Route Reply");
362 1.3 mycroft
363 1.3 mycroft log(LOG_INFO, 0, "for src %s dst %s in vif %d out vif %d\n",
364 1.1 mycroft inet_fmt(route_reply->source_addr.s_addr,s1),
365 1.3 mycroft inet_fmt(route_reply->dest_addr.s_addr,s2),
366 1.1 mycroft route_reply->in_vif,route_reply->out_vif_bm);
367 1.1 mycroft
368 1.1 mycroft /* Send it. */
369 1.3 mycroft return rsrr_send(sendlen);
370 1.1 mycroft }
371 1.1 mycroft
372 1.1 mycroft /* Send an RSRR message. */
373 1.3 mycroft static int
374 1.3 mycroft rsrr_send(sendlen)
375 1.1 mycroft int sendlen;
376 1.1 mycroft {
377 1.1 mycroft int error;
378 1.1 mycroft
379 1.1 mycroft /* Send it. */
380 1.1 mycroft error = sendto(rsrr_socket, rsrr_send_buf, sendlen, 0,
381 1.3 mycroft (struct sockaddr *)&client_addr, client_length);
382 1.1 mycroft
383 1.1 mycroft /* Check for errors. */
384 1.1 mycroft if (error < 0) {
385 1.1 mycroft log(LOG_WARNING, errno, "Failed send on RSRR socket");
386 1.3 mycroft } else if (error != sendlen) {
387 1.1 mycroft log(LOG_WARNING, 0,
388 1.1 mycroft "Sent only %d out of %d bytes on RSRR socket\n", error, sendlen);
389 1.1 mycroft }
390 1.3 mycroft return error;
391 1.3 mycroft }
392 1.3 mycroft
393 1.3 mycroft /* Cache a message being sent to a client. Currently only used for
394 1.3 mycroft * caching Route Reply messages for route change notification.
395 1.3 mycroft */
396 1.3 mycroft static void
397 1.3 mycroft rsrr_cache(gt,route_query)
398 1.3 mycroft struct gtable *gt;
399 1.3 mycroft struct rsrr_rq *route_query;
400 1.3 mycroft {
401 1.3 mycroft struct rsrr_cache *rc, **rcnp;
402 1.3 mycroft struct rsrr_header *rsrr;
403 1.3 mycroft
404 1.3 mycroft rsrr = (struct rsrr_header *) rsrr_send_buf;
405 1.3 mycroft
406 1.3 mycroft rcnp = >->gt_rsrr_cache;
407 1.3 mycroft while ((rc = *rcnp) != NULL) {
408 1.3 mycroft if ((rc->route_query.source_addr.s_addr ==
409 1.3 mycroft route_query->source_addr.s_addr) &&
410 1.3 mycroft (rc->route_query.dest_addr.s_addr ==
411 1.3 mycroft route_query->dest_addr.s_addr) &&
412 1.3 mycroft (!strcmp(rc->client_addr.sun_path,client_addr.sun_path))) {
413 1.3 mycroft /* Cache entry already exists.
414 1.3 mycroft * Check if route notification bit has been cleared.
415 1.3 mycroft */
416 1.3 mycroft if (!BIT_TST(rsrr->flags,RSRR_NOTIFICATION_BIT)) {
417 1.3 mycroft /* Delete cache entry. */
418 1.3 mycroft *rcnp = rc->next;
419 1.3 mycroft free(rc);
420 1.3 mycroft } else {
421 1.3 mycroft /* Update */
422 1.3 mycroft rc->route_query.query_id = route_query->query_id;
423 1.3 mycroft log(LOG_DEBUG, 0,
424 1.3 mycroft "Update cached query id %ld from client %s\n",
425 1.3 mycroft rc->route_query.query_id, rc->client_addr.sun_path);
426 1.3 mycroft }
427 1.3 mycroft return;
428 1.3 mycroft }
429 1.3 mycroft rcnp = &rc->next;
430 1.3 mycroft }
431 1.3 mycroft
432 1.3 mycroft /* Cache entry doesn't already exist. Create one and insert at
433 1.3 mycroft * front of list.
434 1.3 mycroft */
435 1.3 mycroft rc = (struct rsrr_cache *) malloc(sizeof(struct rsrr_cache));
436 1.3 mycroft if (rc == NULL)
437 1.3 mycroft log(LOG_ERR, 0, "ran out of memory");
438 1.3 mycroft rc->route_query.source_addr.s_addr = route_query->source_addr.s_addr;
439 1.3 mycroft rc->route_query.dest_addr.s_addr = route_query->dest_addr.s_addr;
440 1.3 mycroft rc->route_query.query_id = route_query->query_id;
441 1.3 mycroft strcpy(rc->client_addr.sun_path, client_addr.sun_path);
442 1.3 mycroft rc->client_length = client_length;
443 1.3 mycroft rc->next = gt->gt_rsrr_cache;
444 1.3 mycroft gt->gt_rsrr_cache = rc;
445 1.3 mycroft log(LOG_DEBUG, 0, "Cached query id %ld from client %s\n",
446 1.3 mycroft rc->route_query.query_id,rc->client_addr.sun_path);
447 1.3 mycroft }
448 1.3 mycroft
449 1.3 mycroft /* Send all the messages in the cache. Currently this is used to send
450 1.3 mycroft * all the cached Route Reply messages for route change notification.
451 1.3 mycroft */
452 1.3 mycroft void
453 1.3 mycroft rsrr_cache_send(gt,notify)
454 1.3 mycroft struct gtable *gt;
455 1.3 mycroft int notify;
456 1.3 mycroft {
457 1.3 mycroft struct rsrr_cache *rc, **rcnp;
458 1.3 mycroft int flags = 0;
459 1.3 mycroft
460 1.3 mycroft if (notify)
461 1.3 mycroft BIT_SET(flags,RSRR_NOTIFICATION_BIT);
462 1.3 mycroft
463 1.3 mycroft rcnp = >->gt_rsrr_cache;
464 1.3 mycroft while ((rc = *rcnp) != NULL) {
465 1.3 mycroft if (rsrr_accept_rq(&rc->route_query,flags,gt) < 0) {
466 1.3 mycroft log(LOG_DEBUG, 0, "Deleting cached query id %ld from client %s\n",
467 1.3 mycroft rc->route_query.query_id,rc->client_addr.sun_path);
468 1.3 mycroft /* Delete cache entry. */
469 1.3 mycroft *rcnp = rc->next;
470 1.3 mycroft free(rc);
471 1.3 mycroft } else {
472 1.3 mycroft rcnp = &rc->next;
473 1.3 mycroft }
474 1.3 mycroft }
475 1.3 mycroft }
476 1.3 mycroft
477 1.3 mycroft /* Clean the cache by deleting all entries. */
478 1.3 mycroft void
479 1.3 mycroft rsrr_cache_clean(gt)
480 1.3 mycroft struct gtable *gt;
481 1.3 mycroft {
482 1.3 mycroft struct rsrr_cache *rc,*rc_next;
483 1.3 mycroft
484 1.3 mycroft printf("cleaning cache for group %s\n",inet_fmt(gt->gt_mcastgrp, s1));
485 1.3 mycroft rc = gt->gt_rsrr_cache;
486 1.3 mycroft while (rc) {
487 1.3 mycroft rc_next = rc->next;
488 1.3 mycroft free(rc);
489 1.3 mycroft rc = rc_next;
490 1.3 mycroft }
491 1.3 mycroft gt->gt_rsrr_cache = NULL;
492 1.1 mycroft }
493 1.1 mycroft
494 1.1 mycroft void
495 1.1 mycroft rsrr_clean()
496 1.1 mycroft {
497 1.1 mycroft unlink(RSRR_SERV_PATH);
498 1.1 mycroft }
499 1.1 mycroft
500 1.3 mycroft #endif /* RSRR */
501