1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* This tool requests configuration info from a multicast router
|
|
|
|
* and prints the reply (if any). Invoke it as:
|
|
|
|
*
|
|
|
|
* mrinfo router-name-or-address
|
|
|
|
*
|
|
|
|
* Written Wed Mar 24 1993 by Van Jacobson (adapted from the
|
|
|
|
* multicast mapper written by Pavel Curtis).
|
|
|
|
*
|
|
|
|
* The lawyers insist we include the following UC copyright notice.
|
|
|
|
* The mapper from which this is derived contained a Xerox copyright
|
|
|
|
* notice which follows the UC one. Try not to get depressed noting
|
|
|
|
* that the legal gibberish is larger than the program.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1993 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the Computer Systems
|
|
|
|
* Engineering Group at Lawrence Berkeley Laboratory.
|
|
|
|
* 4. Neither the name of the University nor of the Laboratory may be used
|
|
|
|
* to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
* ---------------------------------
|
|
|
|
* Copyright (c) Xerox Corporation 1992. All rights reserved.
|
1995-06-13 18:05:16 +00:00
|
|
|
*
|
1994-09-08 00:26:13 +00:00
|
|
|
* License is granted to copy, to use, and to make and to use derivative works
|
|
|
|
* for research and evaluation purposes, provided that Xerox is acknowledged
|
|
|
|
* in all documentation pertaining to any such copy or derivative work. Xerox
|
|
|
|
* grants no other licenses expressed or implied. The Xerox trade name should
|
|
|
|
* not be used in any advertising without its written permission.
|
1995-06-13 18:05:16 +00:00
|
|
|
*
|
1994-09-08 00:26:13 +00:00
|
|
|
* XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
|
|
|
|
* MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE FOR
|
|
|
|
* ANY PARTICULAR PURPOSE. The software is provided "as is" without express
|
|
|
|
* or implied warranty of any kind.
|
1995-06-13 18:05:16 +00:00
|
|
|
*
|
1994-09-08 00:26:13 +00:00
|
|
|
* These notices must be retained in any copies of any part of this software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static char rcsid[] =
|
1995-07-10 16:13:05 +00:00
|
|
|
"@(#) $Id: mrinfo.c,v 1.6 1995/06/28 17:58:36 wollman Exp $";
|
1994-09-08 00:26:13 +00:00
|
|
|
/* original rcsid:
|
|
|
|
"@(#) Header: mrinfo.c,v 1.6 93/04/08 15:14:16 van Exp (LBL)";
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include "defs.h"
|
1995-06-13 18:05:16 +00:00
|
|
|
#include <arpa/inet.h>
|
1995-06-28 17:58:49 +00:00
|
|
|
#ifdef __STDC__
|
|
|
|
#include <stdarg.h>
|
|
|
|
#else
|
|
|
|
#include <varargs.h>
|
|
|
|
#endif
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
#define DEFAULT_TIMEOUT 4 /* How long to wait before retrying requests */
|
|
|
|
#define DEFAULT_RETRIES 3 /* How many times to ask each router */
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 our_addr, target_addr = 0; /* in NET order */
|
1994-09-08 00:26:13 +00:00
|
|
|
int debug = 0;
|
1995-06-13 18:05:16 +00:00
|
|
|
int nflag = 0;
|
1994-09-08 00:26:13 +00:00
|
|
|
int retries = DEFAULT_RETRIES;
|
|
|
|
int timeout = DEFAULT_TIMEOUT;
|
1995-06-28 17:58:49 +00:00
|
|
|
int target_level = 0;
|
1994-09-08 00:26:13 +00:00
|
|
|
vifi_t numvifs; /* to keep loader happy */
|
|
|
|
/* (see COPY_TABLES macro called in kern.c) */
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
char * inet_name __P((u_int32 addr));
|
|
|
|
void ask __P((u_int32 dst));
|
|
|
|
void ask2 __P((u_int32 dst));
|
|
|
|
int get_number __P((int *var, int deflt, char ***pargv,
|
|
|
|
int *pargc));
|
|
|
|
u_int32 host_addr __P((char *name));
|
|
|
|
void usage __P((void));
|
|
|
|
|
|
|
|
/* to shut up -Wstrict-prototypes */
|
|
|
|
int main __P((int argc, char *argv[]));
|
|
|
|
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
char *
|
|
|
|
inet_name(addr)
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 addr;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
struct hostent *e;
|
1995-06-13 18:05:16 +00:00
|
|
|
struct in_addr in;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (addr == 0)
|
|
|
|
return "local";
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
if (nflag ||
|
|
|
|
(e = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET)) == NULL) {
|
|
|
|
in.s_addr = addr;
|
|
|
|
return (inet_ntoa(in));
|
|
|
|
}
|
|
|
|
return (e->h_name);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Log errors and other messages to stderr, according to the severity of the
|
|
|
|
* message and the current debug level. For errors of severity LOG_ERR or
|
|
|
|
* worse, terminate the program.
|
|
|
|
*/
|
1995-06-28 17:58:49 +00:00
|
|
|
#ifdef __STDC__
|
|
|
|
void
|
|
|
|
log(int severity, int syserr, char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char fmt[100];
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
#else
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
1995-06-28 17:58:49 +00:00
|
|
|
log(severity, syserr, format, va_alist)
|
1994-09-08 00:26:13 +00:00
|
|
|
int severity, syserr;
|
|
|
|
char *format;
|
1995-06-28 17:58:49 +00:00
|
|
|
va_dcl
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
1995-06-28 17:58:49 +00:00
|
|
|
va_list ap;
|
1994-09-08 00:26:13 +00:00
|
|
|
char fmt[100];
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
va_start(ap);
|
|
|
|
#endif
|
1994-09-08 00:26:13 +00:00
|
|
|
switch (debug) {
|
|
|
|
case 0:
|
|
|
|
if (severity > LOG_WARNING)
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
if (severity > LOG_NOTICE)
|
|
|
|
return;
|
|
|
|
case 2:
|
|
|
|
if (severity > LOG_INFO)
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
fmt[0] = '\0';
|
|
|
|
if (severity == LOG_WARNING)
|
|
|
|
strcat(fmt, "warning - ");
|
|
|
|
strncat(fmt, format, 80);
|
1995-06-28 17:58:49 +00:00
|
|
|
vfprintf(stderr, fmt, ap);
|
1994-09-08 00:26:13 +00:00
|
|
|
if (syserr == 0)
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
else if (syserr < sys_nerr)
|
|
|
|
fprintf(stderr, ": %s\n", sys_errlist[syserr]);
|
|
|
|
else
|
|
|
|
fprintf(stderr, ": errno %d\n", syserr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (severity <= LOG_ERR)
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a neighbors-list request.
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
1994-09-08 00:26:13 +00:00
|
|
|
ask(dst)
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 dst;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
send_igmp(our_addr, dst, IGMP_DVMRP, DVMRP_ASK_NEIGHBORS,
|
|
|
|
htonl(MROUTED_LEVEL), 0);
|
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
1994-09-08 00:26:13 +00:00
|
|
|
ask2(dst)
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 dst;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
send_igmp(our_addr, dst, IGMP_DVMRP, DVMRP_ASK_NEIGHBORS2,
|
|
|
|
htonl(MROUTED_LEVEL), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an incoming neighbor-list message.
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
1995-06-28 17:58:49 +00:00
|
|
|
accept_neighbors(src, dst, p, datalen, level)
|
|
|
|
u_int32 src, dst, level;
|
|
|
|
u_char *p;
|
1994-09-08 00:26:13 +00:00
|
|
|
int datalen;
|
|
|
|
{
|
|
|
|
u_char *ep = p + datalen;
|
1995-06-13 18:05:16 +00:00
|
|
|
#define GET_ADDR(a) (a = ((u_int32)*p++ << 24), a += ((u_int32)*p++ << 16),\
|
|
|
|
a += ((u_int32)*p++ << 8), a += *p++)
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
printf("%s (%s):\n", inet_fmt(src, s1), inet_name(src));
|
|
|
|
while (p < ep) {
|
1995-06-13 18:05:16 +00:00
|
|
|
register u_int32 laddr;
|
1994-09-08 00:26:13 +00:00
|
|
|
register u_char metric;
|
|
|
|
register u_char thresh;
|
|
|
|
register int ncount;
|
|
|
|
|
|
|
|
GET_ADDR(laddr);
|
|
|
|
laddr = htonl(laddr);
|
|
|
|
metric = *p++;
|
|
|
|
thresh = *p++;
|
|
|
|
ncount = *p++;
|
|
|
|
while (--ncount >= 0) {
|
1995-06-13 18:05:16 +00:00
|
|
|
register u_int32 neighbor;
|
1994-09-08 00:26:13 +00:00
|
|
|
GET_ADDR(neighbor);
|
|
|
|
neighbor = htonl(neighbor);
|
|
|
|
printf(" %s -> ", inet_fmt(laddr, s1));
|
|
|
|
printf("%s (%s) [%d/%d]\n", inet_fmt(neighbor, s1),
|
|
|
|
inet_name(neighbor), metric, thresh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
1995-06-28 17:58:49 +00:00
|
|
|
accept_neighbors2(src, dst, p, datalen, level)
|
|
|
|
u_int32 src, dst, level;
|
|
|
|
u_char *p;
|
1994-09-08 00:26:13 +00:00
|
|
|
int datalen;
|
|
|
|
{
|
|
|
|
u_char *ep = p + datalen;
|
1995-06-28 17:58:49 +00:00
|
|
|
u_int broken_cisco = ((level & 0xffff) == 0x020a); /* 10.2 */
|
1995-06-13 18:05:16 +00:00
|
|
|
/* well, only possibly_broken_cisco, but that's too long to type. */
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
printf("%s (%s) [version %d.%d]:\n", inet_fmt(src, s1), inet_name(src),
|
1995-06-28 17:58:49 +00:00
|
|
|
level & 0xff, (level >> 8) & 0xff);
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
while (p < ep) {
|
|
|
|
register u_char metric;
|
|
|
|
register u_char thresh;
|
|
|
|
register u_char flags;
|
|
|
|
register int ncount;
|
1995-06-13 18:05:16 +00:00
|
|
|
register u_int32 laddr = *(u_int32*)p;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
p += 4;
|
|
|
|
metric = *p++;
|
|
|
|
thresh = *p++;
|
|
|
|
flags = *p++;
|
|
|
|
ncount = *p++;
|
1995-06-13 18:05:16 +00:00
|
|
|
if (broken_cisco && ncount == 0) /* dumb Ciscos */
|
|
|
|
ncount = 1;
|
|
|
|
if (broken_cisco && ncount > 15) /* dumb Ciscos */
|
|
|
|
ncount = ncount & 0xf;
|
|
|
|
while (--ncount >= 0 && p < ep) {
|
|
|
|
register u_int32 neighbor = *(u_int32*)p;
|
1994-09-08 00:26:13 +00:00
|
|
|
p += 4;
|
|
|
|
printf(" %s -> ", inet_fmt(laddr, s1));
|
|
|
|
printf("%s (%s) [%d/%d", inet_fmt(neighbor, s1),
|
|
|
|
inet_name(neighbor), metric, thresh);
|
|
|
|
if (flags & DVMRP_NF_TUNNEL)
|
|
|
|
printf("/tunnel");
|
|
|
|
if (flags & DVMRP_NF_SRCRT)
|
|
|
|
printf("/srcrt");
|
1995-06-13 18:05:16 +00:00
|
|
|
if (flags & DVMRP_NF_PIM)
|
|
|
|
printf("/pim");
|
1994-09-08 00:26:13 +00:00
|
|
|
if (flags & DVMRP_NF_QUERIER)
|
|
|
|
printf("/querier");
|
|
|
|
if (flags & DVMRP_NF_DISABLED)
|
|
|
|
printf("/disabled");
|
|
|
|
if (flags & DVMRP_NF_DOWN)
|
|
|
|
printf("/down");
|
1995-06-13 18:05:16 +00:00
|
|
|
if (flags & DVMRP_NF_LEAF)
|
|
|
|
printf("/leaf");
|
1994-09-08 00:26:13 +00:00
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
int
|
1994-09-08 00:26:13 +00:00
|
|
|
get_number(var, deflt, pargv, pargc)
|
|
|
|
int *var, *pargc, deflt;
|
|
|
|
char ***pargv;
|
|
|
|
{
|
|
|
|
if ((*pargv)[0][2] == '\0') { /* Get the value from the next
|
|
|
|
* argument */
|
|
|
|
if (*pargc > 1 && isdigit((*pargv)[1][0])) {
|
|
|
|
(*pargv)++, (*pargc)--;
|
|
|
|
*var = atoi((*pargv)[0]);
|
|
|
|
return 1;
|
|
|
|
} else if (deflt >= 0) {
|
|
|
|
*var = deflt;
|
|
|
|
return 1;
|
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
} else { /* Get value from the rest of this argument */
|
|
|
|
if (isdigit((*pargv)[0][2])) {
|
|
|
|
*var = atoi((*pargv)[0] + 2);
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32
|
1994-09-08 00:26:13 +00:00
|
|
|
host_addr(name)
|
|
|
|
char *name;
|
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
struct hostent *e;
|
|
|
|
u_int32 addr;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
addr = inet_addr(name);
|
|
|
|
if ((int)addr == -1) {
|
|
|
|
e = gethostbyname(name);
|
|
|
|
if (e == NULL || e->h_length != sizeof(addr))
|
|
|
|
return (0);
|
1994-09-08 00:26:13 +00:00
|
|
|
memcpy(&addr, e->h_addr_list[0], e->h_length);
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
return(addr);
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: mrinfo [-n] [-t timeout] [-r retries] [router]\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
int
|
|
|
|
main(argc, argv)
|
1994-09-08 00:26:13 +00:00
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
1995-06-28 17:58:49 +00:00
|
|
|
int tries = 0;
|
|
|
|
int trynew = 1;
|
|
|
|
struct timeval et;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
setlinebuf(stderr);
|
|
|
|
|
|
|
|
if (geteuid() != 0) {
|
1995-06-13 18:05:16 +00:00
|
|
|
fprintf(stderr, "mrinfo: must be root\n");
|
1994-09-08 00:26:13 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
argv++, argc--;
|
|
|
|
while (argc > 0 && argv[0][0] == '-') {
|
|
|
|
switch (argv[0][1]) {
|
|
|
|
case 'd':
|
|
|
|
if (!get_number(&debug, DEFAULT_DEBUG, &argv, &argc))
|
1995-06-13 18:05:16 +00:00
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
++nflag;
|
1994-09-08 00:26:13 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (!get_number(&retries, -1, &argv, &argc))
|
1995-06-13 18:05:16 +00:00
|
|
|
usage();
|
1994-09-08 00:26:13 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (!get_number(&timeout, -1, &argv, &argc))
|
1995-06-13 18:05:16 +00:00
|
|
|
usage();
|
1994-09-08 00:26:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
1995-06-13 18:05:16 +00:00
|
|
|
usage();
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
argv++, argc--;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
if (argc > 1)
|
|
|
|
usage();
|
|
|
|
if (argc == 1)
|
|
|
|
target_addr = host_addr(argv[0]);
|
|
|
|
else
|
|
|
|
target_addr = host_addr("127.0.0.1");
|
|
|
|
|
|
|
|
if (target_addr == 0) {
|
|
|
|
fprintf(stderr, "mrinfo: %s: no such host\n", argv[0]);
|
1994-09-08 00:26:13 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (debug)
|
|
|
|
fprintf(stderr, "Debug level %u\n", debug);
|
|
|
|
|
|
|
|
init_igmp();
|
|
|
|
|
|
|
|
{ /* Find a good local address for us. */
|
|
|
|
int udp;
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
int addrlen = sizeof(addr);
|
|
|
|
|
|
|
|
addr.sin_family = AF_INET;
|
1995-06-13 18:05:16 +00:00
|
|
|
#if (defined(BSD) && (BSD >= 199103))
|
1994-09-08 02:51:37 +00:00
|
|
|
addr.sin_len = sizeof addr;
|
1995-06-13 18:05:16 +00:00
|
|
|
#endif
|
1994-09-08 00:26:13 +00:00
|
|
|
addr.sin_addr.s_addr = target_addr;
|
|
|
|
addr.sin_port = htons(2000); /* any port over 1024 will
|
|
|
|
* do... */
|
|
|
|
if ((udp = socket(AF_INET, SOCK_DGRAM, 0)) < 0
|
|
|
|
|| connect(udp, (struct sockaddr *) & addr, sizeof(addr)) < 0
|
|
|
|
|| getsockname(udp, (struct sockaddr *) & addr, &addrlen) < 0) {
|
|
|
|
perror("Determining local address");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
close(udp);
|
|
|
|
our_addr = addr.sin_addr.s_addr;
|
|
|
|
}
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
/*
|
|
|
|
* New strategy: send 'ask2' for two timeouts, then fall back
|
|
|
|
* to 'ask', since it's not very likely that we are going to
|
|
|
|
* find someone who only responds to 'ask' these days
|
|
|
|
*/
|
|
|
|
ask2(target_addr);
|
|
|
|
|
|
|
|
gettimeofday(&et, 0);
|
|
|
|
et.tv_sec += timeout;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/* Main receive loop */
|
|
|
|
for (;;) {
|
|
|
|
fd_set fds;
|
1995-06-28 17:58:49 +00:00
|
|
|
struct timeval tv, now;
|
1994-09-08 00:26:13 +00:00
|
|
|
int count, recvlen, dummy = 0;
|
1995-06-13 18:05:16 +00:00
|
|
|
register u_int32 src, dst, group;
|
1994-09-08 00:26:13 +00:00
|
|
|
struct ip *ip;
|
|
|
|
struct igmp *igmp;
|
|
|
|
int ipdatalen, iphdrlen, igmpdatalen;
|
|
|
|
|
|
|
|
FD_ZERO(&fds);
|
|
|
|
FD_SET(igmp_socket, &fds);
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
gettimeofday(&now, 0);
|
|
|
|
tv.tv_sec = et.tv_sec - now.tv_sec;
|
|
|
|
tv.tv_usec = et.tv_usec - now.tv_usec;
|
|
|
|
|
|
|
|
if (tv.tv_usec < 0) {
|
|
|
|
tv.tv_usec += 1000000L;
|
|
|
|
--tv.tv_sec;
|
|
|
|
}
|
|
|
|
if (tv.tv_sec < 0)
|
|
|
|
tv.tv_sec = tv.tv_usec = 0;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
count = select(igmp_socket + 1, &fds, 0, 0, &tv);
|
|
|
|
|
|
|
|
if (count < 0) {
|
|
|
|
if (errno != EINTR)
|
|
|
|
perror("select");
|
|
|
|
continue;
|
|
|
|
} else if (count == 0) {
|
|
|
|
log(LOG_DEBUG, 0, "Timed out receiving neighbor lists");
|
1995-06-28 17:58:49 +00:00
|
|
|
if (++tries > retries)
|
1994-09-08 00:26:13 +00:00
|
|
|
exit(1);
|
1995-06-28 17:58:49 +00:00
|
|
|
/* If we've tried ASK_NEIGHBORS2 twice with
|
|
|
|
* no response, fall back to ASK_NEIGHBORS
|
|
|
|
*/
|
|
|
|
if (tries == 2 && target_level == 0)
|
|
|
|
trynew = 0;
|
|
|
|
if (target_level == 0 && trynew == 0)
|
1994-09-08 00:26:13 +00:00
|
|
|
ask(target_addr);
|
|
|
|
else
|
|
|
|
ask2(target_addr);
|
1995-07-10 16:13:05 +00:00
|
|
|
gettimeofday(&et, 0);
|
|
|
|
et.tv_sec += timeout;
|
1994-09-08 00:26:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
recvlen = recvfrom(igmp_socket, recv_buf, RECV_BUF_SIZE,
|
1994-09-08 00:26:13 +00:00
|
|
|
0, NULL, &dummy);
|
|
|
|
if (recvlen <= 0) {
|
|
|
|
if (recvlen && errno != EINTR)
|
|
|
|
perror("recvfrom");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recvlen < sizeof(struct ip)) {
|
|
|
|
log(LOG_WARNING, 0,
|
|
|
|
"packet too short (%u bytes) for IP header",
|
|
|
|
recvlen);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ip = (struct ip *) recv_buf;
|
1995-05-16 00:28:50 +00:00
|
|
|
if (ip->ip_p == 0)
|
|
|
|
continue; /* Request to install cache entry */
|
1994-09-08 00:26:13 +00:00
|
|
|
src = ip->ip_src.s_addr;
|
|
|
|
dst = ip->ip_dst.s_addr;
|
|
|
|
iphdrlen = ip->ip_hl << 2;
|
|
|
|
ipdatalen = ip->ip_len;
|
|
|
|
if (iphdrlen + ipdatalen != recvlen) {
|
|
|
|
log(LOG_WARNING, 0,
|
|
|
|
"packet shorter (%u bytes) than hdr+data length (%u+%u)",
|
|
|
|
recvlen, iphdrlen, ipdatalen);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
igmp = (struct igmp *) (recv_buf + iphdrlen);
|
|
|
|
group = igmp->igmp_group.s_addr;
|
|
|
|
igmpdatalen = ipdatalen - IGMP_MINLEN;
|
|
|
|
if (igmpdatalen < 0) {
|
|
|
|
log(LOG_WARNING, 0,
|
|
|
|
"IP data field too short (%u bytes) for IGMP, from %s",
|
|
|
|
ipdatalen, inet_fmt(src, s1));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (igmp->igmp_type != IGMP_DVMRP)
|
|
|
|
continue;
|
|
|
|
|
1995-05-16 00:28:50 +00:00
|
|
|
switch (igmp->igmp_code) {
|
|
|
|
case DVMRP_NEIGHBORS:
|
|
|
|
case DVMRP_NEIGHBORS2:
|
|
|
|
if (src != target_addr) {
|
|
|
|
fprintf(stderr, "mrinfo: got reply from %s",
|
|
|
|
inet_fmt(src, s1));
|
|
|
|
fprintf(stderr, " instead of %s\n",
|
|
|
|
inet_fmt(target_addr, s1));
|
1995-06-13 18:05:16 +00:00
|
|
|
/*continue;*/
|
1995-05-16 00:28:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue; /* ignore all other DVMRP messages */
|
|
|
|
}
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
switch (igmp->igmp_code) {
|
|
|
|
|
|
|
|
case DVMRP_NEIGHBORS:
|
|
|
|
if (group) {
|
|
|
|
/* knows about DVMRP_NEIGHBORS2 msg */
|
|
|
|
if (target_level == 0) {
|
|
|
|
target_level = ntohl(group);
|
|
|
|
ask2(target_addr);
|
|
|
|
}
|
|
|
|
} else {
|
1995-06-28 17:58:49 +00:00
|
|
|
accept_neighbors(src, dst, (u_char *)(igmp + 1),
|
|
|
|
igmpdatalen, ntohl(group));
|
1994-09-08 00:26:13 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DVMRP_NEIGHBORS2:
|
1995-06-28 17:58:49 +00:00
|
|
|
accept_neighbors2(src, dst, (u_char *)(igmp + 1),
|
|
|
|
igmpdatalen, ntohl(group));
|
1994-09-08 00:26:13 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dummies */
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_probe(src, dst, p, datalen, level)
|
|
|
|
u_int32 src, dst, level;
|
|
|
|
char *p;
|
|
|
|
int datalen;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_group_report(src, dst, group, r_type)
|
|
|
|
u_int32 src, dst, group;
|
|
|
|
int r_type;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_neighbor_request2(src, dst)
|
|
|
|
u_int32 src, dst;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_report(src, dst, p, datalen, level)
|
|
|
|
u_int32 src, dst, level;
|
|
|
|
char *p;
|
|
|
|
int datalen;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_neighbor_request(src, dst)
|
|
|
|
u_int32 src, dst;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_prune(src, dst, p, datalen)
|
|
|
|
u_int32 src, dst;
|
|
|
|
char *p;
|
|
|
|
int datalen;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_graft(src, dst, p, datalen)
|
|
|
|
u_int32 src, dst;
|
|
|
|
char *p;
|
|
|
|
int datalen;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_g_ack(src, dst, p, datalen)
|
|
|
|
u_int32 src, dst;
|
|
|
|
char *p;
|
|
|
|
int datalen;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void add_table_entry(origin, mcastgrp)
|
|
|
|
u_int32 origin, mcastgrp;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
void check_vif_state()
|
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_leave_message(src, dst, group)
|
|
|
|
u_int32 src, dst, group;
|
1995-06-13 18:05:16 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_mtrace(src, dst, group, data, no, datalen)
|
|
|
|
u_int32 src, dst, group;
|
|
|
|
char *data;
|
|
|
|
u_int no;
|
|
|
|
int datalen;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
1995-06-28 17:58:49 +00:00
|
|
|
void accept_membership_query(src, dst, group, tmo)
|
|
|
|
u_int32 src, dst, group;
|
|
|
|
int tmo;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
}
|