Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 May 2011 19:46:10 -0700 (PDT)
From:      JACK <jack.shang@huawei.com>
To:        freebsd-net@freebsd.org
Subject:   RE: RE: Is it a bug of RADIX ?????
Message-ID:  <78D2B330B6A30B4CB554FD2EC08D7434F36F04@szxeml508-mbx.china.huawei.com>
In-Reply-To: <4DD3E713.3070008@ipfw.ru>
References:  <1305721909414-4406356.post@n5.nabble.com> <4DD3C17E.9070903@ipfw.ru> <4DD3E713.3070008@ipfw.ru>

next in thread | previous in thread | raw e-mail | index | archive | help

THANKS FOR YOUR REPLY! :)

the version I used can be found here:
http://fxr.watson.org/fxr/source/net/radix.c?v=3DDFBSD

I'm not use the rt_maskedcopy, I 'build' the key by my rdx_build_rtentry.
Maybe there is some bug in my rdx_build_rtentry? but I can't find it!

<pre>
struct rtsockaddr {
    u_char   sa_len;         /* total length */
    // u_char   sa_family;      /* address family */
    u_char   sa_data[18 + 1];    /* actually longer; address value */
};

struct rtentry {
    struct  radix_node rt_nodes[2]; /* tree glue, and other values */
    struct  rtsockaddr key;
    struct  rtsockaddr msk;
    int     rt_index;
};

void rdx_build_rtentry (
    struct rtentry             *rt,
    unsigned int                uiVpnId,
    unsigned int               *puiKey,
    int                         iKeyLen)
{
    int                         k;
    int                         dwLen;

    dwLen =3D (iKeyLen / 32) + !!(iKeyLen & 31);
    rt->key.sa_len =3D 1 + 2 + (iKeyLen / 8) + !!(iKeyLen & 7);
    rt->msk.sa_len =3D rt->key.sa_len;

    rt->key.sa_data[0] =3D (uiVpnId >> 8) & 0xFF;
    rt->key.sa_data[1] =3D uiVpnId & 0xFF;
    rt->msk.sa_data[0] =3D 0xFF;
    rt->msk.sa_data[1] =3D 0xFF;

    for (k =3D 0; k < dwLen; k++)
    {
        rt->key.sa_data[k * 4 + 2] =3D (puiKey[k] >> 24) & 0xFF;
        rt->key.sa_data[k * 4 + 3] =3D (puiKey[k] >> 16) & 0xFF;
        rt->key.sa_data[k * 4 + 4] =3D (puiKey[k] >> 8) & 0xFF;
        rt->key.sa_data[k * 4 + 5] =3D puiKey[k] & 0xFF;
        rt->msk.sa_data[k * 4 + 2] =3D 0xFF;
        rt->msk.sa_data[k * 4 + 3] =3D 0xFF;
        rt->msk.sa_data[k * 4 + 4] =3D 0xFF;
        rt->msk.sa_data[k * 4 + 5] =3D 0xFF;
    }

    for (k =3D iKeyLen / 8 + 2 + !!(iKeyLen & 7);=20
         // k < rt->key.sa_len;=20
         k < sizeof(rt->key.sa_data);
         k++)
    {
        rt->key.sa_data[k] =3D 0;
        rt->msk.sa_data[k] =3D 0;
    }

    if (k =3D (iKeyLen & 0x7))
    {
        rt->key.sa_data[iKeyLen / 8 + 2] &=3D ((1 << k) - 1) << (8 - k);
        rt->msk.sa_data[iKeyLen / 8 + 2] &=3D ((1 << k) - 1) << (8 - k);
    }

    if (1 && 0x36 =3D=3D rt->key.sa_data[2]
          && 0x0a =3D=3D rt->key.sa_data[3])
    {
        int i =3D 0;
        printf ("\r\n%04X/%08X/%2d -> ", uiVpnId, puiKey[0], iKeyLen);
        printf ("%02X ", rt->key.sa_len);
        for (i =3D 0; i < rt->key.sa_len - 0; i++)
        {
            printf ("%02X ", (unsigned char)rt->key.sa_data[i]);
        }
        printf ("/ ");
        printf ("%02X ", rt->key.sa_len);
        for (i =3D 0; i < rt->msk.sa_len - 0; i++)
        {
            printf ("%02X ", (unsigned char)rt->msk.sa_data[i]);
        }
    }
}

int rdx_insert_key (
    struct radix_node_head     *rdx_hdr,
    unsigned int                uiVpnId,
    unsigned int               *puiKey,
    int                         iKeyLen,
    unsigned int                index)
{
    struct rtentry             *rt;

    R_Malloc(rt, struct rtentry *, sizeof(*rt));
    bzero(rt, sizeof(*rt));

    rdx_build_rtentry (rt, uiVpnId, puiKey, iKeyLen);
    rt->rt_index =3D index;

    if (NULL =3D=3D rdx_hdr->rnh_addaddr((char*)&rt->key, (char*)&rt->msk, =
rdx_hdr, rt->rt_nodes))
    {
        return RDX_ALREADY_EXIST;
    }

    return RDX_OK;
}

