int 
lxl_dns_core_init(lxl_cycle_t *cycle)
{
	lxl_dns_pool = lxl_create_pool(LXL_DEFAULT_POOL_SIZE);
	if (lxl_dns_pool == NULL) {
		return -1;
	}

	lxl_dns_root_zone = lxl_palloc(lxl_dns_pool, sizeof(lxl_dns_zone_t));
	if (lxl_dns_root_zone == NULL) {
		return -1;
	}

	lxl_log_error(LXL_LOG_INFO, 0, "dns init zone hash");
	if (lxl_hash_init(&lxl_dns_hash, lxl_dns_pool, 1024000, lxl_hash_key) == -1) {
		lxl_log_error(LXL_LOG_ERROR, 0, "dns init hash failed");
		return -1;
	}

	lxl_list_init(&lxl_dns_root_zone->rrset_list);
	lxl_dns_root_zone->update_sec = lxl_current_sec;

	lxl_log_error(LXL_LOG_INFO, 0, "dns load named root path conf/named.root");
	lxl_dns_load_named_root("conf/named.root");

	lxl_log_error(LXL_LOG_INFO, 0, "dns add root zone");
	if (lxl_dns_zone_add(LXL_DNS_ROOT_LABEL, LXL_DNS_ROOT_LEN, lxl_dns_root_zone) == -1) {
		lxl_log_error(LXL_LOG_ERROR, 0, "dns add root zone failed");
		return -1;
	}

	return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	lxl_log_t *log;
	lxl_pool_t *pool;

	log = lxl_log_init(LXL_LOG_DEBUG, LXL_LOG_FLUSH);
	pool = lxl_pool_create(4096, log);

	lxl_str_t aa = lxl_null_string;
	char *a = "123456";
	lxl_str_t b = lxl_string("123456");
	lxl_str_t c = lxl_null_string, d = lxl_null_string;
/*	lxl_str_newlen(&c, 8);
	lxl_str_newdata(&d, "abcdefg");
	lxl_str_setdata(&c, a);
	lxl_str_free(&c);
	lxl_str_free(&d);*/

	lxl_str_t x = lxl_string("uuuuuuuuuu");
	lxl_str_t xx = lxl_string("iiiiiiiiiiiiii");
	x = xx;

	lxl_str_t s1 = lxl_null_string, s2 = lxl_null_string;
	s1.nalloc = 10;
	s1.data = (char *) lxl_alloc(s1.nalloc, log);
	s2.nalloc = 10;
	s2.data = (char *) lxl_palloc(pool, 10);
	//lxl_str_free(&s1);

	return 0;
}
Exemplo n.º 3
0
int 
lxl_dns_core_init(lxl_cycle_t *cycle)
{
	lxl_connection_t *c;

	lxl_dns_pool = lxl_create_pool(LXL_DEFAULT_POOL_SIZE);
	if (lxl_dns_pool == NULL) {
		return -1;
	}

	lxl_dns_root_zone = lxl_palloc(lxl_dns_pool, sizeof(lxl_dns_zone_t));
	if (lxl_dns_root_zone == NULL) {
		return -1;
	}

	lxl_log_error(LXL_LOG_INFO, 0, "dns init zone hash");
	if (lxl_hash_init(&lxl_dns_hash, lxl_dns_pool, 1024000, lxl_hash_key) == -1) {
		lxl_log_error(LXL_LOG_ERROR, 0, "dns init hash failed");
		return -1;
	}

	lxl_list_init(&lxl_dns_root_zone->rrset_list);
	lxl_dns_root_zone->update_sec = lxl_current_sec;

	lxl_log_error(LXL_LOG_INFO, 0, "dns load named root path conf/named.root");
	if (lxl_dns_load_named_root("conf/named.root") == -1) {
		lxl_log_error(LXL_LOG_ERROR, 0, "dns load named root path conf/named.root failed");
		return -1;
	}

	lxl_log_error(LXL_LOG_INFO, 0, "dns add root zone");
	if (lxl_dns_zone_add(LXL_DNS_ROOT_LABEL, LXL_DNS_ROOT_LEN, lxl_dns_root_zone) == -1) {
		lxl_log_error(LXL_LOG_ERROR, 0, "dns add root zone failed");
		return -1;
	}

	c = lxl_get_connection(-1);
	if (c == NULL) {
		return -1;
	}

	memset(&lxl_dns_event, 0x00, sizeof(lxl_event_t));
	lxl_dns_event.data = c;
	lxl_dns_event.handler = lxl_dns_data_rebuild_handler;
	lxl_add_timer(&lxl_dns_event, 86400*1000);

#if 0
	char *t;
	memcpy(t, "lxl coredump test", 1000);
#endif

	return 0;
}
Exemplo n.º 4
0
lxl_array_t *
lxl_array_create(lxl_pool_t *p, lxl_uint_t n, size_t size)
{
	lxl_array_t *a = lxl_palloc(p, sizeof(lxl_array_t));
	if (a == NULL) {
		return NULL;
	}

	if (lxl_array_init(a, p, n, size) != 0) {
		return NULL;
	}

	return a;
}
Exemplo n.º 5
0
static void *
lxl_event_core_create_conf(lxl_cycle_t *cycle)
{
	lxl_event_conf_t *ecf;

	ecf = lxl_palloc(cycle->pool, sizeof(lxl_event_conf_t));
	if (ecf == NULL) {
		return NULL;
	}

	ecf->connections = LXL_CONF_UNSET_UINT;
	ecf->use = LXL_CONF_UNSET_UINT;	
	ecf->accept_mutex = LXL_CONF_UNSET;
	ecf->name = (void *) LXL_CONF_UNSET;

	return ecf;
}
Exemplo n.º 6
0
lxl_buf_t *
lxl_create_temp_buf(lxl_pool_t *pool, size_t size)
{
	lxl_buf_t *b;

	b = lxl_alloc_buf(pool);
	if (b == NULL) {
		return NULL;
	}

	b->data = lxl_palloc(pool, size);
	if (b->data == NULL) {
		return NULL;
	}

	b->len = 0;
	b->nalloc = size;

	return b;
}
Exemplo n.º 7
0
lxl_dns_zone_t *
lxl_dns_zone_addfind(char *zname, uint16_t zlen)
{
	void **value;
	lxl_dns_zone_t *zone;

	value = lxl_hash_addfind(&lxl_dns_hash, zname, zlen);
	if (value == NULL) {
		return NULL;
	}

	if (*value == NULL) {
		zone = lxl_palloc(lxl_dns_pool, sizeof(lxl_dns_zone_t));
		if (zone == NULL) {
			return NULL;
		}

		lxl_log_debug(LXL_LOG_DEBUG_DNS, 0, "dns data add zone zname:%s zlen:%hu", zname, zlen);
		lxl_list_init(&zone->rrset_list);
		*value = zone;
	}

	return *value;
}
Exemplo n.º 8
0
lxl_int_t 
lxl_dns_rr_add(lxl_pool_t *pool, lxl_dns_zone_t *zone, lxl_dns_rr_t *rr)
{
	lxl_dns_rrset_t *rrset;
	lxl_dns_rdata_t *rdata;

#if 1
	char *data, buffer[40];	/* 40 ipv6 16 ipv4 */
	if (rr->soa_flags & LXL_DNS_RRSET_NORMAL_TYPE) {
		switch(rr->type) {
			case LXL_DNS_A:
				inet_ntop(AF_INET, rr->rdata, buffer, 40);
				data = buffer;
				break;

			case LXL_DNS_AAAA:
				inet_ntop(AF_INET6, rr->rdata, buffer, 40);
				data = buffer;
				break;

			case LXL_DNS_MX:
				data = rr->rdata + 2;

			default:
				data = rr->rdata;
				break;
		}
	} else {
		data = rr->rdata;
	}

	lxl_log_debug(LXL_LOG_DEBUG_DNS, 0, "dns add rr: name:%s type:%04x ttl:%u rdata:%s", rr->name, rr->type, rr->ttl, data);
#endif
	rrset = lxl_dns_rrset_find(&zone->rrset_list, rr->name, rr->nlen, rr->type, LXL_DNS_RRSET_NORMAL_FIND);
	if (rrset == NULL) {
		lxl_log_debug(LXL_LOG_DEBUG_DNS, 0, "dna add rrset");
		rrset = lxl_palloc(pool, sizeof(lxl_dns_rrset_t) + rr->nlen);
		if (rrset == NULL) {
			return -1;
		}

		rdata = lxl_palloc(pool, sizeof(lxl_dns_rdata_t) + rr->rdlength);
		if (rdata == NULL) {
			//lxl_free(rrset);
			return -1;
		}

		
		rrset->soa_nlen = rr->soa_nlen;
		rrset->soa_flags = rr->soa_flags;
		rrset->expires_sec = rr->expires_sec;
		rrset->update_flags = rr->update_flags;

		rrset->type = rr->type;
		rrset->ttl = rr->ttl;
		rrset->nlen = rr->nlen;
		memcpy(rrset->name, rr->name, rr->nlen);

		rdata->update_flags = rr->update_flags;
		rdata->rdlength = rr->rdlength;
		memcpy(rdata->rdata, rr->rdata, rr->rdlength);

		lxl_list_init(&rrset->rdata_list);
		lxl_list_add_tail(&rrset->rdata_list, &rdata->list);
		lxl_list_add_tail(&zone->rrset_list, &rrset->list);

		return 0;
	}

	rrset->update_flags = rr->update_flags;
	rrset->ttl = rr->ttl;
	rrset->expires_sec = rr->expires_sec;
	rdata = lxl_dns_rdata_find(&rrset->rdata_list, rr->rdata, rr->rdlength);
	if (rdata == NULL) {
		lxl_log_debug(LXL_LOG_DEBUG_DNS, 0, "dns add rdata");
		rdata = lxl_palloc(pool, sizeof(lxl_dns_rdata_t) + rr->rdlength);
		if (rdata == NULL) {
			return -1;
		}

		rdata->update_flags = rr->update_flags;
		rdata->rdlength = rr->rdlength;
		memcpy(rdata->rdata, rr->rdata, rr->rdlength);

		lxl_list_add_tail(&rrset->rdata_list, &rdata->list);
	} else {
		rdata->update_flags = rr->update_flags;
	}
	
	return 0;
}
Exemplo n.º 9
0
void 
lxl_dns_data_rebuild(void)
{
	lxl_pool_t *new_pool;
	lxl_list_t *list1, *list2;
	lxl_dns_rr_t rr;
	lxl_dns_zone_t *old_zone, *new_zone;
	lxl_dns_rrset_t *rrset;
	lxl_dns_rdata_t *rdata;
	
	old_zone = lxl_dns_zone_find(LXL_DNS_ROOT_LABEL, LXL_DNS_ROOT_LEN);
	if (old_zone == NULL) {
		lxl_log_error(LXL_LOG_ERROR, 0, "dns data rebuild root not find");
		return;
	}

	lxl_log_error(LXL_LOG_INFO, 0, "dns data rebuild create new pool");
	new_pool = lxl_create_pool(LXL_DEFAULT_POOL_SIZE);
	if (new_pool == NULL) {
		lxl_log_error(LXL_LOG_ERROR, 0, "dns data rebuild create pool failed");
		return;
	}

	lxl_log_error(LXL_LOG_INFO, 0, "dns data rebuild init hash");
	if (lxl_hash_init(&lxl_dns_hash, new_pool, lxl_dns_hash.nelts, lxl_dns_hash.key) == -1) {
        lxl_log_error(LXL_LOG_ERROR, 0, "dns init hash failed");
        return;
    }

	new_zone = lxl_palloc(new_pool, sizeof(lxl_dns_zone_t));
	if (new_zone == NULL) {
		return;
	}

	lxl_list_init(&new_zone->rrset_list);
	new_zone->update_sec = lxl_current_sec;
	for (list1 = lxl_list_head(&old_zone->rrset_list); list1 != lxl_list_sentinel(&old_zone->rrset_list); list1 = lxl_list_next(list1)) {
		rrset = lxl_list_data(list1, lxl_dns_rrset_t, list);
		rr.type = rrset->type;
		rr.ttl = rrset->ttl;
		rr.nlen = rrset->nlen;
		rr.name = rrset->name;
		rr.soa_nlen = 0;
		rr.soa_flags = LXL_DNS_RRSET_NORMAL_TYPE;
		rr.expires_sec = lxl_current_sec + rrset->ttl;
		rr.update_flags = LXL_DNS_RR_NORMAL_TYPE;
		for (list2 = lxl_list_head(&rrset->rdata_list); list2 != lxl_list_sentinel(&rrset->rdata_list); list2 = lxl_list_next(list2)) {
			rdata = lxl_list_data(list2, lxl_dns_rdata_t, list);
			rr.rdlength = rdata->rdlength;
			rr.rdata = rdata->rdata;
			if (lxl_dns_rr_add(new_pool, new_zone, &rr) == -1) {
				lxl_log_error(LXL_LOG_ERROR, 0, "dns data rebuild add rr failed");
				return;
			}
		}
	}

	lxl_log_error(LXL_LOG_INFO, 0, "dns data rebuild add root zone");
	if (lxl_dns_zone_add(LXL_DNS_ROOT_LABEL, LXL_DNS_ROOT_LEN, new_zone) == -1) {
		lxl_log_error(LXL_LOG_ERROR, 0, "dns data rebuild add root zone failed");
		//return;
	}

	lxl_log_error(LXL_LOG_INFO, 0, "dns data rebuild destory pool");
	lxl_destroy_pool(lxl_dns_pool);
	lxl_dns_pool = new_pool;
	lxl_log_error(LXL_LOG_INFO, 0, "dns data rebuild succeed");
}
Exemplo n.º 10
0
static int
lxl_dfss_collect_fid(char *base_path)
{
	size_t			len;
	DIR			   *dir;
	struct stat		stat;
	struct dirent  *de;
	lxl_str_t      *path, *value, *fid;
	lxl_queue_t    *queue;
	lxl_dfs_fid_t  *dfs_fid;

	lxl_log_error(LXL_LOG_INFO, 0, "dfss collect fid %s", base_path);

	queue = lxl_queue_create(lxl_dfss_temp_pool, 1024, sizeof(lxl_str_t));
	if (queue == NULL) {
		return -1;
	}

	value = lxl_queue_in(queue);
	if (value  == NULL) {
		return -1;
	}

	len = strlen(base_path);
	value->data = lxl_palloc(lxl_dfss_temp_pool, len + 1);
	if (value->data == NULL) {
		return -1;
	}

	lxl_str_memcpy(value, base_path, len);

	while ((path = lxl_queue_out(queue)) != NULL) {
		dir = opendir(path->data);
		if (dir == NULL) {
			lxl_log_error(LXL_LOG_ERROR, errno, "opendir(%s) failed", path->data);
			goto failed;
		}

		while ((de = readdir(dir)) != NULL) {
			if (S_ISDIR(de->d_type)) {
				value = lxl_queue_in(queue);
				if (value == NULL) {
					goto failed;
				}

				len = strlen(de->d_name);
				value->data = lxl_palloc(lxl_dfss_temp_pool, len + 1);
				if (value->data == NULL) {
					goto failed;
				}

				lxl_str_memcpy(value, de->d_name, len);
			} else if (S_ISREG(de->d_type)) {
				fid = lxl_palloc(lxl_dfss_temp_pool, sizeof(lxl_str_t));
				if (fid == NULL) {
					goto failed;
				}

				len = strlen(de->d_name);
				fid->data = lxl_palloc(lxl_dfss_temp_pool, len + 1);
				if (fid->data == NULL) {
					goto failed;
				}

				lxl_str_memcpy(fid, de->d_name, len);
				lxl_hash_add(&lxl_dfss_fid_phash, fid->data, len, fid);
			} else {
			}
		}

		closedir(dir);
	}

	return 0;

failed:

	closedir(dir);

	return -1;
}