WTP can join w/o any memory leaks

This commit is contained in:
2022-08-15 16:31:26 +02:00
parent df5e2bcbb7
commit a051ba41de
17 changed files with 119 additions and 99 deletions

View File

@ -110,7 +110,7 @@ static struct cw_DiscoveryResults * run_discovery(struct cw_Conn *conn)
//cw_select_ac(conn->local_cfg, dis);
mavliter_t it;
/* mavliter_t it;
mavliter_init(&it,results->list);
mavliter_foreach(&it){
const char * acname;
@ -119,7 +119,7 @@ static struct cw_DiscoveryResults * run_discovery(struct cw_Conn *conn)
printf("E: %s: %s - prio: %d, ctr: %d\n",acname,e->ip,e->prio,e->ctr);
}
*/
return results;
}

View File

@ -98,7 +98,7 @@ acinfo.result_code=99;
int run_join_d(struct cw_Conn * conn, struct sockaddr *sa)
static int run_join_d(struct cw_Conn * conn, struct sockaddr *sa,cw_Cfg_t * cfg)
{
char addrstr[SOCK_ADDR_BUFSIZE];
int sockfd;
@ -107,8 +107,8 @@ int run_join_d(struct cw_Conn * conn, struct sockaddr *sa)
int rc;
/* Check if we support the same auth methods as the AC */
lsec = cw_ktv_get_byte(conn->local_cfg,"ac-descriptor/security",0);
rsec = cw_ktv_get_byte(conn->remote_cfg,"ac-descriptor/security",0);
lsec = cw_cfg_get_byte(conn->global_cfg,"ac-descriptor/security",255);
rsec = cw_cfg_get_byte(cfg,"ac-descriptor/security",0);
if ((lsec & rsec) == 0){
cw_log(LOG_ERR, "Can't establish DTLS with AC, my sec: %d, remote sec %d",lsec,rsec);
return 0;
@ -154,8 +154,9 @@ int run_join_d(struct cw_Conn * conn, struct sockaddr *sa)
cw_dbg(DBG_DTLS, "DTLS Connection successful established with %s",
sock_addr2str(sa,addrstr));
conn->remote_cfg=cfg;
run_join(conn);
conn->remote_cfg=NULL;
return 1;
}
@ -199,8 +200,26 @@ int run_join(struct cw_Conn *conn)
return 1;
}
int join(struct cw_Conn * conn, struct cw_DiscoveryResults * dis)
int join(struct cw_Conn * conn, struct cw_DiscoveryResults * results)
{
int rc;
mavliter_t it;
mavliter_init(&it,results->list);
mavliter_foreach(&it){
struct sockaddr_storage sockaddr;
const char * acname;
struct cw_DiscoveryResults_elem *e = mavliter_get(&it);
acname = cw_cfg_get(e->cfg,"capwap/ac-name","<unknown>");
cw_dbg(DBG_INFO, "Going to join CAPWAP controller '%s' at %s.",acname,e->ip);
sock_strtoaddr(e->ip,(struct sockaddr*)(&sockaddr));
sock_setport((struct sockaddr*)&sockaddr,5246);
rc = run_join_d(conn,(struct sockaddr*)(&sockaddr),e->cfg);
if (rc)
return 1;
}
stop();
/*

View File

@ -182,43 +182,17 @@ int main (int argc, char **argv)
// cw_run_discovery(conn, "192.168.0.255","192.168.0.14", &dis);
results = cw_run_discovery(conn, "255.255.255.255","192.168.0.14");
// mavl_del_all(conn->remote_cfg);
join(conn,results);
cw_discovery_results_destroy(results);
rc = 0;
printf("Goto errx 0");
goto errX;
//cw_dbg_ktv_dump(dis.prio_ip, DBG_INFO, "=== IP list ===", "IP", "=== END IP List ===");
/*
{
mavliter_t i;
mavliter_init(&i, dis.prio_ip);
mavliter_foreach(&i) {
char ipstr[100];
char *rk;
cw_Val_t *val;
mavl_t cfg;
val = mavliter_get(&i);
rk = val->key;
val = val->val.ptr;
val->type->to_str(val, ipstr, 100);
printf("PTRVAL(%s): %s - %s\n", rk, val->key, ipstr);
cfg = cw_ktv_get_sysptr(dis.prio_ac,rk,NULL);
cw_dbg_ktv_dump(cfg,DBG_INFO,"----- dump of remote","dmp","endof of remote -------");
}
}
*/
mavl_del_all(conn->remote_cfg);
printf("JOIN\n");
// join(conn,&dis);
clean_cfg(conn->remote_cfg);
mavl_merge(conn->local_cfg,conn->remote_cfg);
// clean_cfg(conn->remote_cfg);
// mavl_merge(conn->local_cfg,conn->remote_cfg);
mavl_del_all(conn->remote_cfg);
printf("JOIN CONF\n");