Exemplo n.º 1
0
static int rosedb_query_txn(MDB_txn *txn, MDB_dbi dbi, knot_pkt_t *pkt, struct query_data *qdata)
{
	struct iter it;
	int ret = KNOT_EOK;

	/* Find suffix for QNAME. */
	const knot_dname_t *qname = knot_pkt_qname(qdata->query);
	const knot_dname_t *key = qname;
	while (key) {
		ret = cache_query_fetch(txn, dbi, &it, key);
		if (ret == 0) { /* Found */
			break;
		}

		if (*key == '\0') { /* Last label, not found. */
			return KNOT_ENOENT;
		}

		key = knot_wire_next_label(key, qdata->query->wire);
	}

	/* Synthetize record to response. */
	ret = rosedb_synth(pkt, key, &it, qdata);

	cache_iter_free(&it);
	return ret;
}
Exemplo n.º 2
0
static int rosedb_get(struct cache *cache, MDB_txn *txn, int argc, char *argv[])
{
	knot_dname_t key[KNOT_DNAME_MAXLEN] = { '\0' };
	knot_dname_from_str(key, argv[0], sizeof(key));
	knot_dname_to_lower(key);

	char type_str[16] = { '\0' };

	struct iter it;
	int ret = cache_query_fetch(txn, cache->dbi, &it, key);
	while (ret == 0) {
		struct entry entry;
		cache_iter_val(&it, &entry);
		knot_rdata_t *rd = knot_rdataset_at(&entry.data.rrs, 0);
		knot_rrtype_to_string(entry.data.type, type_str, sizeof(type_str));
		printf("%s\t%s\tTTL=%u\tRDLEN=%u\t%s\t%s\n", argv[0], type_str,
		       knot_rdata_ttl(rd), knot_rdata_rdlen(rd), entry.threat_code, entry.syslog_ip);
		if (cache_iter_next(&it) != 0) {
			break;
		}
	}

	cache_iter_free(&it);

	return ret;
}
Exemplo n.º 3
0
int cache_query_fetch(MDB_txn *txn, MDB_dbi dbi, struct iter *it, const knot_dname_t *name)
{
	it->cur = cursor_acquire(txn, dbi);
	if (it->cur == NULL) {
		return KNOT_ERROR;
	}

	int ret = cache_iter_begin(it, name);
	if (ret != 0) {
		cache_iter_free(it);
		return KNOT_ENOENT;
	}

	return KNOT_EOK;
}