Exemple #1
0
static switch_status_t switch_l3_remove_from_lpm_trie(
    switch_handle_t vrf, switch_ip_addr_t *ip_addr) {
  switch_lpm_trie_t *lpm_trie = NULL;
  void *temp = NULL;
  char *prefix;
  uint32_t v4addr;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  if (ip_addr->type == SWITCH_API_IP_ADDR_V4) {
    JLG(temp, switch_vrf_v4_lpm_tries, vrf);
    v4addr = htonl(ip_addr->ip.v4addr);
    prefix = (char *)(&v4addr);
  } else {
    JLG(temp, switch_vrf_v6_lpm_tries, vrf);
    prefix = (char *)(ip_addr->ip.v6addr);
  }

  if (!temp) {
    SWITCH_API_ERROR(
        "%s:%d: No LPM trie for this vrf %u!", __FUNCTION__, __LINE__, vrf);
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }

  lpm_trie = (switch_lpm_trie_t *)(*(unsigned long *)temp);
  switch_lpm_trie_delete(lpm_trie, prefix, ip_addr->prefix_len);
  if (switch_lpm_trie_size(lpm_trie) == 0) {
    if (ip_addr->type == SWITCH_API_IP_ADDR_V4) {
      JLD(status, switch_vrf_v4_lpm_tries, vrf);
    } else {
      JLD(status, switch_vrf_v6_lpm_tries, vrf);
    }
  }

  return status;
}
Exemple #2
0
static switch_status_t switch_l3_remove_from_vrf_list(
    switch_l3_hash_t *hash_entry) {
  switch_vrf_route_list_t *vrf_route_list = NULL;
  void *temp = NULL;
  switch_ip_addr_t ip_addr;
  switch_handle_t vrf_handle = 0;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  memset(&ip_addr, 0, sizeof(switch_ip_addr_t));
  switch_l3_hash_key_decode(hash_entry, &vrf_handle, &ip_addr);
  if (ip_addr.type == SWITCH_API_IP_ADDR_V4) {
    JLG(temp, switch_vrf_v4_routes, vrf_handle);
  } else {
    JLG(temp, switch_vrf_v6_routes, vrf_handle);
  }

  if (!temp) {
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }

  vrf_route_list = (switch_vrf_route_list_t *)(*(unsigned long *)temp);
  tommy_list_remove_existing(&(vrf_route_list->routes),
                             &(hash_entry->vrf_route_node));
  vrf_route_list->num_entries--;
  if (vrf_route_list->num_entries == 0) {
    if (ip_addr.type == SWITCH_API_IP_ADDR_V4) {
      JLD(status, switch_vrf_v4_routes, vrf_handle);
    } else {
      JLD(status, switch_vrf_v6_routes, vrf_handle);
    }
  }
  return status;
}
Exemple #3
0
static switch_l3_hash_t *switch_l3_lookup_lpm_trie(switch_handle_t vrf,
                                                   switch_ip_addr_t *ip_addr) {
  switch_lpm_trie_t *lpm_trie = NULL;
  void *temp = NULL;
  switch_l3_hash_t *hash_entry;
  char *prefix;
  uint32_t v4addr;

  if (ip_addr->type == SWITCH_API_IP_ADDR_V4) {
    JLG(temp, switch_vrf_v4_lpm_tries, vrf);
    v4addr = htonl(ip_addr->ip.v4addr);
    prefix = (char *)(&v4addr);
  } else {
    JLG(temp, switch_vrf_v6_lpm_tries, vrf);
    prefix = (char *)(ip_addr->ip.v6addr);
  }

  if (!temp) {
    SWITCH_API_ERROR(
        "%s:%d: No LPM trie for this vrf %u!", __FUNCTION__, __LINE__, vrf);
    return NULL;
  }

  lpm_trie = (switch_lpm_trie_t *)(*(unsigned long *)temp);
  if (switch_lpm_trie_lookup(lpm_trie, prefix, (unsigned long *)(&hash_entry)))
    return hash_entry;

  SWITCH_API_ERROR("%s: hash_entry not found.\n", __FUNCTION__);
  return NULL;
}
Exemple #4
0
int dogma_get_location_env(dogma_context_t* ctx, dogma_location_t location, dogma_env_t** env) {
	dogma_env_t** env1;
	dogma_env_t** env2;
	dogma_drone_context_t** drone_env1;
	dogma_key_t index = 0;

	switch(location.type) {

	case DOGMA_LOC_Char:
		*env = ctx->character;
		return DOGMA_OK;

	case DOGMA_LOC_Implant:
		JLG(env1, ctx->character->children, location.implant_index);
		if(env1 == NULL) return DOGMA_NOT_FOUND;
		*env = *env1;
		return DOGMA_OK;

	case DOGMA_LOC_Skill:
		JLG(env1, ctx->character->children, location.skill_typeid);
		if(env1 == NULL) return DOGMA_NOT_FOUND;
		*env = *env1;
		return DOGMA_OK;

	case DOGMA_LOC_Ship:
		*env = ctx->ship;
		return DOGMA_OK;

	case DOGMA_LOC_Module:
		JLG(env1, ctx->ship->children, location.module_index);
		if(env1 == NULL) return DOGMA_NOT_FOUND;
		*env = *env1;
		return DOGMA_OK;

	case DOGMA_LOC_Charge:
		JLG(env1, ctx->ship->children, location.module_index);
		if(env1 == NULL) return DOGMA_NOT_FOUND;
		JLF(env2, (*env1)->children, index);
		if(env2 == NULL) return DOGMA_NOT_FOUND;
		*env = *env2;
		return DOGMA_OK;

	case DOGMA_LOC_Drone:
		JLG(drone_env1, ctx->drone_map, location.drone_typeid);
		if(drone_env1 == NULL) return DOGMA_NOT_FOUND;
		*env = (*drone_env1)->drone;
		assert(*env != NULL);
		return DOGMA_OK;

	default:
		return DOGMA_NOT_FOUND;

	}
}
Exemple #5
0
int network_manager_unregister_peer_for_polling(struct network_manager* nm, struct network_peer* peer)
{
    uintptr_t p = (uintptr_t)peer; 
    int* psock = NULL;
    int sock;

    JLG(psock, nm->poll_socket_by_peer, p);
    if(psock == NULL) return -1; // doesn't exist
    sock = *psock;

    int rc;
    JLD(rc, nm->poll_socket_by_peer, p);

    FD_CLR(sock, &nm->poll_read_fds);
    FD_CLR(sock, &nm->poll_write_fds);
    FD_CLR(sock, &nm->poll_exception_fds);

    if(sock == nm->poll_max_fd) {
        size_t num_fds = vector_count(&nm->poll_fds);

        // Need to figure out what the previous max fd was, which means..
        qsort(vector_data(&nm->poll_fds), (size_t)num_fds, sizeof(uintptr_t), compint);
        int old_fd = (int)vector_pop(&nm->poll_fds);
        assert(old_fd == sock);

        nm->poll_max_fd = 0;
        if(num_fds > 1) {
            nm->poll_max_fd = vector_get(&nm->poll_fds, num_fds - 2);
        }
    }

    return 0;
}
Exemple #6
0
switch_status_t switch_api_l3_v6_routes_print_by_vrf(
    switch_handle_t vrf_handle) {
  switch_l3_hash_t *hash_entry = NULL;
  tommy_node *node = NULL;
  switch_vrf_route_list_t *vrf_route_list = NULL;
  void *temp = NULL;
  switch_ip_addr_t ip_addr;
  char v6_addr[INET6_ADDRSTRLEN];

  JLG(temp, switch_vrf_v6_routes, vrf_handle);
  if (!temp) {
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }
  vrf_route_list = (switch_vrf_route_list_t *)(*(unsigned long *)temp);
  node = tommy_list_head(&(vrf_route_list->routes));
  while (node) {
    hash_entry = node->data;
    switch_l3_hash_key_decode(hash_entry, &vrf_handle, &ip_addr);
    inet_ntop(AF_INET6, ip_addr.ip.v6addr, v6_addr, INET6_ADDRSTRLEN);
    printf("\nvrf_handle %x ip %s -> nhop %x",
           (unsigned int)vrf_handle,
           v6_addr,
           (unsigned int)hash_entry->nhop_handle);
    node = node->next;
  }
  return SWITCH_STATUS_SUCCESS;
}
Exemple #7
0
char *
gc_lookup(void *ptr)
{
        PWord_t pval;
        JLG(pval,mem_annotate,(Word_t)ptr & ~(Word_t)3);
        return pval ? (char *)*pval : "(none)";
}
Exemple #8
0
int dogma_set_module_state(dogma_context_t* ctx, dogma_key_t index, dogma_state_t new_state) {
	dogma_env_t** module_env;

	JLG(module_env, ctx->ship->children, index);
	if(module_env == NULL) return DOGMA_NOT_FOUND;

	return dogma_set_env_state(ctx, *module_env, new_state);
}
int dogma_set_env_state(dogma_context_t* ctx, dogma_env_t* env, dogma_state_t newstate) {
	dogma_array_t enveffects;
	dogma_key_t index = 0;
	const dogma_type_effect_t** te;
	const dogma_effect_t* e;
	dogma_expctx_t result;

	if(env->state == newstate) return DOGMA_OK;

	DOGMA_ASSUME_OK(dogma_get_type_effects(env->id, &enveffects));
	JLF(te, enveffects, index);
	while(te != NULL) {
		DOGMA_ASSUME_OK(dogma_get_effect((*te)->effectid, &e));
		JLN(te, enveffects, index);

		if(e->fittingusagechanceattributeid > 0) {
			/* Effect is chance-based */

			if(newstate > 0) {
				continue;
			}

			/* When unplugging the environment, turn off all
			 * chance-based effects as a precautionary measure */
			bool* v;
			int ret;
			JLG(v, env->chance_effects, e->id);
			if(v != NULL) {
				assert(*v == true);
				JLD(ret, env->chance_effects, e->id);
				DOGMA_ASSUME_OK(dogma_eval_expression(
					ctx, env,
					e->postexpressionid,
					&result
				));
			}

			continue;
		}

		if((newstate >> e->category) & 1) {
			if(!((env->state >> e->category) & 1)) {
				DOGMA_ASSUME_OK(dogma_eval_expression(
					ctx, env,
					e->preexpressionid,
					&result
				));
			}
		} else if((env->state >> e->category) & 1) {
			DOGMA_ASSUME_OK(dogma_eval_expression(
				ctx, env,
				e->postexpressionid,
				&result
			));
		}
	}
void*
ofpat_action_get (Pvoid_t *aargs, enum ofp_action_type t) {
    if (!(J1T (rc, *aargs, t))) {
        P4_LOG ("No arg for ofp_action_type");
        return NULL;
    } else {
        JLG (pv, *aargs, t);
        return (void *) *pv;
    }
}
Exemple #11
0
static switch_status_t switch_l3_insert_into_lpm_trie(
    switch_handle_t vrf,
    switch_ip_addr_t *ip_addr,
    switch_l3_hash_t *hash_entry) {
  switch_lpm_trie_t *lpm_trie = NULL;
  void *temp = NULL;
  size_t key_width_bytes;
  char *prefix;
  uint32_t v4addr;

  if (ip_addr->type == SWITCH_API_IP_ADDR_V4) {
    JLG(temp, switch_vrf_v4_lpm_tries, vrf);
    key_width_bytes = 4;
    v4addr = htonl(ip_addr->ip.v4addr);
    prefix = (char *)(&v4addr);
  } else {
    JLG(temp, switch_vrf_v6_lpm_tries, vrf);
    key_width_bytes = 16;
    prefix = (char *)(ip_addr->ip.v6addr);
  }

  if (!temp) {
    lpm_trie = switch_lpm_trie_create(key_width_bytes, TRUE);
    if (!lpm_trie) {
      SWITCH_API_ERROR("%s:%d: No memory!", __FUNCTION__, __LINE__);
      return SWITCH_STATUS_NO_MEMORY;
    }

    if (ip_addr->type == SWITCH_API_IP_ADDR_V4) {
      JLI(temp, switch_vrf_v4_lpm_tries, vrf);
    } else {
      JLI(temp, switch_vrf_v6_lpm_tries, vrf);
    }
    *(unsigned long *)temp = (unsigned long)(lpm_trie);
  }

  lpm_trie = (switch_lpm_trie_t *)(*(unsigned long *)temp);
  switch_lpm_trie_insert(
      lpm_trie, prefix, ip_addr->prefix_len, (unsigned long)hash_entry);

  return SWITCH_STATUS_SUCCESS;
}
Exemple #12
0
static inline pq_value *_pq_overload_for_types_variadic(pq_context *ctx, pq_overload *overload, size_t n, pq_type **types) {
	Word_t *pvalue;
	pq_type *argument_types_tuple;
	Pvoid_t by_argnum_table = overload->variadic_function_table, by_type_table;
	JLL(pvalue, by_argnum_table, n);
	while(pvalue != NULL) {
		by_type_table = (Pvoid_t)*pvalue;
		argument_types_tuple = pq_get_tuple_type(ctx, n, types);
		JLG(pvalue, by_type_table, (Word_t)argument_types_tuple);
		if(pvalue != NULL) {
			return (pq_value *)*pvalue;
		}
		JLG(pvalue, by_type_table, (Word_t)NULL);
		if(pvalue != NULL) {
			return (pq_value *)*pvalue;
		}
		JLP(pvalue, by_argnum_table, n);
	}
	return NULL;
}
Exemple #13
0
static void update_peers(struct network_manager* nm)
{
    // Perform the select first
    fd_set read_fds      = nm->poll_read_fds,
           write_fds     = nm->poll_write_fds,
           exception_fds = nm->poll_exception_fds;

    struct timeval timeout;
    timeout.tv_sec = 0;
    timeout.tv_usec = 0;

    if(select(nm->poll_max_fd + 1, &read_fds, &write_fds, &exception_fds, &timeout) < 0) {
        // weird error?
        perror("select");
        return;
    }

    // Then loop over all peers passing in the select status
    struct network_peer** ppeer = NULL;
    Word_t index = 0;

    struct vector disconnected_peers;
    vector_init(&disconnected_peers);

    JLF(ppeer, nm->peer_list, index);
    while(ppeer != NULL) {
        int action_flags = 0;

        int* psock = NULL;
        uintptr_t p = (uintptr_t)*ppeer;
        JLG(psock, nm->poll_socket_by_peer, p);
        if(psock != NULL) {
            if(FD_ISSET(*psock, &read_fds)) action_flags |= NETWORK_PEER_ACTION_FLAGS_READ;
            if(FD_ISSET(*psock, &write_fds)) action_flags |= NETWORK_PEER_ACTION_FLAGS_WRITE;
            if(FD_ISSET(*psock, &exception_fds)) action_flags |= NETWORK_PEER_ACTION_FLAGS_EXCEPTION;
        }

        network_peer_update(*ppeer, action_flags);

        if(network_peer_disconnected(*ppeer) == 1) {
            vector_add(&disconnected_peers, (uintptr_t)*ppeer);
        }

        JLN(ppeer, nm->peer_list, index);
    }

    size_t num_disconnected = vector_count(&disconnected_peers);
    for(size_t i = 0; i < num_disconnected; i++) {
        struct network_peer* peer = (struct network_peer*)vector_get(&disconnected_peers, i);
        stop_peer(nm, peer);
    }

    vector_free(&disconnected_peers);
}
Exemple #14
0
static bool switch_int_entry_hdl_get(switch_device_t device,
                                     p4_pd_entry_hdl_t *hdl) {
  void *temp = NULL;
  // check if already created
  JLG(temp, switch_int_proto_entry_handles, device);
  if (temp) {
    *hdl = (p4_pd_entry_hdl_t) * (p4_pd_entry_hdl_t *)temp;
    return true;
  }
  return false;
}
Exemple #15
0
int dogma_remove_charge(dogma_context_t* ctx, dogma_key_t index) {
	dogma_env_t** module_env;
	int count;

	JLG(module_env, ctx->ship->children, index);
	if(module_env == NULL) return DOGMA_NOT_FOUND;

	JLC(count, (*module_env)->children, 0, -1);
	assert(count <= 1); /* If there's more than one charge in this
	                     * module, something is wrong */

	return dogma_remove_env_generic(ctx, *module_env, 0);
}
Exemple #16
0
struct network_peer* network_manager_get_peer_by_address(struct network_manager* nm, struct network_address* address)
{
    Word_t* pindex;
    JHSG(pindex, nm->peer_by_address, (uint8_t*)address, sizeof(struct network_address));
    if(pindex == NULL) return NULL;

    Word_t peer_id = *pindex;
    struct network_peer** ppeer;
    JLG(ppeer, nm->peer_list, peer_id);
    if(ppeer == NULL) return NULL;

    return *ppeer;
}
int return_p(my_int j,my_int k)
{
	int Rc_int;
	JLG(pval,judy,j);
	if (pval==NULL)
		return 0;
	J1T(Rc_int,*pval,2*k+1);
	if (Rc_int==1)
		return 2;
	J1T(Rc_int,*pval,2*k);
	if (Rc_int==1)
		return 1;
   	return 0;
}
Exemple #18
0
int dogma_remove_drone_partial(dogma_context_t* ctx, dogma_typeid_t droneid, unsigned int quantity) {
	dogma_drone_context_t** value;

	JLG(value, ctx->drone_map, droneid);
	if(value == NULL) return DOGMA_OK;

	if(quantity >= (*value)->quantity) {
		return dogma_remove_drone(ctx, droneid);
	} else {
		/* At least one drone will remain */
		(*value)->quantity -= quantity;
		return DOGMA_OK;
	}
}
Exemple #19
0
switch_status_t switch_packet_hostif_delete(switch_device_t device,
                                            switch_hostif_info_t *hostif_info) {
  switch_status_t status = SWITCH_STATUS_SUCCESS;
  void *temp = NULL;

  JLG(temp, switch_intf_fd_array, hostif_info->intf_fd);
  if (!temp) {
    return SWITCH_STATUS_FAILURE;
  }
  JLD(status, switch_intf_fd_array, hostif_info->intf_fd);

  switch_packet_write_to_pipe();

  return status;
}
Exemple #20
0
static switch_status_t switch_l3_insert_into_vrf_list(
    switch_l3_hash_t *hash_entry) {
  switch_vrf_route_list_t *vrf_route_list = NULL;
  void *temp = NULL;
  switch_ip_addr_t ip_addr;
  switch_handle_t vrf_handle = 0;

  memset(&ip_addr, 0, sizeof(switch_ip_addr_t));
  switch_l3_hash_key_decode(hash_entry, &vrf_handle, &ip_addr);
  if (ip_addr.type == SWITCH_API_IP_ADDR_V4) {
    JLG(temp, switch_vrf_v4_routes, vrf_handle);
  } else {
    JLG(temp, switch_vrf_v6_routes, vrf_handle);
  }

  if (!temp) {
    vrf_route_list = switch_malloc(sizeof(switch_vrf_route_list_t), 1);
    if (!vrf_route_list) {
      SWITCH_API_ERROR("%s:%d: No memory!", __FUNCTION__, __LINE__);
      return SWITCH_STATUS_NO_MEMORY;
    }
    tommy_list_init(&(vrf_route_list->routes));
    vrf_route_list->num_entries = 0;
    if (ip_addr.type == SWITCH_API_IP_ADDR_V4) {
      JLI(temp, switch_vrf_v4_routes, vrf_handle);
    } else {
      JLI(temp, switch_vrf_v6_routes, vrf_handle);
    }
    *(unsigned long *)temp = (unsigned long)(vrf_route_list);
  }
  vrf_route_list = (switch_vrf_route_list_t *)(*(unsigned long *)temp);
  tommy_list_insert_tail(
      &(vrf_route_list->routes), &(hash_entry->vrf_route_node), hash_entry);
  vrf_route_list->num_entries++;
  return SWITCH_STATUS_SUCCESS;
}
Exemple #21
0
int dogma_add_charge(dogma_context_t* ctx, dogma_key_t index, dogma_typeid_t chargeid) {
	dogma_env_t** module_env;
	dogma_key_t charge_index = 0;

	JLG(module_env, ctx->ship->children, index);
	if(module_env == NULL) return DOGMA_NOT_FOUND;

	/* Maybe remove previous charge */
	dogma_remove_charge(ctx, index);

	return dogma_add_env_generic(
		ctx,
		*module_env, ctx,
		chargeid, &charge_index, DOGMA_STATE_Active
	);
}
Exemple #22
0
static inline int dogma_remove_env_generic(dogma_context_t* ctx,
                                           dogma_env_t* location,
                                           dogma_key_t index) {
	dogma_env_t** env;
	int result;

	JLG(env, location->children, index);
	if(env == NULL) return DOGMA_NOT_FOUND;

	DOGMA_ASSUME_OK(dogma_set_env_state(ctx, *env, DOGMA_STATE_Unplugged));

	dogma_free_env(ctx, *env);

	JLD(result, location->children, index);
	return DOGMA_OK;
}
Exemple #23
0
size_t network_manager_get_invs(struct network_manager* nm, enum INV_TYPE invtype, struct inv* out, size_t num_invs, int skip_claimed)
{
    size_t r = 0;
    assert(invtype != INV_TYPE_ERROR);

    Word_t start_index = 0;
    Word_t last_index = -1;
    void* list = NULL;

    switch(invtype) {
    case INV_TYPE_TX:
        start_index = nm->tail_tx_inv_id;
        last_index = nm->head_tx_inv_id;
        list = nm->tx_inv_list;
        break;
    case INV_TYPE_BLOCK:
        start_index = nm->tail_block_inv_id;
        last_index = nm->head_block_inv_id;
        list = nm->block_inv_list;
        break;
    case INV_TYPE_ERROR:
        assert(0);
        return 0;
    }

    for(Word_t index = start_index; index < last_index && r < num_invs; index++) {
        struct inv** pinv = NULL;
        JLG(pinv, list, index);
        assert(pinv != NULL);

        // check if this inv is claimed by a peer
        if(skip_claimed != 0) {
            Word_t* pindex = NULL;
            JHSG(pindex, nm->claimed_invs, (uint8_t*)(*pinv), sizeof(struct inv));
            if(pindex != NULL) {
                // This inv is claimed
                continue;
            }
        }

        memcpy(&out[r], *pinv, sizeof(struct inv));
        r++;
    }

    return r;
}
Exemple #24
0
void string_get(l3obj* obj, long i, l3path* val) {
    assert(obj->_type == t_str || obj->_type == t_lit);
    assert(val);

    PWord_t   PValue = 0;
    char** ps = 0;
    JLG(PValue,obj->_judyL,i);
    if (!PValue) {
        val->clear();
        return;
    }
    ps = (char**) (PValue);
    char* s = *ps;
    assert(s);
    val->pushf("%s",s);
    
}
Exemple #25
0
Fichier : hex.c Projet : mrahn/hex
static uint8_t _winning (PPosition_type pos, PState_DFS state, Pvoid_t* PJArray)
{
  if (pos->winner != N)
  {
    return 1;
  }

  Word_t const Index = encode (pos);

  {
    PWord_t PValue;

    JLG (PValue, *PJArray, Index);

    if (PValue)
    {
      ++_cnt_hit;

      return *PValue != pos->player;
    }
  }

  for (int f = 0; f < LEN * LEN; ++f)
  {
    if (pos->taken[f] == N)
    {
      put (pos, state, f);
      const uint8_t w = _winning (pos, state, PJArray);
      unput (pos, f);

      if (w)
      {
        insert (PJArray, Index, pos->player);

        return 0;
      }
    }
  }

  insert (PJArray, Index, 1 - pos->player);

  return 1;
}
Exemple #26
0
int dogma_remove_drone(dogma_context_t* ctx, dogma_typeid_t droneid) {
	dogma_drone_context_t** value;
	dogma_env_t* drone_env;
	int ret;

	JLG(value, ctx->drone_map, droneid);
	if(value == NULL) return DOGMA_OK; /* Nonexistent drone */

	drone_env = (*value)->drone;
	DOGMA_ASSUME_OK(dogma_set_env_state(ctx, drone_env, DOGMA_STATE_Unplugged));

	dogma_free_env(ctx, drone_env);
	free(*value);

	JLD(ret, drone_env->parent->children, drone_env->index);
	JLD(ret, ctx->drone_map, droneid);

	return DOGMA_OK;
}
Exemple #27
0
switch_status_t switch_api_l3_v6_route_entries_get_by_vrf(
    switch_handle_t vrf_handle, switch_l3_table_iterator_fn iterator_fn) {
  switch_l3_hash_t *hash_entry = NULL;
  tommy_node *node = NULL;
  switch_vrf_route_list_t *vrf_route_list = NULL;
  void *temp = NULL;
  switch_ip_addr_t ip_addr;

  JLG(temp, switch_vrf_v6_routes, vrf_handle);
  if (!temp) {
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }
  vrf_route_list = (switch_vrf_route_list_t *)(*(unsigned long *)temp);
  node = tommy_list_head(&(vrf_route_list->routes));
  while (node) {
    hash_entry = node->data;
    switch_l3_hash_key_decode(hash_entry, &vrf_handle, &ip_addr);
    iterator_fn(vrf_handle, ip_addr, hash_entry->nhop_handle);
    node = node->next;
  }
  return SWITCH_STATUS_SUCCESS;
}
Exemple #28
0
static inline pq_value *_pq_overload_for_types_non_variadic(pq_context *ctx, pq_overload *overload, size_t n, pq_type **types) {
	Word_t *pvalue;
	pq_value *best_match;
	int best_score = -1, score;
	Pvoid_t by_argnum_table = overload->function_table, by_type_table;
	JLG(pvalue, by_argnum_table, n);
	if(pvalue != NULL && pvalue != PJERR ) {
		by_type_table = (Pvoid_t)*pvalue;
		Word_t index = 0;
		JLF(pvalue, by_type_table, index);
		while(pvalue != NULL) {
			score = _pq_signature_match_score((pq_type *)index, n, types);
			if(score > best_score) {
				best_score = score;
				best_match = (pq_value *)*pvalue;
			}
			JLN(pvalue, by_type_table, index);
		}
		if(best_score >= 0) return best_match;
	}
	return NULL;
}
Exemple #29
0
int dogma_add_drone(dogma_context_t* ctx, dogma_typeid_t droneid, unsigned int quantity) {
	dogma_env_t** value1;
	dogma_drone_context_t** value2;
	dogma_drone_context_t* drone_ctx;
	dogma_env_t* drone_env;
	dogma_key_t index = DOGMA_SAFE_CHAR_INDEXES;
	int ret;

	if(quantity == 0) return DOGMA_OK;

	JLG(value2, ctx->drone_map, droneid);
	if(value2 != NULL) {
		/* Already have drones of the same type, just add the quantity */
		drone_ctx = *value2;
		drone_ctx->quantity += quantity;
		return DOGMA_OK;
	}

	drone_ctx = malloc(sizeof(dogma_drone_context_t));
	drone_env = malloc(sizeof(dogma_env_t)); /* Two calls to malloc
	                                          * are necessary here,
	                                          * since the env will be
	                                          * freed in
	                                          * dogma_free_env(). */
	JLFE(ret, ctx->character->children, index);
	JLI(value1, ctx->character->children, index);
	*value1 = drone_env;

	DOGMA_INIT_ENV(drone_env, droneid, ctx->character, index, ctx);

	JLI(value2, ctx->drone_map, droneid);
	*value2 = drone_ctx;

	drone_ctx->drone = drone_env;
	drone_ctx->quantity = quantity;

	return dogma_set_env_state(ctx, drone_env, DOGMA_STATE_Active);
}
Exemple #30
0
int network_manager_register_peer_for_polling(struct network_manager* nm, int sock, struct network_peer* peer)
{
    uintptr_t p = (uintptr_t)peer; 
    int* psock = NULL;
    JLG(psock, nm->poll_socket_by_peer, p);
    assert(psock == NULL); // duplicate insert

    JLI(psock, nm->poll_socket_by_peer, p);
    if(psock == NULL) { // memory failure
        return -1;
    }

    *psock = sock;

    FD_SET(sock, &nm->poll_read_fds);
    FD_SET(sock, &nm->poll_write_fds);
    FD_SET(sock, &nm->poll_exception_fds);

    vector_add(&nm->poll_fds, (uintptr_t)sock);
    if(sock > nm->poll_max_fd) nm->poll_max_fd = sock;

    return 0;
}