Esempio n. 1
0
static int start(void *d) {
	plugin_data_t *data = d;
	cp_extension_t **exts;
	
	exts = cp_get_extensions_info(data->ctx, "symuser.strings", NULL, NULL);
	if (exts != NULL && exts[0] != NULL) {
		const char *symname;
		
		symname = cp_lookup_cfg_value(exts[0]->configuration, "@string-symbol");
		if (symname != NULL) {
			data->str = cp_resolve_symbol(data->ctx, exts[0]->plugin->identifier, symname, NULL);
			if (data->str == NULL) {
				cp_log(data->ctx, CP_LOG_ERROR, "Could not resolve symbol specified by extension.");
			}
		} else {
			cp_log(data->ctx, CP_LOG_ERROR, "No string-symbol attribute present in extension.");
		} 
	} else {
		cp_log(data->ctx, CP_LOG_ERROR, "No extensions available.");
	}
	if (exts != NULL) {
		cp_release_info(data->ctx, exts);
	}
	if (data->str == NULL) {
		return CP_ERR_RUNTIME;
	}
	return cp_define_symbol(data->ctx, "used_string", (void *) data->str);
}
Esempio n. 2
0
/* make a negative map-reply */
	int 
_request_reply_negative(void *data, struct communication_fct * fct, \
		struct db_node * rn, struct prefix * pf, uint32_t ttl, uint8_t A, uint8_t act,	uint8_t version ){
	
	struct pk_req_entry *pke = data;
	struct pk_rpl_entry *rpk;
	
	cp_log(LDEBUG, "Send Map-Reply to ITR\n");
		
	rpk = fct->reply_add(pke);
	if (rn){
		fct->reply_add_record(rpk, &rn->p, ttl, 0, version, A, act);
	}
	else if(pf) {
		fct->reply_add_record(rpk, pf, ttl, 0, version, A, act);
	}
	else {
		cp_log(LDEBUG, "Not process...ignore packet\n");		
		return (0);
	}
	
	fct->reply_terminate(rpk);
		
	return (TRUE);
}
Esempio n. 3
0
	int
show_site_info(void *data)
{
	struct site_info *site_data;
	site_data = (struct site_info *) data;
	cp_log(LLOG, "\nInformation of site: %s\n",site_data->name);
	cp_log(LLOG, "Key: %s\n",site_data->key);
	cp_log(LLOG, "Contact: %s\n",site_data->contact);
	cp_log(LLOG, "EID prefix number:: %d\n",site_data->eid->count);
	explore_list(site_data->eid, &show_eid_info);
	return 1;
}
Esempio n. 4
0
	void 
reconfigure(int signum){
	if (ms_db)
		ms_finish_db(ms_db);
	ms_db = ms_init_db();	
	printf("Init database ...\n\n");
	cp_log(LLOG, "Init database ...\n\n");
	site_db = list_init();	
	etr_db = list_init();
	printf("Parse main configuration file ...\n\n");
	cp_log(LLOG, "Parse main configuration file ...\n\n");
	_parser_config(config_file[0]);	
}
Esempio n. 5
0
	int
show_eid_info(void *data)
{
	struct db_node *eid_data;
	char buf[512];
	struct list_entry_t *p;
	struct site_info *site;
	assert(data);

	eid_data = (struct db_node *)data;
	bzero(buf, 512);
	inet_ntop(eid_data->p.family, (void *)&eid_data->p.u.prefix, buf, 512);
	site = NULL;
	if (eid_data->flags) {
		if (((struct mapping_flags *)eid_data->flags)->rsvd ) {
			p = (struct list_entry_t *)(((struct mapping_flags *)eid_data->flags)->rsvd);
			site = (struct site_info *)(p->data);
		}
	}
	else
		site = NULL;
	cp_log(LLOG, "EID prefix::%s/%d - belong to site: %s\n",
			buf, eid_data->p.prefixlen, (site)?site->name:" ");
	return 1;
}
Esempio n. 6
0
/* make a map-reply */
	int 
