<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Erik,<br>
<br>
I tried it and it produces a segmentation fault in
olsr_calculate_lq_mpr:<br>
<br>
MPRS: Update 10.2.16.78<br>
<br>
Program received signal SIGSEGV, Segmentation fault.<br>
0x080527a5 in olsr_calculate_lq_mpr ()<br>
(gdb) bt<br>
#0  0x080527a5 in olsr_calculate_lq_mpr ()<br>
#1  0x08053245 in olsr_output_lq_tc ()<br>
#2  0x0805db89 in scheduler ()<br>
#3  0x080546ac in main ()<br>
(gdb) <br>
<br>
I could look further into it with the debuger but I believe that it
doesn't make sense to have simultaneously two links with the same local
and remote ip. I am not suprised that olsrd can't handle it because it
is as if it had the same link with two different neighbors.<br>
<br>
Regards,<br>
Bill<br>
<blockquote cite="midBAY112-F2296D7B0E9EB49F5BAED60F1F40@phx.gbl"
 type="cite">
  <div style="">
  <p>Actually, I think the problem is surprisingly easy to solve.</p>
  <p>It's like working for the secret service. If your ID changes,
no-one is updated about this. Your old ID just kind of disappears over
time (times out), and your new ID gets known gradually.</p>
  <p>I propose to leave the link entries with the old ID to time out,
taking their neighbor entries with them. The new link entries with the
new ID automatically take care of setting up a new neighbor entry.</p>
  <p>What do you think of the following changes in the add_new_entry()
function (src/link_set.c, lines 402 a.o.):</p>
  <p>  while(tmp_link_set)<br>
    {<br>
      if(COMP_IP(remote, &tmp_link_set->neighbor_iface_addr)
&&<br>
         COMP_IP(local, &tmp_link_set->local_iface_addr)
&&<br>
         COMP_IP(remote_main,
&tmp_link_set->neighbor->neighbor_main_addr))<br>
        return tmp_link_set;<br>
      tmp_link_set = tmp_link_set->next;<br>
    }</p>
  <p>And also, a couple of lines down (lines 502 a.o.):</p>
  <p>  /* Copy the main address - make sure this is done every time<br>
   * as neighbors might change main address */<br>
  /* Erik Tromp - OOPS! Don't do this! Neighbor entries are hashed
through their<br>
   * neighbor_main_addr field, and when that field is changed, their
position<br>
   * in the hash table is no longer correct, so that the function<br>
   * olsr_lookup_neighbor_table() can no longer find the neighbor<br>
   * entry. */<br>
  /*COPY_IP(&neighbor->neighbor_main_addr, remote_main);*/<br>
  <br>
  </p>
  <blockquote
 style="border-left: 2px solid rgb(160, 198, 229); padding-left: 5px; margin-left: 5px; margin-right: 0px;"><font
 style="font-size: 11px; font-family: tahoma,sans-serif;">
    </font>
    <hr color="#a0c6e5" size="1"><font
 style="font-size: 11px; font-family: tahoma,sans-serif;">From: <i>Acinonyx
<a class="moz-txt-link-rfc2396E" href="mailto:acinonyxs@yahoo.gr"><acinonyxs@yahoo.gr></a></i><br>
Reply-To: <i>OLSR development <a class="moz-txt-link-rfc2396E" href="mailto:olsr-dev@olsr.org"><olsr-dev@olsr.org></a></i><br>
To: <i>OLSR development <a class="moz-txt-link-rfc2396E" href="mailto:olsr-dev@olsr.org"><olsr-dev@olsr.org></a></i><br>
Subject: <i>Re: [olsr-dev] bug in mdi code</i><br>
Date: <i>Sun, 12 Nov 2006 15:29:22 +0200</i><br>
    <br>
    <meta content="Microsoft SafeHTML" name="Generator">
Yes you are right Erik,<br>
    <br>
