Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Jul 2012 17:59:38 -0700
From:      prabhakar lakhera <prabhakar.lakhera@gmail.com>
To:        freebsd-net@freebsd.org
Subject:   defrouter_addreq calling RTFREE?
Message-ID:  <CALg%2BrhXhe7WShYJtKUtk3Eh8eGWqj-vnoxyB5O4woMtnnFbkLA@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CALg%2BrhXhe7WShYJtKUtk3Eh8eGWqj-vnoxyB5O4woMtnnFbkLA>