Esempio n. 1
0
void insert_routing_set(struct olsrv2 *olsr,
            union olsr_ip_addr *dest_iface_addr,
            const union olsr_ip_addr *next_iface_addr,
            olsr_u8_t prefix_length,
            olsr_u16_t dist,
            const union olsr_ip_addr *iface_addr)
{
  OLSR_ROUTING_TUPLE data;

  //Multi path check
  if (OLSR_TRUE)
  {
    if (search_routing_set_for_dest_exist(olsr, dest_iface_addr) == OLSR_TRUE ||//yowada add
       match_local_iface_addr(olsr, dest_iface_addr) == OLSR_TRUE)
      {
      if (DEBUG_OLSRV2)
      {
          char* paddr = olsr_niigata_ip_to_string(olsr, dest_iface_addr);
          olsr_printf("Route %s has already exist! hopcount = %d\n",paddr,dist);
          free(paddr);
      }

      return;
      //olsr_error("Multi path!!\n");
      }
  }
//Fix for Solaris
  //data.R_dest_iface_addr = *dest_iface_addr;
  //data.R_next_iface_addr = *next_iface_addr;
  olsr_ip_copy(olsr, &data.R_dest_iface_addr, dest_iface_addr);
  olsr_ip_copy(olsr, &data.R_next_iface_addr, next_iface_addr);
  data.R_prefix_length = prefix_length;
  data.R_dist = dist;
  //data.R_iface_addr = *iface_addr;
  olsr_ip_copy(olsr, &data.R_iface_addr, iface_addr);

  /*
    assert(equal_ip_addr(olsr_cnf->ip_version,
    data.R_dest_iface_addr,
    data.R_iface_addr) == OLSR_FALSE);
  */
  if (equal_ip_addr(olsr,
           &data.R_dest_iface_addr,
           &data.R_iface_addr))
  {
      return;
  }

  OLSR_InsertList(&olsr->routing_set[olsr_hashing(olsr,&data.R_dest_iface_addr)].list,
          &data, sizeof(OLSR_ROUTING_TUPLE));
  /*   OLSR_InsertList_Sort(&olsr->routing_set, */
  /*               &data, */
  /*               sizeof(OLSR_ROUTING_TUPLE), */
  /*               sort_routing_set_handler); */
}
Esempio n. 2
0
olsr_bool search_mpr_set_for_exist(struct olsrv2 *olsr,
                   union olsr_ip_addr *local_iface_addr,
                   union olsr_ip_addr *MPR_if_addr)
{
  OLSR_MPR_TUPLE search;

  olsr_ip_copy(olsr, &search.local_iface_addr, local_iface_addr);
  olsr_ip_copy(olsr, &search.MPR_if_addr, MPR_if_addr);

  return OLSR_CheckMatchExist((void*)olsr,&olsr->mpr_set, (void* )&search, &search_mpr_set_handler);
}
Esempio n. 3
0
OLSR_LIST *search_mpr_set(struct olsrv2 *olsr,
              union olsr_ip_addr *local_iface_addr,
              union olsr_ip_addr *MPR_if_addr)
{
  OLSR_MPR_TUPLE search;

  olsr_ip_copy(olsr, &search.local_iface_addr, local_iface_addr);
  olsr_ip_copy(olsr, &search.MPR_if_addr, MPR_if_addr);

  return OLSR_SearchList((void*)olsr,&olsr->mpr_set, (void* )&search, &search_mpr_set_handler);
}
Esempio n. 4
0
void delete_routing_set_old(struct olsrv2 *olsr,
                union olsr_ip_addr *dest_iface_addr,
                const union olsr_ip_addr *next_iface_addr)
{
  OLSR_ROUTING_TUPLE todelete;

  olsr_ip_copy(olsr, &todelete.R_dest_iface_addr, dest_iface_addr);
  olsr_ip_copy(olsr, &todelete.R_next_iface_addr, next_iface_addr);

  OLSR_DeleteListHandler((void*)olsr,
             &olsr->routing_set_old[olsr_hashing(olsr,dest_iface_addr)].list,
             (void* )&todelete,
             &delete_routing_set_old_handler);
}
OLSR_LIST *
search_topology_set(struct olsrv2 *olsr,
                    const union olsr_ip_addr *adv_neighbor_addr,
                    union olsr_ip_addr *orig_addr)
{
    OLSR_LIST *result = NULL;
    OLSR_TOPOLOGY_TUPLE search;

    olsr_ip_copy(olsr, &search.T_dest_iface_addr, adv_neighbor_addr);
    olsr_ip_copy(olsr, &search.T_last_iface_addr, orig_addr);

