From 7ed7713848b697947b27f4e1eddc398740610e94 Mon Sep 17 00:00:00 2001 From: christos Date: Sat, 27 Mar 2004 20:50:43 +0000 Subject: [PATCH] From Vernon Schryver: Wolfgang Solfrank has explained the problem with router discovery in `routed` in a way I can understand. Let's assume that the configured preference of the interface is 5. This gets converted to 0x80000005 through the use of the UNSIGN_PREF macro. Later on, this value gets put into the PREF macro, which compares it against the interface metric(s) (let's assume those values to be 0 for now). Of course the 0x80000005, cast to int, is much less than 0, so the clamping rule is triggered, which gives us a value of 1. This is then converted via SIGN_PREF into 0x80000001 and put into the message. Certainly, this isn't what was intended. --- sbin/routed/main.c | 6 +++--- sbin/routed/rdisc.c | 11 ++++++----- sbin/routed/routed.8 | 5 ++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sbin/routed/main.c b/sbin/routed/main.c index 7fc89ca45769..927c1d33aca2 100644 --- a/sbin/routed/main.c +++ b/sbin/routed/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.35 2003/11/14 01:31:24 enami Exp $ */ +/* $NetBSD: main.c,v 1.36 2004/03/27 20:50:43 christos Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993\n" "The Regents of the University of California." " All rights reserved.\n"); #ifdef __NetBSD__ -__RCSID("$NetBSD: main.c,v 1.35 2003/11/14 01:31:24 enami Exp $"); +__RCSID("$NetBSD: main.c,v 1.36 2004/03/27 20:50:43 christos Exp $"); #elif defined(__FreeBSD__) __RCSID("$FreeBSD$"); #else @@ -226,7 +226,7 @@ main(int argc, case 'v': /* display version */ verbose++; - msglog("version 2.25"); + msglog("version 2.28"); break; default: diff --git a/sbin/routed/rdisc.c b/sbin/routed/rdisc.c index 9f9c05b767c4..24bbdb6e0bba 100644 --- a/sbin/routed/rdisc.c +++ b/sbin/routed/rdisc.c @@ -1,4 +1,4 @@ -/* $NetBSD: rdisc.c,v 1.14 2002/11/30 04:04:23 christos Exp $ */ +/* $NetBSD: rdisc.c,v 1.15 2004/03/27 20:50:43 christos Exp $ */ /* * Copyright (c) 1995 @@ -39,7 +39,7 @@ #include #ifdef __NetBSD__ -__RCSID("$NetBSD: rdisc.c,v 1.14 2002/11/30 04:04:23 christos Exp $"); +__RCSID("$NetBSD: rdisc.c,v 1.15 2004/03/27 20:50:43 christos Exp $"); #elif defined(__FreeBSD__) __RCSID("$FreeBSD$"); #else @@ -99,9 +99,10 @@ struct dr { /* accumulated advertisements */ #define UNSIGN_PREF(p) SIGN_PREF(p) /* adjust unsigned preference by interface metric, * without driving it to infinity */ -#define PREF(p, ifp) ((int)(p) <= ((ifp)->int_metric+(ifp)->int_adj_outmetric)\ - ? ((p) != 0 ? 1 : 0) \ - : (p) - ((ifp)->int_metric+(ifp)->int_adj_outmetric)) +#define PREF(p, ifp) ((n_long)(p) <= (n_long)((ifp)->int_metric \ + + (ifp)->int_adj_outmetric) \ + ? ((p) != 0 ? 1 : 0) \ + : (p) - ((ifp)->int_metric + (ifp)->int_adj_outmetric)) static void rdisc_sort(void); diff --git a/sbin/routed/routed.8 b/sbin/routed/routed.8 index 8926b05aac43..e5bff5b3f11c 100644 --- a/sbin/routed/routed.8 +++ b/sbin/routed/routed.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: routed.8,v 1.42 2003/09/07 16:22:23 wiz Exp $ +.\" $NetBSD: routed.8,v 1.43 2004/03/27 20:50:43 christos Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -640,8 +640,7 @@ sets the preference in Router Discovery Advertisements to the optionally signed integer .Ar N . The default preference is 0. -Default routes with smaller or more negative preferences are preferred by -clients. +Default routes with larger preferences are preferred by clients. .It Cm rdisc_interval Ns \&= Ns Ar N sets the nominal interval with which Router Discovery Advertisements are transmitted to N seconds and their lifetime to 3*N.