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 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)
42 struct ospf6_nexthop
{
46 /* IP address, if any */
47 struct in6_addr address
;
49 /** Next-hop type information. */
50 enum nexthop_types_t type
;
53 static inline bool ospf6_nexthop_is_set(const struct ospf6_nexthop
*nh
)
58 static inline bool ospf6_nexthop_is_same(const struct ospf6_nexthop
*nha
,
59 const struct ospf6_nexthop
*nhb
)
61 if (nha
->type
!= nhb
->type
)
65 case NEXTHOP_TYPE_BLACKHOLE
:
69 case NEXTHOP_TYPE_IFINDEX
:
70 if (nha
->ifindex
!= nhb
->ifindex
)
74 case NEXTHOP_TYPE_IPV4_IFINDEX
:
75 case NEXTHOP_TYPE_IPV4
:
76 /* OSPFv3 does not support IPv4 next hops. */
79 case NEXTHOP_TYPE_IPV6_IFINDEX
:
80 if (nha
->ifindex
!= nhb
->ifindex
)
83 case NEXTHOP_TYPE_IPV6
:
84 if (!IN6_ARE_ADDR_EQUAL(&nha
->address
, &nhb
->address
))
92 static inline void ospf6_nexthop_clear(struct ospf6_nexthop
*nh
)
94 memset(nh
, 0, sizeof(*nh
));
97 static inline void ospf6_nexthop_copy(struct ospf6_nexthop
*nha
,
98 const struct ospf6_nexthop
*nhb
)
100 memcpy(nha
, nhb
, sizeof(*nha
));
104 struct ospf6_ls_origin
{
107 in_addr_t adv_router
;
111 /* Link State Origin */
112 struct ospf6_ls_origin origin
;
117 /* Optional Capabilities */
120 /* Associated Area */
125 uint8_t subtype
; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
131 struct prefix ls_prefix
;
135 uint32_t cost_config
;
139 /* nh list for this path */
140 struct list
*nh_list
;
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
151 #define OSPF6_PATH_SUBTYPE_DEFAULT_RT 1
153 #define OSPF6_PATH_COST_IS_CONFIGURED(path) (path.u.cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
157 #include "bitfield.h"
160 struct route_node
*rnode
;
161 struct ospf6_route_table
*table
;
162 struct ospf6_route
*prev
;
163 struct ospf6_route
*next
;
165 /* Back pointer to ospf6 */
170 /* Destination Type */
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
176 * into one. See also XXX below.
179 struct prefix prefix
;
182 struct timeval installed
;
183 struct timeval changed
;
189 uint8_t prefix_options
;
194 /* link state id for advertising */
195 uint32_t linkstate_id
;
198 struct ospf6_path path
;
204 struct list
*nh_list
;
206 /* points to the summarised route */
207 struct ospf6_external_aggr_rt
*aggr_route
;
209 /* For Aggr routes */
210 bool to_be_processed
;
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
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
231 struct ospf6_route_table
{
237 struct route_table
*table
;
244 void (*hook_add
)(struct ospf6_route
*);
245 void (*hook_change
)(struct ospf6_route
*);
246 void (*hook_remove
)(struct ospf6_route
*);
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
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
264 #define OSPF6_ROUTE_TABLE_CREATE(s, t) \
265 ospf6_route_table_create(OSPF6_SCOPE_TYPE_##s, OSPF6_TABLE_TYPE_##t)
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])
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])
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"
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)) \
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)
307 #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
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)
312 #define ADV_ROUTER_IN_PREFIX(x) ((x)->u.lp.id.s_addr)
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
,
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
);
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)
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
393 extern void ospf6_brouter_show_header(struct vty
*vty
);
394 extern void ospf6_brouter_show(struct vty
*vty
, struct ospf6_route
*route
);
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
);
403 #endif /* OSPF6_ROUTE_H */