_request_reply(void *data, struct communication_fct * fct, \
		struct db_node * rn, struct prefix * pf){
	struct map_entry * e = NULL;
	struct list_entry_t * _iter;
	struct list_t * l = NULL;
	struct pk_rpl_entry *rpk;
	struct pk_req_entry *pke = data;
	struct list_t *overlap;
	struct list_entry_t *nptr;
	
	struct mapping_flags * mflags = (struct mapping_flags *)rn->flags;
	int pe=0;
	
	cp_log(LDEBUG, "Send Map-Reply to ITR\n");
		
	rpk = fct->reply_add(pke);
	
	/*PCD */
	overlap = list_init();
	ms_get_tree(rn,overlap,_MAPP|_MAPP_XTR);
	nptr = overlap->head.next;
	while(nptr != &overlap->tail){
		rn = (struct db_node *)nptr->data;
		/* get the RLOCs */
		l = (struct list_t *)db_node_get_info(rn);
		assert(l);
		_iter = l->head.next;
		pe = 0;
		if( (_fncs & (_FNC_XTR | _FNC_MS)) && lisp_te){
			while(_iter != &l->tail){
				e = (struct map_entry*)_iter->data;
				if(e->pe)
					pe += e->pe->count; 
				else 
					pe++;
				_iter = _iter->next;
			}
			fct->reply_add_record(rpk, &rn->p, mflags->ttl, pe, mflags->version, mflags->A, mflags->act);
		}
		else
			fct->reply_add_record(rpk, &rn->p, mflags->ttl, l->count, mflags->version, mflags->A, mflags->act);
		
		_iter = l->head.next;
		while(_iter != &l->tail){
			e = (struct map_entry*)_iter->data;

			fct->reply_add_locator(rpk, e);
			_iter = _iter->next;
		}
		nptr = nptr->next;
	}
	fct->reply_terminate(rpk);
	return TRUE;	
}
Esempio n. 7
0
static void logmsg_sev(cp_context_t *ctx, cp_log_severity_t severity, const char *msg) {
	struct log_info_t li = { -1, NULL, NULL };

	check(cp_register_logger(ctx, store_logger, &li, CP_LOG_DEBUG) == CP_OK);
	cp_log(ctx, severity, msg);
	check(li.severity == severity);
	check(li.msg != NULL && !strcmp(li.msg, msg));
	check(li.apid == NULL);
	free(li.msg);
	li.msg = NULL;
	cp_unregister_logger(ctx, store_logger);
}
Esempio n. 8
0
	struct db_table *
ms_get_db_table(const struct lisp_db *db, struct prefix *pf)
{
	assert(pf);
	if (pf->family == AF_INET) {
		return db->lisp_db4;
	}
	else if (pf->family == AF_INET6) {
		return db->lisp_db6;
	}
	cp_log(LDEBUG,"AF_NOT_SUPPORT\n");

	return NULL;
}
Esempio n. 9
0
complex cp_hat(complex x, complex y) {
    long i;
    complex logx;
    complex y_logx;
    complex c;
    if ((y.r == 2) && (y.i == 0)) {
        c = cp_mul(x, x);
        return c;
    }
    logx = cp_log(x);
    y_logx = cp_mul(y, logx);
    c = cp_exp(y_logx);
    return c;
}
Esempio n. 10
0
/**
 * Classifies a file based on file extension. This classifier uses extensions
 * installed at the file type extension point. Therefore we need pointer to
 * the plug-in context to access the extensions. A plug-in instance initializes
 * the classifier structure with the plug-in context pointer and registers a
 * virtual symbol pointing to the classifier.
 */
