blob: d9456a1435d0f091797df85140a5e72ad738a670 [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
32#define OSPF6_DEBUG_ROUTE_ON(level) \
33 (conf_debug_ospf6_route |= (level))
34#define OSPF6_DEBUG_ROUTE_OFF(level) \
35 (conf_debug_ospf6_route &= ~(level))
36#define IS_OSPF6_DEBUG_ROUTE(e) \
37 (conf_debug_ospf6_route & OSPF6_DEBUG_ROUTE_ ## e)
38
39/* Nexthop */
40struct ospf6_nexthop
paul718e3742002-12-13 20:15:29 +000041{
hasso508e53e2004-05-18 18:57:06 +000042 /* Interface index */
43 unsigned int ifindex;
paul718e3742002-12-13 20:15:29 +000044
hasso508e53e2004-05-18 18:57:06 +000045 /* IP address, if any */
46 struct in6_addr address;
paul718e3742002-12-13 20:15:29 +000047};
48
hasso508e53e2004-05-18 18:57:06 +000049#define ospf6_nexthop_is_set(x) \
50 ((x)->ifindex || ! IN6_IS_ADDR_UNSPECIFIED (&(x)->address))
51#define ospf6_nexthop_is_same(a,b) \
52 ((a)->ifindex == (b)->ifindex && \
53 IN6_ARE_ADDR_EQUAL (&(a)->address, &(b)->address))
54#define ospf6_nexthop_clear(x) \
55 do { \
56 (x)->ifindex = 0; \
57 memset (&(x)->address, 0, sizeof (struct in6_addr)); \
58 } while (0)
59#define ospf6_nexthop_copy(a, b) \
60 do { \
61 (a)->ifindex = (b)->ifindex; \
62 memcpy (&(a)->address, &(b)->address, \
63 sizeof (struct in6_addr)); \
64 } while (0)
paul718e3742002-12-13 20:15:29 +000065
66/* Path */
hasso508e53e2004-05-18 18:57:06 +000067struct ospf6_ls_origin
paul718e3742002-12-13 20:15:29 +000068{
69 u_int16_t type;
70 u_int32_t id;
71 u_int32_t adv_router;
72};
73
74struct ospf6_path
75{
76 /* Link State Origin */
hasso508e53e2004-05-18 18:57:06 +000077 struct ospf6_ls_origin origin;
paul718e3742002-12-13 20:15:29 +000078
79 /* Router bits */
80 u_char router_bits;
81
82 /* Optional Capabilities */
hasso508e53e2004-05-18 18:57:06 +000083 u_char options[3];
paul718e3742002-12-13 20:15:29 +000084
85 /* Prefix Options */
86 u_char prefix_options;
87
88 /* Associated Area */
89 u_int32_t area_id;
90
91 /* Path-type */
92 u_char type;
hasso6452df02004-08-15 05:52:07 +000093 u_char subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
paul718e3742002-12-13 20:15:29 +000094
95 /* Cost */
96 u_int8_t metric_type;
97 u_int32_t cost;
98 u_int32_t cost_e2;
99};
100
hasso6452df02004-08-15 05:52:07 +0000101#define OSPF6_PATH_TYPE_NONE 0
102#define OSPF6_PATH_TYPE_INTRA 1
103#define OSPF6_PATH_TYPE_INTER 2
104#define OSPF6_PATH_TYPE_EXTERNAL1 3
105#define OSPF6_PATH_TYPE_EXTERNAL2 4
106#define OSPF6_PATH_TYPE_REDISTRIBUTE 5
107#define OSPF6_PATH_TYPE_MAX 6
hasso508e53e2004-05-18 18:57:06 +0000108
109#include "prefix.h"
110#include "table.h"
111
112struct ospf6_route
paul718e3742002-12-13 20:15:29 +0000113{
hasso508e53e2004-05-18 18:57:06 +0000114 struct route_node *rnode;
paul718e3742002-12-13 20:15:29 +0000115
hasso508e53e2004-05-18 18:57:06 +0000116 struct ospf6_route *prev;
117 struct ospf6_route *next;
paul718e3742002-12-13 20:15:29 +0000118
hasso508e53e2004-05-18 18:57:06 +0000119 unsigned int lock;
paul718e3742002-12-13 20:15:29 +0000120
hasso508e53e2004-05-18 18:57:06 +0000121 /* Destination Type */
122 u_char type;
paul718e3742002-12-13 20:15:29 +0000123
hasso508e53e2004-05-18 18:57:06 +0000124 /* Destination ID */
125 struct prefix prefix;
paul718e3742002-12-13 20:15:29 +0000126
hasso508e53e2004-05-18 18:57:06 +0000127 /* Time */
paul718e3742002-12-13 20:15:29 +0000128 struct timeval installed;
hasso508e53e2004-05-18 18:57:06 +0000129 struct timeval changed;
paul718e3742002-12-13 20:15:29 +0000130
hasso508e53e2004-05-18 18:57:06 +0000131 /* flag */
132 u_char flag;
paul718e3742002-12-13 20:15:29 +0000133
hasso508e53e2004-05-18 18:57:06 +0000134 /* path */
135 struct ospf6_path path;
paul718e3742002-12-13 20:15:29 +0000136
hasso508e53e2004-05-18 18:57:06 +0000137 /* nexthop */
138 struct ospf6_nexthop nexthop[OSPF6_MULTI_PATH_LIMIT];
139
140 /* route option */
141 void *route_option;
hasso049207c2004-08-04 20:02:13 +0000142
143 /* link state id for advertising */
144 u_int32_t linkstate_id;
paul718e3742002-12-13 20:15:29 +0000145};
146
147#define OSPF6_DEST_TYPE_NONE 0
148#define OSPF6_DEST_TYPE_ROUTER 1
149#define OSPF6_DEST_TYPE_NETWORK 2
150#define OSPF6_DEST_TYPE_DISCARD 3
hasso508e53e2004-05-18 18:57:06 +0000151#define OSPF6_DEST_TYPE_LINKSTATE 4
hasso6452df02004-08-15 05:52:07 +0000152#define OSPF6_DEST_TYPE_RANGE 5
153#define OSPF6_DEST_TYPE_MAX 6
paul718e3742002-12-13 20:15:29 +0000154
hasso6452df02004-08-15 05:52:07 +0000155#define OSPF6_ROUTE_CHANGE 0x01
156#define OSPF6_ROUTE_ADD 0x02
157#define OSPF6_ROUTE_REMOVE 0x04
158#define OSPF6_ROUTE_BEST 0x08
hasso4846ef62004-09-03 06:04:00 +0000159#define OSPF6_ROUTE_ACTIVE_SUMMARY 0x10
160#define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x20
hasso9428f2d2004-09-13 14:01:12 +0000161#define OSPF6_ROUTE_WAS_REMOVED 0x40
paul718e3742002-12-13 20:15:29 +0000162
hasso508e53e2004-05-18 18:57:06 +0000163struct ospf6_route_table
164{
165 /* patricia tree */
166 struct route_table *table;
paul718e3742002-12-13 20:15:29 +0000167
hasso508e53e2004-05-18 18:57:06 +0000168 u_int32_t count;
paul718e3742002-12-13 20:15:29 +0000169
hasso508e53e2004-05-18 18:57:06 +0000170 /* hooks */
171 void (*hook_add) (struct ospf6_route *);
172 void (*hook_change) (struct ospf6_route *);
173 void (*hook_remove) (struct ospf6_route *);
174};
175
176extern char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX];
177extern char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX];
178#define OSPF6_DEST_TYPE_NAME(x) \
179 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
180 ospf6_dest_type_str[(x)] : ospf6_dest_type_str[0])
181#define OSPF6_DEST_TYPE_SUBSTR(x) \
182 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
183 ospf6_dest_type_substr[(x)] : ospf6_dest_type_substr[0])
184
185extern char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX];
186extern char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
187#define OSPF6_PATH_TYPE_NAME(x) \
188 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
189 ospf6_path_type_str[(x)] : ospf6_path_type_str[0])
190#define OSPF6_PATH_TYPE_SUBSTR(x) \
191 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
192 ospf6_path_type_substr[(x)] : ospf6_path_type_substr[0])
193
194#define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n"
195#define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
196#define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"
197
198#define ospf6_route_is_prefix(p, r) \
199 (memcmp (p, &(r)->prefix, sizeof (struct prefix)) == 0)
200#define ospf6_route_is_same(ra, rb) \
201 (prefix_same (&(ra)->prefix, &(rb)->prefix))
202#define ospf6_route_is_same_origin(ra, rb) \
203 ((ra)->path.area_id == (rb)->path.area_id && \
204 memcmp (&(ra)->path.origin, &(rb)->path.origin, \
205 sizeof (struct ospf6_ls_origin)) == 0)
206#define ospf6_route_is_identical(ra, rb) \
207 ((ra)->type == (rb)->type && \
208 memcmp (&(ra)->prefix, &(rb)->prefix, sizeof (struct prefix)) == 0 && \
209 memcmp (&(ra)->path, &(rb)->path, sizeof (struct ospf6_path)) == 0 && \
210 memcmp (&(ra)->nexthop, &(rb)->nexthop, \
211 sizeof (struct ospf6_nexthop) * OSPF6_MULTI_PATH_LIMIT) == 0)
212#define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
213
214#define ospf6_linkstate_prefix_adv_router(x) \
215 (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[0]))
216#define ospf6_linkstate_prefix_id(x) \
217 (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[4]))
218
hasso3b687352004-08-19 06:56:53 +0000219#define ADV_ROUTER_IN_PREFIX(x) \
hassoccb59b12004-08-25 09:10:37 +0000220 (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[0]))
221#define ID_IN_PREFIX(x) \
hasso3b687352004-08-19 06:56:53 +0000222 (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[4]))
223
hasso508e53e2004-05-18 18:57:06 +0000224/* Function prototype */
225void ospf6_linkstate_prefix (u_int32_t adv_router, u_int32_t id,
226 struct prefix *prefix);
227void ospf6_linkstate_prefix2str (struct prefix *prefix, char *buf, int size);
228
229struct ospf6_route *ospf6_route_create ();
230void ospf6_route_delete (struct ospf6_route *);
231struct ospf6_route *ospf6_route_copy (struct ospf6_route *route);
232
233void ospf6_route_lock (struct ospf6_route *route);
234void ospf6_route_unlock (struct ospf6_route *route);
235
236struct ospf6_route *
237ospf6_route_lookup (struct prefix *prefix,
238 struct ospf6_route_table *table);
239struct ospf6_route *
240ospf6_route_lookup_identical (struct ospf6_route *route,
241 struct ospf6_route_table *table);
242struct ospf6_route *
243ospf6_route_lookup_bestmatch (struct prefix *prefix,
244 struct ospf6_route_table *table);
245
246struct ospf6_route *
247ospf6_route_add (struct ospf6_route *route, struct ospf6_route_table *table);
248void
249ospf6_route_remove (struct ospf6_route *route, struct ospf6_route_table *table);
250
251struct ospf6_route *ospf6_route_head (struct ospf6_route_table *table);
252struct ospf6_route *ospf6_route_next (struct ospf6_route *route);
253struct ospf6_route *ospf6_route_best_next (struct ospf6_route *route);
254
255struct ospf6_route *ospf6_route_match_head (struct prefix *prefix,
256 struct ospf6_route_table *table);
257struct ospf6_route *ospf6_route_match_next (struct prefix *prefix,
258 struct ospf6_route *route);
259
paul718e3742002-12-13 20:15:29 +0000260void ospf6_route_remove_all (struct ospf6_route_table *);
paul718e3742002-12-13 20:15:29 +0000261struct ospf6_route_table *ospf6_route_table_create ();
262void ospf6_route_table_delete (struct ospf6_route_table *);
hasso508e53e2004-05-18 18:57:06 +0000263void ospf6_route_dump (struct ospf6_route_table *table);
paul718e3742002-12-13 20:15:29 +0000264
hasso6452df02004-08-15 05:52:07 +0000265
266void ospf6_route_show (struct vty *vty, struct ospf6_route *route);
267void ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route);
268
paul718e3742002-12-13 20:15:29 +0000269int ospf6_route_table_show (struct vty *, int, char **,
270 struct ospf6_route_table *);
hasso4846ef62004-09-03 06:04:00 +0000271int ospf6_linkstate_table_show (struct vty *vty, int argc, char **argv,
272 struct ospf6_route_table *table);
hasso508e53e2004-05-18 18:57:06 +0000273
hasso6452df02004-08-15 05:52:07 +0000274void ospf6_brouter_show_header (struct vty *vty);
275void ospf6_brouter_show (struct vty *vty, struct ospf6_route *route);
276
hasso508e53e2004-05-18 18:57:06 +0000277int config_write_ospf6_debug_route (struct vty *vty);
278void install_element_ospf6_debug_route ();
279void ospf6_route_init ();
paul718e3742002-12-13 20:15:29 +0000280
281#endif /* OSPF6_ROUTE_H */
282