]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
508e53e2 | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
718e3744 | 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 | * | |
896014f4 DL |
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 | |
718e3744 | 19 | */ |
20 | ||
21 | #ifndef OSPF6_ROUTE_H | |
22 | #define OSPF6_ROUTE_H | |
23 | ||
ddae3015 | 24 | #include "command.h" |
5afa1c6b | 25 | #include "zclient.h" |
eacd0828 | 26 | #include "lib/json.h" |
d2e5d5d4 | 27 | #include "lib/nexthop.h" |
ddae3015 | 28 | |
508e53e2 | 29 | #define OSPF6_MULTI_PATH_LIMIT 4 |
718e3744 | 30 | |
508e53e2 | 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 | |
d5cb3508 YR |
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) | |
d62a17ae | 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) | |
718e3744 | 43 | |
508e53e2 | 44 | /* Nexthop */ |
d62a17ae | 45 | struct ospf6_nexthop { |
46 | /* Interface index */ | |
47 | ifindex_t ifindex; | |
718e3744 | 48 | |
d62a17ae | 49 | /* IP address, if any */ |
50 | struct in6_addr address; | |
d2e5d5d4 MR |
51 | |
52 | /** Next-hop type information. */ | |
53 | enum nexthop_types_t type; | |
718e3744 | 54 | }; |
55 | ||
d2e5d5d4 MR |
56 | static inline bool ospf6_nexthop_is_set(const struct ospf6_nexthop *nh) |
57 | { | |
58 | return nh->type != 0; | |
59 | } | |
60 | ||
61 | static inline bool ospf6_nexthop_is_same(const struct ospf6_nexthop *nha, | |
62 | const struct ospf6_nexthop *nhb) | |
63 | { | |
64 | if (nha->type != nhb->type) | |
65 | return false; | |
66 | ||
67 | switch (nha->type) { | |
68 | case NEXTHOP_TYPE_BLACKHOLE: | |
69 | /* NOTHING */ | |
70 | break; | |
71 | ||
72 | case NEXTHOP_TYPE_IFINDEX: | |
73 | if (nha->ifindex != nhb->ifindex) | |
74 | return false; | |
75 | break; | |
76 | ||
77 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
78 | case NEXTHOP_TYPE_IPV4: | |
79 | /* OSPFv3 does not support IPv4 next hops. */ | |
80 | return false; | |
81 | ||
82 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
83 | if (nha->ifindex != nhb->ifindex) | |
84 | return false; | |
85 | /* FALLTHROUGH */ | |
86 | case NEXTHOP_TYPE_IPV6: | |
87 | if (!IN6_ARE_ADDR_EQUAL(&nha->address, &nhb->address)) | |
88 | return false; | |
89 | break; | |
90 | } | |
91 | ||
92 | return true; | |
93 | } | |
94 | ||
95 | static inline void ospf6_nexthop_clear(struct ospf6_nexthop *nh) | |
96 | { | |
97 | memset(nh, 0, sizeof(*nh)); | |
98 | } | |
99 | ||
100 | static inline void ospf6_nexthop_copy(struct ospf6_nexthop *nha, | |
101 | const struct ospf6_nexthop *nhb) | |
102 | { | |
103 | memcpy(nha, nhb, sizeof(*nha)); | |
104 | } | |
508e53e2 | 105 | |
718e3744 | 106 | /* Path */ |
d62a17ae | 107 | struct ospf6_ls_origin { |
d7c0a89a | 108 | uint16_t type; |
858f9c08 DL |
109 | in_addr_t id; |
110 | in_addr_t adv_router; | |
718e3744 | 111 | }; |
112 | ||
d62a17ae | 113 | struct ospf6_path { |
114 | /* Link State Origin */ | |
115 | struct ospf6_ls_origin origin; | |
718e3744 | 116 | |
d62a17ae | 117 | /* Router bits */ |
d7c0a89a | 118 | uint8_t router_bits; |
718e3744 | 119 | |
d62a17ae | 120 | /* Optional Capabilities */ |
d7c0a89a | 121 | uint8_t options[3]; |
718e3744 | 122 | |
d62a17ae | 123 | /* Associated Area */ |
858f9c08 | 124 | in_addr_t area_id; |
718e3744 | 125 | |
d62a17ae | 126 | /* Path-type */ |
d7c0a89a QY |
127 | uint8_t type; |
128 | uint8_t subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */ | |
718e3744 | 129 | |
d62a17ae | 130 | /* Cost */ |
d7c0a89a QY |
131 | uint8_t metric_type; |
132 | uint32_t cost; | |
6942698d CS |
133 | |
134 | struct prefix ls_prefix; | |
135 | ||
d62a17ae | 136 | union { |
d7c0a89a QY |
137 | uint32_t cost_e2; |
138 | uint32_t cost_config; | |
d62a17ae | 139 | } u; |
d7c0a89a | 140 | uint32_t tag; |
064d4355 CS |
141 | |
142 | /* nh list for this path */ | |
143 | struct list *nh_list; | |
718e3744 | 144 | }; |
145 | ||
6452df09 | 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 | |
c1879c8f | 151 | #define OSPF6_PATH_TYPE_MAX 5 |
718e3744 | 152 | |
ca1f4309 DS |
153 | #define OSPF6_PATH_SUBTYPE_DEFAULT_RT 1 |
154 | ||
155 | #define OSPF6_PATH_COST_IS_CONFIGURED(path) (path.u.cost_config != OSPF_AREA_RANGE_COST_UNSPEC) | |
156 | ||
508e53e2 | 157 | #include "prefix.h" |
158 | #include "table.h" | |
c3c0ac83 | 159 | #include "bitfield.h" |
718e3744 | 160 | |
d62a17ae | 161 | struct ospf6_route { |
162 | struct route_node *rnode; | |
163 | struct ospf6_route_table *table; | |
164 | struct ospf6_route *prev; | |
165 | struct ospf6_route *next; | |
718e3744 | 166 | |
22813fdb MR |
167 | /* Back pointer to ospf6 */ |
168 | struct ospf6 *ospf6; | |
169 | ||
d62a17ae | 170 | unsigned int lock; |
718e3744 | 171 | |
d62a17ae | 172 | /* Destination Type */ |
d7c0a89a | 173 | uint8_t type; |
508e53e2 | 174 | |
d62a17ae | 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 | |
177 | * them | |
178 | * into one. See also XXX below. | |
179 | */ | |
180 | /* Destination ID */ | |
181 | struct prefix prefix; | |
508e53e2 | 182 | |
d62a17ae | 183 | /* Time */ |
184 | struct timeval installed; | |
185 | struct timeval changed; | |
718e3744 | 186 | |
d62a17ae | 187 | /* flag */ |
3c77bc80 | 188 | uint16_t flag; |
718e3744 | 189 | |
4699ad72 DL |
190 | /* Prefix Options */ |
191 | uint8_t prefix_options; | |
192 | ||
d62a17ae | 193 | /* route option */ |
194 | void *route_option; | |
049207c3 | 195 | |
d62a17ae | 196 | /* link state id for advertising */ |
d7c0a89a | 197 | uint32_t linkstate_id; |
c3c0ac83 | 198 | |
d62a17ae | 199 | /* path */ |
200 | struct ospf6_path path; | |
c3c0ac83 | 201 | |
064d4355 CS |
202 | /* List of Paths. */ |
203 | struct list *paths; | |
204 | ||
d62a17ae | 205 | /* nexthop */ |
206 | struct list *nh_list; | |
4dc43886 MR |
207 | |
208 | /* points to the summarised route */ | |
209 | struct ospf6_external_aggr_rt *aggr_route; | |
210 | ||
211 | /* For Aggr routes */ | |
212 | bool to_be_processed; | |
718e3744 | 213 | }; |
214 | ||
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 | |
508e53e2 | 219 | #define OSPF6_DEST_TYPE_LINKSTATE 4 |
6452df09 | 220 | #define OSPF6_DEST_TYPE_RANGE 5 |
221 | #define OSPF6_DEST_TYPE_MAX 6 | |
718e3744 | 222 | |
3c77bc80 RW |
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 | |
beadc736 | 232 | struct ospf6; |
718e3744 | 233 | |
d62a17ae | 234 | struct ospf6_route_table { |
235 | int scope_type; | |
236 | int table_type; | |
237 | void *scope; | |
cf1ce250 | 238 | |
d62a17ae | 239 | /* patricia tree */ |
240 | struct route_table *table; | |
718e3744 | 241 | |
d7c0a89a | 242 | uint32_t count; |
718e3744 | 243 | |
d62a17ae | 244 | /* hooks */ |
e285b70d | 245 | void (*hook_add)(struct ospf6_route *); |
d62a17ae | 246 | void (*hook_change)(struct ospf6_route *); |
e285b70d | 247 | void (*hook_remove)(struct ospf6_route *); |
508e53e2 | 248 | }; |
718e3744 | 249 | |
cf1ce250 PJ |
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 | |
254 | ||
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 | |
264 | ||
d62a17ae | 265 | #define OSPF6_ROUTE_TABLE_CREATE(s, t) \ |
266 | ospf6_route_table_create(OSPF6_SCOPE_TYPE_##s, OSPF6_TABLE_TYPE_##t) | |
cf1ce250 | 267 | |
2b64873d DL |
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]; | |
d62a17ae | 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]) | |
508e53e2 | 276 | |
2b64873d DL |
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]; | |
d62a17ae | 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]) | |
eacd0828 YR |
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]) | |
508e53e2 | 288 | |
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" | |
292 | ||
66314e9f | 293 | #define ospf6_route_is_prefix(p, r) (prefix_same(p, &(r)->prefix)) |
d62a17ae | 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 \ | |
66314e9f IR |
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) | |
c3c0ac83 | 300 | |
508e53e2 | 301 | #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST)) |
302 | ||
d62a17ae | 303 | #define ospf6_linkstate_prefix_adv_router(x) ((x)->u.lp.id.s_addr) |
304 | #define ospf6_linkstate_prefix_id(x) ((x)->u.lp.adv_router.s_addr) | |
508e53e2 | 305 | |
d62a17ae | 306 | #define ADV_ROUTER_IN_PREFIX(x) ((x)->u.lp.id.s_addr) |
3b68735f | 307 | |
508e53e2 | 308 | /* Function prototype */ |
d7c0a89a | 309 | extern void ospf6_linkstate_prefix(uint32_t adv_router, uint32_t id, |
d62a17ae | 310 | struct prefix *prefix); |
311 | extern void ospf6_linkstate_prefix2str(struct prefix *prefix, char *buf, | |
312 | int size); | |
313 | ||
314 | extern struct ospf6_nexthop *ospf6_nexthop_create(void); | |
064d4355 | 315 | extern int ospf6_nexthop_cmp(struct ospf6_nexthop *a, struct ospf6_nexthop *b); |
d62a17ae | 316 | extern void ospf6_nexthop_delete(struct ospf6_nexthop *nh); |
d62a17ae | 317 | extern void ospf6_clear_nexthops(struct list *nh_list); |
318 | extern int ospf6_num_nexthops(struct list *nh_list); | |
319 | extern void ospf6_copy_nexthops(struct list *dst, struct list *src); | |
320 | extern void ospf6_merge_nexthops(struct list *dst, struct list *src); | |
321 | extern void ospf6_add_nexthop(struct list *nh_list, int ifindex, | |
322 | struct in6_addr *addr); | |
d2e5d5d4 | 323 | extern void ospf6_add_route_nexthop_blackhole(struct ospf6_route *route); |
d62a17ae | 324 | extern int ospf6_num_nexthops(struct list *nh_list); |
325 | extern int ospf6_route_cmp_nexthops(struct ospf6_route *a, | |
326 | struct ospf6_route *b); | |
327 | extern void ospf6_route_zebra_copy_nexthops(struct ospf6_route *route, | |
5afa1c6b | 328 | struct zapi_nexthop nexthops[], |
1fa58587 | 329 | int entries, vrf_id_t vrf_id); |
d62a17ae | 330 | extern int ospf6_route_get_first_nh_index(struct ospf6_route *route); |
c3c0ac83 DS |
331 | |
332 | /* Hide abstraction of nexthop implementation in route from outsiders */ | |
333 | #define ospf6_route_copy_nexthops(dst, src) ospf6_copy_nexthops(dst->nh_list, src->nh_list) | |
334 | #define ospf6_route_merge_nexthops(dst, src) ospf6_merge_nexthops(dst->nh_list, src->nh_list) | |
335 | #define ospf6_route_num_nexthops(route) ospf6_num_nexthops(route->nh_list) | |
d62a17ae | 336 | #define ospf6_route_add_nexthop(route, ifindex, addr) \ |
337 | ospf6_add_nexthop(route->nh_list, ifindex, addr) | |
338 | ||
22813fdb | 339 | extern struct ospf6_route *ospf6_route_create(struct ospf6 *ospf6); |
7932dd93 | 340 | extern void ospf6_route_delete(struct ospf6_route *route); |
d62a17ae | 341 | extern struct ospf6_route *ospf6_route_copy(struct ospf6_route *route); |
342 | extern int ospf6_route_cmp(struct ospf6_route *ra, struct ospf6_route *rb); | |
343 | ||
344 | extern void ospf6_route_lock(struct ospf6_route *route); | |
345 | extern void ospf6_route_unlock(struct ospf6_route *route); | |
d62a17ae | 346 | extern struct ospf6_route *ospf6_route_lookup(struct prefix *prefix, |
347 | struct ospf6_route_table *table); | |
348 | extern struct ospf6_route * | |
349 | ospf6_route_lookup_identical(struct ospf6_route *route, | |
350 | struct ospf6_route_table *table); | |
351 | extern struct ospf6_route * | |
352 | ospf6_route_lookup_bestmatch(struct prefix *prefix, | |
353 | struct ospf6_route_table *table); | |
354 | ||
355 | extern struct ospf6_route *ospf6_route_add(struct ospf6_route *route, | |
e285b70d | 356 | struct ospf6_route_table *table); |
d62a17ae | 357 | extern void ospf6_route_remove(struct ospf6_route *route, |
e285b70d | 358 | struct ospf6_route_table *table); |
d62a17ae | 359 | |
360 | extern struct ospf6_route *ospf6_route_head(struct ospf6_route_table *table); | |
361 | extern struct ospf6_route *ospf6_route_next(struct ospf6_route *route); | |
362 | extern struct ospf6_route *ospf6_route_best_next(struct ospf6_route *route); | |
363 | ||
364 | extern struct ospf6_route * | |
365 | ospf6_route_match_head(struct prefix *prefix, struct ospf6_route_table *table); | |
366 | extern struct ospf6_route *ospf6_route_match_next(struct prefix *prefix, | |
367 | struct ospf6_route *route); | |
368 | ||
e285b70d | 369 | extern void ospf6_route_remove_all(struct ospf6_route_table *table); |
d62a17ae | 370 | extern struct ospf6_route_table *ospf6_route_table_create(int s, int t); |
e285b70d | 371 | extern void ospf6_route_table_delete(struct ospf6_route_table *table); |
d62a17ae | 372 | extern void ospf6_route_dump(struct ospf6_route_table *table); |
373 | ||
374 | ||
eacd0828 YR |
375 | extern void ospf6_route_show(struct vty *vty, struct ospf6_route *route, |
376 | json_object *json, bool use_json); | |
377 | extern void ospf6_route_show_detail(struct vty *vty, struct ospf6_route *route, | |
378 | json_object *json, bool use_json); | |
379 | ||
d62a17ae | 380 | |
7932dd93 DS |
381 | extern int ospf6_route_table_show(struct vty *vty, int argc_start, int argc, |
382 | struct cmd_token **argv, | |
383 | struct ospf6_route_table *table, | |
384 | bool use_json); | |
d62a17ae | 385 | extern int ospf6_linkstate_table_show(struct vty *vty, int idx_ipv4, int argc, |
386 | struct cmd_token **argv, | |
387 | struct ospf6_route_table *table); | |
388 | ||
389 | extern void ospf6_brouter_show_header(struct vty *vty); | |
390 | extern void ospf6_brouter_show(struct vty *vty, struct ospf6_route *route); | |
391 | ||
392 | extern int config_write_ospf6_debug_route(struct vty *vty); | |
393 | extern void install_element_ospf6_debug_route(void); | |
394 | extern void ospf6_route_init(void); | |
064d4355 CS |
395 | extern void ospf6_path_free(struct ospf6_path *op); |
396 | extern struct ospf6_path *ospf6_path_dup(struct ospf6_path *path); | |
03f3c1c1 | 397 | extern void ospf6_copy_paths(struct list *dst, struct list *src); |
718e3744 | 398 | |
399 | #endif /* OSPF6_ROUTE_H */ |