maybe it is a bug in nexthop__same function

Maria Jan Matějka jan.matejka at nic.cz
Mon Mar 11 11:19:20 CET 2019


On March 11, 2019 10:57:06 AM GMT+01:00, Derek Pan <DPan at advaoptical.com> wrote:
> Hi
> 
> I think below function should be used by comparing two netxhop object
> with different pointer.
> If this function is called, the X and Y always have different pointer
> values, but if their values are same, they also can be treated as the
> same.
> I think the "return x== y;" should be replaced by "return 1;".
> Please have a look. Thank.
> 
> int
> nexthop__same(struct nexthop *x, struct nexthop *y)
> {
>   for (; x && y; x = x->next, y = y->next)
>   {
>     if (!ipa_equal(x->gw, y->gw) || (x->iface != y->iface) ||
>              (x->flags != y->flags) || (x->weight != y->weight) ||
>        (x->labels_orig != y->labels_orig) || (x->labels != y->labels))
>       return 0;
> 
>     for (int i = 0; i < x->labels; i++)
>       if (x->label[i] != y->label[i])
>              return 0;
>   }
> 
>   return x == y;
> }

The next hop object is a linked list. This function compares it nodewise. The loop condition is x && y, meaning that both are not null, and the third expression in the for-header retrieves the next nodes.

When the loop ends without returning 0, it is sure that x or y is null. If the other is also null, the lists are same, if not, there are some more next hop in one of the lists and they are obviously not same.

The return x == y is precisely what we want there. Or do I miss something looking into this only on my phone in the underground?

Maria



More information about the Bird-users mailing list