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