예제 #1
0
파일: map.c 프로젝트: qgewfg/gtk-gnutella
/**
 * Lookup a key in the map.
 */
void *
map_lookup(const map_t *m, const void *key)
{
	map_check(m);

	switch (m->type) {
	case MAP_HASH:
		return htable_lookup(m->u.ht, key);
	case MAP_ORDERED_HASH:
		return ohash_table_lookup(m->u.ot, key);
	case MAP_PATRICIA:
		return patricia_lookup(m->u.pt, key);
	case MAP_MAXTYPE:
		g_assert_not_reached();
	}
	return NULL;
}
예제 #2
0
static int remove_from_ptree(patricia_tree_t *tree, int family, void *addr, int bits) {
  prefix_t prefix;
  patricia_node_t *node;
  int rc;

  if(family == AF_INET)
    fill_prefix_v4(&prefix, (struct in_addr*)addr, bits, tree->maxbits);
  else
    fill_prefix_v6(&prefix, (struct in6_addr*)addr, bits, tree->maxbits);

  node = patricia_lookup(tree, &prefix);

  if((patricia_node_t *)0 != node)
    rc = 0, free(node);
  else
    rc = -1;
  
  return(rc);
}
예제 #3
0
static banrecord_t *
trigger_ban(trigger_t *t, packet_info_t *packet, iprecord_t *irec)
{
	banrecord_t *rec;
	prefix_t *pfx;
	patricia_node_t *node;
	struct in_addr sin;

	switch (t->type) {
	case TRIGGER_SRC:
		sin.s_addr = packet->pkt_src.s_addr;
		break;
	case TRIGGER_DST:
	default:
		sin.s_addr = packet->pkt_dst.s_addr;
		break;
	};

	if (ban_find(sin.s_addr) != NULL)
		return NULL;

	rec = calloc(sizeof(banrecord_t), 1);

	rec->trigger = t;
	memcpy(&rec->irec, irec, sizeof(iprecord_t));
	memcpy(&rec->pkt, packet, sizeof(packet_info_t));
	rec->added = mowgli_eventloop_get_time(eventloop);
	rec->expiry_ts = rec->added + (t->expiry ? t->expiry : expiry);

	pfx = New_Prefix(AF_INET, &sin, 32);

	node = patricia_lookup(banrecord_trie, pfx);
	node->data = rec;

	Deref_Prefix(pfx);

	run_triggers(ACTION_BAN, t, packet, rec);

	rec->timer = mowgli_timer_add_once(eventloop, "expire_dynamic_trigger", expire_dynamic_trigger, rec, (t->expiry ? t->expiry : expiry));

	return rec;
}
예제 #4
0
파일: vnfacl.c 프로젝트: carriercomm/vnfapp
static inline void
add_patricia_entry (patricia_tree_t * tree, void * addr, u_int16_t len,
		    void * data)
{
	prefix_t * prefix;
	patricia_node_t * pn;

	prefix = (prefix_t *) malloc (sizeof (prefix_t));

	dst2prefix (addr, len, prefix);

	pn = patricia_lookup (tree, prefix);
	
	if (pn->data != NULL) {
		D ("duplicated entry %s/%d",
		   inet_ntoa (*((struct in_addr *)addr)), len);
	}

	pn->data = data;

	return;
}