    result = OLSR_SearchList((void*)olsr,&olsr->topology_set[olsr_hashing(olsr,orig_addr)].list,
                             (void* )&search,
                             &search_topology_set_handler);

    return result;
}
Esempio n. 6
0
OLSR_LIST *search_routing_set_old_for_next_and_dest(
                            struct olsrv2* olsr,
                            union olsr_ip_addr *dest_iface_addr,
                            const union olsr_ip_addr *next_iface_addr)
{
  OLSR_LIST *result = NULL;
  OLSR_ROUTING_TUPLE search;

  olsr_ip_copy(olsr, &search.R_dest_iface_addr, dest_iface_addr);
  olsr_ip_copy(olsr, &search.R_next_iface_addr, next_iface_addr);

  result = OLSR_SearchList((void*)olsr,&olsr->routing_set_old[olsr_hashing(olsr,dest_iface_addr)].list,
               (void* )&search,
               &search_routing_set_for_next_and_dest_handler);

  return result;

}
void insert_relay_set(struct olsrv2 *olsr,
              union olsr_ip_addr *neighbor_iface_addr)
{
  OLSR_RELAY_TUPLE data;
//Fix for Solaris
  //data.RS_if_addr = *neighbor_iface_addr;
  olsr_ip_copy(olsr, &data.RS_if_addr, neighbor_iface_addr);
  OLSR_InsertList(&olsr->relay_set, &data, sizeof(OLSR_RELAY_TUPLE));
}
olsr_bool search_association_set_for_addr_exist(struct olsrv2 *olsr,
                        union olsr_ip_addr *addr){
    OLSR_ASSOCIATION_TUPLE search;

    olsr_ip_copy(olsr, &search.NA_iface_addr, addr);
    return OLSR_CheckMatchExist((void*)olsr,
                &olsr->associ_set[olsr_hashing(olsr,addr)].list,
                (void* )&search,
                &search_association_set_for_addr_handler);
}
void insert_topology_set(struct olsrv2 *olsr,
                         const union olsr_ip_addr *adv_neighbor_addr,
                         union olsr_ip_addr *orig_addr,
                         olsr_u16_t ASSN)
{
    OLSR_TOPOLOGY_TUPLE data;
//Fix for Solaris
    //data.T_dest_iface_addr = *adv_neighbor_addr;
    //data.T_last_iface_addr = *orig_addr;
    olsr_ip_copy(olsr, &data.T_dest_iface_addr, adv_neighbor_addr);
    olsr_ip_copy(olsr, &data.T_last_iface_addr, orig_addr);
    data.T_seq = ASSN;

    get_current_time(olsr, &data.T_time);
    update_time(&data.T_time,(olsr_32_t)olsr->qual_cnf->topology_hold_time);

    OLSR_InsertList(&olsr->topology_set[olsr_hashing(olsr,orig_addr)].list,
                    &data,
                    sizeof(OLSR_TOPOLOGY_TUPLE));
}
Esempio n. 10
0
void insert_routing_set_old(struct olsrv2 *olsr,
                const union olsr_ip_addr *dest_iface_addr,
                const union olsr_ip_addr *next_iface_addr,
                olsr_u8_t prefix_length,
                olsr_u16_t dist,
                const union olsr_ip_addr *iface_addr)
{
  OLSR_ROUTING_TUPLE data;
//Fix for Solaris
  //data.R_dest_iface_addr = *dest_iface_addr;
  //data.R_next_iface_addr = *next_iface_addr;
  olsr_ip_copy(olsr, &data.R_dest_iface_addr, dest_iface_addr);
  olsr_ip_copy(olsr, &data.R_next_iface_addr, next_iface_addr);
  data.R_prefix_length = prefix_length;
  data.R_dist = dist;
  //data.R_iface_addr = *iface_addr;
  olsr_ip_copy(olsr, &data.R_iface_addr, iface_addr);

  OLSR_InsertList(&olsr->routing_set_old[olsr_hashing(olsr,&data.R_dest_iface_addr)].list,
          &data, sizeof(OLSR_ROUTING_TUPLE));
}
void insert_association_set(struct olsrv2 *olsr,
                OLSR_LIST *iface_list,
                double validity_time){

  OLSR_LIST_ENTRY **entry = NULL, *iface_entry = NULL;
  OLSR_LOCAL_INTERFACE_BLOCK_ENTRY *local_iface_data = NULL;
  int i,j, seq, listNum;
  OLSR_ASSOCIATION_TUPLE *data = NULL;

  listNum = iface_list->numEntry;
  entry = (OLSR_LIST_ENTRY **)olsr_malloc(listNum * sizeof(OLSR_LIST_ENTRY *),
                      __FUNCTION__);
  for(i = 0; i < listNum; i++) {
    entry[i] = (OLSR_LIST_ENTRY *)olsr_malloc(sizeof(OLSR_LIST_ENTRY),
                          __FUNCTION__);
    entry[i]->data =
      (OLSR_ASSOCIATION_TUPLE *)olsr_malloc(sizeof(OLSR_ASSOCIATION_TUPLE),
                        __FUNCTION__);
    entry[i]->size = sizeof(OLSR_ASSOCIATION_TUPLE);
  }

  iface_entry = iface_list->head;
  i = 0;
  while(iface_entry) {

    local_iface_data = (OLSR_LOCAL_INTERFACE_BLOCK_ENTRY *)iface_entry->data;
    data = (OLSR_ASSOCIATION_TUPLE *)entry[i]->data;

    get_current_time(olsr, &data->NA_time);
    update_time(&data->NA_time, (olsr_32_t)validity_time);
    olsr_ip_copy(olsr, &data->NA_iface_addr, &local_iface_data->iface_addr);
    data->num_NAlist = listNum -1;
    data->NA_list =
      (OLSR_LIST_ENTRY **)olsr_malloc(sizeof(OLSR_LIST_ENTRY*) * (listNum-1),
                      __FUNCTION__);

    seq = 0;
    for(j = 0; j < listNum; j++) {
      if(i == j)
    continue;
      data->NA_list[seq++] = entry[j];
    }

    OLSR_InsertListEntry(&olsr->associ_set[olsr_hashing(olsr,&data->NA_iface_addr)].list,
             entry[i]);

    iface_entry = iface_entry->next;
    i++;
  }

  free(entry);

}
void delete_topology_set_for_same_entry(struct olsrv2 *olsr,
                                        const union olsr_ip_addr *orig_addr,
                                        olsr_u16_t ASSN)
{
    OLSR_TOPOLOGY_TUPLE todelete;

    olsr_ip_copy(olsr, &todelete.T_last_iface_addr, orig_addr);
    todelete.T_seq = ASSN;

    olsr->change_topology_set =
        OLSR_DeleteListHandler((void*)olsr,&olsr->topology_set[olsr_hashing(olsr,orig_addr)].list,
                               (void* )&todelete,
                               &delete_topology_set_for_same_entry_handler);
}
Esempio n. 13
0
void proc_routing_set(struct olsrv2 *olsr)
{
  OLSR_LIST_ENTRY *tmp_A = NULL, *tmp_B = NULL;

  OLSR_LINK_TUPLE *link_data = NULL, *link_data_2hop = NULL;
  OLSR_2NEIGH_TUPLE *two_nei_data = NULL;
  //OLSR_ASSOCI_TUPLE *associ_data;
  OLSR_ASSOCIATION_TUPLE *associ_data = NULL, *list_data = NULL;
  OLSR_TOPOLOGY_TUPLE *topology_data = NULL;
  OLSR_ROUTING_TUPLE *routing_data = NULL;
  olsr_u8_t default_prefix;
  olsr_u32_t index;
  int i;

  OLSR_LIST *retList = NULL, *link_retList = NULL;

  olsr_time_t time;
  int hash_index;

  int h;
  olsr_bool insert;;

  get_current_time(olsr, &time);
  // block signals until routing calcuration is finished
  if (olsr->olsr_cnf->ip_version == AF_INET)
  {
      default_prefix = 32;
  }else
  {
      default_prefix = 128;
  }


  //14
  //14.1

  for (hash_index = 0; hash_index < HASHSIZE; hash_index++)
  {
      delete_routing_set_for_all_entry(olsr, &olsr->routing_set[hash_index].list);
  }

  //14.2
  tmp_A = olsr->link_set.head;

  while (tmp_A)
  {
      link_data = (OLSR_LINK_TUPLE *)tmp_A->data;
      if (get_link_status(time,
             link_data->L_SYM_time,
             link_data->L_ASYM_time,
             link_data->L_LOST_LINK_time) == SYMMETRIC)
      {
      if (DEBUG_OLSRV2)
      {
          olsr_printf("------call insert_routing_set---------\n");
      }
      insert_routing_set(olsr,
                 &link_data->L_neighbor_iface_addr,
                 &link_data->L_neighbor_iface_addr,
                 default_prefix,
                 1,
                 &link_data->L_local_iface_addr);

      }

      tmp_A = tmp_A->next;
  }

  //14.3 (XXX)
  // for each neighbor address association tuple, for which two
  // addresses A1 and A2 exist in I_neighbor_iface_addr_list where:

  for (index=0; index < HASHSIZE; index++)
  {
      union olsr_ip_addr A_addr, B_addr;

      tmp_A = olsr->associ_set[index].list.head;
      while (tmp_A)
      {
      associ_data = (OLSR_ASSOCIATION_TUPLE *)tmp_A->data;
      olsr_ip_copy(olsr, &A_addr, &associ_data->NA_iface_addr);

      for (i = 0; i < associ_data->num_NAlist; i++)
      {
          tmp_B = associ_data->NA_list[i];
          list_data = (OLSR_ASSOCIATION_TUPLE *)tmp_B->data;
          olsr_ip_copy(olsr, &B_addr, &list_data->NA_iface_addr);

          if (!equal_ip_addr(olsr, &A_addr, &B_addr))
          {
          retList = search_routing_set_for_dest(olsr, &A_addr);

          if (retList != NULL)
          {
              routing_data = (OLSR_ROUTING_TUPLE *)retList->head->data;
              OLSR_DeleteList_Search(retList);

              insert_routing_set(olsr,
                     &B_addr,
                     &routing_data->R_next_iface_addr,
                     default_prefix,
                     routing_data->R_dist,
                     &routing_data->R_iface_addr);
              assert(routing_data->R_dist == 1);
          }
          }
      }
      tmp_A = tmp_A->next;
      }
  }

  for (hash_index = 0; hash_index < HASHSIZE; hash_index++)
  {
      tmp_A = olsr->routing_set[hash_index].list.head;

      while (tmp_A)
      {
      routing_data = (OLSR_ROUTING_TUPLE *)tmp_A->data;
      retList = search_2neigh_set_for_mpr_n(olsr,
                        &routing_data->R_iface_addr,
                        &routing_data->R_next_iface_addr);
      if (retList)
      {
          tmp_B = retList->head;
          while (tmp_B)
          {
          two_nei_data = (OLSR_2NEIGH_TUPLE *)tmp_B->data;
          link_retList = search_link_set(olsr,
                         &two_nei_data->N2_2hop_iface_addr);
          if (link_retList)
          {
              link_data_2hop = (OLSR_LINK_TUPLE *)link_retList->head->data;
              OLSR_DeleteList_Search(link_retList);
              if (get_link_status(
                 time,
                 link_data_2hop->L_SYM_time,
                 link_data_2hop->L_ASYM_time,
                 link_data_2hop->L_LOST_LINK_time) == SYMMETRIC)
              {
              tmp_B = tmp_B->next;
              continue;
              }
          }

          insert_routing_set(olsr,
                     &two_nei_data->N2_2hop_iface_addr,
                     &routing_data->R_next_iface_addr,
                     default_prefix,
                     2,
                     &routing_data->R_iface_addr);

          tmp_B = tmp_B->next;
          }
          OLSR_DeleteList_Search(retList);
      }
      tmp_A = tmp_A->next;
      }
  }

  //14.5
  //14.5.1

  h = 2;
  insert = OLSR_TRUE;

  while (insert == OLSR_TRUE)
  {
      insert = OLSR_FALSE;

      for (hash_index = 0; hash_index  < HASHSIZE; hash_index++)
      {
      tmp_A = olsr->routing_set[hash_index].list.head;

      while (tmp_A)
      {
          routing_data = (OLSR_ROUTING_TUPLE *)tmp_A->data;

          tmp_A = tmp_A->next;

          if (routing_data->R_dist != h)
          {
          continue;
          }

          retList = search_topology_set_for_last(olsr, &routing_data->R_dest_iface_addr);

          if (retList)
          {
          tmp_B = retList->head;
          while (tmp_B)
          {
              topology_data = (OLSR_TOPOLOGY_TUPLE *)tmp_B->data;

              if (search_routing_set_for_dest_exist(
                 olsr, &topology_data->T_dest_iface_addr) == OLSR_FALSE)
              {
              insert_routing_set(olsr,
                         &topology_data->T_dest_iface_addr,
                         &routing_data->R_next_iface_addr,
                         default_prefix,
                         routing_data->R_dist+1,
                         &routing_data->R_iface_addr);
              insert = OLSR_TRUE;
              }
              tmp_B = tmp_B->next;
          }
          OLSR_DeleteList_Search(retList);
          }
      }//while
      }//for

      h++;
  }
  //14.5.2

}
Esempio n. 14
0
void
create_address_entry(struct olsrv2 *olsr,
    struct address_list *addr_list, struct tlv_tuple_local *tlv_list,
    struct address_tuple** address_entry)
{
  struct address_tuple *new_tuple = NULL;
  struct tlv_tuple *new_tlv = NULL;
  struct address_list *tmp_addr = addr_list;
  struct tlv_tuple_local *tmp_tlv = NULL;
  int addr_index;


