Exemple #1
0
/**
 * Check if a hello message states this node as a MPR.
 *
 * @param message the message to check
 * @param n_link the buffer to put the link status in
 *
 *@return 1 if we are selected as MPR 0 if not
 */
static bool
lookup_mpr_status(const struct hello_message *message, const struct interface *in_if)
{
  struct hello_neighbor *neighbors;

  for (neighbors = message->neighbors; neighbors; neighbors = neighbors->next) {
    if ( neighbors->link != UNSPEC_LINK
        && (olsr_cnf->ip_version == AF_INET
            ? ip4equal(&neighbors->address.v4, &in_if->ip_addr.v4)
            : ip6equal(&neighbors->address.v6, &in_if->int6_addr.sin6_addr))) {

      if (neighbors->link == SYM_LINK && neighbors->status == MPR_NEIGH) {
        return true;
      }
      break;
    }
  }
  /* Not found */
  return false;
}
Exemple #2
0
/**
 * write latlon positions to a file
 */
void mapwrite_work(FILE* fmap)
{
  int hash;
  struct olsr_if *ifs;
  union olsr_ip_addr ip;
  struct ipaddr_str strbuf1, strbuf2;
  struct tc_entry *tc;
  struct tc_edge_entry *tc_edge;

  if (!my_names || !fmap) return;

  for (ifs = olsr_cnf->interfaces; ifs; ifs = ifs->next)
  {
    if (0 != ifs->interf)
    {
      if (olsr_cnf->ip_version == AF_INET)
      {
        if (!(ip4equal((struct in_addr *)&olsr_cnf->main_addr, &ifs->interf->int_addr.sin_addr)))
        {
          if (0 > fprintf(fmap, "Mid('%s','%s');\n",
            olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr),
            olsr_ip_to_string(&strbuf2, (union olsr_ip_addr *)&ifs->interf->int_addr.sin_addr)))
          {
            return;
          }
        }
      }
      else if (!(ip6equal((struct in6_addr *)&olsr_cnf->main_addr, &ifs->interf->int6_addr.sin6_addr)))
      {
        if (0 > fprintf(fmap, "Mid('%s','%s');\n",
          olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr),
          olsr_ip_to_string(&strbuf2, (union olsr_ip_addr *)&ifs->interf->int6_addr.sin6_addr)))
        {
          return;
        }
      }
    }
  }

  for (hash = 0; hash < HASHSIZE; hash++) 
  {
    struct mid_entry *entry = mid_set[hash].next;
    while(entry != &mid_set[hash])
    {
      struct mid_address *alias = entry->aliases;
      while(alias)
      {
        if (0 > fprintf(fmap, "Mid('%s','%s');\n",
          olsr_ip_to_string(&strbuf1, &entry->main_addr),
          olsr_ip_to_string(&strbuf2, &alias->alias)))
        {
          return;
        }
        alias = alias->next_alias;
      }
      entry = entry->next;
    }
  }
  lookup_defhna_latlon(&ip);
  sprintf(my_latlon_str, "%f,%f,%d", my_lat, my_lon, get_isdefhna_latlon());
  if (0 > fprintf(fmap, "Self('%s',%s,'%s','%s');\n",
    olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr), my_latlon_str, 
    olsr_ip_to_string(&strbuf2, &ip), my_names->name))
  {
    return;
  }
  for (hash = 0; hash < HASHSIZE; hash++) 
  {
    struct db_entry *entry;
	struct list_node *list_head, *list_node;

    list_head = &latlon_list[hash];
    for (list_node = list_head->next; list_node != list_head;
         list_node = list_node->next) {
        
      entry = list2db(list_node);

      if (NULL != entry->names)
      {
        if (0 > fprintf(fmap, "Node('%s',%s,'%s','%s');\n",
          olsr_ip_to_string(&strbuf1, &entry->originator),
          entry->names->name, olsr_ip_to_string(&strbuf2, &entry->names->ip),
          lookup_name_latlon(&entry->originator)))
        {
          return;
        }
      }
    }
  }

  OLSR_FOR_ALL_TC_ENTRIES(tc) {
  OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
    char* lla = lookup_position_latlon(&tc->addr);
    char* llb = lookup_position_latlon(&tc_edge->T_dest_addr);
    if (NULL != lla && NULL != llb)
    {
      struct lqtextbuffer lqbuffer, lqbuffer2;
      
      /*
       * To speed up processing, Links with both positions are named PLink()
       */
      if (0 > fprintf(fmap, "PLink('%s','%s',%s,%s,%s,%s);\n", 
            olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr),
            olsr_ip_to_string(&strbuf2, &tc->addr), 
            get_tc_edge_entry_text(tc_edge, ',', &lqbuffer2),
            get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer),
            lla, llb))
      {
        return;
      }
    }
    else
    {
      struct lqtextbuffer lqbuffer, lqbuffer2;
      
      /*
       * If one link end pos is unkown, only send Link()
       */
      if (0 > fprintf(fmap, "Link('%s','%s',%s,%s);\n", 
            olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr),
            olsr_ip_to_string(&strbuf2, &tc->addr), 
            get_tc_edge_entry_text(tc_edge, ',', &lqbuffer2),
            get_linkcost_text(tc_edge->cost, OLSR_FALSE, &lqbuffer)))
      {
        return;
      }
    }
  } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
  } OLSR_FOR_ALL_TC_ENTRIES_END(tc);