Exemplo n.º 1
0
void *
tree_xget(struct tree *t, uint64_t id)
{
	struct treeentry	key, *entry;

	key.id = id;
	if ((entry = SPLAY_FIND(_tree, &t->tree, &key)) == NULL)
		errx(1, "tree_get(%p, 0x%016"PRIx64 ")", t, id);

	return (entry->data);
}
Exemplo n.º 2
0
static struct i915_hw_context *
i915_gem_context_get(struct drm_i915_file_private *file_priv, u32 id)
{
	struct i915_ctx_handle *han, search;
	search.handle = id;
	han = SPLAY_FIND(i915_ctx_tree, &file_priv->ctx_tree, &search);
	if (han == NULL)
		return NULL;

	return (han->ctx);
}
Exemplo n.º 3
0
void *
relay_dns_validate(struct rsession *con, struct relay *rlay,
    struct sockaddr_storage *ss, u_int8_t *buf, size_t len)
{
	struct relay_dnshdr	*hdr = (struct relay_dnshdr *)buf;
	struct rsession		 lookup;
	u_int16_t		 key;
	struct relay_dns_priv	*priv, lpriv;

	/* Validate the header length */
	if (len < sizeof(*hdr))
		return (NULL);

	key = ntohs(hdr->dns_id);

	/*
	 * Check if the header has the response flag set, otherwise
	 * return 0 to tell the UDP server to create a new session.
	 */
	if ((hdr->dns_flags0 & DNS_F0_QR) == 0) {
		priv = malloc(sizeof(struct relay_dns_priv));
		if (priv == NULL)
			return (NULL);
		priv->dp_inkey = shuffle_generate16(&relay_shuffle);
		priv->dp_outkey = key;
		return ((void *)priv);
	}

	/*
	 * Lookup if this response is for a known session and if the
	 * remote host matches the original destination of the request.
	 */
	if (con == NULL) {
		lpriv.dp_inkey = key;
		lookup.se_priv = &lpriv;
		if ((con = SPLAY_FIND(session_tree,
		    &rlay->rl_sessions, &lookup)) != NULL &&
		    con->se_priv != NULL &&
		    relay_cmp_af(ss, &con->se_out.ss) == 0)
			relay_dns_result(con, buf, len);
	} else {
		priv = (struct relay_dns_priv *)con->se_priv;
		if (priv == NULL || key != priv->dp_inkey) {
			relay_close(con, "invalid response");
			return (NULL);
		}
		relay_dns_result(con, buf, len);
	}

