|
|
|
|
@ -23,11 +23,8 @@
|
|
|
|
|
// Вспомогательные функции
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
static void route_bgp_send_table_request(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn) |
|
|
|
|
{ |
|
|
|
|
if (!bgp || !conn) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
static void route_bgp_send_table_request(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn) { |
|
|
|
|
if (!bgp || !conn) return; |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Sending table request to %s", conn->log_name); |
|
|
|
|
struct BGP_ROUTE_REQUEST* req = u_calloc(1, sizeof(struct BGP_ROUTE_REQUEST)); |
|
|
|
|
if (!req) return; |
|
|
|
|
@ -80,8 +77,7 @@ static char* nodeinfo_format(const uint8_t* data, size_t len) {
|
|
|
|
|
// Broadcast / Withdraw: node_id - удаляемый узел, wd_source - от кого получена команда удалить
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
static void route_bgp_broadcast_withdraw(struct ROUTE_BGP* bgp, uint64_t node_id, uint64_t wd_source, struct ETCP_CONN* exclude) |
|
|
|
|
{ |
|
|
|
|
static void route_bgp_broadcast_withdraw(struct ROUTE_BGP* bgp, uint64_t node_id, uint64_t wd_source, struct ETCP_CONN* exclude) { |
|
|
|
|
if (!bgp) { |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "bgp is NULL"); |
|
|
|
|
return; |
|
|
|
|
@ -125,8 +121,7 @@ static void route_bgp_broadcast_withdraw(struct ROUTE_BGP* bgp, uint64_t node_id
|
|
|
|
|
// Приём пакетов
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry* entry) |
|
|
|
|
{ |
|
|
|
|
static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry* entry) { |
|
|
|
|
if (!from_conn || !entry || entry->len < 2) { |
|
|
|
|
if (entry) { |
|
|
|
|
queue_dgram_free(entry); |
|
|
|
|
@ -413,14 +408,27 @@ void route_bgp_remove_conn(struct ETCP_CONN* conn)
|
|
|
|
|
bool need_withdraw = false; |
|
|
|
|
struct ll_entry* node_entry = bgp->nodes ? bgp->nodes->head : NULL; |
|
|
|
|
while (node_entry) { |
|
|
|
|
struct ll_entry* next = node_entry->next; |
|
|
|
|
struct NODEINFO_Q* nq = (struct NODEINFO_Q*)node_entry; |
|
|
|
|
if (route_bgp_remove_path(nq, conn) == 1) { |
|
|
|
|
need_withdraw = true; |
|
|
|
|
if (rt) { |
|
|
|
|
route_delete(rt, nq); |
|
|
|
|
} |
|
|
|
|
nq->dirty = 1; |
|
|
|
|
if (nq->paths) { |
|
|
|
|
queue_free(nq->paths); |
|
|
|
|
nq->paths = NULL; |
|
|
|
|
} |
|
|
|
|
uint64_t key = nq->node.node_id; |
|
|
|
|
struct ll_entry* entry = node_entry; |
|
|
|
|
if (entry) { |
|
|
|
|
queue_remove_data(bgp->nodes, entry); |
|
|
|
|
queue_entry_free(entry); |
|
|
|
|
} |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Removed node %016llx after link down", (unsigned long long)key); |
|
|
|
|
} |
|
|
|
|
node_entry = node_entry->next; |
|
|
|
|
node_entry = next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Удаляем из списка рассылки
|
|
|
|
|
@ -662,12 +670,14 @@ int route_bgp_process_withdraw(struct ROUTE_BGP* bgp, struct ETCP_CONN* sender,
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int ret=route_bgp_remove_path_by_hop(nq, wd_source); |
|
|
|
|
if (ret>0) { |
|
|
|
|
if (ret>0 || !nq->paths || (nq->paths && queue_entry_count(nq->paths) == 0)) { |
|
|
|
|
if (bgp->instance && bgp->instance->rt) { |
|
|
|
|
route_delete(bgp->instance->rt, nq); |
|
|
|
|
} |
|
|
|
|
nq->dirty = 1; |
|
|
|
|
if (nq->paths) { |
|
|
|
|
queue_free(nq->paths); |
|
|
|
|
nq->paths = NULL; |
|
|
|
|
} |
|
|
|
|
uint64_t key = node_id; |
|
|
|
|
struct ll_entry* entry = queue_find_data_by_index(bgp->nodes, &key, 8); |
|
|
|
|
@ -675,7 +685,6 @@ int route_bgp_process_withdraw(struct ROUTE_BGP* bgp, struct ETCP_CONN* sender,
|
|
|
|
|
queue_remove_data(bgp->nodes, entry); |
|
|
|
|
queue_entry_free(entry); |
|
|
|
|
} |
|
|
|
|
nq->dirty = 1; |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Removed node %016llx after WITHDRAW", (unsigned long long)node_id); |
|
|
|
|
route_bgp_broadcast_withdraw(bgp, node_id, wd_source, sender); |
|
|
|
|
} |
|
|
|
|
@ -683,10 +692,6 @@ int route_bgp_process_withdraw(struct ROUTE_BGP* bgp, struct ETCP_CONN* sender,
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Отправка NODEINFO-пакета (всегда отправляем local_node) |
|
|
|
|
* Сигнатура соответствует объявлению в route_bgp.h |
|
|
|
|
*/ |
|
|
|
|
void route_bgp_send_nodeinfo(struct NODEINFO_Q* node, struct ETCP_CONN* conn) { |
|
|
|
|
if (!node || !conn) { |
|
|
|
|
return; |
|
|
|
|
@ -721,19 +726,3 @@ void route_bgp_send_nodeinfo(struct NODEINFO_Q* node, struct ETCP_CONN* conn) {
|
|
|
|
|
|
|
|
|
|
etcp_send(conn, e); |
|
|
|
|
} |
|
|
|
|
/*
|
|
|
|
|
void route_bgp_broadcast_nodeinfo(struct ROUTE_BGP* bgp, struct NODEINFO_Q* node, struct ETCP_CONN* exclude) { |
|
|
|
|
if (!bgp) return; |
|
|
|
|
|
|
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_BGP, "Broadcasting NODEINFO"); |
|
|
|
|
|
|
|
|
|
struct ll_entry* e = bgp->senders_list ? bgp->senders_list->head : NULL; |
|
|
|
|
while (e) { |
|
|
|
|
struct ROUTE_BGP_CONN_ITEM* item = (struct ROUTE_BGP_CONN_ITEM*)e->data; |
|
|
|
|
if (item->conn && item->conn != exclude) { |
|
|
|
|
route_bgp_send_nodeinfo(node, item->conn); |
|
|
|
|
} |
|
|
|
|
e = e->next; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|