If not set into wtp.conf the client bind to any port

This commit is contained in:
vemax78 2013-05-28 22:22:16 +02:00
parent 16fe0bb6bd
commit 37e60bb755
4 changed files with 35 additions and 20 deletions

View File

@ -20,10 +20,11 @@ static int ac_init(void) {
capwap_network_init(&g_ac.net);
g_ac.mtu = CAPWAP_MTU_DEFAULT;
g_ac.binding = capwap_array_create(sizeof(unsigned short), 0);
g_ac.net.bind_sock_ctrl_port = CAPWAP_CONTROL_PORT;
/* Standard name */
strcpy((char*)g_ac.acname.name, AC_STANDARD_NAME);
/* Descriptor */
g_ac.descriptor.stationlimit = AC_DEFAULT_MAXSTATION;
g_ac.descriptor.maxwtp = AC_DEFAULT_MAXSESSIONS;
@ -477,6 +478,16 @@ static int ac_parsing_configuration_1_0(config_t* config) {
}
}
/* Set network port of WTP */
if (config_lookup_int(config, "application.network.port", &configLongInt) == CONFIG_TRUE) {
if ((configLongInt > 0) && (configLongInt < 65535)) {
g_ac.net.bind_sock_ctrl_port = (unsigned short)configLongInt;
} else {
capwap_logging_error("Invalid configuration file, invalid application.network.port value");
return 0;
}
}
/* Set transport of AC */
if (config_lookup_string(config, "application.network.transport", &configString) == CONFIG_TRUE) {
if (!strcmp(configString, "udp")) {

View File

@ -625,7 +625,7 @@ void* ac_session_thread(void* param) {
void ac_get_control_information(struct capwap_list* controllist) {
struct capwap_list* addrlist;
struct capwap_list_item* item;
ASSERT(controllist != NULL);
/* Detect local address */
@ -646,22 +646,22 @@ void ac_get_control_information(struct capwap_list* controllist) {
/* Add */
capwap_itemlist_insert_after(controllist, NULL, itemcontrol);
}
}
/* Free local address list */
capwap_list_free(addrlist);
/* */
capwap_lock_enter(&g_ac.sessionslock);
/* Get wtp count from any local address */
for (item = controllist->first; item != NULL; item = item->next) {
struct capwap_list_item* search;
struct ac_session_control* sessioncontrol = (struct ac_session_control*)item->item;
for (search = g_ac.sessions->first; search != NULL; search = search->next) {
struct ac_session_t* session = (struct ac_session_t*)search->item;
if (!capwap_compare_ip(&session->acctrladdress, &sessioncontrol->localaddress)) {
sessioncontrol->count++;
}

View File

@ -145,7 +145,6 @@ static int capwap_prepare_bind_socket(struct capwap_network* net, int socketfami
struct sockaddr_storage bindaddr;
ASSERT(net != NULL);
ASSERT(net->bind_sock_ctrl_port != 0);
ASSERT((socketfamily == AF_INET) || (socketfamily == AF_INET6));
ASSERT((socketprotocol == IPPROTO_UDP) || (socketprotocol == IPPROTO_UDPLITE));
@ -170,7 +169,7 @@ static int capwap_prepare_bind_socket(struct capwap_network* net, int socketfami
if (sock_data >= 0) {
if (!capwap_configure_socket(sock_data, socketfamily, socketprotocol, 0, net->bind_interface, net->bind_data_flags)) {
/* Bind address */
CAPWAP_SET_NETWORK_PORT(&bindaddr, net->bind_sock_ctrl_port + 1);
CAPWAP_SET_NETWORK_PORT(&bindaddr, (!net->bind_sock_ctrl_port ? 0 : net->bind_sock_ctrl_port + 1));
if (!bind(sock_data, (struct sockaddr*)&bindaddr, sizeof(struct sockaddr_storage))) {
result = 1;
capwap_save_socket(net, socketfamily, socketprotocol, sock_ctrl, sock_data);
@ -453,8 +452,12 @@ void capwap_network_init(struct capwap_network* net) {
ASSERT(net != NULL);
/* */
memset(net, 0, sizeof(struct capwap_network));
/* */
net->sock_family = AF_UNSPEC;
net->bind_sock_ctrl_port = CAPWAP_CONTROL_PORT;
net->bind_sock_ctrl_port = INADDR_ANY;
for (i = 0; i < CAPWAP_MAX_SOCKETS; i++) {
net->sock_ctrl[i] = -1;
net->sock_data[i] = -1;
@ -1211,13 +1214,14 @@ int capwap_get_localaddress_by_remoteaddress(struct sockaddr_storage* local, str
void capwap_interface_list(struct capwap_network* net, struct capwap_list* list) {
struct ifaddrs* ifaddrlist;
struct ifaddrs* ifcurrentpos;
ASSERT(net != NULL);
ASSERT(list != NULL);
/* Get interface list */
if (getifaddrs(&ifaddrlist) != 0)
return;
if (getifaddrs(&ifaddrlist) != 0) {
return;
}
/* */
for (ifcurrentpos = ifaddrlist; ifcurrentpos != NULL; ifcurrentpos = ifcurrentpos->ifa_next) {
@ -1243,25 +1247,25 @@ void capwap_interface_list(struct capwap_network* net, struct capwap_list* list)
if ((net->bind_interface[0] != 0) && (strcmp(net->bind_interface, ifcurrentpos->ifa_name) != 0)) {
continue;
}
/* Add local address */
item = capwap_itemlist_create(sizeof(struct sockaddr_storage));
addr = (struct sockaddr_storage*)item->item;
memset(addr, 0, sizeof(struct sockaddr_storage));
addr->ss_family = ifcurrentpos->ifa_addr->sa_family;
CAPWAP_SET_NETWORK_PORT(addr, net->bind_sock_ctrl_port);
if (addr->ss_family == AF_INET) {
memcpy(&((struct sockaddr_in*)addr)->sin_addr, &((struct sockaddr_in*)ifcurrentpos->ifa_addr)->sin_addr, sizeof(struct in_addr));
} else if (addr->ss_family == AF_INET6) {
memcpy(&((struct sockaddr_in6*)addr)->sin6_addr, &((struct sockaddr_in6*)ifcurrentpos->ifa_addr)->sin6_addr, sizeof(struct in6_addr));
}
/* Add address */
capwap_itemlist_insert_after(list, NULL, item);
}
/* Free */
freeifaddrs(ifaddrlist);
}

View File

@ -753,7 +753,7 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
/* Set network port of WTP */
if (config_lookup_int(config, "application.network.port", &configLongInt) == CONFIG_TRUE) {
if ((configLongInt > 0) && (configLongInt < 65536)) {
if ((configLongInt > 0) && (configLongInt < 65535)) {
g_wtp.net.bind_sock_ctrl_port = (unsigned short)configLongInt;
} else {
capwap_logging_error("Invalid configuration file, invalid application.network.port value");