Line data Source code
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 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)
43 :
44 : /* Nexthop */
45 : struct ospf6_nexthop {
46 : /* Interface index */
47 : ifindex_t ifindex;
48 :
49 : /* IP address, if any */
50 : struct in6_addr address;
51 :
52 : /** Next-hop type information. */
53 : enum nexthop_types_t type;
54 : };
55 :
56 566 : static inline bool ospf6_nexthop_is_set(const struct ospf6_nexthop *nh)
57 : {
58 566 : return nh->type != 0;
59 : }
60 :
61 136 : static inline bool ospf6_nexthop_is_same(const struct ospf6_nexthop *nha,
62 : const struct ospf6_nexthop *nhb)
63 : {
64 136 : if (nha->type != nhb->type)
65 : return false;
66 :
67 136 : switch (nha->type) {
68 : case NEXTHOP_TYPE_BLACKHOLE:
69 : /* NOTHING */
70 : break;
71 :
72 38 : case NEXTHOP_TYPE_IFINDEX:
73 38 : 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 98 : case NEXTHOP_TYPE_IPV6_IFINDEX:
83 98 : if (nha->ifindex != nhb->ifindex)
84 : return false;
85 : /* FALLTHROUGH */
86 : case NEXTHOP_TYPE_IPV6:
87 83 : if (!IN6_ARE_ADDR_EQUAL(&nha->address, &nhb->address))
88 : return false;
89 : break;
90 : }
91 :
92 : return true;
93 : }
94 :
95 0 : static inline void ospf6_nexthop_clear(struct ospf6_nexthop *nh)
96 : {
97 0 : memset(nh, 0, sizeof(*nh));
98 : }
99 :
100 829 : static inline void ospf6_nexthop_copy(struct ospf6_nexthop *nha,
101 : const struct ospf6_nexthop *nhb)
102 : {
103 829 : memcpy(nha, nhb, sizeof(*nha));
104 : }
105 :
106 : /* Path */
107 : struct ospf6_ls_origin {
108 : uint16_t type;
109 : in_addr_t id;
110 : in_addr_t adv_router;
111 : };
112 :
113 : struct ospf6_path {
114 : /* Link State Origin */
115 : struct ospf6_ls_origin origin;
116 :
117 : /* Router bits */
118 : uint8_t router_bits;
119 :
120 : /* Optional Capabilities */
121 : uint8_t options[3];
122 :
123 : /* Associated Area */
124 : in_addr_t area_id;
125 :
126 : /* Path-type */
127 : uint8_t type;
128 : uint8_t subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
129 :
130 : /* Cost */
131 : uint8_t metric_type;
132 : uint32_t cost;
133 :
134 : struct prefix ls_prefix;
135 :
136 : union {
137 : uint32_t cost_e2;
138 : uint32_t cost_config;
139 : } u;
140 : uint32_t tag;
141 :
142 : /* nh list for this path */
143 : struct list *nh_list;
144 : };
145 :
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
152 :
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 :
157 : #include "prefix.h"
158 : #include "table.h"
159 : #include "bitfield.h"
160 :
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;
166 :
167 : /* Back pointer to ospf6 */
168 : struct ospf6 *ospf6;
169 :
170 : unsigned int lock;
171 :
172 : /* Destination Type */
173 : uint8_t type;
174 :
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;
182 :
183 : /* Time */
184 : struct timeval installed;
185 : struct timeval changed;
186 :
187 : /* flag */
188 : uint16_t flag;
189 :
190 : /* Prefix Options */
191 : uint8_t prefix_options;
192 :
193 : /* route option */
194 : void *route_option;
195 :
196 : /* link state id for advertising */
197 : uint32_t linkstate_id;
198 :
199 : /* path */
200 : struct ospf6_path path;
201 :
202 : /* List of Paths. */
203 : struct list *paths;
204 :
205 : /* nexthop */
206 : struct list *nh_list;
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;
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
219 : #define OSPF6_DEST_TYPE_LINKSTATE 4
220 : #define OSPF6_DEST_TYPE_RANGE 5
221 : #define OSPF6_DEST_TYPE_MAX 6
222 :
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
232 : struct ospf6;
233 :
234 : struct ospf6_route_table {
235 : int scope_type;
236 : int table_type;
237 : void *scope;
238 :
239 : /* patricia tree */
240 : struct route_table *table;
241 :
242 : uint32_t count;
243 :
244 : /* hooks */
245 : void (*hook_add)(struct ospf6_route *);
246 : void (*hook_change)(struct ospf6_route *);
247 : void (*hook_remove)(struct ospf6_route *);
248 : };
249 :
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 :
265 : #define OSPF6_ROUTE_TABLE_CREATE(s, t) \
266 : ospf6_route_table_create(OSPF6_SCOPE_TYPE_##s, OSPF6_TABLE_TYPE_##t)
267 :
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])
276 :
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])
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 :
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))
308 :
309 : #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
310 :
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)
313 :
314 : #define ADV_ROUTER_IN_PREFIX(x) ((x)->u.lp.id.s_addr)
315 :
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,
320 : int size);
321 :
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);
339 :
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)
346 :
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);
351 :
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);
362 :
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);
367 :
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);
371 :
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);
376 :
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);
381 :
382 :
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);
387 :
388 :
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,
392 : bool use_json);
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);
396 :
397 : extern void ospf6_brouter_show_header(struct vty *vty);
398 : extern void ospf6_brouter_show(struct vty *vty, struct ospf6_route *route);
399 :
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);
406 :
407 : #endif /* OSPF6_ROUTE_H */
|