  while (tmp_addr)
    {
      new_tuple = (struct address_tuple*)olsr_malloc(sizeof(struct address_tuple),
                             __FUNCTION__);
      memset(new_tuple, 0, sizeof(struct address_tuple));
      olsr_ip_copy(olsr, &new_tuple->ip_addr, &tmp_addr->ip_addr);
      new_tuple->ip_version = olsr->olsr_cnf->ip_version;
      new_tuple->next = NULL;
      new_tuple->addr_tlv = NULL;

      tmp_tlv = tlv_list;
      addr_index = tmp_addr->index;
      while (tmp_tlv)
    {

      if(addr_index < tmp_tlv->index_start || tmp_tlv->index_stop < addr_index)
        {
          tmp_tlv = tmp_tlv->next;
          continue;
        }

      new_tlv = (struct tlv_tuple *)olsr_malloc(sizeof(struct tlv_tuple),
                            __FUNCTION__);
      memset(new_tlv, 0, sizeof(struct tlv_tuple));
      new_tlv->type = tmp_tlv->type;
      new_tlv->length = tmp_tlv->one_field_size;
      new_tlv->next = NULL;

      // set value(in case multi value bit unset)
      if(tmp_tlv->multi_value_bit == 0)
        {
          // in case ,value is less or equal than 32 bit
          if (tmp_tlv->one_field_size <= sizeof(olsr_u32_t))
        {
          new_tlv->value = tmp_tlv->value;
          new_tlv->extended_value = NULL;
        }
          // in case ,value is larger or than 32 bit
          else
        {
          new_tlv->value = 0;
          new_tlv->extended_value = (olsr_u8_t *)olsr_malloc(tmp_tlv->length,
                                __FUNCTION__);
          memcpy(new_tlv->extended_value, tmp_tlv->extended_value,
             sizeof(tmp_tlv->length));
        }
        }
      // in case, multi value bit set
      else
        {// less equal 32 bit // maybe ,too last speed
          if (tmp_tlv->one_field_size <= sizeof(olsr_u32_t))
        {
          new_tlv->value = tmp_tlv->multi_value[addr_index-tmp_tlv->index_start];
          new_tlv->extended_value = NULL;
        }
          // greater than 32 bit
          else
        {
          new_tlv->value = 0;
          new_tlv->extended_value = (olsr_u8_t *)olsr_malloc(tmp_tlv->length,
                               __FUNCTION__);
          memcpy(new_tlv->extended_value, tmp_tlv->extended_value, tmp_tlv->length);
          if(DEBUG_OLSRV2)
          {
              olsr_printf("Not supported!!\n");
          }
        }
        }

      //QUEUE new_tlv
      if (new_tuple->addr_tlv == NULL)
        new_tuple->addr_tlv = new_tlv;
      else
        {
          new_tlv->next = new_tuple->addr_tlv;
          new_tuple->addr_tlv = new_tlv;
        }

      tmp_tlv = tmp_tlv->next;
    }           //while tmp_tlv

      //QUEUE new_tuple
      if (*address_entry == NULL)
    *address_entry = new_tuple;
      else
    {
      new_tuple->next = *address_entry;
      *address_entry = new_tuple;
    }

      tmp_addr = tmp_addr->next;
    }//while tmp_addr

