Reads a lot of dbg options now
FossilOrigin-Name: f2f7d4dd250d0a71788fa264a69d02206f4d28740dd5dae134f9a582e8aa90a0
This commit is contained in:
parent
0ce491e01a
commit
17736837b1
@ -40,6 +40,29 @@ static struct uci_section * get_anon_section(struct uci_package * pkg, const ch
|
||||
}
|
||||
|
||||
|
||||
static void set_dbg_opt(struct uci_context *ctx,struct uci_section * section,int opt,const char * optstr)
|
||||
{
|
||||
const char *str = uci_lookup_option_string(ctx,section,optstr);
|
||||
if (!str)
|
||||
return;
|
||||
if ((strcmp(str,"1")==0) || (strcmp(str,"true")==0))
|
||||
conf_dbg_level |= opt;
|
||||
|
||||
if ((strcmp(str,"0")==0) || (strcmp(str,"false")==0))
|
||||
conf_dbg_level &= ((-1)^opt);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void read_dbg_options(struct uci_context *ctx, struct uci_section *section)
|
||||
{
|
||||
|
||||
set_dbg_opt(ctx,section,DBG_DTLS,"dtls");
|
||||
set_dbg_opt(ctx,section,DBG_DTLS_DETAIL,"dtls_detail");
|
||||
set_dbg_opt(ctx,section,DBG_DTLS_BIO,"dtls_bio");
|
||||
set_dbg_opt(ctx,section,DBG_DTLS_BIO_DMP,"dtls_bio_dmp");
|
||||
}
|
||||
|
||||
int read_config(const char * filename){
|
||||
|
||||
@ -75,7 +98,17 @@ int read_config(const char * filename){
|
||||
|
||||
}
|
||||
|
||||
struct uci_section * section = get_anon_section(pkg,"wtp");
|
||||
|
||||
struct uci_section * section;
|
||||
|
||||
section = get_anon_section(pkg,"dbg");
|
||||
read_dbg_options(ctx,section);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
section = get_anon_section(pkg,"wtp");
|
||||
if (!section) {
|
||||
cw_dbg(DBG_CW_INFO,"No 'wtp' section found, running without config");
|
||||
return 1;
|
||||
@ -119,254 +152,11 @@ int read_config(const char * filename){
|
||||
bstr_replace(&conf_model_no,s);
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
char * conf_primary_if=0;
|
||||
char * conf_wtpname=0;
|
||||
char * conf_dtls_psk=0;
|
||||
char * conf_preferred_ac=0;
|
||||
char * conf_dtls_cipher=0;
|
||||
|
||||
|
||||
struct sockaddr_storage * conf_preferred_ac_sa=0;
|
||||
|
||||
|
||||
char ** conf_ac_list;
|
||||
int conf_ac_list_len;
|
||||
char * conf_control_port=0;
|
||||
uint8_t conf_macaddress[12];
|
||||
uint8_t conf_macaddress_len=0;
|
||||
|
||||
long conf_max_discovery_interval=CONF_DEFAULT_MAX_DISCOVERY_INTERVAL;
|
||||
long conf_discovery_interval=CONF_DEFAULT_DISCOVERY_INTERVAL;
|
||||
long conf_silent_interval=CONF_DEFAULT_SILENT_INTERVAL;
|
||||
long conf_max_discoveries=CONF_DEFAULT_MAX_DISCOVERIES;
|
||||
long conf_echo_interval=CONF_DEFAULT_ECHO_INTERVAL;
|
||||
long conf_max_retransmit=CONF_DEFAULT_MAX_RETRANSMIT;
|
||||
long conf_retransmit_interval=CONF_DEFAULT_RETRANSMIT_INTERVAL;
|
||||
|
||||
long conf_debug_level=CONF_DEFAULT_DEBUG_LEVEL;
|
||||
|
||||
|
||||
int wtpconf_init()
|
||||
{
|
||||
|
||||
|
||||
if (conf_preferred_ac){
|
||||
conf_preferred_ac_sa=malloc(sizeof(struct sockaddr_storage));
|
||||
if (sock_strtoaddr(conf_preferred_ac,conf_preferred_ac_sa)!=1)
|
||||
{
|
||||
cw_log(LOG_ERR,"Preferred AC, invalid address: %s",conf_preferred_ac);
|
||||
free(conf_preferred_ac_sa);
|
||||
conf_preferred_ac_sa=0;
|
||||
}
|
||||
else{
|
||||
if (sock_getport(conf_preferred_ac_sa)==0){
|
||||
sock_setport(conf_preferred_ac_sa,conf_control_port);
|
||||
}
|
||||
}
|
||||
if (conf_preferred_ac_sa!=0){
|
||||
char str[100];
|
||||
sock_addrtostr(conf_preferred_ac_sa,str,100);
|
||||
cw_log(LOG_INFO,"Preferred AC: %s\n",str);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
char * get_prim(int family)
|
||||
{
|
||||
struct ifaddrs *ifap,*ifa;
|
||||
char * r = 0;
|
||||
|
||||
getifaddrs(&ifap);
|
||||
|
||||
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_flags & IFF_LOOPBACK){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ifa->ifa_addr->sa_family != family)
|
||||
continue;
|
||||
|
||||
r = malloc(strlen(ifa->ifa_name)+1);
|
||||
if (r)
|
||||
strcpy(r,ifa->ifa_name);
|
||||
break;
|
||||
|
||||
}
|
||||
freeifaddrs(ifap);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
wtpconf_primary_if()
|
||||
{
|
||||
if (!conf_primary_if){
|
||||
|
||||
#ifdef WITH_IPV6
|
||||
conf_primary_if = get_prim(AF_INET6);
|
||||
if (!conf_primary_if)
|
||||
conf_primary_if = get_prim(AF_INET);
|
||||
#else
|
||||
conf_primary_if = get_prim(AF_INET);
|
||||
#endif
|
||||
if (!conf_primary_if){
|
||||
cw_log(LOG_ERR,"Fatal: Unable to detect primary interface");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
if (!sock_getifhwaddr(conf_primary_if,conf_macaddress,&conf_macaddress_len)){
|
||||
cw_log(LOG_ERR,"Fatal: Unable to detect link layer address for %s\n",conf_primary_if);
|
||||
return 0;
|
||||
};
|
||||
|
||||
#ifdef WITH_CW_LOG_DEBUG
|
||||
char str[128];
|
||||
sock_hwaddrtostr(conf_macaddress,conf_macaddress_len,str);
|
||||
cw_log_debug0("Using primary interface: %s",conf_primary_if);
|
||||
cw_log_debug0("Using primary mac address: %s",str);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char * default_ac_list[] = {
|
||||
"255.255.255.255",
|
||||
"224.0.1.140",
|
||||
};
|
||||
|
||||
wtpconf_ac_list()
|
||||
{
|
||||
if (conf_ac_list)
|
||||
return 1;
|
||||
|
||||
int i;
|
||||
int len=0;
|
||||
int bcrc;
|
||||
struct sockaddr_storage bcaddr;
|
||||
|
||||
bcrc = sock_getifaddr(conf_primary_if,AF_INET,IFF_BROADCAST,&bcaddr);
|
||||
if (bcrc)
|
||||
len++;
|
||||
|
||||
int deflen = sizeof(default_ac_list)/sizeof(char*);
|
||||
|
||||
len += deflen;
|
||||
conf_ac_list = malloc(len*sizeof(char*));
|
||||
if (!conf_ac_list)
|
||||
return 0;
|
||||
|
||||
for (i=0; i<deflen; i++){
|
||||
conf_ac_list[i]=strdup(default_ac_list[i]);
|
||||
if (!conf_ac_list[i])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (bcrc){
|
||||
char bcstr[100];
|
||||
sock_addrtostr(&bcaddr,bcstr,100);
|
||||
char * c = strchr(bcstr,':');
|
||||
*c=0;
|
||||
conf_ac_list[i]=strdup(bcstr);
|
||||
}
|
||||
|
||||
conf_ac_list_len=len;
|
||||
#ifdef WITH_CW_LOG_DEBUG
|
||||
for (i=0; i<conf_ac_list_len; i++){
|
||||
cw_log_debug0("Using AC: %s\n",conf_ac_list[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int read_config(const char * filename){
|
||||
int i,n;
|
||||
|
||||
|
||||
conf_control_port=strdup(CAPWAP_CONTROL_PORT_STR);
|
||||
conf_dtls_cipher=strdup(CONF_DEFAULT_DTLS_CIPHER);
|
||||
|
||||
cfg_opt_t opts[] = {
|
||||
CFG_SIMPLE_STR("wtp_name",&conf_wtpname),
|
||||
CFG_SIMPLE_STR("dtls_psk",&conf_dtls_psk),
|
||||
CFG_SIMPLE_STR("preferred_ac",&conf_preferred_ac),
|
||||
CFG_SIMPLE_STR("primary_if",&conf_primary_if),
|
||||
CFG_SIMPLE_STR("dtls_cipher",&conf_dtls_cipher),
|
||||
CFG_STR_LIST("ac_list", "{}", CFGF_NONE),
|
||||
CFG_SIMPLE_STR("control_port",&conf_control_port),
|
||||
CFG_SIMPLE_INT("discovery_interval",&conf_discovery_interval),
|
||||
CFG_SIMPLE_INT("max_discovery_interval",&conf_max_discovery_interval),
|
||||
CFG_SIMPLE_INT("max_discoveries",&conf_max_discoveries),
|
||||
CFG_SIMPLE_INT("silent_interval",&conf_silent_interval),
|
||||
CFG_SIMPLE_INT("debug_level",&conf_debug_level),
|
||||
CFG_SIMPLE_INT("max_retransmit",&conf_max_retransmit),
|
||||
CFG_SIMPLE_INT("retransmit_interval",&conf_retransmit_interval),
|
||||
CFG_SIMPLE_INT("echo_interval",&conf_echo_interval),
|
||||
|
||||
|
||||
CFG_END()
|
||||
};
|
||||
|
||||
cfg_t *cfg;
|
||||
cfg = cfg_init(opts, 0);
|
||||
|
||||
cfg_parse(cfg, filename);
|
||||
|
||||
|
||||
n = cfg_size(cfg, "ac_list");
|
||||
if (n>0)
|
||||
{
|
||||
conf_ac_list=malloc(sizeof(char*)*n);
|
||||
if (!conf_ac_list)
|
||||
goto errX;
|
||||
|
||||
conf_ac_list_len=0;
|
||||
for (i=0; i<n; i++){
|
||||
char * str = cfg_getnstr(cfg,"ac_list",i);
|
||||
conf_ac_list[conf_ac_list_len]=malloc(strlen(str)+1);
|
||||
if(conf_ac_list) {
|
||||
strcpy(conf_ac_list[conf_ac_list_len],str);
|
||||
conf_ac_list_len++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!wtpconf_primary_if())
|
||||
goto errX;
|
||||
|
||||
if (!wtpconf_ac_list()){
|
||||
printf("ac list error\n");
|
||||
goto errX;
|
||||
}
|
||||
|
||||
|
||||
// wtpconf_init();
|
||||
return 1;
|
||||
|
||||
errX:
|
||||
cfg_free(cfg);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user