From sklower@isi.deterlab.net  Fri Jan  4 02:03:14 2013
Return-Path: <sklower@isi.deterlab.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id E85A0E7D
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  4 Jan 2013 02:03:14 +0000 (UTC)
	(envelope-from sklower@isi.deterlab.net)
Received: from users.isi.deterlab.net (users.isi.deterlab.net [206.117.25.49])
	by mx1.freebsd.org (Postfix) with ESMTP id C43BA2C3
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  4 Jan 2013 02:03:14 +0000 (UTC)
Received: from users.isi.deterlab.net (localhost.isi.deterlab.net [127.0.0.1])
	by users.isi.deterlab.net (8.14.5/8.14.4) with ESMTP id r041jBGf003569;
	Thu, 3 Jan 2013 17:45:11 -0800 (PST)
	(envelope-from sklower@users.isi.deterlab.net)
Received: (from sklower@localhost)
	by users.isi.deterlab.net (8.14.5/8.13.8/Submit) id r041jBwb003568;
	Thu, 3 Jan 2013 17:45:11 -0800 (PST)
	(envelope-from sklower)
Message-Id: <201301040145.r041jBwb003568@users.isi.deterlab.net>
Date: Thu, 3 Jan 2013 17:45:11 -0800 (PST)
From: Keith Sklower <sklower@cs.berkeley.edu>
Reply-To: Keith Sklower <sklower@cs.berkeley.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc: deter-ops@isi.edu
Subject: [patch] rnh_walktree_from visits spurious nodes
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         174959
>Category:       kern
>Synopsis:       [net] [patch] rnh_walktree_from visits spurious nodes
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    melifaro
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 04 02:10:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Thu May  1 15:10:00 UTC 2014
>Originator:     Keith Sklower
>Release:        FreeBSD 9.1-RC2 i386
>Organization:
University of California, Berkeley
>Environment:
System: FreeBSD users.isi.deterlab.net 9.1-RC2 FreeBSD 9.1-RC2 #7: Tue Oct 9 19:14:50 PDT 2012 root@users.isi.deterlab.net:/usr/obj/usr/src/sys/USERS9 i386


	any machine, any version of FreeBSD after 2.3 

>Description:

	The radix tree method rnh_walktree_from (as implemented 
	by rn_walktree_from in /sys/net/radix.c) invokes the helper
	function f on nodes that it should not, even when supplied with
	inputs adhering to its unreasonably strict assumptions.

	It is low priority because nothing in the source
	distribution uses this function anymore.  We have a local need for it.

>How-To-Repeat:

        Construct a routing tree with the following 4 routes:
	128.32.8.0/24
	128.32.9.0/24
	128.32.8.1 (host)
	128.32.8.2 (host)

	invoke rn_walktree_from(tree, 128.32.9.0, 255.255.255.0, f, 0)
	where f prints the IP address in each leaf visited.

	[I can supply 94 line C program that demonstrates this at user level]

	It should only visit 128.32.9.0/24; instead it visits the entire
	tree.

>Fix:

--- radix.c	2012-11-28 10:23:37.000000000 -0800
+++ radix.c.pfix	2013-01-03 16:12:33.000000000 -0800
@@ -1009,11 +1009,11 @@
 	/*
 	 * Two cases: either we stepped off the end of our mask,
 	 * in which case last == rn, or we reached a leaf, in which
-	 * case we want to start from the last node we looked at.
-	 * Either way, last is the node we want to start from.
+	 * case we want to start from the leaf.
 	 */
-	rn = last;
-	lastb = rn->rn_bit;
+	 if (rn-> rn_bit >= 0)
+	    rn = last;
+	lastb = last->rn_bit;
 
 	/* printf("rn %p, lastb %d\n", rn, lastb);*/
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Jan 20 01:54:19 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=174959 
Responsible-Changed-From-To: freebsd-net->melifaro 
Responsible-Changed-By: melifaro 
Responsible-Changed-When: Thu May 1 14:59:13 UTC 2014 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=174959 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/174959: commit references a PR
Date: Thu,  1 May 2014 15:04:39 +0000 (UTC)

 Author: melifaro
 Date: Thu May  1 15:04:32 2014
 New Revision: 265196
 URL: http://svnweb.freebsd.org/changeset/base/265196
 
 Log:
   Fix rnh_walktree_from() function (patch from kern/174959).
   Require valid netmask to be passed since host route is always a leaf.
   
   PR:		kern/174959
   Submitted by:	Keith Sklower
   MFC after:	2 weeks
 
 Modified:
   head/sys/net/radix.c
 
 Modified: head/sys/net/radix.c
 ==============================================================================
 --- head/sys/net/radix.c	Thu May  1 15:03:26 2014	(r265195)
 +++ head/sys/net/radix.c	Thu May  1 15:04:32 2014	(r265196)
 @@ -971,6 +971,8 @@ rn_walktree_from(struct radix_node_head 
  	int stopping = 0;
  	int lastb;
  
 +	KASSERT(m != NULL, ("%s: mask needs to be specified", __func__));
 +
  	/*
  	 * rn_search_m is sort-of-open-coded here. We cannot use the
  	 * function because we need to keep track of the last node seen.
 @@ -994,11 +996,11 @@ rn_walktree_from(struct radix_node_head 
  	/*
  	 * Two cases: either we stepped off the end of our mask,
  	 * in which case last == rn, or we reached a leaf, in which
 -	 * case we want to start from the last node we looked at.
 -	 * Either way, last is the node we want to start from.
 +	 * case we want to start from the leaf.
  	 */
 -	rn = last;
 -	lastb = rn->rn_bit;
 +	if (rn->rn_bit >= 0)
 +		rn = last;
 +	lastb = last->rn_bit;
  
  	/* printf("rn %p, lastb %d\n", rn, lastb);*/
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