  free_address_list(addr_list);
  free_address_tlv(tlv_list);

  return;
}
static olsr_bool
tc_change_structure(struct olsrv2 *olsr, struct tc_message *tc_msg,
            struct message_header *m, union olsr_ip_addr *source)
{
  struct address_tuple *tmp_addr_entry = NULL;
  struct tlv_tuple *tlv_entry = NULL;

  struct tc_mpr_addr *mpr_entry = NULL;
  int i;
  ATTACHED_NETWORK *attached_net_entry = NULL;

  OLSR_LOCAL_INTERFACE_BLOCK_ENTRY local_iface_entry;

  // initialize
  memset(tc_msg, 0, sizeof(struct tc_message));

  // fill ipv4 header informations
  tlv_entry = get_msg_tlv(olsr, Validity_Time);
  if(tlv_entry->length == 1)
    tc_msg->vtime = me_to_double((olsr_u8_t)tlv_entry->value);
  else// greater than 3 byte
    tc_msg->vtime = get_validity_time_from_hop(tlv_entry, m->hop_count);

  olsr_ip_copy(olsr, &tc_msg->source_addr, source);
  olsr_ip_copy(olsr, &tc_msg->originator, &m->orig_addr);
  tc_msg->message_seq_number = m->message_seq_num;
  tc_msg->hop_count = m->hop_count;
  tc_msg->ttl = m->ttl;