int rdx_delete_key (
    struct radix_node_head     *rdx_hdr,
    unsigned int                uiVpnId,
    unsigned int               *puiKey,
    int                         iKeyLen)
{
    struct rtentry             rt =3D {0};
    struct rtentry            *rt_hit;

    rdx_build_rtentry (&rt, uiVpnId, puiKey, iKeyLen);

    rt_hit =3D (struct rtentry *) rdx_hdr->rnh_deladdr((char*)&rt.key, (cha=
r*)&rt.msk, rdx_hdr);
    if (NULL =3D=3D rt_hit)
    {
        return RDX_NOT_EXIST;
    }

    Free (rt_hit);
    return RDX_OK;
}

<b>rdx_hdr =3D NULL;
rn_inithead((void **)&rdx_hdr, 8); // I just want to skip the first byte of=
 key</b>
</pre>

and the output of inserting and deleting was as below:
<pre>
Inserting ...
0000/360AD0A2/30 -> 07 00 00 36 0A D0 A0 00 / 07 FF FF FF FF FF FC 00
0000/360ADFEC/20 -> 06 00 00 36 0A D0 00 / 06 FF FF FF FF F0 00
0000/360AD082/30 -> 07 00 00 36 0A D0 80 00 / 07 FF FF FF FF FF FC 00
Dumping ...
07 00 00 36 0A D0 80 / 07 FF FF FF FF FF FC
07 00 00 36 0A D0 A0 / 07 FF FF FF FF FF FC
06 00 00 36 0A D0 / 06 FF FF FF FF F0
Deleting ...
0000/360AD0A2/30 -> 07 00 00 36 0A D0 A0 00 / 07 FF FF FF FF FF FC 00
0000/360ADFEC/20 -> 06 00 00 36 0A D0 00 / 06 FF FF FF FF F0 00 <<<<< fail =
here
0000/360AD082/30 -> 07 00 00 36 0A D0 80 00 / 07 FF FF FF FF FF FC 00
</pre>

/jack

JACKSHANG/62185
HUAWEI TECHNOLOGIES CO.,LTD.=20

Address: Huawei Industrial Base
Bantian Longgang
Shenzhen 518129, P.R.China
E-mail: JACK.SHANG@HUAWEI.COM
www.huawei.com
---------------------------------------------------------------------------=
----------------------------------------------------------
This e-mail and its attachments contain confidential information from HUAWE=
I, which=20
is intended only for the person or entity whose address is listed above. An=
y use of the=20
information contained herein in any way (including, but not limited to, tot=
al or partial=20
disclosure, reproduction, or dissemination) by persons other than the inten=
ded=20
recipient(s) is prohibited. If you receive this e-mail in error, please not=
ify the sender by=20
phone or email immediately and delete it!
=E5=8F=91=E4=BB=B6=E4=BA=BA: Alexander V. Chernikov-2 [via FreeBSD] [mailto=
:ml-node+4406813-1462758870-209672@n5.nabble.com]=20
=E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2011=E5=B9=B45=E6=9C=8818=E6=97=A5 23=
:37
=E6=94=B6=E4=BB=B6=E4=BA=BA: Jack Shang(hongzhang)
=E4=B8=BB=E9=A2=98: Re: =E7=AD=94=E5=A4=8D: Is it a bug of RADIX ?????

On 18.05.2011 19:15, Jack Shang(hongzhang) wrote:=20
> I do these by call the radix routine such as rn_addroute and rn_delete di=
rectly.=20
Okay. Can you provide FreeBSD version and a piece of code triggering=20
such a situation?=20
IMHO radix assumes destination address to have host bits cleared, code in=
=20
rtrequest1_fib does this via rt_maskedcopy().=20
Are you sure you need to pass=20

0x360AD0A2/30=20
0x360ADFEC/20=20
0x360AD082/30=20

instead of:=20
0x360AD0A0/30=20
0x360AD000/20=20
0x360AD080/30=20


?=20

