1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* The mrouted program is covered by the license in the accompanying file
|
|
|
|
* named "LICENSE". Use of the mrouted program represents acceptance of
|
|
|
|
* the terms and conditions listed in that file.
|
|
|
|
*
|
|
|
|
* The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
|
|
|
|
* Leland Stanford Junior University.
|
|
|
|
*
|
|
|
|
*
|
1997-09-30 06:15:23 +00:00
|
|
|
* $Id: prune.c,v 1.13 1997/02/22 16:07:03 peter Exp $
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
extern int cache_lifetime;
|
|
|
|
extern int max_prune_lifetime;
|
1995-06-13 18:05:16 +00:00
|
|
|
extern struct rtentry *routing_table;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
extern int phys_vif;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* dither cache lifetime to obtain a value between x and 2*x
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
#ifdef SYSV
|
|
|
|
#define CACHE_LIFETIME(x) ((x) + (lrand48() % (x)))
|
|
|
|
#else
|
1994-09-08 00:26:13 +00:00
|
|
|
#define CACHE_LIFETIME(x) ((x) + (random() % (x)))
|
1995-06-13 18:05:16 +00:00
|
|
|
#endif
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
#define CHK_GS(x, y) { \
|
|
|
|
switch(x) { \
|
|
|
|
case 2: \
|
|
|
|
case 4: \
|
|
|
|
case 8: \
|
|
|
|
case 16: \
|
|
|
|
case 32: \
|
|
|
|
case 64: \
|
|
|
|
case 128: \
|
|
|
|
case 256: y = 1; \
|
|
|
|
break; \
|
|
|
|
default: y = 0; \
|
|
|
|
} \
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
struct gtable *kernel_table; /* ptr to list of kernel grp entries*/
|
|
|
|
static struct gtable *kernel_no_route; /* list of grp entries w/o routes */
|
|
|
|
struct gtable *gtp; /* pointer for kernel rt entries */
|
1994-09-08 00:26:13 +00:00
|
|
|
unsigned int kroutes; /* current number of cache entries */
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/****************************************************************************
|
|
|
|
Functions that are local to prune.c
|
|
|
|
****************************************************************************/
|
1995-06-28 17:58:49 +00:00
|
|
|
static void prun_add_ttls __P((struct gtable *gt));
|
|
|
|
static int pruning_neighbor __P((vifi_t vifi, u_int32 addr));
|
|
|
|
static int can_mtrace __P((vifi_t vifi, u_int32 addr));
|
|
|
|
static struct ptable * find_prune_entry __P((u_int32 vr, struct ptable *pt));
|
1996-01-06 21:10:30 +00:00
|
|
|
static void expire_prune __P((vifi_t vifi, struct gtable *gt));
|
1995-06-28 17:58:49 +00:00
|
|
|
static void send_prune __P((struct gtable *gt));
|
|
|
|
static void send_graft __P((struct gtable *gt));
|
|
|
|
static void send_graft_ack __P((u_int32 src, u_int32 dst,
|
|
|
|
u_int32 origin, u_int32 grp));
|
|
|
|
static void update_kernel __P((struct gtable *g));
|
|
|
|
static char * scaletime __P((u_long t));
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
|
|
|
* Updates the ttl values for each vif.
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
static void
|
|
|
|
prun_add_ttls(gt)
|
|
|
|
struct gtable *gt;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct uvif *v;
|
|
|
|
vifi_t vifi;
|
|
|
|
|
|
|
|
for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
|
|
|
|
if (VIFM_ISSET(vifi, gt->gt_grpmems))
|
|
|
|
gt->gt_ttls[vifi] = v->uv_threshold;
|
|
|
|
else
|
|
|
|
gt->gt_ttls[vifi] = 0;
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* checks for scoped multicast addresses
|
|
|
|
*/
|
|
|
|
#define GET_SCOPE(gt) { \
|
1996-01-06 21:10:30 +00:00
|
|
|
register vifi_t _i; \
|
1995-06-13 18:05:16 +00:00
|
|
|
if ((ntohl((gt)->gt_mcastgrp) & 0xff000000) == 0xef000000) \
|
|
|
|
for (_i = 0; _i < numvifs; _i++) \
|
|
|
|
if (scoped_addr(_i, (gt)->gt_mcastgrp)) \
|
|
|
|
VIFM_SET(_i, (gt)->gt_scope); \
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
scoped_addr(vifi, addr)
|
|
|
|
vifi_t vifi;
|
|
|
|
u_int32 addr;
|
|
|
|
{
|
|
|
|
struct vif_acl *acl;
|
|
|
|
|
|
|
|
for (acl = uvifs[vifi].uv_acl; acl; acl = acl->acl_next)
|
|
|
|
if ((addr & acl->acl_mask) == acl->acl_addr)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-09-08 00:26:13 +00:00
|
|
|
* Determine if mcastgrp has a listener on vifi
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
int
|
|
|
|
grplst_mem(vifi, mcastgrp)
|
1994-09-08 00:26:13 +00:00
|
|
|
vifi_t vifi;
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 mcastgrp;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
register struct listaddr *g;
|
|
|
|
register struct uvif *v;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
v = &uvifs[vifi];
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
for (g = v->uv_groups; g != NULL; g = g->al_next)
|
1995-06-13 18:05:16 +00:00
|
|
|
if (mcastgrp == g->al_addr)
|
1994-09-08 00:26:13 +00:00
|
|
|
return 1;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* Finds the group entry with the specified source and netmask.
|
|
|
|
* If netmask is 0, it uses the route's netmask.
|
|
|
|
*
|
|
|
|
* Returns TRUE if found a match, and the global variable gtp is left
|
|
|
|
* pointing to entry before the found entry.
|
|
|
|
* Returns FALSE if no exact match found, gtp is left pointing to before
|
|
|
|
* the entry in question belongs, or is NULL if the it belongs at the
|
|
|
|
* head of the list.
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
int
|
|
|
|
find_src_grp(src, mask, grp)
|
|
|
|
u_int32 src;
|
|
|
|
u_int32 mask;
|
|
|
|
u_int32 grp;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct gtable *gt;
|
|
|
|
|
|
|
|
gtp = NULL;
|
|
|
|
gt = kernel_table;
|
|
|
|
while (gt != NULL) {
|
|
|
|
if (grp == gt->gt_mcastgrp &&
|
|
|
|
(mask ? (gt->gt_route->rt_origin == src &&
|
|
|
|
gt->gt_route->rt_originmask == mask) :
|
|
|
|
((src & gt->gt_route->rt_originmask) ==
|
|
|
|
gt->gt_route->rt_origin)))
|
|
|
|
return TRUE;
|
|
|
|
if (ntohl(grp) > ntohl(gt->gt_mcastgrp) ||
|
|
|
|
(grp == gt->gt_mcastgrp &&
|
|
|
|
(ntohl(mask) < ntohl(gt->gt_route->rt_originmask) ||
|
|
|
|
(mask == gt->gt_route->rt_originmask &&
|
|
|
|
(ntohl(src) > ntohl(gt->gt_route->rt_origin)))))) {
|
|
|
|
gtp = gt;
|
|
|
|
gt = gt->gt_gnext;
|
|
|
|
}
|
|
|
|
else break;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
return FALSE;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* Check if the neighbor supports pruning
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
static int
|
|
|
|
pruning_neighbor(vifi, addr)
|
|
|
|
vifi_t vifi;
|
|
|
|
u_int32 addr;
|
|
|
|
{
|
|
|
|
struct listaddr *n = neighbor_info(vifi, addr);
|
|
|
|
int vers;
|
1995-06-28 17:58:49 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (n == NULL)
|
|
|
|
return 0;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (n->al_flags & NF_PRUNE)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Versions from 3.0 to 3.4 relied on the version number to identify
|
|
|
|
* that they could handle pruning.
|
|
|
|
*/
|
|
|
|
vers = NBR_VERS(n);
|
|
|
|
return (vers >= 0x0300 && vers <= 0x0304);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can the neighbor in question handle multicast traceroute?
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
can_mtrace(vifi, addr)
|
1995-06-28 17:58:49 +00:00
|
|
|
vifi_t vifi;
|
|
|
|
u_int32 addr;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct listaddr *n = neighbor_info(vifi, addr);
|
|
|
|
int vers;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (n == NULL)
|
|
|
|
return 0;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (n->al_flags & NF_MTRACE)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Versions 3.3 and 3.4 relied on the version number to identify
|
|
|
|
* that they could handle traceroute.
|
|
|
|
*/
|
|
|
|
vers = NBR_VERS(n);
|
|
|
|
return (vers >= 0x0303 && vers <= 0x0304);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* Returns the prune entry of the router, or NULL if none exists
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
static struct ptable *
|
|
|
|
find_prune_entry(vr, pt)
|
|
|
|
u_int32 vr;
|
|
|
|
struct ptable *pt;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
while (pt) {
|
|
|
|
if (pt->pt_router == vr)
|
|
|
|
return pt;
|
|
|
|
pt = pt->pt_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a prune message to the dominant router for
|
|
|
|
* this source.
|
|
|
|
*
|
|
|
|
* Record an entry that a prune was sent for this group
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
send_prune(gt)
|
|
|
|
struct gtable *gt;
|
|
|
|
{
|
|
|
|
struct ptable *pt;
|
|
|
|
char *p;
|
1994-09-08 00:26:13 +00:00
|
|
|
int i;
|
1995-06-13 18:05:16 +00:00
|
|
|
int datalen;
|
|
|
|
u_int32 src;
|
|
|
|
u_int32 dst;
|
|
|
|
u_int32 tmp;
|
|
|
|
|
|
|
|
/* Don't process any prunes if router is not pruning */
|
|
|
|
if (pruning == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Can't process a prune if we don't have an associated route */
|
|
|
|
if (gt->gt_route == NULL)
|
|
|
|
return;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* Don't send a prune to a non-pruning router */
|
|
|
|
if (!pruning_neighbor(gt->gt_route->rt_parent, gt->gt_route->rt_gateway))
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sends a prune message to the router upstream.
|
|
|
|
*/
|
|
|
|
src = uvifs[gt->gt_route->rt_parent].uv_lcl_addr;
|
|
|
|
dst = gt->gt_route->rt_gateway;
|
|
|
|
|
|
|
|
p = send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN;
|
|
|
|
datalen = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* determine prune lifetime
|
|
|
|
*/
|
|
|
|
gt->gt_prsent_timer = gt->gt_timer;
|
|
|
|
for (pt = gt->gt_pruntbl; pt; pt = pt->pt_next)
|
|
|
|
if (pt->pt_timer < gt->gt_prsent_timer)
|
|
|
|
gt->gt_prsent_timer = pt->pt_timer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a graft pending, cancel graft retransmission
|
|
|
|
*/
|
|
|
|
gt->gt_grftsnt = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
*p++ = ((char *)&(gt->gt_route->rt_origin))[i];
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
*p++ = ((char *)&(gt->gt_mcastgrp))[i];
|
|
|
|
tmp = htonl(gt->gt_prsent_timer);
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
*p++ = ((char *)&(tmp))[i];
|
|
|
|
datalen += 12;
|
|
|
|
|
|
|
|
send_igmp(src, dst, IGMP_DVMRP, DVMRP_PRUNE,
|
|
|
|
htonl(MROUTED_LEVEL), datalen);
|
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "sent prune for (%s %s)/%d on vif %d to %s",
|
|
|
|
inet_fmts(gt->gt_route->rt_origin, gt->gt_route->rt_originmask, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2),
|
|
|
|
gt->gt_prsent_timer, gt->gt_route->rt_parent,
|
|
|
|
inet_fmt(gt->gt_route->rt_gateway, s3));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* a prune was sent upstream
|
|
|
|
* so, a graft has to be sent to annul the prune
|
|
|
|
* set up a graft timer so that if an ack is not
|
|
|
|
* heard within that time, another graft request
|
|
|
|
* is sent out.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
send_graft(gt)
|
|
|
|
struct gtable *gt;
|
|
|
|
{
|
|
|
|
register char *p;
|
|
|
|
register int i;
|
|
|
|
int datalen;
|
|
|
|
u_int32 src;
|
|
|
|
u_int32 dst;
|
|
|
|
|
|
|
|
/* Can't send a graft without an associated route */
|
|
|
|
if (gt->gt_route == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
src = uvifs[gt->gt_route->rt_parent].uv_lcl_addr;
|
|
|
|
dst = gt->gt_route->rt_gateway;
|
|
|
|
|
|
|
|
p = send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN;
|
|
|
|
datalen = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
*p++ = ((char *)&(gt->gt_route->rt_origin))[i];
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
*p++ = ((char *)&(gt->gt_mcastgrp))[i];
|
|
|
|
datalen += 8;
|
|
|
|
|
|
|
|
if (datalen != 0) {
|
|
|
|
send_igmp(src, dst, IGMP_DVMRP, DVMRP_GRAFT,
|
|
|
|
htonl(MROUTED_LEVEL), datalen);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "sent graft for (%s %s) to %s on vif %d",
|
|
|
|
inet_fmts(gt->gt_route->rt_origin, gt->gt_route->rt_originmask, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2),
|
|
|
|
inet_fmt(gt->gt_route->rt_gateway, s3), gt->gt_route->rt_parent);
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
|
|
|
* Send an ack that a graft was received
|
|
|
|
*/
|
1995-06-28 17:58:49 +00:00
|
|
|
static void
|
1995-06-13 18:05:16 +00:00
|
|
|
send_graft_ack(src, dst, origin, grp)
|
|
|
|
u_int32 src;
|
|
|
|
u_int32 dst;
|
|
|
|
u_int32 origin;
|
|
|
|
u_int32 grp;
|
|
|
|
{
|
|
|
|
register char *p;
|
|
|
|
register int i;
|
|
|
|
int datalen;
|
1995-06-28 17:58:49 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
p = send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN;
|
|
|
|
datalen = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
*p++ = ((char *)&(origin))[i];
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
*p++ = ((char *)&(grp))[i];
|
|
|
|
datalen += 8;
|
|
|
|
|
|
|
|
send_igmp(src, dst, IGMP_DVMRP, DVMRP_GRAFT_ACK,
|
|
|
|
htonl(MROUTED_LEVEL), datalen);
|
1995-06-28 17:58:49 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "sent graft ack for (%s, %s) to %s",
|
|
|
|
inet_fmt(origin, s1), inet_fmt(grp, s2), inet_fmt(dst, s3));
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
|
|
|
* Update the kernel cache with all the routes hanging off the group entry
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_kernel(g)
|
|
|
|
struct gtable *g;
|
|
|
|
{
|
|
|
|
struct stable *st;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
for (st = g->gt_srctbl; st; st = st->st_next)
|
|
|
|
k_add_rg(st->st_origin, g);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Functions that are used externally
|
|
|
|
****************************************************************************/
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
#ifdef SNMP
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include "snmp.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a specific group entry in the group table
|
|
|
|
*/
|
|
|
|
struct gtable *
|
|
|
|
find_grp(grp)
|
|
|
|
u_long grp;
|
|
|
|
{
|
|
|
|
struct gtable *gt;
|
|
|
|
|
|
|
|
for (gt = kernel_table; gt; gt = gt->gt_gnext) {
|
|
|
|
if (ntohl(grp) < ntohl(gt->gt_mcastgrp))
|
|
|
|
break;
|
|
|
|
if (gt->gt_mcastgrp == grp)
|
|
|
|
return gt;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a group entry and source, find the corresponding source table
|
|
|
|
* entry
|
|
|
|
*/
|
|
|
|
struct stable *
|
|
|
|
find_grp_src(gt, src)
|
|
|
|
struct gtable *gt;
|
|
|
|
u_long src;
|
|
|
|
{
|
|
|
|
struct stable *st;
|
|
|
|
u_long grp = gt->gt_mcastgrp;
|
|
|
|
struct gtable *gtcurr;
|
|
|
|
|
|
|
|
for (gtcurr = gt; gtcurr->gt_mcastgrp == grp; gtcurr = gtcurr->gt_gnext) {
|
|
|
|
for (st = gtcurr->gt_srctbl; st; st = st->st_next)
|
|
|
|
if (st->st_origin == src)
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find next entry > specification
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
next_grp_src_mask(gtpp, stpp, grp, src, mask)
|
|
|
|
struct gtable **gtpp; /* ordered by group */
|
|
|
|
struct stable **stpp; /* ordered by source */
|
|
|
|
u_long grp;
|
|
|
|
u_long src;
|
|
|
|
u_long mask;
|
|
|
|
{
|
|
|
|
struct gtable *gt, *gbest = NULL;
|
|
|
|
struct stable *st, *sbest = NULL;
|
|
|
|
|
|
|
|
/* Find first group entry >= grp spec */
|
|
|
|
(*gtpp) = kernel_table;
|
|
|
|
while ((*gtpp) && ntohl((*gtpp)->gt_mcastgrp) < ntohl(grp))
|
|
|
|
(*gtpp)=(*gtpp)->gt_gnext;
|
|
|
|
if (!(*gtpp))
|
|
|
|
return 0; /* no more groups */
|
|
|
|
|
|
|
|
for (gt = kernel_table; gt; gt=gt->gt_gnext) {
|
|
|
|
/* Since grps are ordered, we can stop when group changes from gbest */
|
|
|
|
if (gbest && gbest->gt_mcastgrp != gt->gt_mcastgrp)
|
|
|
|
break;
|
|
|
|
for (st = gt->gt_srctbl; st; st=st->st_next) {
|
|
|
|
|
|
|
|
/* Among those entries > spec, find "lowest" one */
|
|
|
|
if (((ntohl(gt->gt_mcastgrp)> ntohl(grp))
|
|
|
|
|| (ntohl(gt->gt_mcastgrp)==ntohl(grp)
|
|
|
|
&& ntohl(st->st_origin)> ntohl(src))
|
|
|
|
|| (ntohl(gt->gt_mcastgrp)==ntohl(grp)
|
|
|
|
&& ntohl(st->st_origin)==src && 0xFFFFFFFF>ntohl(mask)))
|
|
|
|
&& (!gbest
|
|
|
|
|| (ntohl(gt->gt_mcastgrp)< ntohl(gbest->gt_mcastgrp))
|
|
|
|
|| (ntohl(gt->gt_mcastgrp)==ntohl(gbest->gt_mcastgrp)
|
|
|
|
&& ntohl(st->st_origin)< ntohl(sbest->st_origin)))) {
|
|
|
|
gbest = gt;
|
|
|
|
sbest = st;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(*gtpp) = gbest;
|
|
|
|
(*stpp) = sbest;
|
|
|
|
return (*gtpp)!=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure that sg contains current information for the given group,source.
|
|
|
|
* This is fetched from the kernel as a unit so that counts for the entry
|
|
|
|
* are consistent, i.e. packet and byte counts for the same entry are
|
|
|
|
* read at the same time.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
refresh_sg(sg, gt, st)
|
|
|
|
struct sioc_sg_req *sg;
|
|
|
|
struct gtable *gt;
|
|
|
|
struct stable *st;
|
|
|
|
{
|
|
|
|
static int lastq = -1;
|
|
|
|
|
|
|
|
if (quantum != lastq || sg->src.s_addr!=st->st_origin
|
|
|
|
|| sg->grp.s_addr!=gt->gt_mcastgrp) {
|
|
|
|
lastq = quantum;
|
|
|
|
sg->src.s_addr = st->st_origin;
|
|
|
|
sg->grp.s_addr = gt->gt_mcastgrp;
|
|
|
|
ioctl(udp_socket, SIOCGETSGCNT, (char *)sg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return pointer to a specific route entry. This must be a separate
|
|
|
|
* function from find_route() which modifies rtp.
|
|
|
|
*/
|
|
|
|
struct rtentry *
|
|
|
|
snmp_find_route(src, mask)
|
|
|
|
register u_long src, mask;
|
|
|
|
{
|
|
|
|
register struct rtentry *rt;
|
|
|
|
|
|
|
|
for (rt = routing_table; rt; rt = rt->rt_next) {
|
|
|
|
if (src == rt->rt_origin && mask == rt->rt_originmask)
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find next route entry > specification
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
next_route(rtpp, src, mask)
|
|
|
|
struct rtentry **rtpp;
|
|
|
|
u_long src;
|
|
|
|
u_long mask;
|
|
|
|
{
|
|
|
|
struct rtentry *rt, *rbest = NULL;
|
|
|
|
|
|
|
|
/* Among all entries > spec, find "lowest" one in order */
|
|
|
|
for (rt = routing_table; rt; rt=rt->rt_next) {
|
|
|
|
if ((ntohl(rt->rt_origin) > ntohl(src)
|
|
|
|
|| (ntohl(rt->rt_origin) == ntohl(src)
|
|
|
|
&& ntohl(rt->rt_originmask) > ntohl(mask)))
|
|
|
|
&& (!rbest || (ntohl(rt->rt_origin) < ntohl(rbest->rt_origin))
|
|
|
|
|| (ntohl(rt->rt_origin) == ntohl(rbest->rt_origin)
|
|
|
|
&& ntohl(rt->rt_originmask) < ntohl(rbest->rt_originmask))))
|
|
|
|
rbest = rt;
|
|
|
|
}
|
|
|
|
(*rtpp) = rbest;
|
|
|
|
return (*rtpp)!=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a routing table entry, and a vifi, find the next vifi/entry
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
next_route_child(rtpp, src, mask, vifi)
|
|
|
|
struct rtentry **rtpp;
|
|
|
|
u_long src;
|
|
|
|
u_long mask;
|
|
|
|
vifi_t *vifi; /* vif at which to start looking */
|
|
|
|
{
|
|
|
|
struct rtentry *rt;
|
|
|
|
|
|
|
|
/* Get (S,M) entry */
|
|
|
|
if (!((*rtpp) = snmp_find_route(src,mask)))
|
|
|
|
if (!next_route(rtpp, src, mask))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Continue until we get one with a valid next vif */
|
|
|
|
do {
|
|
|
|
for (; (*rtpp)->rt_children && *vifi<numvifs; (*vifi)++)
|
|
|
|
if (VIFM_ISSET(*vifi, (*rtpp)->rt_children))
|
|
|
|
return 1;
|
|
|
|
*vifi = 0;
|
|
|
|
} while( next_route(rtpp, (*rtpp)->rt_origin, (*rtpp)->rt_originmask) );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a routing table entry, and a vifi, find the next entry
|
|
|
|
* equal to or greater than those
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
next_child(gtpp, stpp, grp, src, mask, vifi)
|
|
|
|
struct gtable **gtpp;
|
|
|
|
struct stable **stpp;
|
|
|
|
u_long grp;
|
|
|
|
u_long src;
|
|
|
|
u_long mask;
|
|
|
|
vifi_t *vifi; /* vif at which to start looking */
|
|
|
|
{
|
|
|
|
struct stable *st;
|
|
|
|
|
|
|
|
/* Get (G,S,M) entry */
|
|
|
|
if (mask!=0xFFFFFFFF
|
|
|
|
|| !((*gtpp) = find_grp(grp))
|
|
|
|
|| !((*stpp) = find_grp_src((*gtpp),src)))
|
|
|
|
if (!next_grp_src_mask(gtpp, stpp, grp, src, mask))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Continue until we get one with a valid next vif */
|
|
|
|
do {
|
|
|
|
for (; (*gtpp)->gt_route->rt_children && *vifi<numvifs; (*vifi)++)
|
|
|
|
if (VIFM_ISSET(*vifi, (*gtpp)->gt_route->rt_children))
|
|
|
|
return 1;
|
|
|
|
*vifi = 0;
|
|
|
|
} while (next_grp_src_mask(gtpp, stpp, (*gtpp)->gt_mcastgrp,
|
|
|
|
(*stpp)->st_origin, 0xFFFFFFFF) );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* SNMP */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the kernel table structure
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
init_ktable()
|
|
|
|
{
|
|
|
|
kernel_table = NULL;
|
|
|
|
kernel_no_route = NULL;
|
|
|
|
kroutes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new table entry for (origin, mcastgrp)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
add_table_entry(origin, mcastgrp)
|
|
|
|
u_int32 origin;
|
|
|
|
u_int32 mcastgrp;
|
|
|
|
{
|
|
|
|
struct rtentry *r;
|
|
|
|
struct gtable *gt,**gtnp,*prev_gt;
|
|
|
|
struct stable *st,**stnp;
|
1996-01-06 21:10:30 +00:00
|
|
|
vifi_t i;
|
|
|
|
|
|
|
|
#ifdef DEBUG_MFC
|
|
|
|
md_log(MD_MISS, origin, mcastgrp);
|
|
|
|
#endif
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
r = determine_route(origin);
|
|
|
|
prev_gt = NULL;
|
1994-09-08 00:26:13 +00:00
|
|
|
if (r == NULL) {
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
|
|
|
* Look for it on the no_route table; if it is found then
|
|
|
|
* it will be detected as a duplicate below.
|
|
|
|
*/
|
|
|
|
for (gt = kernel_no_route; gt; gt = gt->gt_next)
|
|
|
|
if (mcastgrp == gt->gt_mcastgrp &&
|
|
|
|
gt->gt_srctbl && gt->gt_srctbl->st_origin == origin)
|
|
|
|
break;
|
|
|
|
gtnp = &kernel_no_route;
|
|
|
|
} else {
|
|
|
|
gtnp = &r->rt_groups;
|
|
|
|
while ((gt = *gtnp) != NULL) {
|
1995-06-28 17:58:49 +00:00
|
|
|
if (gt->gt_mcastgrp >= mcastgrp)
|
|
|
|
break;
|
1995-06-13 18:05:16 +00:00
|
|
|
gtnp = >->gt_next;
|
|
|
|
prev_gt = gt;
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (gt == NULL || gt->gt_mcastgrp != mcastgrp) {
|
|
|
|
gt = (struct gtable *)malloc(sizeof(struct gtable));
|
|
|
|
if (gt == NULL)
|
|
|
|
log(LOG_ERR, 0, "ran out of memory");
|
|
|
|
|
|
|
|
gt->gt_mcastgrp = mcastgrp;
|
|
|
|
gt->gt_timer = CACHE_LIFETIME(cache_lifetime);
|
|
|
|
time(>->gt_ctime);
|
|
|
|
gt->gt_grpmems = 0;
|
|
|
|
gt->gt_scope = 0;
|
|
|
|
gt->gt_prsent_timer = 0;
|
|
|
|
gt->gt_grftsnt = 0;
|
|
|
|
gt->gt_srctbl = NULL;
|
|
|
|
gt->gt_pruntbl = NULL;
|
|
|
|
gt->gt_route = r;
|
1995-06-28 17:58:49 +00:00
|
|
|
#ifdef RSRR
|
1995-06-13 18:05:16 +00:00
|
|
|
gt->gt_rsrr_cache = NULL;
|
1995-06-28 17:58:49 +00:00
|
|
|
#endif
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
if (r != NULL) {
|
1995-06-28 17:58:49 +00:00
|
|
|
/* obtain the multicast group membership list */
|
|
|
|
for (i = 0; i < numvifs; i++) {
|
|
|
|
if (VIFM_ISSET(i, r->rt_children) &&
|
|
|
|
!(VIFM_ISSET(i, r->rt_leaves)))
|
|
|
|
VIFM_SET(i, gt->gt_grpmems);
|
|
|
|
|
|
|
|
if (VIFM_ISSET(i, r->rt_leaves) && grplst_mem(i, mcastgrp))
|
|
|
|
VIFM_SET(i, gt->gt_grpmems);
|
|
|
|
}
|
|
|
|
GET_SCOPE(gt);
|
|
|
|
if (VIFM_ISSET(r->rt_parent, gt->gt_scope))
|
|
|
|
gt->gt_scope = -1;
|
|
|
|
gt->gt_grpmems &= ~gt->gt_scope;
|
1995-06-13 18:05:16 +00:00
|
|
|
} else {
|
|
|
|
gt->gt_scope = -1;
|
|
|
|
gt->gt_grpmems = 0;
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* update ttls */
|
|
|
|
prun_add_ttls(gt);
|
|
|
|
|
|
|
|
gt->gt_next = *gtnp;
|
|
|
|
*gtnp = gt;
|
|
|
|
if (gt->gt_next)
|
|
|
|
gt->gt_next->gt_prev = gt;
|
1995-06-28 17:58:49 +00:00
|
|
|
gt->gt_prev = prev_gt;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
if (r) {
|
1995-06-28 17:58:49 +00:00
|
|
|
if (find_src_grp(r->rt_origin, r->rt_originmask, gt->gt_mcastgrp)) {
|
|
|
|
struct gtable *g;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
g = gtp ? gtp->gt_gnext : kernel_table;
|
|
|
|
log(LOG_WARNING, 0, "Entry for (%s %s) (rt:%x) exists (rt:%x)",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2),
|
|
|
|
r, g->gt_route);
|
1995-06-13 18:05:16 +00:00
|
|
|
} else {
|
1995-06-28 17:58:49 +00:00
|
|
|
if (gtp) {
|
|
|
|
gt->gt_gnext = gtp->gt_gnext;
|
|
|
|
gt->gt_gprev = gtp;
|
|
|
|
gtp->gt_gnext = gt;
|
|
|
|
} else {
|
|
|
|
gt->gt_gnext = kernel_table;
|
|
|
|
gt->gt_gprev = NULL;
|
|
|
|
kernel_table = gt;
|
|
|
|
}
|
|
|
|
if (gt->gt_gnext)
|
|
|
|
gt->gt_gnext->gt_gprev = gt;
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
1996-01-06 21:10:30 +00:00
|
|
|
gt->gt_gnext = gt->gt_gprev = NULL;
|
1995-05-16 00:28:50 +00:00
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
stnp = >->gt_srctbl;
|
|
|
|
while ((st = *stnp) != NULL) {
|
|
|
|
if (ntohl(st->st_origin) >= ntohl(origin))
|
|
|
|
break;
|
|
|
|
stnp = &st->st_next;
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (st == NULL || st->st_origin != origin) {
|
|
|
|
st = (struct stable *)malloc(sizeof(struct stable));
|
|
|
|
if (st == NULL)
|
|
|
|
log(LOG_ERR, 0, "ran out of memory");
|
|
|
|
|
|
|
|
st->st_origin = origin;
|
|
|
|
st->st_pktcnt = 0;
|
|
|
|
st->st_next = *stnp;
|
|
|
|
*stnp = st;
|
|
|
|
} else {
|
1996-01-06 21:10:30 +00:00
|
|
|
#ifdef DEBUG_MFC
|
|
|
|
md_log(MD_DUPE, origin, mcastgrp);
|
|
|
|
#endif
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_WARNING, 0, "kernel entry already exists for (%s %s)",
|
|
|
|
inet_fmt(origin, s1), inet_fmt(mcastgrp, s2));
|
1996-01-06 21:10:30 +00:00
|
|
|
/* XXX Doing this should cause no harm, and may ensure
|
|
|
|
* kernel<>mrouted synchronization */
|
|
|
|
k_add_rg(origin, gt);
|
1995-06-13 18:05:16 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
kroutes++;
|
|
|
|
k_add_rg(origin, gt);
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "add cache entry (%s %s) gm:%x, parent-vif:%d",
|
|
|
|
inet_fmt(origin, s1),
|
|
|
|
inet_fmt(mcastgrp, s2),
|
|
|
|
gt->gt_grpmems, r ? r->rt_parent : -1);
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/* If there are no leaf vifs
|
|
|
|
* which have this group, then
|
1995-06-13 18:05:16 +00:00
|
|
|
* mark this src-grp as a prune candidate.
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
if (!gt->gt_prsent_timer && !gt->gt_grpmems && r && r->rt_gateway)
|
|
|
|
send_prune(gt);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An mrouter has gone down and come up on an interface
|
|
|
|
* Forward on that interface immediately
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
reset_neighbor_state(vifi, addr)
|
1994-09-08 00:26:13 +00:00
|
|
|
vifi_t vifi;
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 addr;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct rtentry *r;
|
|
|
|
struct gtable *g;
|
1996-01-06 21:10:30 +00:00
|
|
|
struct ptable *pt, **ptnp;
|
|
|
|
struct stable *st;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
for (g = kernel_table; g; g = g->gt_gnext) {
|
|
|
|
r = g->gt_route;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If neighbor was the parent, remove the prune sent state
|
1996-01-06 21:10:30 +00:00
|
|
|
* and all of the source cache info so that prunes get
|
|
|
|
* regenerated.
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
if (vifi == r->rt_parent) {
|
|
|
|
if (addr == r->rt_gateway) {
|
1996-01-06 21:10:30 +00:00
|
|
|
log(LOG_DEBUG, 0, "reset_neighbor_state parent reset (%s %s)",
|
1995-06-13 18:05:16 +00:00
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2));
|
|
|
|
|
|
|
|
g->gt_prsent_timer = 0;
|
|
|
|
g->gt_grftsnt = 0;
|
1997-09-30 06:15:23 +00:00
|
|
|
while ((st = g->gt_srctbl)) {
|
1996-01-06 21:10:30 +00:00
|
|
|
g->gt_srctbl = st->st_next;
|
|
|
|
k_del_rg(st->st_origin, g);
|
|
|
|
kroutes--;
|
|
|
|
free(st);
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Neighbor was not the parent, send grafts to join the groups
|
|
|
|
*/
|
|
|
|
if (g->gt_prsent_timer) {
|
|
|
|
g->gt_grftsnt = 1;
|
|
|
|
send_graft(g);
|
|
|
|
g->gt_prsent_timer = 0;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
|
|
|
* Remove any prunes that this router has sent us.
|
|
|
|
*/
|
1996-01-06 21:10:30 +00:00
|
|
|
ptnp = &g->gt_pruntbl;
|
|
|
|
while ((pt = *ptnp) != NULL) {
|
1995-06-13 18:05:16 +00:00
|
|
|
if (pt->pt_vifi == vifi && pt->pt_router == addr) {
|
1996-01-06 21:10:30 +00:00
|
|
|
*ptnp = pt->pt_next;
|
1995-06-13 18:05:16 +00:00
|
|
|
free(pt);
|
|
|
|
} else
|
1996-01-06 21:10:30 +00:00
|
|
|
ptnp = &pt->pt_next;
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
|
|
|
* And see if we want to forward again.
|
|
|
|
*/
|
|
|
|
if (!VIFM_ISSET(vifi, g->gt_grpmems)) {
|
|
|
|
if (VIFM_ISSET(vifi, r->rt_children) &&
|
|
|
|
!(VIFM_ISSET(vifi, r->rt_leaves)))
|
|
|
|
VIFM_SET(vifi, g->gt_grpmems);
|
|
|
|
|
|
|
|
if (VIFM_ISSET(vifi, r->rt_leaves) &&
|
|
|
|
grplst_mem(vifi, g->gt_mcastgrp))
|
|
|
|
VIFM_SET(vifi, g->gt_grpmems);
|
|
|
|
|
|
|
|
g->gt_grpmems &= ~g->gt_scope;
|
|
|
|
prun_add_ttls(g);
|
|
|
|
|
|
|
|
/* Update kernel state */
|
|
|
|
update_kernel(g);
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(g,1);
|
|
|
|
#endif /* RSRR */
|
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "reset member state (%s %s) gm:%x",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete table entry from the kernel
|
|
|
|
* del_flag determines how many entries to delete
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
del_table_entry(r, mcastgrp, del_flag)
|
1994-09-08 00:26:13 +00:00
|
|
|
struct rtentry *r;
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 mcastgrp;
|
1994-09-08 00:26:13 +00:00
|
|
|
u_int del_flag;
|
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct gtable *g, *prev_g;
|
|
|
|
struct stable *st, *prev_st;
|
|
|
|
struct ptable *pt, *prev_pt;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
if (del_flag == DEL_ALL_ROUTES) {
|
1995-06-13 18:05:16 +00:00
|
|
|
g = r->rt_groups;
|
|
|
|
while (g) {
|
|
|
|
log(LOG_DEBUG, 0, "del_table_entry deleting (%s %s)",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2));
|
|
|
|
st = g->gt_srctbl;
|
|
|
|
while (st) {
|
|
|
|
if (k_del_rg(st->st_origin, g) < 0) {
|
|
|
|
log(LOG_WARNING, errno,
|
|
|
|
"del_table_entry trying to delete (%s, %s)",
|
|
|
|
inet_fmt(st->st_origin, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2));
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
kroutes--;
|
1995-06-13 18:05:16 +00:00
|
|
|
prev_st = st;
|
|
|
|
st = st->st_next;
|
|
|
|
free(prev_st);
|
|
|
|
}
|
|
|
|
g->gt_srctbl = NULL;
|
|
|
|
|
|
|
|
pt = g->gt_pruntbl;
|
|
|
|
while (pt) {
|
1996-01-06 21:10:30 +00:00
|
|
|
prev_pt = pt;
|
|
|
|
pt = pt->pt_next;
|
|
|
|
free(prev_pt);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
g->gt_pruntbl = NULL;
|
|
|
|
|
|
|
|
if (g->gt_gnext)
|
|
|
|
g->gt_gnext->gt_gprev = g->gt_gprev;
|
|
|
|
if (g->gt_gprev)
|
|
|
|
g->gt_gprev->gt_gnext = g->gt_gnext;
|
|
|
|
else
|
|
|
|
kernel_table = g->gt_gnext;
|
|
|
|
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(g,0);
|
|
|
|
rsrr_cache_clean(g);
|
|
|
|
#endif /* RSRR */
|
1996-01-06 21:10:30 +00:00
|
|
|
prev_g = g;
|
|
|
|
g = g->gt_next;
|
|
|
|
free(prev_g);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
r->rt_groups = NULL;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dummy routine - someday this may be needed, so it is just there
|
|
|
|
*/
|
1994-09-08 00:26:13 +00:00
|
|
|
if (del_flag == DEL_RTE_GROUP) {
|
1995-06-13 18:05:16 +00:00
|
|
|
prev_g = (struct gtable *)&r->rt_groups;
|
|
|
|
for (g = r->rt_groups; g; g = g->gt_next) {
|
|
|
|
if (g->gt_mcastgrp == mcastgrp) {
|
|
|
|
log(LOG_DEBUG, 0, "del_table_entry deleting (%s %s)",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2));
|
|
|
|
st = g->gt_srctbl;
|
|
|
|
while (st) {
|
|
|
|
if (k_del_rg(st->st_origin, g) < 0) {
|
|
|
|
log(LOG_WARNING, errno,
|
|
|
|
"del_table_entry trying to delete (%s, %s)",
|
|
|
|
inet_fmt(st->st_origin, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2));
|
|
|
|
}
|
|
|
|
kroutes--;
|
1996-01-06 21:10:30 +00:00
|
|
|
prev_st = st;
|
|
|
|
st = st->st_next;
|
|
|
|
free(prev_st);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
g->gt_srctbl = NULL;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
pt = g->gt_pruntbl;
|
|
|
|
while (pt) {
|
1996-01-06 21:10:30 +00:00
|
|
|
prev_pt = pt;
|
|
|
|
pt = pt->pt_next;
|
|
|
|
free(prev_pt);
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
|
|
|
g->gt_pruntbl = NULL;
|
|
|
|
|
|
|
|
if (g->gt_gnext)
|
|
|
|
g->gt_gnext->gt_gprev = g->gt_gprev;
|
|
|
|
if (g->gt_gprev)
|
|
|
|
g->gt_gprev->gt_gnext = g->gt_gnext;
|
|
|
|
else
|
|
|
|
kernel_table = g->gt_gnext;
|
|
|
|
|
|
|
|
if (prev_g != (struct gtable *)&r->rt_groups)
|
|
|
|
g->gt_next->gt_prev = prev_g;
|
|
|
|
else
|
|
|
|
g->gt_next->gt_prev = NULL;
|
|
|
|
prev_g->gt_next = g->gt_next;
|
|
|
|
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(g,0);
|
|
|
|
rsrr_cache_clean(g);
|
|
|
|
#endif /* RSRR */
|
|
|
|
free(g);
|
|
|
|
g = prev_g;
|
|
|
|
} else {
|
|
|
|
prev_g = g;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* update kernel table entry when a route entry changes
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
update_table_entry(r)
|
1994-09-08 00:26:13 +00:00
|
|
|
struct rtentry *r;
|
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct gtable *g;
|
|
|
|
struct ptable *pt, *prev_pt;
|
1996-01-06 21:10:30 +00:00
|
|
|
vifi_t i;
|
1995-06-28 17:58:49 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
for (g = r->rt_groups; g; g = g->gt_next) {
|
|
|
|
pt = g->gt_pruntbl;
|
|
|
|
while (pt) {
|
|
|
|
prev_pt = pt->pt_next;
|
|
|
|
free(pt);
|
|
|
|
pt = prev_pt;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
g->gt_pruntbl = NULL;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
g->gt_grpmems = 0;
|
1995-06-28 17:58:49 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* obtain the multicast group membership list */
|
|
|
|
for (i = 0; i < numvifs; i++) {
|
|
|
|
if (VIFM_ISSET(i, r->rt_children) &&
|
|
|
|
!(VIFM_ISSET(i, r->rt_leaves)))
|
|
|
|
VIFM_SET(i, g->gt_grpmems);
|
|
|
|
|
|
|
|
if (VIFM_ISSET(i, r->rt_leaves) && grplst_mem(i, g->gt_mcastgrp))
|
|
|
|
VIFM_SET(i, g->gt_grpmems);
|
|
|
|
}
|
|
|
|
if (VIFM_ISSET(r->rt_parent, g->gt_scope))
|
|
|
|
g->gt_scope = -1;
|
|
|
|
g->gt_grpmems &= ~g->gt_scope;
|
1995-06-28 17:58:49 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "updating cache entries (%s %s) gm:%x",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2),
|
|
|
|
g->gt_grpmems);
|
1995-06-28 17:58:49 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (g->gt_grpmems && g->gt_prsent_timer) {
|
|
|
|
g->gt_grftsnt = 1;
|
|
|
|
send_graft(g);
|
|
|
|
g->gt_prsent_timer = 0;
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* update ttls and add entry into kernel */
|
|
|
|
prun_add_ttls(g);
|
|
|
|
update_kernel(g);
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(g,1);
|
|
|
|
#endif /* RSRR */
|
1995-06-28 17:58:49 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* Check if we want to prune this group */
|
|
|
|
if (!g->gt_prsent_timer && g->gt_grpmems == 0 && r->rt_gateway) {
|
|
|
|
g->gt_timer = CACHE_LIFETIME(cache_lifetime);
|
|
|
|
send_prune(g);
|
1995-06-28 17:58:49 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* set the forwarding flag for all mcastgrps on this vifi
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
update_lclgrp(vifi, mcastgrp)
|
1994-09-08 00:26:13 +00:00
|
|
|
vifi_t vifi;
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 mcastgrp;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct rtentry *r;
|
|
|
|
struct gtable *g;
|
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "group %s joined on vif %d",
|
1995-05-16 00:28:50 +00:00
|
|
|
inet_fmt(mcastgrp, s1), vifi);
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
for (g = kernel_table; g; g = g->gt_gnext) {
|
|
|
|
if (ntohl(mcastgrp) < ntohl(g->gt_mcastgrp))
|
|
|
|
break;
|
|
|
|
|
|
|
|
r = g->gt_route;
|
|
|
|
if (g->gt_mcastgrp == mcastgrp &&
|
|
|
|
VIFM_ISSET(vifi, r->rt_children)) {
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
VIFM_SET(vifi, g->gt_grpmems);
|
|
|
|
g->gt_grpmems &= ~g->gt_scope;
|
|
|
|
if (g->gt_grpmems == 0)
|
1994-09-08 00:26:13 +00:00
|
|
|
continue;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
prun_add_ttls(g);
|
|
|
|
log(LOG_DEBUG, 0, "update lclgrp (%s %s) gm:%x",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
|
|
|
|
|
|
|
|
update_kernel(g);
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(g,1);
|
|
|
|
#endif /* RSRR */
|
1995-05-30 03:57:47 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reset forwarding flag for all mcastgrps on this vifi
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
delete_lclgrp(vifi, mcastgrp)
|
1994-09-08 00:26:13 +00:00
|
|
|
vifi_t vifi;
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 mcastgrp;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct rtentry *r;
|
|
|
|
struct gtable *g;
|
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "group %s left on vif %d",
|
1995-05-16 00:28:50 +00:00
|
|
|
inet_fmt(mcastgrp, s1), vifi);
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
for (g = kernel_table; g; g = g->gt_gnext) {
|
|
|
|
if (ntohl(mcastgrp) < ntohl(g->gt_mcastgrp))
|
|
|
|
break;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (g->gt_mcastgrp == mcastgrp) {
|
1995-05-16 00:28:50 +00:00
|
|
|
int stop_sending = 1;
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
r = g->gt_route;
|
|
|
|
/*
|
|
|
|
* If this is not a leaf, then we have router neighbors on this
|
|
|
|
* vif. Only turn off forwarding if they have all pruned.
|
|
|
|
*/
|
|
|
|
if (!VIFM_ISSET(vifi, r->rt_leaves)) {
|
|
|
|
struct listaddr *vr;
|
|
|
|
|
|
|
|
for (vr = uvifs[vifi].uv_neighbors; vr; vr = vr->al_next)
|
|
|
|
if (find_prune_entry(vr->al_addr, g->gt_pruntbl) == NULL) {
|
|
|
|
stop_sending = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1995-05-16 00:28:50 +00:00
|
|
|
|
|
|
|
if (stop_sending) {
|
1995-06-28 17:58:49 +00:00
|
|
|
VIFM_CLR(vifi, g->gt_grpmems);
|
|
|
|
log(LOG_DEBUG, 0, "delete lclgrp (%s %s) gm:%x",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
prun_add_ttls(g);
|
|
|
|
update_kernel(g);
|
1995-06-13 18:05:16 +00:00
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(g,1);
|
|
|
|
#endif /* RSRR */
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
/*
|
|
|
|
* If there are no more members of this particular group,
|
|
|
|
* send prune upstream
|
|
|
|
*/
|
|
|
|
if (!g->gt_prsent_timer && g->gt_grpmems == 0 && r->rt_gateway)
|
|
|
|
send_prune(g);
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Takes the prune message received and then strips it to
|
|
|
|
* determine the (src, grp) pair to be pruned.
|
|
|
|
*
|
|
|
|
* Adds the router to the (src, grp) entry then.
|
|
|
|
*
|
|
|
|
* Determines if further packets have to be sent down that vif
|
|
|
|
*
|
|
|
|
* Determines if a corresponding prune message has to be generated
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
accept_prune(src, dst, p, datalen)
|
|
|
|
u_int32 src;
|
|
|
|
u_int32 dst;
|
1994-09-08 00:26:13 +00:00
|
|
|
char *p;
|
|
|
|
int datalen;
|
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 prun_src;
|
|
|
|
u_int32 prun_grp;
|
|
|
|
u_int32 prun_tmr;
|
1994-09-08 00:26:13 +00:00
|
|
|
vifi_t vifi;
|
|
|
|
int i;
|
1995-06-13 18:05:16 +00:00
|
|
|
int stop_sending;
|
|
|
|
struct rtentry *r;
|
|
|
|
struct gtable *g;
|
|
|
|
struct ptable *pt;
|
1994-09-08 00:26:13 +00:00
|
|
|
struct listaddr *vr;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/* Don't process any prunes if router is not pruning */
|
|
|
|
if (pruning == 0)
|
|
|
|
return;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
if ((vifi = find_vif(src, dst)) == NO_VIF) {
|
|
|
|
log(LOG_INFO, 0,
|
1995-05-16 00:28:50 +00:00
|
|
|
"ignoring prune report from non-neighbor %s",
|
|
|
|
inet_fmt(src, s1));
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1995-05-16 00:28:50 +00:00
|
|
|
/* Check if enough data is present */
|
1995-06-13 18:05:16 +00:00
|
|
|
if (datalen < 12)
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_WARNING, 0,
|
|
|
|
"non-decipherable prune from %s",
|
|
|
|
inet_fmt(src, s1));
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i< 4; i++)
|
|
|
|
((char *)&prun_src)[i] = *p++;
|
|
|
|
for (i = 0; i< 4; i++)
|
|
|
|
((char *)&prun_grp)[i] = *p++;
|
|
|
|
for (i = 0; i< 4; i++)
|
|
|
|
((char *)&prun_tmr)[i] = *p++;
|
1995-06-16 16:57:20 +00:00
|
|
|
prun_tmr = ntohl(prun_tmr);
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "%s on vif %d prunes (%s %s)/%d",
|
|
|
|
inet_fmt(src, s1), vifi,
|
|
|
|
inet_fmt(prun_src, s2), inet_fmt(prun_grp, s3), prun_tmr);
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* Find the subnet for the prune
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
if (find_src_grp(prun_src, 0, prun_grp)) {
|
|
|
|
g = gtp ? gtp->gt_gnext : kernel_table;
|
|
|
|
r = g->gt_route;
|
|
|
|
|
|
|
|
if (!VIFM_ISSET(vifi, r->rt_children)) {
|
|
|
|
log(LOG_WARNING, 0, "prune received from non-child %s for (%s %s)",
|
|
|
|
inet_fmt(src, s1), inet_fmt(prun_src, s2),
|
|
|
|
inet_fmt(prun_grp, s3));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (VIFM_ISSET(vifi, g->gt_scope)) {
|
|
|
|
log(LOG_WARNING, 0, "prune received from %s on scoped grp (%s %s)",
|
|
|
|
inet_fmt(src, s1), inet_fmt(prun_src, s2),
|
|
|
|
inet_fmt(prun_grp, s3));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((pt = find_prune_entry(src, g->gt_pruntbl)) != NULL) {
|
1996-11-11 03:50:15 +00:00
|
|
|
log(LOG_DEBUG, 0, "%s %d from %s for (%s %s)/%d %s %d %s %x",
|
|
|
|
"duplicate prune received on vif",
|
|
|
|
vifi, inet_fmt(src, s1), inet_fmt(prun_src, s2),
|
|
|
|
inet_fmt(prun_grp, s3), prun_tmr,
|
|
|
|
"old timer:", pt->pt_timer, "cur gm:", g->gt_grpmems);
|
1995-06-13 18:05:16 +00:00
|
|
|
pt->pt_timer = prun_tmr;
|
|
|
|
} else {
|
|
|
|
/* allocate space for the prune structure */
|
|
|
|
pt = (struct ptable *)(malloc(sizeof(struct ptable)));
|
|
|
|
if (pt == NULL)
|
|
|
|
log(LOG_ERR, 0, "pt: ran out of memory");
|
|
|
|
|
|
|
|
pt->pt_vifi = vifi;
|
|
|
|
pt->pt_router = src;
|
|
|
|
pt->pt_timer = prun_tmr;
|
|
|
|
|
|
|
|
pt->pt_next = g->gt_pruntbl;
|
|
|
|
g->gt_pruntbl = pt;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* Refresh the group's lifetime */
|
|
|
|
g->gt_timer = CACHE_LIFETIME(cache_lifetime);
|
|
|
|
if (g->gt_timer < prun_tmr)
|
|
|
|
g->gt_timer = prun_tmr;
|
1996-01-06 21:10:30 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
|
|
|
* check if any more packets need to be sent on the
|
|
|
|
* vif which sent this message
|
|
|
|
*/
|
|
|
|
stop_sending = 1;
|
|
|
|
for (vr = uvifs[vifi].uv_neighbors; vr; vr = vr->al_next)
|
|
|
|
if (find_prune_entry(vr->al_addr, g->gt_pruntbl) == NULL) {
|
|
|
|
stop_sending = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stop_sending && !grplst_mem(vifi, prun_grp)) {
|
|
|
|
VIFM_CLR(vifi, g->gt_grpmems);
|
|
|
|
log(LOG_DEBUG, 0, "prune (%s %s), stop sending on vif %d, gm:%x",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2), vifi, g->gt_grpmems);
|
|
|
|
|
|
|
|
prun_add_ttls(g);
|
|
|
|
update_kernel(g);
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(g,1);
|
|
|
|
#endif /* RSRR */
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
|
|
|
* check if all the child routers have expressed no interest
|
|
|
|
* in this group and if this group does not exist in the
|
|
|
|
* interface
|
|
|
|
* Send a prune message then upstream
|
|
|
|
*/
|
|
|
|
if (!g->gt_prsent_timer && g->gt_grpmems == 0 && r->rt_gateway) {
|
|
|
|
send_prune(g);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* There is no kernel entry for this group. Therefore, we can
|
|
|
|
* simply ignore the prune, as we are not forwarding this traffic
|
|
|
|
* downstream.
|
|
|
|
*/
|
|
|
|
log(LOG_DEBUG, 0, "%s (%s %s)/%d from %s",
|
|
|
|
"prune message received with no kernel entry for",
|
|
|
|
inet_fmt(prun_src, s1), inet_fmt(prun_grp, s2),
|
|
|
|
prun_tmr, inet_fmt(src, s3));
|
|
|
|
return;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks if this mcastgrp is present in the kernel table
|
|
|
|
* If so and if a prune was sent, it sends a graft upwards
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
chkgrp_graft(vifi, mcastgrp)
|
1994-09-08 00:26:13 +00:00
|
|
|
vifi_t vifi;
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 mcastgrp;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct rtentry *r;
|
|
|
|
struct gtable *g;
|
|
|
|
|
|
|
|
for (g = kernel_table; g; g = g->gt_gnext) {
|
|
|
|
if (ntohl(mcastgrp) < ntohl(g->gt_mcastgrp))
|
|
|
|
break;
|
|
|
|
|
|
|
|
r = g->gt_route;
|
|
|
|
if (g->gt_mcastgrp == mcastgrp && VIFM_ISSET(vifi, r->rt_children))
|
|
|
|
if (g->gt_prsent_timer) {
|
|
|
|
VIFM_SET(vifi, g->gt_grpmems);
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* If the vif that was joined was a scoped vif,
|
|
|
|
* ignore it ; don't graft back
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
g->gt_grpmems &= ~g->gt_scope;
|
|
|
|
if (g->gt_grpmems == 0)
|
1994-09-08 00:26:13 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* set the flag for graft retransmission */
|
1995-06-13 18:05:16 +00:00
|
|
|
g->gt_grftsnt = 1;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/* send graft upwards */
|
1995-06-13 18:05:16 +00:00
|
|
|
send_graft(g);
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/* reset the prune timer and update cache timer*/
|
1995-06-13 18:05:16 +00:00
|
|
|
g->gt_prsent_timer = 0;
|
|
|
|
g->gt_timer = max_prune_lifetime;
|
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "chkgrp graft (%s %s) gm:%x",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
|
|
|
|
|
|
|
|
prun_add_ttls(g);
|
|
|
|
update_kernel(g);
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(g,1);
|
|
|
|
#endif /* RSRR */
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* determine the multicast group and src
|
1995-06-13 18:05:16 +00:00
|
|
|
*
|
|
|
|
* if it does, then determine if a prune was sent
|
1994-09-08 00:26:13 +00:00
|
|
|
* upstream.
|
|
|
|
* if prune sent upstream, send graft upstream and send
|
|
|
|
* ack downstream.
|
1995-06-13 18:05:16 +00:00
|
|
|
*
|
1994-09-08 00:26:13 +00:00
|
|
|
* if no prune sent upstream, change the forwarding bit
|
|
|
|
* for this interface and send ack downstream.
|
|
|
|
*
|
1995-06-13 18:05:16 +00:00
|
|
|
* if no entry exists for this group send ack downstream.
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
accept_graft(src, dst, p, datalen)
|
|
|
|
u_int32 src;
|
|
|
|
u_int32 dst;
|
1994-09-08 00:26:13 +00:00
|
|
|
char *p;
|
|
|
|
int datalen;
|
|
|
|
{
|
|
|
|
vifi_t vifi;
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 graft_src;
|
|
|
|
u_int32 graft_grp;
|
1994-09-08 00:26:13 +00:00
|
|
|
int i;
|
1995-06-13 18:05:16 +00:00
|
|
|
struct rtentry *r;
|
|
|
|
struct gtable *g;
|
|
|
|
struct ptable *pt, **ptnp;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
if ((vifi = find_vif(src, dst)) == NO_VIF) {
|
|
|
|
log(LOG_INFO, 0,
|
1995-05-16 00:28:50 +00:00
|
|
|
"ignoring graft from non-neighbor %s",
|
|
|
|
inet_fmt(src, s1));
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1995-05-16 00:28:50 +00:00
|
|
|
if (datalen < 8) {
|
1994-09-08 00:26:13 +00:00
|
|
|
log(LOG_WARNING, 0,
|
1995-05-16 00:28:50 +00:00
|
|
|
"received non-decipherable graft from %s",
|
|
|
|
inet_fmt(src, s1));
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
for (i = 0; i< 4; i++)
|
1995-06-13 18:05:16 +00:00
|
|
|
((char *)&graft_src)[i] = *p++;
|
1994-09-08 00:26:13 +00:00
|
|
|
for (i = 0; i< 4; i++)
|
1995-06-13 18:05:16 +00:00
|
|
|
((char *)&graft_grp)[i] = *p++;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
log(LOG_DEBUG, 0, "%s on vif %d grafts (%s %s)",
|
|
|
|
inet_fmt(src, s1), vifi,
|
1995-06-13 18:05:16 +00:00
|
|
|
inet_fmt(graft_src, s2), inet_fmt(graft_grp, s3));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the subnet for the graft
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
if (find_src_grp(graft_src, 0, graft_grp)) {
|
|
|
|
g = gtp ? gtp->gt_gnext : kernel_table;
|
|
|
|
r = g->gt_route;
|
|
|
|
|
|
|
|
if (VIFM_ISSET(vifi, g->gt_scope)) {
|
|
|
|
log(LOG_WARNING, 0, "graft received from %s on scoped grp (%s %s)",
|
|
|
|
inet_fmt(src, s1), inet_fmt(graft_src, s2),
|
|
|
|
inet_fmt(graft_grp, s3));
|
|
|
|
return;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
ptnp = &g->gt_pruntbl;
|
|
|
|
while ((pt = *ptnp) != NULL) {
|
|
|
|
if ((pt->pt_vifi == vifi) && (pt->pt_router == src)) {
|
|
|
|
*ptnp = pt->pt_next;
|
|
|
|
free(pt);
|
|
|
|
|
|
|
|
VIFM_SET(vifi, g->gt_grpmems);
|
|
|
|
log(LOG_DEBUG, 0, "accept graft (%s %s) gm:%x",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(g->gt_mcastgrp, s2), g->gt_grpmems);
|
|
|
|
|
|
|
|
prun_add_ttls(g);
|
|
|
|
update_kernel(g);
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(g,1);
|
|
|
|
#endif /* RSRR */
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
ptnp = &pt->pt_next;
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* send ack downstream */
|
|
|
|
send_graft_ack(dst, src, graft_src, graft_grp);
|
|
|
|
g->gt_timer = max_prune_lifetime;
|
|
|
|
|
|
|
|
if (g->gt_prsent_timer) {
|
|
|
|
/* set the flag for graft retransmission */
|
|
|
|
g->gt_grftsnt = 1;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* send graft upwards */
|
|
|
|
send_graft(g);
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* reset the prune sent timer */
|
|
|
|
g->gt_prsent_timer = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We have no state for the source and group in question.
|
|
|
|
* We can simply acknowledge the graft, since we know
|
|
|
|
* that we have no prune state, and grafts are requests
|
|
|
|
* to remove prune state.
|
|
|
|
*/
|
|
|
|
send_graft_ack(dst, src, graft_src, graft_grp);
|
|
|
|
log(LOG_DEBUG, 0, "%s (%s %s) from %s",
|
|
|
|
"graft received with no kernel entry for",
|
|
|
|
inet_fmt(graft_src, s1), inet_fmt(graft_grp, s2),
|
|
|
|
inet_fmt(src, s3));
|
|
|
|
return;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* find out which group is involved first of all
|
1994-09-08 00:26:13 +00:00
|
|
|
* then determine if a graft was sent.
|
|
|
|
* if no graft sent, ignore the message
|
1995-06-13 18:05:16 +00:00
|
|
|
* if graft was sent and the ack is from the right
|
|
|
|
* source, remove the graft timer so that we don't
|
1994-09-08 00:26:13 +00:00
|
|
|
* have send a graft again
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
accept_g_ack(src, dst, p, datalen)
|
|
|
|
u_int32 src;
|
|
|
|
u_int32 dst;
|
1994-09-08 00:26:13 +00:00
|
|
|
char *p;
|
|
|
|
int datalen;
|
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct gtable *g;
|
1994-09-08 00:26:13 +00:00
|
|
|
vifi_t vifi;
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 grft_src;
|
|
|
|
u_int32 grft_grp;
|
1994-09-08 00:26:13 +00:00
|
|
|
int i;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
if ((vifi = find_vif(src, dst)) == NO_VIF) {
|
|
|
|
log(LOG_INFO, 0,
|
1995-06-13 18:05:16 +00:00
|
|
|
"ignoring graft ack from non-neighbor %s",
|
1995-05-16 00:28:50 +00:00
|
|
|
inet_fmt(src, s1));
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
if (datalen < 0 || datalen > 8) {
|
1994-09-08 00:26:13 +00:00
|
|
|
log(LOG_WARNING, 0,
|
1995-06-13 18:05:16 +00:00
|
|
|
"received non-decipherable graft ack from %s",
|
1995-05-16 00:28:50 +00:00
|
|
|
inet_fmt(src, s1));
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
for (i = 0; i< 4; i++)
|
|
|
|
((char *)&grft_src)[i] = *p++;
|
|
|
|
for (i = 0; i< 4; i++)
|
1995-06-13 18:05:16 +00:00
|
|
|
((char *)&grft_grp)[i] = *p++;
|
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "%s on vif %d acks graft (%s, %s)",
|
1994-09-08 00:26:13 +00:00
|
|
|
inet_fmt(src, s1), vifi,
|
1995-06-13 18:05:16 +00:00
|
|
|
inet_fmt(grft_src, s2), inet_fmt(grft_grp, s3));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the subnet for the graft ack
|
|
|
|
*/
|
|
|
|
if (find_src_grp(grft_src, 0, grft_grp)) {
|
|
|
|
g = gtp ? gtp->gt_gnext : kernel_table;
|
|
|
|
g->gt_grftsnt = 0;
|
|
|
|
} else {
|
|
|
|
log(LOG_WARNING, 0, "%s (%s, %s) from %s",
|
|
|
|
"rcvd graft ack with no kernel entry for",
|
|
|
|
inet_fmt(grft_src, s1), inet_fmt(grft_grp, s2),
|
|
|
|
inet_fmt(src, s3));
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* free all prune entries and kernel routes
|
|
|
|
* normally, this should inform the kernel that all of its routes
|
|
|
|
* are going away, but this is only called by restart(), which is
|
|
|
|
* about to call MRT_DONE which does that anyway.
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
free_all_prunes()
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
register struct rtentry *r;
|
|
|
|
register struct gtable *g, *prev_g;
|
|
|
|
register struct stable *s, *prev_s;
|
|
|
|
register struct ptable *p, *prev_p;
|
|
|
|
|
|
|
|
for (r = routing_table; r; r = r->rt_next) {
|
|
|
|
g = r->rt_groups;
|
|
|
|
while (g) {
|
|
|
|
s = g->gt_srctbl;
|
|
|
|
while (s) {
|
1996-01-06 21:10:30 +00:00
|
|
|
prev_s = s;
|
|
|
|
s = s->st_next;
|
|
|
|
free(prev_s);
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
p = g->gt_pruntbl;
|
|
|
|
while (p) {
|
1996-01-06 21:10:30 +00:00
|
|
|
prev_p = p;
|
|
|
|
p = p->pt_next;
|
|
|
|
free(prev_p);
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1996-01-06 21:10:30 +00:00
|
|
|
prev_g = g;
|
|
|
|
g = g->gt_next;
|
|
|
|
free(prev_g);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
r->rt_groups = NULL;
|
|
|
|
}
|
|
|
|
kernel_table = NULL;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
g = kernel_no_route;
|
|
|
|
while (g) {
|
|
|
|
if (g->gt_srctbl)
|
|
|
|
free(g->gt_srctbl);
|
|
|
|
|
1996-01-06 21:10:30 +00:00
|
|
|
prev_g = g;
|
|
|
|
g = g->gt_next;
|
|
|
|
free(prev_g);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
kernel_no_route = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When a new route is created, search
|
|
|
|
* a) The less-specific part of the routing table
|
|
|
|
* b) The route-less kernel table
|
|
|
|
* for sources that the new route might want to handle.
|
|
|
|
*
|
|
|
|
* "Inheriting" these sources might be cleanest, but simply deleting
|
|
|
|
* them is easier, and letting the kernel re-request them.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
steal_sources(rt)
|
|
|
|
struct rtentry *rt;
|
|
|
|
{
|
|
|
|
register struct rtentry *rp;
|
|
|
|
register struct gtable *gt, **gtnp;
|
|
|
|
register struct stable *st, **stnp;
|
|
|
|
|
|
|
|
for (rp = rt->rt_next; rp; rp = rp->rt_next) {
|
|
|
|
if ((rt->rt_origin & rp->rt_originmask) == rp->rt_origin) {
|
|
|
|
log(LOG_DEBUG, 0, "Route for %s stealing sources from %s",
|
|
|
|
inet_fmts(rt->rt_origin, rt->rt_originmask, s1),
|
|
|
|
inet_fmts(rp->rt_origin, rp->rt_originmask, s2));
|
|
|
|
for (gt = rp->rt_groups; gt; gt = gt->gt_next) {
|
|
|
|
stnp = >->gt_srctbl;
|
|
|
|
while ((st = *stnp) != NULL) {
|
|
|
|
if ((st->st_origin & rt->rt_originmask) == rt->rt_origin) {
|
|
|
|
log(LOG_DEBUG, 0, "%s stealing (%s %s) from %s",
|
|
|
|
inet_fmts(rt->rt_origin, rt->rt_originmask, s1),
|
|
|
|
inet_fmt(st->st_origin, s3),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s4),
|
|
|
|
inet_fmts(rp->rt_origin, rp->rt_originmask, s2));
|
|
|
|
if (k_del_rg(st->st_origin, gt) < 0) {
|
|
|
|
log(LOG_WARNING, errno, "%s (%s, %s)",
|
|
|
|
"steal_sources trying to delete",
|
|
|
|
inet_fmt(st->st_origin, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2));
|
|
|
|
}
|
|
|
|
*stnp = st->st_next;
|
|
|
|
kroutes--;
|
|
|
|
free(st);
|
|
|
|
} else {
|
|
|
|
stnp = &st->st_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
gtnp = &kernel_no_route;
|
|
|
|
while ((gt = *gtnp) != NULL) {
|
|
|
|
if (gt->gt_srctbl && ((gt->gt_srctbl->st_origin & rt->rt_originmask)
|
|
|
|
== rt->rt_origin)) {
|
|
|
|
log(LOG_DEBUG, 0, "%s stealing (%s %s) from %s",
|
|
|
|
inet_fmts(rt->rt_origin, rt->rt_originmask, s1),
|
|
|
|
inet_fmt(gt->gt_srctbl->st_origin, s3),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s4),
|
|
|
|
"no_route table");
|
|
|
|
if (k_del_rg(gt->gt_srctbl->st_origin, gt) < 0) {
|
|
|
|
log(LOG_WARNING, errno, "%s (%s %s)",
|
|
|
|
"steal_sources trying to delete",
|
|
|
|
inet_fmt(gt->gt_srctbl->st_origin, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2));
|
|
|
|
}
|
|
|
|
kroutes--;
|
|
|
|
free(gt->gt_srctbl);
|
|
|
|
*gtnp = gt->gt_next;
|
|
|
|
if (gt->gt_next)
|
|
|
|
gt->gt_next->gt_prev = gt->gt_prev;
|
|
|
|
free(gt);
|
|
|
|
} else {
|
|
|
|
gtnp = >->gt_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Advance the timers on all the cache entries.
|
|
|
|
* If there are any entries whose timers have expired,
|
|
|
|
* remove these entries from the kernel cache.
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
age_table_entry()
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct rtentry *r;
|
|
|
|
struct gtable *gt, **gtnptr;
|
|
|
|
struct stable *st, **stnp;
|
|
|
|
struct ptable *pt, **ptnp;
|
|
|
|
struct sioc_sg_req sg_req;
|
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "ageing entries");
|
|
|
|
|
|
|
|
gtnptr = &kernel_table;
|
|
|
|
while ((gt = *gtnptr) != NULL) {
|
|
|
|
r = gt->gt_route;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/* advance the timer for the kernel entry */
|
1995-06-13 18:05:16 +00:00
|
|
|
gt->gt_timer -= ROUTE_MAX_REPORT_DELAY;
|
|
|
|
|
|
|
|
/* decrement prune timer if need be */
|
|
|
|
if (gt->gt_prsent_timer > 0) {
|
|
|
|
gt->gt_prsent_timer -= ROUTE_MAX_REPORT_DELAY;
|
|
|
|
if (gt->gt_prsent_timer <= 0) {
|
|
|
|
log(LOG_DEBUG, 0, "upstream prune tmo (%s %s)",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2));
|
|
|
|
gt->gt_prsent_timer = -1;
|
|
|
|
}
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/* retransmit graft if graft sent flag is still set */
|
1995-06-13 18:05:16 +00:00
|
|
|
if (gt->gt_grftsnt) {
|
1994-09-08 00:26:13 +00:00
|
|
|
register int y;
|
1995-06-13 18:05:16 +00:00
|
|
|
CHK_GS(gt->gt_grftsnt++, y);
|
1994-09-08 00:26:13 +00:00
|
|
|
if (y)
|
1995-06-13 18:05:16 +00:00
|
|
|
send_graft(gt);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
|
|
|
* Age prunes
|
|
|
|
*
|
|
|
|
* If a prune expires, forward again on that vif.
|
|
|
|
*/
|
|
|
|
ptnp = >->gt_pruntbl;
|
|
|
|
while ((pt = *ptnp) != NULL) {
|
|
|
|
if ((pt->pt_timer -= ROUTE_MAX_REPORT_DELAY) <= 0) {
|
|
|
|
log(LOG_DEBUG, 0, "expire prune (%s %s) from %s on vif %d",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2),
|
|
|
|
inet_fmt(pt->pt_router, s3),
|
|
|
|
pt->pt_vifi);
|
1995-05-16 00:28:50 +00:00
|
|
|
|
1996-01-06 21:10:30 +00:00
|
|
|
expire_prune(pt->pt_vifi, gt);
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-05-16 00:28:50 +00:00
|
|
|
/* remove the router's prune entry and await new one */
|
1995-06-13 18:05:16 +00:00
|
|
|
*ptnp = pt->pt_next;
|
|
|
|
free(pt);
|
|
|
|
} else {
|
|
|
|
ptnp = &pt->pt_next;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
/*
|
1996-01-06 21:10:30 +00:00
|
|
|
* If the cache entry has expired, delete source table entries for
|
|
|
|
* silent sources. If there are no source entries left, and there
|
|
|
|
* are no downstream prunes, then the entry is deleted.
|
|
|
|
* Otherwise, the cache entry's timer is refreshed.
|
1995-06-28 17:58:49 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
if (gt->gt_timer <= 0) {
|
1996-01-06 21:10:30 +00:00
|
|
|
/* Check for traffic before deleting source entries */
|
|
|
|
sg_req.grp.s_addr = gt->gt_mcastgrp;
|
|
|
|
stnp = >->gt_srctbl;
|
|
|
|
while ((st = *stnp) != NULL) {
|
|
|
|
sg_req.src.s_addr = st->st_origin;
|
|
|
|
if (ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) < 0) {
|
|
|
|
log(LOG_WARNING, errno, "%s (%s %s)",
|
|
|
|
"age_table_entry: SIOCGETSGCNT failing for",
|
|
|
|
inet_fmt(st->st_origin, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2));
|
|
|
|
/* Make sure it gets deleted below */
|
|
|
|
sg_req.pktcnt = st->st_pktcnt;
|
|
|
|
}
|
|
|
|
if (sg_req.pktcnt == st->st_pktcnt) {
|
|
|
|
*stnp = st->st_next;
|
|
|
|
log(LOG_DEBUG, 0, "age_table_entry deleting (%s %s)",
|
|
|
|
inet_fmt(st->st_origin, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2));
|
|
|
|
if (k_del_rg(st->st_origin, gt) < 0) {
|
|
|
|
log(LOG_WARNING, errno,
|
|
|
|
"age_table_entry trying to delete (%s %s)",
|
1995-06-13 18:05:16 +00:00
|
|
|
inet_fmt(st->st_origin, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2));
|
|
|
|
}
|
1996-01-06 21:10:30 +00:00
|
|
|
kroutes--;
|
|
|
|
free(st);
|
|
|
|
} else {
|
|
|
|
st->st_pktcnt = sg_req.pktcnt;
|
|
|
|
stnp = &st->st_next;
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
1996-01-06 21:10:30 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1996-01-06 21:10:30 +00:00
|
|
|
/*
|
|
|
|
* Retain the group entry if we have downstream prunes or if
|
|
|
|
* there is at least one source in the list that still has
|
|
|
|
* traffic, or if our upstream prune timer is running.
|
|
|
|
*/
|
|
|
|
if (gt->gt_pruntbl != NULL || gt->gt_srctbl != NULL ||
|
|
|
|
gt->gt_prsent_timer > 0) {
|
|
|
|
gt->gt_timer = CACHE_LIFETIME(cache_lifetime);
|
|
|
|
if (gt->gt_prsent_timer == -1)
|
|
|
|
if (gt->gt_grpmems == 0)
|
|
|
|
send_prune(gt);
|
|
|
|
else
|
|
|
|
gt->gt_prsent_timer = 0;
|
|
|
|
gtnptr = >->gt_gnext;
|
|
|
|
continue;
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "timeout cache entry (%s, %s)",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2));
|
|
|
|
|
|
|
|
if (gt->gt_prev)
|
|
|
|
gt->gt_prev->gt_next = gt->gt_next;
|
|
|
|
else
|
|
|
|
gt->gt_route->rt_groups = gt->gt_next;
|
|
|
|
if (gt->gt_next)
|
|
|
|
gt->gt_next->gt_prev = gt->gt_prev;
|
|
|
|
|
|
|
|
if (gt->gt_gprev) {
|
|
|
|
gt->gt_gprev->gt_gnext = gt->gt_gnext;
|
|
|
|
gtnptr = >->gt_gprev->gt_gnext;
|
|
|
|
} else {
|
|
|
|
kernel_table = gt->gt_gnext;
|
|
|
|
gtnptr = &kernel_table;
|
|
|
|
}
|
|
|
|
if (gt->gt_gnext)
|
|
|
|
gt->gt_gnext->gt_gprev = gt->gt_gprev;
|
|
|
|
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(gt,0);
|
|
|
|
rsrr_cache_clean(gt);
|
|
|
|
#endif /* RSRR */
|
|
|
|
free((char *)gt);
|
|
|
|
} else {
|
|
|
|
if (gt->gt_prsent_timer == -1)
|
1996-01-06 21:10:30 +00:00
|
|
|
if (gt->gt_grpmems == 0)
|
|
|
|
send_prune(gt);
|
|
|
|
else
|
|
|
|
gt->gt_prsent_timer = 0;
|
1995-06-13 18:05:16 +00:00
|
|
|
gtnptr = >->gt_gnext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When traversing the no_route table, the decision is much easier.
|
|
|
|
* Just delete it if it has timed out.
|
|
|
|
*/
|
|
|
|
gtnptr = &kernel_no_route;
|
|
|
|
while ((gt = *gtnptr) != NULL) {
|
|
|
|
/* advance the timer for the kernel entry */
|
|
|
|
gt->gt_timer -= ROUTE_MAX_REPORT_DELAY;
|
|
|
|
|
|
|
|
if (gt->gt_timer < 0) {
|
|
|
|
if (gt->gt_srctbl) {
|
|
|
|
if (k_del_rg(gt->gt_srctbl->st_origin, gt) < 0) {
|
|
|
|
log(LOG_WARNING, errno, "%s (%s %s)",
|
|
|
|
"age_table_entry trying to delete no-route",
|
|
|
|
inet_fmt(gt->gt_srctbl->st_origin, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2));
|
|
|
|
}
|
|
|
|
free(gt->gt_srctbl);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
*gtnptr = gt->gt_next;
|
|
|
|
if (gt->gt_next)
|
|
|
|
gt->gt_next->gt_prev = gt->gt_prev;
|
|
|
|
|
|
|
|
free((char *)gt);
|
|
|
|
} else {
|
|
|
|
gtnptr = >->gt_next;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-01-06 21:10:30 +00:00
|
|
|
/*
|
|
|
|
* Modify the kernel to forward packets when one or multiple prunes that
|
|
|
|
* were received on the vif given by vifi, for the group given by gt,
|
|
|
|
* have expired.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
expire_prune(vifi, gt)
|
|
|
|
vifi_t vifi;
|
|
|
|
struct gtable *gt;
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No need to send a graft, any prunes that we sent
|
|
|
|
* will expire before any prunes that we have received.
|
|
|
|
*/
|
|
|
|
if (gt->gt_prsent_timer > 0) {
|
|
|
|
log(LOG_DEBUG, 0, "prune expired with %d left on %s",
|
|
|
|
gt->gt_prsent_timer, "prsent_timer");
|
|
|
|
gt->gt_prsent_timer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* modify the kernel entry to forward packets */
|
|
|
|
if (!VIFM_ISSET(vifi, gt->gt_grpmems)) {
|
|
|
|
struct rtentry *rt = gt->gt_route;
|
|
|
|
VIFM_SET(vifi, gt->gt_grpmems);
|
|
|
|
log(LOG_DEBUG, 0, "forw again (%s %s) gm:%x vif:%d",
|
|
|
|
inet_fmts(rt->rt_origin, rt->rt_originmask, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2), gt->gt_grpmems, vifi);
|
|
|
|
|
|
|
|
prun_add_ttls(gt);
|
|
|
|
update_kernel(gt);
|
|
|
|
#ifdef RSRR
|
|
|
|
/* Send route change notification to reservation protocol. */
|
|
|
|
rsrr_cache_send(gt,1);
|
|
|
|
#endif /* RSRR */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
static char *
|
1995-06-13 18:05:16 +00:00
|
|
|
scaletime(t)
|
|
|
|
u_long t;
|
|
|
|
{
|
|
|
|
static char buf1[5];
|
|
|
|
static char buf2[5];
|
|
|
|
static char *buf=buf1;
|
|
|
|
char s;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
if (buf == buf1)
|
|
|
|
buf = buf2;
|
|
|
|
else
|
|
|
|
buf = buf1;
|
|
|
|
|
|
|
|
if (t < 120) {
|
|
|
|
s = 's';
|
|
|
|
} else if (t < 3600) {
|
|
|
|
t /= 60;
|
|
|
|
s = 'm';
|
|
|
|
} else if (t < 86400) {
|
|
|
|
t /= 3600;
|
|
|
|
s = 'h';
|
|
|
|
} else if (t < 864000) {
|
|
|
|
t /= 86400;
|
|
|
|
s = 'd';
|
|
|
|
} else {
|
|
|
|
t /= 604800;
|
|
|
|
s = 'w';
|
|
|
|
}
|
|
|
|
if (t > 999)
|
|
|
|
return "*** ";
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
sprintf(p,"%3d%c", (int)t, s);
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* Print the contents of the cache table on file 'fp2'.
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
dump_cache(fp2)
|
1994-09-08 00:26:13 +00:00
|
|
|
FILE *fp2;
|
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
register struct rtentry *r;
|
|
|
|
register struct gtable *gt;
|
|
|
|
register struct stable *st;
|
|
|
|
register struct ptable *pt;
|
1996-01-06 21:10:30 +00:00
|
|
|
register vifi_t i;
|
1996-11-11 03:50:15 +00:00
|
|
|
char c;
|
1995-06-13 18:05:16 +00:00
|
|
|
register time_t thyme = time(0);
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
fprintf(fp2,
|
|
|
|
"Multicast Routing Cache Table (%d entries)\n%s", kroutes,
|
1995-06-13 18:05:16 +00:00
|
|
|
" Origin Mcast-group CTmr Age Ptmr IVif Forwvifs\n");
|
|
|
|
|
|
|
|
for (gt = kernel_no_route; gt; gt = gt->gt_next) {
|
|
|
|
if (gt->gt_srctbl) {
|
|
|
|
fprintf(fp2, " %-18s %-15s %-4s %-4s - -1\n",
|
|
|
|
inet_fmts(gt->gt_srctbl->st_origin, 0xffffffff, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2), scaletime(gt->gt_timer),
|
|
|
|
scaletime(thyme - gt->gt_ctime));
|
|
|
|
fprintf(fp2, ">%s\n", inet_fmt(gt->gt_srctbl->st_origin, s1));
|
|
|
|
}
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
for (gt = kernel_table; gt; gt = gt->gt_gnext) {
|
|
|
|
r = gt->gt_route;
|
|
|
|
fprintf(fp2, " %-18s %-15s",
|
|
|
|
inet_fmts(r->rt_origin, r->rt_originmask, s1),
|
|
|
|
inet_fmt(gt->gt_mcastgrp, s2));
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
fprintf(fp2, " %-4s", scaletime(gt->gt_timer));
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
fprintf(fp2, " %-4s %-4s ", scaletime(thyme - gt->gt_ctime),
|
|
|
|
gt->gt_prsent_timer ? scaletime(gt->gt_prsent_timer) :
|
|
|
|
" -");
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
fprintf(fp2, "%2u%c%c ", r->rt_parent,
|
|
|
|
gt->gt_prsent_timer ? 'P' : ' ',
|
|
|
|
VIFM_ISSET(r->rt_parent, gt->gt_scope) ? 'B' : ' ');
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
for (i = 0; i < numvifs; ++i) {
|
1995-06-13 18:05:16 +00:00
|
|
|
if (VIFM_ISSET(i, gt->gt_grpmems))
|
1994-09-08 00:26:13 +00:00
|
|
|
fprintf(fp2, " %u ", i);
|
1995-06-13 18:05:16 +00:00
|
|
|
else if (VIFM_ISSET(i, r->rt_children) &&
|
|
|
|
!VIFM_ISSET(i, r->rt_leaves))
|
|
|
|
fprintf(fp2, " %u%c", i,
|
|
|
|
VIFM_ISSET(i, gt->gt_scope) ? 'b' : 'p');
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
fprintf(fp2, "\n");
|
1996-11-11 03:50:15 +00:00
|
|
|
if (gt->gt_pruntbl) {
|
|
|
|
fprintf(fp2, "<");
|
|
|
|
c = '(';
|
|
|
|
for (pt = gt->gt_pruntbl; pt; pt = pt->pt_next) {
|
|
|
|
fprintf(fp2, "%c%s:%d/%d", c, inet_fmt(pt->pt_router, s1),
|
|
|
|
pt->pt_vifi, pt->pt_timer);
|
|
|
|
c = ',';
|
|
|
|
}
|
|
|
|
fprintf(fp2, ")\n");
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
for (st = gt->gt_srctbl; st; st = st->st_next) {
|
|
|
|
fprintf(fp2, ">%s\n", inet_fmt(st->st_origin, s1));
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Traceroute function which returns traceroute replies to the requesting
|
|
|
|
* router. Also forwards the request to downstream routers.
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
accept_mtrace(src, dst, group, data, no, datalen)
|
|
|
|
u_int32 src;
|
|
|
|
u_int32 dst;
|
|
|
|
u_int32 group;
|
1994-09-08 00:26:13 +00:00
|
|
|
char *data;
|
1995-06-28 17:58:49 +00:00
|
|
|
u_int no; /* promoted u_char */
|
1994-09-08 00:26:13 +00:00
|
|
|
int datalen;
|
|
|
|
{
|
|
|
|
u_char type;
|
|
|
|
struct rtentry *rt;
|
1995-06-13 18:05:16 +00:00
|
|
|
struct gtable *gt;
|
1994-09-08 00:26:13 +00:00
|
|
|
struct tr_query *qry;
|
|
|
|
struct tr_resp *resp;
|
|
|
|
int vifi;
|
|
|
|
char *p;
|
|
|
|
int rcount;
|
1995-06-13 18:05:16 +00:00
|
|
|
int errcode = TR_NO_ERR;
|
|
|
|
int resptype;
|
1994-09-08 00:26:13 +00:00
|
|
|
struct timeval tp;
|
|
|
|
struct sioc_vif_req v_req;
|
|
|
|
struct sioc_sg_req sg_req;
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/* Remember qid across invocations */
|
|
|
|
static u_int32 oqid = 0;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/* timestamp the request/response */
|
1995-06-13 18:05:16 +00:00
|
|
|
gettimeofday(&tp, 0);
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if it is a query or a response
|
|
|
|
*/
|
|
|
|
if (datalen == QLEN) {
|
|
|
|
type = QUERY;
|
1995-06-28 17:58:49 +00:00
|
|
|
log(LOG_DEBUG, 0, "Initial traceroute query rcvd from %s to %s",
|
1995-06-13 18:05:16 +00:00
|
|
|
inet_fmt(src, s1), inet_fmt(dst, s2));
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
else if ((datalen - QLEN) % RLEN == 0) {
|
1994-09-08 00:26:13 +00:00
|
|
|
type = RESP;
|
1995-06-28 17:58:49 +00:00
|
|
|
log(LOG_DEBUG, 0, "In-transit traceroute query rcvd from %s to %s",
|
1995-06-13 18:05:16 +00:00
|
|
|
inet_fmt(src, s1), inet_fmt(dst, s2));
|
1995-06-28 17:58:49 +00:00
|
|
|
if (IN_MULTICAST(ntohl(dst))) {
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "Dropping multicast response");
|
|
|
|
return;
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
else {
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_WARNING, 0, "%s from %s to %s",
|
1995-06-28 17:58:49 +00:00
|
|
|
"Non decipherable traceroute request recieved",
|
1995-06-13 18:05:16 +00:00
|
|
|
inet_fmt(src, s1), inet_fmt(dst, s2));
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qry = (struct tr_query *)data;
|
|
|
|
|
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* if it is a packet with all reports filled, drop it
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
|
|
|
if ((rcount = (datalen - QLEN)/RLEN) == no) {
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "packet with all reports filled in");
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "s: %s g: %s d: %s ", inet_fmt(qry->tr_src, s1),
|
|
|
|
inet_fmt(group, s2), inet_fmt(qry->tr_dst, s3));
|
|
|
|
log(LOG_DEBUG, 0, "rttl: %d rd: %s", qry->tr_rttl,
|
|
|
|
inet_fmt(qry->tr_raddr, s1));
|
1995-06-28 17:58:49 +00:00
|
|
|
log(LOG_DEBUG, 0, "rcount:%d, qid:%06x", rcount, qry->tr_qid);
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/* determine the routing table entry for this traceroute */
|
|
|
|
rt = determine_route(qry->tr_src);
|
1995-06-13 18:05:16 +00:00
|
|
|
if (rt) {
|
|
|
|
log(LOG_DEBUG, 0, "rt parent vif: %d rtr: %s metric: %d",
|
|
|
|
rt->rt_parent, inet_fmt(rt->rt_gateway, s1), rt->rt_metric);
|
|
|
|
log(LOG_DEBUG, 0, "rt origin %s",
|
|
|
|
inet_fmts(rt->rt_origin, rt->rt_originmask, s1));
|
|
|
|
} else
|
|
|
|
log(LOG_DEBUG, 0, "...no route");
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/*
|
1995-06-13 18:05:16 +00:00
|
|
|
* Query type packet - check if rte exists
|
1994-09-08 00:26:13 +00:00
|
|
|
* Check if the query destination is a vif connected to me.
|
|
|
|
* and if so, whether I should start response back
|
|
|
|
*/
|
|
|
|
if (type == QUERY) {
|
1996-01-06 21:10:30 +00:00
|
|
|
if (oqid == qry->tr_qid) {
|
|
|
|
/*
|
|
|
|
* If the multicast router is a member of the group being
|
|
|
|
* queried, and the query is multicasted, then the router can
|
|
|
|
* recieve multiple copies of the same query. If we have already
|
|
|
|
* replied to this traceroute, just ignore it this time.
|
|
|
|
*
|
|
|
|
* This is not a total solution, but since if this fails you
|
|
|
|
* only get N copies, N <= the number of interfaces on the router,
|
|
|
|
* it is not fatal.
|
|
|
|
*/
|
|
|
|
log(LOG_DEBUG, 0, "ignoring duplicate traceroute packet");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
if (rt == NULL) {
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "Mcast traceroute: no route entry %s",
|
1994-09-08 00:26:13 +00:00
|
|
|
inet_fmt(qry->tr_src, s1));
|
|
|
|
if (IN_MULTICAST(ntohl(dst)))
|
|
|
|
return;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
vifi = find_vif(qry->tr_dst, 0);
|
|
|
|
|
|
|
|
if (vifi == NO_VIF) {
|
|
|
|
/* The traceroute destination is not on one of my subnet vifs. */
|
|
|
|
log(LOG_DEBUG, 0, "Destination %s not an interface",
|
1994-09-08 00:26:13 +00:00
|
|
|
inet_fmt(qry->tr_dst, s1));
|
1995-06-13 18:05:16 +00:00
|
|
|
if (IN_MULTICAST(ntohl(dst)))
|
|
|
|
return;
|
|
|
|
errcode = TR_WRONG_IF;
|
|
|
|
} else if (rt != NULL && !VIFM_ISSET(vifi, rt->rt_children)) {
|
|
|
|
log(LOG_DEBUG, 0, "Destination %s not on forwarding tree for src %s",
|
1994-09-08 00:26:13 +00:00
|
|
|
inet_fmt(qry->tr_dst, s1), inet_fmt(qry->tr_src, s2));
|
1995-06-13 18:05:16 +00:00
|
|
|
if (IN_MULTICAST(ntohl(dst)))
|
|
|
|
return;
|
|
|
|
errcode = TR_WRONG_IF;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* determine which interface the packet came in on
|
1995-06-13 18:05:16 +00:00
|
|
|
* RESP packets travel hop-by-hop so this either traversed
|
|
|
|
* a tunnel or came from a directly attached mrouter.
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
|
|
|
if ((vifi = find_vif(src, dst)) == NO_VIF) {
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "Wrong interface for packet");
|
|
|
|
errcode = TR_WRONG_IF;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
}
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
/* Now that we've decided to send a response, save the qid */
|
|
|
|
oqid = qry->tr_qid;
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "Sending traceroute response");
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/* copy the packet to the sending buffer */
|
|
|
|
p = send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
bcopy(data, p, datalen);
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
p += datalen;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is no room to insert our reply, coopt the previous hop
|
|
|
|
* error indication to relay this fact.
|
|
|
|
*/
|
|
|
|
if (p + sizeof(struct tr_resp) > send_buf + RECV_BUF_SIZE) {
|
|
|
|
resp = (struct tr_resp *)p - 1;
|
|
|
|
resp->tr_rflags = TR_NO_SPACE;
|
|
|
|
rt = NULL;
|
|
|
|
goto sendit;
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* fill in initial response fields
|
|
|
|
*/
|
|
|
|
resp = (struct tr_resp *)p;
|
1995-06-13 18:05:16 +00:00
|
|
|
bzero(resp, sizeof(struct tr_resp));
|
|
|
|
datalen += RLEN;
|
|
|
|
|
1996-11-11 03:50:15 +00:00
|
|
|
resp->tr_qarr = htonl(((tp.tv_sec + JAN_1970) << 16) +
|
|
|
|
((tp.tv_usec << 10) / 15625));
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
resp->tr_rproto = PROTO_DVMRP;
|
1995-06-13 18:05:16 +00:00
|
|
|
if (errcode != TR_NO_ERR) {
|
|
|
|
resp->tr_rflags = errcode;
|
|
|
|
rt = NULL; /* hack to enforce send straight to requestor */
|
|
|
|
goto sendit;
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
resp->tr_outaddr = uvifs[vifi].uv_lcl_addr;
|
|
|
|
resp->tr_fttl = uvifs[vifi].uv_threshold;
|
|
|
|
resp->tr_rflags = TR_NO_ERR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* obtain # of packets out on interface
|
|
|
|
*/
|
|
|
|
v_req.vifi = vifi;
|
|
|
|
if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) >= 0)
|
1995-07-10 16:13:05 +00:00
|
|
|
resp->tr_vifout = htonl(v_req.ocount);
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fill in scoping & pruning information
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
if (rt)
|
|
|
|
for (gt = rt->rt_groups; gt; gt = gt->gt_next) {
|
|
|
|
if (gt->gt_mcastgrp >= group)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gt = NULL;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (gt && gt->gt_mcastgrp == group) {
|
1994-09-08 00:26:13 +00:00
|
|
|
sg_req.src.s_addr = qry->tr_src;
|
|
|
|
sg_req.grp.s_addr = group;
|
|
|
|
if (ioctl(udp_socket, SIOCGETSGCNT, (char *)&sg_req) >= 0)
|
1995-07-10 16:13:05 +00:00
|
|
|
resp->tr_pktcnt = htonl(sg_req.pktcnt);
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (VIFM_ISSET(vifi, gt->gt_scope))
|
1994-09-08 00:26:13 +00:00
|
|
|
resp->tr_rflags = TR_SCOPED;
|
1995-06-13 18:05:16 +00:00
|
|
|
else if (gt->gt_prsent_timer)
|
1994-09-08 00:26:13 +00:00
|
|
|
resp->tr_rflags = TR_PRUNED;
|
1995-06-13 18:05:16 +00:00
|
|
|
else if (!VIFM_ISSET(vifi, gt->gt_grpmems))
|
|
|
|
if (VIFM_ISSET(vifi, rt->rt_children) &&
|
|
|
|
!VIFM_ISSET(vifi, rt->rt_leaves))
|
|
|
|
resp->tr_rflags = TR_OPRUNED;
|
|
|
|
else
|
|
|
|
resp->tr_rflags = TR_NO_FWD;
|
|
|
|
} else {
|
|
|
|
if (scoped_addr(vifi, group))
|
|
|
|
resp->tr_rflags = TR_SCOPED;
|
1995-06-28 17:58:49 +00:00
|
|
|
else if (rt && !VIFM_ISSET(vifi, rt->rt_children))
|
1995-06-13 18:05:16 +00:00
|
|
|
resp->tr_rflags = TR_NO_FWD;
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if no rte exists, set NO_RTE error
|
|
|
|
*/
|
|
|
|
if (rt == NULL) {
|
|
|
|
src = dst; /* the dst address of resp. pkt */
|
1995-05-16 00:28:50 +00:00
|
|
|
resp->tr_inaddr = 0;
|
1994-09-08 00:26:13 +00:00
|
|
|
resp->tr_rflags = TR_NO_RTE;
|
1995-06-13 18:05:16 +00:00
|
|
|
resp->tr_rmtaddr = 0;
|
|
|
|
} else {
|
1994-09-08 00:26:13 +00:00
|
|
|
/* get # of packets in on interface */
|
|
|
|
v_req.vifi = rt->rt_parent;
|
|
|
|
if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)&v_req) >= 0)
|
1995-07-10 16:13:05 +00:00
|
|
|
resp->tr_vifin = htonl(v_req.icount);
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
MASK_TO_VAL(rt->rt_originmask, resp->tr_smask);
|
|
|
|
src = uvifs[rt->rt_parent].uv_lcl_addr;
|
|
|
|
resp->tr_inaddr = src;
|
|
|
|
resp->tr_rmtaddr = rt->rt_gateway;
|
|
|
|
if (!VIFM_ISSET(vifi, rt->rt_children)) {
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "Destination %s not on forwarding tree for src %s",
|
1994-09-08 00:26:13 +00:00
|
|
|
inet_fmt(qry->tr_dst, s1), inet_fmt(qry->tr_src, s2));
|
|
|
|
resp->tr_rflags = TR_WRONG_IF;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
if (rt->rt_metric >= UNREACHABLE) {
|
|
|
|
resp->tr_rflags = TR_NO_RTE;
|
|
|
|
/* Hack to send reply directly */
|
|
|
|
rt = NULL;
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
sendit:
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* if metric is 1 or no. of reports is 1, send response to requestor
|
1995-06-13 18:05:16 +00:00
|
|
|
* else send to upstream router. If the upstream router can't handle
|
|
|
|
* mtrace, set an error code and send to requestor anyway.
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
log(LOG_DEBUG, 0, "rcount:%d, no:%d", rcount, no);
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if ((rcount + 1 == no) || (rt == NULL) || (rt->rt_metric == 1)) {
|
|
|
|
resptype = IGMP_MTRACE_RESP;
|
1994-09-08 00:26:13 +00:00
|
|
|
dst = qry->tr_raddr;
|
1995-06-13 18:05:16 +00:00
|
|
|
} else
|
|
|
|
if (!can_mtrace(rt->rt_parent, rt->rt_gateway)) {
|
|
|
|
dst = qry->tr_raddr;
|
|
|
|
resp->tr_rflags = TR_OLD_ROUTER;
|
|
|
|
resptype = IGMP_MTRACE_RESP;
|
|
|
|
} else {
|
|
|
|
dst = rt->rt_gateway;
|
|
|
|
resptype = IGMP_MTRACE;
|
|
|
|
}
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
if (IN_MULTICAST(ntohl(dst))) {
|
1995-06-28 17:58:49 +00:00
|
|
|
/*
|
|
|
|
* Send the reply on a known multicast capable vif.
|
|
|
|
* If we don't have one, we can't source any multicasts anyway.
|
1995-06-13 18:05:16 +00:00
|
|
|
*/
|
1995-06-28 17:58:49 +00:00
|
|
|
if (phys_vif != -1) {
|
|
|
|
log(LOG_DEBUG, 0, "Sending reply to %s from %s",
|
|
|
|
inet_fmt(dst, s1), inet_fmt(uvifs[phys_vif].uv_lcl_addr, s2));
|
|
|
|
k_set_ttl(qry->tr_rttl);
|
|
|
|
send_igmp(uvifs[phys_vif].uv_lcl_addr, dst,
|
|
|
|
resptype, no, group,
|
|
|
|
datalen);
|
|
|
|
k_set_ttl(1);
|
|
|
|
} else
|
|
|
|
log(LOG_INFO, 0, "No enabled phyints -- %s",
|
|
|
|
"dropping traceroute reply");
|
|
|
|
} else {
|
|
|
|
log(LOG_DEBUG, 0, "Sending %s to %s from %s",
|
|
|
|
resptype == IGMP_MTRACE_RESP ? "reply" : "request on",
|
|
|
|
inet_fmt(dst, s1), inet_fmt(src, s2));
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
send_igmp(src, dst,
|
1995-06-13 18:05:16 +00:00
|
|
|
resptype, no, group,
|
|
|
|
datalen);
|
1995-06-28 17:58:49 +00:00
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|