  if ((tlv_entry = get_msg_tlv(olsr, Content_Sequence_Number)) == NULL){
    olsr_error("This Message include no ASSN\n");
  }else{//assume that assn is less equal than 4byte
    tc_msg->assn = (olsr_u16_t)tlv_entry->value;
  }
/*
//codexxx'
  tlv_entry = get_msg_tlv(olsr, queuelen);
   tc_msg->queuelength = (olsr_u8_t)tlv_entry->value;
  
  //end codexxx'  
*/
  if(proc_assn_history_set(olsr, &tc_msg->originator, tc_msg->assn)){
    free_all_address_entries(olsr);
    free_message_tlv(olsr);
    olsr_free_tc_packet(tc_msg);

    return OLSR_FALSE;
  }

  //local interface block
  OLSR_InitList(&tc_msg->local_iface_list);
  tmp_addr_entry = olsr->local_interface_block_entry;
  while(tmp_addr_entry) {
    olsr_ip_copy(olsr, &local_iface_entry.iface_addr, &tmp_addr_entry->ip_addr);
    local_iface_entry.other_if = OLSR_FALSE;

    tlv_entry = tmp_addr_entry->addr_tlv;
    while(tlv_entry) {
      switch(tlv_entry->type){
      case Other_If:
    if(tlv_entry->value == OLSR_TRUE)
      local_iface_entry.other_if = OLSR_TRUE;
    break;
      default:
    break;
      }
      tlv_entry = tlv_entry->next;
    }
    OLSR_InsertList(&tc_msg->local_iface_list, &local_iface_entry,
            sizeof(OLSR_LOCAL_INTERFACE_BLOCK_ENTRY));

    tmp_addr_entry= tmp_addr_entry->next;
  }

