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