Parser for new listen address syntax added.
FossilOrigin-Name: cf7162fa76324c9c2fa516b8a60339b72d85272778d2f4c08ecb7df77defddd0
This commit is contained in:
parent
c1255f8261
commit
9a6da5aca1
136
src/ac/conf.c
136
src/ac/conf.c
@ -31,6 +31,8 @@
|
||||
#include "capwap/cw_util.h"
|
||||
#include "capwap/action.h"
|
||||
|
||||
#include "ac.h"
|
||||
|
||||
uint8_t conf_macaddress[12];
|
||||
uint8_t conf_macaddress_len = 0;
|
||||
|
||||
@ -148,12 +150,14 @@ static int init_acid()
|
||||
#endif
|
||||
|
||||
if (!conf_primary_if) {
|
||||
cw_log(LOG_ERR,"Fatal: Unable to detect primary interface, needed to set ac_id. Pleas use confiPleas u to set ac_id");
|
||||
cw_log(LOG_ERR,
|
||||
"Fatal: Unable to detect primary interface, needed to set ac_id. Pleas use confiPleas u to set ac_id");
|
||||
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);
|
||||
cw_log(LOG_ERR, "Fatal: Unable to detect link layer address for %s\n",
|
||||
conf_primary_if);
|
||||
return 0;
|
||||
};
|
||||
|
||||
@ -255,12 +259,12 @@ static int init_version()
|
||||
{
|
||||
|
||||
/* Init hardware version */
|
||||
if (!conf_hardware_version)
|
||||
{
|
||||
if (!conf_hardware_version) {
|
||||
struct utsname u;
|
||||
int rc = uname(&u);
|
||||
if (rc < 0)
|
||||
conf_hardware_version=(bstr_t)strdup(CONF_DEFAULT_HARDWARE_VERSION);
|
||||
conf_hardware_version =
|
||||
(bstr_t) strdup(CONF_DEFAULT_HARDWARE_VERSION);
|
||||
else {
|
||||
char str[265];
|
||||
sprintf(str, "%s / %s %s", u.machine, u.sysname, u.release);
|
||||
@ -268,18 +272,22 @@ static int init_version()
|
||||
}
|
||||
|
||||
}
|
||||
bstr_replace(&conf_hardware_version,bstr_create_from_cfgstr((char*)conf_hardware_version));
|
||||
bstr_replace(&conf_hardware_version,
|
||||
bstr_create_from_cfgstr((char *) conf_hardware_version));
|
||||
|
||||
/* software version */
|
||||
if (!conf_software_version)
|
||||
conf_software_version = (bstr_t) strdup(CONF_DEFAULT_SOFTWARE_VERSION);
|
||||
bstr_replace(&conf_software_version,bstr_create_from_cfgstr((char*)conf_software_version));
|
||||
bstr_replace(&conf_software_version,
|
||||
bstr_create_from_cfgstr((char *) conf_software_version));
|
||||
|
||||
|
||||
/* Cisco hardware version */
|
||||
if (!conf_cisco_hardware_version)
|
||||
conf_cisco_hardware_version=(bstr_t)strdup(CONF_DEFAULT_CISCO_HARDWARE_VERSION);
|
||||
bstr_replace(&conf_cisco_hardware_version,bstr_create_from_cfgstr((char*)conf_cisco_hardware_version));
|
||||
conf_cisco_hardware_version =
|
||||
(bstr_t) strdup(CONF_DEFAULT_CISCO_HARDWARE_VERSION);
|
||||
bstr_replace(&conf_cisco_hardware_version,
|
||||
bstr_create_from_cfgstr((char *) conf_cisco_hardware_version));
|
||||
|
||||
/* Cisco software version */
|
||||
/*
|
||||
@ -297,7 +305,9 @@ static int init_control_port()
|
||||
{
|
||||
char str[30];
|
||||
sprintf(str, "%d", CONF_DEFAULT_CONTROL_PORT);
|
||||
conf_control_port=(char*)cw_setstr((uint8_t**)&conf_control_port,(uint8_t*)str,strlen(str));
|
||||
conf_control_port =
|
||||
(char *) cw_setstr((uint8_t **) & conf_control_port, (uint8_t *) str,
|
||||
strlen(str));
|
||||
|
||||
|
||||
#ifdef WITH_LWAPP
|
||||
@ -350,13 +360,14 @@ static int init_listen_addrs()
|
||||
if ((ifa->ifa_flags & IFF_LOOPBACK)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ifa->ifa_addr->sa_family == AF_INET && conf_ipv4) {
|
||||
sock_addrtostr(ifa->ifa_addr, str, 100);
|
||||
*strchr(str, ':') = 0;
|
||||
conf_listen_addrs[ctr]=(char*)cw_setstr((uint8_t**)&conf_listen_addrs[ctr],(uint8_t*)str,strlen(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++;
|
||||
|
||||
@ -368,7 +379,9 @@ static int init_listen_addrs()
|
||||
strcat(str, "%");
|
||||
strcat(str, ifa->ifa_name);
|
||||
}
|
||||
conf_listen_addrs[ctr]=(char*)cw_setstr((uint8_t**)&conf_listen_addrs[ctr],(uint8_t*)str,strlen(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++;
|
||||
}
|
||||
@ -484,7 +497,6 @@ int init_mcast_groups()
|
||||
if (conf_ipv4) {
|
||||
n4 = sizeof(conf_default_mcast_groups_ipv4) / sizeof(char *);
|
||||
}
|
||||
|
||||
#ifdef WITH_IPV6
|
||||
if (conf_ipv6) {
|
||||
n6 = sizeof(conf_default_mcast_groups_ipv6) / sizeof(char *);
|
||||
@ -503,14 +515,18 @@ int init_mcast_groups()
|
||||
int i;
|
||||
for (i = 0; i < n4; i++) {
|
||||
uint8_t *g = (uint8_t *) conf_default_mcast_groups_ipv4[i];
|
||||
conf_mcast_groups[ctr]=(char*)cw_setstr((uint8_t**)&conf_mcast_groups[ctr],g,strlen((char*)g));
|
||||
conf_mcast_groups[ctr] =
|
||||
(char *) cw_setstr((uint8_t **) & conf_mcast_groups[ctr], g,
|
||||
strlen((char *) g));
|
||||
if (conf_mcast_groups[ctr])
|
||||
ctr++;
|
||||
}
|
||||
|
||||
for (i = 0; i < n6; i++) {
|
||||
uint8_t *g = (uint8_t *) conf_default_mcast_groups_ipv6[i];
|
||||
conf_mcast_groups[ctr]=(char*)cw_setstr((uint8_t**)&conf_mcast_groups[ctr],g,strlen((char*)g));
|
||||
conf_mcast_groups[ctr] =
|
||||
(char *) cw_setstr((uint8_t **) & conf_mcast_groups[ctr], g,
|
||||
strlen((char *) g));
|
||||
if (conf_mcast_groups[ctr])
|
||||
ctr++;
|
||||
}
|
||||
@ -591,7 +607,88 @@ void conf_init_capwap_mode()
|
||||
}
|
||||
|
||||
|
||||
int read_config(const char * filename){
|
||||
|
||||
int conf_parse_listen_addr(const char *addrstr, char *saddr, char *port, int *proto)
|
||||
{
|
||||
char *p = strchr(addrstr, '/');
|
||||
if (!p)
|
||||
*proto = AC_PROTO_CAPWAP;
|
||||
else {
|
||||
if (strcmp("capwap", p + 1) == 0)
|
||||
*proto = AC_PROTO_CAPWAP;
|
||||
else if (strcmp("lwapp", p + 1) == 0)
|
||||
*proto = AC_PROTO_LWAPP;
|
||||
else
|
||||
*proto = AC_PROTO_UNKNOWN;
|
||||
}
|
||||
|
||||
char *ctrlport;
|
||||
switch (*proto) {
|
||||
case AC_PROTO_CAPWAP:
|
||||
ctrlport = CAPWAP_CONTROL_PORT_STR;
|
||||
break;
|
||||
case AC_PROTO_LWAPP:
|
||||
ctrlport = LWAPP_CONTROL_PORT_STR;
|
||||
break;
|
||||
default:
|
||||
ctrlport = "0";
|
||||
}
|
||||
|
||||
|
||||
int i, l;
|
||||
int c = 0;
|
||||
|
||||
if (p)
|
||||
l = p - addrstr;
|
||||
else
|
||||
l = strlen(addrstr);
|
||||
|
||||
for (i = 0; i < l; i++) {
|
||||
if (addrstr[i] == ':')
|
||||
c++;
|
||||
}
|
||||
|
||||
/* no colon found, asume its ipv4 w/o port */
|
||||
if (c == 0) {
|
||||
strncpy(saddr, addrstr, l);
|
||||
saddr[l] = 0;
|
||||
strcpy(port, ctrlport);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* one colon found, so we assume, its an ipv4
|
||||
* address with port */
|
||||
if (c == 1) {
|
||||
char *c = strchr(addrstr, ':');
|
||||
strncpy(saddr, addrstr, c - addrstr);
|
||||
saddr[c - addrstr] = 0;
|
||||
strncpy(port, c + 1, l - (c - addrstr));
|
||||
port[l - (c - addrstr) - 1] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* we assume now, its ipv6 */
|
||||
char *b = strstr(addrstr, "]:");
|
||||
if (!b) {
|
||||
/* ippv6 w/o port */
|
||||
strncpy(saddr, addrstr, l);
|
||||
saddr[l] = 0;
|
||||
strcpy(port, ctrlport);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy(saddr, addrstr + 1, b - addrstr);
|
||||
saddr[b - addrstr - 1] = 0;
|
||||
strncpy(port, b + 2, l - (b - addrstr) - 2);
|
||||
port[l - (b - addrstr) - 2] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int read_config(const char *filename)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
if (!init_control_port())
|
||||
@ -662,7 +759,8 @@ int read_config(const char * filename){
|
||||
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);
|
||||
conf_read_strings(cfg, "mcast_groups", &conf_mcast_groups,
|
||||
&conf_mcast_groups_len);
|
||||
|
||||
/* read ipv4 broadcast addresses */
|
||||
conf_read_strings(cfg, "bcast_addrs", &conf_bcast_addrs, &conf_bcast_addrs_len);
|
||||
@ -728,5 +826,3 @@ void free_config()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -130,4 +130,9 @@ extern long conf_strict_headers;
|
||||
extern int conf_capwap_mode;
|
||||
|
||||
|
||||
|
||||
extern int conf_parse_listen_addr(const char *addr, char *saddr, char *port, int *proto);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user