]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_spf.h
Merge pull request #12989 from opensourcerouting/fix/memory_leaks_bgpd
[mirror_frr.git] / ospf6d / ospf6_spf.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2003 Yasuhiro Ohara
4 */
5
6 #ifndef OSPF6_SPF_H
7 #define OSPF6_SPF_H
8
9 #include "typesafe.h"
10 #include "ospf6_top.h"
11 #include "lib/json.h"
12
13 /* Debug option */
14 extern unsigned char conf_debug_ospf6_spf;
15 #define OSPF6_DEBUG_SPF_PROCESS 0x01
16 #define OSPF6_DEBUG_SPF_TIME 0x02
17 #define OSPF6_DEBUG_SPF_DATABASE 0x04
18 #define OSPF6_DEBUG_SPF_ON(level) (conf_debug_ospf6_spf |= (level))
19 #define OSPF6_DEBUG_SPF_OFF(level) (conf_debug_ospf6_spf &= ~(level))
20 #define IS_OSPF6_DEBUG_SPF(level) \
21 (conf_debug_ospf6_spf & OSPF6_DEBUG_SPF_##level)
22
23 #define OSPF6_ASE_CALC_INTERVAL 1
24
25 PREDECL_SKIPLIST_NONUNIQ(vertex_pqueue);
26 /* Transit Vertex */
27 struct ospf6_vertex {
28 /* type of this vertex */
29 uint8_t type;
30
31 /* Vertex Identifier */
32 struct prefix vertex_id;
33
34 struct vertex_pqueue_item pqi;
35
36 /* Identifier String */
37 char name[128];
38
39 /* Associated Area */
40 struct ospf6_area *area;
41
42 /* Associated LSA */
43 struct ospf6_lsa *lsa;
44
45 /* Distance from Root (i.e. Cost) */
46 uint32_t cost;
47
48 /* Router hops to this node */
49 uint8_t hops;
50
51 /* capability bits */
52 uint8_t capability;
53
54 /* Optional capabilities */
55 uint8_t options[3];
56
57 /* For tree display */
58 struct ospf6_vertex *parent;
59 struct list *child_list;
60
61 /* nexthops to this node */
62 struct list *nh_list;
63 uint32_t link_id;
64 };
65
66 #define OSPF6_VERTEX_TYPE_ROUTER 0x01
67 #define OSPF6_VERTEX_TYPE_NETWORK 0x02
68 #define VERTEX_IS_TYPE(t, v) ((v)->type == OSPF6_VERTEX_TYPE_##t ? 1 : 0)
69
70 /* What triggered the SPF? */
71 #define OSPF6_SPF_FLAGS_ROUTER_LSA_ADDED (1 << 0)
72 #define OSPF6_SPF_FLAGS_ROUTER_LSA_REMOVED (1 << 1)
73 #define OSPF6_SPF_FLAGS_NETWORK_LSA_ADDED (1 << 2)
74 #define OSPF6_SPF_FLAGS_NETWORK_LSA_REMOVED (1 << 3)
75 #define OSPF6_SPF_FLAGS_LINK_LSA_ADDED (1 << 4)
76 #define OSPF6_SPF_FLAGS_LINK_LSA_REMOVED (1 << 5)
77 #define OSPF6_SPF_FLAGS_ROUTER_LSA_ORIGINATED (1 << 6)
78 #define OSPF6_SPF_FLAGS_NETWORK_LSA_ORIGINATED (1 << 7)
79 #define OSPF6_SPF_FLAGS_CONFIG_CHANGE (1 << 8)
80 #define OSPF6_SPF_FLAGS_ASBR_STATUS_CHANGE (1 << 9)
81 #define OSPF6_SPF_FLAGS_GR_FINISH (1 << 10)
82
83 static inline void ospf6_set_spf_reason(struct ospf6 *ospf, unsigned int reason)
84 {
85 ospf->spf_reason |= reason;
86 }
87
88 static inline void ospf6_reset_spf_reason(struct ospf6 *ospf)
89 {
90 ospf->spf_reason = 0;
91 }
92
93 static inline unsigned int ospf6_lsadd_to_spf_reason(struct ospf6_lsa *lsa)
94 {
95 unsigned int reason = 0;
96
97 switch (ntohs(lsa->header->type)) {
98 case OSPF6_LSTYPE_ROUTER:
99 reason = OSPF6_SPF_FLAGS_ROUTER_LSA_ADDED;
100 break;
101 case OSPF6_LSTYPE_NETWORK:
102 reason = OSPF6_SPF_FLAGS_NETWORK_LSA_ADDED;
103 break;
104 case OSPF6_LSTYPE_LINK:
105 reason = OSPF6_SPF_FLAGS_LINK_LSA_ADDED;
106 break;
107 default:
108 break;
109 }
110 return (reason);
111 }
112
113 static inline unsigned int ospf6_lsremove_to_spf_reason(struct ospf6_lsa *lsa)
114 {
115 unsigned int reason = 0;
116
117 switch (ntohs(lsa->header->type)) {
118 case OSPF6_LSTYPE_ROUTER:
119 reason = OSPF6_SPF_FLAGS_ROUTER_LSA_REMOVED;
120 break;
121 case OSPF6_LSTYPE_NETWORK:
122 reason = OSPF6_SPF_FLAGS_NETWORK_LSA_REMOVED;
123 break;
124 case OSPF6_LSTYPE_LINK:
125 reason = OSPF6_SPF_FLAGS_LINK_LSA_REMOVED;
126 break;
127 default:
128 break;
129 }
130 return (reason);
131 }
132
133 extern void ospf6_spf_table_finish(struct ospf6_route_table *result_table);
134 extern void ospf6_spf_calculation(uint32_t router_id,
135 struct ospf6_route_table *result_table,
136 struct ospf6_area *oa);
137 extern void ospf6_spf_schedule(struct ospf6 *ospf, unsigned int reason);
138
139 extern void ospf6_spf_display_subtree(struct vty *vty, const char *prefix,
140 int rest, struct ospf6_vertex *v,
141 json_object *json_obj, bool use_json);
142
143 extern void ospf6_spf_config_write(struct vty *vty, struct ospf6 *ospf6);
144 extern int config_write_ospf6_debug_spf(struct vty *vty);
145 extern void install_element_ospf6_debug_spf(void);
146 extern void ospf6_spf_init(void);
147 extern void ospf6_spf_reason_string(unsigned int reason, char *buf, int size);
148 extern struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area,
149 struct ospf6_lsdb *lsdb,
150 uint32_t adv_router);
151 extern void ospf6_remove_temp_router_lsa(struct ospf6_area *area);
152 extern void ospf6_ase_calculate_timer_add(struct ospf6 *ospf6);
153 extern int ospf6_ase_calculate_route(struct ospf6 *ospf6, struct ospf6_lsa *lsa,
154 struct ospf6_area *area);
155 #endif /* OSPF6_SPF_H */