blob: 027a648a3b3e7a1f8343d6347d67a7add81b1131 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
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
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22#ifndef OSPF6_ROUTE_H
23#define OSPF6_ROUTE_H
24
hasso508e53e2004-05-18 18:57:06 +000025#define OSPF6_MULTI_PATH_LIMIT 4
paul718e3742002-12-13 20:15:29 +000026
hasso508e53e2004-05-18 18:57:06 +000027/* Debug option */
28extern unsigned char conf_debug_ospf6_route;
29#define OSPF6_DEBUG_ROUTE_TABLE 0x01
30#define OSPF6_DEBUG_ROUTE_INTRA 0x02
31#define OSPF6_DEBUG_ROUTE_INTER 0x04
Paul Jakmacf1ce252006-05-15 10:46:07 +000032#define OSPF6_DEBUG_ROUTE_MEMORY 0x80
hasso508e53e2004-05-18 18:57:06 +000033#define OSPF6_DEBUG_ROUTE_ON(level) \
34 (conf_debug_ospf6_route |= (level))
35#define OSPF6_DEBUG_ROUTE_OFF(level) \
36 (conf_debug_ospf6_route &= ~(level))
37#define IS_OSPF6_DEBUG_ROUTE(e) \
38 (conf_debug_ospf6_route & OSPF6_DEBUG_ROUTE_ ## e)
39
40/* Nexthop */
41struct ospf6_nexthop
paul718e3742002-12-13 20:15:29 +000042{
hasso508e53e2004-05-18 18:57:06 +000043 /* Interface index */
Paul Jakma9099f9b2016-01-18 10:12:10 +000044 ifindex_t ifindex;
paul718e3742002-12-13 20:15:29 +000045
hasso508e53e2004-05-18 18:57:06 +000046 /* IP address, if any */
47 struct in6_addr address;
paul718e3742002-12-13 20:15:29 +000048};
49
hasso508e53e2004-05-18 18:57:06 +000050#define ospf6_nexthop_is_set(x) \
51 ((x)->ifindex || ! IN6_IS_ADDR_UNSPECIFIED (&(x)->address))
52#define ospf6_nexthop_is_same(a,b) \
53 ((a)->ifindex == (b)->ifindex && \
54 IN6_ARE_ADDR_EQUAL (&(a)->address, &(b)->address))
55#define ospf6_nexthop_clear(x) \
56 do { \
57 (x)->ifindex = 0; \
58 memset (&(x)->address, 0, sizeof (struct in6_addr)); \
59 } while (0)
60#define ospf6_nexthop_copy(a, b) \
61 do { \
62 (a)->ifindex = (b)->ifindex; \
63 memcpy (&(a)->address, &(b)->address, \
64 sizeof (struct in6_addr)); \
65 } while (0)
paul718e3742002-12-13 20:15:29 +000066
67/* Path */
hasso508e53e2004-05-18 18:57:06 +000068struct ospf6_ls_origin
paul718e3742002-12-13 20:15:29 +000069{
70 u_int16_t type;
71 u_int32_t id;
72 u_int32_t adv_router;
73};
74
75struct ospf6_path
76{
77 /* Link State Origin */
hasso508e53e2004-05-18 18:57:06 +000078 struct ospf6_ls_origin origin;
paul718e3742002-12-13 20:15:29 +000079
80 /* Router bits */
81 u_char router_bits;
82
83 /* Optional Capabilities */
hasso508e53e2004-05-18 18:57:06 +000084 u_char options[3];
paul718e3742002-12-13 20:15:29 +000085
86 /* Prefix Options */
87 u_char prefix_options;
88
89 /* Associated Area */
90 u_int32_t area_id;
91
92 /* Path-type */
93 u_char type;
hasso6452df02004-08-15 05:52:07 +000094 u_char subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
paul718e3742002-12-13 20:15:29 +000095
96 /* Cost */
97 u_int8_t metric_type;
98 u_int32_t cost;
99 u_int32_t cost_e2;
Christian Franke7ae2b602016-10-01 06:41:40 +0200100 u_int32_t tag;
paul718e3742002-12-13 20:15:29 +0000101};
102
hasso6452df02004-08-15 05:52:07 +0000103#define OSPF6_PATH_TYPE_NONE 0
104#define OSPF6_PATH_TYPE_INTRA 1
105#define OSPF6_PATH_TYPE_INTER 2
106#define OSPF6_PATH_TYPE_EXTERNAL1 3
107#define OSPF6_PATH_TYPE_EXTERNAL2 4
108#define OSPF6_PATH_TYPE_REDISTRIBUTE 5
109#define OSPF6_PATH_TYPE_MAX 6
hasso508e53e2004-05-18 18:57:06 +0000110
111#include "prefix.h"
112#include "table.h"
113
114struct ospf6_route
paul718e3742002-12-13 20:15:29 +0000115{
hasso508e53e2004-05-18 18:57:06 +0000116 struct route_node *rnode;
Paul Jakmacf1ce252006-05-15 10:46:07 +0000117 struct ospf6_route_table *table;
hasso508e53e2004-05-18 18:57:06 +0000118 struct ospf6_route *prev;
119 struct ospf6_route *next;
paul718e3742002-12-13 20:15:29 +0000120
hasso508e53e2004-05-18 18:57:06 +0000121 unsigned int lock;
paul718e3742002-12-13 20:15:29 +0000122
hasso508e53e2004-05-18 18:57:06 +0000123 /* Destination Type */
124 u_char type;
paul718e3742002-12-13 20:15:29 +0000125
Paul Jakma7aa9dce2014-09-19 14:42:23 +0100126 /* XXX: It would likely be better to use separate struct in_addr's
127 * for the advertising router-ID and prefix IDs, instead of stuffing them
128 * into one. See also XXX below.
129 */
hasso508e53e2004-05-18 18:57:06 +0000130 /* Destination ID */
131 struct prefix prefix;
paul718e3742002-12-13 20:15:29 +0000132
hasso508e53e2004-05-18 18:57:06 +0000133 /* Time */
paul718e3742002-12-13 20:15:29 +0000134 struct timeval installed;
hasso508e53e2004-05-18 18:57:06 +0000135 struct timeval changed;
paul718e3742002-12-13 20:15:29 +0000136
hasso508e53e2004-05-18 18:57:06 +0000137 /* flag */
138 u_char flag;
paul718e3742002-12-13 20:15:29 +0000139
hasso508e53e2004-05-18 18:57:06 +0000140 /* path */
141 struct ospf6_path path;
paul718e3742002-12-13 20:15:29 +0000142
hasso508e53e2004-05-18 18:57:06 +0000143 /* nexthop */
144 struct ospf6_nexthop nexthop[OSPF6_MULTI_PATH_LIMIT];
145
146 /* route option */
147 void *route_option;
hasso049207c2004-08-04 20:02:13 +0000148
149 /* link state id for advertising */
150 u_int32_t linkstate_id;
paul718e3742002-12-13 20:15:29 +0000151};
152
153#define OSPF6_DEST_TYPE_NONE 0
154#define OSPF6_DEST_TYPE_ROUTER 1
155#define OSPF6_DEST_TYPE_NETWORK 2
156#define OSPF6_DEST_TYPE_DISCARD 3
hasso508e53e2004-05-18 18:57:06 +0000157#define OSPF6_DEST_TYPE_LINKSTATE 4
hasso6452df02004-08-15 05:52:07 +0000158#define OSPF6_DEST_TYPE_RANGE 5
159#define OSPF6_DEST_TYPE_MAX 6
paul718e3742002-12-13 20:15:29 +0000160
hasso6452df02004-08-15 05:52:07 +0000161#define OSPF6_ROUTE_CHANGE 0x01
162#define OSPF6_ROUTE_ADD 0x02
163#define OSPF6_ROUTE_REMOVE 0x04
164#define OSPF6_ROUTE_BEST 0x08
hasso4846ef62004-09-03 06:04:00 +0000165#define OSPF6_ROUTE_ACTIVE_SUMMARY 0x10
166#define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x20
hasso9428f2d2004-09-13 14:01:12 +0000167#define OSPF6_ROUTE_WAS_REMOVED 0x40
paul718e3742002-12-13 20:15:29 +0000168
hasso508e53e2004-05-18 18:57:06 +0000169struct ospf6_route_table
170{
Paul Jakmacf1ce252006-05-15 10:46:07 +0000171 int scope_type;
172 int table_type;
173 void *scope;
174
hasso508e53e2004-05-18 18:57:06 +0000175 /* patricia tree */
176 struct route_table *table;
paul718e3742002-12-13 20:15:29 +0000177
hasso508e53e2004-05-18 18:57:06 +0000178 u_int32_t count;
paul718e3742002-12-13 20:15:29 +0000179
hasso508e53e2004-05-18 18:57:06 +0000180 /* hooks */
181 void (*hook_add) (struct ospf6_route *);
182 void (*hook_change) (struct ospf6_route *);
183 void (*hook_remove) (struct ospf6_route *);
184};
185
Paul Jakmacf1ce252006-05-15 10:46:07 +0000186#define OSPF6_SCOPE_TYPE_NONE 0
187#define OSPF6_SCOPE_TYPE_GLOBAL 1
188#define OSPF6_SCOPE_TYPE_AREA 2
189#define OSPF6_SCOPE_TYPE_INTERFACE 3
190
191#define OSPF6_TABLE_TYPE_NONE 0
192#define OSPF6_TABLE_TYPE_ROUTES 1
193#define OSPF6_TABLE_TYPE_BORDER_ROUTERS 2
194#define OSPF6_TABLE_TYPE_CONNECTED_ROUTES 3
195#define OSPF6_TABLE_TYPE_EXTERNAL_ROUTES 4
196#define OSPF6_TABLE_TYPE_SPF_RESULTS 5
197#define OSPF6_TABLE_TYPE_PREFIX_RANGES 6
198#define OSPF6_TABLE_TYPE_SUMMARY_PREFIXES 7
199#define OSPF6_TABLE_TYPE_SUMMARY_ROUTERS 8
200
201#define OSPF6_ROUTE_TABLE_CREATE(s, t) \
202 ospf6_route_table_create (OSPF6_SCOPE_TYPE_ ## s, \
203 OSPF6_TABLE_TYPE_ ## t)
204
paul0c083ee2004-10-10 12:54:58 +0000205extern const char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX];
206extern const char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX];
hasso508e53e2004-05-18 18:57:06 +0000207#define OSPF6_DEST_TYPE_NAME(x) \
208 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
209 ospf6_dest_type_str[(x)] : ospf6_dest_type_str[0])
210#define OSPF6_DEST_TYPE_SUBSTR(x) \
211 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
212 ospf6_dest_type_substr[(x)] : ospf6_dest_type_substr[0])
213
paul0c083ee2004-10-10 12:54:58 +0000214extern const char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX];
215extern const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
hasso508e53e2004-05-18 18:57:06 +0000216#define OSPF6_PATH_TYPE_NAME(x) \
217 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
218 ospf6_path_type_str[(x)] : ospf6_path_type_str[0])
219#define OSPF6_PATH_TYPE_SUBSTR(x) \
220 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
221 ospf6_path_type_substr[(x)] : ospf6_path_type_substr[0])
222
223#define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n"
224#define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
225#define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"
226
227#define ospf6_route_is_prefix(p, r) \
228 (memcmp (p, &(r)->prefix, sizeof (struct prefix)) == 0)
229#define ospf6_route_is_same(ra, rb) \
230 (prefix_same (&(ra)->prefix, &(rb)->prefix))
231#define ospf6_route_is_same_origin(ra, rb) \
232 ((ra)->path.area_id == (rb)->path.area_id && \
233 memcmp (&(ra)->path.origin, &(rb)->path.origin, \
234 sizeof (struct ospf6_ls_origin)) == 0)
235#define ospf6_route_is_identical(ra, rb) \
236 ((ra)->type == (rb)->type && \
237 memcmp (&(ra)->prefix, &(rb)->prefix, sizeof (struct prefix)) == 0 && \
238 memcmp (&(ra)->path, &(rb)->path, sizeof (struct ospf6_path)) == 0 && \
239 memcmp (&(ra)->nexthop, &(rb)->nexthop, \
240 sizeof (struct ospf6_nexthop) * OSPF6_MULTI_PATH_LIMIT) == 0)
241#define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
242
243#define ospf6_linkstate_prefix_adv_router(x) \
David Lamparter0de01382015-03-03 10:30:27 +0100244 ((x)->u.lp.id.s_addr)
hasso508e53e2004-05-18 18:57:06 +0000245#define ospf6_linkstate_prefix_id(x) \
David Lamparter0de01382015-03-03 10:30:27 +0100246 ((x)->u.lp.adv_router.s_addr)
hasso508e53e2004-05-18 18:57:06 +0000247
hasso3b687352004-08-19 06:56:53 +0000248#define ADV_ROUTER_IN_PREFIX(x) \
David Lamparter0de01382015-03-03 10:30:27 +0100249 ((x)->u.lp.id.s_addr)
hassoccb59b12004-08-25 09:10:37 +0000250#define ID_IN_PREFIX(x) \
David Lamparter0de01382015-03-03 10:30:27 +0100251 ((x)->u.lp.adv_router.s_addr)
hasso3b687352004-08-19 06:56:53 +0000252
hasso508e53e2004-05-18 18:57:06 +0000253/* Function prototype */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100254extern void ospf6_linkstate_prefix (u_int32_t adv_router, u_int32_t id,
255 struct prefix *prefix);
256extern void ospf6_linkstate_prefix2str (struct prefix *prefix, char *buf,
257 int size);
hasso508e53e2004-05-18 18:57:06 +0000258
Paul Jakma6ac29a52008-08-15 13:45:30 +0100259extern struct ospf6_route *ospf6_route_create (void);
260extern void ospf6_route_delete (struct ospf6_route *);
261extern struct ospf6_route *ospf6_route_copy (struct ospf6_route *route);
hasso508e53e2004-05-18 18:57:06 +0000262
Paul Jakma6ac29a52008-08-15 13:45:30 +0100263extern void ospf6_route_lock (struct ospf6_route *route);
264extern void ospf6_route_unlock (struct ospf6_route *route);
hasso508e53e2004-05-18 18:57:06 +0000265
Paul Jakma6ac29a52008-08-15 13:45:30 +0100266extern struct ospf6_route *ospf6_route_lookup (struct prefix *prefix,
267 struct ospf6_route_table *table);
268extern struct ospf6_route *ospf6_route_lookup_identical (struct ospf6_route *route,
hasso508e53e2004-05-18 18:57:06 +0000269 struct ospf6_route_table *table);
Paul Jakma6ac29a52008-08-15 13:45:30 +0100270extern struct ospf6_route *ospf6_route_lookup_bestmatch (struct prefix *prefix,
271 struct ospf6_route_table *table);
272
273extern struct ospf6_route *ospf6_route_add (struct ospf6_route *route,
274 struct ospf6_route_table *table);
275extern void ospf6_route_remove (struct ospf6_route *route,
276 struct ospf6_route_table *table);
277
278extern struct ospf6_route *ospf6_route_head (struct ospf6_route_table *table);
279extern struct ospf6_route *ospf6_route_next (struct ospf6_route *route);
280extern struct ospf6_route *ospf6_route_best_next (struct ospf6_route *route);
281
282extern struct ospf6_route *ospf6_route_match_head (struct prefix *prefix,
283 struct ospf6_route_table *table);
284extern struct ospf6_route *ospf6_route_match_next (struct prefix *prefix,
hasso508e53e2004-05-18 18:57:06 +0000285 struct ospf6_route *route);
286
Paul Jakma6ac29a52008-08-15 13:45:30 +0100287extern void ospf6_route_remove_all (struct ospf6_route_table *);
288extern struct ospf6_route_table *ospf6_route_table_create (int s, int t);
289extern void ospf6_route_table_delete (struct ospf6_route_table *);
290extern void ospf6_route_dump (struct ospf6_route_table *table);
paul718e3742002-12-13 20:15:29 +0000291
hasso6452df02004-08-15 05:52:07 +0000292
Paul Jakma6ac29a52008-08-15 13:45:30 +0100293extern void ospf6_route_show (struct vty *vty, struct ospf6_route *route);
294extern void ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route);
hasso6452df02004-08-15 05:52:07 +0000295
Paul Jakma6ac29a52008-08-15 13:45:30 +0100296extern int ospf6_route_table_show (struct vty *, int, const char *[],
297 struct ospf6_route_table *);
298extern int ospf6_linkstate_table_show (struct vty *vty, int argc,
299 const char *argv[],
300 struct ospf6_route_table *table);
hasso508e53e2004-05-18 18:57:06 +0000301
Paul Jakma6ac29a52008-08-15 13:45:30 +0100302extern void ospf6_brouter_show_header (struct vty *vty);
303extern void ospf6_brouter_show (struct vty *vty, struct ospf6_route *route);
hasso6452df02004-08-15 05:52:07 +0000304
Paul Jakma6ac29a52008-08-15 13:45:30 +0100305extern int config_write_ospf6_debug_route (struct vty *vty);
306extern void install_element_ospf6_debug_route (void);
307extern void ospf6_route_init (void);
Phil Laverdiereef2d5d12012-01-02 20:04:26 +0400308extern void ospf6_clean (void);
paul718e3742002-12-13 20:15:29 +0000309
310#endif /* OSPF6_ROUTE_H */
311