  // all mpr selector : advertized by tc
  tc_msg->mpr_selector_address = NULL;
  tc_msg->attached_net_addr = NULL;
  for (i = 0; i < olsr->num_of_addr_tlv_block_entries; ++i){
    tmp_addr_entry = olsr->addr_tlv_block_entries[i];
    tlv_entry = NULL;
    while (tmp_addr_entry){
      //attached network address
      if((tlv_entry = have_attached_network_tlv(tmp_addr_entry->addr_tlv)) != NULL)
    {
      attached_net_entry = (ATTACHED_NETWORK *)olsr_malloc( sizeof(ATTACHED_NETWORK), __FUNCTION__);
      memset(attached_net_entry, 0 , sizeof(ATTACHED_NETWORK));
      attached_net_entry->next = NULL;
      olsr_ip_copy(olsr, &attached_net_entry->network_addr, &tmp_addr_entry->ip_addr);
      attached_net_entry->prefix_length = (olsr_u8_t)tlv_entry->value;

      //queue
      if(tc_msg->attached_net_addr == NULL)
        tc_msg->attached_net_addr = attached_net_entry;
      else{
        attached_net_entry->next = tc_msg->attached_net_addr;
        tc_msg->attached_net_addr = attached_net_entry;
      }
      tmp_addr_entry = tmp_addr_entry->next;
      continue;
    }

      mpr_entry = (struct tc_mpr_addr *)olsr_malloc(sizeof(struct tc_mpr_addr), __FUNCTION__);
      memset(mpr_entry, 0, sizeof(struct tc_mpr_addr));

      olsr_ip_copy(olsr, &mpr_entry->address, &tmp_addr_entry->ip_addr);


      if (tc_msg->mpr_selector_address == NULL){//first
    tc_msg->mpr_selector_address = mpr_entry;
    mpr_entry->next = NULL;
      }else{
    mpr_entry->next = tc_msg->mpr_selector_address;
    tc_msg->mpr_selector_address = mpr_entry;
      }
      tmp_addr_entry = tmp_addr_entry->next;
    }

  }//for

  debug_code(print_tc_message(olsr, tc_msg));
  //free address tlv & message tlv
  free_all_address_entries(olsr);
  free_message_tlv(olsr);

