WTP can join w/o any memory leaks
This commit is contained in:
parent
df5e2bcbb7
commit
a051ba41de
11
src/cw/cfg.c
11
src/cw/cfg.c
@ -544,6 +544,17 @@ uint8_t cw_cfg_get_byte(cw_Cfg_t * cfg, char *key, uint8_t def)
|
||||
return v.val.byte;
|
||||
}
|
||||
|
||||
uint8_t cw_cfg_get_byte_l(cw_Cfg_t ** cfgs, char *key, uint8_t def)
|
||||
{
|
||||
struct cw_Val v;
|
||||
memset(&v,0,sizeof(struct cw_Val));
|
||||
const char *s = cw_cfg_get_l(cfgs,key,NULL);
|
||||
if (s==NULL)
|
||||
return def;
|
||||
CW_TYPE_BYTE->from_str(&v,s);
|
||||
return v.val.byte;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t cw_cfg_get_word(cw_Cfg_t * cfg, char *key, uint16_t def)
|
||||
|
@ -43,6 +43,7 @@ void cw_cfg_copy(cw_Cfg_t *src, cw_Cfg_t *dst);
|
||||
void cw_cfg_destroy(cw_Cfg_t *cfg);
|
||||
void cw_cfg_clear(cw_Cfg_t *cfg);
|
||||
int cw_cfg_base_exists(cw_Cfg_t * cfg, const char *key);
|
||||
uint8_t cw_cfg_get_byte_l(cw_Cfg_t ** cfgs, char *key, uint8_t def);
|
||||
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "msgset.h"
|
||||
#include "mavltypes.h"
|
||||
|
||||
|
||||
#include "dtls.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -937,6 +937,7 @@ int cw_read_messages(struct cw_Conn *conn)
|
||||
*/
|
||||
void conn_destroy(struct cw_Conn * conn)
|
||||
{
|
||||
dtls_shutdown(conn);
|
||||
if (conn->fragman)
|
||||
fragman_destroy(conn->fragman);
|
||||
if (conn->q)
|
||||
@ -954,6 +955,8 @@ void conn_destroy(struct cw_Conn * conn)
|
||||
if (conn->local_cfg)
|
||||
cw_cfg_destroy(conn->local_cfg);
|
||||
|
||||
|
||||
|
||||
free(conn);
|
||||
}
|
||||
|
||||
|
@ -127,6 +127,11 @@ static int bread(cw_Cfg_t *cfg, const char * key, const uint8_t *src, int len, c
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int bwrite(cw_Cfg_t ** cfgs, const char *key, uint8_t *dst, const void * param)
|
||||
{
|
||||
return cw_generic_write_l(cfgs,CW_TYPE_IPADDRESS,key,dst,param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const struct cw_Type cw_type_ipaddress = {
|
||||
@ -141,6 +146,7 @@ const struct cw_Type cw_type_ipaddress = {
|
||||
get_type_name,
|
||||
NULL,
|
||||
bread,
|
||||
bwrite,
|
||||
|
||||
};
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#define dtls_connect dtls_openssl_connect
|
||||
#define dtls_shutdown dtls_openssl_shutdown
|
||||
#define dtls_get_cipher dtls_openssl_get_cipher
|
||||
#define dtls_data_destroy dtls_openssl_data_destroy
|
||||
#else
|
||||
#include "dtls_gnutls.h"
|
||||
#define dtls_init dtls_gnutls_init
|
||||
|
@ -207,11 +207,14 @@ void dtls_openssl_data_destroy(struct dtls_openssl_data * d){
|
||||
if (!d)
|
||||
return;
|
||||
|
||||
if (d->ctx)
|
||||
SSL_CTX_free(d->ctx);
|
||||
|
||||
if (d->ssl)
|
||||
SSL_free(d->ssl);
|
||||
|
||||
if (d->ctx)
|
||||
SSL_CTX_free(d->ctx);
|
||||
if (d->biomethod)
|
||||
BIO_meth_free(d->biomethod);
|
||||
|
||||
|
||||
free(d);
|
||||
|
@ -38,6 +38,7 @@ struct dtls_openssl_data{
|
||||
SSL_CTX * ctx;
|
||||
SSL * ssl;
|
||||
BIO * bio;
|
||||
BIO_METHOD * biomethod;
|
||||
uint8_t buffer[4096];
|
||||
int len;
|
||||
int pos;
|
||||
@ -78,6 +79,7 @@ extern int dtls_openssl_log_error_queue(const char *txt);
|
||||
extern BIO_METHOD * dtls_openssl_bio_method();
|
||||
|
||||
extern int dtls_openssl_shutdown(struct cw_Conn *conn);
|
||||
extern void dtls_openssl_data_destroy(struct dtls_openssl_data * d);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
@ -49,12 +49,15 @@ dtls_openssl_connect(struct cw_Conn *conn)
|
||||
dtls_openssl_data_create(conn, DTLS_client_method(),
|
||||
biomethod);
|
||||
|
||||
|
||||
cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 2");
|
||||
|
||||
d = (struct dtls_openssl_data *) conn->dtls_data;
|
||||
if (!d)
|
||||
return 0;
|
||||
|
||||
d->biomethod = biomethod;
|
||||
|
||||
/*
|
||||
if (conn->dtls_psk)
|
||||
SSL_set_psk_client_callback(d->ssl, psk_client_cb);
|
||||
|
@ -7,20 +7,19 @@
|
||||
#include "cw/cw.h"
|
||||
#include "cw/dbg.h"
|
||||
|
||||
static int write_boarddata_subelem(uint8_t * dst, mavl_t ktv, const char * parent_key,
|
||||
const char *skey, int type){
|
||||
static int write_boarddata_subelem(uint8_t * dst, cw_Cfg_t ** cfg, const char * parent_key,
|
||||
const char *skey, int type, void *param){
|
||||
|
||||
char key[256];
|
||||
cw_Val_t * val;
|
||||
uint8_t *d;
|
||||
|
||||
d=dst;
|
||||
char key[CW_CFG_MAX_KEY_LEN];
|
||||
int len;
|
||||
|
||||
sprintf(key,"%s/%s",parent_key,skey);
|
||||
|
||||
val = cw_ktv_get(ktv,key,CW_TYPE_BSTR16);
|
||||
//val = cw_ktv_get(ktv,key,CW_TYPE_BSTR16);
|
||||
len = cw_generic_write_l(cfg, CW_TYPE_BSTR16,key,
|
||||
dst+4, param);
|
||||
|
||||
if (val == NULL) {
|
||||
if (len==-1) {
|
||||
cw_log(LOG_ERR,
|
||||
"Creating WTP Board Data sub-element %d. Key not '%s' found",type,key);
|
||||
return 0;
|
||||
@ -28,11 +27,9 @@ static int write_boarddata_subelem(uint8_t * dst, mavl_t ktv, const char * paren
|
||||
|
||||
|
||||
|
||||
d += cw_put_word(d, type);
|
||||
d += cw_put_word(d, val->type->len(val));
|
||||
d += val->type->put(val,d);
|
||||
|
||||
return d-dst;
|
||||
cw_set_word(dst, (uint16_t)type);
|
||||
cw_set_word(dst+2,(uint16_t)len);
|
||||
return len+4;
|
||||
}
|
||||
|
||||
|
||||
@ -40,35 +37,31 @@ static int write_boarddata_subelem(uint8_t * dst, mavl_t ktv, const char * paren
|
||||
int capwap_out_wtp_board_data(struct cw_ElemHandler * eh,
|
||||
struct cw_ElemHandlerParams * params, uint8_t * dst)
|
||||
{
|
||||
stop();
|
||||
|
||||
cw_Val_t * val;
|
||||
mavl_t cfg;
|
||||
int rc;
|
||||
uint8_t * d;
|
||||
char key[256];
|
||||
int l;
|
||||
|
||||
d=dst+4;
|
||||
|
||||
cfg = params->cfg;
|
||||
|
||||
sprintf(key,"%s/%s",eh->key,CW_SKEY_VENDOR);
|
||||
val = cw_ktv_get(cfg,key,CW_TYPE_DWORD);
|
||||
rc = cw_generic_write_l(params->cfg_list, CW_TYPE_DWORD,key,
|
||||
d, eh->param);
|
||||
|
||||
|
||||
if (val ==NULL) {
|
||||
if (rc==-1) {
|
||||
cw_log(LOG_ERR,
|
||||
"Creating WTP Board Data element. Key '%s' not found.", key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
d += val->type->put(val,d);
|
||||
/*cw_ktv_add(cfg,vendor_key,CW_TYPE_DWORD,data,len);*/
|
||||
d += rc;
|
||||
|
||||
d+=write_boarddata_subelem(d,cfg,eh->key,"model-no",CW_BOARDDATA_MODELNO);
|
||||
d+=write_boarddata_subelem(d,cfg,eh->key,"serial-no",CW_BOARDDATA_SERIALNO);
|
||||
d+=write_boarddata_subelem(d,cfg,eh->key,"board-id",CW_BOARDDATA_BOARDID);
|
||||
d+=write_boarddata_subelem(d,cfg,eh->key,"revision",CW_BOARDDATA_REVISION);
|
||||
d+=write_boarddata_subelem(d,cfg,eh->key,"mac-address",CW_BOARDDATA_MACADDRESS);
|
||||
d+=write_boarddata_subelem(d,params->cfg_list,eh->key,"model-no",CW_BOARDDATA_MODELNO,eh->param);
|
||||
d+=write_boarddata_subelem(d,params->cfg_list,eh->key,"serial-no",CW_BOARDDATA_SERIALNO,eh->param);
|
||||
d+=write_boarddata_subelem(d,params->cfg_list,eh->key,"board-id",CW_BOARDDATA_BOARDID,eh->param);
|
||||
d+=write_boarddata_subelem(d,params->cfg_list,eh->key,"revision",CW_BOARDDATA_REVISION,eh->param);
|
||||
d+=write_boarddata_subelem(d,params->cfg_list,eh->key,"mac-address",CW_BOARDDATA_MACADDRESS,eh->param);
|
||||
|
||||
|
||||
l = d - dst-4;
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
static int cw_put_encryption_subelems(uint8_t *dst,int capwap_mode)
|
||||
{
|
||||
stop();
|
||||
|
||||
int n=2;
|
||||
int i;
|
||||
|
||||
@ -33,27 +31,21 @@ int capwap_out_wtp_descriptor(struct cw_ElemHandler * eh,
|
||||
int len,l;
|
||||
/* // XXX Dummy WTP Descriptor Header */
|
||||
uint8_t *d;
|
||||
cw_Val_t * val;
|
||||
int val;
|
||||
|
||||
d = dst+4;
|
||||
|
||||
sprintf(key,"%s/%s",eh->key,CW_SKEY_MAX_RADIOS);
|
||||
val = cw_ktv_get(params->cfg,key, CW_TYPE_BYTE);
|
||||
if (val != NULL)
|
||||
d+=val->type->put(val,d);
|
||||
else{
|
||||
cw_dbg(DBG_WARN,"Cannot get value for %s, setting to 0", CW_SKEY_MAX_RADIOS);
|
||||
val = cw_cfg_get_byte_l(params->cfg_list,key, 0);
|
||||
d+=cw_put_byte(d,val);
|
||||
if (val<=0){
|
||||
cw_dbg(DBG_WARN,"Cannot value for %s, setting to 0", CW_SKEY_MAX_RADIOS);
|
||||
d+=cw_put_byte(d,0);
|
||||
}
|
||||
|
||||
sprintf(key,"%s/%s",eh->key,CW_SKEY_RADIOS_IN_USE);
|
||||
val = cw_ktv_get(params->cfg,key, CW_TYPE_BYTE);
|
||||
if (val != NULL){
|
||||
d+=val->type->put(val,d);
|
||||
}
|
||||
else{
|
||||
d+=cw_put_byte(d,0); /*radios in use*/
|
||||
}
|
||||
val = cw_cfg_get_byte_l(params->cfg_list,key, 0);
|
||||
d+=cw_put_byte(d,val); /*radios in use*/
|
||||
|
||||
/* d+=cw_put_encryption_capabilities_7(d,1); */
|
||||
/* d+=cw_put_encryption_subelems(d,params->conn->capwap_mode);*/
|
||||
@ -80,6 +72,6 @@ int capwap_out_wtp_descriptor(struct cw_ElemHandler * eh,
|
||||
len = d-dst-4;
|
||||
l = len + cw_put_elem_hdr(dst,eh->id,len);
|
||||
|
||||
cw_dbg_elem(DBG_ELEM_OUT,NULL,params->msgdata->type,eh,dst,l);
|
||||
// cw_dbg_elem(DBG_ELEM_OUT,NULL,params->msgdata->type,eh,dst,l);
|
||||
return l;
|
||||
}
|
||||
|
@ -866,7 +866,7 @@ static struct cw_ElemHandler handlers70[] = {
|
||||
CW_TYPE_STRUCT, /* type */
|
||||
"cisco/mwar-addr", /* Key */
|
||||
cw_in_generic, /* get */
|
||||
cw_out_generic_struct, /* put */
|
||||
cw_out_generic, /* put */
|
||||
NULL,
|
||||
NULL,
|
||||
mwar_addr
|
||||
@ -2352,16 +2352,27 @@ static int postprocess_join_request(struct cw_ElemHandlerParams * params, uint8_
|
||||
|
||||
static int preprocess_join_request(struct cw_Conn *conn)
|
||||
{
|
||||
cw_Val_t * ver;
|
||||
bstr16_t ver;
|
||||
int use_ac_version;
|
||||
char verstr[512];
|
||||
|
||||
if (conn->role != CW_ROLE_WTP)
|
||||
return 0;
|
||||
|
||||
stop();
|
||||
use_ac_version = cw_cfg_get_bool(conn->global_cfg,"cisco/wtp-use-ac-version",0);
|
||||
if (use_ac_version){
|
||||
ver = cw_cfg_get_bstr16(conn->remote_cfg,"ac-descriptor/software/version",NULL );
|
||||
cw_cfg_set_bstr16(conn->local_cfg,"wtp-descriptor/software/version",ver);
|
||||
|
||||
cw_format_version(verstr,bstr16_data(ver),bstr16_len(ver));
|
||||
cw_dbg(DBG_INFO, "Cisco WTP - Using AC's software version: %s", verstr);
|
||||
free(ver);
|
||||
|
||||
}
|
||||
|
||||
// stop();
|
||||
|
||||
/*
|
||||
use_ac_version = cw_ktv_get_bool(conn->local_cfg,"cisco/wtp-use-ac-version",0);
|
||||
|
||||
if (use_ac_version){
|
||||
ver = cw_ktv_get(conn->remote_cfg,"ac-descriptor/software/version", CW_TYPE_BSTR16);
|
||||
|
@ -8,15 +8,18 @@
|
||||
int cisco_out_capwap_local_ip_address(struct cw_ElemHandler * eh,
|
||||
struct cw_ElemHandlerParams * params, uint8_t * dst)
|
||||
{
|
||||
stop();
|
||||
|
||||
cw_Val_t * ip;
|
||||
ip = cw_ktv_get(params->cfg,eh->key,CW_TYPE_IPADDRESS);
|
||||
if (ip==NULL){
|
||||
const char * ipstr;
|
||||
int rc;
|
||||
cw_Val_t ip;
|
||||
ipstr = cw_cfg_get_l(params->cfg_list,eh->key,NULL);
|
||||
if (ipstr==NULL){
|
||||
return 0;
|
||||
}
|
||||
return cw_put_local_ip_address(dst,eh->id,
|
||||
CW_TYPE_IPADDRESS->from_str(&ip,ipstr);
|
||||
rc= cw_put_local_ip_address(dst,eh->id,
|
||||
CAPWAP_ELEM_WTP_IPV4_IP_ADDRESS,
|
||||
CAPWAP_ELEM_WTP_IPV6_IP_ADDRESS,
|
||||
ip->type->data(ip),ip->type->len(ip));
|
||||
ip.type->data(&ip),ip.type->len(&ip));
|
||||
ip.type->del(&ip);
|
||||
return rc;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ int cisco_out_wtp_descriptor(struct cw_ElemHandler * eh,
|
||||
struct cw_ElemHandlerParams * params, uint8_t * dst)
|
||||
{
|
||||
|
||||
|
||||
char key[CW_CFG_MAX_KEY_LEN];
|
||||
int len;
|
||||
/* // XXX Dummy WTP Descriptor Header */
|
||||
|
@ -240,7 +240,6 @@ int static setup_cfg(struct cw_Conn * conn)
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
/*
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user