2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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
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.
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
27 #include "lib/nexthop.h"
29 #define OSPF6_MULTI_PATH_LIMIT 4
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 0x08
37 #define OSPF6_DEBUG_ROUTE_ALL \
38 (OSPF6_DEBUG_ROUTE_TABLE | OSPF6_DEBUG_ROUTE_INTRA \
39 | OSPF6_DEBUG_ROUTE_INTER | OSPF6_DEBUG_ROUTE_MEMORY)
40 #define OSPF6_DEBUG_ROUTE_ON(level) (conf_debug_ospf6_route |= (level))
41 #define OSPF6_DEBUG_ROUTE_OFF(level) (conf_debug_ospf6_route &= ~(level))
42 #define IS_OSPF6_DEBUG_ROUTE(e) (conf_debug_ospf6_route & OSPF6_DEBUG_ROUTE_##e)
45 struct ospf6_nexthop
{
49 /* IP address, if any */
50 struct in6_addr address
;
52 /** Next-hop type information. */
53 enum nexthop_types_t type
;
56 static inline bool ospf6_nexthop_is_set(const struct ospf6_nexthop
*nh
)
61 static inline bool ospf6_nexthop_is_same(const struct ospf6_nexthop
*nha
,
62 const struct ospf6_nexthop
*nhb
)
64 if (nha
->type
!= nhb
->type
)
68 case NEXTHOP_TYPE_BLACKHOLE
:
72 case NEXTHOP_TYPE_IFINDEX
:
73 if (nha
->ifindex
!= nhb
->ifindex
)
77 case NEXTHOP_TYPE_IPV4_IFINDEX
:
78 case NEXTHOP_TYPE_IPV4
:
79 /* OSPFv3 does not support IPv4 next hops. */
82 case NEXTHOP_TYPE_IPV6_IFINDEX
:
83 if (nha
->ifindex
!= nhb
->ifindex
)
86 case NEXTHOP_TYPE_IPV6
:
87 if (!IN6_ARE_ADDR_EQUAL(&nha
->address
, &nhb
->address
))
95 static inline void ospf6_nexthop_clear(struct ospf6_nexthop
*nh
)
97 memset(nh
, 0, sizeof(*nh
));
100 static inline void ospf6_nexthop_copy(struct ospf6_nexthop
*nha
,
101 const struct ospf6_nexthop
*nhb
)
103 memcpy(nha
, nhb
, sizeof(*nha
));
107 struct ospf6_ls_origin
{
110 in_addr_t adv_router
;
114 /* Link State Origin */
115 struct ospf6_ls_origin origin
;
120 /* Optional Capabilities */
123 /* Associated Area */
128 uint8_t subtype
; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
134 struct prefix ls_prefix
;
138 uint32_t cost_config
;
142 /* nh list for this path */
143 struct list
*nh_list
;
146 #define OSPF6_PATH_TYPE_NONE 0
147 #define OSPF6_PATH_TYPE_INTRA 1
148 #define OSPF6_PATH_TYPE_INTER 2
149 #define OSPF6_PATH_TYPE_EXTERNAL1 3
150 #define OSPF6_PATH_TYPE_EXTERNAL2 4
151 #define OSPF6_PATH_TYPE_MAX 5
153 #define OSPF6_PATH_SUBTYPE_DEFAULT_RT 1
155 #define OSPF6_PATH_COST_IS_CONFIGURED(path) (path.u.cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
159 #include "bitfield.h"
162 struct route_node
*rnode
;
163 struct ospf6_route_table
*table
;
164 struct ospf6_route
*prev
;
165 struct ospf6_route
*next
;
167 /* Back pointer to ospf6 */
172 /* Destination Type */
175 /* XXX: It would likely be better to use separate struct in_addr's
176 * for the advertising router-ID and prefix IDs, instead of stuffing
178 * into one. See also XXX below.
181 struct prefix prefix
;
184 struct timeval installed
;
185 struct timeval changed
;
191 uint8_t prefix_options
;
196 /* link state id for advertising */
197 uint32_t linkstate_id
;
200 struct ospf6_path path
;
206 struct list
*nh_list
;
208 /* points to the summarised route */
209 struct ospf6_external_aggr_rt
*aggr_route
;
211 /* For Aggr routes */
212 bool to_be_processed
;
215 #define OSPF6_DEST_TYPE_NONE 0
216 #define OSPF6_DEST_TYPE_ROUTER 1
217 #define OSPF6_DEST_TYPE_NETWORK 2
218 #define OSPF6_DEST_TYPE_DISCARD 3
219 #define OSPF6_DEST_TYPE_LINKSTATE 4
220 #define OSPF6_DEST_TYPE_RANGE 5
221 #define OSPF6_DEST_TYPE_MAX 6
223 #define OSPF6_ROUTE_CHANGE 0x0001
224 #define OSPF6_ROUTE_ADD 0x0002
225 #define OSPF6_ROUTE_REMOVE 0x0004
226 #define OSPF6_ROUTE_BEST 0x0008
227 #define OSPF6_ROUTE_ACTIVE_SUMMARY 0x0010
228 #define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x0020
229 #define OSPF6_ROUTE_WAS_REMOVED 0x0040
230 #define OSPF6_ROUTE_BLACKHOLE_ADDED 0x0080
231 #define OSPF6_ROUTE_NSSA_RANGE 0x0100
234 struct ospf6_route_table
{
240 struct route_table
*table
;
245 void (*hook_add
)(struct ospf6_route
*);
246 void (*hook_change
)(struct ospf6_route
*);
247 void (*hook_remove
)(struct ospf6_route
*);
250 #define OSPF6_SCOPE_TYPE_NONE 0
251 #define OSPF6_SCOPE_TYPE_GLOBAL 1
252 #define OSPF6_SCOPE_TYPE_AREA 2
253 #define OSPF6_SCOPE_TYPE_INTERFACE 3
255 #define OSPF6_TABLE_TYPE_NONE 0
256 #define OSPF6_TABLE_TYPE_ROUTES 1
257 #define OSPF6_TABLE_TYPE_BORDER_ROUTERS 2
258 #define OSPF6_TABLE_TYPE_CONNECTED_ROUTES 3
259 #define OSPF6_TABLE_TYPE_EXTERNAL_ROUTES 4
260 #define OSPF6_TABLE_TYPE_SPF_RESULTS 5
261 #define OSPF6_TABLE_TYPE_PREFIX_RANGES 6
262 #define OSPF6_TABLE_TYPE_SUMMARY_PREFIXES 7
263 #define OSPF6_TABLE_TYPE_SUMMARY_ROUTERS 8
265 #define OSPF6_ROUTE_TABLE_CREATE(s, t) \
266 ospf6_route_table_create(OSPF6_SCOPE_TYPE_##s, OSPF6_TABLE_TYPE_##t)
268 extern const char *const ospf6_dest_type_str
[OSPF6_DEST_TYPE_MAX
];
269 extern const char *const ospf6_dest_type_substr
[OSPF6_DEST_TYPE_MAX
];
270 #define OSPF6_DEST_TYPE_NAME(x) \
271 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? ospf6_dest_type_str[(x)] \
272 : ospf6_dest_type_str[0])
273 #define OSPF6_DEST_TYPE_SUBSTR(x) \
274 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? ospf6_dest_type_substr[(x)] \
275 : ospf6_dest_type_substr[0])
277 extern const char *const ospf6_path_type_str
[OSPF6_PATH_TYPE_MAX
];
278 extern const char *const ospf6_path_type_substr
[OSPF6_PATH_TYPE_MAX
];
279 #define OSPF6_PATH_TYPE_NAME(x) \
280 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? ospf6_path_type_str[(x)] \
281 : ospf6_path_type_str[0])
282 #define OSPF6_PATH_TYPE_SUBSTR(x) \
283 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? ospf6_path_type_substr[(x)] \
284 : ospf6_path_type_substr[0])
285 #define OSPF6_PATH_TYPE_JSON(x) \
286 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? ospf6_path_type_json[(x)] \
287 : ospf6_path_type_json[0])
289 #define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n"
290 #define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
291 #define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"
293 #define ospf6_route_is_prefix(p, r) (prefix_same(p, &(r)->prefix))
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 && (ra)->path.origin.type == (rb)->path.origin.type \
298 && (ra)->path.origin.id == (rb)->path.origin.id \
299 && (ra)->path.origin.adv_router == (rb)->path.origin.adv_router)
300 #define ospf6_route_is_identical(ra, rb) \
301 ((ra)->type == (rb)->type && \
302 prefix_same(&(ra)->prefix, &(rb)->prefix) && \
303 (ra)->path.type == (rb)->path.type && \
304 (ra)->path.cost == (rb)->path.cost && \
305 (ra)->path.u.cost_e2 == (rb)->path.u.cost_e2 && \
306 listcount(ra->paths) == listcount(rb->paths) && \
307 ospf6_route_cmp_nexthops(ra, rb))
309 #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
311 #define ospf6_linkstate_prefix_adv_router(x) ((x)->u.lp.id.s_addr)
312 #define ospf6_linkstate_prefix_id(x) ((x)->u.lp.adv_router.s_addr)
314 #define ADV_ROUTER_IN_PREFIX(x) ((x)->u.lp.id.s_addr)
316 /* Function prototype */
317 extern void ospf6_linkstate_prefix(uint32_t adv_router
, uint32_t id
,
318 struct prefix
*prefix
);
319 extern void ospf6_linkstate_prefix2str(struct prefix
*prefix
, char *buf
,
322 extern struct ospf6_nexthop
*ospf6_nexthop_create(void);
323 extern int ospf6_nexthop_cmp(struct ospf6_nexthop
*a
, struct ospf6_nexthop
*b
);
324 extern void ospf6_nexthop_delete(struct ospf6_nexthop
*nh
);
325 extern void ospf6_clear_nexthops(struct list
*nh_list
);
326 extern int ospf6_num_nexthops(struct list
*nh_list
);
327 extern void ospf6_copy_nexthops(struct list
*dst
, struct list
*src
);
328 extern void ospf6_merge_nexthops(struct list
*dst
, struct list
*src
);
329 extern void ospf6_add_nexthop(struct list
*nh_list
, int ifindex
,
330 struct in6_addr
*addr
);
331 extern void ospf6_add_route_nexthop_blackhole(struct ospf6_route
*route
);
332 extern int ospf6_num_nexthops(struct list
*nh_list
);
333 extern bool ospf6_route_cmp_nexthops(struct ospf6_route
*a
,
334 struct ospf6_route
*b
);
335 extern void ospf6_route_zebra_copy_nexthops(struct ospf6_route
*route
,
336 struct zapi_nexthop nexthops
[],
337 int entries
, vrf_id_t vrf_id
);
338 extern int ospf6_route_get_first_nh_index(struct ospf6_route
*route
);
340 /* Hide abstraction of nexthop implementation in route from outsiders */
341 #define ospf6_route_copy_nexthops(dst, src) ospf6_copy_nexthops(dst->nh_list, src->nh_list)
342 #define ospf6_route_merge_nexthops(dst, src) ospf6_merge_nexthops(dst->nh_list, src->nh_list)
343 #define ospf6_route_num_nexthops(route) ospf6_num_nexthops(route->nh_list)
344 #define ospf6_route_add_nexthop(route, ifindex, addr) \
345 ospf6_add_nexthop(route->nh_list, ifindex, addr)
347 extern struct ospf6_route
*ospf6_route_create(struct ospf6
*ospf6
);
348 extern void ospf6_route_delete(struct ospf6_route
*route
);
349 extern struct ospf6_route
*ospf6_route_copy(struct ospf6_route
*route
);
350 extern int ospf6_route_cmp(struct ospf6_route
*ra
, struct ospf6_route
*rb
);
352 extern void ospf6_route_lock(struct ospf6_route
*route
);
353 extern void ospf6_route_unlock(struct ospf6_route
*route
);
354 extern struct ospf6_route
*ospf6_route_lookup(struct prefix
*prefix
,
355 struct ospf6_route_table
*table
);
356 extern struct ospf6_route
*
357 ospf6_route_lookup_identical(struct ospf6_route
*route
,
358 struct ospf6_route_table
*table
);
359 extern struct ospf6_route
*
360 ospf6_route_lookup_bestmatch(struct prefix
*prefix
,
361 struct ospf6_route_table
*table
);
363 extern struct ospf6_route
*ospf6_route_add(struct ospf6_route
*route
,
364 struct ospf6_route_table
*table
);
365 extern void ospf6_route_remove(struct ospf6_route
*route
,
366 struct ospf6_route_table
*table
);
368 extern struct ospf6_route
*ospf6_route_head(struct ospf6_route_table
*table
);
369 extern struct ospf6_route
*ospf6_route_next(struct ospf6_route
*route
);
370 extern struct ospf6_route
*ospf6_route_best_next(struct ospf6_route
*route
);
372 extern struct ospf6_route
*
373 ospf6_route_match_head(struct prefix
*prefix
, struct ospf6_route_table
*table
);
374 extern struct ospf6_route
*ospf6_route_match_next(struct prefix
*prefix
,
375 struct ospf6_route
*route
);
377 extern void ospf6_route_remove_all(struct ospf6_route_table
*table
);
378 extern struct ospf6_route_table
*ospf6_route_table_create(int s
, int t
);
379 extern void ospf6_route_table_delete(struct ospf6_route_table
*table
);
380 extern void ospf6_route_dump(struct ospf6_route_table
*table
);
383 extern void ospf6_route_show(struct vty
*vty
, struct ospf6_route
*route
,
384 json_object
*json
, bool use_json
);
385 extern void ospf6_route_show_detail(struct vty
*vty
, struct ospf6_route
*route
,
386 json_object
*json
, bool use_json
);
389 extern int ospf6_route_table_show(struct vty
*vty
, int argc_start
, int argc
,
390 struct cmd_token
**argv
,
391 struct ospf6_route_table
*table
,
393 extern int ospf6_linkstate_table_show(struct vty
*vty
, int idx_ipv4
, int argc
,
394 struct cmd_token
**argv
,
395 struct ospf6_route_table
*table
);
397 extern void ospf6_brouter_show_header(struct vty
*vty
);
398 extern void ospf6_brouter_show(struct vty
*vty
, struct ospf6_route
*route
);
400 extern int config_write_ospf6_debug_route(struct vty
*vty
);
401 extern void install_element_ospf6_debug_route(void);
402 extern void ospf6_route_init(void);
403 extern void ospf6_path_free(struct ospf6_path
*op
);
404 extern struct ospf6_path
*ospf6_path_dup(struct ospf6_path
*path
);
405 extern void ospf6_copy_paths(struct list
*dst
, struct list
*src
);
407 #endif /* OSPF6_ROUTE_H */