rework MAC type handling so that split, local and both MAC's are possible
This commit is contained in:
parent
0df59ddaad
commit
627ecd5a9e
@ -1,47 +1,58 @@
|
||||
#include "capwap.h"
|
||||
#include "capwap_element.h"
|
||||
|
||||
/********************************************************************
|
||||
|
||||
0
|
||||
0 1 2 3 4 5 6 7
|
||||
+-+-+-+-+-+-+-+-+
|
||||
| MAC Type |
|
||||
+-+-+-+-+-+-+-+-+
|
||||
|
||||
Type: 44 for WTP MAC Type
|
||||
|
||||
Length: 1
|
||||
|
||||
********************************************************************/
|
||||
/*
|
||||
*
|
||||
* 0
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* +-+-+-+-+-+-+-+-+
|
||||
* | MAC Type |
|
||||
* +-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* Type: 44 for WTP MAC Type
|
||||
*
|
||||
* Length: 1
|
||||
*
|
||||
*/
|
||||
|
||||
/* */
|
||||
static void 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;
|
||||
static void
|
||||
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((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);
|
||||
}
|
||||
|
||||
/* */
|
||||
static void* capwap_wtpmactype_element_clone(void* data) {
|
||||
static void *capwap_wtpmactype_element_clone(void *data)
|
||||
{
|
||||
ASSERT(data != NULL);
|
||||
|
||||
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);
|
||||
|
||||
capwap_free(data);
|
||||
}
|
||||
|
||||
/* */
|
||||
static void* capwap_wtpmactype_element_parsing(capwap_message_elements_handle handle, struct capwap_read_message_elements_ops* func) {
|
||||
static void *
|
||||
capwap_wtpmactype_element_parsing(capwap_message_elements_handle handle,
|
||||
struct capwap_read_message_elements_ops *func)
|
||||
{
|
||||
struct capwap_wtpmactype_element *data;
|
||||
|
||||
ASSERT(handle != NULL);
|
||||
@ -53,9 +64,14 @@ static void* capwap_wtpmactype_element_parsing(capwap_message_elements_handle ha
|
||||
}
|
||||
|
||||
/* 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);
|
||||
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);
|
||||
log_printf(LOG_DEBUG, "Invalid WTP MAC Type element: invalid type");
|
||||
return NULL;
|
||||
|
@ -3,7 +3,11 @@
|
||||
|
||||
#define CAPWAP_ELEMENT_WTPMACTYPE_VENDOR 0
|
||||
#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
|
||||
|
@ -804,6 +804,20 @@ static int wtp_parsing_cfg_descriptor_info(config_t *config)
|
||||
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 */
|
||||
static int wtp_parsing_configuration_1_0(config_t* config) {
|
||||
int i;
|
||||
@ -946,13 +960,42 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
||||
}
|
||||
|
||||
/* Set mactype of WTP */
|
||||
if (config_lookup_string(config, "application.mactype", &configString) == CONFIG_TRUE) {
|
||||
if (!strcmp(configString, "localmac")) {
|
||||
configSetting = config_lookup(config, "application.mactype");
|
||||
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;
|
||||
} else if (!strcmp(configString, "splitmac")) {
|
||||
break;
|
||||
case 0x02:
|
||||
g_wtp.mactype.type = CAPWAP_SPLITMAC;
|
||||
} else {
|
||||
log_printf(LOG_ERR, "Invalid configuration file, unknown application.mactype value");
|
||||
break;
|
||||
case 0x03:
|
||||
g_wtp.mactype.type = CAPWAP_LOCALANDSPLITMAC;
|
||||
break;
|
||||
default:
|
||||
log_printf(LOG_ERR, "Invalid configuration file, invalid application.mactype value");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user