Пример #1
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;
}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
0
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
			));
		}
	}
Пример #5
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;
}
Пример #6
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;
}
Пример #7
0
static int start_peer(struct network_manager* nm)
{
    // Randomly pick an address to connect to
    struct network_address address;
    int have_address = 0;

    for(int i = 0; i < 50; i++) {
        if(database_get_random_peer_address(chaind_database(nm->chaind), &address) <= 0) {
            // Error, or no address to select
            break;
        }

        // Apply default port if sin_port == 0
        if(address.sin_port == 0) address.sin_port = htons(NETWORK_DEFAULT_PORT);

        if(network_manager_get_peer_by_address(nm, &address) == NULL) {
            have_address = 1;
            break;
        }
    }

    if(!have_address) return -1;

    struct network_peer* peer = network_peer_create(nm);
    struct network_peer** ppeer = NULL;

    Word_t peer_id = nm->next_peer_id;
    JLI(ppeer, nm->peer_list, peer_id);
    *ppeer = peer;
    nm->next_peer_id += 1;

    Word_t* pindex;
    JHSI(pindex, nm->peer_by_address, (uint8_t*)&address, sizeof(struct network_address));
    *pindex = peer_id;

    int res = network_peer_connect(peer, &address, blockchain_link_height(chaind_best_blockchain_link(nm->chaind)));

    if(res != 0) {
        int rc;
        JLD(rc, nm->peer_list, peer_id);
        JHSD(rc, nm->peer_by_address, (uint8_t*)&address, sizeof(struct network_address));
        network_peer_destroy(peer);
        return res;
    }

    nm->num_peers += 1;
    return 0;
}
Пример #8
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;
}
Пример #9
0
static void remove_watch(DBusWatch* watch, void *userdata)
{
    struct dbus* dbus = (struct dbus*)userdata;

    Word_t index = 0;
    DBusWatch** pwatch;

    JLF(pwatch, dbus->watches, index);
    while(pwatch != NULL) {
        if(*pwatch == watch) {
            Word_t wrc;
            JLD(wrc, dbus->watches, index);
            break;
        }
        JLN(pwatch, dbus->watches, index);
    }
}
Пример #10
0
switch_status_t switch_int_transit_enable(switch_device_t device,
                                          int32_t switch_id,
                                          int32_t enable) {
  switch_status_t status = SWITCH_STATUS_SUCCESS;
#ifdef P4_INT_TRANSIT_ENABLE
  p4_pd_entry_hdl_t entry_hdl;
  if (enable) {
    void *temp = NULL;
    // check if already created
    if (switch_int_entry_hdl_get(device, &entry_hdl)) {
      return SWITCH_STATUS_ITEM_ALREADY_EXISTS;
    }
    // use the lowest priority entry for transit
    status = switch_pd_int_transit_enable(device, switch_id, 1, &entry_hdl);
    if (status == SWITCH_STATUS_SUCCESS) {
      JLI(temp, switch_int_proto_entry_handles, device);
      if (!temp) {
        return SWITCH_STATUS_NO_MEMORY;
      }
      *(p4_pd_entry_hdl_t *)temp = entry_hdl;
    }
  } else {
    // disable
    int rc;
    if (!switch_int_entry_hdl_get(device, &entry_hdl)) {
      return SWITCH_STATUS_ITEM_NOT_FOUND;
    }
    status = switch_pd_int_transit_disable(device, entry_hdl);
    if (status == SWITCH_STATUS_SUCCESS) {
      JLD(rc, switch_int_proto_entry_handles, device);
    }
  }
#else
  (void)device, (void)switch_id, (void)enable;
#endif
  return status;
}
Пример #11
0
static void stop_peer(struct network_manager* nm, struct network_peer* peer)
{
    struct network_address address;
    network_peer_address(peer, &address);

    Word_t* pindex;
    JHSG(pindex, nm->peer_by_address, (uint8_t*)&address, sizeof(struct network_address));
    assert(pindex != NULL);

    Word_t peer_id = *pindex;
    struct network_peer** ppeer;
    JLG(ppeer, nm->peer_list, peer_id);
    assert(ppeer != NULL);
    assert(*ppeer == peer);

    // Remove from lists
    int rc;
    JLD(rc, nm->peer_list, peer_id);
    JHSD(rc, nm->peer_by_address, (uint8_t*)&address, sizeof(struct network_address));
    
    // Done with you!
    network_peer_destroy(peer);
    nm->num_peers -= 1;
}
Пример #12
0
/* returns 1 if was present, 0 otherwise */
static inline int delete_prefix(node_t *current_node,
                                unsigned short prefix_key) {
  int rc;
  JLD(rc, current_node->PJLarray_prefixes, (Word_t)prefix_key);
  return rc;
}
Пример #13
0
static inline int delete_branch(node_t *current_node, byte_t byte) {
  int rc;
  JLD(rc, current_node->PJLarray_branches, (Word_t)byte);
  return rc;
}
Пример #14
0
static void remove_from_wanted_invs(struct network_manager* nm, struct inv const* invs, size_t num_invs)
{
    Word_t swap_index;
    struct inv** pinv1;
    struct inv** pinv2;
    struct inv* inv2;
    int rc;
    Word_t* pindex1;
    Word_t* pindex2;

    for(size_t i = 0; i < num_invs; i++) {
        struct inv const* inv = &invs[i];

        JHSG(pindex1, nm->wanted_invs_by_inv, (uint8_t*)inv, sizeof(struct inv));
        assert(pindex1 != NULL);

        Word_t* tail = NULL;
        Word_t* head = NULL;
        void** list = NULL;

        switch(inv->type) {
        case INV_TYPE_BLOCK:
            head = &nm->head_block_inv_id;
            tail = &nm->tail_block_inv_id;
            list = &nm->block_inv_list;
            break;
        case INV_TYPE_TX:
            head = &nm->head_tx_inv_id;
            tail = &nm->tail_tx_inv_id;
            list = &nm->tx_inv_list;
            break;
        case INV_TYPE_ERROR:
            assert(0);
            break;
        }

        assert(*head > *tail);

        swap_index = *head - 1;
        if(*pindex1 == *tail) {
            JLG(pinv1, *list, *pindex1);
            assert(memcmp(*pinv1, inv, sizeof(struct inv)) == 0);

            free(*pinv1);
            JLD(rc, *list, *pindex1);

            (*tail) += 1;
        } else if(*pindex1 < swap_index) {
            JLG(pinv1, *list, *pindex1);
            assert(pinv1 != NULL);

            JLG(pinv2, *list, swap_index);
            assert(pinv2 != NULL);

            assert(memcmp(*pinv1, inv, sizeof(struct inv)) == 0);
            assert(memcmp(*pinv1, *pinv2, sizeof(struct inv)) != 0);

            // JLD will kill the pinv2 pointer, so save the inv
            inv2 = *pinv2;
            free(*pinv1);
            JLD(rc, *list, swap_index);

            // JLD can reorder the array..
            JLI(pinv1, *list, *pindex1);
            *pinv1 = inv2;

            // Remove from wanted array
            JHSG(pindex2, nm->wanted_invs_by_inv, (uint8_t*)inv2, sizeof(struct inv));
            *pindex2 = *pindex1;
            (*head) -= 1;
        } else {
            assert(*pindex1 == swap_index);

            JLG(pinv2, *list, swap_index);
            assert(memcmp(*pinv2, inv, sizeof(struct inv)) == 0);

            free(*pinv2);
            JLD(rc, *list, swap_index);

            (*head) -= 1;
        }

        JHSD(rc, nm->wanted_invs_by_inv, (uint8_t*)inv, sizeof(struct inv));
    }
}
Пример #15
0
int jtableL_remove(jtableL *table, unsigned long key) {
	int ret;

	JLD(ret, table->t, key);
	return ret;
}