int add_ip(char *addr,unsigned int nip, short type) {
	unsigned long totaltime;
	//void *val;
	char **val=NULL;
	struct in_addr tmpip;
	struct t_node *node=NULL;
	int dodns=0;
	//char *rr=NULL;
	printf("Add_ip %u %d\n",nip,type);
    node=xmalloc(sizeof(struct t_node));

	//set time
	struct timeval now;
	struct timezone dtz;
	gettimeofday(&now, &dtz);
	totaltime = now.tv_sec;
#ifdef DEBUG
	DPRINTF("type: %d\n",type);
	twalk(cache, action);
#endif

	switch (type) {
		//bad ips
		case IP_RBL:
			dodns=0;
			totaltime += WEEK;
			break;
		case IP_XUSA:
			dodns=1;
			totaltime += WEEK * 4;
			break;
		case IP_BANNED:
			totaltime += MONTH * 24;
			break;
		case IP_DYN:
			totaltime += WEEK * 4;
			break;
		case IP_VIOLATION:
			totaltime += HOUR * global.bantime;
			break;

		//good ips
		case IP_GOOD:
			totaltime += DAY;
			dodns=1;
			break;
		case IP_TRUSTED:
			dodns=0;
			totaltime += MONTH * 24;
			break;
		case IP_OLD:
			totaltime -= MONTH;
			break;

		//in case we forget someone, assume the worse
		default:
			type=IP_BANNED;
			totaltime += WEEK * 4;
	}

	if (nip == 0) { //numeric ip is not passed
		if(inet_aton(addr,&tmpip) != 1){
			free(node);
			return IP_BANNED;
		}
		node->ip = tmpip.s_addr;
	} else 
		node->ip = nip;

	node->status = type;
	node->expire = totaltime;
	node->rr = NULL;
	if (dodns)
		node->rr = getrr(node->ip,NULL);

	printf("adding '%u' -> (%d)\n",node->ip,node->status);

	pthread_mutex_lock(&m_cache);
	val = tsearch(node, &cache, compare);
	pthread_mutex_unlock(&m_cache);
	if ((struct t_node *) *val != node)
		printf("add ip val != node\n");
	//	free(node);
	//printf("Value: %x \n\n",node2.ip);
	return 0;
}