/**
 *Insert a plc peer entry in the table
 *
 *@param main_addr the main address of the new node
 *
 *@return 0 if plc peer already exists 1 if inserted
 */
struct plc_peer_entry *
insert_plc_peer_neighbor(const union olsr_ip_addr *main_addr, unsigned char *mac)
{
  uint32_t hash;
  struct plc_peer_entry *new_peer;

  hash = olsr_ip_hashing(main_addr);

  /* Check if entry exists */

  for (new_peer = plc_peer_neighbors[hash].next; new_peer != &plc_peer_neighbors[hash]; new_peer = new_peer->next) {
    if (ipequal(&new_peer->plc_peer_main_addr, main_addr))
      return 0;
  }

  //olsr_printf(3, "inserting peer\n");

  new_peer = olsr_malloc(sizeof(struct plc_peer_entry), "New peer entry");

  /* Set address, willingness and status */
  new_peer->plc_peer_main_addr = *main_addr;
  memcpy(new_peer->plc_data.mac, mac, 6);

  /* Queue */
  QUEUE_ELEM(plc_peer_neighbors[hash], new_peer);
  table_size++;
  return 1;
}
Esempio n. 2
0
void
olsr_update_neighbor_main_addr(struct neighbor_entry *entry, const union olsr_ip_addr *new_main_addr)
{
  /*remove from old pos*/
  DEQUEUE_ELEM(entry);

  /*update main addr*/
  entry->neighbor_main_addr = *new_main_addr;

  /*insert it again*/
  QUEUE_ELEM(neighbortable[olsr_ip_hashing(new_main_addr)], entry);

}
Esempio n. 3
0
/**
 *Add a MPR selector to the MPR selector set
 *
 *@param add address of the MPR selector
 *@param vtime validity time for the new entry
 *
 *@return a pointer to the new entry
 */
struct mpr_selector *
olsr_add_mpr_selector(const union olsr_ip_addr *addr, olsr_reltime vtime)
{
  struct ipaddr_str buf;
  struct mpr_selector *new_entry;

  OLSR_PRINTF(1, "MPRS: adding %s\n", olsr_ip_to_string(&buf, addr));

  new_entry = olsr_malloc(sizeof(struct mpr_selector), "Add MPR selector");
  /* Fill struct */
  new_entry->MS_main_addr = *addr;
  olsr_set_mpr_sel_timer(new_entry, vtime);
  /* Queue */
  QUEUE_ELEM(mprs_list, new_entry);
  /*
     new_entry->prev = &mprs_list;
     new_entry->next = mprs_list.next;
     mprs_list.next->prev = new_entry;
     mprs_list.next = new_entry;
   */
  return new_entry;
}
Esempio n. 4
0
/**
 *Insert a neighbor entry in the neighbor table
 *
 *@param main_addr the main address of the new node
 *
 *@return 0 if neighbor already exists 1 if inserted
 */
struct neighbor_entry *
olsr_insert_neighbor_table(const union olsr_ip_addr *main_addr)
{
  olsr_u32_t             hash;
  struct neighbor_entry  *new_neigh;
  
  hash = olsr_ip_hashing(main_addr);

  /* Check if entry exists */
  
  for(new_neigh = neighbortable[hash].next;
      new_neigh != &neighbortable[hash];
      new_neigh = new_neigh->next)
    {
      if(ipequal(&new_neigh->neighbor_main_addr, main_addr))
	return new_neigh;
    }
  
  //printf("inserting neighbor\n");
  
  new_neigh = olsr_malloc(sizeof(struct neighbor_entry), "New neighbor entry");
  
  /* Set address, willingness and status */
  new_neigh->neighbor_main_addr = *main_addr;
  new_neigh->willingness = WILL_NEVER;
  new_neigh->status = NOT_SYM;

  new_neigh->neighbor_2_list.next = &new_neigh->neighbor_2_list;
  new_neigh->neighbor_2_list.prev = &new_neigh->neighbor_2_list;
  
  new_neigh->linkcount = 0;
  new_neigh->is_mpr = OLSR_FALSE;
  new_neigh->was_mpr = OLSR_FALSE;

  /* Queue */
  QUEUE_ELEM(neighbortable[hash], new_neigh);

  return new_neigh;
}