summaryrefslogtreecommitdiff
path: root/lib/link_state.h
diff options
context:
space:
mode:
authorOlivier Dugeon <olivier.dugeon@orange.com>2023-02-20 19:18:00 +0100
committerOlivier Dugeon <olivier.dugeon@orange.com>2023-04-07 16:40:25 +0200
commit9a9f0b893ea125f6aa664f633c91a4576759fbca (patch)
tree36db394b9753f6ebd64697ba31680581f2b0cca1 /lib/link_state.h
parentbdf62ec61b343adc007a93a66081d26d1483950a (diff)
lib: Update Edge Key in link_state
The original uin64_t for the edge key in link state is not always appropriate with IPv6 addresses. In some cases, 2 different edge with 2 different IPv6 addresses could conduct to the same key. The resulting TED is wrong in this case. This patch replace the uint64_t edge key by a dedicated structure. The resulting key of the edge is: - the local IPv4 address of the corresponding link - the local IPv6 address if no IPv4 address is configured on the link - the local + remote link ID for unnumbered address Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Diffstat (limited to 'lib/link_state.h')
-rw-r--r--lib/link_state.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/link_state.h b/lib/link_state.h
index e6a6388ba4..e4b97a34ed 100644
--- a/lib/link_state.h
+++ b/lib/link_state.h
@@ -382,13 +382,23 @@ struct ls_vertex {
struct list *prefixes; /* List of advertised prefix */
};
+/* Link State Edge Key structure */
+struct ls_edge_key {
+ uint8_t family;
+ union {
+ struct in_addr addr;
+ struct in6_addr addr6;
+ uint64_t link_id;
+ } k;
+};
+
/* Link State Edge structure */
PREDECL_RBTREE_UNIQ(edges);
struct ls_edge {
enum ls_type type; /* Link State Type */
enum ls_status status; /* Status of the Edge in the TED */
struct edges_item entry; /* Entry in RB tree */
- uint64_t key; /* Unique Key identifier */
+ struct ls_edge_key key; /* Unique Key identifier */
struct ls_attributes *attributes; /* Link State attributes */
struct ls_vertex *source; /* Pointer to the source Vertex */
struct ls_vertex *destination; /* Pointer to the destination Vertex */
@@ -416,13 +426,25 @@ DECLARE_RBTREE_UNIQ(vertices, struct ls_vertex, entry, vertex_cmp);
macro_inline int edge_cmp(const struct ls_edge *edge1,
const struct ls_edge *edge2)
{
- return numcmp(edge1->key, edge2->key);
+ if (edge1->key.family != edge2->key.family)
+ return numcmp(edge1->key.family, edge2->key.family);
+
+ switch (edge1->key.family) {
+ case AF_INET:
+ return memcmp(&edge1->key.k.addr, &edge2->key.k.addr, 4);
+ case AF_INET6:
+ return memcmp(&edge1->key.k.addr6, &edge2->key.k.addr6, 16);
+ case AF_LOCAL:
+ return numcmp(edge1->key.k.link_id, edge2->key.k.link_id);
+ default:
+ return 0;
+ }
}
DECLARE_RBTREE_UNIQ(edges, struct ls_edge, entry, edge_cmp);
/*
* Prefix comparison are done to the host part so, 10.0.0.1/24
- * and 10.0.0.2/24 are considered come different
+ * and 10.0.0.2/24 are considered different
*/
macro_inline int subnet_cmp(const struct ls_subnet *a,
const struct ls_subnet *b)
@@ -619,7 +641,7 @@ extern void ls_edge_del_all(struct ls_ted *ted, struct ls_edge *edge);
* @return Edge if found, NULL otherwise
*/
extern struct ls_edge *ls_find_edge_by_key(struct ls_ted *ted,
- const uint64_t key);
+ const struct ls_edge_key key);
/**
* Find Edge in the Link State Data Base by the source (local IPv4 or IPv6