rework MAC type handling so that split, local and both MAC's are possible
This commit is contained in:
parent
0df59ddaad
commit
627ecd5a9e
@ -1,48 +1,59 @@
|
|||||||
#include "capwap.h"
|
#include "capwap.h"
|
||||||
#include "capwap_element.h"
|
#include "capwap_element.h"
|
||||||
|
|
||||||
/********************************************************************
|
/*
|
||||||
|
*
|
||||||
0
|
* 0
|
||||||
0 1 2 3 4 5 6 7
|
* 0 1 2 3 4 5 6 7
|
||||||
+-+-+-+-+-+-+-+-+
|
* +-+-+-+-+-+-+-+-+
|
||||||
| MAC Type |
|
* | MAC Type |
|
||||||
+-+-+-+-+-+-+-+-+
|
* +-+-+-+-+-+-+-+-+
|
||||||
|
*
|
||||||
Type: 44 for WTP MAC Type
|
* Type: 44 for WTP MAC Type
|
||||||
|
*
|
||||||
Length: 1
|
* Length: 1
|
||||||
|
*
|
||||||
********************************************************************/
|
*/
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
static void capwap_wtpmactype_element_create(void* data, capwap_message_elements_handle handle, struct capwap_write_message_elements_ops* func) {
|
static void
|
||||||
struct capwap_wtpmactype_element* element = (struct capwap_wtpmactype_element*)data;
|
capwap_wtpmactype_element_create(void *data, capwap_message_elements_handle handle,
|
||||||
|
struct capwap_write_message_elements_ops *func)
|
||||||
|
{
|
||||||
|
struct capwap_wtpmactype_element *element =
|
||||||
|
(struct capwap_wtpmactype_element*)data;
|
||||||
|
|
||||||
ASSERT(data != NULL);
|
ASSERT(data != NULL);
|
||||||
ASSERT((element->type == CAPWAP_LOCALMAC) || (element->type == CAPWAP_SPLITMAC) || (element->type == CAPWAP_LOCALANDSPLITMAC));
|
ASSERT((element->type == CAPWAP_LOCALMAC) ||
|
||||||
|
(element->type == CAPWAP_SPLITMAC) ||
|
||||||
|
(element->type == CAPWAP_LOCALANDSPLITMAC));
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
func->write_u8(handle, element->type);
|
func->write_u8(handle, element->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
static void* capwap_wtpmactype_element_clone(void* data) {
|
static void *capwap_wtpmactype_element_clone(void *data)
|
||||||
|
{
|
||||||
ASSERT(data != NULL);
|
ASSERT(data != NULL);
|
||||||
|
|
||||||
return capwap_clone(data, sizeof(struct capwap_wtpmactype_element));
|
return capwap_clone(data, sizeof(struct capwap_wtpmactype_element));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
static void capwap_wtpmactype_element_free(void* data) {
|
static void capwap_wtpmactype_element_free(void *data)
|
||||||
|
{
|
||||||
ASSERT(data != NULL);
|
ASSERT(data != NULL);
|
||||||
|
|
||||||
capwap_free(data);
|
capwap_free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
static void* capwap_wtpmactype_element_parsing(capwap_message_elements_handle handle, struct capwap_read_message_elements_ops* func) {
|
static void *
|
||||||
struct capwap_wtpmactype_element* data;
|
capwap_wtpmactype_element_parsing(capwap_message_elements_handle handle,
|
||||||
|
struct capwap_read_message_elements_ops *func)
|
||||||
|
{
|
||||||
|
struct capwap_wtpmactype_element *data;
|
||||||
|
|
||||||
ASSERT(handle != NULL);
|
ASSERT(handle != NULL);
|
||||||
ASSERT(func != NULL);
|
ASSERT(func != NULL);
|
||||||
@ -53,9 +64,14 @@ static void* capwap_wtpmactype_element_parsing(capwap_message_elements_handle ha
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Retrieve data */
|
/* Retrieve data */
|
||||||
data = (struct capwap_wtpmactype_element*)capwap_alloc(sizeof(struct capwap_wtpmactype_element));
|
data = (struct capwap_wtpmactype_element *)
|
||||||
|
capwap_alloc(sizeof(struct capwap_wtpmactype_element));
|
||||||
|
|
||||||
func->read_u8(handle, &data->type);
|
func->read_u8(handle, &data->type);
|
||||||
if ((data->type != CAPWAP_LOCALMAC) && (data->type != CAPWAP_SPLITMAC) && (data->type != CAPWAP_LOCALANDSPLITMAC)) {
|
if ((data->type != CAPWAP_LOCALMAC) &&
|
||||||
|
(data->type != CAPWAP_SPLITMAC) &&
|
||||||
|
(data->type != CAPWAP_LOCALANDSPLITMAC))
|
||||||
|
{
|
||||||
capwap_wtpmactype_element_free((void*)data);
|
capwap_wtpmactype_element_free((void*)data);
|
||||||
log_printf(LOG_DEBUG, "Invalid WTP MAC Type element: invalid type");
|
log_printf(LOG_DEBUG, "Invalid WTP MAC Type element: invalid type");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
#ifndef __CAPWAP_ELEMENT_WTPMACTYPE_HEADER__
|
#ifndef __CAPWAP_ELEMENT_WTPMACTYPE_HEADER__
|
||||||
#define __CAPWAP_ELEMENT_WTPMACTYPE_HEADER__
|
#define __CAPWAP_ELEMENT_WTPMACTYPE_HEADER__
|
||||||
|
|
||||||
#define CAPWAP_ELEMENT_WTPMACTYPE_VENDOR 0
|
#define CAPWAP_ELEMENT_WTPMACTYPE_VENDOR 0
|
||||||
#define CAPWAP_ELEMENT_WTPMACTYPE_TYPE 44
|
#define CAPWAP_ELEMENT_WTPMACTYPE_TYPE 44
|
||||||
#define CAPWAP_ELEMENT_WTPMACTYPE (struct capwap_message_element_id){ .vendor = CAPWAP_ELEMENT_WTPMACTYPE_VENDOR, .type = CAPWAP_ELEMENT_WTPMACTYPE_TYPE }
|
#define CAPWAP_ELEMENT_WTPMACTYPE \
|
||||||
|
(struct capwap_message_element_id) { \
|
||||||
|
.vendor = CAPWAP_ELEMENT_WTPMACTYPE_VENDOR, \
|
||||||
|
.type = CAPWAP_ELEMENT_WTPMACTYPE_TYPE \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define CAPWAP_LOCALMAC 0
|
#define CAPWAP_LOCALMAC 0
|
||||||
#define CAPWAP_SPLITMAC 1
|
#define CAPWAP_SPLITMAC 1
|
||||||
#define CAPWAP_LOCALANDSPLITMAC 2
|
#define CAPWAP_LOCALANDSPLITMAC 2
|
||||||
|
|
||||||
struct capwap_wtpmactype_element {
|
struct capwap_wtpmactype_element {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
|
@ -804,6 +804,20 @@ static int wtp_parsing_cfg_descriptor_info(config_t *config)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int wtp_parsing_mac_type(const char *str, int *type)
|
||||||
|
{
|
||||||
|
if (!strcmp(str, "localmac")) {
|
||||||
|
*type |= 0x01;
|
||||||
|
} else if (!strcmp(str, "splitmac")) {
|
||||||
|
*type |= 0x02;
|
||||||
|
} else {
|
||||||
|
log_printf(LOG_ERR, "Invalid configuration file, unknown application.mactype value");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parsing configuration */
|
/* Parsing configuration */
|
||||||
static int wtp_parsing_configuration_1_0(config_t* config) {
|
static int wtp_parsing_configuration_1_0(config_t* config) {
|
||||||
int i;
|
int i;
|
||||||
@ -946,13 +960,42 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set mactype of WTP */
|
/* Set mactype of WTP */
|
||||||
if (config_lookup_string(config, "application.mactype", &configString) == CONFIG_TRUE) {
|
configSetting = config_lookup(config, "application.mactype");
|
||||||
if (!strcmp(configString, "localmac")) {
|
if (configSetting != NULL) {
|
||||||
|
int type = 0;
|
||||||
|
|
||||||
|
switch (config_setting_type(configSetting)) {
|
||||||
|
case CONFIG_TYPE_ARRAY: {
|
||||||
|
int count = config_setting_length(configSetting);
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
if (!wtp_parsing_mac_type(config_setting_get_string_elem(configSetting, i), &type))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CONFIG_TYPE_STRING:
|
||||||
|
if (!wtp_parsing_mac_type(config_setting_get_string(configSetting), &type))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
log_printf(LOG_ERR, "Invalid configuration file, invalid application.mactype type");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 0x01:
|
||||||
g_wtp.mactype.type = CAPWAP_LOCALMAC;
|
g_wtp.mactype.type = CAPWAP_LOCALMAC;
|
||||||
} else if (!strcmp(configString, "splitmac")) {
|
break;
|
||||||
|
case 0x02:
|
||||||
g_wtp.mactype.type = CAPWAP_SPLITMAC;
|
g_wtp.mactype.type = CAPWAP_SPLITMAC;
|
||||||
} else {
|
break;
|
||||||
log_printf(LOG_ERR, "Invalid configuration file, unknown application.mactype value");
|
case 0x03:
|
||||||
|
g_wtp.mactype.type = CAPWAP_LOCALANDSPLITMAC;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log_printf(LOG_ERR, "Invalid configuration file, invalid application.mactype value");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user