  return OLSR_TRUE;
}
static olsr_bool
hello_change_structure(struct olsrv2 *olsr, struct hello_message *h_msg,
               struct message_header *m)
{
  struct address_tuple *tmp_addr_entry = NULL;
  struct tlv_tuple *tlv_entry = NULL;
  struct hello_neighbor *neigh = NULL;
  olsr_u8_t link_status_count;
  olsr_u8_t mpr_selection_count;
  olsr_u8_t other_neigh_count;

  //olsr_bool link_status_flag;
  //olsr_bool mpr_selection_flag;
  //olsr_bool other_neigh_flag;
  olsr_bool add_neigh;

  OLSR_LOCAL_INTERFACE_BLOCK_ENTRY local_iface_entry;

//MEMSET added for Linux
  memset(&local_iface_entry, 0, sizeof(OLSR_LOCAL_INTERFACE_BLOCK_ENTRY));

  int i;


  //initialize
  memset(h_msg, 0, sizeof(struct hello_message));
  //wiss: fill validity from message tlv
  tlv_entry = get_msg_tlv(olsr, Validity_Time);  // byetle3 3enna men el olsr el TLV_entry yalli 3endou tlv_type "Validity_Time"
  if(tlv_entry->length == 1)
    h_msg->vtime = me_to_double((olsr_u8_t)tlv_entry->value);
  else// greater than 3 byte
    h_msg->vtime = get_validity_time_from_hop(tlv_entry, m->hop_count);

  h_msg->htime = (double)h_msg->vtime/3; //wiss: ma fhemet chou hiye el htime

  //olsr_ip_copy(&h_msg->source_addr, &m->orig_addr);
  tmp_addr_entry = olsr->local_interface_block_entry;
  olsr_ip_copy(olsr, &h_msg->source_addr, &tmp_addr_entry->ip_addr);
  olsr_ip_copy(olsr, &h_msg->orig_addr, &m->orig_addr);
  //olsr_printf("Source = %s\n", IP_TO_STRING(&h_msg->source_addr));


  h_msg->hop_count = m->hop_count;
  h_msg->ttl = m->ttl;
  h_msg->message_seq_number = m->message_seq_num;

  // fill willingness from message tlv
  if((tlv_entry = get_msg_tlv(olsr, Willingness)) == NULL){
    // default //wiss: ya3ni hon ma la2a TLV willingness donc will_default
    h_msg->willingness = WILL_DEFAULT;
  }else{
    // assume that willingness is less equal than 4byte
    h_msg->willingness = (olsr_u8_t)tlv_entry->value;
  }

  //codexxx
  tlv_entry = get_msg_tlv(olsr, queuelen);
   h_msg->queuelength = (olsr_u8_t)tlv_entry->value;
  
  //end codexxx

  //local interface block
  OLSR_InitList(&h_msg->local_iface_list);
  tmp_addr_entry = olsr->local_interface_block_entry;
  while(tmp_addr_entry) {
    olsr_ip_copy(olsr, &local_iface_entry.iface_addr, &tmp_addr_entry->ip_addr);
    local_iface_entry.other_if = OLSR_FALSE;

    tlv_entry = tmp_addr_entry->addr_tlv;
    while(tlv_entry) {
      switch(tlv_entry->type){
      case Other_If:
    local_iface_entry.other_if = (olsr_u8_t)tlv_entry->value;
    break;
      default:
    break;
      }
      tlv_entry = tlv_entry->next;
    } // wiss: set local_iface_entry.other_if
    OLSR_InsertList(&h_msg->local_iface_list, &local_iface_entry,
            sizeof(OLSR_LOCAL_INTERFACE_BLOCK_ENTRY));

    tmp_addr_entry= tmp_addr_entry->next;
  }
// wiss : lahon biikoun tmalla el hello message "h_msg" bi kell el ma3loumet el lezme ella el champs "neighbors"
  //test
/*   olsr_ip_copy(&local_iface_entry.iface_addr, &olsr->local_interface_block_entry->ip_addr); */
/*   local_iface_entry.iface_addr.v4 += 1; */
/*   local_iface_entry.other_if = OLSR_FALSE; */
/*   OLSR_InsertList(&h_msg->local_iface_list, &local_iface_entry, */
/*        sizeof(OLSR_LOCAL_INTERFACE_BLOCK_ENTRY)); */

/*   olsr_ip_copy(&local_iface_entry.iface_addr, &olsr->local_interface_block_entry->ip_addr); */
/*   local_iface_entry.iface_addr.v4 += 2; */
/*   local_iface_entry.other_if = OLSR_FALSE; */
/*   OLSR_InsertList(&h_msg->local_iface_list, &local_iface_entry, */
/*        sizeof(OLSR_LOCAL_INTERFACE_BLOCK_ENTRY)); */

