freewtp/src/common/capwap_element_acipv4list.c

78 lines
2.4 KiB
C
Raw Normal View History

2013-05-01 14:52:55 +02:00
#include "capwap.h"
#include "capwap_element.h"
/********************************************************************
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IP Address[] |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Type: 2 for AC IPv4 List
2013-05-01 14:52:55 +02:00
Length: >= 4
********************************************************************/
/* */
static void capwap_acipv4list_element_create(void* data, capwap_message_elements_handle handle, struct capwap_write_message_elements_ops* func) {
unsigned long i;
struct capwap_acipv4list_element* element = (struct capwap_acipv4list_element*)data;
2013-05-01 14:52:55 +02:00
ASSERT(data != NULL);
2013-05-01 14:52:55 +02:00
/* */
for (i = 0; i < element->addresses->count; i++) {
func->write_block(handle, (uint8_t*)capwap_array_get_item_pointer(element->addresses, i), sizeof(struct in_addr));
2013-05-01 14:52:55 +02:00
}
}
/* */
static void* capwap_acipv4list_element_parsing(capwap_message_elements_handle handle, struct capwap_read_message_elements_ops* func) {
uint16_t length;
struct capwap_acipv4list_element* data;
2013-05-01 14:52:55 +02:00
ASSERT(handle != NULL);
ASSERT(func != NULL);
length = func->read_ready(handle);
if ((length >= 4) && (length <= CAPWAP_ACIPV4LIST_MAX_ELEMENTS * 4) && (length % 4)) {
capwap_logging_debug("Invalid AC IPv4 List element: unbuffer");
2013-05-01 14:52:55 +02:00
return NULL;
}
/* */
data = (struct capwap_acipv4list_element*)capwap_alloc(sizeof(struct capwap_acipv4list_element));
if (!data) {
capwap_outofmemory();
}
2013-05-01 14:52:55 +02:00
/* Retrieve data */
data->addresses = capwap_array_create(sizeof(struct in_addr), 0, 0);
while (length > 0) {
struct in_addr* address = (struct in_addr*)capwap_array_get_item_pointer(data->addresses, data->addresses->count);
func->read_block(handle, (uint8_t*)address, sizeof(struct in_addr));
length -= 4;
2013-05-01 14:52:55 +02:00
}
return data;
}
/* */
static void capwap_acipv4list_element_free(void* data) {
struct capwap_acipv4list_element* element = (struct capwap_acipv4list_element*)data;
2013-05-01 14:52:55 +02:00
ASSERT(data != NULL);
capwap_array_free(element->addresses);
capwap_free(data);
2013-05-01 14:52:55 +02:00
}
/* */
struct capwap_message_elements_ops capwap_element_acipv4list_ops = {
.create_message_element = capwap_acipv4list_element_create,
.parsing_message_element = capwap_acipv4list_element_parsing,
.free_parsed_message_element = capwap_acipv4list_element_free
};