summaryrefslogtreecommitdiff
path: root/usr.sbin/mrouted/vif.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1995-12-14 01:46:23 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1995-12-14 01:46:23 +0000
commitacfc88313dd86a33e6c0424cda0578b15a539e42 (patch)
tree8831738b9326fa2111446b81b93fee2285da3e07 /usr.sbin/mrouted/vif.c
parenta10a6913325bfa093081ff08628e32d3b0f2a565 (diff)
from netbsd; update to mrouted 3.8
Diffstat (limited to 'usr.sbin/mrouted/vif.c')
-rw-r--r--usr.sbin/mrouted/vif.c686
1 files changed, 397 insertions, 289 deletions
diff --git a/usr.sbin/mrouted/vif.c b/usr.sbin/mrouted/vif.c
index 406e8157858..326d17dcd67 100644
--- a/usr.sbin/mrouted/vif.c
+++ b/usr.sbin/mrouted/vif.c
@@ -1,4 +1,4 @@
-/* $NetBSD: vif.c,v 1.5 1995/10/09 03:52:01 thorpej Exp $ */
+/* $NetBSD: vif.c,v 1.6 1995/12/10 10:07:19 mycroft Exp $ */
/*
* The mrouted program is covered by the license in the accompanying file
@@ -11,29 +11,48 @@
#include "defs.h"
-
+#include <fcntl.h>
/*
* Exported variables.
*/
-struct uvif uvifs[MAXVIFS]; /* array of virtual interfaces */
-vifi_t numvifs; /* number of vifs in use */
-int vifs_down; /* 1=>some interfaces are down */
+struct uvif uvifs[MAXVIFS]; /* array of virtual interfaces */
+vifi_t numvifs; /* number of vifs in use */
+int vifs_down; /* 1=>some interfaces are down */
+int phys_vif; /* An enabled vif */
int udp_socket; /* Since the honkin' kernel doesn't support */
/* ioctls on raw IP sockets, we need a UDP */
/* socket as well as our IGMP (raw) socket. */
/* How dumb. */
int vifs_with_neighbors; /* == 1 if I am a leaf */
+typedef struct {
+ vifi_t vifi;
+ struct listaddr *g;
+ int q_time;
+} cbk_t;
+
/*
* Forward declarations.
*/
-static void start_vif();
-static void stop_vif();
-static void age_old_hosts();
+static void start_vif __P((vifi_t vifi));
+static void start_vif2 __P((vifi_t vifi));
+static void stop_vif __P((vifi_t vifi));
+static void age_old_hosts __P((void));
+static void send_probe_on_vif __P((struct uvif *v));
+static int info_version __P((char *p));
+static void DelVif __P((void *arg));
+static int SetTimer __P((int vifi, struct listaddr *g));
+static int DeleteTimer __P((int id));
+static void SendQuery __P((void *arg));
+static int SetQueryTimer __P((struct listaddr *g, vifi_t vifi, int to_expire,
+ int q_time));
+
/*
- * Initialize the virtual interfaces.
+ * Initialize the virtual interfaces, but do not install
+ * them in the kernel. Start routing on all vifs that are
+ * not down or disabled.
*/
void
init_vifs()
@@ -44,6 +63,7 @@ init_vifs()
extern char *configfilename;
numvifs = 0;
+ vifs_with_neighbors = 0;
vifs_down = FALSE;
/*
@@ -63,11 +83,15 @@ init_vifs()
*/
enabled_vifs = 0;
enabled_phyints = 0;
+ phys_vif = -1;
for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
if (!(v->uv_flags & VIFF_DISABLED)) {
++enabled_vifs;
- if (!(v->uv_flags & VIFF_TUNNEL))
+ if (!(v->uv_flags & VIFF_TUNNEL)) {
+ if (phys_vif == -1)
+ phys_vif = vifi;
++enabled_phyints;
+ }
}
}
if (enabled_vifs < 2)
@@ -78,22 +102,18 @@ init_vifs()
log(LOG_WARNING, 0,
"no enabled interfaces, forwarding via tunnels only");
- /*
- * Start routing on all virtual interfaces that are not down or
- * administratively disabled.
- */
- log(LOG_INFO,0,"Installing vifs in kernel...");
+ log(LOG_INFO, 0, "Installing vifs in mrouted...");
for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
if (!(v->uv_flags & VIFF_DISABLED)) {
if (!(v->uv_flags & VIFF_DOWN)) {
if (v->uv_flags & VIFF_TUNNEL)
- log(LOG_INFO,0,"vif #%d, tunnel %s -> %s", vifi,
- inet_fmt(v->uv_lcl_addr,s1),
- inet_fmt(v->uv_rmt_addr,s2));
+ log(LOG_INFO, 0, "vif #%d, tunnel %s -> %s", vifi,
+ inet_fmt(v->uv_lcl_addr, s1),
+ inet_fmt(v->uv_rmt_addr, s2));
else
- log(LOG_INFO,0,"vif #%d, phyint %s", vifi,
- inet_fmt(v->uv_lcl_addr,s1));
- start_vif(vifi);
+ log(LOG_INFO, 0, "vif #%d, phyint %s", vifi,
+ inet_fmt(v->uv_lcl_addr, s1));
+ start_vif2(vifi);
} else log(LOG_INFO, 0,
"%s is not yet up; vif #%u not in service",
v->uv_name, vifi);
@@ -101,6 +121,34 @@ init_vifs()
}
}
+/*
+ * Start routing on all virtual interfaces that are not down or
+ * administratively disabled.
+ */
+void
+init_installvifs()
+{
+ vifi_t vifi;
+ struct uvif *v;
+
+ log(LOG_INFO, 0, "Installing vifs in kernel...");
+ for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
+ if (!(v->uv_flags & VIFF_DISABLED)) {
+ if (!(v->uv_flags & VIFF_DOWN)) {
+ if (v->uv_flags & VIFF_TUNNEL)
+ log(LOG_INFO, 0, "vif #%d, tunnel %s -> %s", vifi,
+ inet_fmt(v->uv_lcl_addr, s1),
+ inet_fmt(v->uv_rmt_addr, s2));
+ else
+ log(LOG_INFO, 0, "vif #%d, phyint %s", vifi,
+ inet_fmt(v->uv_lcl_addr, s1));
+ k_add_vif(vifi, &uvifs[vifi]);
+ } else log(LOG_INFO, 0,
+ "%s is not yet up; vif #%u not in service",
+ v->uv_name, vifi);
+ }
+ }
+}
/*
* See if any interfaces have changed from up state to down, or vice versa,
@@ -151,7 +199,7 @@ check_vif_state()
/*
* Send a probe message on vif v
*/
-void
+static void
send_probe_on_vif(v)
register struct uvif *v;
{
@@ -188,12 +236,28 @@ send_probe_on_vif(v)
}
/*
- * Start routing on the specified virtual interface.
+ * Add a vifi to the kernel and start routing on it.
*/
static void
start_vif(vifi)
vifi_t vifi;
{
+ /*
+ * Install the interface in the kernel's vif structure.
+ */
+ k_add_vif(vifi, &uvifs[vifi]);
+
+ start_vif2(vifi);
+}
+
+/*
+ * Add a vifi to all the user-level data structures but don't add
+ * it to the kernel yet.
+ */
+static void
+start_vif2(vifi)
+ vifi_t vifi;
+{
struct uvif *v;
u_int32_t src;
struct phaddr *p;
@@ -202,11 +266,6 @@ start_vif(vifi)
src = v->uv_lcl_addr;
/*
- * Install the interface in the kernel's vif structure.
- */
- k_add_vif(vifi, &uvifs[vifi]);
-
- /*
* Update the existing route entries to take into account the new vif.
*/
add_vif_to_routes(vifi);
@@ -236,7 +295,7 @@ start_vif(vifi)
update_route(v->uv_subnet, v->uv_subnetmask, 0, 0, vifi);
for (p = v->uv_addrs; p; p = p->pa_next) {
start_route_updates();
- update_route(p->pa_addr, p->pa_mask, 0, 0, vifi);
+ update_route(p->pa_subnet, p->pa_subnetmask, 0, 0, vifi);
}
/*
@@ -246,7 +305,8 @@ start_vif(vifi)
*/
v->uv_flags |= VIFF_QUERIER;
send_igmp(src, allhosts_group, IGMP_HOST_MEMBERSHIP_QUERY,
- IGMP_MAX_HOST_REPORT_DELAY * IGMP_TIMER_SCALE, 0, 0);
+ (v->uv_flags & VIFF_IGMPV1) ? 0 :
+ IGMP_MAX_HOST_REPORT_DELAY * IGMP_TIMER_SCALE, 0, 0);
age_old_hosts();
}
@@ -291,7 +351,7 @@ stop_vif(vifi)
update_route(v->uv_subnet, v->uv_subnetmask, UNREACHABLE, 0, vifi);
for (p = v->uv_addrs; p; p = p->pa_next) {
start_route_updates();
- update_route(p->pa_addr, p->pa_mask, UNREACHABLE, 0, vifi);
+ update_route(p->pa_subnet, p->pa_subnetmask, UNREACHABLE, 0, vifi);
}
/*
@@ -384,11 +444,13 @@ find_vif(src, dst)
}
else {
if ((src & v->uv_subnetmask) == v->uv_subnet &&
- src != v->uv_subnetbcast)
+ ((v->uv_subnetmask == 0xffffffff) ||
+ (src != v->uv_subnetbcast)))
return(vifi);
for (p=v->uv_addrs; p; p=p->pa_next) {
- if ((src & p->pa_mask) == p->pa_addr &&
- src != p->pa_addr)
+ if ((src & p->pa_subnetmask) == p->pa_subnet &&
+ ((p->pa_subnetmask == 0xffffffff) ||
+ (src != p->pa_subnetbcast)))
return(vifi);
}
}
@@ -403,16 +465,15 @@ age_old_hosts()
register vifi_t vifi;
register struct uvif *v;
register struct listaddr *g;
- for (vifi = 0, v = uvifs; vifi < numvifs; vifi++, v++) {
- /* -*- increment the time since an old report was heard */
- for (g = v->uv_groups; g != NULL; g = g->al_next) {
- g->al_last ++;
- if (g->al_last >= OLD_AGE_THRESHOLD){
- g->al_old = 0;
- g->al_last = OLD_AGE_THRESHOLD;
- }
- }
- }
+
+ /*
+ * Decrement the old-hosts-present timer for each
+ * active group on each vif.
+ */
+ for (vifi = 0, v = uvifs; vifi < numvifs; vifi++, v++)
+ for (g = v->uv_groups; g != NULL; g = g->al_next)
+ if (g->al_old)
+ g->al_old--;
}
@@ -429,6 +490,7 @@ query_groups()
if (v->uv_flags & VIFF_QUERIER) {
send_igmp(v->uv_lcl_addr, allhosts_group,
IGMP_HOST_MEMBERSHIP_QUERY,
+ (v->uv_flags & VIFF_IGMPV1) ? 0 :
IGMP_MAX_HOST_REPORT_DELAY * IGMP_TIMER_SCALE, 0, 0);
}
}
@@ -456,16 +518,19 @@ accept_membership_query(src, dst, group, tmo)
v = &uvifs[vifi];
- /* If we consider ourselves the querier for this vif, but hear a
+ /*
+ * If we consider ourselves the querier for this vif, but hear a
* query from a router with a lower IP address, yield to them.
*
* This is done here as well as in the neighbor discovery in case
* there is a querier that doesn't speak DVMRP.
+ *
+ * XXX If this neighbor doesn't speak DVMRP, then we need to create
+ * some neighbor state for him so that we can time him out!
*/
if ((v->uv_flags & VIFF_QUERIER) &&
(ntohl(src) < ntohl(v->uv_lcl_addr))) {
-
- v->uv_flags &= ~VIFF_QUERIER;
+ v->uv_flags &= ~VIFF_QUERIER;
}
}
@@ -497,17 +562,14 @@ accept_group_report(src, dst, group, r_type)
*/
for (g = v->uv_groups; g != NULL; g = g->al_next) {
if (group == g->al_addr) {
- if (r_type == IGMP_v2_HOST_MEMBERSHIP_REPORT) {
- g->al_last = OLD_AGE_THRESHOLD;
- g->al_old = 0;
- }
- else {
- g->al_last = 0;
- g->al_old = 1;
- }
-
- /** delete old timer set a timer for expiration **/
- g->al_timer= GROUP_EXPIRE_TIME;
+ if (r_type == IGMP_v1_HOST_MEMBERSHIP_REPORT)
+ g->al_old = OLD_AGE_THRESHOLD;
+#ifdef SNMP
+ g->al_genid = src;
+#endif /* SNMP */
+
+ /** delete old timers, set a timer for expiration **/
+ g->al_timer = GROUP_EXPIRE_TIME;
if (g->al_query)
g->al_query = DeleteTimer(g->al_query);
if (g->al_timerid)
@@ -526,14 +588,13 @@ accept_group_report(src, dst, group, r_type)
log(LOG_ERR, 0, "ran out of memory"); /* fatal */
g->al_addr = group;
- if (r_type == IGMP_v2_HOST_MEMBERSHIP_REPORT) {
- g->al_last = OLD_AGE_THRESHOLD;
+ if (r_type == IGMP_v2_HOST_MEMBERSHIP_REPORT)
g->al_old = 0;
- }
- else {
- g->al_last = 0;
- g->al_old = 1;
- }
+ else
+ g->al_old = OLD_AGE_THRESHOLD;
+#ifdef SNMP
+ g->al_genid = src;
+#endif
/** set a timer for expiration **/
g->al_query = 0;
@@ -554,7 +615,7 @@ accept_group_report(src, dst, group, r_type)
void
-accept_leave_message( src, dst, group)
+accept_leave_message(src, dst, group)
u_int32_t src, dst, group;
{
register vifi_t vifi;
@@ -571,7 +632,7 @@ accept_leave_message( src, dst, group)
v = &uvifs[vifi];
- if (!(v->uv_flags & VIFF_QUERIER))
+ if (!(v->uv_flags & VIFF_QUERIER) || (v->uv_flags & VIFF_IGMPV1))
return;
/*
@@ -832,6 +893,68 @@ accept_neighbor_request2(src, dst)
datalen);
}
+void
+accept_info_request(src, dst, p, datalen)
+ u_int32_t src, dst;
+ u_char *p;
+ int datalen;
+{
+ u_char *q;
+ int len;
+ int outlen = 0;
+
+ q = (u_char *) (send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN);
+
+ /* To be general, this must deal properly with breaking up over-sized
+ * packets. That implies passing a length to each function, and
+ * allowing each function to request to be called again. Right now,
+ * we're only implementing the one thing we are positive will fit into
+ * a single packet, so we wimp out.
+ */
+ while (datalen > 0) {
+ len = 0;
+ switch (*p) {
+ case DVMRP_INFO_VERSION:
+ len = info_version(q);
+ break;
+
+ case DVMRP_INFO_NEIGHBORS:
+ default:
+ log(LOG_INFO, 0, "ignoring unknown info type %d", *p);
+ break;
+ }
+ *(q+1) = len++;
+ outlen += len * 4;
+ q += len * 4;
+ len = (*(p+1) + 1) * 4;
+ p += len;
+ datalen -= len;
+ }
+
+ if (outlen != 0)
+ send_igmp(INADDR_ANY, src, IGMP_DVMRP, DVMRP_INFO_REPLY,
+ htonl(MROUTED_LEVEL), outlen);
+}
+
+/*
+ * Information response -- return version string
+ */
+static int
+info_version(p)
+ char *p;
+{
+ int len;
+ extern char versionstring[];
+
+ *p++ = DVMRP_INFO_VERSION;
+ p++; /* skip over length */
+ *p++ = 0; /* zero out */
+ *p++ = 0; /* reserved fields */
+ strcpy(p, versionstring); /* XXX strncpy!!! */
+
+ len = strlen(versionstring);
+ return ((len + 3) / 4);
+}
/*
* Process an incoming neighbor-list message.
@@ -839,7 +962,7 @@ accept_neighbor_request2(src, dst)
void
accept_neighbors(src, dst, p, datalen, level)
u_int32_t src, dst, level;
- char *p;
+ u_char *p;
int datalen;
{
log(LOG_INFO, 0, "ignoring spurious DVMRP neighbor list from %s to %s",
@@ -853,13 +976,26 @@ accept_neighbors(src, dst, p, datalen, level)
void
accept_neighbors2(src, dst, p, datalen, level)
u_int32_t src, dst, level;
- char *p;
+ u_char *p;
int datalen;
{
log(LOG_INFO, 0, "ignoring spurious DVMRP neighbor list2 from %s to %s",
inet_fmt(src, s1), inet_fmt(dst, s2));
}
+/*
+ * Process an incoming info reply message.
+ */
+void
+accept_info_reply(src, dst, p, datalen)
+ u_int32_t src, dst;
+ u_char *p;
+ int datalen;
+{
+ log(LOG_INFO, 0, "ignoring spurious DVMRP info reply from %s to %s",
+ inet_fmt(src, s1), inet_fmt(dst, s2));
+}
+
/*
* Update the neighbor entry for neighbor 'addr' on vif 'vifi'.
@@ -879,7 +1015,8 @@ update_neighbor(vifi, addr, msgtype, p, datalen, level)
register struct listaddr *n;
u_int32_t genid = 0;
u_int32_t router;
- int he_hears_me = TRUE;
+ u_int32_t send_tables = 0;
+ int do_reset = FALSE;
int nflags;
v = &uvifs[vifi];
@@ -906,18 +1043,83 @@ update_neighbor(vifi, addr, msgtype, p, datalen, level)
}
/*
- * If we have received a route report from a neighbor, and we believed
- * that we had no neighbors on this vif, send a full route report to
- * all neighbors on the vif.
+ * Look for addr in list of neighbors.
+ */
+ for (n = v->uv_neighbors; n != NULL; n = n->al_next) {
+ if (addr == n->al_addr) {
+ break;
+ }
+ }
+
+ /*
+ * Found it. Reset its timer, and check for a version change
*/
+ if (n) {
+ n->al_timer = 0;
+
+ /*
+ * update the neighbors version and protocol number
+ * if changed => router went down and came up,
+ * so take action immediately.
+ */
+ if ((n->al_pv != (level & 0xff)) ||
+ (n->al_mv != ((level >> 8) & 0xff))) {
+
+ do_reset = TRUE;
+ log(LOG_DEBUG, 0,
+ "version change neighbor %s [old:%d.%d, new:%d.%d]",
+ inet_fmt(addr, s1),
+ n->al_pv, n->al_mv, level&0xff, (level >> 8) & 0xff);
+
+ n->al_pv = level & 0xff;
+ n->al_mv = (level >> 8) & 0xff;
+ }
+ } else {
+ /*
+ * If not found, add it to the list. If the neighbor has a lower
+ * IP address than me, yield querier duties to it.
+ */
+ log(LOG_DEBUG, 0, "New neighbor %s on vif %d v%d.%d nf 0x%02x",
+ inet_fmt(addr, s1), vifi, level & 0xff, (level >> 8) & 0xff,
+ (level >> 16) & 0xff);
+
+ n = (struct listaddr *)malloc(sizeof(struct listaddr));
+ if (n == NULL)
+ log(LOG_ERR, 0, "ran out of memory"); /* fatal */
+
+ n->al_addr = addr;
+ n->al_pv = level & 0xff;
+ n->al_mv = (level >> 8) & 0xff;
+ n->al_genid = 0;
+
+ time(&n->al_ctime);
+ n->al_timer = 0;
+ n->al_next = v->uv_neighbors;
+
+ /*
+ * If we thought that we had no neighbors on this vif, send a route
+ * report to the vif. If this is just a new neighbor on the same
+ * vif, send the route report just to the new neighbor.
+ */
+ if (v->uv_neighbors == NULL) {
+ send_tables = (v->uv_flags & VIFF_TUNNEL) ? addr : dvmrp_group;
+ vifs_with_neighbors++;
+ } else {
+ send_tables = addr;
+ }
+
+ v->uv_neighbors = n;
- if (msgtype == DVMRP_REPORT && v->uv_neighbors == NULL)
- report(ALL_ROUTES, vifi,
- (v->uv_flags & VIFF_TUNNEL) ? addr : dvmrp_group);
+ if (!(v->uv_flags & VIFF_TUNNEL) &&
+ ntohl(addr) < ntohl(v->uv_lcl_addr))
+ v->uv_flags &= ~VIFF_QUERIER;
+ }
/*
- * Check if the router gen-ids are the same (only if vers > 3.2)
+ * Check if the router gen-ids are the same.
* Need to reset the prune state of the router if not.
+ * Also check for one-way interfaces by seeing if we are in our
+ * neighbor's list of known routers.
*/
if (msgtype == DVMRP_PROBE) {
@@ -937,13 +1139,24 @@ update_neighbor(vifi, addr, msgtype, p, datalen, level)
for (i = 0; i < 4; i++)
((char *)&genid)[i] = *p++;
- datalen -=4;
+ datalen -= 4;
+
+ if (n->al_genid == 0)
+ n->al_genid = genid;
+ else if (n->al_genid != genid) {
+ log(LOG_DEBUG, 0,
+ "new genid neigbor %s on vif %d [old:%x, new:%x]",
+ inet_fmt(addr, s1), vifi, n->al_genid, genid);
+
+ n->al_genid = genid;
+ do_reset = TRUE;
+ }
/*
* loop through router list and check for one-way ifs.
*/
- he_hears_me = FALSE;
+ v->uv_flags |= VIFF_ONEWAY;
while (datalen > 0) {
if (datalen < 4) {
@@ -956,139 +1169,37 @@ update_neighbor(vifi, addr, msgtype, p, datalen, level)
((char *)&router)[i] = *p++;
datalen -= 4;
if (router == v->uv_lcl_addr) {
- he_hears_me = TRUE;
+ v->uv_flags &= ~VIFF_ONEWAY;
break;
}
}
}
}
- /*
- * Look for addr in list of neighbors; if found, reset its timer.
- */
- for (n = v->uv_neighbors; n != NULL; n = n->al_next) {
- if (addr == n->al_addr) {
- n->al_timer = 0;
-
- /*
- * If probe message and version no >= 3.3 check genid
- */
- if (msgtype == DVMRP_PROBE &&
- ((n->al_pv >= 3 && n->al_mv > 2) || n->al_pv > 3)) {
- if (he_hears_me == TRUE && v->uv_flags & VIFF_ONEWAY)
- v->uv_flags &= ~VIFF_ONEWAY;
-
- if (he_hears_me == FALSE)
- v->uv_flags |= VIFF_ONEWAY;
-
- if (n->al_genid == 0)
- n->al_genid = genid;
- else if (n->al_genid != genid) {
- log(LOG_DEBUG, 0,
- "reset neighbor %s on vif %d [old genid:%x, new:%x]",
- inet_fmt(addr, s1), vifi, n->al_genid, genid);
-
- n->al_genid = genid;
- n->al_pv = level & 0xff;
- n->al_mv = (level >> 8) & 0xff;
- n->al_flags = 0; /*XXX*/
- reset_neighbor_state(vifi, addr);
-
- /*
- * need to do a full route report here
- * it gets done by accept_probe()
- */
- return (TRUE);
- }
-
- /*XXX nflags shouldn't be dealt with in 2 places in the same
- *XXX routine...*/
- if (n->al_flags != nflags) {
- n->al_flags = nflags;
- if (nflags & NF_LEAF) {
- if (!v->uv_leaf_timer)
- v->uv_leaf_timer = LEAF_CONFIRMATION_TIME;
- } else {
- v->uv_flags &= ~VIFF_LEAF;
- v->uv_leaf_timer = 0;
- }
- /* Neighbor flags changed, do a full report */
- return TRUE;
- }
- }
-
- /*
- * update the neighbors version and protocol number
- * if changed => router went down and came up,
- * so take action immediately.
- */
- if ((n->al_pv != (level & 0xff)) ||
- (n->al_mv != ((level >> 8) & 0xff))) {
-
- log(LOG_DEBUG, 0,
- "resetting neighbor %s [old:%d.%d, new:%d.%d]",
- inet_fmt(addr, s1),
- n->al_pv, n->al_mv, level&0xff, (level >> 8) & 0xff);
-
- n->al_pv = level & 0xff;
- n->al_mv = (level >> 8) & 0xff;
-
- reset_neighbor_state(vifi, addr);
- }
-
- /* recurring probe - so no need to do a route report */
- if (msgtype == DVMRP_PROBE)
- return (FALSE);
- else
- return (TRUE);
+ if (n->al_flags != nflags) {
+ n->al_flags = nflags;
+
+ if (n->al_flags & NF_LEAF) {
+ /*XXX If we have non-leaf neighbors then we know we shouldn't
+ * mark this vif as a leaf. For now we just count on other
+ * probes and/or reports resetting the timer. */
+ if (!v->uv_leaf_timer)
+ v->uv_leaf_timer = LEAF_CONFIRMATION_TIME;
+ } else {
+ /* If we get a leaf to non-leaf transition, we *must* update
+ * the routing table. */
+ if (v->uv_flags & VIFF_LEAF && send_tables == 0)
+ send_tables = addr;
+ v->uv_flags &= ~VIFF_LEAF;
+ v->uv_leaf_timer = 0;
}
}
-
- /*
- * If not found, add it to the list. If the neighbor has a lower
- * IP address than me, yield querier duties to it.
- */
- if (n == NULL) {
- log(LOG_DEBUG, 0, "New neighbor %s on vif %d v%d.%d nf 0x%02x",
- inet_fmt(addr, s1), vifi, level & 0xff, (level >> 8) & 0xff,
- (level >> 16) & 0xff);
-
- n = (struct listaddr *)malloc(sizeof(struct listaddr));
- if (n == NULL)
- log(LOG_ERR, 0, "ran out of memory"); /* fatal */
-
- n->al_addr = addr;
- n->al_pv = level & 0xff;
- n->al_mv = (level >> 8) & 0xff;
- if (msgtype == DVMRP_PROBE)
- n->al_genid = genid;
- else
- n->al_genid = 0;
-
- time(&n->al_ctime);
- n->al_timer = 0;
- n->al_next = v->uv_neighbors;
-
- if (v->uv_neighbors == NULL)
- vifs_with_neighbors++;
-
- v->uv_neighbors = n;
-
- if (!(v->uv_flags & VIFF_TUNNEL) &&
- ntohl(addr) < ntohl(v->uv_lcl_addr))
- v->uv_flags &= ~VIFF_QUERIER;
- }
-
- n->al_flags = nflags;
- if (!(n->al_flags & NF_LEAF)) {
- v->uv_flags &= ~VIFF_LEAF;
- v->uv_leaf_timer = 0;
- } else {
- /*XXX If we have non-leaf neighbors then we know we shouldn't
- * mark this vif as a leaf. For now we just count on other
- * probes and/or reports resetting the timer. */
- if (!v->uv_leaf_timer)
- v->uv_leaf_timer = LEAF_CONFIRMATION_TIME;
+ if (do_reset) {
+ reset_neighbor_state(vifi, addr);
+ if (!send_tables)
+ send_tables = addr;
}
+ if (send_tables)
+ report(ALL_ROUTES, vifi, send_tables);
return (TRUE);
}
@@ -1170,20 +1281,6 @@ neighbor_info(vifi, addr)
}
/*
- * Return the neighbor's version number
- * returns (protocol_version << 8 + mrouted_version) of neighbor
- */
-int
-nbr_vers(vifi, addr)
- vifi_t vifi;
- u_int32_t addr;
-{
- struct listaddr *u = neighbor_info(vifi, addr);
-
- return u ? NBR_VERS(u) : 0;
-}
-
-/*
* Print the contents of the uvifs array on file 'fp'.
*/
void
@@ -1229,14 +1326,15 @@ dump_vifs(fp)
if (v->uv_flags & VIFF_QUERIER) fprintf(fp, " querier");
if (v->uv_flags & VIFF_SRCRT) fprintf(fp, " src-rt");
if (v->uv_flags & VIFF_LEAF) fprintf(fp, " leaf");
+ if (v->uv_flags & VIFF_IGMPV1) fprintf(fp, " IGMPv1");
fprintf(fp, "\n");
if (v->uv_addrs != NULL) {
fprintf(fp, " alternate subnets: %s\n",
- inet_fmts(v->uv_addrs->pa_addr, v->uv_addrs->pa_mask, s1));
+ inet_fmts(v->uv_addrs->pa_subnet, v->uv_addrs->pa_subnetmask, s1));
for (p = v->uv_addrs->pa_next; p; p = p->pa_next) {
fprintf(fp, " %s\n",
- inet_fmts(p->pa_addr, p->pa_mask, s1));
+ inet_fmts(p->pa_subnet, p->pa_subnetmask, s1));
}
}
@@ -1276,9 +1374,9 @@ dump_vifs(fp)
"SIOCGETVIFCNT fails");
}
else {
- fprintf(fp, " pkts in : %d\n",
+ fprintf(fp, " pkts in : %ld\n",
v_req.icount);
- fprintf(fp, " pkts out: %d\n",
+ fprintf(fp, " pkts out: %ld\n",
v_req.ocount);
}
fprintf(fp, "\n");
@@ -1286,88 +1384,98 @@ dump_vifs(fp)
fprintf(fp, "\n");
}
-
-/**** the timeout routines ********/
-
-typedef struct {
- vifi_t vifi;
- struct listaddr *g;
- int q_time;
-} cbk_t;
-
-static cbk_t *cbk;
-
-void
-DelVif(cbk)
-cbk_t *cbk;
+/*
+ * Time out record of a group membership on a vif
+ */
+static void
+DelVif(arg)
+ void *arg;
{
- /* -*- make the list consistent */
- register vifi_t vifi = cbk->vifi;
- register struct uvif *v;
- register struct listaddr *a, *prev_a, *g = cbk->g;
-
- v = &uvifs[vifi];
+ cbk_t *cbk = (cbk_t *)arg;
+ vifi_t vifi = cbk->vifi;
+ struct uvif *v = &uvifs[vifi];
+ struct listaddr *a, **anp, *g = cbk->g;
- for (prev_a = (struct listaddr *)&(v->uv_groups),
- a = v->uv_groups;
- a != NULL;
- prev_a = a, a = a->al_next) {
-
- if (a != g) continue;
+ /*
+ * Group has expired
+ * delete all kernel cache entries with this group
+ */
+ if (g->al_query)
+ DeleteTimer(g->al_query);
- /*
- * Group has expired
- * delete all kernel cache entries with this group
- */
- if (g->al_query) DeleteTimer(g->al_query);
- delete_lclgrp(vifi, a->al_addr);
+ delete_lclgrp(vifi, g->al_addr);
- prev_a->al_next = a->al_next;
- free((char *)a);
- a = prev_a;
- }
+ anp = &(v->uv_groups);
+ while ((a = *anp) != NULL) {
+ if (a == g) {
+ *anp = a->al_next;
+ free((char *)a);
+ } else {
+ anp = &a->al_next;
+ }
+ }
- free(cbk);
+ free(cbk);
}
-
-int
-SetTimer( vifi, g)
- vifi_t vifi; struct listaddr *g;
+/*
+ * Set a timer to delete the record of a group membership on a vif.
+ */
+static int
+SetTimer(vifi, g)
+ vifi_t vifi;
+ struct listaddr *g;
{
- cbk = (cbk_t *) malloc(sizeof(cbk_t));
- cbk->g = g;
- cbk->vifi = vifi;
- return timer_setTimer(g->al_timer,DelVif,cbk);
+ cbk_t *cbk;
+
+ cbk = (cbk_t *) malloc(sizeof(cbk_t));
+ cbk->g = g;
+ cbk->vifi = vifi;
+ return timer_setTimer(g->al_timer, (cfunc_t)DelVif, (void *)cbk);
}
-int
-DeleteTimer( id)
-int id;
+/*
+ * Delete a timer that was set above.
+ */
+static int
+DeleteTimer(id)
+ int id;
{
- timer_clearTimer(id);
- return 0;
+ timer_clearTimer(id);
+ return 0;
}
-void
-SendQuery(cbk)
-cbk_t *cbk;
+/*
+ * Send a group-specific query.
+ */
+static void
+SendQuery(arg)
+ void *arg;
{
- register struct uvif *v = &uvifs[cbk->vifi];
- send_igmp(v->uv_lcl_addr, cbk->g->al_addr,
- IGMP_HOST_MEMBERSHIP_QUERY,
- cbk->q_time, 0, 0);
- cbk->g->al_query = 0;
- free(cbk);
+ cbk_t *cbk = (cbk_t *)arg;
+ register struct uvif *v = &uvifs[cbk->vifi];
+
+ send_igmp(v->uv_lcl_addr, cbk->g->al_addr,
+ IGMP_HOST_MEMBERSHIP_QUERY,
+ cbk->q_time, cbk->g->al_addr, 0);
+ cbk->g->al_query = 0;
+ free(cbk);
}
-int
-SetQueryTimer(g , vifi, to_expire, q_time)
- struct listaddr *g; vifi_t vifi;
- int to_expire, q_time;
+/*
+ * Set a timer to send a group-specific query.
+ */
+static int
+SetQueryTimer(g, vifi, to_expire, q_time)
+ struct listaddr *g;
+ vifi_t vifi;
+ int to_expire, q_time;
{
- cbk = (cbk_t *) malloc(sizeof(cbk_t));
- cbk->g = g;
- cbk->q_time = q_time; cbk-> vifi = vifi;
- return timer_setTimer(to_expire,SendQuery,cbk);
+ cbk_t *cbk;
+
+ cbk = (cbk_t *) malloc(sizeof(cbk_t));
+ cbk->g = g;
+ cbk->q_time = q_time;
+ cbk->vifi = vifi;
+ return timer_setTimer(to_expire, (cfunc_t)SendQuery, (void *)cbk);
}