From owner-freebsd-net@FreeBSD.ORG Fri Jul 20 00:59:40 2012 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 04BF7106564A for ; Fri, 20 Jul 2012 00:59:40 +0000 (UTC) (envelope-from prabhakar.lakhera@gmail.com) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by mx1.freebsd.org (Postfix) with ESMTP id 7C75B8FC08 for ; Fri, 20 Jul 2012 00:59:39 +0000 (UTC) Received: by lbon10 with SMTP id n10so5469607lbo.13 for ; Thu, 19 Jul 2012 17:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=viLUhLc4J4XkIDZe1bWRfxRVSbDXXToF2wz7Fesl6/Y=; b=Hh52tZIxsLg4N7qRt7yuIEGoe6lUtXU2I/RzQm7rqyMbCTmAK8hgEjPvfYcjwOlOL+ D0Pi0Ht7SNuY73M3XpD3XGPQvDDl2Gv7ChFp5GaGrzdHM7A3hKjTO6hXz9F63y2dzMzX cUmt/gQJrBqMGSY7cdVNif/5twRd26zrWgZE/R5WDfFcQ+L3eSS1gOxfWHs5PTur7ZR9 O0Eo1V09kS6z3Bmp3/Hb6N6QLtbXYyF0jWJYdrO+wQbOtg4c14wGzHgvqd+5YyjP0NXE cmv8H+sern2OpHB2IRBr8ZTCBx+E3/B4y9NSIkWGn8q/E7O6Rs0JEy0s10mzABaGvv2B 8OBQ== MIME-Version: 1.0 Received: by 10.152.104.44 with SMTP id gb12mr4174228lab.29.1342745978452; Thu, 19 Jul 2012 17:59:38 -0700 (PDT) Received: by 10.114.23.170 with HTTP; Thu, 19 Jul 2012 17:59:38 -0700 (PDT) Date: Thu, 19 Jul 2012 17:59:38 -0700 Message-ID: From: prabhakar lakhera To: freebsd-net@freebsd.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: defrouter_addreq calling RTFREE? X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jul 2012 00:59:40 -0000 Hi, It could very well be that my brain wires are not working late in the day. >From what I know most of the routing table entries (unless referenced by some other entity or another route in routing table) have reference count 0. At least that's how things used to be in BSD as also stated in TCP IP illustrated: *Routing Table Reference Counts* *The handling of the routing table reference count, rt_refcnt, differs from most other reference * *counts. We see in Figure 18.2 that most routes have a reference count of 0, yet the routing table entries * *without any references are not deleted. We just saw the reason in rtfree: an entry with a * *reference count of 0 is not deleted unless the entry=92s RTF_UP flag is no= t set. The only time this flag * *is cleared is by rtrequest when a route is deleted from the routing tree. = * I fail to understand why defrouter_addreq in nd6_rtr.c calls RTFREE: error =3D rtrequest(RTM_ADD, (struct sockaddr *)&def, (struct sockaddr *)&gate, (struct sockaddr *)&mask, RTF_GATEWAY, &newrt); =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D> Since we provide &newr= t the reference would be incremented to 1? if (newrt) { nd6_rtmsg(RTM_ADD, newrt); /* tell user process */ RTFREE(newrt); =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D> When we call= RTFREE the reference is 1? } Now RTFREE has been defined as: #define RTFREE(_rt) do { \ RT_LOCK(_rt); \ RTFREE_LOCKED(_rt); \ } while (0) and RTFREE_LOCKED is defined as: #define RTFREE_LOCKED(_rt) do { \ if ((_rt)->rt_refcnt <=3D 1) \ rtfree(_rt); \ =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D> rtfre= e will be called since ref else { \ RT_REMREF(_rt); \ RT_UNLOCK(_rt); \ } \ /* guard against invalid refs */ \ _rt =3D 0; \ } while (0) Shouldn't the count be just decremented calling RT_REMREF(rt); like in rtinit? Best, Prabhakar