#include "printfrr.h"
#include <lib/json.h>
#include "link_state.h"
+#include "iso.h"
/* Link State Memory allocation */
DEFINE_MTYPE_STATIC(LIB, LS_DB, "Link State Database");
/* Then remove Vertex from Link State Data Base and free memory */
vertices_del(&ted->vertices, vertex);
XFREE(MTYPE_LS_DB, vertex);
- vertex = NULL;
}
void ls_vertex_del_all(struct ls_ted *ted, struct ls_vertex *vertex)
}
}
-static uint64_t get_edge_key(struct ls_attributes *attr, bool dst)
+static struct ls_edge_key get_edge_key(struct ls_attributes *attr, bool dst)
{
- uint64_t key = 0;
+ struct ls_edge_key key = {.family = AF_UNSPEC};
struct ls_standard *std;
if (!attr)
std = &attr->standard;
if (dst) {
- /* Key is the IPv4 remote address */
- if (CHECK_FLAG(attr->flags, LS_ATTR_NEIGH_ADDR))
- key = ((uint64_t)ntohl(std->remote.s_addr))
- & 0xffffffff;
- /* or the 64 bits LSB of IPv6 remote address */
- else if (CHECK_FLAG(attr->flags, LS_ATTR_NEIGH_ADDR6))
- key = ((uint64_t)ntohl(std->remote6.s6_addr32[2]) << 32
- | (uint64_t)ntohl(std->remote6.s6_addr32[3]));
- /* of remote identifier if no IP addresses are defined */
- else if (CHECK_FLAG(attr->flags, LS_ATTR_NEIGH_ID))
- key = (((uint64_t)std->remote_id) & 0xffffffff)
- | ((uint64_t)std->local_id << 32);
+ if (CHECK_FLAG(attr->flags, LS_ATTR_NEIGH_ADDR)) {
+ /* Key is the IPv4 remote address */
+ key.family = AF_INET;
+ IPV4_ADDR_COPY(&key.k.addr, &std->remote);
+ } else if (CHECK_FLAG(attr->flags, LS_ATTR_NEIGH_ADDR6)) {
+ /* or the IPv6 remote address */
+ key.family = AF_INET6;
+ IPV6_ADDR_COPY(&key.k.addr6, &std->remote6);
+ } else if (CHECK_FLAG(attr->flags, LS_ATTR_NEIGH_ID)) {
+ /* or Remote identifier if IP addr. are not defined */
+ key.family = AF_LOCAL;
+ key.k.link_id =
+ (((uint64_t)std->remote_id) & 0xffffffff) |
+ ((uint64_t)std->local_id << 32);
+ }
} else {
- /* Key is the IPv4 local address */
- if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ADDR))
- key = ((uint64_t)ntohl(std->local.s_addr)) & 0xffffffff;
- /* or the 64 bits LSB of IPv6 local address */
- else if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ADDR6))
- key = ((uint64_t)ntohl(std->local6.s6_addr32[2]) << 32
- | (uint64_t)ntohl(std->local6.s6_addr32[3]));
- /* of local identifier if no IP addresses are defined */
- else if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ID))
- key = (((uint64_t)std->local_id) & 0xffffffff)
- | ((uint64_t)std->remote_id << 32);
+ if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ADDR)) {
+ /* Key is the IPv4 local address */
+ key.family = AF_INET;
+ IPV4_ADDR_COPY(&key.k.addr, &std->local);
+ } else if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ADDR6)) {
+ /* or the 64 bits LSB of IPv6 local address */
+ key.family = AF_INET6;
+ IPV6_ADDR_COPY(&key.k.addr6, &std->local6);
+ } else if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ID)) {
+ /* or Remote identifier if IP addr. are not defined */
+ key.family = AF_LOCAL;
+ key.k.link_id =
+ (((uint64_t)std->local_id) & 0xffffffff) |
+ ((uint64_t)std->remote_id << 32);
+ }
}
return key;
struct ls_attributes *attributes)
{
struct ls_edge *new;
- uint64_t key = 0;
+ struct ls_edge_key key;
if (attributes == NULL)
return NULL;
key = get_edge_key(attributes, false);
- if (key == 0)
+ if (key.family == AF_UNSPEC)
return NULL;
/* Create Edge and add it to the TED */
return new;
}
-struct ls_edge *ls_find_edge_by_key(struct ls_ted *ted, const uint64_t key)
+struct ls_edge *ls_find_edge_by_key(struct ls_ted *ted,
+ const struct ls_edge_key key)
{
struct ls_edge edge = {};
- if (key == 0)
+ if (key.family == AF_UNSPEC)
return NULL;
edge.key = key;
return NULL;
edge.key = get_edge_key(attributes, false);
- if (edge.key == 0)
+ if (edge.key.family == AF_UNSPEC)
return NULL;
return edges_find(&ted->edges, &edge);
return NULL;
edge.key = get_edge_key(attributes, true);
- if (edge.key == 0)
+ if (edge.key.family == AF_UNSPEC)
return NULL;
return edges_find(&ted->edges, &edge);
if (!e1 && !e2)
return 1;
- if (e1->key != e2->key)
+ if (edge_cmp(e1, e2) != 0)
return 0;
if (e1->attributes == e2->attributes)
case LS_MSG_EVENT_DELETE:
vertex = ls_find_vertex_by_id(ted, node->adv);
if (vertex) {
- if (delete)
+ if (delete) {
ls_vertex_del_all(ted, vertex);
- else
+ vertex = NULL;
+ } else
vertex->status = DELETE;
}
break;
case LS_MSG_EVENT_DELETE:
subnet = ls_find_subnet(ted, &pref->pref);
if (subnet) {
- if (delete)
+ if (delete) {
ls_subnet_del_all(ted, subnet);
- else
+ subnet = NULL;
+ } else
subnet->status = DELETE;
}
break;
if (msg == NULL)
return;
+ if (msg->event == LS_MSG_EVENT_DELETE) {
+ switch (msg->type) {
+ case LS_MSG_TYPE_NODE:
+ ls_node_del(msg->data.node);
+ break;
+ case LS_MSG_TYPE_ATTRIBUTES:
+ ls_attributes_del(msg->data.attr);
+ break;
+ case LS_MSG_TYPE_PREFIX:
+ ls_prefix_del(msg->data.prefix);
+ break;
+ }
+ }
+
XFREE(MTYPE_LS_DB, msg);
}
static const char *ls_node_id_to_text(struct ls_node_id lnid, char *str,
size_t size)
{
- if (lnid.origin == ISIS_L1 || lnid.origin == ISIS_L2) {
- uint8_t *id;
-
- id = lnid.id.iso.sys_id;
- snprintfrr(str, size, "%02x%02x.%02x%02x.%02x%02x", id[0],
- id[1], id[2], id[3], id[4], id[5]);
- } else
+ if (lnid.origin == ISIS_L1 || lnid.origin == ISIS_L2)
+ snprintfrr(str, size, "%pSY", lnid.id.iso.sys_id);
+ else
snprintfrr(str, size, "%pI4", &lnid.id.ip.addr);
return str;
}
}
+static const char *edge_key_to_text(struct ls_edge_key key)
+{
+#define FORMAT_BUF_COUNT 4
+ static char buf_ring[FORMAT_BUF_COUNT][INET6_BUFSIZ];
+ static size_t cur_buf = 0;
+ char *rv;
+
+ rv = buf_ring[cur_buf];
+ cur_buf = (cur_buf + 1) % FORMAT_BUF_COUNT;
+
+ switch (key.family) {
+ case AF_INET:
+ snprintfrr(rv, INET6_BUFSIZ, "%pI4", &key.k.addr);
+ break;
+ case AF_INET6:
+ snprintfrr(rv, INET6_BUFSIZ, "%pI6", &key.k.addr6);
+ break;
+ case AF_LOCAL:
+ snprintfrr(rv, INET6_BUFSIZ, "%" PRIu64, key.k.link_id);
+ break;
+ default:
+ snprintfrr(rv, INET6_BUFSIZ, "(Unknown)");
+ break;
+ }
+
+ return rv;
+}
+
static void ls_show_edge_vty(struct ls_edge *edge, struct vty *vty,
bool verbose)
{
attr = edge->attributes;
sbuf_init(&sbuf, NULL, 0);
- sbuf_push(&sbuf, 2, "Edge (%" PRIu64 "): ", edge->key);
+ sbuf_push(&sbuf, 2, "Edge (%s): ", edge_key_to_text(edge->key));
if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ADDR))
sbuf_push(&sbuf, 0, "%pI4", &attr->standard.local);
else if (CHECK_FLAG(attr->flags, LS_ATTR_LOCAL_ADDR6))
attr = edge->attributes;
- json_object_int_add(json, "edge-id", edge->key);
+ json_object_string_add(json, "edge-id", edge_key_to_text(edge->key));
json_object_string_add(json, "status", status2txt[edge->status]);
json_object_string_add(json, "origin", origin2txt[attr->adv.origin]);
ls_node_id_to_text(attr->adv, buf, INET6_BUFSIZ);
for (ALL_LIST_ELEMENTS_RO(vertex->incoming_edges, lst_node,
vertex_edge)) {
zlog_debug(
- " inc edge key:%" PRIu64 " attr key:%pI4 loc:(%pI4) rmt:(%pI4)",
- vertex_edge->key,
+ " inc edge key:%s attr key:%pI4 loc:(%pI4) rmt:(%pI4)",
+ edge_key_to_text(vertex_edge->key),
&vertex_edge->attributes->adv.id.ip.addr,
&vertex_edge->attributes->standard.local,
&vertex_edge->attributes->standard.remote);
for (ALL_LIST_ELEMENTS_RO(vertex->outgoing_edges, lst_node,
vertex_edge)) {
zlog_debug(
- " out edge key:%" PRIu64 " attr key:%pI4 loc:(%pI4) rmt:(%pI4)",
- vertex_edge->key,
+ " out edge key:%s attr key:%pI4 loc:(%pI4) rmt:(%pI4)",
+ edge_key_to_text(vertex_edge->key),
&vertex_edge->attributes->adv.id.ip.addr,
&vertex_edge->attributes->standard.local,
&vertex_edge->attributes->standard.remote);
}
}
frr_each (edges, &ted->edges, edge) {
- zlog_debug(" Ted edge key:%" PRIu64 "src:%pI4 dst:%pI4", edge->key,
+ zlog_debug(" Ted edge key:%s src:%pI4 dst:%pI4",
+ edge_key_to_text(edge->key),
edge->source ? &edge->source->node->router_id
: &inaddr_any,
edge->destination