WTP can run discoveryw/o memory leaks
This commit is contained in:
parent
daa808f9a2
commit
df5e2bcbb7
@ -6,6 +6,7 @@
|
||||
#
|
||||
#capwap/ac-name
|
||||
#
|
||||
capwap/ac-name: actube
|
||||
|
||||
capwap/ssl-cipher: DHE-RSA:RSA:AES-256-CBC:AES-128-CBC:SHA1:PSK
|
||||
capwap/ssl-psk-enable: false
|
||||
|
@ -364,7 +364,7 @@ static void *wtpman_main(void *arg)
|
||||
|
||||
tmp = conn->local_cfg;
|
||||
|
||||
mavl_merge(conn->default_cfg, conn->local_cfg);
|
||||
/* mavl_merge(conn->default_cfg, conn->local_cfg);*/
|
||||
/* mavl_merge(conn->default_cfg, conn->remote_cfg);*/
|
||||
|
||||
conn->local_cfg = conn->update_cfg;
|
||||
|
@ -202,7 +202,9 @@ MISCSRC=\
|
||||
strheap.c\
|
||||
netconn.c\
|
||||
conn.c \
|
||||
val.c
|
||||
val.c \
|
||||
discovery.c\
|
||||
|
||||
|
||||
# conn_q_wait_packet.c\
|
||||
# conn_init.c\
|
||||
|
@ -625,6 +625,9 @@ int cw_cfg_set_val(cw_Cfg_t * cfg, const char *key, const struct cw_Type *type,
|
||||
return 1;
|
||||
}
|
||||
|
||||
//int cw_cfg_put(cw_Cfg_t *cfg, const char *key, const struct cw_Type *type,const void
|
||||
|
||||
|
||||
|
||||
void cw_cfg_copy(cw_Cfg_t *src, cw_Cfg_t *dst)
|
||||
{
|
||||
|
@ -155,6 +155,7 @@ int cw_assemble_message(struct cw_Conn *conn, uint8_t * rawout)
|
||||
|
||||
|
||||
cw_decode_elements( ¶ms, elems_ptr,elems_len);
|
||||
cw_cfg_destroy(cfg);
|
||||
|
||||
printf ("----------------------------------- end redecode -----------------------------\n");
|
||||
|
||||
@ -459,20 +460,6 @@ int cw_in_check_generic(struct cw_Conn *conn, struct cw_action_in *a, uint8_t *
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void cw_read_elem(struct cw_ElemHandler * handler, struct cw_Conn * conn,
|
||||
uint8_t * elem_data, int elem_len, struct sockaddr * from){
|
||||
mavldata_t data, *result;
|
||||
char str[30];
|
||||
|
||||
result = handler->type->get(&data,elem_data,elem_len);
|
||||
|
||||
handler->type->to_str(result,str,30);
|
||||
printf("Read %d-%s: %s %s\n", handler->id, handler->name, handler->key, str);
|
||||
//mavl_insert(conn->remote_cfg
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
|
||||
struct sockaddr *from)
|
||||
@ -638,7 +625,7 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
|
||||
cw_dbg(DBG_MSG_PARSING, "*** Parsing message of type %d - (%s) ***",
|
||||
message->type, message->name);
|
||||
|
||||
params.cfg = cw_cfg_create(); //conn->remote_cfg;
|
||||
params.cfg = cw_cfg_create();
|
||||
params.cfg_list[0]=params.cfg;
|
||||
params.cfg_list[1]=conn->local_cfg;
|
||||
params.cfg_list[2]=conn->global_cfg;
|
||||
@ -705,7 +692,10 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
|
||||
* Put further actions here, if needed.
|
||||
*/
|
||||
}
|
||||
|
||||
mlist_destroy(unrecognized);
|
||||
cw_cfg_destroy(params.cfg);
|
||||
conn->remote_cfg=NULL;
|
||||
|
||||
return result_code;
|
||||
|
||||
@ -955,6 +945,15 @@ void conn_destroy(struct cw_Conn * conn)
|
||||
if (conn->msg_callbacks)
|
||||
mavl_destroy(conn->msg_callbacks);
|
||||
|
||||
if (conn->base_rmac)
|
||||
free(conn->base_rmac);
|
||||
|
||||
if (conn->remote_cfg)
|
||||
cw_cfg_destroy(conn->remote_cfg);
|
||||
|
||||
if (conn->local_cfg)
|
||||
cw_cfg_destroy(conn->local_cfg);
|
||||
|
||||
free(conn);
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ struct cw_Conn {
|
||||
|
||||
|
||||
mavl_t remote_cfg;
|
||||
mavl_t default_cfg;
|
||||
// mavl_t default_cfg;
|
||||
mavl_t update_cfg;
|
||||
mavl_t local_cfg;
|
||||
mavl_t global_cfg;
|
||||
|
@ -38,7 +38,7 @@ int cw_read_wtp_descriptor(mavl_t cfg, struct cw_Conn *conn,
|
||||
"Non standard conform WTP Descriptor, number of encryptoin elements is 0.");
|
||||
}
|
||||
|
||||
sprintf(key,"%s/%s",eh->key, CW_SKEY_MAX_RADIOS);
|
||||
sprintf(key,"%s/%s",eh->key, "max-radios");
|
||||
cw_ktv_add(cfg,key,CW_TYPE_BYTE,NULL,data,1);
|
||||
|
||||
sprintf(key,"%s/%s",eh->key, CW_SKEY_RADIOS_IN_USE);
|
||||
|
@ -29,7 +29,7 @@ int cw_read_wtp_descriptor_7(mavl_t cfg, struct cw_Conn *conn,
|
||||
int pos;
|
||||
char key[64];
|
||||
|
||||
sprintf(key,"%s/%s",eh->key, CW_SKEY_MAX_RADIOS);
|
||||
sprintf(key,"%s/%s",eh->key, "max-radios");
|
||||
cw_cfg_set_int(cfg,key,cw_get_byte(data));
|
||||
|
||||
sprintf(key,"%s/%s",eh->key, CW_SKEY_RADIOS_IN_USE);
|
||||
|
120
src/cw/discovery.c
Normal file
120
src/cw/discovery.c
Normal file
@ -0,0 +1,120 @@
|
||||
|
||||
#include "discovery.h"
|
||||
|
||||
#include "dbg.h"
|
||||
|
||||
static int cmp(const void *v1, const void *v2)
|
||||
{
|
||||
int rc;
|
||||
struct cw_DiscoveryResults_elem *e1,*e2;
|
||||
e1=(struct cw_DiscoveryResults_elem *)v1;
|
||||
e2=(struct cw_DiscoveryResults_elem *)v2;
|
||||
|
||||
rc = e1->prio - e2->prio;
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
rc = e1->wtps - e2->wtps;
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
|
||||
return e1->ctr-e2->ctr;
|
||||
}
|
||||
|
||||
static void del(void *r)
|
||||
{
|
||||
struct cw_DiscoveryResults_elem *e = (struct cw_DiscoveryResults_elem *)r;
|
||||
cw_cfg_destroy(e->cfg);
|
||||
}
|
||||
|
||||
struct cw_DiscoveryResults *cw_discovery_results_create()
|
||||
{
|
||||
struct cw_DiscoveryResults *dis;
|
||||
|
||||
dis = malloc(sizeof(struct cw_DiscoveryResults));
|
||||
if (dis == NULL)
|
||||
return NULL;
|
||||
|
||||
dis->nr = 0;
|
||||
dis->list =
|
||||
mavl_create(cmp, del, sizeof(struct cw_DiscoveryResults_elem));
|
||||
if (dis->list == NULL) {
|
||||
cw_discovery_results_destroy(dis);
|
||||
return NULL;
|
||||
}
|
||||
return dis;
|
||||
}
|
||||
|
||||
void cw_discovery_results_destroy(struct cw_DiscoveryResults *r)
|
||||
{
|
||||
if (r->list)
|
||||
mavl_destroy(r->list);
|
||||
free(r);
|
||||
}
|
||||
|
||||
void cw_discovery_results_add(struct cw_DiscoveryResults *dis,
|
||||
cw_Cfg_t * ac_cfg, cw_Cfg_t * wtp_cfg)
|
||||
{
|
||||
|
||||
const char *acname;
|
||||
char key[CW_CFG_MAX_KEY_LEN];
|
||||
struct cw_DiscoveryResults_elem e;
|
||||
int i;
|
||||
|
||||
/* get ac name */
|
||||
acname = cw_cfg_get(ac_cfg, "capwap/ac-name", NULL);
|
||||
if (acname == NULL) {
|
||||
/* this should not happen, because AC Name is a
|
||||
* amndatory message element */
|
||||
e.prio = 255;
|
||||
} else {
|
||||
/* Get priority for AC from
|
||||
* ac-name-with-priority list */
|
||||
sprintf(key, "ac-name-with-priority/%s", acname);
|
||||
e.prio = cw_cfg_get_byte(wtp_cfg, key, 255);
|
||||
}
|
||||
|
||||
/* for each control ip address the AC has sent */
|
||||
i = 0;
|
||||
do {
|
||||
const char *ipval;
|
||||
|
||||
sprintf(key, "capwap-control-ip-address.%d/wtps", i);
|
||||
e.wtps = cw_cfg_get_word(ac_cfg, key, 65535);
|
||||
|
||||
|
||||
// cw_dbg(DBG_X, "WTPS %d, K: %s", e.wtps);
|
||||
if (e.wtps == 65535)
|
||||
break;
|
||||
|
||||
sprintf(key, "capwap-control-ip-address.%d/address", i);
|
||||
ipval = cw_cfg_get(ac_cfg, key, "");
|
||||
|
||||
sprintf(key, "%04d%05d%04d", e.prio, e.wtps, dis->nr);
|
||||
|
||||
e.ctr=dis->list->count;
|
||||
|
||||
i++;
|
||||
e.cfg = cw_cfg_create();
|
||||
if (e.cfg == NULL)
|
||||
continue;
|
||||
|
||||
cw_cfg_copy(ac_cfg,e.cfg);
|
||||
|
||||
strcpy(e.ip,ipval);
|
||||
|
||||
mavl_insert(dis->list,&e,NULL);
|
||||
|
||||
/* cw_ktv_add(dis->prio_ip, key, CW_TYPE_SYSPTR, NULL, (uint8_t *) (&ipval),
|
||||
sizeof(ipval));
|
||||
cw_ktv_add(dis->prio_ac, key, CW_TYPE_SYSPTR, NULL, (uint8_t *)(&remote_cfg),
|
||||
sizeof(remote_cfg)); */
|
||||
|
||||
// cw_dbg(DBG_X, "KEY: %s: %s", key, ipval);
|
||||
|
||||
} while (i < 255);
|
||||
dis->nr++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
29
src/cw/discovery.h
Normal file
29
src/cw/discovery.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef DISCOVERY_H
|
||||
#define DISCOVERY_H
|
||||
|
||||
#include <mavl.h>
|
||||
|
||||
#include "cfg.h"
|
||||
|
||||
|
||||
struct cw_DiscoveryResults_elem {
|
||||
uint32_t key;
|
||||
char ip[64];
|
||||
cw_Cfg_t * cfg;
|
||||
int prio;
|
||||
int wtps;
|
||||
int ctr;
|
||||
};
|
||||
|
||||
struct cw_DiscoveryResults
|
||||
{
|
||||
int nr;
|
||||
struct mavl * list;
|
||||
};
|
||||
|
||||
void cw_discovery_results_destroy(struct cw_DiscoveryResults *dis);
|
||||
struct cw_DiscoveryResults * cw_discovery_results_create();
|
||||
void cw_discovery_results_add(struct cw_DiscoveryResults *dis, cw_Cfg_t *ac_cfg, cw_Cfg_t * wtp_cfg);
|
||||
void cw_discovery_results_destroy(struct cw_DiscoveryResults * r);
|
||||
|
||||
#endif
|
@ -29,8 +29,6 @@ int capwap_in_capwap_control_ip_address(struct cw_ElemHandler *eh,
|
||||
struct cw_ElemHandlerParams *params,
|
||||
uint8_t * data, int len)
|
||||
{
|
||||
return 0;
|
||||
stop();
|
||||
|
||||
char key[CW_CFG_MAX_KEY_LEN];
|
||||
int idx;
|
||||
@ -40,11 +38,14 @@ int capwap_in_capwap_control_ip_address(struct cw_ElemHandler *eh,
|
||||
|
||||
/* printf("SKEY is %s , idx: %d\n",key,idx);*/
|
||||
|
||||
sprintf(key,"%s/address.%d",eh->key,idx);
|
||||
cw_ktv_add(params->cfg,key,CW_TYPE_IPADDRESS,NULL,data,len-2);
|
||||
sprintf(key,"%s.%d/address",eh->key,idx);
|
||||
CW_TYPE_IPADDRESS->read(params->cfg,key,data,len-2,eh->param);
|
||||
|
||||
sprintf(key,"%s/wtps.%d",eh->key,idx);
|
||||
cw_ktv_add(params->cfg,key,CW_TYPE_WORD,NULL,data+len-2,2);
|
||||
// cw_ktv_add(params->cfg,key,CW_TYPE_IPADDRESS,NULL,data,len-2);
|
||||
|
||||
sprintf(key,"%s.%d/wtps",eh->key,idx);
|
||||
CW_TYPE_WORD->read(params->cfg,key,data+len-2,2,eh->param);
|
||||
// cw_ktv_add(params->cfg,key,CW_TYPE_WORD,NULL,data+len-2,2);
|
||||
|
||||
/* if (handler-id == CW_ELEM_CAPWAP_CONTROL_IPV4_ADDRESS) {
|
||||
struct sockaddr_in addr;
|
||||
|
@ -2360,7 +2360,7 @@ static int preprocess_join_request(struct cw_Conn *conn)
|
||||
return 0;
|
||||
|
||||
stop();
|
||||
|
||||
/*
|
||||
use_ac_version = cw_ktv_get_bool(conn->local_cfg,"cisco/wtp-use-ac-version",0);
|
||||
|
||||
if (use_ac_version){
|
||||
@ -2385,5 +2385,6 @@ static int preprocess_join_request(struct cw_Conn *conn)
|
||||
cw_msgset_add(conn->msgset,messages75, handlers75);
|
||||
}
|
||||
}
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
@ -8,32 +8,41 @@ int cisco_out_wtp_descriptor(struct cw_ElemHandler * eh,
|
||||
struct cw_ElemHandlerParams * params, uint8_t * dst)
|
||||
{
|
||||
|
||||
stop();
|
||||
|
||||
char key[CW_CFG_MAX_KEY_LEN];
|
||||
int len;
|
||||
/* // XXX Dummy WTP Descriptor Header */
|
||||
uint8_t *d;
|
||||
cw_Val_t * val;
|
||||
int rc;
|
||||
|
||||
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);
|
||||
sprintf(key,"%s/%s",eh->key,"max-radios");
|
||||
rc = cw_generic_write_l(params->cfg_list, CW_TYPE_BYTE,key,
|
||||
d, eh->param);
|
||||
|
||||
// val = cw_ktv_get(params->cfg,key, CW_TYPE_BYTE);
|
||||
if (rc==-1){
|
||||
cw_dbg(DBG_WARN,"Cannot get value for %s, setting to 0", key);
|
||||
d+=cw_put_byte(d,0);
|
||||
}
|
||||
else {
|
||||
d+=rc;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
rc = cw_generic_write_l(params->cfg_list, CW_TYPE_BYTE,key,
|
||||
d, eh->param);
|
||||
|
||||
|
||||
// val = cw_ktv_get(params->cfg,key, CW_TYPE_BYTE);
|
||||
if (rc != -1){
|
||||
cw_dbg(DBG_WARN,"Cannot get value for %s, setting to 0", key);
|
||||
d+=cw_put_byte(d,0);
|
||||
}
|
||||
else{
|
||||
d+=cw_put_byte(d,0); /*radios in use*/
|
||||
d+=rc; /*radios in use*/
|
||||
}
|
||||
|
||||
d+=cw_put_encryption_capabilities_7(d,1);
|
||||
|
@ -58,6 +58,7 @@ static struct cw_MsgSet * register_messages(struct cw_MsgSet *set, int mode)
|
||||
case CW_MOD_MODE_CAPWAP:
|
||||
{
|
||||
capwap_mod->register_messages(set, CW_MOD_MODE_CAPWAP);
|
||||
|
||||
capwap80211_mod->register_messages(set, CW_MOD_MODE_BINDINGS);
|
||||
cisco_register_msg_set(set,CW_MOD_MODE_CAPWAP);
|
||||
|
||||
@ -229,10 +230,13 @@ int static setup_cfg(struct cw_Conn * conn)
|
||||
// conn->header_len=header_len;
|
||||
|
||||
security = cw_setup_dtls(conn,conn->global_cfg,"cisco",CAPWAP_CIPHER);
|
||||
|
||||
if (conn->role == CW_ROLE_AC){
|
||||
cw_cfg_set_int(conn->local_cfg,"ac-descriptor/security",security);
|
||||
|
||||
if (conn->default_cfg==NULL){
|
||||
conn->default_cfg=cw_cfg_create();
|
||||
// if (conn->default_cfg==NULL){
|
||||
// conn->default_cfg=cw_cfg_create();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,130 +15,40 @@
|
||||
#include "cw/rand.h"
|
||||
|
||||
#include "wtp.h"
|
||||
#include "cw/cfg.h"
|
||||
|
||||
#include "cw/discovery.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int cw_select_ac(mavl_t local_cfg, struct cw_DiscoveryResult * dis)
|
||||
static int discovery_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len)
|
||||
{
|
||||
mlistelem_t *e;
|
||||
/*mavl_t iplist;*/
|
||||
int en;
|
||||
struct cw_DiscoveryResults *results = (struct cw_DiscoveryResults *)params->conn->data;
|
||||
// cw_Cfg_t * cfg = cw_cfg_create();
|
||||
// cw_cfg_copy(params->cfg,cfg);
|
||||
|
||||
/*iplist = cw_ktv_create();
|
||||
if (iplist == NULL){
|
||||
cw_log_errno("cw_select_ac: Can't allocate memory for aciplist");
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
cw_discovery_results_add(results,params->cfg,params->conn->global_cfg);
|
||||
printf("Have Discovery %d\n",results->nr);
|
||||
|
||||
en = 0;
|
||||
|
||||
/* for each discovery response */
|
||||
mlist_foreach(e, dis->results) {
|
||||
char acname[CAPWAP_MAX_AC_NAME_LEN + 1];
|
||||
char key[CW_CFG_MAX_KEY_LEN];
|
||||
mavl_t remote_cfg;
|
||||
cw_Val_t *val, *ipval;
|
||||
int prio, i;
|
||||
|
||||
remote_cfg = mlistelem_get_ptr(e);
|
||||
|
||||
/* get ac name */
|
||||
val = cw_ktv_get(remote_cfg, "ac-name", CW_TYPE_BSTR16);
|
||||
if (val == NULL) {
|
||||
/* this should not happen, because AC Name is a
|
||||
* amndatory message element */
|
||||
prio = 255;
|
||||
} else {
|
||||
/* Get priority for AC from
|
||||
* ac-name-with-priority list */
|
||||
val->type->to_str(val, acname, CAPWAP_MAX_AC_NAME_LEN);
|
||||
sprintf(key, "ac-name-with-priority/%s", acname);
|
||||
prio = cw_ktv_get_byte(local_cfg, key, 255);
|
||||
}
|
||||
|
||||
/* for each control ip address the AC has sent */
|
||||
i = 0;
|
||||
do {
|
||||
sprintf(key, "%s.%d", "capwap-control-ip-address/wtps", i);
|
||||
val = cw_ktv_get(remote_cfg, key, CW_TYPE_WORD);
|
||||
if (val == NULL)
|
||||
break;
|
||||
|
||||
sprintf(key, "%s.%d", "capwap-control-ip-address/address", i);
|
||||
ipval = cw_ktv_get(remote_cfg, key, CW_TYPE_IPADDRESS);
|
||||
|
||||
sprintf(key, "%04d%05d%04d", prio, val->val.word, en);
|
||||
|
||||
cw_ktv_add(dis->prio_ip, key, CW_TYPE_SYSPTR, NULL, (uint8_t *) (&ipval),
|
||||
sizeof(ipval));
|
||||
cw_ktv_add(dis->prio_ac, key, CW_TYPE_SYSPTR, NULL, (uint8_t *)(&remote_cfg),
|
||||
sizeof(remote_cfg));
|
||||
i++;
|
||||
en++;
|
||||
} while (1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void cw_discovery_free_results(struct cw_DiscoveryResult * dis)
|
||||
{
|
||||
if (dis->prio_ac != NULL)
|
||||
mavl_destroy(dis->prio_ac);
|
||||
if (dis->prio_ip != NULL)
|
||||
mavl_destroy(dis->prio_ip);
|
||||
if (dis->results != NULL)
|
||||
mlist_destroy(dis->results);
|
||||
}
|
||||
|
||||
|
||||
static void result_del(void * data)
|
||||
{
|
||||
|
||||
mavl_t todelete = *((void**)data);
|
||||
mavl_destroy(todelete);
|
||||
|
||||
|
||||
/*mavl_t*/
|
||||
}
|
||||
|
||||
int cw_discovery_init_results(struct cw_DiscoveryResult *dis)
|
||||
{
|
||||
|
||||
dis->results = mlist_create(NULL, result_del, sizeof(void *));
|
||||
if (dis->results==NULL)
|
||||
goto errX;
|
||||
dis->prio_ac=cw_ktv_create();
|
||||
if (dis->prio_ac==NULL)
|
||||
goto errX;
|
||||
dis->prio_ip=cw_ktv_create();
|
||||
if (dis->prio_ac==NULL)
|
||||
goto errX;
|
||||
return 1;
|
||||
errX:
|
||||
cw_discovery_free_results(dis);
|
||||
// cw_cfg_dump(params->cfg);
|
||||
// mlist_append_ptr(dis->results, cfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int run_discovery(struct cw_Conn *conn, struct cw_DiscoveryResult * dis)
|
||||
static struct cw_DiscoveryResults * run_discovery(struct cw_Conn *conn)
|
||||
{
|
||||
time_t timer;
|
||||
struct sockaddr_storage from;
|
||||
int delay, min, max;
|
||||
|
||||
struct cw_DiscoveryResults * results;
|
||||
results = cw_discovery_results_create();
|
||||
|
||||
|
||||
min = cw_ktv_get_byte(conn->local_cfg,"capwap-timers/min-discovery-interval",
|
||||
min = cw_cfg_get_byte(conn->local_cfg,"capwap-timers/min-discovery-interval",
|
||||
CAPWAP_MIN_DISCOVERY_INTERVAL);
|
||||
max = cw_ktv_get_byte(conn->local_cfg,"capwap-timers/max-discovery-interval",
|
||||
max = cw_cfg_get_byte(conn->local_cfg,"capwap-timers/max-discovery-interval",
|
||||
CAPWAP_MAX_DISCOVERY_INTERVAL);
|
||||
|
||||
delay = cw_randint(min,max);
|
||||
@ -150,29 +60,37 @@ static int run_discovery(struct cw_Conn *conn, struct cw_DiscoveryResult * dis)
|
||||
|
||||
conn->capwap_state = CAPWAP_STATE_DISCOVERY;
|
||||
|
||||
|
||||
conn->remote_cfg=cw_cfg_create();
|
||||
/* create and send a discovery request message */
|
||||
cw_init_request(conn, CAPWAP_MSG_DISCOVERY_REQUEST);
|
||||
cw_assemble_message(conn, conn->req_buffer);
|
||||
|
||||
|
||||
conn_send_msg(conn, conn->req_buffer);
|
||||
cw_cfg_destroy(conn->remote_cfg);
|
||||
conn->remote_cfg=NULL;
|
||||
|
||||
|
||||
timer = cw_timer_start(cw_ktv_get_byte(conn->local_cfg, "discovery-interval",
|
||||
|
||||
|
||||
timer = cw_timer_start(cw_cfg_get_byte(conn->local_cfg, "discovery-interval",
|
||||
CAPWAP_DISCOVERY_INTERVAL))-1;
|
||||
|
||||
/*discovery_results = mlist_create(NULL, NULL, sizeof(void *));*/
|
||||
|
||||
conn->data = results;
|
||||
cw_conn_set_msg_cb(conn,CAPWAP_MSG_DISCOVERY_RESPONSE,discovery_cb);
|
||||
|
||||
|
||||
while (!cw_timer_timeout(timer)
|
||||
&& conn->capwap_state == CAPWAP_STATE_DISCOVERY) {
|
||||
int rc;
|
||||
char addr_str[SOCK_ADDR_BUFSIZE];
|
||||
|
||||
conn->remote_cfg = cw_ktv_create();
|
||||
if (conn->remote_cfg == NULL) {
|
||||
cw_log_errno("Can't allocate memory for remote_cfg");
|
||||
break;
|
||||
}
|
||||
cw_dbg(DBG_X,"READ NOW");
|
||||
// conn->remote_cfg = cw_ktv_create();
|
||||
// if (conn->remote_cfg == NULL) {
|
||||
// cw_log_errno("Can't allocate memory for remote_cfg");
|
||||
// break;
|
||||
// }
|
||||
|
||||
rc = cw_read_from(conn, &from);
|
||||
if (rc < 0) {
|
||||
@ -182,16 +100,28 @@ static int run_discovery(struct cw_Conn *conn, struct cw_DiscoveryResult * dis)
|
||||
cw_log(LOG_ERROR, "Error reading messages: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
cw_dbg(DBG_INFO, "Received Discovery Response from %s",
|
||||
sock_addr2str(&from, addr_str));
|
||||
mlist_append_ptr(dis->results, conn->remote_cfg);
|
||||
// cw_dbg(DBG_INFO, "Received Discovery Response from %s",
|
||||
// sock_addr2str(&from, addr_str));
|
||||
// mlist_append_ptr(dis->results, conn->remote_cfg);
|
||||
|
||||
// cw_cfg_dump(conn->remote_cfg);
|
||||
}
|
||||
|
||||
cw_select_ac(conn->local_cfg, dis);
|
||||
|
||||
//cw_select_ac(conn->local_cfg, dis);
|
||||
|
||||
mavliter_t it;
|
||||
mavliter_init(&it,results->list);
|
||||
mavliter_foreach(&it){
|
||||
const char * acname;
|
||||
struct cw_DiscoveryResults_elem *e = mavliter_get(&it);
|
||||
acname = cw_cfg_get(e->cfg,"capwap/ac-name","<unknown>");
|
||||
printf("E: %s: %s - prio: %d, ctr: %d\n",acname,e->ip,e->prio,e->ctr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@ -200,15 +130,14 @@ static int run_discovery(struct cw_Conn *conn, struct cw_DiscoveryResult * dis)
|
||||
/**
|
||||
* Run discovery for on address (eg broadcast 255.255.255.255)
|
||||
*/
|
||||
int cw_run_discovery(struct cw_Conn *conn, const char *addr, const char *bindaddr,
|
||||
struct cw_DiscoveryResult * dis)
|
||||
struct cw_DiscoveryResults * cw_run_discovery(struct cw_Conn *conn, const char *addr, const char *bindaddr )
|
||||
{
|
||||
struct cw_DiscoveryResults * results;
|
||||
char sock_buf[SOCK_ADDR_BUFSIZE];
|
||||
struct sockaddr_storage dstaddr;
|
||||
char caddr[256], control_port[64];
|
||||
|
||||
int rc;
|
||||
/*struct cw_DiscoveryResult dis;*/
|
||||
|
||||
|
||||
/*dis.results = mlist_create(NULL, NULL, sizeof(void *));*/
|
||||
@ -302,7 +231,7 @@ int cw_run_discovery(struct cw_Conn *conn, const char *addr, const char *bindadd
|
||||
cw_dbg(DBG_INFO, "Discovery to %s",
|
||||
sock_addr2str_p(&conn->addr, sock_buf));
|
||||
|
||||
run_discovery(conn, dis);
|
||||
results = run_discovery(conn);
|
||||
|
||||
conn->readfrom = NULL;
|
||||
close(sockfd);
|
||||
@ -312,5 +241,5 @@ int cw_run_discovery(struct cw_Conn *conn, const char *addr, const char *bindadd
|
||||
|
||||
freeaddrinfo(res0);
|
||||
|
||||
return 0;
|
||||
return results;
|
||||
}
|
||||
|
@ -199,8 +199,11 @@ int run_join(struct cw_Conn *conn)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int join(struct cw_Conn * conn, struct cw_DiscoveryResult * dis)
|
||||
int join(struct cw_Conn * conn, struct cw_DiscoveryResults * dis)
|
||||
{
|
||||
|
||||
stop();
|
||||
/*
|
||||
mavliter_t ii;
|
||||
mavliter_init(&ii,dis->prio_ip);
|
||||
|
||||
@ -239,6 +242,6 @@ int join(struct cw_Conn * conn, struct cw_DiscoveryResult * dis)
|
||||
if (rc)
|
||||
return 1;
|
||||
|
||||
}
|
||||
}*/
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,11 +2,11 @@
|
||||
#define __WTP_H
|
||||
|
||||
#include "cw/conn.h"
|
||||
|
||||
#include "cw/discovery.h"
|
||||
|
||||
|
||||
extern int sulking_state();
|
||||
extern int join();
|
||||
//extern int join();
|
||||
extern int discovery();
|
||||
extern int image_update();
|
||||
extern int setup_conf(struct cw_Conn * conn);
|
||||
@ -15,19 +15,9 @@ extern int run();
|
||||
extern int changestate();
|
||||
|
||||
|
||||
struct cw_DiscoveryResults * cw_run_discovery(struct cw_Conn *conn, const char *addr, const char *bindaddr );
|
||||
|
||||
struct cw_DiscoveryResult{
|
||||
mavl_t prio_ip;
|
||||
mavl_t prio_ac;
|
||||
mlist_t results;
|
||||
};
|
||||
|
||||
int cw_run_discovery(struct cw_Conn *conn, const char *acaddr, const char *bindaddr,
|
||||
struct cw_DiscoveryResult * dis);
|
||||
|
||||
int cw_discovery_init_results(struct cw_DiscoveryResult *dis);
|
||||
void cw_discovery_free_results(struct cw_DiscoveryResult * dis);
|
||||
int join(struct cw_Conn * conn, struct cw_DiscoveryResult * dis);
|
||||
int join(struct cw_Conn * conn, struct cw_DiscoveryResults * dis);
|
||||
|
||||
struct cw_Conn * get_conn();
|
||||
|
||||
|
@ -88,12 +88,11 @@ int main (int argc, char **argv)
|
||||
struct bootcfg bootcfg;
|
||||
struct cw_Mod * mod;
|
||||
struct cw_MsgSet * msgset=NULL;
|
||||
struct cw_Conn * conn;
|
||||
struct cw_Conn * conn=NULL;
|
||||
FILE * file;
|
||||
cw_Cfg_t * global_cfg =NULL;
|
||||
const cw_Type_t ** ti;
|
||||
int i;
|
||||
struct cw_DiscoveryResult dis;
|
||||
int rc;
|
||||
|
||||
|
||||
@ -130,21 +129,13 @@ int main (int argc, char **argv)
|
||||
goto errX;
|
||||
}
|
||||
|
||||
// cw_ktv_read_file(file,global_cfg,types_tree);
|
||||
|
||||
|
||||
// cw_dbg_ktv_dump(global_cfg,DBG_CFG_DMP,"----- global cfg start -----","","----- global cfg end -----");
|
||||
|
||||
exit(0);
|
||||
|
||||
/*clean_cfg(global_cfg);*/
|
||||
|
||||
|
||||
/* create a connection object */
|
||||
conn = conn_create_noq(-1, NULL);
|
||||
if (conn==NULL){
|
||||
cw_log(LOG_ERR, "Connot create conn: %s", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
rc = EXIT_FAILURE;
|
||||
goto errX;
|
||||
}
|
||||
|
||||
|
||||
@ -153,44 +144,52 @@ int main (int argc, char **argv)
|
||||
conn->dtls_verify_peer=0;
|
||||
conn->dtls_mtu = 1200;
|
||||
conn->msgset=msgset;
|
||||
conn->local_cfg = global_cfg;
|
||||
conn->remote_cfg = NULL;
|
||||
conn->global_cfg = global_cfg;
|
||||
conn->local_cfg = cw_cfg_create();
|
||||
//conn->remote_cfg = cw_cfg_create();
|
||||
|
||||
conn->role = CW_ROLE_WTP;
|
||||
conn->wbid=1;
|
||||
|
||||
for (i=0;i<bootcfg.nmods; i++){
|
||||
mod = cw_mod_load(bootcfg.modnames[i], global_cfg, CW_ROLE_WTP);
|
||||
if (mod == NULL){
|
||||
exit (EXIT_FAILURE);
|
||||
rc = EXIT_FAILURE;
|
||||
goto errX;
|
||||
}
|
||||
|
||||
|
||||
/* Build a message set from our loaded modules */
|
||||
mod->register_messages(msgset, CW_MOD_MODE_CAPWAP);
|
||||
mod->register_messages(msgset, CW_MOD_MODE_BINDINGS);
|
||||
if (mod->setup_cfg)
|
||||
mod->setup_cfg(conn);
|
||||
}
|
||||
/*
|
||||
{
|
||||
int idx;
|
||||
cw_dbg_ktv_dump(conn->local_cfg,DBG_INFO,"head","BREP: ","bot");
|
||||
idx = cw_ktv_idx_get(conn->local_cfg,"tube",0,NULL);
|
||||
printf("IDX: %d\n",idx);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
dtls_init();
|
||||
|
||||
conn->base_rmac = get_base_rmac();
|
||||
|
||||
|
||||
cw_discovery_init_results(&dis);
|
||||
/*cw_run_discovery(conn, "255.255.255.255","192.168.56.1", &dis);*/
|
||||
/* cw_run_discovery(conn, "255.255.255.255",NULL, &dis);*/
|
||||
cw_run_discovery(conn, "192.168.0.162","192.168.0.14", &dis);
|
||||
cw_dbg_ktv_dump(dis.prio_ip, DBG_INFO, "=== IP list ===", "IP", "=== END IP List ===");
|
||||
|
||||
struct cw_DiscoveryResulsts * results;
|
||||
// cw_run_discovery(conn, "192.168.0.162","192.168.0.14", &dis);
|
||||
//cw_run_discovery(conn, "255.255.255.255","192.168.0.14", &dis);
|
||||
// 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");
|
||||
|
||||
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);
|
||||
@ -214,10 +213,10 @@ exit(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
mavl_del_all(conn->remote_cfg);
|
||||
printf("JOIN\n");
|
||||
join(conn,&dis);
|
||||
// join(conn,&dis);
|
||||
clean_cfg(conn->remote_cfg);
|
||||
mavl_merge(conn->local_cfg,conn->remote_cfg);
|
||||
|
||||
@ -233,7 +232,7 @@ printf("JOIN CONF\n");
|
||||
|
||||
run(conn);
|
||||
|
||||
cw_discovery_free_results(&dis);
|
||||
// cw_discovery_free_results(&dis);
|
||||
|
||||
return (EXIT_SUCCESS);
|
||||
errX:
|
||||
@ -242,6 +241,8 @@ errX:
|
||||
|
||||
if (global_cfg != NULL)
|
||||
cw_cfg_destroy(global_cfg);
|
||||
if (conn)
|
||||
conn_destroy(conn);
|
||||
|
||||
|
||||
return rc;
|
||||
|
Loading…
Reference in New Issue
Block a user