the previous fix doesn't update the neighbor set. So we end up with a
"ghost" neighbor entry. :(<br>
    <br>
Ok, so could we delete (or decrease linkcount if  > 1) and recreate
a neighbor entry with the new main address?<br>
    <br>
Do you think it will work?<br>
    </font>
    <blockquote cite="midBAY112-DAV12C955839706F30521458FF1F50@phx.gbl">
      <style>
      </style><font
 style="font-size: 11px; font-family: tahoma,sans-serif;">
      </font>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">Bill,</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2"><br>
I'm afraid that this fix is not enough.</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">Is updating 'neighbor->neighbor_main_addr'
safe? It seems that the neighbor set is hashed through
'neighbor_main_addr'. If 'neighbor_main_addr' is changed, the neighbor
entry must get another position in the hash table.</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">Also, a problem arises when a node is neighbor
to another node via two separate network interfaces (i.e. via 2 links).</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">In that case there will be one neighbor entry
with linkcount 2 (1 for each link).<br>
      <br>
When the main IP address of the neighbor node changes, the HELLO
messages from that interface are sent with the new IP address as source
('remote'), and with the new IP address as originator address
('remote_main').</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">Because 'remote' does not match any existing
link, the while(tmp_link_set) loop will not find any existing link, so
a new link entry is made.</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">Also, since ''remote_main' does not match any
existing neighbor entry, a new neighbor entry is made:</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">  if(NULL == (neighbor =
olsr_lookup_neighbor_table(remote_main)))<br>
    {<br>
      </font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">The linkcount will be 1:</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">  neighbor->linkcount++;<br>
      </font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">Next, a HELLO message comes in via the second
network interface, with the new IP address as originator address
('remote_main'). </font><font face="Arial" size="2">The fix you
propose will correctly update the (old) neighbor entry (the one with
with 'linkcount' 2):</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">   
COPY_IP(&tmp_link_set->neighbor->neighbor_main_addr, remote_main);</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">After a while, the link with the old remote IP
address will time out. However, the old, but updated neigbor entry will
not be removed, since its 'linkcount' > 1. Its 'linkcount' value
will be decreased from 2 to 1.</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">The result: we have two neighbor entries, each
with 'linkcount' 1, and each with the same 'neighbor_main_addr'.</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2"><br>
Besides this, there is a small bug in the function chk_if_changed
(src/unix/ifnet.c)<br>
      <br>
       memcpy(&main_addr, <br>
       &((struct sockaddr_in
*)&ifp->int_addr)->sin_addr.s_addr, <br>
       ipsize);<br>
     }</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">   ifp->int_addr = ifr.ifr_addr;<br>
      </font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">The memcpy is copying the existing IP address in
main_addr, not the new IP address. Or: ifr.ifr_addr is copied into
ifp->int_addr too late.</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">Last: the olsr_process_received_mid function
only adds MID aliases, not remove. I have written a function that
removes the MID aliases which are registered but no longer declared in
the received MID message. Here is the code:</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">/**<br>
 *Remove aliases from 'entry' which are not listed in
'declared_aliases'.<br>
 *<br>
 <a href="mailto:*@param">*@param</a> entry the MID entry<br>
 <a href="mailto:*@param">*@param</a> declared_aliases the list of
declared aliases for the MID entry<br>
 *<br>
 <a href="mailto:*@return">*@return</a> nada<br>
 */<br>
void<br>
olsr_prune_aliases(union olsr_ip_addr *m_addr, struct mid_alias
*declared_aliases)<br>
{<br>
  struct mid_entry *entry;<br>
  olsr_u32_t hash;<br>
  struct mid_address *registered_aliases;<br>
  struct mid_address *previous_alias;<br>
  struct mid_alias *save_declared_aliases = declared_aliases;</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">  hash = olsr_hashing(m_addr);</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">  /* Check for registered entry */<br>
  for(entry = mid_set[hash].next;<br>
      entry != &mid_set[hash];<br>
      entry = entry->next)<br>
    {<br>
      if(COMP_IP(&entry->main_addr, m_addr))</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">        break;<br>
    }<br>
  if(entry == &mid_set[hash])<br>
    {<br>
      /* MID entry not found, nothing to prune here */<br>
      return;<br>
    }</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">  registered_aliases = entry->aliases;<br>
  previous_alias = NULL;</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">  while(registered_aliases != 0)<br>
    {<br>
      struct mid_address *current_alias = registered_aliases;<br>
      registered_aliases = registered_aliases->next_alias;</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">      declared_aliases = save_declared_aliases;</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">      /* Go through the list of declared aliases
to find the matching current alias */<br>
      while(declared_aliases != 0 &&<br>
            ! COMP_IP(&current_alias->alias,
&declared_aliases->alias_addr))<br>
        {<br>
          declared_aliases = declared_aliases->next;<br>
        }</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">      if (declared_aliases == 0)<br>
        {<br>
          /* Current alias not found in list of declared aliases: free
current alias */<br>
          OLSR_PRINTF(1, "MID remove: (%s, ",
olsr_ip_to_string(&entry->main_addr))<br>
          OLSR_PRINTF(1, "%s)\n",
olsr_ip_to_string(&current_alias->alias))</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">          /* Update linked list as seen by
'entry' */<br>
          if (previous_alias != NULL)<br>
            {<br>
              previous_alias->next_alias =
current_alias->next_alias;<br>
            }<br>
          else<br>
            {<br>
              entry->aliases = current_alias->next_alias;<br>
            }</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">          /* Remove from hash table */<br>
          DEQUEUE_ELEM(current_alias);<br>
 <br>
          free(current_alias);</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">          /*<br>
           *Recalculate topology<br>
           */<br>
          changes_neighborhood = OLSR_TRUE;<br>
          changes_topology = OLSR_TRUE;<br>
        }<br>
      else<br>
        {<br>
          previous_alias = current_alias;<br>
        }<br>
    }<br>
}</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2"><br>
      </font> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">Regards,</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><font
 face="Arial" size="2">Erik</font></font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"> </font></div>
      <div><font
 style="font-size: 11px; font-family: tahoma,sans-serif;"><br>
      <br>
      <font face="Arial" size="2">----- Original Message ----- <br>
