]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_route.h
Merge pull request #12816 from gpnaveen/stc_rte_err_msg
[mirror_frr.git] / ospf6d / ospf6_route.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/*
508e53e2 3 * Copyright (C) 2003 Yasuhiro Ohara
718e3744 4 */
5
6#ifndef OSPF6_ROUTE_H
7#define OSPF6_ROUTE_H
8
ddae3015 9#include "command.h"
5afa1c6b 10#include "zclient.h"
eacd0828 11#include "lib/json.h"
d2e5d5d4 12#include "lib/nexthop.h"
ddae3015 13
508e53e2 14#define OSPF6_MULTI_PATH_LIMIT 4
718e3744 15
508e53e2 16/* Debug option */
17extern unsigned char conf_debug_ospf6_route;
18#define OSPF6_DEBUG_ROUTE_TABLE 0x01
19#define OSPF6_DEBUG_ROUTE_INTRA 0x02
20#define OSPF6_DEBUG_ROUTE_INTER 0x04
d5cb3508
YR
21#define OSPF6_DEBUG_ROUTE_MEMORY 0x08
22#define OSPF6_DEBUG_ROUTE_ALL \
23 (OSPF6_DEBUG_ROUTE_TABLE | OSPF6_DEBUG_ROUTE_INTRA \
24 | OSPF6_DEBUG_ROUTE_INTER | OSPF6_DEBUG_ROUTE_MEMORY)
d62a17ae 25#define OSPF6_DEBUG_ROUTE_ON(level) (conf_debug_ospf6_route |= (level))
26#define OSPF6_DEBUG_ROUTE_OFF(level) (conf_debug_ospf6_route &= ~(level))
27#define IS_OSPF6_DEBUG_ROUTE(e) (conf_debug_ospf6_route & OSPF6_DEBUG_ROUTE_##e)
718e3744 28
508e53e2 29/* Nexthop */
d62a17ae 30struct ospf6_nexthop {
31 /* Interface index */
32 ifindex_t ifindex;
718e3744 33
d62a17ae 34 /* IP address, if any */
35 struct in6_addr address;
d2e5d5d4
MR
36
37 /** Next-hop type information. */
38 enum nexthop_types_t type;
718e3744 39};
40
d2e5d5d4
MR
41static inline bool ospf6_nexthop_is_set(const struct ospf6_nexthop *nh)
42{
43 return nh->type != 0;
44}
45
46static inline bool ospf6_nexthop_is_same(const struct ospf6_nexthop *nha,
47 const struct ospf6_nexthop *nhb)
48{
49 if (nha->type != nhb->type)
50 return false;
51
52 switch (nha->type) {
53 case NEXTHOP_TYPE_BLACKHOLE:
54 /* NOTHING */
55 break;
56
57 case NEXTHOP_TYPE_IFINDEX:
58 if (nha->ifindex != nhb->ifindex)
59 return false;
60 break;
61
62 case NEXTHOP_TYPE_IPV4_IFINDEX:
63 case NEXTHOP_TYPE_IPV4:
64 /* OSPFv3 does not support IPv4 next hops. */
65 return false;
66
67 case NEXTHOP_TYPE_IPV6_IFINDEX:
68 if (nha->ifindex != nhb->ifindex)
69 return false;
70 /* FALLTHROUGH */
71 case NEXTHOP_TYPE_IPV6:
72 if (!IN6_ARE_ADDR_EQUAL(&nha->address, &nhb->address))
73 return false;
74 break;
75 }
76
77 return true;
78}
79
80static inline void ospf6_nexthop_clear(struct ospf6_nexthop *nh)
81{
82 memset(nh, 0, sizeof(*nh));
83}
84
85static inline void ospf6_nexthop_copy(struct ospf6_nexthop *nha,
86 const struct ospf6_nexthop *nhb)
87{
88 memcpy(nha, nhb, sizeof(*nha));
89}
508e53e2 90
718e3744 91/* Path */
d62a17ae 92struct ospf6_ls_origin {
d7c0a89a 93 uint16_t type;
858f9c08
DL
94 in_addr_t id;
95 in_addr_t adv_router;
718e3744 96};
97
d62a17ae 98struct ospf6_path {
99 /* Link State Origin */
100 struct ospf6_ls_origin origin;
718e3744 101
d62a17ae 102 /* Router bits */
d7c0a89a 103 uint8_t router_bits;
718e3744 104
d62a17ae 105 /* Optional Capabilities */
d7c0a89a 106 uint8_t options[3];
718e3744 107
d62a17ae 108 /* Associated Area */
858f9c08 109 in_addr_t area_id;
718e3744 110
d62a17ae 111 /* Path-type */
d7c0a89a
QY
112 uint8_t type;
113 uint8_t subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
718e3744 114
d62a17ae 115 /* Cost */
d7c0a89a
QY
116 uint8_t metric_type;
117 uint32_t cost;
6942698d
CS
118
119 struct prefix ls_prefix;
120
d62a17ae 121 union {
d7c0a89a
QY
122 uint32_t cost_e2;
123 uint32_t cost_config;
d62a17ae 124 } u;
d7c0a89a 125 uint32_t tag;
064d4355
CS
126
127 /* nh list for this path */
128 struct list *nh_list;
718e3744 129};
130
6452df09 131#define OSPF6_PATH_TYPE_NONE 0
132#define OSPF6_PATH_TYPE_INTRA 1
133#define OSPF6_PATH_TYPE_INTER 2
134#define OSPF6_PATH_TYPE_EXTERNAL1 3
135#define OSPF6_PATH_TYPE_EXTERNAL2 4
c1879c8f 136#define OSPF6_PATH_TYPE_MAX 5
718e3744 137
ca1f4309
DS
138#define OSPF6_PATH_SUBTYPE_DEFAULT_RT 1
139
140#define OSPF6_PATH_COST_IS_CONFIGURED(path) (path.u.cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
141
508e53e2 142#include "prefix.h"
143#include "table.h"
c3c0ac83 144#include "bitfield.h"
718e3744 145
d62a17ae 146struct ospf6_route {
147 struct route_node *rnode;
148 struct ospf6_route_table *table;
149 struct ospf6_route *prev;
150 struct ospf6_route *next;
718e3744 151
22813fdb
MR
152 /* Back pointer to ospf6 */
153 struct ospf6 *ospf6;
154
d62a17ae 155 unsigned int lock;
718e3744 156
d62a17ae 157 /* Destination Type */
d7c0a89a 158 uint8_t type;
508e53e2 159
d62a17ae 160 /* XXX: It would likely be better to use separate struct in_addr's
161 * for the advertising router-ID and prefix IDs, instead of stuffing
162 * them
163 * into one. See also XXX below.
164 */
165 /* Destination ID */
166 struct prefix prefix;
508e53e2 167
d62a17ae 168 /* Time */
169 struct timeval installed;
170 struct timeval changed;
718e3744 171
d62a17ae 172 /* flag */
3c77bc80 173 uint16_t flag;
718e3744 174
4699ad72
DL
175 /* Prefix Options */
176 uint8_t prefix_options;
177
d62a17ae 178 /* route option */
179 void *route_option;
049207c3 180
d62a17ae 181 /* link state id for advertising */
d7c0a89a 182 uint32_t linkstate_id;
c3c0ac83 183
d62a17ae 184 /* path */
185 struct ospf6_path path;
c3c0ac83 186
064d4355
CS
187 /* List of Paths. */
188 struct list *paths;
189
d62a17ae 190 /* nexthop */
191 struct list *nh_list;
4dc43886
MR
192
193 /* points to the summarised route */
194 struct ospf6_external_aggr_rt *aggr_route;
195
196 /* For Aggr routes */
197 bool to_be_processed;
718e3744 198};
199
200#define OSPF6_DEST_TYPE_NONE 0
201#define OSPF6_DEST_TYPE_ROUTER 1
202#define OSPF6_DEST_TYPE_NETWORK 2
203#define OSPF6_DEST_TYPE_DISCARD 3
508e53e2 204#define OSPF6_DEST_TYPE_LINKSTATE 4
6452df09 205#define OSPF6_DEST_TYPE_RANGE 5
206#define OSPF6_DEST_TYPE_MAX 6
718e3744 207
3c77bc80
RW
208#define OSPF6_ROUTE_CHANGE 0x0001
209#define OSPF6_ROUTE_ADD 0x0002
210#define OSPF6_ROUTE_REMOVE 0x0004
211#define OSPF6_ROUTE_BEST 0x0008
212#define OSPF6_ROUTE_ACTIVE_SUMMARY 0x0010
213#define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x0020
214#define OSPF6_ROUTE_WAS_REMOVED 0x0040
215#define OSPF6_ROUTE_BLACKHOLE_ADDED 0x0080
216#define OSPF6_ROUTE_NSSA_RANGE 0x0100
beadc736 217struct ospf6;
718e3744 218
d62a17ae 219struct ospf6_route_table {
220 int scope_type;
221 int table_type;
222 void *scope;
cf1ce250 223
d62a17ae 224 /* patricia tree */
225 struct route_table *table;
718e3744 226
d7c0a89a 227 uint32_t count;
718e3744 228
d62a17ae 229 /* hooks */
e285b70d 230 void (*hook_add)(struct ospf6_route *);
d62a17ae 231 void (*hook_change)(struct ospf6_route *);
e285b70d 232 void (*hook_remove)(struct ospf6_route *);
508e53e2 233};
718e3744 234
cf1ce250
PJ
235#define OSPF6_SCOPE_TYPE_NONE 0
236#define OSPF6_SCOPE_TYPE_GLOBAL 1
237#define OSPF6_SCOPE_TYPE_AREA 2
238#define OSPF6_SCOPE_TYPE_INTERFACE 3
239
240#define OSPF6_TABLE_TYPE_NONE 0
241#define OSPF6_TABLE_TYPE_ROUTES 1
242#define OSPF6_TABLE_TYPE_BORDER_ROUTERS 2
243#define OSPF6_TABLE_TYPE_CONNECTED_ROUTES 3
244#define OSPF6_TABLE_TYPE_EXTERNAL_ROUTES 4
245#define OSPF6_TABLE_TYPE_SPF_RESULTS 5
246#define OSPF6_TABLE_TYPE_PREFIX_RANGES 6
247#define OSPF6_TABLE_TYPE_SUMMARY_PREFIXES 7
248#define OSPF6_TABLE_TYPE_SUMMARY_ROUTERS 8
249
d62a17ae 250#define OSPF6_ROUTE_TABLE_CREATE(s, t) \
251 ospf6_route_table_create(OSPF6_SCOPE_TYPE_##s, OSPF6_TABLE_TYPE_##t)
cf1ce250 252
2b64873d
DL
253extern const char *const ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX];
254extern const char *const ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX];
d62a17ae 255#define OSPF6_DEST_TYPE_NAME(x) \
256 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? ospf6_dest_type_str[(x)] \
257 : ospf6_dest_type_str[0])
258#define OSPF6_DEST_TYPE_SUBSTR(x) \
259 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? ospf6_dest_type_substr[(x)] \
260 : ospf6_dest_type_substr[0])
508e53e2 261
2b64873d
DL
262extern const char *const ospf6_path_type_str[OSPF6_PATH_TYPE_MAX];
263extern const char *const ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
d62a17ae 264#define OSPF6_PATH_TYPE_NAME(x) \
265 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? ospf6_path_type_str[(x)] \
266 : ospf6_path_type_str[0])
267#define OSPF6_PATH_TYPE_SUBSTR(x) \
268 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? ospf6_path_type_substr[(x)] \
269 : ospf6_path_type_substr[0])
eacd0828
YR
270#define OSPF6_PATH_TYPE_JSON(x) \
271 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? ospf6_path_type_json[(x)] \
272 : ospf6_path_type_json[0])
508e53e2 273
274#define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n"
275#define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
276#define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"
277
66314e9f 278#define ospf6_route_is_prefix(p, r) (prefix_same(p, &(r)->prefix))
d62a17ae 279#define ospf6_route_is_same(ra, rb) (prefix_same(&(ra)->prefix, &(rb)->prefix))
280#define ospf6_route_is_same_origin(ra, rb) \
281 ((ra)->path.area_id == (rb)->path.area_id \
66314e9f
IR
282 && (ra)->path.origin.type == (rb)->path.origin.type \
283 && (ra)->path.origin.id == (rb)->path.origin.id \
284 && (ra)->path.origin.adv_router == (rb)->path.origin.adv_router)
4dfe1520
RW
285#define ospf6_route_is_identical(ra, rb) \
286 ((ra)->type == (rb)->type && \
287 prefix_same(&(ra)->prefix, &(rb)->prefix) && \
288 (ra)->path.type == (rb)->path.type && \
289 (ra)->path.cost == (rb)->path.cost && \
290 (ra)->path.u.cost_e2 == (rb)->path.u.cost_e2 && \
291 listcount(ra->paths) == listcount(rb->paths) && \
8f1bf687 292 ospf6_route_cmp_nexthops(ra, rb))
c3c0ac83 293
508e53e2 294#define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
295
d62a17ae 296#define ospf6_linkstate_prefix_adv_router(x) ((x)->u.lp.id.s_addr)
297#define ospf6_linkstate_prefix_id(x) ((x)->u.lp.adv_router.s_addr)
508e53e2 298
d62a17ae 299#define ADV_ROUTER_IN_PREFIX(x) ((x)->u.lp.id.s_addr)
3b68735f 300
508e53e2 301/* Function prototype */
d7c0a89a 302extern void ospf6_linkstate_prefix(uint32_t adv_router, uint32_t id,
d62a17ae 303 struct prefix *prefix);
304extern void ospf6_linkstate_prefix2str(struct prefix *prefix, char *buf,
305 int size);
306
307extern struct ospf6_nexthop *ospf6_nexthop_create(void);
064d4355 308extern int ospf6_nexthop_cmp(struct ospf6_nexthop *a, struct ospf6_nexthop *b);
d62a17ae 309extern void ospf6_nexthop_delete(struct ospf6_nexthop *nh);
d62a17ae 310extern void ospf6_clear_nexthops(struct list *nh_list);
311extern int ospf6_num_nexthops(struct list *nh_list);
312extern void ospf6_copy_nexthops(struct list *dst, struct list *src);
313extern void ospf6_merge_nexthops(struct list *dst, struct list *src);
314extern void ospf6_add_nexthop(struct list *nh_list, int ifindex,
6861a5e4 315 const struct in6_addr *addr);
d2e5d5d4 316extern void ospf6_add_route_nexthop_blackhole(struct ospf6_route *route);
d62a17ae 317extern int ospf6_num_nexthops(struct list *nh_list);
8f1bf687
DS
318extern bool ospf6_route_cmp_nexthops(struct ospf6_route *a,
319 struct ospf6_route *b);
d62a17ae 320extern void ospf6_route_zebra_copy_nexthops(struct ospf6_route *route,
5afa1c6b 321 struct zapi_nexthop nexthops[],
1fa58587 322 int entries, vrf_id_t vrf_id);
d62a17ae 323extern int ospf6_route_get_first_nh_index(struct ospf6_route *route);
c3c0ac83
DS
324
325/* Hide abstraction of nexthop implementation in route from outsiders */
326#define ospf6_route_copy_nexthops(dst, src) ospf6_copy_nexthops(dst->nh_list, src->nh_list)
327#define ospf6_route_merge_nexthops(dst, src) ospf6_merge_nexthops(dst->nh_list, src->nh_list)
328#define ospf6_route_num_nexthops(route) ospf6_num_nexthops(route->nh_list)
d62a17ae 329#define ospf6_route_add_nexthop(route, ifindex, addr) \
330 ospf6_add_nexthop(route->nh_list, ifindex, addr)
331
22813fdb 332extern struct ospf6_route *ospf6_route_create(struct ospf6 *ospf6);
7932dd93 333extern void ospf6_route_delete(struct ospf6_route *route);
d62a17ae 334extern struct ospf6_route *ospf6_route_copy(struct ospf6_route *route);
335extern int ospf6_route_cmp(struct ospf6_route *ra, struct ospf6_route *rb);
336
337extern void ospf6_route_lock(struct ospf6_route *route);
338extern void ospf6_route_unlock(struct ospf6_route *route);
d62a17ae 339extern struct ospf6_route *ospf6_route_lookup(struct prefix *prefix,
340 struct ospf6_route_table *table);
341extern struct ospf6_route *
342ospf6_route_lookup_identical(struct ospf6_route *route,
343 struct ospf6_route_table *table);
344extern struct ospf6_route *
345ospf6_route_lookup_bestmatch(struct prefix *prefix,
346 struct ospf6_route_table *table);
347
348extern struct ospf6_route *ospf6_route_add(struct ospf6_route *route,
e285b70d 349 struct ospf6_route_table *table);
d62a17ae 350extern void ospf6_route_remove(struct ospf6_route *route,
e285b70d 351 struct ospf6_route_table *table);
d62a17ae 352
353extern struct ospf6_route *ospf6_route_head(struct ospf6_route_table *table);
354extern struct ospf6_route *ospf6_route_next(struct ospf6_route *route);
355extern struct ospf6_route *ospf6_route_best_next(struct ospf6_route *route);
356
357extern struct ospf6_route *
358ospf6_route_match_head(struct prefix *prefix, struct ospf6_route_table *table);
359extern struct ospf6_route *ospf6_route_match_next(struct prefix *prefix,
360 struct ospf6_route *route);
361
e285b70d 362extern void ospf6_route_remove_all(struct ospf6_route_table *table);
d62a17ae 363extern struct ospf6_route_table *ospf6_route_table_create(int s, int t);
e285b70d 364extern void ospf6_route_table_delete(struct ospf6_route_table *table);
d62a17ae 365extern void ospf6_route_dump(struct ospf6_route_table *table);
366
367
eacd0828
YR
368extern void ospf6_route_show(struct vty *vty, struct ospf6_route *route,
369 json_object *json, bool use_json);
370extern void ospf6_route_show_detail(struct vty *vty, struct ospf6_route *route,
371 json_object *json, bool use_json);
372
d62a17ae 373
7932dd93
DS
374extern int ospf6_route_table_show(struct vty *vty, int argc_start, int argc,
375 struct cmd_token **argv,
376 struct ospf6_route_table *table,
377 bool use_json);
d62a17ae 378extern int ospf6_linkstate_table_show(struct vty *vty, int idx_ipv4, int argc,
379 struct cmd_token **argv,
380 struct ospf6_route_table *table);
381
382extern void ospf6_brouter_show_header(struct vty *vty);
383extern void ospf6_brouter_show(struct vty *vty, struct ospf6_route *route);
384
385extern int config_write_ospf6_debug_route(struct vty *vty);
386extern void install_element_ospf6_debug_route(void);
387extern void ospf6_route_init(void);
064d4355
CS
388extern void ospf6_path_free(struct ospf6_path *op);
389extern struct ospf6_path *ospf6_path_dup(struct ospf6_path *path);
03f3c1c1 390extern void ospf6_copy_paths(struct list *dst, struct list *src);
718e3744 391
392#endif /* OSPF6_ROUTE_H */