2017-11-30 11:13:15 +00:00
|
|
|
#define TRACE_MODULE _gtp_node
|
|
|
|
|
2017-12-01 15:44:07 +00:00
|
|
|
#include "core_debug.h"
|
|
|
|
|
2017-12-05 11:39:15 +00:00
|
|
|
#include "gtp_conv.h"
|
2017-11-30 11:13:15 +00:00
|
|
|
#include "gtp_node.h"
|
2017-12-02 06:49:03 +00:00
|
|
|
#include "gtp_xact.h"
|
2017-12-02 05:17:32 +00:00
|
|
|
|
2017-12-06 14:42:37 +00:00
|
|
|
#define MAX_GTP_NODE_POOL_SIZE 512
|
|
|
|
|
|
|
|
pool_declare(gtp_node_pool, gtp_node_t, MAX_GTP_NODE_POOL_SIZE);
|
2017-12-02 05:17:32 +00:00
|
|
|
|
|
|
|
status_t gtp_node_init(void)
|
|
|
|
{
|
2017-12-06 14:42:37 +00:00
|
|
|
pool_init(>p_node_pool, MAX_GTP_NODE_POOL_SIZE);
|
2017-12-02 05:17:32 +00:00
|
|
|
|
|
|
|
return CORE_OK;
|
|
|
|
}
|
|
|
|
status_t gtp_node_final(void)
|
|
|
|
{
|
|
|
|
if (pool_size(>p_node_pool) != pool_avail(>p_node_pool))
|
|
|
|
d_error("%d not freed in gtp_node_pool[%d]",
|
|
|
|
pool_size(>p_node_pool) - pool_avail(>p_node_pool),
|
|
|
|
pool_size(>p_node_pool));
|
|
|
|
d_trace(3, "%d not freed in gtp_node_pool[%d]\n",
|
|
|
|
pool_size(>p_node_pool) - pool_avail(>p_node_pool),
|
|
|
|
pool_size(>p_node_pool));
|
|
|
|
pool_final(>p_node_pool);
|
|
|
|
|
|
|
|
return CORE_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-05 11:39:15 +00:00
|
|
|
status_t gtp_add_node(list_t *list, gtp_node_t **node,
|
|
|
|
c_sockaddr_t *all_list, int no_ipv4, int no_ipv6, int prefer_ipv4)
|
2017-12-02 05:17:32 +00:00
|
|
|
{
|
2017-12-05 11:39:15 +00:00
|
|
|
status_t rv;
|
|
|
|
gtp_node_t *new_node = NULL;
|
|
|
|
c_sockaddr_t *preferred_list = NULL;
|
|
|
|
|
|
|
|
d_assert(list, return CORE_ERROR,);
|
|
|
|
d_assert(all_list, return CORE_ERROR,);
|
|
|
|
|
|
|
|
rv = core_copyaddrinfo(&preferred_list, all_list);
|
|
|
|
d_assert(rv == CORE_OK, return CORE_ERROR,);
|
|
|
|
if (no_ipv4 == 1)
|
|
|
|
{
|
|
|
|
rv = core_filteraddrinfo(&preferred_list, AF_INET6);
|
|
|
|
d_assert(rv == CORE_OK, return CORE_ERROR,);
|
|
|
|
}
|
|
|
|
if (no_ipv6 == 1)
|
|
|
|
{
|
|
|
|
rv = core_filteraddrinfo(&preferred_list, AF_INET);
|
|
|
|
d_assert(rv == CORE_OK, return CORE_ERROR,);
|
|
|
|
}
|
|
|
|
if (prefer_ipv4 == 1)
|
|
|
|
{
|
|
|
|
rv = core_sortaddrinfo(&preferred_list, AF_INET);
|
|
|
|
d_assert(rv == CORE_OK, return CORE_ERROR,);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = core_sortaddrinfo(&preferred_list, AF_INET6);
|
|
|
|
d_assert(rv == CORE_OK, return CORE_ERROR,);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preferred_list)
|
|
|
|
{
|
|
|
|
pool_alloc_node(>p_node_pool, &new_node);
|
|
|
|
d_assert(new_node, return CORE_ERROR,);
|
|
|
|
memset(new_node, 0, sizeof(gtp_node_t));
|
|
|
|
|
|
|
|
new_node->sa_list = preferred_list;
|
|
|
|
|
|
|
|
list_init(&new_node->local_list);
|
|
|
|
list_init(&new_node->remote_list);
|
|
|
|
|
|
|
|
list_append(list, new_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
*node = new_node;
|
|
|
|
|
|
|
|
return CORE_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-02 05:17:32 +00:00
|
|
|
status_t gtp_remove_node(list_t *list, gtp_node_t *node)
|
|
|
|
{
|
|
|
|
d_assert(node, return CORE_ERROR,);
|
|
|
|
|
|
|
|
list_remove(list, node);
|
|
|
|
|
2017-12-05 04:28:34 +00:00
|
|
|
if (node->sock)
|
|
|
|
sock_delete(node->sock);
|
|
|
|
|
2017-12-02 06:49:03 +00:00
|
|
|
gtp_xact_delete_all(node);
|
|
|
|
|
2017-12-02 05:17:32 +00:00
|
|
|
core_freeaddrinfo(node->sa_list);
|
|
|
|
pool_free_node(>p_node_pool, node);
|
|
|
|
|
|
|
|
return CORE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t gtp_remove_all_nodes(list_t *list)
|
|
|
|
{
|
|
|
|
gtp_node_t *node = NULL, *next_node = NULL;
|
|
|
|
|
|
|
|
node = list_first(list);
|
|
|
|
while(node)
|
|
|
|
{
|
|
|
|
next_node = list_next(node);
|
|
|
|
|
|
|
|
gtp_remove_node(list, node);
|
|
|
|
|
|
|
|
node = next_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CORE_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-07 04:27:17 +00:00
|
|
|
gtp_node_t* gtp_find_node(list_t *list, gtp_f_teid_t *f_teid)
|
2017-12-06 14:42:37 +00:00
|
|
|
{
|
2017-12-07 07:51:21 +00:00
|
|
|
status_t rv;
|
2017-12-07 04:27:17 +00:00
|
|
|
gtp_node_t *node = NULL;
|
2017-12-07 06:04:35 +00:00
|
|
|
ip_t ip;
|
2017-12-06 14:42:37 +00:00
|
|
|
|
2017-12-07 04:27:17 +00:00
|
|
|
d_assert(list, return NULL,);
|
|
|
|
d_assert(f_teid, return NULL,);
|
2017-12-06 14:42:37 +00:00
|
|
|
|
2017-12-07 07:51:21 +00:00
|
|
|
rv = gtp_f_teid_to_ip(f_teid, &ip);
|
|
|
|
d_assert(rv == CORE_OK, return NULL,);
|
2017-12-06 14:42:37 +00:00
|
|
|
|
2017-12-03 07:31:53 +00:00
|
|
|
node = list_first(list);
|
2017-12-05 11:39:15 +00:00
|
|
|
while (node)
|
2017-12-03 07:31:53 +00:00
|
|
|
{
|
2017-12-07 06:04:35 +00:00
|
|
|
if (memcmp(&node->ip, &ip, ip.len) == 0)
|
2017-12-05 11:39:15 +00:00
|
|
|
break;
|
2017-12-03 07:31:53 +00:00
|
|
|
|
2017-12-05 11:39:15 +00:00
|
|
|
node = list_next(node);
|
2017-12-03 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 11:39:15 +00:00
|
|
|
return node;
|
2017-12-03 07:31:53 +00:00
|
|
|
}
|