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