From d21d623f8e8a4315c961e4c21e8791364bf5da82 Mon Sep 17 00:00:00 2001 From: bms Date: Wed, 25 Feb 2004 23:45:57 +0000 Subject: Sync HEAD sources to vendor branch import of routed v2.27 from rhyolite.com. Update for the MD5 changes requested in bin/35843. Preserve local changes. Education by: obrien, markm, pointy-stick PR: bin/35843 (and doubtless others) --- sbin/routed/input.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'sbin/routed/input.c') diff --git a/sbin/routed/input.c b/sbin/routed/input.c index 6d258f1..a768424 100644 --- a/sbin/routed/input.c +++ b/sbin/routed/input.c @@ -35,11 +35,13 @@ #include "defs.h" -#if !defined(sgi) && !defined(__NetBSD__) -static char sccsid[] __attribute__((unused)) = "@(#)input.c 8.1 (Berkeley) 6/5/93"; -#elif defined(__NetBSD__) -#include +#ifdef __NetBSD__ __RCSID("$NetBSD$"); +#elif defined(__FreeBSD__) +__RCSID("$FreeBSD$"); +#else +__RCSID("$Revision: 2.26 $"); +#ident "$Revision: 2.26 $" #endif #ident "$FreeBSD$" @@ -328,9 +330,14 @@ input(struct sockaddr_in *from, /* received from this IP address */ v12buf.n->n_family = RIP_AF_INET; v12buf.n->n_dst = RIP_DEFAULT; i = aifp->int_d_metric; - if (0 != (rt = rtget(RIP_DEFAULT, 0))) - i = MIN(i, (rt->rt_metric - +aifp->int_metric+1)); + if (0 != (rt = rtget(RIP_DEFAULT, 0))) { + j = (rt->rt_metric + +aifp->int_metric + +aifp->int_adj_outmetric + +1); + if (i > j) + i = j; + } v12buf.n->n_metric = htonl(i); v12buf.n++; break; @@ -396,11 +403,15 @@ input(struct sockaddr_in *from, /* received from this IP address */ */ v12buf.n->n_family = RIP_AF_INET; v12buf.n->n_dst = dst; - v12buf.n->n_metric = (rt->rt_metric+1 - + ((aifp!=0) - ? aifp->int_metric - : 1)); - if (v12buf.n->n_metric > HOPCNT_INFINITY) + j = rt->rt_metric+1; + if (!aifp) + ++j; + else + j += (aifp->int_metric + + aifp->int_adj_outmetric); + if (j < HOPCNT_INFINITY) + v12buf.n->n_metric = j; + else v12buf.n->n_metric = HOPCNT_INFINITY; if (v12buf.buf->rip_vers != RIPv1) { v12buf.n->n_tag = rt->rt_tag; @@ -484,8 +495,8 @@ input(struct sockaddr_in *from, /* received from this IP address */ if (from->sin_port != ntohs(RIP_PORT)) { msglim(&bad_router, FROM_NADDR, " discard RIP response from unknown port" - " %d on host %s", ntohs(from->sin_port), - naddr_ntoa(FROM_NADDR)); + " %d on %s", + ntohs(from->sin_port), naddr_ntoa(FROM_NADDR)); return; } @@ -654,7 +665,8 @@ input(struct sockaddr_in *from, /* received from this IP address */ /* 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) n->n_metric = HOPCNT_INFINITY; @@ -967,12 +979,12 @@ ck_passwd(struct interface *aifp, */ if (TRACEPACKETS) { if (NA->au.a_md5.md5_auth_len - != RIP_AUTH_MD5_LEN) + != RIP_AUTH_MD5_HASH_LEN) msglim(use_authp, from, "unknown MD5 RIPv2 auth len %#x" " instead of %#x from %s", NA->au.a_md5.md5_auth_len, - RIP_AUTH_MD5_LEN, + RIP_AUTH_MD5_HASH_LEN, naddr_ntoa(from)); if (na2->a_family != RIP_AF_AUTH) msglim(use_authp, from, @@ -989,8 +1001,9 @@ ck_passwd(struct interface *aifp, } MD5Init(&md5_ctx); - MD5Update(&md5_ctx, (u_char *)rip, len); - MD5Update(&md5_ctx, ap->key, RIP_AUTH_MD5_LEN); + MD5Update(&md5_ctx, (u_char *)rip, + len + RIP_AUTH_MD5_HASH_XTRA); + MD5Update(&md5_ctx, ap->key, RIP_AUTH_MD5_KEY_LEN); MD5Final(hash, &md5_ctx); if (!memcmp(hash, na2->au.au_pw, sizeof(hash))) return 1; -- cgit v1.1