Exemplo n.º 1
0
cw_aciplist_t get_aciplist()
{
    int i=0;

    cw_aciplist_t aciplist = cw_aciplist_create();

    if(!aciplist)
        return 0;


    for (i=0; i<socklist_len; i++) {

        if (socklist[i].type != SOCKLIST_UNICAST_SOCKET)
            break;

        struct sockaddr_storage sa;
        unsigned int salen=sizeof(sa);
        if ( getsockname(socklist[i].sockfd,(struct sockaddr*)&sa,&salen)<0)
            continue;

        cw_acip_t * acip;
        acip = malloc(sizeof(cw_acip_t));
        if (!acip)
            continue;

        sock_copyaddr(&acip->ip,(struct sockaddr*)&sa);
        if (acip->ip.ss_family == AF_INET)
            acip->wtp_count=11;
        else
            acip->wtp_count=3;


//		printf ("Adding IP %s\n",sock_addr2str(&acip->ip));

        cw_aciplist_add(aciplist,acip);


    }
    return aciplist;
}
Exemplo n.º 2
0
cw_aciplist_t cw_select_ac(struct conn *conn, mbag_t discs)
{

	/* create a list for results */
	cw_aciplist_t resultlist=cw_aciplist_create();
	if (!resultlist)
		return NULL;
	if (!discs)
		return resultlist;

/*
	cw_aciplist_t aciplist = cw_aciplist_create();
	if (!aciplist) {
		cw_log(LOG_ERROR, "Can't allocate aciplist");
		return NULL;
	}

*/

	/* get the AC Name with Priority list */
	cw_acpriolist_t priolist;
	priolist = mbag_get_mavl(conn->config, CW_ITEM_AC_NAME_WITH_PRIORITY);
	if (!priolist )
		priolist=cw_acpriolist_create();


	/* for each discovery reponse */
	DEFINE_AVLITER(i, discs);
	avliter_foreach(&i){

		mbag_t ac = ((mbag_item_t *) (avliter_get(&i)))->data;

		/* get the ac name */
		char *ac_name = mbag_get_str(ac, CW_ITEM_AC_NAME,NULL);
		int prio = 256;

		if (ac_name) {
			/* See if we can find AC Name in Priority List */
			if (priolist)
				prio = cw_acpriolist_get(priolist, ac_name);
		}

		/* get the IP list, the current AC has sent */
		cw_aciplist_t acips =
		    mbag_get_mavl(ac, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST);

		if (!acips)
			continue;

		/* for each IP from the current AC add it to the result list
		 * and give it the priority whe have determined */
		DEFINE_AVLITER(i2, acips);
		avliter_foreach(&i2){


			cw_acip_t *acip = avliter_get(&i2);

			cw_acip_t *n = malloc(sizeof(cw_acip_t));
			memcpy(n,acip,sizeof(cw_acip_t));
		
			/* we missuse the wtp_count to sort by 
			 * priority and wp_count */	
			n->wtp_count |= prio<<16; 

			cw_aciplist_del(resultlist,n);
			cw_aciplist_add(resultlist,n);
		}

	}

	return resultlist;
}