vif.c revision 1.2 1 /*
2 * The mrouted program is covered by the license in the accompanying file
3 * named "LICENSE". Use of the mrouted program represents acceptance of
4 * the terms and conditions listed in that file.
5 *
6 * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
7 * Leland Stanford Junior University.
8 *
9 *
10 * from: Id: vif.c,v 1.5 1993/06/24 05:11:16 deering Exp
11 * $Id: vif.c,v 1.2 1994/05/16 15:17:39 brezak Exp $
12 */
13
14 #ifndef lint
15 static char rcsid[] = "$Id: vif.c,v 1.2 1994/05/16 15:17:39 brezak Exp $";
16 #endif
17
18 #include "defs.h"
19
20
21 /*
22 * Exported variables.
23 */
24 struct uvif uvifs[MAXVIFS]; /* array of virtual interfaces */
25 vifi_t numvifs; /* number of vifs in use */
26 int vifs_down; /* 1=>some interfaces are down */
27 int udp_socket; /* Since the honkin' kernel doesn't support */
28 /* ioctls on raw IP sockets, we need a UDP */
29 /* socket as well as our IGMP (raw) socket. */
30 /* How dumb. */
31
32 /*
33 * Forward declarations.
34 */
35 static void start_vif();
36 static void stop_vif();
37
38
39 /*
40 * Initialize the virtual interfaces.
41 */
42 void init_vifs()
43 {
44 vifi_t vifi;
45 struct uvif *v;
46 int enabled_vifs, enabled_phyints;
47
48 numvifs = 0;
49 vifs_down = FALSE;
50
51 /*
52 * Configure the vifs based on the interface configuration of the
53 * the kernel and the contents of the configuration file.
54 * (Open a UDP socket for ioctl use in the config procedures.)
55 */
56 if ((udp_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
57 log(LOG_ERR, errno, "UDP socket");
58 config_vifs_from_kernel();
59 config_vifs_from_file();
60
61 /*
62 * Quit if there are fewer than two enabled vifs.
63 */
64 enabled_vifs = 0;
65 enabled_phyints = 0;
66 for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
67 if (!(v->uv_flags & VIFF_DISABLED)) {
68 ++enabled_vifs;
69 if (!(v->uv_flags & VIFF_TUNNEL))
70 ++enabled_phyints;
71 }
72 }
73 if (enabled_vifs < 2)
74 log(LOG_ERR, 0, "can't forward: %s",
75 enabled_vifs == 0 ? "no enabled vifs" : "only one enabled vif");
76
77 if (enabled_phyints == 0)
78 log(LOG_WARNING, 0,
79 "no enabled interfaces, forwarding via tunnels only");
80
81 /*
82 * Start routing on all virtual interfaces that are not down or
83 * administratively disabled.
84 */
85 for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
86 if (!(v->uv_flags & VIFF_DISABLED)) {
87 if (!(v->uv_flags & VIFF_DOWN))
88 start_vif(vifi);
89 else log(LOG_INFO, 0,
90 "%s is not yet up; vif #%u not in service",
91 v->uv_name, vifi);
92 }
93 }
94 }
95
96
97 /*
98 * See if any interfaces have changed from up state to down, or vice versa,
99 * including any non-multicast-capable interfaces that are in use as local
100 * tunnel end-points. Ignore interfaces that have been administratively
101 * disabled.
102 */
103 void check_vif_state()
104 {
105 register vifi_t vifi;
106 register struct uvif *v;
107 struct ifreq ifr;
108
109 vifs_down = FALSE;
110 for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
111
112 if (v->uv_flags & VIFF_DISABLED) continue;
113
114 strncpy(ifr.ifr_name, v->uv_name, IFNAMSIZ);
115 if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ifr) < 0)
116 log(LOG_ERR, errno,
117 "ioctl SIOCGIFFLAGS for %s", ifr.ifr_name);
118
119 if (v->uv_flags & VIFF_DOWN) {
120 if (ifr.ifr_flags & IFF_UP) {
121 v->uv_flags &= ~VIFF_DOWN;
122 start_vif(vifi);
123 log(LOG_INFO, 0,
124 "%s has come up; vif #%u now in service",
125 v->uv_name, vifi);
126 }
127 else vifs_down = TRUE;
128 }
129 else {
130 if (!(ifr.ifr_flags & IFF_UP)) {
131 stop_vif(vifi);
132 v->uv_flags |= VIFF_DOWN;
133 log(LOG_INFO, 0,
134 "%s has gone down; vif #%u taken out of service",
135 v->uv_name, vifi);
136 vifs_down = TRUE;
137 }
138 }
139 }
140 }
141
142
143 /*
144 * Start routing on the specified virtual interface.
145 */
146 static void start_vif(vifi)
147 vifi_t vifi;
148 {
149 struct uvif *v;
150 u_long src, dst;
151
152 v = &uvifs[vifi];
153 src = v->uv_lcl_addr;
154 dst = (v->uv_flags & VIFF_TUNNEL) ? v->uv_rmt_addr : dvmrp_group;
155
156 /*
157 * Install the interface in the kernel's vif structure.
158 */
159 k_add_vif(vifi, &uvifs[vifi]);
160
161 /*
162 * Update the existing route entries to take into account the new vif.
163 */
164 add_vif_to_routes(vifi);
165
166 if (!(v->uv_flags & VIFF_TUNNEL)) {
167 /*
168 * Join the DVMRP multicast group on the interface.
169 * (This is not strictly necessary, since the kernel promiscuously
170 * receives IGMP packets addressed to ANY IP multicast group while
171 * multicast routing is enabled. However, joining the group allows
172 * this host to receive non-IGMP packets as well, such as 'pings'.)
173 */
174 k_join(dvmrp_group, src);
175
176 /*
177 * Install an entry in the routing table for the subnet to which
178 * the interface is connected.
179 */
180 start_route_updates();
181 update_route(v->uv_subnet, v->uv_subnetmask, 0, 0, vifi);
182
183 /*
184 * Until neighbors are discovered, assume responsibility for sending
185 * periodic group membership queries to the subnet. Send the first
186 * query.
187 */
188 v->uv_flags |= VIFF_QUERIER;
189 send_igmp(src, allhosts_group, IGMP_HOST_MEMBERSHIP_QUERY, 0, 0, 0);
190 }
191
192 /*
193 * Send a probe via the new vif to look for neighbors.
194 */
195 send_igmp(src, dst, IGMP_DVMRP, DVMRP_PROBE, htonl(MROUTED_LEVEL), 0);
196 }
197
198
199 /*
200 * Stop routing on the specified virtual interface.
201 */
202 static void stop_vif(vifi)
203 vifi_t vifi;
204 {
205 struct uvif *v;
206 struct listaddr *a;
207
208 v = &uvifs[vifi];
209
210 if (!(v->uv_flags & VIFF_TUNNEL)) {
211 /*
212 * Depart from the DVMRP multicast group on the interface.
213 */
214 k_leave(dvmrp_group, v->uv_lcl_addr);
215
216 /*
217 * Update the entry in the routing table for the subnet to which
218 * the interface is connected, to take into account the interface
219 * failure.
220 */
221 start_route_updates();
222 update_route(v->uv_subnet, v->uv_subnetmask, UNREACHABLE, 0, vifi);
223
224 /*
225 * Discard all group addresses. (No need to tell kernel;
226 * the k_del_vif() call, below, will clean up kernel state.)
227 */
228 while (v->uv_groups != NULL) {
229 a = v->uv_groups;
230 v->uv_groups = a->al_next;
231 free((char *)a);
232 }
233
234 v->uv_flags &= ~VIFF_QUERIER;
235 }
236
237 /*
238 * Update the existing route entries to take into account the vif failure.
239 */
240 delete_vif_from_routes(vifi);
241
242 /*
243 * Delete the interface from the kernel's vif structure.
244 */
245 k_del_vif(vifi);
246
247 /*
248 * Discard all neighbor addresses.
249 */
250 while (v->uv_neighbors != NULL) {
251 a = v->uv_neighbors;
252 v->uv_neighbors = a->al_next;
253 free((char *)a);
254 }
255 }
256
257
258 /*
259 * Find the virtual interface from which an incoming packet arrived,
260 * based on the packet's source and destination IP addresses.
261 */
262 vifi_t find_vif(src, dst)
263 register u_long src;
264 register u_long dst;
265 {
266 register vifi_t vifi;
267 register struct uvif *v;
268
269 for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
270 if (!(v->uv_flags & (VIFF_DOWN|VIFF_DISABLED))) {
271 if (v->uv_flags & VIFF_TUNNEL) {
272 if (src == v->uv_rmt_addr && dst == v->uv_lcl_addr)
273 return(vifi);
274 }
275 else {
276 if ((src & v->uv_subnetmask) == v->uv_subnet &&
277 src != v->uv_subnetbcast)
278 return(vifi);
279 }
280 }
281 }
282 return (NO_VIF);
283 }
284
285
286 /*
287 * Send group membership queries to all subnets for which I am querier.
288 */
289 void query_groups()
290 {
291 register vifi_t vifi;
292 register struct uvif *v;
293
294 for (vifi = 0, v = uvifs; vifi < numvifs; vifi++, v++) {
295 if (v->uv_flags & VIFF_QUERIER) {
296 send_igmp(v->uv_lcl_addr, allhosts_group,
297 IGMP_HOST_MEMBERSHIP_QUERY, 0, 0, 0);
298 }
299 }
300 }
301
302
303 /*
304 * Process an incoming group membership report.
305 */
306 void accept_group_report(src, dst, group)
307 u_long src, dst, group;
308 {
309 register vifi_t vifi;
310 register struct uvif *v;
311 register struct listaddr *g;
312
313 if ((vifi = find_vif(src, dst)) == NO_VIF ||
314 (uvifs[vifi].uv_flags & VIFF_TUNNEL)) {
315 log(LOG_INFO, 0,
316 "ignoring group membership report from non-adjacent host %s",
317 inet_fmt(src, s1));
318 return;
319 }
320
321 v = &uvifs[vifi];
322
323 /*
324 * Look for the group in our group list; if found, reset its timer.
325 */
326 for (g = v->uv_groups; g != NULL; g = g->al_next) {
327 if (group == g->al_addr) {
328 g->al_timer = 0;
329 break;
330 }
331 }
332
333 /*
334 * If not found, add it to the list and tell the kernel.
335 */
336 if (g == NULL) {
337 g = (struct listaddr *)malloc(sizeof(struct listaddr));
338 if (g == NULL)
339 log(LOG_ERR, 0, "ran out of memory"); /* fatal */
340
341 g->al_addr = group;
342 g->al_timer = 0;
343 g->al_next = v->uv_groups;
344 v->uv_groups = g;
345
346 k_add_group(vifi, group);
347 }
348 }
349
350
351 /*
352 * Send a probe on all vifs from which no neighbors have been heard recently.
353 */
354 void probe_for_neighbors()
355 {
356 register vifi_t vifi;
357 register struct uvif *v;
358
359 for (vifi = 0, v = uvifs; vifi < numvifs; vifi++, v++) {
360 if (!(v->uv_flags & (VIFF_DOWN|VIFF_DISABLED)) &&
361 v->uv_neighbors == NULL) {
362 send_igmp(v->uv_lcl_addr,
363 (v->uv_flags & VIFF_TUNNEL) ? v->uv_rmt_addr
364 : dvmrp_group,
365 IGMP_DVMRP, DVMRP_PROBE, htonl(MROUTED_LEVEL), 0);
366 }
367 }
368 }
369
370
371 /*
372 * Send a list of all of our neighbors to the requestor, `src'.
373 */
374 void accept_neighbor_request(src, dst)
375 u_long src, dst;
376 {
377 vifi_t vifi;
378 struct uvif *v;
379 u_char *p, *ncount;
380 struct listaddr *la;
381 int datalen;
382 u_long temp_addr, us, them = src;
383
384 /* Determine which of our addresses to use as the source of our response
385 * to this query.
386 */
387 if (IN_MULTICAST(ntohl(dst))) { /* query sent to a multicast group */
388 int udp; /* find best interface to reply on */
389 struct sockaddr_in addr;
390 int addrlen = sizeof(addr);
391
392 addr.sin_family = AF_INET;
393 addr.sin_addr.s_addr = dst;
394 addr.sin_port = htons(2000); /* any port over 1024 will do... */
395 if ((udp = socket(AF_INET, SOCK_DGRAM, 0)) < 0
396 || connect(udp, (struct sockaddr *) &addr, sizeof(addr)) < 0
397 || getsockname(udp, (struct sockaddr *) &addr, &addrlen) < 0) {
398 log(LOG_WARNING, errno, "Determining local address");
399 close(udp);
400 return;
401 }
402 close(udp);
403 us = addr.sin_addr.s_addr;
404 } else /* query sent to us alone */
405 us = dst;
406
407 #define PUT_ADDR(a) temp_addr = ntohl(a); \
408 *p++ = temp_addr >> 24; \
409 *p++ = (temp_addr >> 16) & 0xFF; \
410 *p++ = (temp_addr >> 8) & 0xFF; \
411 *p++ = temp_addr & 0xFF;
412
413 p = (u_char *) (send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN);
414 datalen = 0;
415
416 for (vifi = 0, v = uvifs; vifi < numvifs; vifi++, v++) {
417 if (v->uv_flags & VIFF_DISABLED)
418 continue;
419
420 ncount = 0;
421
422 for (la = v->uv_neighbors; la; la = la->al_next) {
423
424 /* Make sure that there's room for this neighbor... */
425 if (datalen + (ncount == 0 ? 4 + 3 + 4 : 4) > MAX_DVMRP_DATA_LEN) {
426 send_igmp(us, them, IGMP_DVMRP, DVMRP_NEIGHBORS,
427 htonl(MROUTED_LEVEL), datalen);
428 p = (u_char *) (send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN);
429 datalen = 0;
430 ncount = 0;
431 }
432
433 /* Put out the header for this neighbor list... */
434 if (ncount == 0) {
435 PUT_ADDR(v->uv_lcl_addr);
436 *p++ = v->uv_metric;
437 *p++ = v->uv_threshold;
438 ncount = p;
439 *p++ = 0;
440 datalen += 4 + 3;
441 }
442
443 PUT_ADDR(la->al_addr);
444 datalen += 4;
445 (*ncount)++;
446 }
447 }
448
449 if (datalen != 0)
450 send_igmp(us, them, IGMP_DVMRP, DVMRP_NEIGHBORS, htonl(MROUTED_LEVEL),
451 datalen);
452 }
453
454 /*
455 * Send a list of all of our neighbors to the requestor, `src'.
456 */
457 void accept_neighbor_request2(src, dst)
458 u_long src, dst;
459 {
460 vifi_t vifi;
461 struct uvif *v;
462 u_char *p, *ncount;
463 struct listaddr *la;
464 int datalen;
465 u_long temp_addr, us, them = src;
466
467 /* Determine which of our addresses to use as the source of our response
468 * to this query.
469 */
470 if (IN_MULTICAST(ntohl(dst))) { /* query sent to a multicast group */
471 int udp; /* find best interface to reply on */
472 struct sockaddr_in addr;
473 int addrlen = sizeof(addr);
474
475 addr.sin_family = AF_INET;
476 addr.sin_addr.s_addr = dst;
477 addr.sin_port = htons(2000); /* any port over 1024 will do... */
478 if ((udp = socket(AF_INET, SOCK_DGRAM, 0)) < 0
479 || connect(udp, (struct sockaddr *) &addr, sizeof(addr)) < 0
480 || getsockname(udp, (struct sockaddr *) &addr, &addrlen) < 0) {
481 log(LOG_WARNING, errno, "Determining local address");
482 close(udp);
483 return;
484 }
485 close(udp);
486 us = addr.sin_addr.s_addr;
487 } else /* query sent to us alone */
488 us = dst;
489
490 p = (u_char *) (send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN);
491 datalen = 0;
492
493 for (vifi = 0, v = uvifs; vifi < numvifs; vifi++, v++) {
494 register u_short vflags = v->uv_flags;
495 register u_char rflags = 0;
496 if (vflags & VIFF_TUNNEL)
497 rflags |= DVMRP_NF_TUNNEL;
498 if (vflags & VIFF_DOWN)
499 rflags |= DVMRP_NF_DOWN;
500 if (vflags & VIFF_DISABLED)
501 rflags |= DVMRP_NF_DISABLED;
502 if (vflags & VIFF_QUERIER)
503 rflags |= DVMRP_NF_QUERIER;
504 ncount = 0;
505 la = v->uv_neighbors;
506 if (la == NULL) {
507 /*
508 * include down & disabled interfaces and interfaces on
509 * leaf nets.
510 */
511 if (rflags & DVMRP_NF_TUNNEL)
512 rflags |= DVMRP_NF_DOWN;
513 if (datalen > MAX_DVMRP_DATA_LEN - 12) {
514 send_igmp(us, them, IGMP_DVMRP, DVMRP_NEIGHBORS2,
515 htonl(MROUTED_LEVEL), datalen);
516 p = (u_char *) (send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN);
517 datalen = 0;
518 }
519 *(u_int*)p = v->uv_lcl_addr;
520 p += 4;
521 *p++ = v->uv_metric;
522 *p++ = v->uv_threshold;
523 *p++ = rflags;
524 *p++ = 1;
525 *(u_int*)p = v->uv_rmt_addr;
526 p += 4;
527 datalen += 12;
528 } else {
529 for ( ; la; la = la->al_next) {
530 /* Make sure that there's room for this neighbor... */
531 if (datalen + (ncount == 0 ? 4+4+4 : 4) > MAX_DVMRP_DATA_LEN) {
532 send_igmp(us, them, IGMP_DVMRP, DVMRP_NEIGHBORS2,
533 htonl(MROUTED_LEVEL), datalen);
534 p = (u_char *) (send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN);
535 datalen = 0;
536 ncount = 0;
537 }
538 /* Put out the header for this neighbor list... */
539 if (ncount == 0) {
540 *(u_int*)p = v->uv_lcl_addr;
541 p += 4;
542 *p++ = v->uv_metric;
543 *p++ = v->uv_threshold;
544 *p++ = rflags;
545 ncount = p;
546 *p++ = 0;
547 datalen += 4 + 4;
548 }
549 *(u_int*)p = la->al_addr;
550 p += 4;
551 datalen += 4;
552 (*ncount)++;
553 }
554 }
555 }
556 if (datalen != 0)
557 send_igmp(us, them, IGMP_DVMRP, DVMRP_NEIGHBORS2, htonl(MROUTED_LEVEL),
558 datalen);
559 }
560
561
562 /*
563 * Process an incoming neighbor-list message.
564 */
565 void accept_neighbors(src, dst, p, datalen, level)
566 u_long src, dst, level;
567 char *p;
568 int datalen;
569 {
570 log(LOG_INFO, 0, "ignoring spurious DVMRP neighbor list from %s to %s",
571 inet_fmt(src, s1), inet_fmt(dst, s2));
572 }
573
574 /*
575 * Process an incoming neighbor-list message.
576 */
577 void accept_neighbors2(src, dst, p, datalen, level)
578 u_long src, dst, level;
579 char *p;
580 int datalen;
581 {
582 log(LOG_INFO, 0, "ignoring spurious DVMRP neighbor list2 from %s to %s",
583 inet_fmt(src, s1), inet_fmt(dst, s2));
584 }
585
586
587 /*
588 * Update the neighbor entry for neighbor 'addr' on vif 'vifi'.
589 * 'msgtype' is the type of DVMRP message received from the neighbor.
590 * Return TRUE if 'addr' is a valid neighbor, FALSE otherwise.
591 */
592 int update_neighbor(vifi, addr, msgtype)
593 vifi_t vifi;
594 u_long addr;
595 int msgtype;
596 {
597 register struct uvif *v;
598 register struct listaddr *n;
599
600 v = &uvifs[vifi];
601
602 /*
603 * Confirm that 'addr' is a valid neighbor address on vif 'vifi'.
604 * IT IS ASSUMED that this was preceded by a call to find_vif(), which
605 * checks that 'addr' is either a valid remote tunnel endpoint or a
606 * non-broadcast address belonging to a directly-connected subnet.
607 * Therefore, here we check only that 'addr' is not our own address
608 * (due to an impostor or erroneous loopback) or an address of the form
609 * {subnet,0} ("the unknown host"). These checks are not performed in
610 * find_vif() because those types of address are acceptable for some
611 * types of IGMP message (such as group membership reports).
612 */
613 if (!(v->uv_flags & VIFF_TUNNEL) &&
614 (addr == v->uv_lcl_addr ||
615 addr == v->uv_subnet )) {
616 log(LOG_WARNING, 0,
617 "received DVMRP message from 'the unknown host' or self: %s",
618 inet_fmt(addr, s1));
619 return (FALSE);
620 }
621
622 /*
623 * If we have received a route report from a neighbor, and we believed
624 * that we had no neighbors on this vif, send a full route report to
625 * all neighbors on the vif.
626 */
627
628 if (msgtype == DVMRP_REPORT && v->uv_neighbors == NULL)
629 report(ALL_ROUTES, vifi,
630 (v->uv_flags & VIFF_TUNNEL) ? addr : dvmrp_group);
631
632 /*
633 * Look for addr in list of neighbors; if found, reset its timer.
634 */
635 for (n = v->uv_neighbors; n != NULL; n = n->al_next) {
636 if (addr == n->al_addr) {
637 n->al_timer = 0;
638 break;
639 }
640 }
641
642 /*
643 * If not found, add it to the list. If the neighbor has a lower
644 * IP address than me, yield querier duties to it.
645 */
646 if (n == NULL) {
647 n = (struct listaddr *)malloc(sizeof(struct listaddr));
648 if (n == NULL)
649 log(LOG_ERR, 0, "ran out of memory"); /* fatal */
650
651 n->al_addr = addr;
652 n->al_timer = 0;
653 n->al_next = v->uv_neighbors;
654 v->uv_neighbors = n;
655
656 if (!(v->uv_flags & VIFF_TUNNEL) &&
657 ntohl(addr) < ntohl(v->uv_lcl_addr))
658 v->uv_flags &= ~VIFF_QUERIER;
659 }
660
661 return (TRUE);
662 }
663
664
665 /*
666 * On every timer interrupt, advance the timer in each neighbor and
667 * group entry on every vif.
668 */
669 void age_vifs()
670 {
671 register vifi_t vifi;
672 register struct uvif *v;
673 register struct listaddr *a, *prev_a, *n;
674 register u_long addr;
675
676 for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v ) {
677
678 for (prev_a = (struct listaddr *)&(v->uv_neighbors),
679 a = v->uv_neighbors;
680 a != NULL;
681 prev_a = a, a = a->al_next) {
682
683 if ((a->al_timer += TIMER_INTERVAL) < NEIGHBOR_EXPIRE_TIME)
684 continue;
685
686 /*
687 * Neighbor has expired; delete it from the neighbor list,
688 * delete it from the 'dominants' and 'subordinates arrays of
689 * any route entries and assume querier duties unless there is
690 * another neighbor with a lower IP address than mine.
691 */
692 addr = a->al_addr;
693 prev_a->al_next = a->al_next;
694 free((char *)a);
695 a = prev_a;
696
697 delete_neighbor_from_routes(addr, vifi);
698
699 if (!(v->uv_flags & VIFF_TUNNEL)) {
700 v->uv_flags |= VIFF_QUERIER;
701 for (n = v->uv_neighbors; n != NULL; n = n->al_next) {
702 if (ntohl(n->al_addr) < ntohl(v->uv_lcl_addr)) {
703 v->uv_flags &= ~VIFF_QUERIER;
704 break;
705 }
706 }
707 }
708 }
709
710 for (prev_a = (struct listaddr *)&(v->uv_groups),
711 a = v->uv_groups;
712 a != NULL;
713 prev_a = a, a = a->al_next) {
714
715 if ((a->al_timer += TIMER_INTERVAL) < GROUP_EXPIRE_TIME)
716 continue;
717
718 /*
719 * Group has expired; tell kernel and delete from group list.
720 */
721 k_del_group(vifi, a->al_addr);
722
723 prev_a->al_next = a->al_next;
724 free((char *)a);
725 a = prev_a;
726 }
727 }
728 }
729
730
731 /*
732 * Print the contents of the uvifs array on file 'fp'.
733 */
734 void dump_vifs(fp)
735 FILE *fp;
736 {
737 register vifi_t vifi;
738 register struct uvif *v;
739 register struct listaddr *a;
740
741 fprintf(fp,
742 "\nVirtual Interface Table\n%s",
743 " Vif Local-Address Metric Thresh Flags\n");
744
745 for (vifi = 0, v = uvifs; vifi < numvifs; vifi++, v++) {
746
747 fprintf(fp, " %2u %-15s %6s: %-15s %4u %7u ",
748 vifi,
749 inet_fmt(v->uv_lcl_addr, s1),
750 (v->uv_flags & VIFF_TUNNEL) ?
751 "tunnel":
752 "subnet",
753 (v->uv_flags & VIFF_TUNNEL) ?
754 inet_fmt(v->uv_rmt_addr, s2) :
755 inet_fmts(v->uv_subnet, v->uv_subnetmask, s3),
756 v->uv_metric,
757 v->uv_threshold);
758
759 if (v->uv_flags & VIFF_DOWN) fprintf(fp, " down");
760 if (v->uv_flags & VIFF_DISABLED) fprintf(fp, " disabled");
761 if (v->uv_flags & VIFF_QUERIER) fprintf(fp, " querier");
762 fprintf(fp, "\n");
763
764 if (v->uv_neighbors != NULL) {
765 fprintf(fp, " peers : %-15s\n",
766 inet_fmt(v->uv_neighbors->al_addr, s1));
767 for (a = v->uv_neighbors->al_next; a != NULL; a = a->al_next) {
768 fprintf(fp, " %-15s\n",
769 inet_fmt(a->al_addr, s1));
770 }
771 }
772
773 if (v->uv_groups != NULL) {
774 fprintf(fp, " groups: %-15s\n",
775 inet_fmt(v->uv_groups->al_addr, s1));
776 for (a = v->uv_groups->al_next; a != NULL; a = a->al_next) {
777 fprintf(fp, " %-15s\n",
778 inet_fmt(a->al_addr, s1));
779 }
780 }
781 }
782 fprintf(fp, "\n");
783 }
784