Re: [homenet] on prefix comparison

Alexandru Petrescu <alexandru.petrescu@gmail.com> Wed, 29 October 2014 18:26 UTC

Return-Path: <alexandru.petrescu@gmail.com>
X-Original-To: homenet@ietfa.amsl.com
Delivered-To: homenet@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id E2AC01A873E for <homenet@ietfa.amsl.com>; Wed, 29 Oct 2014 11:26:38 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.383
X-Spam-Level:
X-Spam-Status: No, score=-2.383 tagged_above=-999 required=5 tests=[BAYES_05=-0.5, DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, HELO_EQ_FR=0.35, J_CHICKENPOX_24=0.6, J_CHICKENPOX_61=0.6, NML_ADSP_CUSTOM_MED=0.9, RCVD_IN_DNSWL_HI=-5, SPF_SOFTFAIL=0.665] autolearn=ham
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c1gqi6NMGiFH for <homenet@ietfa.amsl.com>; Wed, 29 Oct 2014 11:26:37 -0700 (PDT)
Received: from cirse-out.extra.cea.fr (cirse-out.extra.cea.fr [132.167.192.142]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 853F31A0117 for <homenet@ietf.org>; Wed, 29 Oct 2014 11:26:36 -0700 (PDT)
Received: from pisaure.intra.cea.fr (pisaure.intra.cea.fr [132.166.88.21]) by cirse.extra.cea.fr (8.14.2/8.14.2/CEAnet-Internet-out-2.3) with ESMTP id s9TIQWtX023015; Wed, 29 Oct 2014 19:26:32 +0100
Received: from pisaure.intra.cea.fr (localhost [127.0.0.1]) by localhost (Postfix) with SMTP id 6B51520A426; Wed, 29 Oct 2014 19:28:09 +0100 (CET)
Received: from muguet2.intra.cea.fr (muguet2.intra.cea.fr [132.166.192.7]) by pisaure.intra.cea.fr (Postfix) with ESMTP id 5D84220A41F; Wed, 29 Oct 2014 19:28:09 +0100 (CET)
Received: from [127.0.0.1] (is010446-4.intra.cea.fr [10.8.33.116]) by muguet2.intra.cea.fr (8.13.8/8.13.8/CEAnet-Intranet-out-1.2) with ESMTP id s9TIQBQU011404; Wed, 29 Oct 2014 19:26:32 +0100
Message-ID: <54513143.2070004@gmail.com>
Date: Wed, 29 Oct 2014 19:26:11 +0100
From: Alexandru Petrescu <alexandru.petrescu@gmail.com>
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
MIME-Version: 1.0
To: Pierre Pfister <pierre.pfister@darou.fr>
References: <A0C73AEC-6D0F-498B-9BDD-D6AF91202CCB@darou.fr> <54350D62.5050706@gmail.com> <048F40EB-A1D5-4D70-986B-9DDE55FF7C22@darou.fr> <543526D9.2020107@gmail.com> <54352A62.2040605@gmail.com> <4BCB9E4C-31F2-4769-A994-32F58490BD2B@darou.fr>
In-Reply-To: <4BCB9E4C-31F2-4769-A994-32F58490BD2B@darou.fr>
Content-Type: text/plain; charset="windows-1252"; format="flowed"
Content-Transfer-Encoding: 8bit
Archived-At: http://mailarchive.ietf.org/arch/msg/homenet/b1tP4QwG2uV4zc-gPhvrkOXEHDQ
Cc: homenet@ietf.org
Subject: Re: [homenet] on prefix comparison
X-BeenThere: homenet@ietf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <homenet.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/homenet>, <mailto:homenet-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/homenet/>
List-Post: <mailto:homenet@ietf.org>
List-Help: <mailto:homenet-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/homenet>, <mailto:homenet-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 29 Oct 2014 18:26:39 -0000

Hi Pierre,

I took some time to understand the code.

But here is what I would like to say.

Your algorithm decides whether or not one prefix collides with another, 
by comparing prefix/plen pairs according to an exact match rule.

On another hand, the forwarding towards these prefixes is realized by 
longest-prefix match rule applied to an address against successive 
entries in a routing table.  By this rule an address/128 matches the 
first one entry whose prefix length is longest, if several; and default 
otherwise.

If one hears two prefix/plen pairs in RAs and decides they 'collide' by 
the exact match rule implemented by the code below then one may decide 
this is a bad configuration situation.  At the same time the forwarding 
may be set up ok, because it uses the longest-prefix match rule, not 
exact match, and has a default to escape to as well.

This is why I am saying that any method to compare prefixes may not be 
agreed on, may not lead to effective results, unless designed according 
to the rules used for forwarding.

Yours,

Alex



Le 08/10/2014 14:25, Pierre Pfister a écrit :
> A prefix can only contain another prefix if its prefix length is smaller.
>
> Here is some C-code that provides what you are looking for.
>
> Cheers,
>
> - Pierre
>
>
> /* Tell whether a prefix contains an address */
> uint8_t prefix_contains(const struct in6_addr *p, uint8_t plen, const struct in6_addr *addr)
> {
> 	int blen = plen >> 3;
> 	if(blen && memcmp(p, addr, blen))
> 		return 0;
>
> 	int rem = plen & 0x07;
> 	if(rem && ((p->s6_addr[blen] ^ addr->s6_addr[blen]) >> (8 - rem)))
> 		return 0;
>
> 	return 1;
> }
>
> /* Tell whether a prefix contains another prefix */
> uint8_t prefix_include(const struct in6_addr *p1, uint8_t plen1, const struct in6_addr *p2, uint8_t plen2)
> {
> 	if(plen1 > plen2)
> 		return 0;
> 	
> 	return prefix_contains(p1, plen1, p2);
> }
>
> /* Tell whether two prefixes are colliding */
> uint8_t prefix_collision(const struct in6_addr *p1, uint8_t plen1, const struct in6_addr *p2, uint8_t plen2)
> {
> 	return prefix_include(p1, plen1, p2, plen2) || prefix_include(p2, plen2, p1, plen1);
> }
>
>
> Le 8 oct. 2014 à 14:13, Alexandru Petrescu <alexandru.petrescu@gmail.com> a écrit :
>
>> Pierre, just a small doubt, but I agree with you in general.
>>
>> Le 08/10/2014 13:58, Alexandru Petrescu a écrit :
>> [...]
>>>> Equality is never considered alone. Actually, most of the time, you
>>>> will find considerations such as: The prefix is not included or does
>>>> not include any other Assigned Prefix with a higher precedence.
>>
>> It is hard to say whether a prefix is included into another or not.  We do not have a published algorithm to say what it means for a prefix to include another.
>>
>> In general, we have a common understanding (and not published algorithm) about what it means 'longest prefix match'.  But that compares an address to a prefix, not a prefix to a prefix.
>>
>> Sure, one could assume that an address is just a /128 prefix and execute longest prefix match with it as if it were an address.
>>
>> But then again which prefix has the role of the address and which is the role of the prefix?  In other words, when hearing two prefixes on a link and want to compare them, which of them should be compared against the other by using the longest-prefix match?  There are two possibilities and two different outputs for a particular tuple of prefixes, depending on the order of this longest prefix match.
>>
>> Of course, I do not mention the easy case which compares two prefixes of precisely same length.
>>
>> Just because the length is different may make think that the prefixes are different.  Or otherwise one could be aggregated into another.  But there are several types of aggregation: matching up to the shortest length, matching up to middle, up to longest length, beyond the longest length.
>>
>> These cases are not documented and people may implement them in many different ways with different outputs when trying to tell whether this or that prefix are equal or included into one another.
>>
>> Alex
>>
>>
>
>
>