Compare commits

..

No commits in common. "156466eab94235c2b6ab366066c275419f31ffeb" and "1616d77a0f8f1dbcac6fe49645e24c946704bee1" have entirely different histories.

6 changed files with 63 additions and 133 deletions

View File

@ -48,8 +48,7 @@
#include "cw/cfg.h"
int ac_run(cw_Cfg_t * cfg);
int ac_run();
#include <getopt.h>
@ -65,7 +64,7 @@ static int parse_args (int argc, char *argv[], struct bootcfg * bootcfg)
int c;
opterr = 1;
bootcfg->cfgfilename = "config.ckv";
bootcfg->cfgfilename = "config.atv";
while ( (c = getopt (argc, argv, "vc:d:p:")) != -1) {
@ -176,7 +175,7 @@ int main (int argc, char *argv[])
int rc = 0;
struct bootcfg bootcfg;
FILE * file;
mavl_t types_tree;
mavl_t types_tree, acglobal_cfg;
const cw_Type_t **ti;
@ -194,11 +193,13 @@ int main (int argc, char *argv[])
rc = cw_cfg_load(bootcfg.cfgfilename,global_cfg);
if (rc)
{
if (rc)
if (rc<0)
fprintf(stderr,"Can't load cfg '%s': %s\n",bootcfg.cfgfilename,strerror(errno));
goto errX;
};
actube_global_cfg = acglobal_cfg;
cw_log_name = "AC-Tube";
@ -218,13 +219,9 @@ int main (int argc, char *argv[])
if (!dataman_list_init())
goto errX;
ac_conf_init(global_cfg);
cw_cfg_dump(global_cfg);
cw_log (LOG_INFO, "Starting AC-Tube, Name=%s, ID=%s", conf_acname, conf_acid);
rc = ac_run(global_cfg);
rc = ac_run();
errX:
if (global_cfg)
@ -246,18 +243,15 @@ void process_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, in
void process_cw_data_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len);
int ac_run(cw_Cfg_t * cfg)
int ac_run()
{
if (1 /*!conf_listen_addrs_len*/) {
if (!conf_listen_addrs_len) {
cw_log (LOG_ERR, "Fatal error: No listen addresses found.");
// return 1;
return 1;
}
extern void cw_cfg_iterate(cw_Cfg_t *);
cw_cfg_iterate(cfg);
return 1;
/* it is important to create the unicast sockets first,
* because when we create the mcast an bcast sockets next
@ -266,7 +260,7 @@ int ac_run(cw_Cfg_t * cfg)
int i;
/* for (i = 0; i < conf_listen_addrs_len; i++) {
for (i = 0; i < conf_listen_addrs_len; i++) {
char addr[100];
char port[50];
int proto;
@ -275,8 +269,7 @@ int ac_run(cw_Cfg_t * cfg)
socklist_add_unicast (addr, port, proto);
}
*/
if (socklist_len == 0) {
cw_log (LOG_ERR, "Fatal error: Could not setup any listen socket");
return 1;

View File

@ -36,7 +36,6 @@
#include "conf.h"
#include "ac.h"
#include "cw/cfg.h"
#include "cw/mavltypes.h"
@ -61,6 +60,8 @@ long conf_max_wtps = CONF_DEFAULT_MAXWTPS;
char *conf_logfilename = CONF_DEFAULT_LOGFILENAME;
struct sockaddr_storage *conf_salist = NULL;
char **conf_listen_addrs;
int conf_listen_addrs_len = 0;
char **conf_mcast_groups = 0;
@ -214,23 +215,41 @@ static int init_control_port()
#include <ifaddrs.h>
static int init_listen_addrs(cw_Cfg_t * cfg)
static int init_listen_addrs()
{
char key[CW_CFG_MAX_KEY_LEN];
struct ifaddrs *ifap, *ifa;
int rc;
int ctr;
const char * a0;
a0 = cw_cfg_get(cfg,"actube/listen.0",NULL);
if (a0)
if (conf_listen_addrs != 0)
return 1;
rc = getifaddrs(&ifap);
if (rc == -1)
return 0;
/* count the addresses */
ctr = 0;
for (ifa = ifap; ifa != 0; ifa = ifa->ifa_next) {
if (!ifa->ifa_addr)
continue;
if (ifa->ifa_addr->sa_family == AF_INET && conf_ipv4)
ctr++;
if (ifa->ifa_addr->sa_family == AF_INET6 && conf_ipv6)
ctr++;
}
conf_listen_addrs = malloc(sizeof(char *) * ctr);
if (!conf_listen_addrs) {
rc = 0;
goto errX;
}
memset(conf_listen_addrs, 0, sizeof(char *) * ctr);
ctr = 0;
/* get the addresses */
for (ifa = ifap; ifa != 0; ifa = ifa->ifa_next) {
@ -248,9 +267,12 @@ static int init_listen_addrs(cw_Cfg_t * cfg)
if (ifa->ifa_addr->sa_family == AF_INET && conf_ipv4) {
sock_addrtostr(ifa->ifa_addr, str, 100,0);
conf_listen_addrs[ctr] =
(char *) cw_setstr((uint8_t **) & conf_listen_addrs[ctr],
(uint8_t *) str, strlen(str));
if (conf_listen_addrs[ctr])
ctr++;
sprintf(key,"actube/listen.%d",ctr++);
cw_cfg_set(cfg,key,str);
}
if (ifa->ifa_addr->sa_family == AF_INET6 && conf_ipv6) {
sock_addrtostr(ifa->ifa_addr, str, 100,0);
@ -259,10 +281,14 @@ static int init_listen_addrs(cw_Cfg_t * cfg)
strcat(str, "%");
strcat(str, ifa->ifa_name);
}
sprintf(key,"actube/listen.%d",ctr++);
cw_cfg_set(cfg,key,str);
conf_listen_addrs[ctr] =
(char *) cw_setstr((uint8_t **) & conf_listen_addrs[ctr],
(uint8_t *) str, strlen(str));
if (conf_listen_addrs[ctr])
ctr++;
}
}
conf_listen_addrs_len = ctr;
rc = 1;
errX:
freeifaddrs(ifap);
@ -677,6 +703,9 @@ int read_config(const char *filename)
/* read debug options */
conf_read_dbg_level(cfg);
/* read the listen addresses */
conf_read_strings(cfg, "listen", &conf_listen_addrs, &conf_listen_addrs_len);
/* read multi cast groups */
conf_read_strings(cfg, "mcast_groups", &conf_mcast_groups,
&conf_mcast_groups_len);
@ -734,6 +763,7 @@ int read_config(const char *filename)
init_listen_addrs();
init_mcast_groups();
init_bcast_addrs();
@ -745,13 +775,3 @@ void free_config()
{
}
void ac_conf_init(cw_Cfg_t *cfg)
{
printf("ac conf\n");
init_listen_addrs(cfg);
}

View File

@ -31,7 +31,7 @@
#include "cw/bstr.h"
#include "cw/mod.h"
#include "cw/vendors.h"
#include "cw/cfg.h"
extern struct cw_Mod ** conf_mods;
@ -94,6 +94,8 @@ extern bstr_t conf_cisco_software_version;
extern char **conf_listen_addrs;
extern int conf_listen_addrs_len;
extern struct sockaddr *conf_ac_ips;
extern int conf_ac_ips_len;
@ -139,8 +141,5 @@ extern int conf_parse_listen_addr(const char *addr, char *saddr, char *port, int
#define CFG_ENTRY_MODS "mods"
#define CONF_PREFIX "actube"
void ac_conf_init(cw_Cfg_t *cfg);
#endif

View File

@ -3,7 +3,7 @@
#include "cw/mod.h"
struct cw_DiscoveryCache * discovery_cache_create(int len);
@ -14,5 +14,4 @@ void discovery_cache_add(struct cw_DiscoveryCache *cache,
int discovery_cache_get(struct cw_DiscoveryCache * cache,struct sockaddr *addr,
struct cw_Mod ** modcapwap, struct cw_Mod **modbindings);
void discovery_cache_destroy(struct cw_DiscoveryCache * c);
#endif
#endif

View File

@ -52,13 +52,13 @@ int cw_cfg_set(cw_Cfg_t * cfg,const char *key, const char *val)
return -1;
}
const char * cw_cfg_get(cw_Cfg_t * cfg, char *key, const char *def)
char * cw_cfg_get(cw_Cfg_t * cfg, char *key)
{
struct cw_Cfg_entry e,*r;
e.key = key;
r = mavl_get(cfg,&e);
if (!r)
return def;
return NULL;
return r->val;
}
@ -368,86 +368,5 @@ int cw_cfg_load(const char *filename,cw_Cfg_t * cfg)
return errno;
errs = cw_cfg_read_from_file(f,cfg);
fclose(f);
if (errs)
errno = EINVAL;
return errno;
return errs;
}
static int cw_cfg_get_next_idx(cw_Cfg_t * cfg, const char *key, int n)
{
char ikey[CW_CFG_MAX_KEY_LEN];
struct cw_Cfg_entry search, * result;
char *d;
int i;
sprintf(ikey,"%s.%d",key,n);
search.key=ikey;
result = mavl_get_first(cfg,&search);
printf("KEY: %s\n",search.key);
printf("NNNNN: %s\n",result->key);
if (result==NULL)
return -1;
d=NULL;
for (i = strlen(ikey); i>=0; i--){
if (ikey[i]=='.'){
d = result->key+i;
break;
}
}
if (d==NULL){
return -1;
}
if(result->key[i]!='.'){
return -1;
}
if (strncmp(result->key,ikey,i)!=0)
return -1;
printf("TRANSFER %s\n",result->key+i+1);
return atoi(result->key+i+1);
}
void cw_cfg_iterate(cw_Cfg_t * cfg)
{
printf("Iterate\n");
struct cw_Cfg_entry *e;
struct cw_Cfg_entry search;
search.key="actube/listen";
int i=0;
i = cw_cfg_get_next_idx(cfg,"actube/listen",i);
printf("This i %d\n",i);
while ( (i = cw_cfg_get_next_idx(cfg,"actube/listen",i))!=-1) {
printf("Here i %d\n",i);
printf("we have key: %s.%d\n","actube/listen",i);
printf("Next=%d\n",i);
i++;
};
e = mavl_get_first(cfg,&search);
if (!e){
printf("NULL\n");
return;
}
printf("%s : %s\n",e->key,e->val);
}

View File

@ -18,7 +18,7 @@ struct cw_Cfg_entry{
char *val;
};
const char * cw_cfg_get(cw_Cfg_t * cfg, char *key, const char *def);
char * cw_cfg_get(cw_Cfg_t * cfg, char *key);
#endif