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.3 1994/06/09 16:04:03 brezak Exp $ 12 */ 13 14 #ifndef lint 15 static char rcsid[] = "$Id: vif.c,v 1.3 1994/06/09 16:04:03 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_SRCRT) 499 rflags |= DVMRP_NF_SRCRT; 500 if (vflags & VIFF_DOWN) 501 rflags |= DVMRP_NF_DOWN; 502 if (vflags & VIFF_DISABLED) 503 rflags |= DVMRP_NF_DISABLED; 504 if (vflags & VIFF_QUERIER) 505 rflags |= DVMRP_NF_QUERIER; 506 ncount = 0; 507 la = v->uv_neighbors; 508 if (la == NULL) { 509 /* 510 * include down & disabled interfaces and interfaces on 511 * leaf nets. 512 */ 513 if (rflags & DVMRP_NF_TUNNEL) 514 rflags |= DVMRP_NF_DOWN; 515 if (datalen > MAX_DVMRP_DATA_LEN - 12) { 516 send_igmp(us, them, IGMP_DVMRP, DVMRP_NEIGHBORS2, 517 htonl(MROUTED_LEVEL), datalen); 518 p = (u_char *) (send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN); 519 datalen = 0; 520 } 521 *(u_int*)p = v->uv_lcl_addr; 522 p += 4; 523 *p++ = v->uv_metric; 524 *p++ = v->uv_threshold; 525 *p++ = rflags; 526 *p++ = 1; 527 *(u_int*)p = v->uv_rmt_addr; 528 p += 4; 529 datalen += 12; 530 } else { 531 for ( ; la; la = la->al_next) { 532 /* Make sure that there's room for this neighbor... */ 533 if (datalen + (ncount == 0 ? 4+4+4 : 4) > MAX_DVMRP_DATA_LEN) { 534 send_igmp(us, them, IGMP_DVMRP, DVMRP_NEIGHBORS2, 535 htonl(MROUTED_LEVEL), datalen); 536 p = (u_char *) (send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN); 537 datalen = 0; 538 ncount = 0; 539 } 540 /* Put out the header for this neighbor list... */ 541 if (ncount == 0) { 542 *(u_int*)p = v->uv_lcl_addr; 543 p += 4; 544 *p++ = v->uv_metric; 545 *p++ = v->uv_threshold; 546 *p++ = rflags; 547 ncount = p; 548 *p++ = 0; 549 datalen += 4 + 4; 550 } 551 *(u_int*)p = la->al_addr; 552 p += 4; 553 datalen += 4; 554 (*ncount)++; 555 } 556 } 557 } 558 if (datalen != 0) 559 send_igmp(us, them, IGMP_DVMRP, DVMRP_NEIGHBORS2, htonl(MROUTED_LEVEL), 560 datalen); 561 } 562 563 564 /* 565 * Process an incoming neighbor-list message. 566 */ 567 void accept_neighbors(src, dst, p, datalen, level) 568 u_long src, dst, level; 569 char *p; 570 int datalen; 571 { 572 log(LOG_INFO, 0, "ignoring spurious DVMRP neighbor list from %s to %s", 573 inet_fmt(src, s1), inet_fmt(dst, s2)); 574 } 575 576 /* 577 * Process an incoming neighbor-list message. 578 */ 579 void accept_neighbors2(src, dst, p, datalen, level) 580 u_long src, dst, level; 581 char *p; 582 int datalen; 583 { 584 log(LOG_INFO, 0, "ignoring spurious DVMRP neighbor list2 from %s to %s", 585 inet_fmt(src, s1), inet_fmt(dst, s2)); 586 } 587 588 589 /* 590 * Update the neighbor entry for neighbor 'addr' on vif 'vifi'. 591 * 'msgtype' is the type of DVMRP message received from the neighbor. 592 * Return TRUE if 'addr' is a valid neighbor, FALSE otherwise. 593 */ 594 int update_neighbor(vifi, addr, msgtype) 595 vifi_t vifi; 596 u_long addr; 597 int msgtype; 598 { 599 register struct uvif *v; 600 register struct listaddr *n; 601 602 v = &uvifs[vifi]; 603 604 /* 605 * Confirm that 'addr' is a valid neighbor address on vif 'vifi'. 606 * IT IS ASSUMED that this was preceded by a call to find_vif(), which 607 * checks that 'addr' is either a valid remote tunnel endpoint or a 608 * non-broadcast address belonging to a directly-connected subnet. 609 * Therefore, here we check only that 'addr' is not our own address 610 * (due to an impostor or erroneous loopback) or an address of the form 611 * {subnet,0} ("the unknown host"). These checks are not performed in 612 * find_vif() because those types of address are acceptable for some 613 * types of IGMP message (such as group membership reports). 614 */ 615 if (!(v->uv_flags & VIFF_TUNNEL) && 616 (addr == v->uv_lcl_addr || 617 addr == v->uv_subnet )) { 618 log(LOG_WARNING, 0, 619 "received DVMRP message from 'the unknown host' or self: %s", 620 inet_fmt(addr, s1)); 621 return (FALSE); 622 } 623 624 /* 625 * If we have received a route report from a neighbor, and we believed 626 * that we had no neighbors on this vif, send a full route report to 627 * all neighbors on the vif. 628 */ 629 630 if (msgtype == DVMRP_REPORT && v->uv_neighbors == NULL) 631 report(ALL_ROUTES, vifi, 632 (v->uv_flags & VIFF_TUNNEL) ? addr : dvmrp_group); 633 634 /* 635 * Look for addr in list of neighbors; if found, reset its timer. 636 */ 637 for (n = v->uv_neighbors; n != NULL; n = n->al_next) { 638 if (addr == n->al_addr) { 639 n->al_timer = 0; 640 break; 641 } 642 } 643 644 /* 645 * If not found, add it to the list. If the neighbor has a lower 646 * IP address than me, yield querier duties to it. 647 */ 648 if (n == NULL) { 649 n = (struct listaddr *)malloc(sizeof(struct listaddr)); 650 if (n == NULL) 651 log(LOG_ERR, 0, "ran out of memory"); /* fatal */ 652 653 n->al_addr = addr; 654 n->al_timer = 0; 655 n->al_next = v->uv_neighbors; 656 v->uv_neighbors = n; 657 658 if (!(v->uv_flags & VIFF_TUNNEL) && 659 ntohl(addr) < ntohl(v->uv_lcl_addr)) 660 v->uv_flags &= ~VIFF_QUERIER; 661 } 662 663 return (TRUE); 664 } 665 666 667 /* 668 * On every timer interrupt, advance the timer in each neighbor and 669 * group entry on every vif. 670 */ 671 void age_vifs() 672 { 673 register vifi_t vifi; 674 register struct uvif *v; 675 register struct listaddr *a, *prev_a, *n; 676 register u_long addr; 677 678 for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v ) { 679 680 for (prev_a = (struct listaddr *)&(v->uv_neighbors), 681 a = v->uv_neighbors; 682 a != NULL; 683 prev_a = a, a = a->al_next) { 684 685 if ((a->al_timer += TIMER_INTERVAL) < NEIGHBOR_EXPIRE_TIME) 686 continue; 687 688 /* 689 * Neighbor has expired; delete it from the neighbor list, 690 * delete it from the 'dominants' and 'subordinates arrays of 691 * any route entries and assume querier duties unless there is 692 * another neighbor with a lower IP address than mine. 693 */ 694 addr = a->al_addr; 695 prev_a->al_next = a->al_next; 696 free((char *)a); 697 a = prev_a; 698 699 delete_neighbor_from_routes(addr, vifi); 700 701 if (!(v->uv_flags & VIFF_TUNNEL)) { 702 v->uv_flags |= VIFF_QUERIER; 703 for (n = v->uv_neighbors; n != NULL; n = n->al_next) { 704 if (ntohl(n->al_addr) < ntohl(v->uv_lcl_addr)) { 705 v->uv_flags &= ~VIFF_QUERIER; 706 break; 707 } 708 } 709 } 710 } 711 712 for (prev_a = (struct listaddr *)&(v->uv_groups), 713 a = v->uv_groups; 714 a != NULL; 715 prev_a = a, a = a->al_next) { 716 717 if ((a->al_timer += TIMER_INTERVAL) < GROUP_EXPIRE_TIME) 718 continue; 719 720 /* 721 * Group has expired; tell kernel and delete from group list. 722 */ 723 k_del_group(vifi, a->al_addr); 724 725 prev_a->al_next = a->al_next; 726 free((char *)a); 727 a = prev_a; 728 } 729 } 730 } 731 732 733 /* 734 * Print the contents of the uvifs array on file 'fp'. 735 */ 736 void dump_vifs(fp) 737 FILE *fp; 738 { 739 register vifi_t vifi; 740 register struct uvif *v; 741 register struct listaddr *a; 742 743 fprintf(fp, 744 "\nVirtual Interface Table\n%s", 745 " Vif Local-Address Metric Thresh Flags\n"); 746 747 for (vifi = 0, v = uvifs; vifi < numvifs; vifi++, v++) { 748 749 fprintf(fp, " %2u %-15s %6s: %-15s %4u %7u ", 750 vifi, 751 inet_fmt(v->uv_lcl_addr, s1), 752 (v->uv_flags & VIFF_TUNNEL) ? 753 "tunnel": 754 "subnet", 755 (v->uv_flags & VIFF_TUNNEL) ? 756 inet_fmt(v->uv_rmt_addr, s2) : 757 inet_fmts(v->uv_subnet, v->uv_subnetmask, s3), 758 v->uv_metric, 759 v->uv_threshold); 760 761 if (v->uv_flags & VIFF_DOWN) fprintf(fp, " down"); 762 if (v->uv_flags & VIFF_DISABLED) fprintf(fp, " disabled"); 763 if (v->uv_flags & VIFF_QUERIER) fprintf(fp, " querier"); 764 if (v->uv_flags & VIFF_SRCRT) fprintf(fp, " src-rt"); 765 fprintf(fp, "\n"); 766 767 if (v->uv_neighbors != NULL) { 768 fprintf(fp, " peers : %-15s\n", 769 inet_fmt(v->uv_neighbors->al_addr, s1)); 770 for (a = v->uv_neighbors->al_next; a != NULL; a = a->al_next) { 771 fprintf(fp, " %-15s\n", 772 inet_fmt(a->al_addr, s1)); 773 } 774 } 775 776 if (v->uv_groups != NULL) { 777 fprintf(fp, " groups: %-15s\n", 778 inet_fmt(v->uv_groups->al_addr, s1)); 779 for (a = v->uv_groups->al_next; a != NULL; a = a->al_next) { 780 fprintf(fp, " %-15s\n", 781 inet_fmt(a->al_addr, s1)); 782 } 783 } 784 } 785 fprintf(fp, "\n"); 786 } 787