]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_route.h
ospf6d: Add vty_socket cli option to override the compiled-in location for the VTY...
[mirror_frr.git] / ospf6d / ospf6_route.h
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
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
25 #define OSPF6_MULTI_PATH_LIMIT 4
26
27 /* Debug option */
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)
39
40 /* Nexthop */
41 struct ospf6_nexthop
42 {
43 /* Interface index */
44 ifindex_t ifindex;
45
46 /* IP address, if any */
47 struct in6_addr address;
48 };
49
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) \
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)
66
67 /* Path */
68 struct ospf6_ls_origin
69 {
70 u_int16_t type;
71 u_int32_t id;
72 u_int32_t adv_router;
73 };
74
75 struct ospf6_path
76 {
77 /* Link State Origin */
78 struct ospf6_ls_origin origin;
79
80 /* Router bits */
81 u_char router_bits;
82
83 /* Optional Capabilities */
84 u_char options[3];
85
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;
94 u_char subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
95
96 /* Cost */
97 u_int8_t metric_type;
98 u_int32_t cost;
99 union {
100 u_int32_t cost_e2;
101 u_int32_t cost_config;
102 } u;
103 u_int32_t tag;
104 };
105
106 #define OSPF6_PATH_TYPE_NONE 0
107 #define OSPF6_PATH_TYPE_INTRA 1
108 #define OSPF6_PATH_TYPE_INTER 2
109 #define OSPF6_PATH_TYPE_EXTERNAL1 3
110 #define OSPF6_PATH_TYPE_EXTERNAL2 4
111 #define OSPF6_PATH_TYPE_REDISTRIBUTE 5
112 #define OSPF6_PATH_TYPE_MAX 6
113
114 #define OSPF6_PATH_SUBTYPE_DEFAULT_RT 1
115
116 #define OSPF6_PATH_COST_IS_CONFIGURED(path) (path.u.cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
117
118 #include "prefix.h"
119 #include "table.h"
120 #include "bitfield.h"
121
122 struct ospf6_route
123 {
124 struct route_node *rnode;
125 struct ospf6_route_table *table;
126 struct ospf6_route *prev;
127 struct ospf6_route *next;
128
129 unsigned int lock;
130
131 /* Destination Type */
132 u_char type;
133
134 /* XXX: It would likely be better to use separate struct in_addr's
135 * for the advertising router-ID and prefix IDs, instead of stuffing them
136 * into one. See also XXX below.
137 */
138 /* Destination ID */
139 struct prefix prefix;
140
141 /* Time */
142 struct timeval installed;
143 struct timeval changed;
144
145 /* flag */
146 u_char flag;
147
148 /* route option */
149 void *route_option;
150
151 /* link state id for advertising */
152 u_int32_t linkstate_id;
153
154 /* path */
155 struct ospf6_path path;
156
157 /* nexthop */
158 struct list *nh_list;
159
160 };
161
162 #define OSPF6_DEST_TYPE_NONE 0
163 #define OSPF6_DEST_TYPE_ROUTER 1
164 #define OSPF6_DEST_TYPE_NETWORK 2
165 #define OSPF6_DEST_TYPE_DISCARD 3
166 #define OSPF6_DEST_TYPE_LINKSTATE 4
167 #define OSPF6_DEST_TYPE_RANGE 5
168 #define OSPF6_DEST_TYPE_MAX 6
169
170 #define OSPF6_ROUTE_CHANGE 0x01
171 #define OSPF6_ROUTE_ADD 0x02
172 #define OSPF6_ROUTE_REMOVE 0x04
173 #define OSPF6_ROUTE_BEST 0x08
174 #define OSPF6_ROUTE_ACTIVE_SUMMARY 0x10
175 #define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x20
176 #define OSPF6_ROUTE_WAS_REMOVED 0x40
177 #define OSPF6_ROUTE_BLACKHOLE_ADDED 0x80
178
179 struct ospf6_route_table
180 {
181 int scope_type;
182 int table_type;
183 void *scope;
184
185 /* patricia tree */
186 struct route_table *table;
187
188 u_int32_t count;
189
190 bitfield_t idspace;
191
192 /* hooks */
193 void (*hook_add) (struct ospf6_route *);
194 void (*hook_change) (struct ospf6_route *);
195 void (*hook_remove) (struct ospf6_route *);
196 };
197
198 #define OSPF6_SCOPE_TYPE_NONE 0
199 #define OSPF6_SCOPE_TYPE_GLOBAL 1
200 #define OSPF6_SCOPE_TYPE_AREA 2
201 #define OSPF6_SCOPE_TYPE_INTERFACE 3
202
203 #define OSPF6_TABLE_TYPE_NONE 0
204 #define OSPF6_TABLE_TYPE_ROUTES 1
205 #define OSPF6_TABLE_TYPE_BORDER_ROUTERS 2
206 #define OSPF6_TABLE_TYPE_CONNECTED_ROUTES 3
207 #define OSPF6_TABLE_TYPE_EXTERNAL_ROUTES 4
208 #define OSPF6_TABLE_TYPE_SPF_RESULTS 5
209 #define OSPF6_TABLE_TYPE_PREFIX_RANGES 6
210 #define OSPF6_TABLE_TYPE_SUMMARY_PREFIXES 7
211 #define OSPF6_TABLE_TYPE_SUMMARY_ROUTERS 8
212
213 #define OSPF6_ROUTE_TABLE_CREATE(s, t) \
214 ospf6_route_table_create (OSPF6_SCOPE_TYPE_ ## s, \
215 OSPF6_TABLE_TYPE_ ## t)
216
217 extern const char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX];
218 extern const char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX];
219 #define OSPF6_DEST_TYPE_NAME(x) \
220 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
221 ospf6_dest_type_str[(x)] : ospf6_dest_type_str[0])
222 #define OSPF6_DEST_TYPE_SUBSTR(x) \
223 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? \
224 ospf6_dest_type_substr[(x)] : ospf6_dest_type_substr[0])
225
226 extern const char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX];
227 extern const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
228 #define OSPF6_PATH_TYPE_NAME(x) \
229 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
230 ospf6_path_type_str[(x)] : ospf6_path_type_str[0])
231 #define OSPF6_PATH_TYPE_SUBSTR(x) \
232 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? \
233 ospf6_path_type_substr[(x)] : ospf6_path_type_substr[0])
234
235 #define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n"
236 #define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
237 #define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"
238
239 #define ospf6_route_is_prefix(p, r) \
240 (memcmp (p, &(r)->prefix, sizeof (struct prefix)) == 0)
241 #define ospf6_route_is_same(ra, rb) \
242 (prefix_same (&(ra)->prefix, &(rb)->prefix))
243 #define ospf6_route_is_same_origin(ra, rb) \
244 ((ra)->path.area_id == (rb)->path.area_id && \
245 memcmp (&(ra)->path.origin, &(rb)->path.origin, \
246 sizeof (struct ospf6_ls_origin)) == 0)
247 #define ospf6_route_is_identical(ra, rb) \
248 ((ra)->type == (rb)->type && \
249 memcmp (&(ra)->prefix, &(rb)->prefix, sizeof (struct prefix)) == 0 && \
250 memcmp (&(ra)->path, &(rb)->path, sizeof (struct ospf6_path)) == 0 && \
251 ospf6_route_cmp_nexthops (ra, rb) == 0)
252
253 #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
254
255 #define ospf6_linkstate_prefix_adv_router(x) \
256 ((x)->u.lp.id.s_addr)
257 #define ospf6_linkstate_prefix_id(x) \
258 ((x)->u.lp.adv_router.s_addr)
259
260 #define ADV_ROUTER_IN_PREFIX(x) \
261 ((x)->u.lp.id.s_addr)
262
263 /* Function prototype */
264 extern void ospf6_linkstate_prefix (u_int32_t adv_router, u_int32_t id,
265 struct prefix *prefix);
266 extern void ospf6_linkstate_prefix2str (struct prefix *prefix, char *buf,
267 int size);
268
269 extern struct ospf6_nexthop *ospf6_nexthop_create (void);
270 extern void ospf6_nexthop_delete (struct ospf6_nexthop *nh);
271 extern void ospf6_free_nexthops (struct list *nh_list);
272 extern void ospf6_clear_nexthops (struct list *nh_list);
273 extern int ospf6_num_nexthops (struct list *nh_list);
274 extern void ospf6_copy_nexthops (struct list *dst, struct list *src);
275 extern void ospf6_merge_nexthops (struct list *dst, struct list *src);
276 extern void ospf6_add_nexthop (struct list *nh_list, int ifindex,
277 struct in6_addr *addr);
278 extern int ospf6_num_nexthops (struct list *nh_list);
279 extern int ospf6_route_cmp_nexthops (struct ospf6_route *a,
280 struct ospf6_route *b);
281 extern void ospf6_route_zebra_copy_nexthops (struct ospf6_route *route,
282 ifindex_t *ifindices,
283 struct in6_addr **addr,
284 int entries);
285 extern int ospf6_route_get_first_nh_index (struct ospf6_route *route);
286
287 /* Hide abstraction of nexthop implementation in route from outsiders */
288 #define ospf6_route_copy_nexthops(dst, src) ospf6_copy_nexthops(dst->nh_list, src->nh_list)
289 #define ospf6_route_merge_nexthops(dst, src) ospf6_merge_nexthops(dst->nh_list, src->nh_list)
290 #define ospf6_route_num_nexthops(route) ospf6_num_nexthops(route->nh_list)
291 #define ospf6_route_add_nexthop(route, ifindex, addr) \
292 ospf6_add_nexthop(route->nh_list, ifindex, addr)
293
294 extern struct ospf6_route *ospf6_route_create (void);
295 extern void ospf6_route_delete (struct ospf6_route *);
296 extern struct ospf6_route *ospf6_route_copy (struct ospf6_route *route);
297 extern int ospf6_route_cmp (struct ospf6_route *ra, struct ospf6_route *rb);
298
299 extern void ospf6_route_lock (struct ospf6_route *route);
300 extern void ospf6_route_unlock (struct ospf6_route *route);
301
302 extern struct ospf6_route *ospf6_route_lookup (struct prefix *prefix,
303 struct ospf6_route_table *table);
304 extern struct ospf6_route *ospf6_route_lookup_identical (struct ospf6_route *route,
305 struct ospf6_route_table *table);
306 extern struct ospf6_route *ospf6_route_lookup_bestmatch (struct prefix *prefix,
307 struct ospf6_route_table *table);
308
309 extern struct ospf6_route *ospf6_route_add (struct ospf6_route *route,
310 struct ospf6_route_table *table);
311 extern void ospf6_route_remove (struct ospf6_route *route,
312 struct ospf6_route_table *table);
313
314 extern struct ospf6_route *ospf6_route_head (struct ospf6_route_table *table);
315 extern struct ospf6_route *ospf6_route_next (struct ospf6_route *route);
316 extern struct ospf6_route *ospf6_route_best_next (struct ospf6_route *route);
317
318 extern struct ospf6_route *ospf6_route_match_head (struct prefix *prefix,
319 struct ospf6_route_table *table);
320 extern struct ospf6_route *ospf6_route_match_next (struct prefix *prefix,
321 struct ospf6_route *route);
322
323 extern void ospf6_route_remove_all (struct ospf6_route_table *);
324 extern struct ospf6_route_table *ospf6_route_table_create (int s, int t);
325 extern void ospf6_route_table_delete (struct ospf6_route_table *);
326 extern void ospf6_route_dump (struct ospf6_route_table *table);
327
328
329 extern void ospf6_route_show (struct vty *vty, struct ospf6_route *route);
330 extern void ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route);
331
332 extern int ospf6_route_table_show (struct vty *, int, const char *[],
333 struct ospf6_route_table *);
334 extern int ospf6_linkstate_table_show (struct vty *vty, int argc,
335 const char *argv[],
336 struct ospf6_route_table *table);
337
338 extern void ospf6_brouter_show_header (struct vty *vty);
339 extern void ospf6_brouter_show (struct vty *vty, struct ospf6_route *route);
340
341 extern int config_write_ospf6_debug_route (struct vty *vty);
342 extern void install_element_ospf6_debug_route (void);
343 extern void ospf6_route_init (void);
344 extern void ospf6_clean (void);
345
346 #endif /* OSPF6_ROUTE_H */
347