/**
 *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;
}
Beispiel #2
0
/**
 *Add a gatewayentry to the HNA set
 *
 *@param addr the address of the gateway
 *
 *@return the created entry
 */
struct hna_entry *
olsr_add_hna_entry(const union olsr_ip_addr *addr)
{
    struct hna_entry *new_entry;
    uint32_t hash;

    new_entry = olsr_cookie_malloc(hna_entry_mem_cookie);

    /* Fill struct */
    new_entry->A_gateway_addr = *addr;

    /* Link nets */
    new_entry->networks.next = &new_entry->networks;
    new_entry->networks.prev = &new_entry->networks;

    /* queue */
    hash = olsr_ip_hashing(addr);

    hna_set[hash].next->prev = new_entry;
    new_entry->next = hna_set[hash].next;
    hna_set[hash].next = new_entry;
    new_entry->prev = &hna_set[hash];

    return new_entry;
}
int
delete_plc_peer_neighbor(const union olsr_ip_addr *peer_addr)
{
  uint32_t hash;
  struct plc_peer_entry *entry;

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

  hash = olsr_ip_hashing(peer_addr);

  entry = plc_peer_neighbors[hash].next;

  /*
   * Find neighbor entry
   */
  while (entry != &plc_peer_neighbors[hash]) {
    if (ipequal(&entry->plc_peer_main_addr, peer_addr))
      break;

    entry = entry->next;
  }

  if (entry == &plc_peer_neighbors[hash])
    return 0;

   /* Dequeue */
  DEQUEUE_ELEM(entry);

  free(entry);
  table_size--;
  return 1;
}
Beispiel #4
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);

}
int
olsr_delete_neighbor_table(const union olsr_ip_addr *neighbor_addr)
{  
  struct  neighbor_2_list_entry *two_hop_list, *two_hop_to_delete;
  olsr_u32_t                    hash;
  struct neighbor_entry         *entry;

  //printf("inserting neighbor\n");

  hash = olsr_ip_hashing(neighbor_addr);

  entry = neighbortable[hash].next;

  /*
   * Find neighbor entry
   */
  while(entry != &neighbortable[hash])
    {
      if(ipequal(&entry->neighbor_main_addr, neighbor_addr))
	break;
      
      entry = entry->next;
    }

  if(entry == &neighbortable[hash])
    return 0;


  two_hop_list = entry->neighbor_2_list.next;

  while (two_hop_list != &entry->neighbor_2_list) {
      two_hop_to_delete = two_hop_list;
      two_hop_list = two_hop_list->next;

      two_hop_to_delete->neighbor_2->neighbor_2_pointer--;
      olsr_delete_neighbor_pointer(two_hop_to_delete->neighbor_2,
                                   &entry->neighbor_main_addr);

      olsr_del_nbr2_list(two_hop_to_delete);
    }


  /* Dequeue */
  DEQUEUE_ELEM(entry);

  free(entry);

  changes_neighborhood = OLSR_TRUE;
  return 1;

}
// ------------------------------------------------------------
struct qaul_user_LL_item* Qaullib_User_LL_Add (union olsr_ip_addr *ip, unsigned char *id)
{
	struct qaul_user_LL_item *new_item;
	new_item = (struct qaul_user_LL_item *)malloc(sizeof(struct qaul_user_LL_item));

	if(QAUL_DEBUG)
		printf("Qaullib_User_LL_Add\n");

	// get index
	uint32_t hash = olsr_ip_hashing(ip);

	// fill in content
	qaul_user_LL_id++;
	new_item->time = time(NULL);
	new_item->type = QAUL_USERTYPE_UNCHECKED;
	new_item->changed = QAUL_USERCHANGED_UNCHANGED;
	new_item->lq = 10.1;
	new_item->favorite = 0;
	memcpy((char *)&new_item->ip, ip, sizeof(union olsr_ip_addr));

	// set hash
	if(id != 0)
	{
		memcpy(new_item->id, id, sizeof(new_item->id));
		Qaullib_HashToString(id, new_item->idstr);
	}
	else
	{
		memset(new_item->id, 0, sizeof(new_item->id));
		memset(new_item->idstr, 0, sizeof(new_item->id));
	}

	// lock
	pthread_mutex_lock( &qaullib_mutex_userLL );
	// create links
	new_item->prev = &Qaul_user_LL_table[hash];
	new_item->next = Qaul_user_LL_table[hash].next;

	Qaul_user_LL_table[hash].next = new_item;
	new_item->next->prev = new_item;
	qaul_user_LL_count++;

	// unlock
	pthread_mutex_unlock( &qaullib_mutex_userLL );

	return new_item;
}
Beispiel #7
0
/**
 * Lookup a gateway entry
 *
 * @param gw the address of the gateway
 * @return the located entry or NULL if not found
 */
struct hna_entry *
olsr_lookup_hna_gw(const union olsr_ip_addr *gw)
{
    struct hna_entry *tmp_hna;
    uint32_t hash = olsr_ip_hashing(gw);

    /* Check for registered entry */

    for (tmp_hna = hna_set[hash].next; tmp_hna != &hna_set[hash]; tmp_hna = tmp_hna->next) {
        if (ipequal(&tmp_hna->A_gateway_addr, gw)) {
            return tmp_hna;
        }
    }

    /* Not found */
    return NULL;
}
/**
 *Lookup a peer entry in the plc_peer_neighbors based on an address.
 *
 *@param dst the IP address of the peer to look up
 *
 *@return a pointer to the neighbor struct registered on the given
 *address. NULL if not found.
 */
struct plc_peer_entry *
lookup_plc_peer_by_ip(const union olsr_ip_addr *dst)
{
  struct plc_peer_entry *entry;
  uint32_t hash = olsr_ip_hashing(dst);

  //olsr_printf(3, "\nLookup %s\n", olsr_ip_to_string(&buf, dst));
  for (entry = plc_peer_neighbors[hash].next; entry != &plc_peer_neighbors[hash]; entry = entry->next) {
    //olsr_printf(3, "Checking %s\n", olsr_ip_to_string(&buf, &entry->plc_peer_main_addr));
    if (ipequal(&entry->plc_peer_main_addr, dst))
      return entry;

  }
  //olsr_printf(3, "NOPE\n\n");

  return NULL;

}
Beispiel #9
0
/**
 *Lookup a neighbor entry in the neighbortable based on an address.
 *
 *@param dst the IP address of the neighbor to look up
 *
 *@return a pointer to the neighbor struct registered on the given
 *address. NULL if not found.
 */
struct neighbor_entry *
olsr_lookup_neighbor_table_alias(const union olsr_ip_addr *dst)
{
  struct neighbor_entry *entry;
  uint32_t hash = olsr_ip_hashing(dst);

  //printf("\nLookup %s\n", olsr_ip_to_string(&buf, dst));
  for (entry = neighbortable[hash].next; entry != &neighbortable[hash]; entry = entry->next) {
    //printf("Checking %s\n", olsr_ip_to_string(&buf, &entry->neighbor_main_addr));
    if (ipequal(&entry->neighbor_main_addr, dst))
      return entry;

  }
  //printf("NOPE\n\n");

  return NULL;

}
Beispiel #10
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;
}
void Qaullib_User_LL_InitNodeWithIP(struct qaul_user_LL_node *node, union olsr_ip_addr *ip)
{
	node->index = olsr_ip_hashing(ip);
	node->item = &Qaul_user_LL_table[node->index];
}