> ________________________________________=20
> =E5=8F=91=E4=BB=B6=E4=BA=BA: Alexander V. Chernikov [[hidden email]]=20
> =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2011=E5=B9=B45=E6=9C=8818=E6=97=A5 =
20:54=20
> =E5=88=B0: Jack Shang(hongzhang)=20
> Cc: [hidden email]=20
> =E4=B8=BB=E9=A2=98: Re: Is it a bug of RADIX ?????=20
>=20
> On 18.05.2011 16:31, JACK wrote:=20
>> After inserting the following IPv4 routers:=20
>>=20
>> 0x360AD0A2/30=20
>> 0x360ADFEC/20=20
>> 0x360AD082/30=20
>>=20
>> I try to delete the above routes, when delete the second=20
>> route(0x360ADFEC/20), the operation fail.=20
> Can you specify exact commands you are issuing to add/remove routes?=20
> (or "route monitor" output if you are doing this from some dynamic=20
> routing software)=20
>=20
> The following order works for me (8.2-STABLE):=20
>=20
> 16:44 [0] bibi# route add -net 54.10.208.162/30 10.11.0.1=20
> add net 54.10.208.162: gateway 10.11.0.1=20
> 16:45 [0] bibi# route add -net 54.10.223.236/20 10.11.0.1=20
> add net 54.10.223.236: gateway 10.11.0.1=20
> 16:46 [0] bibi# route add -net 54.10.208.130/30 10.11.0.1=20
> add net 54.10.208.130: gateway 10.11.0.1=20
>=20
> 16:46 [0] bibi# netstat -rn -finet | grep 54=20
> 54.10.208.0/20 =C2=A0 =C2=A0 10.11.0.1 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
UGS =C2=A0 =C2=A0 =C2=A0 =C2=A0 0 =C2=A0 =C2=A0 =C2=A0 =C2=A00 =C2=A0 =C2=
=A0em0=20
> 54.10.208.128/30 =C2=A0 10.11.0.1 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0UGS =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 0 =C2=A0 =C2=A0 =C2=A0 =C2=A00 =C2=A0 =C2=A0em0=
=20
> 54.10.208.160/30 =C2=A0 10.11.0.1 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0UGS =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 0 =C2=A0 =C2=A0 =C2=A0 =C2=A00 =C2=A0 =C2=A0em0=
=20
> 16:46 [0] bibi# route delete 54.10.208.0/20=20
> delete net 54.10.208.0=20
> 16:48 [0] bibi# route delete 54.10.208.128/30=20
> delete net 54.10.208.128=20
> 16:49 [0] bibi# route delete 54.10.208.160/30=20
> delete net 54.10.208.160=20
> 16:49 [0] bibi# netstat -rn -finet | grep 54=20
> 16:49 [0] bibi#=20
>=20
>=20
>> struct radix_node * rn_delete (........)=20
>> {=20
>> =C2=A0 =C2=A0 =C2=A0...=20
>> =C2=A0 =C2=A0 =C2=A0/*=20
>> =C2=A0 =C2=A0 =C2=A0 * Delete our route from mask lists.=20
>> =C2=A0 =C2=A0 =C2=A0 */=20
>> =C2=A0 =C2=A0 =C2=A0if (netmask !=3D NULL) {=20
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if ((x =3D rn_addmask(netmask, TRUE, h=
ead_off)) =3D=3D NULL)=20
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (NULL);=20
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0netmask =3D x->rn_key;=20
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0while (tt->rn_mask !=3D netmask)=20
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if ((tt =3D tt->rn_duped=
key) =3D=3D NULL)=20
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (NU=
LL); // rn_delete return here!!!=20
>> =C2=A0 =C2=A0 =C2=A0}=20
>> =C2=A0 =C2=A0 =C2=A0...=20
>> }=20
>>=20
>> but, if I delete as the following order, all routers was deleted=20
>> successfully:=20
>>=20
>> 0x360AD0A2/30=20
>> 0x360AD082/30=20
>> 0x360ADFEC/20=20
>>=20
>>=20
>> so, is it a bug of RADIX?=20
>>=20
>> /jack=20
>>=20
>>=20
>>=20
>>=20
>> --=20
>> View this message in context: http://freebsd.1045724.n5.nabble.com/Is-it=
-a-bug-of-RADIX-tp4406356p4406356.html
>> Sent from the freebsd-net mailing list archive at Nabble.com.=20
>> _______________________________________________=20
>> [hidden email] mailing list=20
>> http://lists.freebsd.org/mailman/listinfo/freebsd-net
>> To unsubscribe, send any mail to "[hidden email]"=20

_______________________________________________=20
[hidden email] mailing list=20
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "[hidden email]"=20

________________________________________
If you reply to this email, your message will be added to the discussion be=
low:
http://freebsd.1045724.n5.nabble.com/Is-it-a-bug-of-RADIX-tp4406356p4406813=
.html=20
To unsubscribe from Is it a bug of RADIX ?????, click here.=20


--
View this message in context: http://freebsd.1045724.n5.nabble.com/Is-it-a-=
bug-of-RADIX-tp4406356p4408573.html
Sent from the freebsd-net mailing list archive at Nabble.com.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?78D2B330B6A30B4CB554FD2EC08D7434F36F04>