static int classify(void *d, const char *path) {
	cp_context_t *ctx = d;
	cp_extension_t **exts;
	const char *type = NULL;
	int i;

	// Go through all extensions registered at the extension point
	exts = cp_get_extensions_info(ctx, "org.c-pluff.examples.cpfile.extension.file-types", NULL, NULL);
	if (exts == NULL) {
		cp_log(ctx, CP_LOG_ERROR, "Could not resolve file type extensions.");
		return 0;
	}
	for (i = 0; type == NULL && exts[i] != NULL; i++) {
		int j;

		// Go through all file types provided by the extension
		for (j = 0; type == NULL && j < exts[i]->configuration->num_children; j++) {
			cp_cfg_element_t *elem = exts[i]->configuration->children + j;
			const char *desc = NULL;

			if (strcmp(elem->name, "file-type") == 0
				&& (desc = cp_lookup_cfg_value(elem, "@description")) != NULL
				&& (is_of_type(path, elem))) {
				type = desc;
			}
		}
	}

	// Release extension information
	cp_release_info(ctx, exts);

	// Print file type if recognized, otherwise try other classifiers
	if (type != NULL) {
		fputs(type, stdout);
		putchar('\n');
		return 1;
	} else {
		return 0;
	}
}
Esempio n. 11
0
	void
list_site(struct list_t *list)
{
	cp_log(LLOG, "\nSite number:: %d\n",list->count);
	explore_list(list, &show_site_info);
}
Esempio n. 12
0
	void
list_db(struct db_table *db)
{
	struct db_node *rn;
	static struct pool_node {
		int n_direct;
		struct db_node *link2node;
	} node_list[50000];
	char *sref[7];
	sref[1] = "NODE";
	sref[2] = "MS";
	sref[3] = "MS_ACK";
	sref[4] = "MS_NOT_REGISTERED";
	sref[5] = "DELEGATION_HOLE";
	sref[6] = "NOTE_AUTHORITATIVE";

	int i = 0;
	int j = 0;
	int k;
	int count_list = 0;
	int trdeep[MAX_NODES];
	assert(db);
	assert(db->top);

	rn = db->top;
	for (i = 0; i< MAX_NODES ;i++ ) {
		node_list[i].link2node = NULL;
	}

	node_list[count_list++].link2node = rn;
	node_list[count_list].n_direct = _CENTER;
	for (i = 0; i< MAX_NODES; i++)
		trdeep[i] = 0;

	trdeep[count_list] = 0;
	while (rn != NULL) {
		k = trdeep[j]+1;
		if (rn->l_left != NULL) {
			node_list[count_list].link2node = rn->l_left;
			node_list[count_list++].n_direct = _LEFT;
			trdeep[count_list]=k;
		}
		if (rn->l_right != NULL) {
			node_list[count_list].link2node = rn->l_right;
			node_list[count_list++].n_direct = _RIGHT;
			trdeep[count_list]=k;
		}
		rn = node_list[++j].link2node;
	}
	int deep = 0;
	int deep_avg = 0;
	for (i = 0; i < MAX_NODES; i++) {
		if (trdeep[i] > 0)
			deep_avg += trdeep[i];

		if (deep < trdeep[i])
			deep = trdeep[i];
	}
	cp_log(LDEBUG, "Max deep of tree::%d\n",deep);
	cp_log(LDEBUG, "Avg deep of tree::%d\n",deep_avg/count_list);
	cp_log(LDEBUG, "Number of Node::%d\n",count_list);

	char buf2[BSIZE];
	struct list_t *info2;
	char *s_direct;
	char refe[50];
	char buf[50];
	struct list_entry_t *rl;
	struct map_entry *e;

	for (j = 0; j < count_list ; j++ ) {
		rn = node_list[j].link2node;
		if (rn == db->top)
			s_direct = "ROOT";
		else
			s_direct = (node_list[j].n_direct == _LEFT ) ? "LEFT":"RIGHT";

		bzero(buf2, BSIZE);
		inet_ntop(rn->p.family, (void *)&rn->p.u.prefix, buf2, BSIZE);

		if (rn->flags && ((struct mapping_flags *)rn->flags)->referral) {
			sprintf(refe, "%s%s","Reference::",sref[((struct mapping_flags *)rn->flags)->referral]);
		}
		else
			sprintf(refe, "%s"," ");
		node_type2_str(rn, buf);

		cp_log(LLOG, "%d:: %s - %s/%d - %s - %s \n", j, s_direct, buf2, rn->p.prefixlen,buf, refe);
		if (ms_node_is_type(rn,_MAPP)) {
			assert(rn->info);
			info2 = (struct list_t *)rn->info;
			rl = info2->head.next;
			while (rl != &info2->tail) {
				char buf[BSIZE];
				bzero(buf, BSIZE);
				e = (struct map_entry *)rl->data;
				switch (e->rloc.sa.sa_family) {
					case AF_INET:
						inet_ntop(AF_INET, (void *)&e->rloc.sin.sin_addr, buf, BSIZE);
						break;
					case AF_INET6:
						inet_ntop(AF_INET6, (void *)&e->rloc.sin6.sin6_addr, buf, BSIZE);
						break;
					default:
						cp_log(LDEBUG, "unsuported family\n");
						continue;
				}
				cp_log(LDEBUG, "\t[rloc=%s, priority=%u, weight=%u, m_priority=%u, m_weight=%u, r=%d]\n", \
					buf, \
					e->priority, \
					e->weight, \
					e->m_priority, \
					e->m_weight, \
					e->r);
				rl = rl->next;
			}
		}
	}
}
Esempio n. 13
0
/* processing with map-request - only MS|NODE|MR function*/
	int 