From: "Acinonyx" <</font><a href="mailto:acinonyxs@yahoo.gr"><font
 face="Arial" size="2">acinonyxs@yahoo.gr</font></a><font face="Arial"
 size="2">><br>
To: "OLSR development" <</font><a href="mailto:olsr-dev@olsr.org"><font
 face="Arial" size="2">olsr-dev@olsr.org</font></a><font face="Arial"
 size="2">><br>
Sent: Friday, November 10, 2006 11:16 PM<br>
Subject: Re: [olsr-dev] bug in mdi code<br>
      <br>
      <br>
> Ok, here is a patch i made. It adds neighbor main address update on<br>
> every link entry update.<br>
><br>
> I tested it and it works.<br>
><br>
> Bill<br>
><br>
> -------------------<br>
> diff -Naur olsrd-0.4.10/src/link_set.c
olsrd-0.4.10-patched/src/link_set.c<br>
> --- olsrd-0.4.10/src/link_set.c 2005-11-17 06:25:44.000000000 +0200<br>
> +++ olsrd-0.4.10-patched/src/link_set.c 2006-11-10
23:45:24.000000000 +0200<br>
> @@ -403,7 +466,10 @@<br>
>      {<br>
>        if(COMP_IP(remote,
&tmp_link_set->neighbor_iface_addr) &&<br>
>          COMP_IP(local, &tmp_link_set->local_iface_addr))<br>
> -       return tmp_link_set;<br>
> +        {<br>
> +         
COPY_IP(&tmp_link_set->neighbor->neighbor_main_addr,<br>
> remote_main);<br>
> +         return tmp_link_set;<br>
> +        }<br>
>        tmp_link_set = tmp_link_set->next;<br>
>      }<br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> olsr-dev mailing list<br>
> </font><a href="mailto:olsr-dev@olsr.org"><font face="Arial"
 size="2">olsr-dev@olsr.org</font></a><br>
      <font face="Arial" size="2">> </font><a
 href="https://www.olsr.org/mailman/listinfo/olsr-dev"><font
 face="Arial" size="2">https://www.olsr.org/mailman/listinfo/olsr-dev</font></a><br>
      <font face="Arial" size="2">><br>
      </font></font></div>
      <pre><hr size="4" width="90%">
<font style="font-size: 11px; font-family: tahoma,sans-serif;">_______________________________________________
olsr-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:olsr-dev@olsr.org">olsr-dev@olsr.org</a>
<a class="moz-txt-link-freetext"
 href="https://www.olsr.org/mailman/listinfo/olsr-dev">https://www.olsr.org/mailman/listinfo/olsr-dev</a>
  </font></pre>
    </blockquote>
    <font style="font-size: 11px; font-family: tahoma,sans-serif;"><br>
    <br>
    </font>
    <p><font style="font-size: 11px; font-family: tahoma,sans-serif;">>_______________________________________________<br>
>olsr-dev mailing list<br>
><a class="moz-txt-link-abbreviated" href="mailto:olsr-dev@olsr.org">olsr-dev@olsr.org</a><br>
><a class="moz-txt-link-freetext" href="https://www.olsr.org/mailman/listinfo/olsr-dev">https://www.olsr.org/mailman/listinfo/olsr-dev</a><br>
    </font></p>
  </blockquote>
  </div>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
olsr-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:olsr-dev@olsr.org">olsr-dev@olsr.org</a>
<a class="moz-txt-link-freetext" href="https://www.olsr.org/mailman/listinfo/olsr-dev">https://www.olsr.org/mailman/listinfo/olsr-dev</a>
  </pre>
</blockquote>
<br>
</body>
</html>