	/*
	 * This is not a new session, ignore it in the UDP server.
	 */
	return (NULL);
}
Exemplo n.º 4
0
void *
dict_xget(struct dict *d, const char *k)
{
	struct dictentry	key, *entry;

	key.key = k;
	if ((entry = SPLAY_FIND(_dict, &d->dict, &key)) == NULL)
		errx(1, "dict_xget(%p, %s)", d, k);

	return (entry->data);
}
Exemplo n.º 5
0
void *
dict_get(struct dict *d, const char *k)
{
	struct dictentry	key, *entry;

	key.key = k;
	if ((entry = SPLAY_FIND(_dict, &d->dict, &key)) == NULL)
		return (NULL);

	return (entry->data);
}
Exemplo n.º 6
0
void *
tree_get(struct tree *t, uint64_t id)
{
	struct treeentry	key, *entry;

	key.id = id;
	if ((entry = SPLAY_FIND(_tree, &t->tree, &key)) == NULL)
		return (NULL);

	return (entry->data);
}
Exemplo n.º 7
0
static assoc_item *
get_assoc(FILE *fp)
{
	char line[1024];
	char *p, *q;
	assoc_item *assoc = NULL;
	struct xp_fingerprint fprint;

	/* Get one line */
	p = fgets(line, sizeof(line), fp);
	if (p == NULL)
		return (NULL);

	/* Remove leading whitespace */
	p += strspn(p, WHITESPACE);

	/* Remove comments and blank lines */
	if (*p == '\0' || *p == '#')
		return (NULL);

	/* Remove trailing comments */
	q = p;
	strsep(&q, "#\r\n");

	/* Split on ; */
	q = p;
	p = strsep(&q, ";");
	if (p == NULL || q == NULL)
		return (NULL);

	/* Make a new association */
	assoc = (assoc_item *)calloc(1, sizeof(struct assoc_item));
	if (assoc == NULL)
		return (NULL);

	/* The value in p is the nmap name.  The value in q is the xprobe
	 * name.
	 */
	fprint.os_id = q;
	assoc->nmap_name = strdup(p);
	assoc->xp_fprint = SPLAY_FIND(xp_fprint_tree, &xp_fprints, &fprint);

	/* Make sure the strdup and SPLAY_FIND succeeded, otherwise clean up */
	if (assoc->nmap_name == NULL || assoc->xp_fprint == NULL) {
		if (assoc->nmap_name)
			free (assoc->nmap_name);
		free (assoc);
		return (NULL);
	}

	/* fprintf(stderr, "%s <-> %s\n",p,q); */
	return (assoc);
}
Exemplo n.º 8
0
void
analyze_country_enter(const struct addr *addr, const struct addr *dst)
{
	struct keycount tmpkey, *key;

	struct country_state *state = calloc(1, sizeof(struct country_state));
	if (state == NULL)
	{
		syslog(LOG_ERR, "%s: failed to calloc state", __func__);
		exit(EXIT_FAILURE);
	}

	state->src = *addr;
	state->dst = *dst;

	/*
	 * Check if this IP returned a resolver error in the last hour.
	 */
	tmpkey.key = &addr->addr_ip;
	tmpkey.keylen = sizeof(addr->addr_ip);
	if ((key = SPLAY_FIND(kctree, &country_cache, &tmpkey)) != NULL) {
		if (count_get_minute(key->count) ||
		    count_get_hour(key->count)) {
			state->result_from_cache = 1;
			analyze_country_enter_cb(DNS_ERR_NOTEXIST, DNS_PTR,
			    0, 0, NULL, state);
			return;
		}
	}

	if (!checkpoint_doreplay) {
		struct in_addr in;
		in.s_addr = addr->addr_ip;
		evdns_resolve_reverse(&in, 0, analyze_country_enter_cb, state);
	} else {
		/*
		 * If we are replaying a checkpoint, we do not want to do
		 * async calls.
		 */
		struct hostent *hp = gethostbyaddr(
			(const char *)&addr->addr_ip, IP_ADDR_LEN, AF_INET);
		if (hp == NULL) {
			analyze_country_enter_cb(DNS_ERR_NOTEXIST, DNS_PTR,
			    0, 0, NULL, state);
		} else {
			analyze_country_enter_cb(DNS_ERR_NONE, DNS_PTR,
			    1, 1200 /* ttl */, (void *)&hp->h_name, state);
		}
	}
}
Exemplo n.º 9
0
int
main(int argc, char **argv)
{
	struct node *tmp, *ins;
	int i, max, min;

	SPLAY_INIT(&root);

	for (i = 0; i < ITER; i++) {
		tmp = malloc(sizeof(struct node));
		if (tmp == NULL) err(1, "malloc");
		do {
			tmp->key = arc4random_uniform(MAX-MIN);
			tmp->key += MIN;
		} while (SPLAY_FIND(tree, &root, tmp) != NULL);
		if (i == 0)
			max = min = tmp->key;
		else {
			if (tmp->key > max)
				max = tmp->key;
			if (tmp->key < min)
				min = tmp->key;
		}
		if (SPLAY_INSERT(tree, &root, tmp) != NULL)
			errx(1, "SPLAY_INSERT failed");
	}

	ins = SPLAY_MIN(tree, &root);
	if (ins->key != min)
		errx(1, "min does not match");
	tmp = ins;
	ins = SPLAY_MAX(tree, &root);
	if (ins->key != max)
		errx(1, "max does not match");

	if (SPLAY_REMOVE(tree, &root, tmp) != tmp)
		errx(1, "SPLAY_REMOVE failed");

	for (i = 0; i < ITER - 1; i++) {
		tmp = SPLAY_ROOT(&root);
		if (tmp == NULL)
			errx(1, "SPLAY_ROOT error");
		if (SPLAY_REMOVE(tree, &root, tmp) != tmp)
			errx(1, "SPLAY_REMOVE error");
		free(tmp);
	}

	exit(0);
}
Exemplo n.º 10
0
void *
tree_xpop(struct tree *t, uint64_t id)
{
	struct treeentry	key, *entry;
	void			*data;

	key.id = id;
	if ((entry = SPLAY_FIND(tree, t, &key)) == NULL)
		errx(1, "tree_xpop(%p, 0x%016" PRIx64 ")", t, id);

	data = entry->data;
	SPLAY_REMOVE(tree, t, entry);
	free(entry);

	return (data);
}
Exemplo n.º 11
0
Arquivo: tree.c Projeto: bingos/bitrig
void *
tree_pop(struct tree *t, uint64_t id)
{
	struct treeentry	key, *entry;
	void			*data;

	key.id = id;
	if ((entry = SPLAY_FIND(tree, t, &key)) == NULL)
		return (NULL);

	data = entry->data;
	SPLAY_REMOVE(tree, t, entry);
	free(entry);

	return (data);
}
Exemplo n.º 12
0
void
analyze_spammer_enter(const struct addr *src, uint32_t bytes)
{
	struct keycount tmpkey, *key;

	tmpkey.key = &src->addr_ip;
	tmpkey.keylen = sizeof(src->addr_ip);

	if ((key = SPLAY_FIND(kctree, &spammers, &tmpkey)) == NULL) {
		key = keycount_new(&src->addr_ip, sizeof(src->addr_ip),
		    NULL, NULL);
		SPLAY_INSERT(kctree, &spammers, key);
	}

	count_increment(key->count, bytes);
}
Exemplo n.º 13
0
static void do_destroy(struct i915_hw_context *ctx)
{
	struct drm_device *dev = ctx->obj->base.dev;
	struct drm_i915_private *dev_priv = dev->dev_private;

	if (ctx->file_priv) {
		struct i915_ctx_handle *han, find;
		find.handle = ctx->id;
		han = SPLAY_FIND(i915_ctx_tree, &ctx->file_priv->ctx_tree, &find);
		if (han != NULL)
			SPLAY_REMOVE(i915_ctx_tree, &ctx->file_priv->ctx_tree, han);
	} else
		BUG_ON(ctx != dev_priv->ring[RCS].default_context);

	drm_gem_object_unreference(&ctx->obj->base);
	kfree(ctx);
}
Exemplo n.º 14
0
void *
dict_xpop(struct dict *d, const char *k)
{
	struct dictentry	key, *entry;
	void			*data;

	key.key = k;
	if ((entry = SPLAY_FIND(_dict, &d->dict, &key)) == NULL)
		errx(1, "dict_xpop(%p, %s)", d, k);

	data = entry->data;
	SPLAY_REMOVE(_dict, &d->dict, entry);
	free(entry);
	d->count -= 1;

	return (data);
}
Exemplo n.º 15
0
void
waitq_run(void *tag, void *result)
{
	struct waitq	*wq, key;
	struct waiter	*w;

	key.tag = tag;
	wq = SPLAY_FIND(waitqtree, &waitqs, &key);
	SPLAY_REMOVE(waitqtree, &waitqs, wq);

	while((w = TAILQ_FIRST(&wq->waiters))) {
		TAILQ_REMOVE(&wq->waiters, w, entry);
		w->cb(tag, w->arg, result);
		free(w);
	}
	free(wq);
}
Exemplo n.º 16
0
void
analyze_os_enter(const struct addr *addr, const char *osfp)
{
	struct keycount tmpkey, *key;

	tmpkey.key = osfp;
	tmpkey.keylen = strlen(osfp) + 1;

	if ((key = SPLAY_FIND(kctree, &oses, &tmpkey)) == NULL) {
		key = keycount_new(osfp, strlen(osfp) + 1,
		    aux_create, aux_free);
		SPLAY_INSERT(kctree, &oses, key);
	}

	/* If the address is new, we are going to increase the counter */
	if (aux_enter(key->auxilary, addr->addr_ip))
		count_increment(key->count, 1);
}
Exemplo n.º 17
0
Arquivo: tree.c Projeto: bingos/bitrig
void *
tree_set(struct tree *t, uint64_t id, void *data)
{
	struct treeentry	*entry, key;

	key.id = id;
	if ((entry = SPLAY_FIND(tree, t, &key)) == NULL) {
		entry = malloc(sizeof *entry);
		if (entry == NULL)
			return (NULL);
		entry->id = id;
		SPLAY_INSERT(tree, t, entry);
	}

	entry->data = data;

	return (entry);
}
Elf_Addr
_dl_md_plabel(Elf_Addr pc, Elf_Addr *sl)
{
	hppa_plabel_t key, *p;

	key.pc = pc;
	key.sl = sl;
	p = SPLAY_FIND(_dl_md_plabels, &_dl_md_plabel_root, &key);
	if (p == NULL) {
		p = _dl_malloc(sizeof(*p));
		if (p == NULL)
			_dl_exit(5);
		p->pc = pc;
		p->sl = sl;
		SPLAY_INSERT(_dl_md_plabels, &_dl_md_plabel_root, p);
	}

	return (Elf_Addr)p | 2;
}
Exemplo n.º 19
0
void *
tree_set(struct tree *t, uint64_t id, void *data)
{
	struct treeentry	*entry, key;
	char			*old;

	key.id = id;
	if ((entry = SPLAY_FIND(tree, t, &key)) == NULL) {
		entry = xmalloc(sizeof *entry, "tree_set");
		entry->id = id;
		SPLAY_INSERT(tree, t, entry);
		old = NULL;
	} else
		old = entry->data;

	entry->data = data;

	return (old);
}
Exemplo n.º 20
0
void
analyze_port_enter(uint16_t port,
    const struct addr *src, const struct addr *dst)
{
	struct keycount tmpkey, *key;

	tmpkey.key = &port;
	tmpkey.keylen = sizeof(port);

	if ((key = SPLAY_FIND(kctree, &ports, &tmpkey)) == NULL) {
		key = keycount_new(&port, sizeof(port),
		    aux_create, aux_free);
		SPLAY_INSERT(kctree, &ports, key);
	}

	/* If the address is new, we are going to increase the counter */
	if (aux_enter(key->auxilary, port_hash(src, dst)))
		count_increment(key->count, 1);
}
Exemplo n.º 21
0
void *
dict_set(struct dict *d, const char *k, void *data)
{
	struct dictentry	*entry, key;
	char			*old;

	key.key = k;
	if ((entry = SPLAY_FIND(_dict, &d->dict, &key)) == NULL) {
		if ((entry = dict_alloc(k, data)) == NULL)
			err(1, "dict_set: malloc");
		SPLAY_INSERT(_dict, &d->dict, entry);
		old = NULL;
		d->count += 1;
	} else {
		old = entry->data;
		entry->data = data;
	}

	return (old);
}
Exemplo n.º 22
0
int
cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx)
{
	struct cmd_unbind_key_data	*data = self->data;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;

	if ((mtab = mode_key_findtable(data->tablename)) == NULL) {
		ctx->error(ctx, "unknown key table: %s", data->tablename);
		return (-1);
	}

	mtmp.key = data->key & ~KEYC_PREFIX;
	mtmp.mode = data->command_key ? 1 : 0;
	if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
		SPLAY_REMOVE(mode_key_tree, mtab->tree, mbind);
		xfree(mbind);
	}
	return (0);
}
Exemplo n.º 23
0
void *
tree_set(struct tree *t, uint64_t id, void *data)
{
	struct treeentry	*entry, key;
	char			*old;

	key.id = id;
	if ((entry = SPLAY_FIND(_tree, &t->tree, &key)) == NULL) {
		if ((entry = malloc(sizeof *entry)) == NULL)
			err(1, "tree_set: malloc");
		entry->id = id;
		SPLAY_INSERT(_tree, &t->tree, entry);
		old = NULL;
		t->count += 1;
	} else
		old = entry->data;

	entry->data = data;

	return (old);
}
void
lfs_deregister_block(struct vnode *vp, daddr_t lbn)
{
	struct lfs *fs;
	struct inode *ip;
	struct lbnentry *lbp;
	struct lbnentry tmp;

	ip = VTOI(vp);

	/* Don't count metadata */
	if (lbn < 0 || vp->v_type != VREG || ip->i_number == LFS_IFILE_INUM)
		return;

	fs = ip->i_lfs;
	tmp.lbn = lbn;
	lbp = SPLAY_FIND(lfs_splay, &ip->i_lfs_lbtree, &tmp);
	if (lbp == NULL)
		return;

	lfs_do_deregister(fs, ip, lbp);
}
Exemplo n.º 25
0
int
correlate_nmap_with_xprobe(struct personality *pers)
{
	struct assoc_item *assoc;
	struct assoc_item lookup;

	if (pers == NULL)
		return 0;

	/* Lookup the association */
	lookup.nmap_name = pers->name;
	if ((assoc = SPLAY_FIND(assoc_tree, &associations, &lookup)) == NULL)
		return (0);

	/* 
	 * If we have the association, put the xprobe fingerprint in
	 * the personality.
	 */
	pers->xp_fprint = assoc->xp_fprint;

	return (0);
}
Exemplo n.º 26
0
int
waitq_wait(void *tag, void (*cb)(void *, void *, void *), void *arg)
{
	struct waitq	*wq, key;
	struct waiter	*w;

	key.tag = tag;
	wq = SPLAY_FIND(waitqtree, &waitqs, &key);
	if (wq == NULL) {
		wq = xmalloc(sizeof *wq, "waitq_wait");
		wq->tag = tag;
		TAILQ_INIT(&wq->waiters);
		SPLAY_INSERT(waitqtree, &waitqs, wq);
	}

	w = xmalloc(sizeof *w, "waitq_wait");
	w->cb = cb;
	w->arg = arg;
	TAILQ_INSERT_TAIL(&wq->waiters, w, entry);

	return (w == TAILQ_FIRST(&wq->waiters));
}
Exemplo n.º 27
0
int
aux_enter(struct aux *aux, uint32_t value)
{
	struct auxtree *tree = &aux->tree;
	struct auxq *queue = &aux->queue;
	struct auxkey tmp, *key;

	tmp.value = value;
	if ((key = SPLAY_FIND(auxtree, tree, &tmp)) != NULL) {
		/* Mark this entry as recently used - LRU fashion */
		TAILQ_REMOVE(queue, key, next);
		TAILQ_INSERT_HEAD(queue, key, next);
		return (0);
	}

	if (aux->entries >= aux->limit) {
		key = TAILQ_LAST(queue, auxq);

		/* The old entry has to go, bye bye */
		SPLAY_REMOVE(auxtree, tree, key);
		TAILQ_REMOVE(queue, key, next);
		memset(key, 0, sizeof(struct auxkey));
		aux->entries--;
	} else {
		if ((key = calloc(1, sizeof(struct auxkey))) == NULL)
		{
			syslog(LOG_ERR, "%s: calloc failed to allocate key",__func__);
			exit(EXIT_FAILURE);
		}
	}
	key->value = tmp.value;

	/* Insert the new key */
	SPLAY_INSERT(auxtree, tree, key);
	TAILQ_INSERT_TAIL(queue, key, next);
	aux->entries++;

	return (1);
}
Exemplo n.º 28
0
int
cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
{
	struct args			*args = self->args;
	const char			*tablename;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;

	tablename = args_get(args, 't');
	if ((mtab = mode_key_findtable(tablename)) == NULL) {
		ctx->error(ctx, "unknown key table: %s", tablename);
		return (-1);
	}

	mtmp.key = key;
	mtmp.mode = !!args_has(args, 'c');
	if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
		SPLAY_REMOVE(mode_key_tree, mtab->tree, mbind);
		xfree(mbind);
	}
	return (0);
}
Exemplo n.º 29
0
enum mode_key_cmd
mode_key_lookup(struct mode_key_data *mdata, int key)
{
	struct mode_key_binding	*mbind, mtmp;

	mtmp.key = key;
	mtmp.mode = mdata->mode;
	if ((mbind = SPLAY_FIND(mode_key_tree, mdata->tree, &mtmp)) == NULL) {
		if (mdata->mode != 0)
			return (MODEKEY_NONE);
		return (MODEKEY_OTHER);
	}

	switch (mbind->cmd) {
	case MODEKEYEDIT_SWITCHMODE:
	case MODEKEYEDIT_SWITCHMODEAPPEND:
		mdata->mode = 1 - mdata->mode;
		/* FALLTHROUGH */
	default:
		return (mbind->cmd);
	}
}
Exemplo n.º 30
0
void
filter_insert(struct filtertree *filters, uint32_t count, void *report)
{
	struct filter *filter, tmp;

	tmp.count = count;
	tmp.report = report;

	/* Check if we already manage this data */
	if ((filter = SPLAY_FIND(filtertree, filters, &tmp)) != NULL)
		return;

	if ((filter = calloc(1, sizeof(struct filter))) == NULL)
	{
		syslog(LOG_ERR, "%s: calloc failed to allocate filter",__func__);
		exit(EXIT_FAILURE);
	}

	filter->count = count;
	filter->report = report;
	SPLAY_INSERT(filtertree, filters, filter);
}