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
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.
25 #define OSPF6_MULTI_PATH_LIMIT 4
28 extern 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_MEMORY 0x80
33 #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)
46 /* IP address, if any */
47 struct in6_addr address
;
50 #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) \
58 memset (&(x)->address, 0, sizeof (struct in6_addr)); \
60 #define ospf6_nexthop_copy(a, b) \
62 (a)->ifindex = (b)->ifindex; \
63 memcpy (&(a)->address, &(b)->address, \
64 sizeof (struct in6_addr)); \
68 struct ospf6_ls_origin
77 /* Link State Origin */
78 struct ospf6_ls_origin origin
;
83 /* Optional Capabilities */
87 u_char prefix_options
;
94 u_char subtype
; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
102 #define OSPF6_PATH_TYPE_NONE 0
103 #define OSPF6_PATH_TYPE_INTRA 1
104 #define OSPF6_PATH_TYPE_INTER 2
105 #define OSPF6_PATH_TYPE_EXTERNAL1 3
106 #define OSPF6_PATH_TYPE_EXTERNAL2 4
107 #define OSPF6_PATH_TYPE_REDISTRIBUTE 5
108 #define OSPF6_PATH_TYPE_MAX 6
115 struct route_node
*rnode
;
116 struct ospf6_route_table
*table
;
117 struct ospf6_route
*prev
;
118 struct ospf6_route
*next
;
122 /* Destination Type */
126 struct prefix prefix
;
129 struct timeval installed
;
130 struct timeval changed
;
136 struct ospf6_path path
;
139 struct ospf6_nexthop nexthop
[OSPF6_MULTI_PATH_LIMIT
];
144 /* link state id for advertising */
145 u_int32_t linkstate_id
;
148 #define OSPF6_DEST_TYPE_NONE 0
149 #define OSPF6_DEST_TYPE_ROUTER 1
150 #define OSPF6_DEST_TYPE_NETWORK 2
151 #define OSPF6_DEST_TYPE_DISCARD 3
152 #define OSPF6_DEST_TYPE_LINKSTATE 4
153 #define OSPF6_DEST_TYPE_RANGE 5
154 #define OSPF6_DEST_TYPE_MAX 6
156 #define OSPF6_ROUTE_CHANGE 0x01
157 #define OSPF6_ROUTE_ADD 0x02
158 #define OSPF6_ROUTE_REMOVE 0x04
159 #define OSPF6_ROUTE_BEST 0x08
160 #define OSPF6_ROUTE_ACTIVE_SUMMARY 0x10
161 #define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x20
162 #define OSPF6_ROUTE_WAS_REMOVED 0x40
164 struct ospf6_route_table
171 struct route_table
*table
;
176 void (*hook_add
) (struct ospf6_route
*);
177 void (*hook_change
) (struct ospf6_route
*);
178 void (*hook_remove
) (struct ospf6_route
*);
181 #define OSPF6_SCOPE_TYPE_NONE 0
182 #define OSPF6_SCOPE_TYPE_GLOBAL 1
183 #define OSPF6_SCOPE_TYPE_AREA 2
184 #define OSPF6_SCOPE_TYPE_INTERFACE 3
186 #define OSPF6_TABLE_TYPE_NONE 0
187 #define OSPF6_TABLE_TYPE_ROUTES 1
188 #define OSPF6_TABLE_TYPE_BORDER_ROUTERS 2
189 #define OSPF6_TABLE_TYPE_CONNECTED_ROUTES 3
190 #define OSPF6_TABLE_TYPE_EXTERNAL_ROUTES 4
191 #define OSPF6_TABLE_TYPE_SPF_RESULTS 5
192 #define OSPF6_TABLE_TYPE_PREFIX_RANGES 6
193 #define OSPF6_TABLE_TYPE_SUMMARY_PREFIXES 7
194 #define OSPF6_TABLE_TYPE_SUMMARY_ROUTERS 8
196 #define OSPF6_ROUTE_TABLE_CREATE(s, t) \
197 ospf6_route_table_create (OSPF6_SCOPE_TYPE_ ## s, \
198 OSPF6_TABLE_TYPE_ ## t)
200 extern const char *ospf6_dest_type_str
[OSPF6_DEST_TYPE_MAX
];
201 extern const char *ospf6_dest_type_substr
[OSPF6_DEST_TYPE_MAX
];
202 #define OSPF6_DEST_TYPE_NAME(x) \
203 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
204 ospf6_dest_type_str[(x)] : ospf6_dest_type_str[0])
205 #define OSPF6_DEST_TYPE_SUBSTR(x) \
206 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
207 ospf6_dest_type_substr[(x)] : ospf6_dest_type_substr[0])
209 extern const char *ospf6_path_type_str
[OSPF6_PATH_TYPE_MAX
];
210 extern const char *ospf6_path_type_substr
[OSPF6_PATH_TYPE_MAX
];
211 #define OSPF6_PATH_TYPE_NAME(x) \
212 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
213 ospf6_path_type_str[(x)] : ospf6_path_type_str[0])
214 #define OSPF6_PATH_TYPE_SUBSTR(x) \
215 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
216 ospf6_path_type_substr[(x)] : ospf6_path_type_substr[0])
218 #define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n"
219 #define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
220 #define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"
222 #define ospf6_route_is_prefix(p, r) \
223 (memcmp (p, &(r)->prefix, sizeof (struct prefix)) == 0)
224 #define ospf6_route_is_same(ra, rb) \
225 (prefix_same (&(ra)->prefix, &(rb)->prefix))
226 #define ospf6_route_is_same_origin(ra, rb) \
227 ((ra)->path.area_id == (rb)->path.area_id && \
228 memcmp (&(ra)->path.origin, &(rb)->path.origin, \
229 sizeof (struct ospf6_ls_origin)) == 0)
230 #define ospf6_route_is_identical(ra, rb) \
231 ((ra)->type == (rb)->type && \
232 memcmp (&(ra)->prefix, &(rb)->prefix, sizeof (struct prefix)) == 0 && \
233 memcmp (&(ra)->path, &(rb)->path, sizeof (struct ospf6_path)) == 0 && \
234 memcmp (&(ra)->nexthop, &(rb)->nexthop, \
235 sizeof (struct ospf6_nexthop) * OSPF6_MULTI_PATH_LIMIT) == 0)
236 #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
238 #define ospf6_linkstate_prefix_adv_router(x) \
239 (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[0]))
240 #define ospf6_linkstate_prefix_id(x) \
241 (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[4]))
243 #define ADV_ROUTER_IN_PREFIX(x) \
244 (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[0]))
245 #define ID_IN_PREFIX(x) \
246 (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[4]))
248 /* Function prototype */
249 void ospf6_linkstate_prefix (u_int32_t adv_router
, u_int32_t id
,
250 struct prefix
*prefix
);
251 void ospf6_linkstate_prefix2str (struct prefix
*prefix
, char *buf
, int size
);
253 struct ospf6_route
*ospf6_route_create ();
254 void ospf6_route_delete (struct ospf6_route
*);
255 struct ospf6_route
*ospf6_route_copy (struct ospf6_route
*route
);
257 void ospf6_route_lock (struct ospf6_route
*route
);
258 void ospf6_route_unlock (struct ospf6_route
*route
);
261 ospf6_route_lookup (struct prefix
*prefix
,
262 struct ospf6_route_table
*table
);
264 ospf6_route_lookup_identical (struct ospf6_route
*route
,
265 struct ospf6_route_table
*table
);
267 ospf6_route_lookup_bestmatch (struct prefix
*prefix
,
268 struct ospf6_route_table
*table
);
271 ospf6_route_add (struct ospf6_route
*route
, struct ospf6_route_table
*table
);
273 ospf6_route_remove (struct ospf6_route
*route
, struct ospf6_route_table
*table
);
275 struct ospf6_route
*ospf6_route_head (struct ospf6_route_table
*table
);
276 struct ospf6_route
*ospf6_route_next (struct ospf6_route
*route
);
277 struct ospf6_route
*ospf6_route_best_next (struct ospf6_route
*route
);
279 struct ospf6_route
*ospf6_route_match_head (struct prefix
*prefix
,
280 struct ospf6_route_table
*table
);
281 struct ospf6_route
*ospf6_route_match_next (struct prefix
*prefix
,
282 struct ospf6_route
*route
);
284 void ospf6_route_remove_all (struct ospf6_route_table
*);
285 struct ospf6_route_table
*ospf6_route_table_create (int s
, int t
);
286 void ospf6_route_table_delete (struct ospf6_route_table
*);
287 void ospf6_route_dump (struct ospf6_route_table
*table
);
290 void ospf6_route_show (struct vty
*vty
, struct ospf6_route
*route
);
291 void ospf6_route_show_detail (struct vty
*vty
, struct ospf6_route
*route
);
293 int ospf6_route_table_show (struct vty
*, int, const char *[],
294 struct ospf6_route_table
*);
295 int ospf6_linkstate_table_show (struct vty
*vty
, int argc
, const char *argv
[],
296 struct ospf6_route_table
*table
);
298 void ospf6_brouter_show_header (struct vty
*vty
);
299 void ospf6_brouter_show (struct vty
*vty
, struct ospf6_route
*route
);
301 int config_write_ospf6_debug_route (struct vty
*vty
);
302 void install_element_ospf6_debug_route ();
303 void ospf6_route_init ();
305 #endif /* OSPF6_ROUTE_H */