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.
6 * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
7 * Leland Stanford Junior University.
10 * prune.c,v 3.8.4.59 1998/03/01 02:06:32 fenner Exp
14 static const char rcsid[] =
20 extern int cache_lifetime;
21 extern int prune_lifetime;
22 extern struct rtentry *routing_table;
26 extern int allow_black_holes;
29 * randomize value to obtain a value between .5x and 1.5x
30 * in order to prevent synchronization
33 #define JITTERED_VALUE(x) ((x)/2 + (lrand48() % (x)))
35 #define JITTERED_VALUE(x) ((x)/2 + (arc4random() % (x)))
37 #define CACHE_LIFETIME(x) JITTERED_VALUE(x) /* XXX */
39 struct gtable *kernel_table; /* ptr to list of kernel grp entries*/
40 static struct gtable *kernel_no_route; /* list of grp entries w/o routes */
41 struct gtable *gtp; /* pointer for kernel rt entries */
42 unsigned int kroutes; /* current number of cache entries */
44 /****************************************************************************
45 Functions that are local to prune.c
46 ****************************************************************************/
47 static int scoped_addr __P((vifi_t vifi, u_int32 addr));
48 static void prun_add_ttls __P((struct gtable *gt));
49 static int pruning_neighbor __P((vifi_t vifi, u_int32 addr));
50 static int can_mtrace __P((vifi_t vifi, u_int32 addr));
51 static struct ptable * find_prune_entry __P((u_int32 vr, struct ptable *pt));
52 static void remove_sources __P((struct gtable *gt));
53 static void rexmit_prune __P((void *arg));
54 static void expire_prune __P((vifi_t vifi, struct gtable *gt));
55 static void send_prune __P((struct gtable *gt));
56 static void send_graft __P((struct gtable *gt));
57 static void send_graft_ack __P((u_int32 src, u_int32 dst,
58 u_int32 origin, u_int32 grp,
60 static void update_kernel __P((struct gtable *g));
63 * Updates the ttl values for each vif.
72 for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
73 if (VIFM_ISSET(vifi, gt->gt_grpmems))
74 gt->gt_ttls[vifi] = v->uv_threshold;
76 gt->gt_ttls[vifi] = 0;
81 * checks for scoped multicast addresses
82 * XXX I want to make the check of allow_black_holes based on ALLOW_BLACK_HOLES
83 * but macros are not functions.
85 #define GET_SCOPE(gt) { \
87 VIFM_CLRALL((gt)->gt_scope); \
88 if (allow_black_holes || \
89 (ntohl((gt)->gt_mcastgrp) & 0xff000000) == 0xef000000) \
90 for (_i = 0; _i < numvifs; _i++) \
91 if (scoped_addr(_i, (gt)->gt_mcastgrp)) \
92 VIFM_SET(_i, (gt)->gt_scope); \
94 if ((gt)->gt_route == NULL || ((gt)->gt_route->rt_parent != NO_VIF && \
95 VIFM_ISSET((gt)->gt_route->rt_parent, (gt)->gt_scope))) \
96 VIFM_SETALL((gt)->gt_scope);
98 #define APPLY_SCOPE(gt) VIFM_CLR_MASK((gt)->gt_grpmems, (gt)->gt_scope)
100 #define GET_MEMBERSHIP(gt, vifi) { \
101 if ((gt)->gt_route && \
102 VIFM_ISSET((vifi), (gt)->gt_route->rt_children) && \
103 (!SUBS_ARE_PRUNED((gt)->gt_route->rt_subordinates, \
104 uvifs[vifi].uv_nbrmap, (gt)->gt_prunes) || \
105 grplst_mem((vifi), (gt)->gt_mcastgrp))) \
106 VIFM_SET((vifi), (gt)->gt_grpmems); \
110 scoped_addr(vifi, addr)
116 for (acl = uvifs[vifi].uv_acl; acl; acl = acl->acl_next)
117 if ((addr & acl->acl_mask) == acl->acl_addr)
124 * Determine the list of outgoing vifs, based upon
125 * route subordinates, prunes received, and group
129 determine_forwvifs(gt)
134 VIFM_CLRALL(gt->gt_grpmems);
135 for (i = 0; i < numvifs; i++) {
136 GET_MEMBERSHIP(gt, i);
143 * Send a prune or a graft if necessary.
146 send_prune_or_graft(gt)
149 if (VIFM_ISEMPTY(gt->gt_grpmems))
151 else if (gt->gt_prsent_timer)
156 * Determine if mcastgrp has a listener on vifi
159 grplst_mem(vifi, mcastgrp)
163 register struct listaddr *g;
164 register struct uvif *v;
168 for (g = v->uv_groups; g != NULL; g = g->al_next)
169 if (mcastgrp == g->al_addr)
176 * Finds the group entry with the specified source and netmask.
177 * If netmask is 0, it uses the route's netmask.
179 * Returns TRUE if found a match, and the global variable gtp is left
180 * pointing to entry before the found entry.
181 * Returns FALSE if no exact match found, gtp is left pointing to before
182 * the entry in question belongs, or is NULL if the it belongs at the
186 find_src_grp(src, mask, grp)
196 if (grp == gt->gt_mcastgrp &&
197 (mask ? (gt->gt_route->rt_origin == src &&
198 gt->gt_route->rt_originmask == mask) :
199 ((src & gt->gt_route->rt_originmask) ==
200 gt->gt_route->rt_origin)))
202 if (ntohl(grp) > ntohl(gt->gt_mcastgrp) ||
203 (grp == gt->gt_mcastgrp &&
204 (ntohl(mask) < ntohl(gt->gt_route->rt_originmask) ||
205 (mask == gt->gt_route->rt_originmask &&
206 (ntohl(src) > ntohl(gt->gt_route->rt_origin)))))) {
216 * Check if the neighbor supports pruning
219 pruning_neighbor(vifi, addr)
223 struct listaddr *n = neighbor_info(vifi, addr);
230 return (vers >= 0x0300 && ((vers & 0xff00) != 0x0a00));
234 * Can the neighbor in question handle multicast traceroute?
237 can_mtrace(vifi, addr)
241 struct listaddr *n = neighbor_info(vifi, addr);
245 return 1; /* fail "safe" */
248 return (vers >= 0x0303 && ((vers & 0xff00) != 0x0a00));
252 * Returns the prune entry of the router, or NULL if none exists
254 static struct ptable *
255 find_prune_entry(vr, pt)
260 if (pt->pt_router == vr)
269 * Remove all the sources hanging off the group table entry from the kernel
270 * cache. Remember the packet counts wherever possible, to keep the mtrace
271 * counters consistent. This prepares for possible prune retransmission,
272 * either on a multi-access network or when a prune that we sent upstream
280 struct sioc_sg_req sg_req;
282 sg_req.grp.s_addr = gt->gt_mcastgrp;
285 * call k_del_rg() on every one of the gt->gt_srctbl entries
286 * but first save the packet count so that the mtrace packet
287 * counters can remain approximately correct. There's a race
288 * here but it's minor.
290 for (st = gt->gt_srctbl; st; st = st->st_next) {
291 if (st->st_ctime == 0)
293 IF_DEBUG(DEBUG_PRUNE)
294 log(LOG_DEBUG, 0, "rexmit_prune deleting (%s %s) (next is %d sec)",
295 inet_fmt(st->st_origin, s1),
296 inet_fmt(gt->gt_mcastgrp, s2),
297 gt->gt_prune_rexmit);
298 sg_req.src.s_addr = st->st_origin;
299 if (ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) < 0) {
302 k_del_rg(st->st_origin, gt);
303 st->st_ctime = 0; /* flag that it's not in the kernel any more */
304 st->st_savpkt += sg_req.pktcnt;
309 * Now, add_table_entry will prune when asked to add a cache entry.
314 * Prepare for possible prune retransmission
320 struct gtable *gt = *(struct gtable **)arg;
324 gt->gt_rexmit_timer = 0;
326 /* Make sure we're still not forwarding traffic */
327 if (!VIFM_ISEMPTY(gt->gt_grpmems)) {
328 IF_DEBUG(DEBUG_PRUNE)
329 log(LOG_DEBUG, 0, "rexmit_prune (%s %s): gm:%x",
330 RT_FMT(gt->gt_route, s1), inet_fmt(gt->gt_mcastgrp, s2),
339 * Send a prune message to the dominant router for
342 * Record an entry that a prune was sent for this group
358 * Can't process a prune if we don't have an associated route
359 * or if the route points to a local interface.
361 if (gt->gt_route == NULL || gt->gt_route->rt_parent == NO_VIF ||
362 gt->gt_route->rt_gateway == 0)
365 /* Don't send a prune to a non-pruning router */
366 if (!pruning_neighbor(gt->gt_route->rt_parent, gt->gt_route->rt_gateway))
369 v = &uvifs[gt->gt_route->rt_parent];
371 * sends a prune message to the router upstream.
374 dst = v->uv_flags & VIFF_TUNNEL ? dvmrp_group : gt->gt_route->rt_gateway; /*XXX*/
376 dst = gt->gt_route->rt_gateway;
379 p = send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN;
383 * determine prune lifetime, if this isn't a retransmission.
385 * Use interface-specified lifetime if there is one.
387 if (gt->gt_prsent_timer == 0) {
388 int l = prune_lifetime;
390 if (v->uv_prune_lifetime != 0)
391 l = v->uv_prune_lifetime;
393 gt->gt_prsent_timer = JITTERED_VALUE(l);
394 for (pt = gt->gt_pruntbl; pt; pt = pt->pt_next)
395 if (pt->pt_timer < gt->gt_prsent_timer)
396 gt->gt_prsent_timer = pt->pt_timer;
397 } else if (gt->gt_prsent_timer < 0) {
398 IF_DEBUG(DEBUG_PRUNE)
399 log(LOG_DEBUG, 0, "asked to rexmit? (%s,%s)/%d on vif %d to %s with negative time",
400 RT_FMT(gt->gt_route, s1), inet_fmt(gt->gt_mcastgrp, s2),
401 gt->gt_prsent_timer, gt->gt_route->rt_parent,
402 inet_fmt(gt->gt_route->rt_gateway, s3));
407 if (rexmitting && !(v->uv_flags & VIFF_REXMIT_PRUNES)) {
408 IF_DEBUG(DEBUG_PRUNE)
409 log(LOG_DEBUG, 0, "not rexmitting prune for (%s %s)/%d on vif %d to %s",
410 RT_FMT(gt->gt_route, s1), inet_fmt(gt->gt_mcastgrp, s2),
411 gt->gt_prsent_timer, gt->gt_route->rt_parent,
412 inet_fmt(gt->gt_route->rt_gateway, s3));
415 if (gt->gt_prsent_timer <= MIN_PRUNE_LIFE) {
416 IF_DEBUG(DEBUG_PRUNE)
417 log(LOG_DEBUG, 0, "not bothering to send prune for (%s,%s)/%d on vif %d to %s because it's too short",
418 RT_FMT(gt->gt_route, s1), inet_fmt(gt->gt_mcastgrp, s2),
419 gt->gt_prsent_timer, gt->gt_route->rt_parent,
420 inet_fmt(gt->gt_route->rt_gateway, s3));
425 * If we have a graft pending, cancel graft retransmission
429 for (i = 0; i < 4; i++)
430 *p++ = ((char *)&(gt->gt_route->rt_origin))[i];
431 for (i = 0; i < 4; i++)
432 *p++ = ((char *)&(gt->gt_mcastgrp))[i];
433 tmp = htonl(gt->gt_prsent_timer);
434 for (i = 0; i < 4; i++)
435 *p++ = ((char *)&(tmp))[i];
438 send_on_vif(v, dst, DVMRP_PRUNE, datalen);
440 IF_DEBUG(DEBUG_PRUNE)
441 log(LOG_DEBUG, 0, "%s prune for (%s %s)/%d on vif %d to %s",
442 rexmitting ? "rexmitted" : "sent",
443 RT_FMT(gt->gt_route, s1), inet_fmt(gt->gt_mcastgrp, s2),
444 gt->gt_prsent_timer, gt->gt_route->rt_parent,
445 inet_fmt(gt->gt_route->rt_gateway, s3));
447 if ((v->uv_flags & VIFF_REXMIT_PRUNES) &&
448 gt->gt_rexmit_timer == 0 &&
449 gt->gt_prsent_timer > gt->gt_prune_rexmit) {
450 struct gtable **arg =
451 (struct gtable **)malloc(sizeof (struct gtable **));
454 gt->gt_rexmit_timer = timer_setTimer(
455 JITTERED_VALUE(gt->gt_prune_rexmit),
457 gt->gt_prune_rexmit *= 2;
462 * a prune was sent upstream
463 * so, a graft has to be sent to annul the prune
464 * set up a graft timer so that if an ack is not
465 * heard within that time, another graft request
477 /* Can't send a graft without an associated route */
478 if (gt->gt_route == NULL || gt->gt_route->rt_parent == NO_VIF) {
483 gt->gt_prsent_timer = 0;
484 gt->gt_prune_rexmit = PRUNE_REXMIT_VAL;
485 if (gt->gt_rexmit_timer)
486 timer_clearTimer(gt->gt_rexmit_timer);
488 if (gt->gt_grftsnt == 0)
492 dst = uvifs[gt->gt_route->rt_parent].uv_flags & VIFF_TUNNEL ? dvmrp_group : gt->gt_route->rt_gateway; /*XXX*/
494 dst = gt->gt_route->rt_gateway;
497 p = send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN;
500 for (i = 0; i < 4; i++)
501 *p++ = ((char *)&(gt->gt_route->rt_origin))[i];
502 for (i = 0; i < 4; i++)
503 *p++ = ((char *)&(gt->gt_mcastgrp))[i];
506 send_on_vif(&uvifs[gt->gt_route->rt_parent], dst, DVMRP_GRAFT, datalen);
507 IF_DEBUG(DEBUG_PRUNE)
508 log(LOG_DEBUG, 0, "sent graft for (%s %s) to %s on vif %d",
509 RT_FMT(gt->gt_route, s1), inet_fmt(gt->gt_mcastgrp, s2),
510 inet_fmt(gt->gt_route->rt_gateway, s3), gt->gt_route->rt_parent);
514 * Send an ack that a graft was received
517 send_graft_ack(src, dst, origin, grp, vifi)
528 p = send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN;
531 for (i = 0; i < 4; i++)
532 *p++ = ((char *)&(origin))[i];
533 for (i = 0; i < 4; i++)
534 *p++ = ((char *)&(grp))[i];
538 send_igmp(src, dst, IGMP_DVMRP, DVMRP_GRAFT_ACK,
539 htonl(MROUTED_LEVEL), datalen);
542 if (uvifs[vifi].uv_flags & VIFF_TUNNEL)
543 dst = dvmrp_group; /* XXX */
545 send_on_vif(&uvifs[vifi], dst, DVMRP_GRAFT_ACK, datalen);
548 IF_DEBUG(DEBUG_PRUNE)
550 log(LOG_DEBUG, 0, "sent graft ack for (%s, %s) to %s",
551 inet_fmt(origin, s1), inet_fmt(grp, s2), inet_fmt(dst, s3));
553 log(LOG_DEBUG, 0, "sent graft ack for (%s, %s) to %s on vif %d",
554 inet_fmt(origin, s1), inet_fmt(grp, s2), inet_fmt(dst, s3), vifi);
558 * Update the kernel cache with all the routes hanging off the group entry
566 for (st = g->gt_srctbl; st; st = st->st_next)
567 if (st->st_ctime != 0)
568 k_add_rg(st->st_origin, g);
571 /****************************************************************************
572 Functions that are used externally
573 ****************************************************************************/
576 #include <sys/types.h>
580 * Find a specific group entry in the group table
588 for (gt = kernel_table; gt; gt = gt->gt_gnext) {
589 if (ntohl(grp) < ntohl(gt->gt_mcastgrp))
591 if (gt->gt_mcastgrp == grp)
598 * Given a group entry and source, find the corresponding source table
602 find_grp_src(gt, src)
607 u_long grp = gt->gt_mcastgrp;
608 struct gtable *gtcurr;
610 for (gtcurr = gt; gtcurr->gt_mcastgrp == grp; gtcurr = gtcurr->gt_gnext) {
611 for (st = gtcurr->gt_srctbl; st; st = st->st_next)
612 if (st->st_origin == src)
619 * Find next entry > specification
622 next_grp_src_mask(gtpp, stpp, grp, src, mask)
623 struct gtable **gtpp; /* ordered by group */
624 struct stable **stpp; /* ordered by source */
629 struct gtable *gt, *gbest = NULL;
630 struct stable *st, *sbest = NULL;
632 /* Find first group entry >= grp spec */
633 (*gtpp) = kernel_table;
634 while ((*gtpp) && ntohl((*gtpp)->gt_mcastgrp) < ntohl(grp))
635 (*gtpp)=(*gtpp)->gt_gnext;
637 return 0; /* no more groups */
639 for (gt = kernel_table; gt; gt=gt->gt_gnext) {
640 /* Since grps are ordered, we can stop when group changes from gbest */
641 if (gbest && gbest->gt_mcastgrp != gt->gt_mcastgrp)
643 for (st = gt->gt_srctbl; st; st=st->st_next) {
645 /* Among those entries > spec, find "lowest" one */
646 if (((ntohl(gt->gt_mcastgrp)> ntohl(grp))
647 || (ntohl(gt->gt_mcastgrp)==ntohl(grp)
648 && ntohl(st->st_origin)> ntohl(src))
649 || (ntohl(gt->gt_mcastgrp)==ntohl(grp)
650 && ntohl(st->st_origin)==src && 0xFFFFFFFF>ntohl(mask)))
652 || (ntohl(gt->gt_mcastgrp)< ntohl(gbest->gt_mcastgrp))
653 || (ntohl(gt->gt_mcastgrp)==ntohl(gbest->gt_mcastgrp)
654 && ntohl(st->st_origin)< ntohl(sbest->st_origin)))) {
666 * Ensure that sg contains current information for the given group,source.
667 * This is fetched from the kernel as a unit so that counts for the entry
668 * are consistent, i.e. packet and byte counts for the same entry are
669 * read at the same time.
672 refresh_sg(sg, gt, st)
673 struct sioc_sg_req *sg;
677 static int lastq = -1;
679 if (quantum != lastq || sg->src.s_addr!=st->st_origin
680 || sg->grp.s_addr!=gt->gt_mcastgrp) {
682 sg->src.s_addr = st->st_origin;
683 sg->grp.s_addr = gt->gt_mcastgrp;
684 ioctl(udp_socket, SIOCGETSGCNT, (char *)sg);
689 * Given a routing table entry, and a vifi, find the next entry
690 * equal to or greater than those
693 next_child(gtpp, stpp, grp, src, mask, vifi)
694 struct gtable **gtpp;
695 struct stable **stpp;
699 vifi_t *vifi; /* vif at which to start looking */
701 /* Get (G,S,M) entry */
703 || !((*gtpp) = find_grp(grp))
704 || !((*stpp) = find_grp_src((*gtpp),src)))
705 if (!next_grp_src_mask(gtpp, stpp, grp, src, mask))
708 /* Continue until we get one with a valid next vif */
710 for (; (*gtpp)->gt_route->rt_children && *vifi<numvifs; (*vifi)++)
711 if (VIFM_ISSET(*vifi, (*gtpp)->gt_route->rt_children))
714 } while (next_grp_src_mask(gtpp, stpp, (*gtpp)->gt_mcastgrp,
715 (*stpp)->st_origin, 0xFFFFFFFF) );
722 * Initialize the kernel table structure
728 kernel_no_route = NULL;
733 * Add a new table entry for (origin, mcastgrp)
736 add_table_entry(origin, mcastgrp)
741 struct gtable *gt,**gtnp,*prev_gt;
742 struct stable *st,**stnp;
745 * Since we have to enable mrouting to get the version number,
746 * some cache creation requests can sneak through. Ignore them
747 * since we're not going to do useful stuff until we've performed
748 * final initialization.
754 md_log(MD_MISS, origin, mcastgrp);
757 r = determine_route(origin);
761 * Look for it on the no_route table; if it is found then
762 * it will be detected as a duplicate below.
764 for (gt = kernel_no_route; gt; gt = gt->gt_next)
765 if (mcastgrp == gt->gt_mcastgrp &&
766 gt->gt_srctbl && gt->gt_srctbl->st_origin == origin)
768 gtnp = &kernel_no_route;
770 gtnp = &r->rt_groups;
771 while ((gt = *gtnp) != NULL) {
772 if (gt->gt_mcastgrp >= mcastgrp)
779 if (gt == NULL || gt->gt_mcastgrp != mcastgrp) {
780 gt = (struct gtable *)malloc(sizeof(struct gtable));
782 log(LOG_ERR, 0, "ran out of memory");
784 gt->gt_mcastgrp = mcastgrp;
785 gt->gt_timer = CACHE_LIFETIME(cache_lifetime);
787 gt->gt_prsent_timer = 0;
789 gt->gt_srctbl = NULL;
790 gt->gt_pruntbl = NULL;
792 gt->gt_rexmit_timer = 0;
793 NBRM_CLRALL(gt->gt_prunes);
794 gt->gt_prune_rexmit = PRUNE_REXMIT_VAL;
796 gt->gt_rsrr_cache = NULL;
799 /* Calculate forwarding vifs */
800 determine_forwvifs(gt);
808 gt->gt_next->gt_prev = gt;
809 gt->gt_prev = prev_gt;
812 if (find_src_grp(r->rt_origin, r->rt_originmask, gt->gt_mcastgrp)) {
815 g = gtp ? gtp->gt_gnext : kernel_table;
816 log(LOG_WARNING, 0, "Entry for (%s %s) (rt:%x) exists (rt:%x)",
817 RT_FMT(r, s1), inet_fmt(g->gt_mcastgrp, s2),
821 gt->gt_gnext = gtp->gt_gnext;
825 gt->gt_gnext = kernel_table;
830 gt->gt_gnext->gt_gprev = gt;
833 gt->gt_gnext = gt->gt_gprev = NULL;
837 stnp = >->gt_srctbl;
838 while ((st = *stnp) != NULL) {
839 if (ntohl(st->st_origin) >= ntohl(origin))
844 if (st == NULL || st->st_origin != origin) {
845 st = (struct stable *)malloc(sizeof(struct stable));
847 log(LOG_ERR, 0, "ran out of memory");
849 st->st_origin = origin;
856 if (st->st_ctime == 0) {
857 /* An old source which we're keeping around for statistics */
861 md_log(MD_DUPE, origin, mcastgrp);
863 /* Ignore kernel->mrouted retransmissions */
864 if (time(0) - st->st_ctime > 5)
865 log(LOG_WARNING, 0, "kernel entry already exists for (%s %s)",
866 inet_fmt(origin, s1), inet_fmt(mcastgrp, s2));
867 k_add_rg(origin, gt);
873 k_add_rg(origin, gt);
875 IF_DEBUG(DEBUG_CACHE)
876 log(LOG_DEBUG, 0, "add cache entry (%s %s) gm:%x, parent-vif:%d",
877 inet_fmt(origin, s1),
878 inet_fmt(mcastgrp, s2),
879 gt->gt_grpmems, r ? r->rt_parent : -1);
882 * If there are no downstream routers that want traffic for
883 * this group, send (or retransmit) a prune upstream.
885 if (VIFM_ISEMPTY(gt->gt_grpmems))
890 * A router has gone down. Remove prune state pertinent to that router.
893 reset_neighbor_state(vifi, addr)
899 struct ptable *pt, **ptnp;
902 for (g = kernel_table; g; g = g->gt_gnext) {
906 * If neighbor was the parent, remove the prune sent state
907 * and all of the source cache info so that prunes get
910 if (vifi == r->rt_parent) {
911 if (addr == r->rt_gateway) {
913 log(LOG_DEBUG, 0, "reset_neighbor_state parent reset (%s %s)",
914 RT_FMT(r, s1), inet_fmt(g->gt_mcastgrp, s2));
916 g->gt_prsent_timer = 0;
918 while ((st = g->gt_srctbl) != NULL) {
919 g->gt_srctbl = st->st_next;
920 if (st->st_ctime != 0) {
921 k_del_rg(st->st_origin, g);
929 * Remove any prunes that this router has sent us.
931 ptnp = &g->gt_pruntbl;
932 while ((pt = *ptnp) != NULL) {
933 if (pt->pt_vifi == vifi && pt->pt_router == addr) {
934 NBRM_CLR(pt->pt_index, g->gt_prunes);
942 * And see if we want to forward again.
944 if (!VIFM_ISSET(vifi, g->gt_grpmems)) {
945 GET_MEMBERSHIP(g, vifi);
949 /* Update kernel state */
952 /* Send route change notification to reservation protocol. */
953 rsrr_cache_send(g,1);
957 * If removing this prune causes us to start forwarding
958 * (e.g. the neighbor rebooted), and we sent a prune upstream,
959 * send a graft to cancel the prune.
961 if (!VIFM_ISEMPTY(g->gt_grpmems) && g->gt_prsent_timer)
965 log(LOG_DEBUG, 0, "reset neighbor state (%s %s) gm:%x",
967 inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
974 * Delete table entry from the kernel
975 * del_flag determines how many entries to delete
978 del_table_entry(r, mcastgrp, del_flag)
983 struct gtable *g, *prev_g;
984 struct stable *st, *prev_st;
985 struct ptable *pt, *prev_pt;
987 if (del_flag == DEL_ALL_ROUTES) {
990 IF_DEBUG(DEBUG_CACHE)
991 log(LOG_DEBUG, 0, "del_table_entry deleting (%s %s)",
992 RT_FMT(r, s1), inet_fmt(g->gt_mcastgrp, s2));
995 if (st->st_ctime != 0) {
996 if (k_del_rg(st->st_origin, g) < 0) {
997 log(LOG_WARNING, errno,
998 "del_table_entry trying to delete (%s, %s)",
999 inet_fmt(st->st_origin, s1),
1000 inet_fmt(g->gt_mcastgrp, s2));
1008 g->gt_srctbl = NULL;
1016 g->gt_pruntbl = NULL;
1019 g->gt_gnext->gt_gprev = g->gt_gprev;
1021 g->gt_gprev->gt_gnext = g->gt_gnext;
1023 kernel_table = g->gt_gnext;
1026 /* Send route change notification to reservation protocol. */
1027 rsrr_cache_send(g,0);
1028 rsrr_cache_clean(g);
1030 if (g->gt_rexmit_timer)
1031 timer_clearTimer(g->gt_rexmit_timer);
1037 r->rt_groups = NULL;
1041 * Dummy routine - someday this may be needed, so it is just there
1043 if (del_flag == DEL_RTE_GROUP) {
1044 prev_g = (struct gtable *)&r->rt_groups;
1045 for (g = r->rt_groups; g; g = g->gt_next) {
1046 if (g->gt_mcastgrp == mcastgrp) {
1047 IF_DEBUG(DEBUG_CACHE)
1048 log(LOG_DEBUG, 0, "del_table_entry deleting (%s %s)",
1049 RT_FMT(r, s1), inet_fmt(g->gt_mcastgrp, s2));
1052 if (st->st_ctime != 0) {
1053 if (k_del_rg(st->st_origin, g) < 0) {
1054 log(LOG_WARNING, errno,
1055 "del_table_entry trying to delete (%s, %s)",
1056 inet_fmt(st->st_origin, s1),
1057 inet_fmt(g->gt_mcastgrp, s2));
1065 g->gt_srctbl = NULL;
1073 g->gt_pruntbl = NULL;
1076 g->gt_gnext->gt_gprev = g->gt_gprev;
1078 g->gt_gprev->gt_gnext = g->gt_gnext;
1080 kernel_table = g->gt_gnext;
1082 if (prev_g != (struct gtable *)&r->rt_groups)
1083 g->gt_next->gt_prev = prev_g;
1085 g->gt_next->gt_prev = NULL;
1086 prev_g->gt_next = g->gt_next;
1088 if (g->gt_rexmit_timer)
1089 timer_clearTimer(g->gt_rexmit_timer);
1091 /* Send route change notification to reservation protocol. */
1092 rsrr_cache_send(g,0);
1093 rsrr_cache_clean(g);
1105 * update kernel table entry when a route entry changes
1108 update_table_entry(r, old_parent_gw)
1110 u_int32 old_parent_gw;
1113 struct ptable *pt, **ptnp;
1115 for (g = r->rt_groups; g; g = g->gt_next) {
1116 ptnp = &g->gt_pruntbl;
1118 * Delete prune entries from non-children, or non-subordinates.
1120 while ((pt = *ptnp)) {
1121 if (!VIFM_ISSET(pt->pt_vifi, r->rt_children) ||
1122 !NBRM_ISSET(pt->pt_index, r->rt_subordinates)) {
1124 IF_DEBUG(DEBUG_PRUNE)
1125 log(LOG_DEBUG, 0, "update_table_entry deleting prune for (%s %s) from %s on vif %d -%s%s",
1126 RT_FMT(r, s1), inet_fmt(g->gt_mcastgrp, s2),
1127 inet_fmt(pt->pt_router, s3), pt->pt_vifi,
1128 VIFM_ISSET(pt->pt_vifi, r->rt_children) ? "" : " not a child",
1129 NBRM_ISSET(pt->pt_index, r->rt_subordinates) ? "" : " not a subordinate");
1131 if (!NBRM_ISSET(pt->pt_index, g->gt_prunes)) {
1133 "gt_prunes lost track of (%s %s) from %s on vif %d",
1134 RT_FMT(r, s1), inet_fmt(g->gt_mcastgrp, s2),
1135 inet_fmt(pt->pt_router, s3), pt->pt_vifi);
1138 NBRM_CLR(pt->pt_index, g->gt_prunes);
1139 *ptnp = pt->pt_next;
1143 ptnp = &((*ptnp)->pt_next);
1146 IF_DEBUG(DEBUG_CACHE)
1147 log(LOG_DEBUG, 0, "updating cache entries (%s %s) old gm:%x",
1148 RT_FMT(r, s1), inet_fmt(g->gt_mcastgrp, s2),
1152 * Forget about a prune or graft that we sent previously if we
1153 * have a new parent router (since the new parent router will
1154 * know nothing about what I sent to the previous parent). The
1155 * old parent will forget any prune state it is keeping for us.
1157 if (old_parent_gw != r->rt_gateway) {
1158 g->gt_prsent_timer = 0;
1162 /* Recalculate membership */
1163 determine_forwvifs(g);
1164 /* send a prune or graft if needed. */
1165 send_prune_or_graft(g);
1167 IF_DEBUG(DEBUG_CACHE)
1168 log(LOG_DEBUG, 0, "updating cache entries (%s %s) new gm:%x",
1169 RT_FMT(r, s1), inet_fmt(g->gt_mcastgrp, s2),
1172 /* update ttls and add entry into kernel */
1176 /* Send route change notification to reservation protocol. */
1177 rsrr_cache_send(g,1);
1183 * set the forwarding flag for all mcastgrps on this vifi
1186 update_lclgrp(vifi, mcastgrp)
1193 IF_DEBUG(DEBUG_MEMBER)
1194 log(LOG_DEBUG, 0, "group %s joined on vif %d",
1195 inet_fmt(mcastgrp, s1), vifi);
1197 for (g = kernel_table; g; g = g->gt_gnext) {
1198 if (ntohl(mcastgrp) < ntohl(g->gt_mcastgrp))
1202 if (g->gt_mcastgrp == mcastgrp &&
1203 VIFM_ISSET(vifi, r->rt_children)) {
1205 VIFM_SET(vifi, g->gt_grpmems);
1207 if (VIFM_ISEMPTY(g->gt_grpmems))
1211 IF_DEBUG(DEBUG_CACHE)
1212 log(LOG_DEBUG, 0, "update lclgrp (%s %s) gm:%x",
1214 inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
1218 /* Send route change notification to reservation protocol. */
1219 rsrr_cache_send(g,1);
1226 * reset forwarding flag for all mcastgrps on this vifi
1229 delete_lclgrp(vifi, mcastgrp)
1235 IF_DEBUG(DEBUG_MEMBER)
1236 log(LOG_DEBUG, 0, "group %s left on vif %d",
1237 inet_fmt(mcastgrp, s1), vifi);
1239 for (g = kernel_table; g; g = g->gt_gnext) {
1240 if (ntohl(mcastgrp) < ntohl(g->gt_mcastgrp))
1243 if (g->gt_mcastgrp == mcastgrp && VIFM_ISSET(vifi, g->gt_grpmems)) {
1244 if (g->gt_route == NULL ||
1245 SUBS_ARE_PRUNED(g->gt_route->rt_subordinates,
1246 uvifs[vifi].uv_nbrmap, g->gt_prunes)) {
1247 VIFM_CLR(vifi, g->gt_grpmems);
1248 IF_DEBUG(DEBUG_CACHE)
1249 log(LOG_DEBUG, 0, "delete lclgrp (%s %s) gm:%x",
1250 RT_FMT(g->gt_route, s1),
1251 inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
1256 /* Send route change notification to reservation protocol. */
1257 rsrr_cache_send(g,1);
1261 * If there are no more members of this particular group,
1262 * send prune upstream
1264 if (VIFM_ISEMPTY(g->gt_grpmems) && g->gt_route->rt_gateway)
1272 * Takes the prune message received and then strips it to
1273 * determine the (src, grp) pair to be pruned.
1275 * Adds the router to the (src, grp) entry then.
1277 * Determines if further packets have to be sent down that vif
1279 * Determines if a corresponding prune message has to be generated
1282 accept_prune(src, dst, p, datalen)
1297 if ((vifi = find_vif(src, dst)) == NO_VIF) {
1299 "ignoring prune report from non-neighbor %s",
1304 /* Check if enough data is present */
1308 "non-decipherable prune from %s",
1313 for (i = 0; i< 4; i++)
1314 ((char *)&prun_src)[i] = *p++;
1315 for (i = 0; i< 4; i++)
1316 ((char *)&prun_grp)[i] = *p++;
1317 for (i = 0; i< 4; i++)
1318 ((char *)&prun_tmr)[i] = *p++;
1319 prun_tmr = ntohl(prun_tmr);
1321 if (prun_tmr <= MIN_PRUNE_LIFE) {
1322 IF_DEBUG(DEBUG_PRUNE)
1323 log(LOG_DEBUG, 0, "ignoring prune from %s on vif %d for (%s %s)/%d because its lifetime is too short",
1324 inet_fmt(src, s1), vifi,
1325 inet_fmt(prun_src, s2), inet_fmt(prun_grp, s3), prun_tmr);
1329 IF_DEBUG(DEBUG_PRUNE)
1330 log(LOG_DEBUG, 0, "%s on vif %d prunes (%s %s)/%d",
1331 inet_fmt(src, s1), vifi,
1332 inet_fmt(prun_src, s2), inet_fmt(prun_grp, s3), prun_tmr);
1335 * Find the subnet for the prune
1337 if (find_src_grp(prun_src, 0, prun_grp)) {
1338 g = gtp ? gtp->gt_gnext : kernel_table;
1341 IF_DEBUG(DEBUG_PRUNE)
1342 log(LOG_DEBUG, 0, "found grp state, (%s %s), metric is %d, children are %x, subords are %08x%08x",
1343 RT_FMT(r, s1), inet_fmt(g->gt_mcastgrp, s2), r->rt_metric,
1344 r->rt_children, r->rt_subordinates.hi, r->rt_subordinates.lo);
1345 if (!VIFM_ISSET(vifi, r->rt_children)) {
1346 IF_DEBUG(DEBUG_PRUNE)
1347 log(LOG_WARNING, 0, "prune received from non-child %s for (%s %s) (dominant on vif %d is %s)",
1348 inet_fmt(src, s1), inet_fmt(prun_src, s2),
1349 inet_fmt(prun_grp, s3), vifi,
1350 inet_fmt(r->rt_dominants[vifi], s4));
1356 if (VIFM_ISSET(vifi, g->gt_scope)) {
1357 log(LOG_WARNING, 0, "prune received from %s on scoped grp (%s %s)",
1358 inet_fmt(src, s1), inet_fmt(prun_src, s2),
1359 inet_fmt(prun_grp, s3));
1362 if ((pt = find_prune_entry(src, g->gt_pruntbl)) != NULL) {
1363 IF_DEBUG(DEBUG_PRUNE)
1364 log(LOG_DEBUG, 0, "%s %d from %s for (%s %s)/%d %s %d %s %x",
1365 "duplicate prune received on vif",
1366 vifi, inet_fmt(src, s1), inet_fmt(prun_src, s2),
1367 inet_fmt(prun_grp, s3), prun_tmr,
1368 "old timer:", pt->pt_timer, "cur gm:", g->gt_grpmems);
1369 pt->pt_timer = prun_tmr;
1371 struct listaddr *n = neighbor_info(vifi, src);
1374 log(LOG_WARNING, 0, "Prune from non-neighbor %s on vif %d!?",
1375 inet_fmt(src, s1), vifi);
1379 /* allocate space for the prune structure */
1380 pt = (struct ptable *)(malloc(sizeof(struct ptable)));
1382 log(LOG_ERR, 0, "pt: ran out of memory");
1385 pt->pt_router = src;
1386 pt->pt_timer = prun_tmr;
1388 pt->pt_next = g->gt_pruntbl;
1392 pt->pt_index = n->al_index;
1393 NBRM_SET(n->al_index, g->gt_prunes);
1398 * check if any more packets need to be sent on the
1399 * vif which sent this message
1401 if (SUBS_ARE_PRUNED(r->rt_subordinates,
1402 uvifs[vifi].uv_nbrmap, g->gt_prunes) &&
1403 !grplst_mem(vifi, prun_grp)) {
1406 VIFM_CLR(vifi, g->gt_grpmems);
1407 IF_DEBUG(DEBUG_PRUNE)
1408 log(LOG_DEBUG, 0, "vifnbrs=0x%08x%08x, subord=0x%08x%08x prunes=0x%08x%08x",
1409 uvifs[vifi].uv_nbrmap.hi,uvifs[vifi].uv_nbrmap.lo,
1410 r->rt_subordinates.hi, r->rt_subordinates.lo,
1411 g->gt_prunes.hi, g->gt_prunes.lo);
1413 NBRM_COPY(r->rt_subordinates, tmp);
1414 NBRM_MASK(tmp, uvifs[vifi].uv_nbrmap);
1415 if (!NBRM_ISSETALLMASK(g->gt_prunes, tmp))
1416 log(LOG_WARNING, 0, "subordinate error");
1417 /* XXX end debugging */
1418 IF_DEBUG(DEBUG_PRUNE|DEBUG_CACHE)
1419 log(LOG_DEBUG, 0, "prune (%s %s), stop sending on vif %d, gm:%x",
1421 inet_fmt(g->gt_mcastgrp, s2), vifi, g->gt_grpmems);
1426 /* Send route change notification to reservation protocol. */
1427 rsrr_cache_send(g,1);
1432 * check if all the child routers have expressed no interest
1433 * in this group and if this group does not exist in the
1435 * Send a prune message then upstream
1437 if (VIFM_ISEMPTY(g->gt_grpmems) && r->rt_gateway) {
1442 * There is no kernel entry for this group. Therefore, we can
1443 * simply ignore the prune, as we are not forwarding this traffic
1446 IF_DEBUG(DEBUG_PRUNE|DEBUG_CACHE)
1447 log(LOG_DEBUG, 0, "%s (%s %s)/%d from %s",
1448 "prune message received with no kernel entry for",
1449 inet_fmt(prun_src, s1), inet_fmt(prun_grp, s2),
1450 prun_tmr, inet_fmt(src, s3));
1456 * Checks if this mcastgrp is present in the kernel table
1457 * If so and if a prune was sent, it sends a graft upwards
1460 chkgrp_graft(vifi, mcastgrp)
1467 for (g = kernel_table; g; g = g->gt_gnext) {
1468 if (ntohl(mcastgrp) < ntohl(g->gt_mcastgrp))
1472 if (g->gt_mcastgrp == mcastgrp && VIFM_ISSET(vifi, r->rt_children))
1473 if (g->gt_prsent_timer) {
1474 VIFM_SET(vifi, g->gt_grpmems);
1477 * If the vif that was joined was a scoped vif,
1478 * ignore it ; don't graft back
1481 if (VIFM_ISEMPTY(g->gt_grpmems))
1484 /* send graft upwards */
1487 /* update cache timer*/
1488 g->gt_timer = CACHE_LIFETIME(cache_lifetime);
1490 IF_DEBUG(DEBUG_PRUNE|DEBUG_CACHE)
1491 log(LOG_DEBUG, 0, "chkgrp graft (%s %s) gm:%x",
1493 inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
1498 /* Send route change notification to reservation protocol. */
1499 rsrr_cache_send(g,1);
1505 /* determine the multicast group and src
1507 * if it does, then determine if a prune was sent
1509 * if prune sent upstream, send graft upstream and send
1512 * if no prune sent upstream, change the forwarding bit
1513 * for this interface and send ack downstream.
1515 * if no entry exists for this group send ack downstream.
1518 accept_graft(src, dst, p, datalen)
1530 struct ptable *pt, **ptnp;
1534 "received non-decipherable graft from %s",
1539 for (i = 0; i< 4; i++)
1540 ((char *)&graft_src)[i] = *p++;
1541 for (i = 0; i< 4; i++)
1542 ((char *)&graft_grp)[i] = *p++;
1544 vifi = find_vif(src, dst);
1545 send_graft_ack(dst, src, graft_src, graft_grp, vifi);
1547 if (vifi == NO_VIF) {
1549 "ignoring graft for (%s %s) from non-neighbor %s",
1550 inet_fmt(graft_src, s2), inet_fmt(graft_grp, s3),
1555 IF_DEBUG(DEBUG_PRUNE)
1556 log(LOG_DEBUG, 0, "%s on vif %d grafts (%s %s)",
1557 inet_fmt(src, s1), vifi,
1558 inet_fmt(graft_src, s2), inet_fmt(graft_grp, s3));
1561 * Find the subnet for the graft
1563 if (find_src_grp(graft_src, 0, graft_grp)) {
1564 g = gtp ? gtp->gt_gnext : kernel_table;
1567 if (VIFM_ISSET(vifi, g->gt_scope)) {
1568 log(LOG_WARNING, 0, "graft received from %s on scoped grp (%s %s)",
1569 inet_fmt(src, s1), inet_fmt(graft_src, s2),
1570 inet_fmt(graft_grp, s3));
1574 ptnp = &g->gt_pruntbl;
1575 while ((pt = *ptnp) != NULL) {
1576 if ((pt->pt_vifi == vifi) && (pt->pt_router == src)) {
1577 NBRM_CLR(pt->pt_index, g->gt_prunes);
1578 *ptnp = pt->pt_next;
1581 VIFM_SET(vifi, g->gt_grpmems);
1582 IF_DEBUG(DEBUG_PRUNE|DEBUG_CACHE)
1583 log(LOG_DEBUG, 0, "accept graft (%s %s) gm:%x",
1585 inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
1590 /* Send route change notification to reservation protocol. */
1591 rsrr_cache_send(g,1);
1595 ptnp = &pt->pt_next;
1599 g->gt_timer = CACHE_LIFETIME(cache_lifetime);
1601 if (g->gt_prsent_timer)
1602 /* send graft upwards */
1606 * We have no state for the source and group in question.
1607 * This is fine, since we know that we have no prune state, and
1608 * grafts are requests to remove prune state.
1610 IF_DEBUG(DEBUG_PRUNE)
1611 log(LOG_DEBUG, 0, "%s (%s %s) from %s",
1612 "graft received with no kernel entry for",
1613 inet_fmt(graft_src, s1), inet_fmt(graft_grp, s2),
1620 * find out which group is involved first of all
1621 * then determine if a graft was sent.
1622 * if no graft sent, ignore the message
1623 * if graft was sent and the ack is from the right
1624 * source, remove the graft timer so that we don't
1625 * have send a graft again
1628 accept_g_ack(src, dst, p, datalen)
1640 if ((vifi = find_vif(src, dst)) == NO_VIF) {
1642 "ignoring graft ack from non-neighbor %s",
1647 if (datalen < 0 || datalen > 8) {
1649 "received non-decipherable graft ack from %s",
1654 for (i = 0; i< 4; i++)
1655 ((char *)&grft_src)[i] = *p++;
1656 for (i = 0; i< 4; i++)
1657 ((char *)&grft_grp)[i] = *p++;
1659 IF_DEBUG(DEBUG_PRUNE)
1660 log(LOG_DEBUG, 0, "%s on vif %d acks graft (%s, %s)",
1661 inet_fmt(src, s1), vifi,
1662 inet_fmt(grft_src, s2), inet_fmt(grft_grp, s3));
1665 * Find the subnet for the graft ack
1667 if (find_src_grp(grft_src, 0, grft_grp)) {
1668 g = gtp ? gtp->gt_gnext : kernel_table;
1671 log(LOG_WARNING, 0, "%s (%s, %s) from %s",
1672 "rcvd graft ack with no kernel entry for",
1673 inet_fmt(grft_src, s1), inet_fmt(grft_grp, s2),
1684 * free all prune entries and kernel routes
1685 * normally, this should inform the kernel that all of its routes
1686 * are going away, but this is only called by restart(), which is
1687 * about to call MRT_DONE which does that anyway.
1692 register struct rtentry *r;
1693 register struct gtable *g, *prev_g;
1694 register struct stable *s, *prev_s;
1695 register struct ptable *p, *prev_p;
1697 for (r = routing_table; r; r = r->rt_next) {
1716 if (prev_g->gt_rexmit_timer)
1717 timer_clearTimer(prev_g->gt_rexmit_timer);
1720 r->rt_groups = NULL;
1722 kernel_table = NULL;
1724 g = kernel_no_route;
1731 if (prev_g->gt_rexmit_timer)
1732 timer_clearTimer(prev_g->gt_rexmit_timer);
1735 kernel_no_route = NULL;
1739 * When a new route is created, search
1740 * a) The less-specific part of the routing table
1741 * b) The route-less kernel table
1742 * for sources that the new route might want to handle.
1744 * "Inheriting" these sources might be cleanest, but simply deleting
1745 * them is easier, and letting the kernel re-request them.
1751 register struct rtentry *rp;
1752 register struct gtable *gt, **gtnp;
1753 register struct stable *st, **stnp;
1755 for (rp = rt->rt_next; rp; rp = rp->rt_next) {
1756 if (rp->rt_groups == NULL)
1758 if ((rt->rt_origin & rp->rt_originmask) == rp->rt_origin) {
1759 IF_DEBUG(DEBUG_ROUTE)
1760 log(LOG_DEBUG, 0, "Route for %s stealing sources from %s",
1761 RT_FMT(rt, s1), RT_FMT(rp, s2));
1762 for (gt = rp->rt_groups; gt; gt = gt->gt_next) {
1763 stnp = >->gt_srctbl;
1764 while ((st = *stnp) != NULL) {
1765 if ((st->st_origin & rt->rt_originmask) == rt->rt_origin) {
1766 IF_DEBUG(DEBUG_ROUTE)
1767 log(LOG_DEBUG, 0, "%s stealing (%s %s) from %s",
1769 inet_fmt(st->st_origin, s3),
1770 inet_fmt(gt->gt_mcastgrp, s4),
1772 if (st->st_ctime != 0) {
1773 if (k_del_rg(st->st_origin, gt) < 0) {
1774 log(LOG_WARNING, errno, "%s (%s, %s)",
1775 "steal_sources trying to delete",
1776 inet_fmt(st->st_origin, s1),
1777 inet_fmt(gt->gt_mcastgrp, s2));
1781 *stnp = st->st_next;
1784 stnp = &st->st_next;
1791 gtnp = &kernel_no_route;
1792 while ((gt = *gtnp) != NULL) {
1793 if (gt->gt_srctbl && ((gt->gt_srctbl->st_origin & rt->rt_originmask)
1794 == rt->rt_origin)) {
1795 IF_DEBUG(DEBUG_ROUTE)
1796 log(LOG_DEBUG, 0, "%s stealing (%s %s) from %s",
1798 inet_fmt(gt->gt_srctbl->st_origin, s3),
1799 inet_fmt(gt->gt_mcastgrp, s4),
1801 if (gt->gt_srctbl->st_ctime != 0) {
1802 if (k_del_rg(gt->gt_srctbl->st_origin, gt) < 0) {
1803 log(LOG_WARNING, errno, "%s (%s %s)",
1804 "steal_sources trying to delete",
1805 inet_fmt(gt->gt_srctbl->st_origin, s1),
1806 inet_fmt(gt->gt_mcastgrp, s2));
1810 free(gt->gt_srctbl);
1811 *gtnp = gt->gt_next;
1813 gt->gt_next->gt_prev = gt->gt_prev;
1814 if (gt->gt_rexmit_timer)
1815 timer_clearTimer(gt->gt_rexmit_timer);
1818 gtnp = >->gt_next;
1824 * Advance the timers on all the cache entries.
1825 * If there are any entries whose timers have expired,
1826 * remove these entries from the kernel cache.
1832 struct gtable *gt, **gtnptr;
1833 struct stable *st, **stnp;
1834 struct ptable *pt, **ptnp;
1835 struct sioc_sg_req sg_req;
1837 IF_DEBUG(DEBUG_PRUNE|DEBUG_CACHE)
1838 log(LOG_DEBUG, 0, "aging forwarding cache entries");
1840 gtnptr = &kernel_table;
1841 while ((gt = *gtnptr) != NULL) {
1842 vifi_t i; /* XXX Debugging */
1843 int fixit = 0; /* XXX Debugging */
1847 /* XXX Debugging... */
1848 for (i = 0; i < numvifs; i++) {
1850 * If we're not sending on this vif,
1851 * And this group isn't scoped on this vif,
1852 * And I'm the parent for this route on this vif,
1853 * And there are subordinates on this vif,
1854 * And all of the subordinates haven't pruned,
1856 * and remember to fix it up later
1858 if (!VIFM_ISSET(i, gt->gt_grpmems) &&
1859 !VIFM_ISSET(i, gt->gt_scope) &&
1860 VIFM_ISSET(i, r->rt_children) &&
1861 NBRM_ISSETMASK(uvifs[i].uv_nbrmap, r->rt_subordinates) &&
1862 !SUBS_ARE_PRUNED(r->rt_subordinates, uvifs[i].uv_nbrmap, gt->gt_prunes)) {
1863 log(LOG_WARNING, 0, "(%s %s) is blackholing on vif %d",
1864 RT_FMT(r, s1), inet_fmt(gt->gt_mcastgrp, s2), i);
1869 log(LOG_WARNING, 0, "fixing membership for (%s %s) gm:%x",
1870 RT_FMT(r, s1), inet_fmt(gt->gt_mcastgrp, s2), gt->gt_grpmems);
1871 determine_forwvifs(gt);
1872 send_prune_or_graft(gt);
1873 log(LOG_WARNING, 0, "fixed membership for (%s %s) gm:%x",
1874 RT_FMT(r, s1), inet_fmt(gt->gt_mcastgrp, s2), gt->gt_grpmems);
1880 /* If there are group members,
1881 * and there are recent sources,
1882 * and we have a route,
1883 * and it's not directly connected,
1884 * and we haven't sent a prune,
1885 * if there are any cache entries in the kernel
1886 * [if there aren't we're probably waiting to rexmit],
1890 if (VIFM_ISEMPTY(gt->gt_grpmems) && gt->gt_srctbl && r && r->rt_gateway && gt->gt_prsent_timer == 0) {
1891 for (st = gt->gt_srctbl; st; st = st->st_next)
1892 if (st->st_ctime != 0)
1895 log(LOG_WARNING, 0, "grpmems for (%s %s) is empty but no prune state!", RT_FMT(r, s1), inet_fmt(gt->gt_mcastgrp, s2));
1896 send_prune_or_graft(gt);
1902 /* XXX ...Debugging */
1904 /* advance the timer for the kernel entry */
1905 gt->gt_timer -= TIMER_INTERVAL;
1907 /* decrement prune timer if need be */
1908 if (gt->gt_prsent_timer > 0) {
1909 gt->gt_prsent_timer -= TIMER_INTERVAL;
1910 if (gt->gt_prsent_timer <= 0) {
1911 IF_DEBUG(DEBUG_PRUNE)
1912 log(LOG_DEBUG, 0, "upstream prune tmo (%s %s)",
1914 inet_fmt(gt->gt_mcastgrp, s2));
1915 gt->gt_prsent_timer = -1;
1916 /* Reset the prune retransmission timer to its initial value */
1917 gt->gt_prune_rexmit = PRUNE_REXMIT_VAL;
1921 /* retransmit graft with exponential backoff */
1922 if (gt->gt_grftsnt) {
1925 y = ++gt->gt_grftsnt;
1926 while (y && !(y & 1))
1935 * If a prune expires, forward again on that vif.
1937 ptnp = >->gt_pruntbl;
1938 while ((pt = *ptnp) != NULL) {
1939 if ((pt->pt_timer -= TIMER_INTERVAL) <= 0) {
1940 IF_DEBUG(DEBUG_PRUNE)
1941 log(LOG_DEBUG, 0, "expire prune (%s %s) from %s on vif %d",
1943 inet_fmt(gt->gt_mcastgrp, s2),
1944 inet_fmt(pt->pt_router, s3),
1946 if (gt->gt_prsent_timer > 0) {
1947 log(LOG_WARNING, 0, "prune (%s %s) from %s on vif %d expires with %d left on prsent timer",
1949 inet_fmt(gt->gt_mcastgrp, s2),
1950 inet_fmt(pt->pt_router, s3),
1951 pt->pt_vifi, gt->gt_prsent_timer);
1952 /* Send a graft to heal the tree. */
1956 NBRM_CLR(pt->pt_index, gt->gt_prunes);
1957 expire_prune(pt->pt_vifi, gt);
1959 /* remove the router's prune entry and await new one */
1960 *ptnp = pt->pt_next;
1963 ptnp = &pt->pt_next;
1968 * If the cache entry has expired, delete source table entries for
1969 * silent sources. If there are no source entries left, and there
1970 * are no downstream prunes, then the entry is deleted.
1971 * Otherwise, the cache entry's timer is refreshed.
1973 if (gt->gt_timer <= 0) {
1974 IF_DEBUG(DEBUG_CACHE)
1975 log(LOG_DEBUG, 0, "(%s %s) timed out, checking for traffic",
1976 RT_FMT(gt->gt_route, s1),
1977 inet_fmt(gt->gt_mcastgrp, s2));
1978 /* Check for traffic before deleting source entries */
1979 sg_req.grp.s_addr = gt->gt_mcastgrp;
1980 stnp = >->gt_srctbl;
1981 while ((st = *stnp) != NULL) {
1983 * Source entries with no ctime are not actually in the
1984 * kernel; they have been removed by rexmit_prune() so
1985 * are safe to remove from the list at this point.
1988 sg_req.src.s_addr = st->st_origin;
1989 if (ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) < 0) {
1990 log(LOG_WARNING, errno, "%s (%s %s)",
1991 "age_table_entry: SIOCGETSGCNT failing for",
1992 inet_fmt(st->st_origin, s1),
1993 inet_fmt(gt->gt_mcastgrp, s2));
1994 /* Make sure it gets deleted below */
1995 sg_req.pktcnt = st->st_pktcnt;
1998 sg_req.pktcnt = st->st_pktcnt;
2000 if (sg_req.pktcnt == st->st_pktcnt) {
2001 *stnp = st->st_next;
2002 IF_DEBUG(DEBUG_CACHE)
2003 log(LOG_DEBUG, 0, "age_table_entry deleting (%s %s)",
2004 inet_fmt(st->st_origin, s1),
2005 inet_fmt(gt->gt_mcastgrp, s2));
2006 if (st->st_ctime != 0) {
2007 if (k_del_rg(st->st_origin, gt) < 0) {
2008 log(LOG_WARNING, errno,
2009 "age_table_entry trying to delete (%s %s)",
2010 inet_fmt(st->st_origin, s1),
2011 inet_fmt(gt->gt_mcastgrp, s2));
2017 st->st_pktcnt = sg_req.pktcnt;
2018 stnp = &st->st_next;
2023 * Retain the group entry if we have downstream prunes or if
2024 * there is at least one source in the list that still has
2025 * traffic, or if our upstream prune timer or graft
2026 * retransmission timer is running.
2028 if (gt->gt_pruntbl != NULL || gt->gt_srctbl != NULL ||
2029 gt->gt_prsent_timer > 0 || gt->gt_grftsnt > 0) {
2030 IF_DEBUG(DEBUG_CACHE)
2031 log(LOG_DEBUG, 0, "refresh lifetim of cache entry %s%s%s%s(%s, %s)",
2032 gt->gt_pruntbl ? "(dstrm prunes) " : "",
2033 gt->gt_srctbl ? "(trfc flow) " : "",
2034 gt->gt_prsent_timer > 0 ? "(upstrm prune) " : "",
2035 gt->gt_grftsnt > 0 ? "(grft rexmit) " : "",
2037 inet_fmt(gt->gt_mcastgrp, s2));
2038 gt->gt_timer = CACHE_LIFETIME(cache_lifetime);
2039 if (gt->gt_prsent_timer == -1) {
2041 * The upstream prune timed out. Remove any kernel
2044 gt->gt_prsent_timer = 0;
2045 if (gt->gt_pruntbl) {
2046 log(LOG_WARNING, 0, "upstream prune for (%s %s) expires with downstream prunes active",
2047 RT_FMT(r, s1), inet_fmt(gt->gt_mcastgrp, s2));
2051 gtnptr = >->gt_gnext;
2055 IF_DEBUG(DEBUG_CACHE)
2056 log(LOG_DEBUG, 0, "timeout cache entry (%s, %s)",
2058 inet_fmt(gt->gt_mcastgrp, s2));
2061 gt->gt_prev->gt_next = gt->gt_next;
2063 gt->gt_route->rt_groups = gt->gt_next;
2065 gt->gt_next->gt_prev = gt->gt_prev;
2068 gt->gt_gprev->gt_gnext = gt->gt_gnext;
2069 gtnptr = >->gt_gprev->gt_gnext;
2071 kernel_table = gt->gt_gnext;
2072 gtnptr = &kernel_table;
2075 gt->gt_gnext->gt_gprev = gt->gt_gprev;
2078 /* Send route change notification to reservation protocol. */
2079 rsrr_cache_send(gt,0);
2080 rsrr_cache_clean(gt);
2082 if (gt->gt_rexmit_timer)
2083 timer_clearTimer(gt->gt_rexmit_timer);
2087 if (gt->gt_prsent_timer == -1) {
2089 * The upstream prune timed out. Remove any kernel
2092 gt->gt_prsent_timer = 0;
2093 if (gt->gt_pruntbl) {
2094 log(LOG_WARNING, 0, "upstream prune for (%s %s) expires with downstream prunes active",
2095 RT_FMT(r, s1), inet_fmt(gt->gt_mcastgrp, s2));
2099 gtnptr = >->gt_gnext;
2104 * When traversing the no_route table, the decision is much easier.
2105 * Just delete it if it has timed out.
2107 gtnptr = &kernel_no_route;
2108 while ((gt = *gtnptr) != NULL) {
2109 /* advance the timer for the kernel entry */
2110 gt->gt_timer -= TIMER_INTERVAL;
2112 if (gt->gt_timer < 0) {
2113 if (gt->gt_srctbl) {
2114 if (gt->gt_srctbl->st_ctime != 0) {
2115 if (k_del_rg(gt->gt_srctbl->st_origin, gt) < 0) {
2116 log(LOG_WARNING, errno, "%s (%s %s)",
2117 "age_table_entry trying to delete no-route",
2118 inet_fmt(gt->gt_srctbl->st_origin, s1),
2119 inet_fmt(gt->gt_mcastgrp, s2));
2123 free(gt->gt_srctbl);
2125 *gtnptr = gt->gt_next;
2127 gt->gt_next->gt_prev = gt->gt_prev;
2129 if (gt->gt_rexmit_timer)
2130 timer_clearTimer(gt->gt_rexmit_timer);
2134 gtnptr = >->gt_next;
2140 * Modify the kernel to forward packets when one or multiple prunes that
2141 * were received on the vif given by vifi, for the group given by gt,
2145 expire_prune(vifi, gt)
2150 * No need to send a graft, any prunes that we sent
2151 * will expire before any prunes that we have received.
2152 * However, in the case that we did make a mistake,
2153 * send a graft to compensate.
2155 if (gt->gt_prsent_timer >= MIN_PRUNE_LIFE) {
2156 IF_DEBUG(DEBUG_PRUNE)
2157 log(LOG_DEBUG, 0, "prune expired with %d left on %s",
2158 gt->gt_prsent_timer, "prsent_timer");
2159 gt->gt_prsent_timer = 0;
2163 /* modify the kernel entry to forward packets */
2164 if (!VIFM_ISSET(vifi, gt->gt_grpmems)) {
2165 struct rtentry *rt = gt->gt_route;
2166 VIFM_SET(vifi, gt->gt_grpmems);
2167 IF_DEBUG(DEBUG_CACHE)
2168 log(LOG_DEBUG, 0, "forw again (%s %s) gm:%x vif:%d",
2170 inet_fmt(gt->gt_mcastgrp, s2), gt->gt_grpmems, vifi);
2175 /* Send route change notification to reservation protocol. */
2176 rsrr_cache_send(gt,1);
2182 * Print the contents of the cache table on file 'fp2'.
2188 register struct rtentry *r;
2189 register struct gtable *gt;
2190 register struct stable *st;
2191 register struct ptable *pt;
2194 register time_t thyme = time(0);
2197 "Multicast Routing Cache Table (%d entries)\n%s", kroutes,
2198 " Origin Mcast-group CTmr Age Ptmr Rx IVif Forwvifs\n");
2200 "<(prunesrc:vif[idx]/tmr) prunebitmap\n%s",
2201 ">Source Lifetime SavPkt Pkts Bytes RPFf\n");
2203 for (gt = kernel_no_route; gt; gt = gt->gt_next) {
2204 if (gt->gt_srctbl) {
2205 fprintf(fp2, " %-18s %-15s %-8s %-8s - -1 (no route)\n",
2206 inet_fmts(gt->gt_srctbl->st_origin, 0xffffffff, s1),
2207 inet_fmt(gt->gt_mcastgrp, s2), scaletime(gt->gt_timer),
2208 scaletime(thyme - gt->gt_ctime));
2209 fprintf(fp2, ">%s\n", inet_fmt(gt->gt_srctbl->st_origin, s1));
2213 for (gt = kernel_table; gt; gt = gt->gt_gnext) {
2215 fprintf(fp2, " %-18s %-15s",
2217 inet_fmt(gt->gt_mcastgrp, s2));
2219 fprintf(fp2, " %-8s", scaletime(gt->gt_timer));
2221 fprintf(fp2, " %-8s %-8s ", scaletime(thyme - gt->gt_ctime),
2222 gt->gt_prsent_timer ? scaletime(gt->gt_prsent_timer) :
2225 if (gt->gt_prune_rexmit) {
2226 int i = gt->gt_prune_rexmit;
2229 while (i > PRUNE_REXMIT_VAL) {
2233 if (n == 0 && gt->gt_prsent_timer == 0)
2236 fprintf(fp2, "%2d", n);
2241 fprintf(fp2, " %2u%c%c", r->rt_parent,
2242 gt->gt_prsent_timer ? 'P' :
2243 gt->gt_grftsnt ? 'G' : ' ',
2244 VIFM_ISSET(r->rt_parent, gt->gt_scope) ? 'B' : ' ');
2246 for (i = 0; i < numvifs; ++i) {
2247 if (VIFM_ISSET(i, gt->gt_grpmems))
2248 fprintf(fp2, " %u ", i);
2249 else if (VIFM_ISSET(i, r->rt_children) &&
2250 NBRM_ISSETMASK(uvifs[i].uv_nbrmap, r->rt_subordinates))
2251 fprintf(fp2, " %u%c", i,
2252 VIFM_ISSET(i, gt->gt_scope) ? 'b' :
2253 SUBS_ARE_PRUNED(r->rt_subordinates,
2254 uvifs[i].uv_nbrmap, gt->gt_prunes) ? 'p' : '!');
2257 if (gt->gt_pruntbl) {
2260 for (pt = gt->gt_pruntbl; pt; pt = pt->pt_next) {
2261 fprintf(fp2, "%c%s:%d[%d]/%d", c, inet_fmt(pt->pt_router, s1),
2262 pt->pt_vifi, pt->pt_index, pt->pt_timer);
2266 fprintf(fp2, " 0x%08lx%08lx\n",/*XXX*/
2267 gt->gt_prunes.hi, gt->gt_prunes.lo);
2269 for (st = gt->gt_srctbl; st; st = st->st_next) {
2270 fprintf(fp2, ">%-18s %-8s %6ld", inet_fmt(st->st_origin, s1),
2271 st->st_ctime ? scaletime(thyme - st->st_ctime) : "-",
2274 struct sioc_sg_req sg_req;
2276 sg_req.src.s_addr = st->st_origin;
2277 sg_req.grp.s_addr = gt->gt_mcastgrp;
2278 if (ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) < 0) {
2279 log(LOG_WARNING, errno, "SIOCGETSGCNT on (%s %s)",
2280 inet_fmt(st->st_origin, s1),
2281 inet_fmt(gt->gt_mcastgrp, s2));
2283 fprintf(fp2, " %8ld %8ld %4ld", sg_req.pktcnt,
2284 sg_req.bytecnt, sg_req.wrong_if);
2293 * Traceroute function which returns traceroute replies to the requesting
2294 * router. Also forwards the request to downstream routers.
2297 accept_mtrace(src, dst, group, data, no, datalen)
2302 u_int no; /* promoted u_char */
2308 struct tr_query *qry;
2309 struct tr_resp *resp;
2313 int errcode = TR_NO_ERR;
2316 struct sioc_vif_req v_req;
2317 struct sioc_sg_req sg_req;
2319 /* Remember qid across invocations */
2320 static u_int32 oqid = 0;
2322 /* timestamp the request/response */
2323 gettimeofday(&tp, 0);
2326 * Check if it is a query or a response
2328 if (datalen == QLEN) {
2330 IF_DEBUG(DEBUG_TRACE)
2331 log(LOG_DEBUG, 0, "Initial traceroute query rcvd from %s to %s",
2332 inet_fmt(src, s1), inet_fmt(dst, s2));
2334 else if ((datalen - QLEN) % RLEN == 0) {
2336 IF_DEBUG(DEBUG_TRACE)
2337 log(LOG_DEBUG, 0, "In-transit traceroute query rcvd from %s to %s",
2338 inet_fmt(src, s1), inet_fmt(dst, s2));
2339 if (IN_MULTICAST(ntohl(dst))) {
2340 IF_DEBUG(DEBUG_TRACE)
2341 log(LOG_DEBUG, 0, "Dropping multicast response");
2346 log(LOG_WARNING, 0, "%s from %s to %s",
2347 "Non decipherable traceroute request recieved",
2348 inet_fmt(src, s1), inet_fmt(dst, s2));
2352 qry = (struct tr_query *)data;
2355 * if it is a packet with all reports filled, drop it
2357 if ((rcount = (datalen - QLEN)/RLEN) == no) {
2358 IF_DEBUG(DEBUG_TRACE)
2359 log(LOG_DEBUG, 0, "packet with all reports filled in");
2363 IF_DEBUG(DEBUG_TRACE) {
2364 log(LOG_DEBUG, 0, "s: %s g: %s d: %s ", inet_fmt(qry->tr_src, s1),
2365 inet_fmt(group, s2), inet_fmt(qry->tr_dst, s3));
2366 log(LOG_DEBUG, 0, "rttl: %d rd: %s", qry->tr_rttl,
2367 inet_fmt(qry->tr_raddr, s1));
2368 log(LOG_DEBUG, 0, "rcount:%d, qid:%06x", rcount, qry->tr_qid);
2371 /* determine the routing table entry for this traceroute */
2372 rt = determine_route(qry->tr_src);
2373 IF_DEBUG(DEBUG_TRACE)
2375 log(LOG_DEBUG, 0, "rt parent vif: %d rtr: %s metric: %d",
2376 rt->rt_parent, inet_fmt(rt->rt_gateway, s1), rt->rt_metric);
2377 log(LOG_DEBUG, 0, "rt origin %s",
2380 log(LOG_DEBUG, 0, "...no route");
2383 * Query type packet - check if rte exists
2384 * Check if the query destination is a vif connected to me.
2385 * and if so, whether I should start response back
2387 if (type == QUERY) {
2388 if (oqid == qry->tr_qid) {
2390 * If the multicast router is a member of the group being
2391 * queried, and the query is multicasted, then the router can
2392 * recieve multiple copies of the same query. If we have already
2393 * replied to this traceroute, just ignore it this time.
2395 * This is not a total solution, but since if this fails you
2396 * only get N copies, N <= the number of interfaces on the router,
2399 IF_DEBUG(DEBUG_TRACE)
2400 log(LOG_DEBUG, 0, "ignoring duplicate traceroute packet");
2405 IF_DEBUG(DEBUG_TRACE)
2406 log(LOG_DEBUG, 0, "Mcast traceroute: no route entry %s",
2407 inet_fmt(qry->tr_src, s1));
2408 if (IN_MULTICAST(ntohl(dst)))
2411 vifi = find_vif(qry->tr_dst, 0);
2413 if (vifi == NO_VIF) {
2414 /* The traceroute destination is not on one of my subnet vifs. */
2415 IF_DEBUG(DEBUG_TRACE)
2416 log(LOG_DEBUG, 0, "Destination %s not an interface",
2417 inet_fmt(qry->tr_dst, s1));
2418 if (IN_MULTICAST(ntohl(dst)))
2420 errcode = TR_WRONG_IF;
2421 } else if (rt != NULL && !VIFM_ISSET(vifi, rt->rt_children)) {
2422 IF_DEBUG(DEBUG_TRACE)
2423 log(LOG_DEBUG, 0, "Destination %s not on forwarding tree for src %s",
2424 inet_fmt(qry->tr_dst, s1), inet_fmt(qry->tr_src, s2));
2425 if (IN_MULTICAST(ntohl(dst)))
2427 errcode = TR_WRONG_IF;
2432 * determine which interface the packet came in on
2433 * RESP packets travel hop-by-hop so this either traversed
2434 * a tunnel or came from a directly attached mrouter.
2436 if ((vifi = find_vif(src, dst)) == NO_VIF) {
2437 IF_DEBUG(DEBUG_TRACE)
2438 log(LOG_DEBUG, 0, "Wrong interface for packet");
2439 errcode = TR_WRONG_IF;
2443 /* Now that we've decided to send a response, save the qid */
2446 IF_DEBUG(DEBUG_TRACE)
2447 log(LOG_DEBUG, 0, "Sending traceroute response");
2449 /* copy the packet to the sending buffer */
2450 p = send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN;
2452 bcopy(data, p, datalen);
2457 * If there is no room to insert our reply, coopt the previous hop
2458 * error indication to relay this fact.
2460 if (p + sizeof(struct tr_resp) > send_buf + RECV_BUF_SIZE) {
2461 resp = (struct tr_resp *)p - 1;
2462 resp->tr_rflags = TR_NO_SPACE;
2468 * fill in initial response fields
2470 resp = (struct tr_resp *)p;
2471 bzero(resp, sizeof(struct tr_resp));
2474 resp->tr_qarr = htonl(((tp.tv_sec + JAN_1970) << 16) +
2475 ((tp.tv_usec << 10) / 15625));
2477 resp->tr_rproto = PROTO_DVMRP;
2478 resp->tr_outaddr = (vifi == NO_VIF) ? dst : uvifs[vifi].uv_lcl_addr;
2479 resp->tr_fttl = (vifi == NO_VIF) ? 0 : uvifs[vifi].uv_threshold;
2480 resp->tr_rflags = errcode;
2483 * obtain # of packets out on interface
2486 if (vifi != NO_VIF && ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) >= 0)
2487 resp->tr_vifout = htonl(v_req.ocount);
2489 resp->tr_vifout = 0xffffffff;
2492 * fill in scoping & pruning information
2495 for (gt = rt->rt_groups; gt; gt = gt->gt_next) {
2496 if (gt->gt_mcastgrp >= group)
2502 if (gt && gt->gt_mcastgrp == group) {
2505 for (st = gt->gt_srctbl; st; st = st->st_next)
2506 if (qry->tr_src == st->st_origin)
2509 sg_req.src.s_addr = qry->tr_src;
2510 sg_req.grp.s_addr = group;
2511 if (st && st->st_ctime != 0 &&
2512 ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) >= 0)
2513 resp->tr_pktcnt = htonl(sg_req.pktcnt + st->st_savpkt);
2515 resp->tr_pktcnt = htonl(st ? st->st_savpkt : 0xffffffff);
2517 if (VIFM_ISSET(vifi, gt->gt_scope))
2518 resp->tr_rflags = TR_SCOPED;
2519 else if (gt->gt_prsent_timer)
2520 resp->tr_rflags = TR_PRUNED;
2521 else if (!VIFM_ISSET(vifi, gt->gt_grpmems))
2522 if (!NBRM_ISEMPTY(uvifs[vifi].uv_nbrmap) &&
2523 SUBS_ARE_PRUNED(rt->rt_subordinates,
2524 uvifs[vifi].uv_nbrmap, gt->gt_prunes))
2525 resp->tr_rflags = TR_OPRUNED;
2527 resp->tr_rflags = TR_NO_FWD;
2529 if ((vifi != NO_VIF && scoped_addr(vifi, group)) ||
2530 (rt && scoped_addr(rt->rt_parent, group)))
2531 resp->tr_rflags = TR_SCOPED;
2532 else if (rt && !VIFM_ISSET(vifi, rt->rt_children))
2533 resp->tr_rflags = TR_NO_FWD;
2537 * if no rte exists, set NO_RTE error
2540 src = dst; /* the dst address of resp. pkt */
2541 resp->tr_inaddr = 0;
2542 resp->tr_rflags = TR_NO_RTE;
2543 resp->tr_rmtaddr = 0;
2545 /* get # of packets in on interface */
2546 v_req.vifi = rt->rt_parent;
2547 if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) >= 0)
2548 resp->tr_vifin = htonl(v_req.icount);
2550 resp->tr_vifin = 0xffffffff;
2552 MASK_TO_VAL(rt->rt_originmask, resp->tr_smask);
2553 src = uvifs[rt->rt_parent].uv_lcl_addr;
2554 resp->tr_inaddr = src;
2555 resp->tr_rmtaddr = rt->rt_gateway;
2556 if (!VIFM_ISSET(vifi, rt->rt_children)) {
2557 IF_DEBUG(DEBUG_TRACE)
2558 log(LOG_DEBUG, 0, "Destination %s not on forwarding tree for src %s",
2559 inet_fmt(qry->tr_dst, s1), inet_fmt(qry->tr_src, s2));
2560 resp->tr_rflags = TR_WRONG_IF;
2562 if (rt->rt_metric >= UNREACHABLE) {
2563 resp->tr_rflags = TR_NO_RTE;
2564 /* Hack to send reply directly */
2571 * if metric is 1 or no. of reports is 1, send response to requestor
2572 * else send to upstream router. If the upstream router can't handle
2573 * mtrace, set an error code and send to requestor anyway.
2575 IF_DEBUG(DEBUG_TRACE)
2576 log(LOG_DEBUG, 0, "rcount:%d, no:%d", rcount, no);
2578 if ((rcount + 1 == no) || (rt == NULL) || (rt->rt_metric == 1)) {
2579 resptype = IGMP_MTRACE_RESP;
2580 dst = qry->tr_raddr;
2582 if (!can_mtrace(rt->rt_parent, rt->rt_gateway)) {
2583 dst = qry->tr_raddr;
2584 resp->tr_rflags = TR_OLD_ROUTER;
2585 resptype = IGMP_MTRACE_RESP;
2587 dst = rt->rt_gateway;
2588 resptype = IGMP_MTRACE;
2591 if (IN_MULTICAST(ntohl(dst))) {
2593 * Send the reply on a known multicast capable vif.
2594 * If we don't have one, we can't source any multicasts anyway.
2596 if (phys_vif != -1) {
2597 IF_DEBUG(DEBUG_TRACE)
2598 log(LOG_DEBUG, 0, "Sending reply to %s from %s",
2599 inet_fmt(dst, s1), inet_fmt(uvifs[phys_vif].uv_lcl_addr, s2));
2600 k_set_ttl(qry->tr_rttl);
2601 send_igmp(uvifs[phys_vif].uv_lcl_addr, dst,
2602 resptype, no, group,
2606 log(LOG_INFO, 0, "No enabled phyints -- %s",
2607 "dropping traceroute reply");
2609 IF_DEBUG(DEBUG_TRACE)
2610 log(LOG_DEBUG, 0, "Sending %s to %s from %s",
2611 resptype == IGMP_MTRACE_RESP ? "reply" : "request on",
2612 inet_fmt(dst, s1), inet_fmt(src, s2));
2615 resptype, no, group,