  // all neighbor :advertized by hello
  h_msg->neighbors = NULL;
  for (i = 0; i < olsr->num_of_addr_tlv_block_entries; ++i){
    tmp_addr_entry = olsr->addr_tlv_block_entries[i];
    while (tmp_addr_entry)
      {
    neigh = (struct hello_neighbor *)olsr_malloc(sizeof(struct hello_neighbor), __FUNCTION__);
    memset(neigh, 0, sizeof(struct hello_neighbor));

    add_neigh = OLSR_TRUE;


    tlv_entry = tmp_addr_entry->addr_tlv;
    link_status_count = mpr_selection_count = other_neigh_count = 0;
    //link_status_flag = mpr_selection_flag = other_neigh_flag = OLSR_FALSE;


    neigh->is_mpr = OLSR_FALSE;
    neigh->status = 255;
    neigh->other_neigh = 255;

    while (tlv_entry){
      switch (tlv_entry->type)
        {
        case Link_Status:
          link_status_count++;
          //link_status_flag = OLSR_TRUE;
          //assume that link status is less equal than 4byte
          neigh->status = (olsr_u8_t)tlv_entry->value;
          break;
        case MPR_Selection:
          mpr_selection_count++;
          //assume that mpr selection is less equal than 4byte
          neigh->is_mpr = OLSR_TRUE;
          break;
        case Other_Neigh:
          other_neigh_count ++;
          //other_neigh_flag = OLSR_TRUE;
          neigh->other_neigh = OLSR_TRUE;
          break;
        default:
          //default ignore
          break;
        }

      tlv_entry = tlv_entry->next;
    }

    // wiss:  la hon menkoun 3abayna el fields taba3 el neigh ella el IP address
    if (link_status_count > 1 || other_neigh_count > 1 || mpr_selection_count > 1)
    {
        if(DEBUG_OLSRV2)
        {
        char* paddr = olsr_niigata_ip_to_string(olsr, &neigh->address);
        olsr_printf("This Neighbor %s have over 2 same tlv type\n",paddr);
        free(paddr);
        }
      add_neigh = OLSR_FALSE; // wiss: bima ennu 3endou aktar men 2 same TLV men7ot add_neigh= false
    }

    if (olsr->olsr_cnf->ip_version == AF_INET){
      //check inconsistency
      if (neigh->is_mpr == OLSR_TRUE && neigh->status != SYMMETRIC)
        {
        if(DEBUG_OLSRV2)
        {
            olsr_printf("MPR have non symmetric link\n");
        }
        free(neigh);

        tmp_addr_entry = tmp_addr_entry->next;
        continue;
        /*
        free_all_address_entries(olsr);
        free_message_tlv(olsr);
        return OLSR_FALSE;
        */
        }

//    if (neigh->transmitting_iface == Other && neigh->status != SYMMETRIC)
//    {
//        if (DEBUG_OLSRV2){
//        olsr_printf("Other Interface have non symmetric link\n");
//        }
//        free_all_address_entries(olsr);
//        free_message_tlv(olsr);
//        free(neigh);
//        return OLSR_FALSE;
//    }

    }

    //add neighbor to hello_message
    if (add_neigh == OLSR_TRUE){ // wiss: bikoun true iza linkstatus count aw mpr count aw ...count <=1
      //copy neigh
      olsr_ip_copy(olsr, &neigh->address, &tmp_addr_entry->ip_addr);
      //queue
      if (h_msg->neighbors == NULL)
        {
          neigh->next = NULL;
          h_msg->neighbors = neigh;
        }
      else
        {
          neigh->next = h_msg->neighbors;
          h_msg->neighbors = neigh;
        }
    }else{// add_neigh == FALSE
      //skip this neighbor
        if(DEBUG_OLSRV2)
        {
        olsr_printf("Neighbor %s don't add neigh list\n");
        }
        free(neigh);
    }

    //next address advertized by hello
    tmp_addr_entry = tmp_addr_entry->next;
      }
  }//for


  if(DEBUG_OLSRV2)
  {
      print_hello_message(olsr, h_msg);
  }

  // free address tlv & message tlv
  free_all_address_entries(olsr);
  free_message_tlv(olsr);

  return OLSR_TRUE;
}