Exemplo n.º 1
0
switch_status_t
switch_smac_rewrite_add_entry(switch_mac_addr_t *mac)
{
    switch_smac_entry_t               *smac_entry = NULL;
    switch_status_t                    status = SWITCH_STATUS_SUCCESS;
    uint16_t                           smac_index = 0;
    switch_device_t                    device = SWITCH_DEV_ID;

    smac_entry = switch_smac_rewrite_search_entry(mac);
    if (smac_entry) {
        smac_entry->ref_count++;
        return SWITCH_STATUS_SUCCESS;
    }
    smac_entry = switch_malloc(sizeof(switch_smac_entry_t), 1);
    if (!smac_entry) {
        return SWITCH_STATUS_NO_MEMORY;
    }
    memset(smac_entry, 0, sizeof(switch_smac_entry_t));
    smac_index = switch_api_id_allocator_allocate(smac_rewrite_index_allocator);
    memcpy(&smac_entry->mac, mac, ETH_LEN);
    smac_entry->smac_index = smac_index;
    smac_entry->ref_count = 1;
    switch_smac_rewrite_hash_insert(smac_entry);
    status = switch_pd_smac_rewrite_table_add_entry(device, smac_entry);
    return status;
}
Exemplo n.º 2
0
static uint16_t switch_dmac_rewrite_insert_hash(switch_device_t device,
                                                switch_mac_addr_t *mac) {
  unsigned char key[SWITCH_DMAC_REWRITE_HASH_KEY_SIZE];
  unsigned int len = 0;
  uint32_t hash = 0;
  uint16_t mac_index = 0;
  switch_status_t status = SWITCH_STATUS_SUCCESS;
  switch_dmac_rewrite_t *dmac_rewrite = NULL;

  dmac_rewrite = switch_dmac_rewrite_search_hash(mac);
  if (dmac_rewrite) {
    mac_index = dmac_rewrite->index;
    dmac_rewrite->ref_count++;
  } else {
    switch_dmac_rewrite_hash_key_init(key, mac, &len, &hash);
    dmac_rewrite = switch_malloc(sizeof(switch_dmac_rewrite_t), 1);
    if (!dmac_rewrite) {
      return mac_index;
    }
    mac_index = switch_api_id_allocator_allocate(dmac_rewrite_index_allocator);
    memcpy(&dmac_rewrite->mac, mac, sizeof(switch_mac_addr_t));
    dmac_rewrite->index = mac_index;
    dmac_rewrite->ref_count = 1;
    status = switch_pd_tunnel_dmac_rewrite_table_add_entry(
        device, mac_index, mac, &dmac_rewrite->rewrite_entry);
    if (status != SWITCH_STATUS_SUCCESS) {
      SWITCH_API_ERROR(
          "%s:%d: unable to add tunnel dmac entry!", __FUNCTION__, __LINE__);
      return mac_index;
    }
    tommy_hashtable_insert(
        &switch_dmac_rewrite_table, &(dmac_rewrite->node), dmac_rewrite, hash);
  }
  return mac_index;
}