Virgin import of rhyolite.com routed v2.27

This commit is contained in:
Bruce M Simpson 2004-02-25 23:20:22 +00:00
parent 8b336df137
commit caa79e368e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/SGI/dist_v_2_21/; revision=126247
14 changed files with 375 additions and 180 deletions

View File

@ -33,12 +33,10 @@
* @(#)defs.h 8.1 (Berkeley) 6/5/93 * @(#)defs.h 8.1 (Berkeley) 6/5/93
* *
* $NetBSD$ * $NetBSD$
* $FreeBSD$
* "$Revision: 2.27 $"
*/ */
#ifdef sgi
#ident "$Revision: 2.17 $"
#endif
/* Definitions for RIPv2 routing process. /* Definitions for RIPv2 routing process.
* *
* This code is based on the 4.4BSD `routed` daemon, with extensions to * This code is based on the 4.4BSD `routed` daemon, with extensions to
@ -100,6 +98,12 @@
#define RIPVERSION RIPv2 #define RIPVERSION RIPv2
#include <protocols/routed.h> #include <protocols/routed.h>
#ifndef __RCSID
#define __RCSID(_s) static const char rcsid[] UNUSED = _s
#endif
#ifndef __COPYRIGHT
#define __COPYRIGHT(_s) static const char copyright[] UNUSED = _s
#endif
/* Type of an IP address. /* Type of an IP address.
* Some systems do not like to pass structures, so do not use in_addr. * Some systems do not like to pass structures, so do not use in_addr.
@ -119,11 +123,19 @@
#define _HAVE_SIN_LEN #define _HAVE_SIN_LEN
#endif #endif
/* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at /* Turn on if IP_{ADD,DROP}_MEMBERSHIP and IP_MULTICAST_IF considers address
* the dstaddr of point-to-point interfaces. * within 0.0.0.0/8 as interface index.
*/ */
#ifdef __NetBSD__ #ifdef __NetBSD__
#define MCAST_PPP_BUG #define MCAST_IFINDEX
#endif
/* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at
* the dstaddr of point-to-point interfaces.
* #define MCAST_PPP_BUG
*/
#ifdef MCAST_IFINDEX
#undef MCAST_PPP_BUG
#endif #endif
#define DAY (24*60*60) #define DAY (24*60*60)
@ -290,7 +302,9 @@ struct interface {
time_t int_query_time; time_t int_query_time;
u_short int_transitions; /* times gone up-down */ u_short int_transitions; /* times gone up-down */
char int_metric; char int_metric;
char int_d_metric; /* for faked default route */ u_char int_d_metric; /* for faked default route */
u_char int_adj_inmetric; /* adjust advertised metrics */
u_char int_adj_outmetric; /* instead of interface metric */
struct int_data { struct int_data {
u_int ipackets; /* previous network stats */ u_int ipackets; /* previous network stats */
u_int ierrors; u_int ierrors;
@ -399,7 +413,9 @@ extern struct parm {
naddr parm_net; naddr parm_net;
naddr parm_mask; naddr parm_mask;
char parm_d_metric; u_char parm_d_metric;
u_char parm_adj_inmetric;
char parm_adj_outmetric;
u_int parm_int_state; u_int parm_int_state;
int parm_rdisc_pref; /* signed IRDP preference */ int parm_rdisc_pref; /* signed IRDP preference */
int parm_rdisc_int; /* IRDP advertising interval */ int parm_rdisc_int; /* IRDP advertising interval */
@ -645,6 +661,9 @@ extern struct interface *iflookup(naddr);
extern struct auth *find_auth(struct interface *); extern struct auth *find_auth(struct interface *);
extern void end_md5_auth(struct ws_buf *, struct auth *); extern void end_md5_auth(struct ws_buf *, struct auth *);
#if defined(__FreeBSD__) || defined(__NetBSD__)
#include <md5.h>
#else
#define MD5_DIGEST_LEN 16 #define MD5_DIGEST_LEN 16
typedef struct { typedef struct {
u_int32_t state[4]; /* state (ABCD) */ u_int32_t state[4]; /* state (ABCD) */
@ -654,3 +673,4 @@ typedef struct {
extern void MD5Init(MD5_CTX*); extern void MD5Init(MD5_CTX*);
extern void MD5Update(MD5_CTX*, u_char*, u_int); extern void MD5Update(MD5_CTX*, u_char*, u_int);
extern void MD5Final(u_char[MD5_DIGEST_LEN], MD5_CTX*); extern void MD5Final(u_char[MD5_DIGEST_LEN], MD5_CTX*);
#endif

View File

@ -34,13 +34,14 @@
#include "defs.h" #include "defs.h"
#include "pathnames.h" #include "pathnames.h"
#if !defined(sgi) && !defined(__NetBSD__) #ifdef __NetBSD__
static char sccsid[] __attribute__((unused)) = "@(#)if.c 8.1 (Berkeley) 6/5/93";
#elif defined(__NetBSD__)
#include <sys/cdefs.h>
__RCSID("$NetBSD$"); __RCSID("$NetBSD$");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.27 $");
#ident "$Revision: 2.27 $"
#endif #endif
#ident "$Revision: 2.22 $"
struct interface *ifnet; /* all interfaces */ struct interface *ifnet; /* all interfaces */
@ -212,14 +213,14 @@ ifwithname(char *name, /* "ec0" or whatever */
struct interface * struct interface *
ifwithindex(u_short index, ifwithindex(u_short ifindex,
int rescan_ok) int rescan_ok)
{ {
struct interface *ifp; struct interface *ifp;
for (;;) { for (;;) {
for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) { for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) {
if (ifp->int_index == index) if (ifp->int_index == ifindex)
return ifp; return ifp;
} }
@ -242,6 +243,7 @@ struct interface *
iflookup(naddr addr) iflookup(naddr addr)
{ {
struct interface *ifp, *maybe; struct interface *ifp, *maybe;
int once = 0;
maybe = 0; maybe = 0;
for (;;) { for (;;) {
@ -265,9 +267,9 @@ iflookup(naddr addr)
} }
} }
if (maybe != 0 if (maybe != 0 || once || IF_RESCAN_DELAY())
|| IF_RESCAN_DELAY())
return maybe; return maybe;
once = 1;
/* If there is no known interface, maybe there is a /* If there is no known interface, maybe there is a
* new interface. So just once look for new interfaces. * new interface. So just once look for new interfaces.
@ -404,7 +406,8 @@ check_dup(naddr addr, /* IP address, so network byte order */
/* The local address can only be shared with a point-to-point /* The local address can only be shared with a point-to-point
* link. * link.
*/ */
if (ifp->int_addr == addr if ((!(ifp->int_state & IS_REMOTE) || !(if_flags & IS_REMOTE))
&& ifp->int_addr == addr
&& (((if_flags|ifp->int_if_flags) & IFF_POINTOPOINT) == 0)) && (((if_flags|ifp->int_if_flags) & IFF_POINTOPOINT) == 0))
return ifp; return ifp;
@ -496,10 +499,14 @@ ifdel(struct interface *ifp)
#endif #endif
&& rip_sock >= 0) { && rip_sock >= 0) {
m.imr_multiaddr.s_addr = htonl(INADDR_RIP_GROUP); m.imr_multiaddr.s_addr = htonl(INADDR_RIP_GROUP);
#ifdef MCAST_IFINDEX
m.imr_interface.s_addr = htonl(ifp->int_index);
#else
m.imr_interface.s_addr = ((ifp->int_if_flags m.imr_interface.s_addr = ((ifp->int_if_flags
& IFF_POINTOPOINT) & IFF_POINTOPOINT)
? ifp->int_dstaddr ? ifp->int_dstaddr
: ifp->int_addr); : ifp->int_addr);
#endif
if (setsockopt(rip_sock,IPPROTO_IP,IP_DROP_MEMBERSHIP, if (setsockopt(rip_sock,IPPROTO_IP,IP_DROP_MEMBERSHIP,
&m, sizeof(m)) < 0 &m, sizeof(m)) < 0
&& errno != EADDRNOTAVAIL && errno != EADDRNOTAVAIL
@ -735,6 +742,10 @@ ifinit(void)
ifam2 = (struct ifa_msghdr*)((char*)ifam + ifam->ifam_msglen); ifam2 = (struct ifa_msghdr*)((char*)ifam + ifam->ifam_msglen);
#ifdef RTM_OIFINFO
if (ifam->ifam_type == RTM_OIFINFO)
continue; /* just ignore compat message */
#endif
if (ifam->ifam_type == RTM_IFINFO) { if (ifam->ifam_type == RTM_IFINFO) {
struct sockaddr_dl *sdl; struct sockaddr_dl *sdl;

View File

@ -33,13 +33,14 @@
#include "defs.h" #include "defs.h"
#if !defined(sgi) && !defined(__NetBSD__) #ifdef __NetBSD__
static char sccsid[] __attribute__((unused)) = "@(#)input.c 8.1 (Berkeley) 6/5/93";
#elif defined(__NetBSD__)
#include <sys/cdefs.h>
__RCSID("$NetBSD$"); __RCSID("$NetBSD$");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.26 $");
#ident "$Revision: 2.26 $"
#endif #endif
#ident "$Revision: 2.17 $"
static void input(struct sockaddr_in *, struct interface *, struct interface *, static void input(struct sockaddr_in *, struct interface *, struct interface *,
struct rip *, int); struct rip *, int);
@ -326,9 +327,14 @@ input(struct sockaddr_in *from, /* received from this IP address */
v12buf.n->n_family = RIP_AF_INET; v12buf.n->n_family = RIP_AF_INET;
v12buf.n->n_dst = RIP_DEFAULT; v12buf.n->n_dst = RIP_DEFAULT;
i = aifp->int_d_metric; i = aifp->int_d_metric;
if (0 != (rt = rtget(RIP_DEFAULT, 0))) if (0 != (rt = rtget(RIP_DEFAULT, 0))) {
i = MIN(i, (rt->rt_metric j = (rt->rt_metric
+aifp->int_metric+1)); +aifp->int_metric
+aifp->int_adj_outmetric
+1);
if (i > j)
i = j;
}
v12buf.n->n_metric = htonl(i); v12buf.n->n_metric = htonl(i);
v12buf.n++; v12buf.n++;
break; break;
@ -394,11 +400,15 @@ input(struct sockaddr_in *from, /* received from this IP address */
*/ */
v12buf.n->n_family = RIP_AF_INET; v12buf.n->n_family = RIP_AF_INET;
v12buf.n->n_dst = dst; v12buf.n->n_dst = dst;
v12buf.n->n_metric = (rt->rt_metric+1 j = rt->rt_metric+1;
+ ((aifp!=0) if (!aifp)
? aifp->int_metric ++j;
: 1)); else
if (v12buf.n->n_metric > HOPCNT_INFINITY) j += (aifp->int_metric
+ aifp->int_adj_outmetric);
if (j < HOPCNT_INFINITY)
v12buf.n->n_metric = j;
else
v12buf.n->n_metric = HOPCNT_INFINITY; v12buf.n->n_metric = HOPCNT_INFINITY;
if (v12buf.buf->rip_vers != RIPv1) { if (v12buf.buf->rip_vers != RIPv1) {
v12buf.n->n_tag = rt->rt_tag; v12buf.n->n_tag = rt->rt_tag;
@ -482,7 +492,8 @@ input(struct sockaddr_in *from, /* received from this IP address */
if (from->sin_port != ntohs(RIP_PORT)) { if (from->sin_port != ntohs(RIP_PORT)) {
msglim(&bad_router, FROM_NADDR, msglim(&bad_router, FROM_NADDR,
" discard RIP response from unknown port" " discard RIP response from unknown port"
" %d", from->sin_port); " %d on %s",
ntohs(from->sin_port), naddr_ntoa(FROM_NADDR));
return; return;
} }
@ -651,7 +662,8 @@ input(struct sockaddr_in *from, /* received from this IP address */
/* Adjust metric according to incoming interface.. /* Adjust metric according to incoming interface..
*/ */
n->n_metric += aifp->int_metric; n->n_metric += (aifp->int_metric
+ aifp->int_adj_inmetric);
if (n->n_metric > HOPCNT_INFINITY) if (n->n_metric > HOPCNT_INFINITY)
n->n_metric = HOPCNT_INFINITY; n->n_metric = HOPCNT_INFINITY;
@ -964,12 +976,12 @@ ck_passwd(struct interface *aifp,
*/ */
if (TRACEPACKETS) { if (TRACEPACKETS) {
if (NA->au.a_md5.md5_auth_len if (NA->au.a_md5.md5_auth_len
!= RIP_AUTH_MD5_LEN) != RIP_AUTH_MD5_HASH_LEN)
msglim(use_authp, from, msglim(use_authp, from,
"unknown MD5 RIPv2 auth len %#x" "unknown MD5 RIPv2 auth len %#x"
" instead of %#x from %s", " instead of %#x from %s",
NA->au.a_md5.md5_auth_len, NA->au.a_md5.md5_auth_len,
RIP_AUTH_MD5_LEN, RIP_AUTH_MD5_HASH_LEN,
naddr_ntoa(from)); naddr_ntoa(from));
if (na2->a_family != RIP_AF_AUTH) if (na2->a_family != RIP_AF_AUTH)
msglim(use_authp, from, msglim(use_authp, from,
@ -986,8 +998,9 @@ ck_passwd(struct interface *aifp,
} }
MD5Init(&md5_ctx); MD5Init(&md5_ctx);
MD5Update(&md5_ctx, (u_char *)rip, len); MD5Update(&md5_ctx, (u_char *)rip,
MD5Update(&md5_ctx, ap->key, RIP_AUTH_MD5_LEN); len + RIP_AUTH_MD5_HASH_XTRA);
MD5Update(&md5_ctx, ap->key, RIP_AUTH_MD5_KEY_LEN);
MD5Final(hash, &md5_ctx); MD5Final(hash, &md5_ctx);
if (!memcmp(hash, na2->au.au_pw, sizeof(hash))) if (!memcmp(hash, na2->au.au_pw, sizeof(hash)))
return 1; return 1;

View File

@ -40,18 +40,18 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/file.h> #include <sys/file.h>
#if !defined(sgi) && !defined(__NetBSD__) __COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993\n"
char copyright[] = "The Regents of the University of California."
"@(#) Copyright (c) 1983, 1988, 1993\n\ " All rights reserved.\n");
The Regents of the University of California. All rights reserved.\n"; #ifdef __NetBSD__
static char sccsid[] __attribute__((unused)) = "@(#)main.c 8.1 (Berkeley) 6/5/93";
#elif defined(__NetBSD__)
__RCSID("$NetBSD$"); __RCSID("$NetBSD$");
__COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993\n\ #include <util.h>
The Regents of the University of California. All rights reserved.\n"); #elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.27 $");
#ident "$Revision: 2.27 $"
#endif #endif
#ident "$Revision: 2.22 $"
pid_t mypid; pid_t mypid;
@ -119,7 +119,7 @@ main(int argc,
*/ */
signal(SIGHUP, SIG_IGN); signal(SIGHUP, SIG_IGN);
openlog("routed", LOG_PID | LOG_ODELAY, LOG_DAEMON); openlog("routed", LOG_PID, LOG_DAEMON);
ftrace = stdout; ftrace = stdout;
gettimeofday(&clk, 0); gettimeofday(&clk, 0);
@ -221,7 +221,7 @@ main(int argc,
case 'v': case 'v':
/* display version */ /* display version */
verbose++; verbose++;
msglog("version 2.22"); msglog("version 2.25");
break; break;
default: default:
@ -294,6 +294,9 @@ main(int argc,
BADERR(0,"daemon()"); BADERR(0,"daemon()");
#endif #endif
#if defined(__NetBSD__)
pidfile(0);
#endif
mypid = getpid(); mypid = getpid();
srandom((int)(clk.tv_sec ^ clk.tv_usec ^ mypid)); srandom((int)(clk.tv_sec ^ clk.tv_usec ^ mypid));
@ -638,7 +641,7 @@ static int /* <0 or file descriptor */
get_rip_sock(naddr addr, get_rip_sock(naddr addr,
int serious) /* 1=failure to bind is serious */ int serious) /* 1=failure to bind is serious */
{ {
struct sockaddr_in sin; struct sockaddr_in rsin;
unsigned char ttl; unsigned char ttl;
int s; int s;
@ -646,14 +649,14 @@ get_rip_sock(naddr addr,
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
BADERR(1,"rip_sock = socket()"); BADERR(1,"rip_sock = socket()");
memset(&sin, 0, sizeof(sin)); memset(&rsin, 0, sizeof(rsin));
#ifdef _HAVE_SIN_LEN #ifdef _HAVE_SIN_LEN
sin.sin_len = sizeof(sin); rsin.sin_len = sizeof(rsin);
#endif #endif
sin.sin_family = AF_INET; rsin.sin_family = AF_INET;
sin.sin_port = htons(RIP_PORT); rsin.sin_port = htons(RIP_PORT);
sin.sin_addr.s_addr = addr; rsin.sin_addr.s_addr = addr;
if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { if (bind(s, (struct sockaddr *)&rsin, sizeof(rsin)) < 0) {
if (serious) if (serious)
BADERR(errno != EADDRINUSE, "bind(rip_sock)"); BADERR(errno != EADDRINUSE, "bind(rip_sock)");
return -1; return -1;
@ -717,9 +720,13 @@ rip_mcast_on(struct interface *ifp)
#endif #endif
&& !(ifp->int_state & IS_ALIAS)) { && !(ifp->int_state & IS_ALIAS)) {
m.imr_multiaddr.s_addr = htonl(INADDR_RIP_GROUP); m.imr_multiaddr.s_addr = htonl(INADDR_RIP_GROUP);
#ifdef MCAST_IFINDEX
m.imr_interface.s_addr = htonl(ifp->int_index);
#else
m.imr_interface.s_addr = ((ifp->int_if_flags & IFF_POINTOPOINT) m.imr_interface.s_addr = ((ifp->int_if_flags & IFF_POINTOPOINT)
? ifp->int_dstaddr ? ifp->int_dstaddr
: ifp->int_addr); : ifp->int_addr);
#endif
if (setsockopt(rip_sock,IPPROTO_IP, IP_ADD_MEMBERSHIP, if (setsockopt(rip_sock,IPPROTO_IP, IP_ADD_MEMBERSHIP,
&m, sizeof(m)) < 0) &m, sizeof(m)) < 0)
LOGERR("setsockopt(IP_ADD_MEMBERSHIP RIP)"); LOGERR("setsockopt(IP_ADD_MEMBERSHIP RIP)");
@ -861,6 +868,7 @@ msglog(const char *p, ...)
(void)vfprintf(ftrace, p, args); (void)vfprintf(ftrace, p, args);
(void)fputc('\n', ftrace); (void)fputc('\n', ftrace);
} }
va_end(args);
} }
@ -923,6 +931,7 @@ msglim(struct msg_limit *lim, naddr addr, const char *p, ...)
(void)vfprintf(ftrace, p, args); (void)vfprintf(ftrace, p, args);
(void)fputc('\n', ftrace); (void)fputc('\n', ftrace);
} }
va_end(args);
} }
@ -940,6 +949,7 @@ logbad(int dump, const char *p, ...)
(void)vfprintf(stderr, p, args); (void)vfprintf(stderr, p, args);
(void)fputs("; giving up\n",stderr); (void)fputs("; giving up\n",stderr);
(void)fflush(stderr); (void)fflush(stderr);
va_end(args);
if (dump) if (dump)
abort(); abort();

View File

@ -33,12 +33,14 @@
#include "defs.h" #include "defs.h"
#if !defined(sgi) && !defined(__NetBSD__) #ifdef __NetBSD__
static char sccsid[] __attribute__((unused)) = "@(#)output.c 8.1 (Berkeley) 6/5/93";
#elif defined(__NetBSD__)
__RCSID("$NetBSD$"); __RCSID("$NetBSD$");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.27 $");
#ident "$Revision: 2.27 $"
#endif #endif
#ident "$Revision: 2.21 $"
u_int update_seqno; u_int update_seqno;
@ -100,7 +102,7 @@ output(enum output_type type,
struct rip *buf, struct rip *buf,
int size) /* this many bytes */ int size) /* this many bytes */
{ {
struct sockaddr_in sin; struct sockaddr_in osin;
int flags; int flags;
const char *msg; const char *msg;
int res; int res;
@ -108,12 +110,12 @@ output(enum output_type type,
int soc; int soc;
int serrno; int serrno;
sin = *dst; osin = *dst;
if (sin.sin_port == 0) if (osin.sin_port == 0)
sin.sin_port = htons(RIP_PORT); osin.sin_port = htons(RIP_PORT);
#ifdef _HAVE_SIN_LEN #ifdef _HAVE_SIN_LEN
if (sin.sin_len == 0) if (osin.sin_len == 0)
sin.sin_len = sizeof(sin); osin.sin_len = sizeof(osin);
#endif #endif
soc = rip_sock; soc = rip_sock;
@ -150,6 +152,10 @@ output(enum output_type type,
} else { } else {
msg = "Send mcast"; msg = "Send mcast";
if (rip_sock_mcast != ifp) { if (rip_sock_mcast != ifp) {
#ifdef MCAST_IFINDEX
/* specify ifindex */
tgt_mcast = htonl(ifp->int_index);
#else
#ifdef MCAST_PPP_BUG #ifdef MCAST_PPP_BUG
/* Do not specify the primary interface /* Do not specify the primary interface
* explicitly if we have the multicast * explicitly if we have the multicast
@ -164,6 +170,7 @@ output(enum output_type type,
} else } else
#endif #endif
tgt_mcast = ifp->int_addr; tgt_mcast = ifp->int_addr;
#endif
if (0 > setsockopt(rip_sock, if (0 > setsockopt(rip_sock,
IPPROTO_IP, IP_MULTICAST_IF, IPPROTO_IP, IP_MULTICAST_IF,
&tgt_mcast, &tgt_mcast,
@ -177,7 +184,7 @@ output(enum output_type type,
} }
rip_sock_mcast = ifp; rip_sock_mcast = ifp;
} }
sin.sin_addr.s_addr = htonl(INADDR_RIP_GROUP); osin.sin_addr.s_addr = htonl(INADDR_RIP_GROUP);
} }
break; break;
@ -190,18 +197,18 @@ output(enum output_type type,
return -1; return -1;
} }
trace_rip(msg, "to", &sin, ifp, buf, size); trace_rip(msg, "to", &osin, ifp, buf, size);
res = sendto(soc, buf, size, flags, res = sendto(soc, buf, size, flags,
(struct sockaddr *)&sin, sizeof(sin)); (struct sockaddr *)&osin, sizeof(osin));
if (res < 0 if (res < 0
&& (ifp == 0 || !(ifp->int_state & IS_BROKE))) { && (ifp == 0 || !(ifp->int_state & IS_BROKE))) {
serrno = errno; serrno = errno;
msglog("%s sendto(%s%s%s.%d): %s", msg, msglog("%s sendto(%s%s%s.%d): %s", msg,
ifp != 0 ? ifp->int_name : "", ifp != 0 ? ifp->int_name : "",
ifp != 0 ? ", " : "", ifp != 0 ? ", " : "",
inet_ntoa(sin.sin_addr), inet_ntoa(osin.sin_addr),
ntohs(sin.sin_port), ntohs(osin.sin_port),
strerror(errno)); strerror(errno));
errno = serrno; errno = serrno;
} }
@ -277,7 +284,7 @@ clr_ws_buf(struct ws_buf *wb,
na->a_family = RIP_AF_AUTH; na->a_family = RIP_AF_AUTH;
na->a_type = RIP_AUTH_MD5; na->a_type = RIP_AUTH_MD5;
na->au.a_md5.md5_keyid = ap->keyid; na->au.a_md5.md5_keyid = ap->keyid;
na->au.a_md5.md5_auth_len = RIP_AUTH_MD5_LEN; na->au.a_md5.md5_auth_len = RIP_AUTH_MD5_KEY_LEN;
na->au.a_md5.md5_seqno = htonl(clk.tv_sec); na->au.a_md5.md5_seqno = htonl(clk.tv_sec);
wb->n++; wb->n++;
wb->lim--; /* make room for trailer */ wb->lim--; /* make room for trailer */
@ -301,8 +308,8 @@ end_md5_auth(struct ws_buf *wb,
na2->a_type = htons(1); na2->a_type = htons(1);
na->au.a_md5.md5_pkt_len = htons(len); na->au.a_md5.md5_pkt_len = htons(len);
MD5Init(&md5_ctx); MD5Init(&md5_ctx);
MD5Update(&md5_ctx, (u_char *)wb->buf, len); MD5Update(&md5_ctx, (u_char *)wb->buf, len + RIP_AUTH_MD5_HASH_XTRA);
MD5Update(&md5_ctx, ap->key, RIP_AUTH_MD5_LEN); MD5Update(&md5_ctx, ap->key, RIP_AUTH_MD5_KEY_LEN);
MD5Final(na2->au.au_pw, &md5_ctx); MD5Final(na2->au.au_pw, &md5_ctx);
wb->n++; wb->n++;
} }
@ -545,8 +552,7 @@ walk_supply(struct radix_node *rn,
* without confusing RIPv1 listeners into thinking the * without confusing RIPv1 listeners into thinking the
* network routes are host routes. * network routes are host routes.
*/ */
if ((ws.state & WS_ST_AG) if ((ws.state & WS_ST_AG) && (ws.state & WS_ST_RIP2_ALL))
&& !(ws.state & WS_ST_RIP2_ALL))
ags |= AGS_AGGREGATE; ags |= AGS_AGGREGATE;
} else { } else {
@ -590,6 +596,11 @@ walk_supply(struct radix_node *rn,
* *
* Notice spare routes with the same metric that we are about to * Notice spare routes with the same metric that we are about to
* advertise, to split the horizon on redundant, inactive paths. * advertise, to split the horizon on redundant, inactive paths.
*
* Do not suppress advertisements of interface-related addresses on
* non-point-to-point interfaces. This ensures that we have something
* to say every 30 seconds to help detect broken Ethernets or
* other interfaces where one packet every 30 seconds costs nothing.
*/ */
if (ws.ifp != 0 if (ws.ifp != 0
&& !(ws.state & WS_ST_QUERY) && !(ws.state & WS_ST_QUERY)
@ -709,7 +720,7 @@ supply(struct sockaddr_in *dst,
/* Adjust the advertised metric by the outgoing interface /* Adjust the advertised metric by the outgoing interface
* metric. * metric.
*/ */
ws.metric = ifp->int_metric+1; ws.metric = ifp->int_metric + 1 + ifp->int_adj_outmetric;
} }
ripv12_buf.rip.rip_vers = vers; ripv12_buf.rip.rip_vers = vers;

View File

@ -35,12 +35,14 @@
#include "pathnames.h" #include "pathnames.h"
#include <sys/stat.h> #include <sys/stat.h>
#if !defined(sgi) && !defined(__NetBSD__) #ifdef __NetBSD__
static char sccsid[] __attribute__((unused)) = "@(#)if.c 8.1 (Berkeley) 6/5/93";
#elif defined(__NetBSD__)
__RCSID("$NetBSD$"); __RCSID("$NetBSD$");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.26 $");
#ident "$Revision: 2.26 $"
#endif #endif
#ident "$Revision: 2.21 $"
struct parm *parms; struct parm *parms;
@ -83,8 +85,10 @@ get_parms(struct interface *ifp)
ifp->int_rdisc_pref = parmp->parm_rdisc_pref; ifp->int_rdisc_pref = parmp->parm_rdisc_pref;
if (parmp->parm_rdisc_int != 0) if (parmp->parm_rdisc_int != 0)
ifp->int_rdisc_int = parmp->parm_rdisc_int; ifp->int_rdisc_int = parmp->parm_rdisc_int;
if (parmp->parm_d_metric != 0) if (parmp->parm_adj_inmetric != 0)
ifp->int_d_metric = parmp->parm_d_metric; ifp->int_adj_inmetric = parmp->parm_adj_inmetric;
if (parmp->parm_adj_outmetric != 0)
ifp->int_adj_outmetric = parmp->parm_adj_outmetric;
} }
} }
@ -311,7 +315,7 @@ gwkludge(void)
if (state & IS_PASSIVE) if (state & IS_PASSIVE)
state |= IS_NO_RIP; state |= IS_NO_RIP;
ifp = check_dup(gate,dst,netmask,0); ifp = check_dup(gate,dst,netmask,state);
if (ifp != 0) { if (ifp != 0) {
msglog("duplicate "_PATH_GATEWAYS" entry \"%s\"",lptr); msglog("duplicate "_PATH_GATEWAYS" entry \"%s\"",lptr);
continue; continue;
@ -755,7 +759,7 @@ parse_parms(char *line,
} else if (PARS("passive")) { } else if (PARS("passive")) {
CKF((GROUP_IS_SOL_OUT|GROUP_IS_ADV_OUT), IS_NO_RDISC); CKF((GROUP_IS_SOL_OUT|GROUP_IS_ADV_OUT), IS_NO_RDISC);
parm.parm_int_state |= IS_NO_RIP| IS_PASSIVE; parm.parm_int_state |= IS_NO_RIP | IS_PASSIVE;
} else if (PARSEQ("rdisc_pref")) { } else if (PARSEQ("rdisc_pref")) {
if (parm.parm_rdisc_pref != 0 if (parm.parm_rdisc_pref != 0
@ -779,10 +783,24 @@ parse_parms(char *line,
} else if (PARSEQ("fake_default")) { } else if (PARSEQ("fake_default")) {
if (parm.parm_d_metric != 0 if (parm.parm_d_metric != 0
|| IS_RIP_OUT_OFF(parm.parm_int_state) || IS_RIP_OUT_OFF(parm.parm_int_state)
|| (parm.parm_d_metric = (int)strtoul(buf,&p,0), || (i = strtoul(buf,&p,0), *p != '\0')
*p != '\0') || i > HOPCNT_INFINITY-1)
|| parm.parm_d_metric > HOPCNT_INFINITY-1)
return bad_str(tgt); return bad_str(tgt);
parm.parm_d_metric = i;
} else if (PARSEQ("adj_inmetric")) {
if (parm.parm_adj_inmetric != 0
|| (i = strtoul(buf,&p,0), *p != '\0')
|| i > HOPCNT_INFINITY-1)
return bad_str(tgt);
parm.parm_adj_inmetric = i;
} else if (PARSEQ("adj_outmetric")) {
if (parm.parm_adj_outmetric != 0
|| (i = strtoul(buf,&p,0), *p != '\0')
|| i > HOPCNT_INFINITY-1)
return bad_str(tgt);
parm.parm_adj_outmetric = i;
} else if (PARSEQ("trust_gateway")) { } else if (PARSEQ("trust_gateway")) {
/* look for trust_gateway=x.y.z|net/mask|...) */ /* look for trust_gateway=x.y.z|net/mask|...) */
@ -892,9 +910,23 @@ check_parms(struct parm *new)
return ("conflicting, duplicate poor man's router" return ("conflicting, duplicate poor man's router"
" discovery or fake default metric"); " discovery or fake default metric");
} }
if (new->parm_adj_inmetric != 0
&& parmp->parm_adj_inmetric != 0
&& new->parm_adj_inmetric != parmp->parm_adj_inmetric) {
return ("conflicting interface input "
"metric adjustments");
}
if (new->parm_adj_outmetric != 0
&& parmp->parm_adj_outmetric != 0
&& new->parm_adj_outmetric != parmp->parm_adj_outmetric) {
return ("conflicting interface output "
"metric adjustments");
}
} }
/* link new entry on the so that when the entries are scanned, /* link new entry on the list so that when the entries are scanned,
* they affect the result in the order the operator specified. * they affect the result in the order the operator specified.
*/ */
parmp = (struct parm*)rtmalloc(sizeof(*parmp), "check_parms"); parmp = (struct parm*)rtmalloc(sizeof(*parmp), "check_parms");

View File

@ -33,6 +33,8 @@
* @(#)pathnames.h 8.1 (Berkeley) 6/5/93 * @(#)pathnames.h 8.1 (Berkeley) 6/5/93
* *
* $NetBSD$ * $NetBSD$
* $FreeBSD$
* $Revision: 2.23 $
*/ */
#include <paths.h> #include <paths.h>
@ -42,7 +44,9 @@
/* All remotely requested trace files must either start with this prefix /* All remotely requested trace files must either start with this prefix
* or be the same as the tracefile specified when the daemon was started. * or be the same as the tracefile specified when the daemon was started.
* If this is a directory, routed will create log files in it. That * If this is a directory, routed will create log files in it. That
* might be a security problem. * might be a security problem. However, if bad guys can write in the
* default value, /etc, you have far worse security problems than anything
* this might do. In other words, it makes no sense to turn this off.
* *
* Leave this undefined, and only the trace file originally specified * Leave this undefined, and only the trace file originally specified
* when routed was started, if any, will be appended to. * when routed was started, if any, will be appended to.

View File

@ -39,12 +39,14 @@
#include "defs.h" #include "defs.h"
#if !defined(sgi) && !defined(__NetBSD__) #ifdef __NetBSD__
static char sccsid[] __attribute__((unused)) = "@(#)rdisc.c 8.1 (Berkeley) x/y/95";
#elif defined(__NetBSD__)
__RCSID("$NetBSD$"); __RCSID("$NetBSD$");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.23 $");
#ident "$Revision: 2.23 $"
#endif #endif
#ident "$Revision: 2.17 $"
#define log(x, msg) syslog(x, msg) #define log(x, msg) syslog(x, msg)
#define panic(s) {log(LOG_ERR,s); exit(1);} #define panic(s) {log(LOG_ERR,s); exit(1);}

View File

@ -36,12 +36,14 @@
#include <netinet/ip.h> #include <netinet/ip.h>
#include <netinet/ip_icmp.h> #include <netinet/ip_icmp.h>
#if !defined(sgi) && !defined(__NetBSD__) #ifdef __NetBSD__
static char sccsid[] __attribute__((unused)) = "@(#)rdisc.c 8.1 (Berkeley) x/y/95";
#elif defined(__NetBSD__)
__RCSID("$NetBSD$"); __RCSID("$NetBSD$");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.27 $");
#ident "$Revision: 2.27 $"
#endif #endif
#ident "$Revision: 2.22 $"
/* router advertisement ICMP packet */ /* router advertisement ICMP packet */
struct icmp_ad { struct icmp_ad {
@ -95,8 +97,9 @@ struct dr { /* accumulated advertisements */
#define UNSIGN_PREF(p) SIGN_PREF(p) #define UNSIGN_PREF(p) SIGN_PREF(p)
/* adjust unsigned preference by interface metric, /* adjust unsigned preference by interface metric,
* without driving it to infinity */ * without driving it to infinity */
#define PREF(p, ifp) ((int)(p) <= (ifp)->int_metric ? ((p) != 0 ? 1 : 0) \ #define PREF(p, ifp) ((int)(p) <= ((ifp)->int_metric+(ifp)->int_adj_outmetric)\
: (p) - ((ifp)->int_metric)) ? ((p) != 0 ? 1 : 0) \
: (p) - ((ifp)->int_metric+(ifp)->int_adj_outmetric))
static void rdisc_sort(void); static void rdisc_sort(void);
@ -189,9 +192,13 @@ set_rdisc_mg(struct interface *ifp,
return; return;
#endif #endif
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
#ifdef MCAST_IFINDEX
m.imr_interface.s_addr = htonl(ifp->int_index);
#else
m.imr_interface.s_addr = ((ifp->int_if_flags & IFF_POINTOPOINT) m.imr_interface.s_addr = ((ifp->int_if_flags & IFF_POINTOPOINT)
? ifp->int_dstaddr ? ifp->int_dstaddr
: ifp->int_addr); : ifp->int_addr);
#endif
if (supplier if (supplier
|| (ifp->int_state & IS_NO_ADV_IN) || (ifp->int_state & IS_NO_ADV_IN)
|| !on) { || !on) {
@ -691,17 +698,17 @@ send_rdisc(union ad_u *p,
naddr dst, /* 0 or unicast destination */ naddr dst, /* 0 or unicast destination */
int type) /* 0=unicast, 1=bcast, 2=mcast */ int type) /* 0=unicast, 1=bcast, 2=mcast */
{ {
struct sockaddr_in sin; struct sockaddr_in rsin;
int flags; int flags;
const char *msg; const char *msg;
naddr tgt_mcast; naddr tgt_mcast;
memset(&sin, 0, sizeof(sin)); memset(&rsin, 0, sizeof(rsin));
sin.sin_addr.s_addr = dst; rsin.sin_addr.s_addr = dst;
sin.sin_family = AF_INET; rsin.sin_family = AF_INET;
#ifdef _HAVE_SIN_LEN #ifdef _HAVE_SIN_LEN
sin.sin_len = sizeof(sin); rsin.sin_len = sizeof(rsin);
#endif #endif
flags = MSG_DONTROUTE; flags = MSG_DONTROUTE;
@ -714,10 +721,10 @@ send_rdisc(union ad_u *p,
case 1: /* broadcast */ case 1: /* broadcast */
if (ifp->int_if_flags & IFF_POINTOPOINT) { if (ifp->int_if_flags & IFF_POINTOPOINT) {
msg = "Send pt-to-pt"; msg = "Send pt-to-pt";
sin.sin_addr.s_addr = ifp->int_dstaddr; rsin.sin_addr.s_addr = ifp->int_dstaddr;
} else { } else {
msg = "Send broadcast"; msg = "Send broadcast";
sin.sin_addr.s_addr = ifp->int_brdaddr; rsin.sin_addr.s_addr = ifp->int_brdaddr;
} }
break; break;
@ -731,6 +738,10 @@ send_rdisc(union ad_u *p,
} }
if (rdisc_sock_mcast != ifp) { if (rdisc_sock_mcast != ifp) {
/* select the right interface. */ /* select the right interface. */
#ifdef MCAST_IFINDEX
/* specify ifindex */
tgt_mcast = htonl(ifp->int_index);
#else
#ifdef MCAST_PPP_BUG #ifdef MCAST_PPP_BUG
/* Do not specify the primary interface explicitly /* Do not specify the primary interface explicitly
* if we have the multicast point-to-point kernel * if we have the multicast point-to-point kernel
@ -744,6 +755,7 @@ send_rdisc(union ad_u *p,
} else } else
#endif #endif
tgt_mcast = ifp->int_addr; tgt_mcast = ifp->int_addr;
#endif
if (0 > setsockopt(rdisc_sock, if (0 > setsockopt(rdisc_sock,
IPPROTO_IP, IP_MULTICAST_IF, IPPROTO_IP, IP_MULTICAST_IF,
&tgt_mcast, sizeof(tgt_mcast))) { &tgt_mcast, sizeof(tgt_mcast))) {
@ -761,16 +773,16 @@ send_rdisc(union ad_u *p,
if (rdisc_sock < 0) if (rdisc_sock < 0)
get_rdisc_sock(); get_rdisc_sock();
trace_rdisc(msg, ifp->int_addr, sin.sin_addr.s_addr, ifp, trace_rdisc(msg, ifp->int_addr, rsin.sin_addr.s_addr, ifp,
p, p_size); p, p_size);
if (0 > sendto(rdisc_sock, p, p_size, flags, if (0 > sendto(rdisc_sock, p, p_size, flags,
(struct sockaddr *)&sin, sizeof(sin))) { (struct sockaddr *)&rsin, sizeof(rsin))) {
if (ifp == 0 || !(ifp->int_state & IS_BROKE)) if (ifp == 0 || !(ifp->int_state & IS_BROKE))
msglog("sendto(%s%s%s): %s", msglog("sendto(%s%s%s): %s",
ifp != 0 ? ifp->int_name : "", ifp != 0 ? ifp->int_name : "",
ifp != 0 ? ", " : "", ifp != 0 ? ", " : "",
inet_ntoa(sin.sin_addr), inet_ntoa(rsin.sin_addr),
strerror(errno)); strerror(errno));
if (ifp != 0) if (ifp != 0)
if_sick(ifp); if_sick(ifp);

View File

@ -1,4 +1,4 @@
.\" $Revision: 2.19 $ .\" $Revision: 2.26 $
.\" .\"
.\" Copyright (c) 1983, 1991, 1993 .\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -114,11 +114,18 @@ The
packet generated contains a list of known routes, each marked packet generated contains a list of known routes, each marked
with a "hop count" metric (a count of 16 or greater is with a "hop count" metric (a count of 16 or greater is
considered "infinite"). considered "infinite").
Advertised metrics reflect the metric associated with interface Th advertised metric for a route reflects the metrics associated
with interfaces
(see (see
.Xr ifconfig 8 ), .Xr ifconfig 8 )
though which it is received and sent,
so setting the metric on an interface so setting the metric on an interface
is an effective way to steer traffic. is an effective way to steer traffic.
See also
.Cm adj_inmetric
and
.Cm adj_outmetric
parameters below.
.Pp .Pp
Responses do not include routes with a first hop on the requesting Responses do not include routes with a first hop on the requesting
network to implement in part network to implement in part
@ -155,7 +162,7 @@ also periodically checks the routing table entries.
If an entry has not been updated for 3 minutes, the entry's metric If an entry has not been updated for 3 minutes, the entry's metric
is set to infinity and marked for deletion. is set to infinity and marked for deletion.
Deletions are delayed until the route has been advertised with Deletions are delayed until the route has been advertised with
an infinite metric to insure the invalidation an infinite metric to ensure the invalidation
is propagated throughout the local internet. is propagated throughout the local internet.
This is a form of This is a form of
.Em poison reverse . .Em poison reverse .
@ -506,6 +513,7 @@ a line starting with
.Cm if=alias(Hname) , .Cm if=alias(Hname) ,
.Cm if=remote(Hname) , .Cm if=remote(Hname) ,
etc. should be used. etc. should be used.
.Ss Parameters
.Pp .Pp
Lines that start with neither "net" nor "host" must consist of one Lines that start with neither "net" nor "host" must consist of one
or more of the following parameter settings, separated by commas or or more of the following parameter settings, separated by commas or
@ -558,7 +566,8 @@ all passwords have expired, in which case the password that expired most
recently is used, or unless no passwords are valid yet, in which case recently is used, or unless no passwords are valid yet, in which case
no password is output. no password is output.
Incoming packets can carry any password that is valid, will Incoming packets can carry any password that is valid, will
be valid within 24 hours, or that was valid within 24 hours. be valid within the next 24 hours, or that was valid within the preceding
24 hours.
To protect the secrets, the passwd settings are valid only in the To protect the secrets, the passwd settings are valid only in the
.Em /etc/gateways .Em /etc/gateways
file and only when that file is readable only by UID 0. file and only when that file is readable only by UID 0.
@ -645,17 +654,47 @@ Unless modified with
.Cm fake_default , .Cm fake_default ,
the default route is broadcast with a metric of 14. the default route is broadcast with a metric of 14.
That serves as a "poor man's router discovery" protocol. That serves as a "poor man's router discovery" protocol.
.It Cm adj_inmetric Ns \&= Ns Ar delta
adjusts the hop count or metric of received RIP routes by
.Ar delta .
The metric of every received RIP route is increased by the sum
of two values associated with the interface.
One is the adj_inmetric value and the other is the interface
metric set with
.Xr ifconfig 8 .
.It Cm adj_outmetric Ns \&= Ns Ar delta
adjusts the hop count or metric of advertised RIP routes by
.Ar delta .
The metric of every received RIP route is increased by the metric
associated with the interface by which it was received, or by 1 if
the interface does not have a non-zero metric.
The metric of the received route is then increased by the
adj_outmetric associated with the interface.
Every advertised route is increased by a total of four
values,
the metric set for the interface by which it was received with
.Xr ifconfig 8 ,
the
.Cm adj_inmetric Ar delta
of the receiving interface,
the metric set for the interface by which it is transmitted with
.Xr ifconfig 8 ,
and the
.Cm adj_outmetric Ar delta
of the transmitting interface.
.It Cm trust_gateway Ns \&= Ns Ar rname[|net1/mask1|net2/mask2|...] .It Cm trust_gateway Ns \&= Ns Ar rname[|net1/mask1|net2/mask2|...]
causes RIP packets from that router and other routers named in causes RIP packets from router
other .Ar rname
and other routers named in other
.Cm trust_gateway .Cm trust_gateway
keywords to be accepted, and packets from other routers to be ignored. keywords to be accepted, and packets from other routers to be ignored.
If networks are specified, then routes to other networks will be ignored If networks are specified, then routes to other networks will be ignored
from that router. from that router.
.It Cm redirect_ok .It Cm redirect_ok
causes RIP to allow ICMP Redirect messages when the system is acting allows the kernel to listen ICMP Redirect messages when the system is acting
as a router and forwarding packets. as a router and forwarding packets.
Otherwise, ICMP Redirect messages are overridden. Otherwise, ICMP Redirect messages are overridden and deleted when the
system is acting as a router.
.El .El
.Pp .Pp
.Sh FILES .Sh FILES
@ -666,9 +705,7 @@ for distant gateways
.Sh SEE ALSO .Sh SEE ALSO
.Xr icmp 4 , .Xr icmp 4 ,
.Xr udp 4 , .Xr udp 4 ,
.Xr gated 8 , .Xr rtquery 8
.Xr htable 8 ,
.Xr rtquery 8 .
.Rs .Rs
.%T Internet Transport Protocols .%T Internet Transport Protocols
.%R XSIS 028112 .%R XSIS 028112
@ -682,3 +719,5 @@ The
.Nm .Nm
command appeared in command appeared in
.Bx 4.2 . .Bx 4.2 .
\" LocalWords: loopback ICMP rtquery ifconfig multicasting Solicitations RIPv
\" LocalWords: netstat rdisc

View File

@ -1,4 +1,4 @@
.\" $Revision: 2.17 $ .\" $Revision: 2.27 $
.\" $NetBSD: rtquery.8,v 1.14 1999/02/23 10:47:41 christos Exp $ .\" $NetBSD: rtquery.8,v 1.14 1999/02/23 10:47:41 christos Exp $
.\" .\"
.Dd June 1, 1996 .Dd June 1, 1996
@ -115,8 +115,8 @@ turns off tracing.
dumps the daemon's routing table to the current tracefile. dumps the daemon's routing table to the current tracefile.
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr routed 8 , .Xr gated 8 ,
.Xr gated 8 .Xr routed 8
.br .br
RFC\ 1058 - Routing Information Protocol, RIPv1 RFC\ 1058 - Routing Information Protocol, RIPv1
.br .br

View File

@ -31,10 +31,6 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
char copyright[] =
"@(#) Copyright (c) 1982, 1986, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/protosw.h> #include <sys/protosw.h>
@ -55,17 +51,32 @@ char copyright[] =
#include <bstring.h> #include <bstring.h>
#endif #endif
#if !defined(sgi) && !defined(__NetBSD__) #define UNUSED __attribute__((unused))
static char sccsid[] __attribute__((unused))= "@(#)query.c 8.1 (Berkeley) 6/5/93"; #ifndef __RCSID
#elif defined(__NetBSD__) #define __RCSID(_s) static const char rcsid[] UNUSED = _s
__RCSID("$NetBSD: rtquery.c,v 1.10 1999/02/23 10:47:41 christos Exp $"); #endif
#ifndef __COPYRIGHT
#define __COPYRIGHT(_s) static const char copyright[] UNUSED = _s
#endif
__COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993\n"
"The Regents of the University of California."
" All rights reserved.\n");
#ifdef __NetBSD__
__RCSID("$NetBSD$");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.26 $");
#ident "$Revision: 2.26 $"
#endif #endif
#ident "$Revision: 2.17 $"
#ifndef sgi #ifndef sgi
#define _HAVE_SIN_LEN #define _HAVE_SIN_LEN
#endif #endif
#ifdef __NetBSD__
#include <md5.h>
#else
#define MD5_DIGEST_LEN 16 #define MD5_DIGEST_LEN 16
typedef struct { typedef struct {
u_int32_t state[4]; /* state (ABCD) */ u_int32_t state[4]; /* state (ABCD) */
@ -75,6 +86,7 @@ typedef struct {
extern void MD5Init(MD5_CTX*); extern void MD5Init(MD5_CTX*);
extern void MD5Update(MD5_CTX*, u_char*, u_int); extern void MD5Update(MD5_CTX*, u_char*, u_int);
extern void MD5Final(u_char[MD5_DIGEST_LEN], MD5_CTX*); extern void MD5Final(u_char[MD5_DIGEST_LEN], MD5_CTX*);
#endif
#define WTIME 15 /* Time to wait for all responses */ #define WTIME 15 /* Time to wait for all responses */
@ -386,7 +398,7 @@ query_loop(char *argv[], int argc)
NA0.a_family = RIP_AF_AUTH; NA0.a_family = RIP_AF_AUTH;
NA0.a_type = RIP_AUTH_MD5; NA0.a_type = RIP_AUTH_MD5;
NA0.au.a_md5.md5_keyid = (int8_t)keyid; NA0.au.a_md5.md5_keyid = (int8_t)keyid;
NA0.au.a_md5.md5_auth_len = RIP_AUTH_MD5_LEN; NA0.au.a_md5.md5_auth_len = RIP_AUTH_MD5_KEY_LEN;
NA0.au.a_md5.md5_seqno = 0; NA0.au.a_md5.md5_seqno = 0;
cc = (char *)&NA2-(char *)&OMSG; cc = (char *)&NA2-(char *)&OMSG;
NA0.au.a_md5.md5_pkt_len = htons(cc); NA0.au.a_md5.md5_pkt_len = htons(cc);
@ -396,7 +408,7 @@ query_loop(char *argv[], int argc)
MD5Update(&md5_ctx, MD5Update(&md5_ctx,
(u_char *)&OMSG, cc); (u_char *)&OMSG, cc);
MD5Update(&md5_ctx, MD5Update(&md5_ctx,
(u_char *)passwd, RIP_AUTH_MD5_LEN); (u_char *)passwd, RIP_AUTH_MD5_HASH_LEN);
MD5Final(NA2.au.au_pw, &md5_ctx); MD5Final(NA2.au.au_pw, &md5_ctx);
omsg_len += 2*sizeof(OMSG.rip_nets[0]); omsg_len += 2*sizeof(OMSG.rip_nets[0]);
} }
@ -410,7 +422,7 @@ query_loop(char *argv[], int argc)
seen = 0; seen = 0;
while (0 > out(*argv++)) { while (0 > out(*argv++)) {
if (*argv == 0) if (*argv == 0)
exit(-1); exit(1);
answered++; answered++;
} }
@ -593,7 +605,7 @@ rip_input(struct sockaddr_in *from,
struct in_addr in; struct in_addr in;
const char *name; const char *name;
char net_buf[80]; char net_buf[80];
u_char hash[RIP_AUTH_MD5_LEN]; u_char hash[RIP_AUTH_MD5_KEY_LEN];
MD5_CTX md5_ctx; MD5_CTX md5_ctx;
u_char md5_authed = 0; u_char md5_authed = 0;
u_int mask, dmask; u_int mask, dmask;
@ -733,9 +745,10 @@ rip_input(struct sockaddr_in *from,
&& na->a_type == ntohs(1)) { && na->a_type == ntohs(1)) {
MD5Init(&md5_ctx); MD5Init(&md5_ctx);
MD5Update(&md5_ctx, (u_char *)&IMSG, MD5Update(&md5_ctx, (u_char *)&IMSG,
(char *)na-(char *)&IMSG); (char *)na-(char *)&IMSG
+RIP_AUTH_MD5_HASH_XTRA);
MD5Update(&md5_ctx, (u_char *)passwd, MD5Update(&md5_ctx, (u_char *)passwd,
RIP_AUTH_MD5_LEN); RIP_AUTH_MD5_KEY_LEN);
MD5Final(hash, &md5_ctx); MD5Final(hash, &md5_ctx);
(void)printf(" %s hash\n", (void)printf(" %s hash\n",
memcmp(hash, na->au.au_pw, memcmp(hash, na->au.au_pw,
@ -747,10 +760,10 @@ rip_input(struct sockaddr_in *from,
} else { } else {
(void)sprintf(net_buf, "(af %#x) %d.%d.%d.%d", (void)sprintf(net_buf, "(af %#x) %d.%d.%d.%d",
ntohs(n->n_family), ntohs(n->n_family),
(char)(n->n_dst >> 24), (u_char)(n->n_dst >> 24),
(char)(n->n_dst >> 16), (u_char)(n->n_dst >> 16),
(char)(n->n_dst >> 8), (u_char)(n->n_dst >> 8),
(char)n->n_dst); (u_char)n->n_dst);
} }
(void)printf(" %-18s metric %2d %-10s", (void)printf(" %-18s metric %2d %-10s",

View File

@ -33,12 +33,14 @@
#include "defs.h" #include "defs.h"
#if !defined(sgi) && !defined(__NetBSD__) #ifdef __NetBSD__
static char sccsid[] __attribute__((unused)) = "@(#)tables.c 8.1 (Berkeley) 6/5/93";
#elif defined(__NetBSD__)
__RCSID("$NetBSD$"); __RCSID("$NetBSD$");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.27 $");
#ident "$Revision: 2.27 $"
#endif #endif
#ident "$Revision: 2.22 $"
static struct rt_spare *rts_better(struct rt_entry *); static struct rt_spare *rts_better(struct rt_entry *);
static struct rt_spare rts_empty = {0,0,0,HOPCNT_INFINITY,0,0,0}; static struct rt_spare rts_empty = {0,0,0,HOPCNT_INFINITY,0,0,0};
@ -251,8 +253,6 @@ ag_flush(naddr lim_dst_h, /* flush routes to here */
* then mark the suppressor redundant. * then mark the suppressor redundant.
*/ */
if (ag_cors->ag_pref <= ag->ag_pref) { if (ag_cors->ag_pref <= ag->ag_pref) {
if (ag_cors->ag_seqno > ag->ag_seqno)
ag_cors->ag_seqno = ag->ag_seqno;
if (AG_IS_REDUN(ag->ag_state) if (AG_IS_REDUN(ag->ag_state)
&& ag_cors->ag_mask==ag->ag_mask<<1) { && ag_cors->ag_mask==ag->ag_mask<<1) {
if (ag_cors->ag_dst_h == dst_h) if (ag_cors->ag_dst_h == dst_h)
@ -287,7 +287,7 @@ ag_check(naddr dst,
naddr nhop, naddr nhop,
char metric, char metric,
char pref, char pref,
u_int seqno, u_int new_seqno,
u_short tag, u_short tag,
u_short state, u_short state,
void (*out)(struct ag_info *)) /* output using this */ void (*out)(struct ag_info *)) /* output using this */
@ -314,7 +314,7 @@ ag_check(naddr dst,
nc_ag.ag_pref = pref; nc_ag.ag_pref = pref;
nc_ag.ag_tag = tag; nc_ag.ag_tag = tag;
nc_ag.ag_state = state; nc_ag.ag_state = state;
nc_ag.ag_seqno = seqno; nc_ag.ag_seqno = new_seqno;
out(&nc_ag); out(&nc_ag);
return; return;
} }
@ -344,8 +344,6 @@ ag_check(naddr dst,
&& (ag_cors->ag_gate == ag->ag_gate && (ag_cors->ag_gate == ag->ag_gate
|| (ag->ag_state & AGS_FINE_GATE) || (ag->ag_state & AGS_FINE_GATE)
|| (ag_cors->ag_state & AGS_CORS_GATE))) { || (ag_cors->ag_state & AGS_CORS_GATE))) {
if (ag_cors->ag_seqno > ag->ag_seqno)
ag_cors->ag_seqno = ag->ag_seqno;
/* If the suppressed target was redundant, /* If the suppressed target was redundant,
* then mark the suppressor redundant. * then mark the suppressor redundant.
*/ */
@ -404,17 +402,13 @@ ag_check(naddr dst,
ag->ag_tag = tag; ag->ag_tag = tag;
ag->ag_metric = metric; ag->ag_metric = metric;
ag->ag_pref = pref; ag->ag_pref = pref;
if (ag->ag_seqno < new_seqno)
ag->ag_seqno = new_seqno;
x = ag->ag_state; x = ag->ag_state;
ag->ag_state = state; ag->ag_state = state;
state = x; state = x;
} }
/* The sequence number controls flash updating,
* and should be the smaller of the two.
*/
if (ag->ag_seqno > seqno)
ag->ag_seqno = seqno;
/* Some bits are set if they are set on either route, /* Some bits are set if they are set on either route,
* except when the route is for an interface. * except when the route is for an interface.
*/ */
@ -454,8 +448,8 @@ ag_check(naddr dst,
* *
* Combine and promote (aggregate) the pair of routes. * Combine and promote (aggregate) the pair of routes.
*/ */
if (seqno > ag->ag_seqno) if (new_seqno < ag->ag_seqno)
seqno = ag->ag_seqno; new_seqno = ag->ag_seqno;
if (!AG_IS_REDUN(state)) if (!AG_IS_REDUN(state))
state &= ~AGS_REDUN1; state &= ~AGS_REDUN1;
if (AG_IS_REDUN(ag->ag_state)) if (AG_IS_REDUN(ag->ag_state))
@ -516,10 +510,10 @@ ag_check(naddr dst,
pref = x; pref = x;
/* take the newest sequence number */ /* take the newest sequence number */
if (seqno >= ag->ag_seqno) if (new_seqno <= ag->ag_seqno)
seqno = ag->ag_seqno; new_seqno = ag->ag_seqno;
else else
ag->ag_seqno = seqno; ag->ag_seqno = new_seqno;
} else { } else {
if (!(state & AGS_AGGREGATE)) if (!(state & AGS_AGGREGATE))
@ -535,10 +529,10 @@ ag_check(naddr dst,
if (!AG_IS_REDUN(state)) if (!AG_IS_REDUN(state))
state &= ~AGS_REDUN1; state &= ~AGS_REDUN1;
state &= ~AGS_REDUN0; state &= ~AGS_REDUN0;
if (seqno > ag->ag_seqno) if (new_seqno < ag->ag_seqno)
seqno = ag->ag_seqno; new_seqno = ag->ag_seqno;
else else
ag->ag_seqno = seqno; ag->ag_seqno = new_seqno;
} }
mask <<= 1; mask <<= 1;
@ -599,7 +593,7 @@ ag_check(naddr dst,
nag->ag_pref = pref; nag->ag_pref = pref;
nag->ag_tag = tag; nag->ag_tag = tag;
nag->ag_state = state; nag->ag_state = state;
nag->ag_seqno = seqno; nag->ag_seqno = new_seqno;
nag->ag_fine = ag; nag->ag_fine = ag;
if (ag != 0) if (ag != 0)
@ -632,6 +626,9 @@ rtm_type_name(u_char type)
"RTM_RESOLVE", "RTM_RESOLVE",
"RTM_NEWADDR", "RTM_NEWADDR",
"RTM_DELADDR", "RTM_DELADDR",
#ifdef RTM_OIFINFO
"RTM_OIFINFO",
#endif
"RTM_IFINFO", "RTM_IFINFO",
"RTM_NEWMADDR", "RTM_NEWMADDR",
"RTM_DELMADDR" "RTM_DELMADDR"
@ -1011,7 +1008,7 @@ rtm_lose(struct rt_msghdr *rtm,
*/ */
static int static int
get_info_gate(struct sockaddr **sap, get_info_gate(struct sockaddr **sap,
struct sockaddr_in *sin) struct sockaddr_in *rsin)
{ {
struct sockaddr_dl *sdl = (struct sockaddr_dl *)*sap; struct sockaddr_dl *sdl = (struct sockaddr_dl *)*sap;
struct interface *ifp; struct interface *ifp;
@ -1027,12 +1024,12 @@ get_info_gate(struct sockaddr **sap,
if (ifp == 0) if (ifp == 0)
return 0; return 0;
sin->sin_addr.s_addr = ifp->int_addr; rsin->sin_addr.s_addr = ifp->int_addr;
#ifdef _HAVE_SA_LEN #ifdef _HAVE_SA_LEN
sin->sin_len = sizeof(*sin); rsin->sin_len = sizeof(*rsin);
#endif #endif
sin->sin_family = AF_INET; rsin->sin_family = AF_INET;
*sap = (struct sockaddr*)sin; *sap = (struct sockaddr*)rsin;
return 1; return 1;
} }
@ -1113,6 +1110,13 @@ flush_kern(void)
if (rtm->rtm_flags & RTF_LLINFO) if (rtm->rtm_flags & RTF_LLINFO)
continue; continue;
#if defined(RTF_CLONED) && defined(__bsdi__)
/* ignore cloned routes
*/
if (rtm->rtm_flags & RTF_CLONED)
continue;
#endif
/* ignore multicast addresses /* ignore multicast addresses
*/ */
if (IN_MULTICAST(ntohl(S_ADDR(INFO_DST(&info))))) if (IN_MULTICAST(ntohl(S_ADDR(INFO_DST(&info)))))
@ -1220,6 +1224,10 @@ read_rt(void)
ifinit_timer.tv_sec = now.tv_sec; ifinit_timer.tv_sec = now.tv_sec;
continue; continue;
} }
#ifdef RTM_OIFINFO
if (m.r.rtm.rtm_type == RTM_OIFINFO)
continue; /* ignore compat message */
#endif
strcpy(str, rtm_type_name(m.r.rtm.rtm_type)); strcpy(str, rtm_type_name(m.r.rtm.rtm_type));
strp = &str[strlen(str)]; strp = &str[strlen(str)];
@ -1259,6 +1267,13 @@ read_rt(void)
continue; continue;
} }
#if defined(RTF_CLONED) && defined(__bsdi__)
if (m.r.rtm.rtm_flags & RTF_CLONED) {
trace_act("ignore cloned %s", str);
continue;
}
#endif
if (get_info_gate(&INFO_GATE(&info), &gate_sin)) { if (get_info_gate(&INFO_GATE(&info), &gate_sin)) {
gate = S_ADDR(INFO_GATE(&info)); gate = S_ADDR(INFO_GATE(&info));
strp += sprintf(strp, " --> %s", naddr_ntoa(gate)); strp += sprintf(strp, " --> %s", naddr_ntoa(gate));

View File

@ -38,12 +38,14 @@
#include <sys/signal.h> #include <sys/signal.h>
#include <fcntl.h> #include <fcntl.h>
#if !defined(sgi) && !defined(__NetBSD__) #ifdef __NetBSD__
static char sccsid[] __attribute__((unused)) = "@(#)trace.c 8.1 (Berkeley) 6/5/93";
#elif defined(__NetBSD__)
__RCSID("$NetBSD$"); __RCSID("$NetBSD$");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
__RCSID("$Revision: 2.27 $");
#ident "$Revision: 2.27 $"
#endif #endif
#ident "$Revision: 2.17 $"
#ifdef sgi #ifdef sgi
@ -186,6 +188,7 @@ tmsg(const char *p, ...)
lastlog(); lastlog();
va_start(args, p); va_start(args, p);
vfprintf(ftrace, p, args); vfprintf(ftrace, p, args);
va_end(args);
(void)fputc('\n',ftrace); (void)fputc('\n',ftrace);
fflush(ftrace); fflush(ftrace);
} }
@ -239,6 +242,7 @@ trace_off(const char *p, ...)
lastlog(); lastlog();
va_start(args, p); va_start(args, p);
vfprintf(ftrace, p, args); vfprintf(ftrace, p, args);
va_end(args);
(void)fputc('\n',ftrace); (void)fputc('\n',ftrace);
} }
trace_close(file_trace); trace_close(file_trace);
@ -641,9 +645,15 @@ trace_if(const char *act,
ifp->int_mask, 1)); ifp->int_mask, 1));
if (ifp->int_metric != 0) if (ifp->int_metric != 0)
(void)fprintf(ftrace, "metric=%d ", ifp->int_metric); (void)fprintf(ftrace, "metric=%d ", ifp->int_metric);
if (ifp->int_adj_inmetric != 0)
(void)fprintf(ftrace, "adj_inmetric=%u ",
ifp->int_adj_inmetric);
if (ifp->int_adj_outmetric != 0)
(void)fprintf(ftrace, "adj_outmetric=%u ",
ifp->int_adj_outmetric);
if (!IS_RIP_OUT_OFF(ifp->int_state) if (!IS_RIP_OUT_OFF(ifp->int_state)
&& ifp->int_d_metric != 0) && ifp->int_d_metric != 0)
(void)fprintf(ftrace, "fake_default=%d ", ifp->int_d_metric); (void)fprintf(ftrace, "fake_default=%u ", ifp->int_d_metric);
trace_bits(if_bits, ifp->int_if_flags, 0); trace_bits(if_bits, ifp->int_if_flags, 0);
trace_bits(is_bits, ifp->int_state, 0); trace_bits(is_bits, ifp->int_state, 0);
(void)fputc('\n',ftrace); (void)fputc('\n',ftrace);
@ -721,6 +731,7 @@ trace_misc(const char *p, ...)
lastlog(); lastlog();
va_start(args, p); va_start(args, p);
vfprintf(ftrace, p, args); vfprintf(ftrace, p, args);
va_end(args);
(void)fputc('\n',ftrace); (void)fputc('\n',ftrace);
} }
@ -738,6 +749,7 @@ trace_act(const char *p, ...)
lastlog(); lastlog();
va_start(args, p); va_start(args, p);
vfprintf(ftrace, p, args); vfprintf(ftrace, p, args);
va_end(args);
(void)fputc('\n',ftrace); (void)fputc('\n',ftrace);
} }
@ -755,6 +767,7 @@ trace_pkt(const char *p, ...)
lastlog(); lastlog();
va_start(args, p); va_start(args, p);
vfprintf(ftrace, p, args); vfprintf(ftrace, p, args);
va_end(args);
(void)fputc('\n',ftrace); (void)fputc('\n',ftrace);
} }