generic_process_request(void *data, struct communication_fct * fct){
	struct db_table * table;
	struct db_node * rn = NULL;
	struct prefix p;
	int is_ddt;
	struct db_node *node = NULL;	
	int rt;
	struct pk_req_entry *pke = data;
		
	/* look for the eid */
	fct->request_get_eid(pke, &p);
	table = ms_get_db_table(ms_db,&p);
	rn = db_node_match_prefix(table, &p);
			
	fct->request_is_ddt(pke, &is_ddt);

	/* Received DDT request */
	if(is_ddt){
		/*function of {map-register-with-DDT|DDT-node}*/
		if(!rn){
			/*If the requested XEID did not match either a configured delegation or
				an authoritative XEID-prefix, then the request is dropped and a
				negative Map-Referral with action code NOT-AUTHORITATIVE is returned.
			*/	
			if(_fncs & _FNC_NODE){
				rt =  _request_referral_negative(pke, fct, node, &p, 0, 0, LISP_REFERRAL_NOT_AUTHORITATIVE, 0, 1);
				
			}				
			return (TRUE);
		}
		node = rn;
		if( !rn->flags || !((struct mapping_flags *)rn->flags)->range){
			node = ms_get_target(rn);
		}
		
		/* existing mapping for request */	
		if (ms_node_is_type(node, _MAPP)){
			/* not referral node, it must belong to MS */			
			if( !((struct mapping_flags *)node->flags)->referral){
				/* do ms function: reply or foward to ETR */
				if(_fncs & _FNC_MS){
					if(ms_node_is_proxy_reply(node)){
						rt = _request_reply(pke, fct, node, NULL);
						
						return (TRUE);
					}
					
					cp_log(LDEBUG, "Forwarding to ETR\n");
						
					_request_referral(pke, fct, node);
					
					rt = _forward_to_etr(pke,node);	
						
					return (TRUE);
				}
				/*it not be here: it is not MS but is has normal mapping */
				return FALSE;
			}
			
			/* referral node, must belong to NODE or MR*/
			if ( _fncs & _FNC_NODE){
				/*Auth EID referral - return with map-referral*/				
				if( ((struct mapping_flags *)node->flags)->A ){					
					rt =  _request_referral(pke, fct, node);	
					return (TRUE);
				}else{
					while(node != table->top && 
							(!node->flags ||
							!((struct mapping_flags *)node->flags)->A))
						node = node->parent;			
					if(node == table->top){
						rt =  _request_referral_negative(pke, fct, node, &p, 0, 0, LISP_REFERRAL_NOT_AUTHORITATIVE, 0, 1);					
						return TRUE;
					}
					rt =  _request_referral(pke, fct, node);
					return TRUE;
				}				
			}
		}
		else{//not exist mapping
			if ( _fncs & _FNC_MS || _fncs & _FNC_NODE){
				/* node has type */
				while (node != table->top && 
						( !node->flags || 
						!( ((struct mapping_flags *)node->flags)->range & (_EID | _GEID | _GREID)) ))
					node = node->parent;
				
				if(node == table->top){
					rt =  _request_referral_negative(pke, fct, node, &p, 0, 0, LISP_REFERRAL_NOT_AUTHORITATIVE, 0, 1);
					return TRUE;
				}else{
					switch (((struct mapping_flags *)node->flags)->range){
						case _EID: /* EID not is registered */
							if ( _fncs & _FNC_MS){
								rt =  _request_referral_negative(pke, fct, node, &p, 60, 1, LISP_REFERRAL_MS_NOT_REGISTERED, 0, 1);	
								return TRUE;
							}
							break;
						case _GEID:/* EID not assign for any ETR */
							if ( _fncs & _FNC_MS){
								/* in ieft, this case is same as _EID, but it think TTL must longer*/
								rt =  _request_referral_negative(pke, fct, node, &p, 900, 1, LISP_REFERRAL_MS_NOT_REGISTERED, 0, 1);	
								return TRUE;
							}	
							break;
						case _GREID:/* EID not delegated */
							if ( _fncs & _FNC_NODE){
								rt = _request_referral_negative(pke, fct, rn, &p, 60, 0, LISP_REFERRAL_DELEGATION_HOLE,0, 1 );		
								return TRUE;	
							}
							break;						
					}
					/*can not here or database has problem */
					return FALSE;
				}
			}
		}	
		cp_log(LDEBUG, "Not process...ignore packet\n");
		return FALSE;
	}
	/* Received non DDT request */
	else{
		/*function of {map-resolver |map-register-with-no-DDD-function} */
		node = rn;		
		if(!(rn->flags) || !((struct mapping_flags *)rn->flags)->range){
			node = ms_get_target(rn);
		}
		
		if ( ms_node_is_type(node, _MAPP)){
			/* node is MAPP, must belong to MS */
			if( !ms_node_is_referral(node)){
				if(_fncs & _FNC_MS){
					if(ms_node_is_proxy_reply(node)){
						rt = _request_reply(pke, fct, node, NULL);
																	
						return rt;
					}
					else{
						cp_log(LDEBUG, "Forwarding to ETR\n");
						
						rt = _forward_to_etr(pke,node);							
						return rt;	
					}				
				}
				return FALSE;
			}
			else{
				/* do MR function */
				if(_fncs & _FNC_MR){
					pending_request(pke, fct, node);					
					return 1;
				}
			}
		}
		else{/*node is not mapping */
			while (node != table->top && 
						( !node->flags || 
						!( ((struct mapping_flags *)node->flags)->range & (_EID | _GEID)) ))
				node = node->parent;
			if(_fncs & _FNC_MS){
				if(node == table->top)
					return FALSE;
				if ( ms_node_is_type(node,_EID))
					rt = _request_reply_negative(pke, fct, node, &p, 60, 1, 1, 0);	
				else
					rt = _request_reply_negative(pke, fct, node, &p, 900, 1, 1, 0);	
				return TRUE;					
			}
			if(_fncs & _FNC_MR){
				pending_request(pke, fct, node);					
				return TRUE;
			}
		}	
	}
	cp_log(LDEBUG, "Not process...ignore packet\n");
	return FALSE;			
}