]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_route.h
Merge pull request #8824 from volta-networks/fix_check_for_link_param_change
[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 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 19 */
20
21#ifndef OSPF6_ROUTE_H
22#define OSPF6_ROUTE_H
23
ddae3015 24#include "command.h"
5afa1c6b 25#include "zclient.h"
eacd0828 26#include "lib/json.h"
ddae3015 27
508e53e2 28#define OSPF6_MULTI_PATH_LIMIT 4
718e3744 29
508e53e2 30/* Debug option */
31extern unsigned char conf_debug_ospf6_route;
32#define OSPF6_DEBUG_ROUTE_TABLE 0x01
33#define OSPF6_DEBUG_ROUTE_INTRA 0x02
34#define OSPF6_DEBUG_ROUTE_INTER 0x04
cf1ce250 35#define OSPF6_DEBUG_ROUTE_MEMORY 0x80
d62a17ae 36#define OSPF6_DEBUG_ROUTE_ON(level) (conf_debug_ospf6_route |= (level))
37#define OSPF6_DEBUG_ROUTE_OFF(level) (conf_debug_ospf6_route &= ~(level))
38#define IS_OSPF6_DEBUG_ROUTE(e) (conf_debug_ospf6_route & OSPF6_DEBUG_ROUTE_##e)
718e3744 39
508e53e2 40/* Nexthop */
d62a17ae 41struct ospf6_nexthop {
42 /* Interface index */
43 ifindex_t ifindex;
718e3744 44
d62a17ae 45 /* IP address, if any */
46 struct in6_addr address;
718e3744 47};
48
d62a17ae 49#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, sizeof(struct in6_addr)); \
63 } while (0)
508e53e2 64
718e3744 65/* Path */
d62a17ae 66struct ospf6_ls_origin {
d7c0a89a 67 uint16_t type;
858f9c08
DL
68 in_addr_t id;
69 in_addr_t adv_router;
718e3744 70};
71
d62a17ae 72struct ospf6_path {
73 /* Link State Origin */
74 struct ospf6_ls_origin origin;
718e3744 75
d62a17ae 76 /* Router bits */
d7c0a89a 77 uint8_t router_bits;
718e3744 78
d62a17ae 79 /* Optional Capabilities */
d7c0a89a 80 uint8_t options[3];
718e3744 81
d62a17ae 82 /* Prefix Options */
d7c0a89a 83 uint8_t prefix_options;
718e3744 84
d62a17ae 85 /* Associated Area */
858f9c08 86 in_addr_t area_id;
718e3744 87
d62a17ae 88 /* Path-type */
d7c0a89a
QY
89 uint8_t type;
90 uint8_t subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
718e3744 91
d62a17ae 92 /* Cost */
d7c0a89a
QY
93 uint8_t metric_type;
94 uint32_t cost;
6942698d
CS
95
96 struct prefix ls_prefix;
97
d62a17ae 98 union {
d7c0a89a
QY
99 uint32_t cost_e2;
100 uint32_t cost_config;
d62a17ae 101 } u;
d7c0a89a 102 uint32_t tag;
064d4355
CS
103
104 /* nh list for this path */
105 struct list *nh_list;
718e3744 106};
107
6452df09 108#define OSPF6_PATH_TYPE_NONE 0
109#define OSPF6_PATH_TYPE_INTRA 1
110#define OSPF6_PATH_TYPE_INTER 2
111#define OSPF6_PATH_TYPE_EXTERNAL1 3
112#define OSPF6_PATH_TYPE_EXTERNAL2 4
113#define OSPF6_PATH_TYPE_REDISTRIBUTE 5
114#define OSPF6_PATH_TYPE_MAX 6
718e3744 115
ca1f4309
DS
116#define OSPF6_PATH_SUBTYPE_DEFAULT_RT 1
117
118#define OSPF6_PATH_COST_IS_CONFIGURED(path) (path.u.cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
119
508e53e2 120#include "prefix.h"
121#include "table.h"
c3c0ac83 122#include "bitfield.h"
718e3744 123
d62a17ae 124struct ospf6_route {
125 struct route_node *rnode;
126 struct ospf6_route_table *table;
127 struct ospf6_route *prev;
128 struct ospf6_route *next;
718e3744 129
d62a17ae 130 unsigned int lock;
718e3744 131
d62a17ae 132 /* Destination Type */
d7c0a89a 133 uint8_t type;
508e53e2 134
d62a17ae 135 /* XXX: It would likely be better to use separate struct in_addr's
136 * for the advertising router-ID and prefix IDs, instead of stuffing
137 * them
138 * into one. See also XXX below.
139 */
140 /* Destination ID */
141 struct prefix prefix;
508e53e2 142
d62a17ae 143 /* Time */
144 struct timeval installed;
145 struct timeval changed;
718e3744 146
d62a17ae 147 /* flag */
d7c0a89a 148 uint8_t flag;
718e3744 149
d62a17ae 150 /* route option */
151 void *route_option;
049207c3 152
d62a17ae 153 /* link state id for advertising */
d7c0a89a 154 uint32_t linkstate_id;
c3c0ac83 155
d62a17ae 156 /* path */
157 struct ospf6_path path;
c3c0ac83 158
064d4355
CS
159 /* List of Paths. */
160 struct list *paths;
161
d62a17ae 162 /* nexthop */
163 struct list *nh_list;
718e3744 164};
165
166#define OSPF6_DEST_TYPE_NONE 0
167#define OSPF6_DEST_TYPE_ROUTER 1
168#define OSPF6_DEST_TYPE_NETWORK 2
169#define OSPF6_DEST_TYPE_DISCARD 3
508e53e2 170#define OSPF6_DEST_TYPE_LINKSTATE 4
6452df09 171#define OSPF6_DEST_TYPE_RANGE 5
172#define OSPF6_DEST_TYPE_MAX 6
718e3744 173
6452df09 174#define OSPF6_ROUTE_CHANGE 0x01
175#define OSPF6_ROUTE_ADD 0x02
176#define OSPF6_ROUTE_REMOVE 0x04
177#define OSPF6_ROUTE_BEST 0x08
4846ef64 178#define OSPF6_ROUTE_ACTIVE_SUMMARY 0x10
179#define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x20
9428f2dc 180#define OSPF6_ROUTE_WAS_REMOVED 0x40
c3c0ac83 181#define OSPF6_ROUTE_BLACKHOLE_ADDED 0x80
beadc736 182struct ospf6;
718e3744 183
d62a17ae 184struct ospf6_route_table {
185 int scope_type;
186 int table_type;
187 void *scope;
cf1ce250 188
d62a17ae 189 /* patricia tree */
190 struct route_table *table;
718e3744 191
d7c0a89a 192 uint32_t count;
718e3744 193
d62a17ae 194 bitfield_t idspace;
c3c0ac83 195
d62a17ae 196 /* hooks */
e285b70d 197 void (*hook_add)(struct ospf6_route *);
d62a17ae 198 void (*hook_change)(struct ospf6_route *);
e285b70d 199 void (*hook_remove)(struct ospf6_route *);
508e53e2 200};
718e3744 201
cf1ce250
PJ
202#define OSPF6_SCOPE_TYPE_NONE 0
203#define OSPF6_SCOPE_TYPE_GLOBAL 1
204#define OSPF6_SCOPE_TYPE_AREA 2
205#define OSPF6_SCOPE_TYPE_INTERFACE 3
206
207#define OSPF6_TABLE_TYPE_NONE 0
208#define OSPF6_TABLE_TYPE_ROUTES 1
209#define OSPF6_TABLE_TYPE_BORDER_ROUTERS 2
210#define OSPF6_TABLE_TYPE_CONNECTED_ROUTES 3
211#define OSPF6_TABLE_TYPE_EXTERNAL_ROUTES 4
212#define OSPF6_TABLE_TYPE_SPF_RESULTS 5
213#define OSPF6_TABLE_TYPE_PREFIX_RANGES 6
214#define OSPF6_TABLE_TYPE_SUMMARY_PREFIXES 7
215#define OSPF6_TABLE_TYPE_SUMMARY_ROUTERS 8
216
d62a17ae 217#define OSPF6_ROUTE_TABLE_CREATE(s, t) \
218 ospf6_route_table_create(OSPF6_SCOPE_TYPE_##s, OSPF6_TABLE_TYPE_##t)
cf1ce250 219
2b64873d
DL
220extern const char *const ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX];
221extern const char *const ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX];
d62a17ae 222#define OSPF6_DEST_TYPE_NAME(x) \
223 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? ospf6_dest_type_str[(x)] \
224 : ospf6_dest_type_str[0])
225#define OSPF6_DEST_TYPE_SUBSTR(x) \
226 (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ? ospf6_dest_type_substr[(x)] \
227 : ospf6_dest_type_substr[0])
508e53e2 228
2b64873d
DL
229extern const char *const ospf6_path_type_str[OSPF6_PATH_TYPE_MAX];
230extern const char *const ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
d62a17ae 231#define OSPF6_PATH_TYPE_NAME(x) \
232 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? ospf6_path_type_str[(x)] \
233 : ospf6_path_type_str[0])
234#define OSPF6_PATH_TYPE_SUBSTR(x) \
235 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? ospf6_path_type_substr[(x)] \
236 : ospf6_path_type_substr[0])
eacd0828
YR
237#define OSPF6_PATH_TYPE_JSON(x) \
238 (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ? ospf6_path_type_json[(x)] \
239 : ospf6_path_type_json[0])
508e53e2 240
241#define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the address\n"
242#define OSPF6_ROUTE_PREFIX_STR "Display the route\n"
243#define OSPF6_ROUTE_MATCH_STR "Display the route matches the prefix\n"
244
d62a17ae 245#define ospf6_route_is_prefix(p, r) \
246 (memcmp(p, &(r)->prefix, sizeof(struct prefix)) == 0)
247#define ospf6_route_is_same(ra, rb) (prefix_same(&(ra)->prefix, &(rb)->prefix))
248#define ospf6_route_is_same_origin(ra, rb) \
249 ((ra)->path.area_id == (rb)->path.area_id \
250 && memcmp(&(ra)->path.origin, &(rb)->path.origin, \
251 sizeof(struct ospf6_ls_origin)) \
252 == 0)
253#define ospf6_route_is_identical(ra, rb) \
254 ((ra)->type == (rb)->type \
255 && memcmp(&(ra)->prefix, &(rb)->prefix, sizeof(struct prefix)) == 0 \
256 && memcmp(&(ra)->path, &(rb)->path, sizeof(struct ospf6_path)) == 0 \
03f3c1c1 257 && listcount(ra->paths) == listcount(rb->paths) \
d62a17ae 258 && ospf6_route_cmp_nexthops(ra, rb) == 0)
c3c0ac83 259
508e53e2 260#define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
261
d62a17ae 262#define ospf6_linkstate_prefix_adv_router(x) ((x)->u.lp.id.s_addr)
263#define ospf6_linkstate_prefix_id(x) ((x)->u.lp.adv_router.s_addr)
508e53e2 264
d62a17ae 265#define ADV_ROUTER_IN_PREFIX(x) ((x)->u.lp.id.s_addr)
3b68735f 266
508e53e2 267/* Function prototype */
d7c0a89a 268extern void ospf6_linkstate_prefix(uint32_t adv_router, uint32_t id,
d62a17ae 269 struct prefix *prefix);
270extern void ospf6_linkstate_prefix2str(struct prefix *prefix, char *buf,
271 int size);
272
273extern struct ospf6_nexthop *ospf6_nexthop_create(void);
064d4355 274extern int ospf6_nexthop_cmp(struct ospf6_nexthop *a, struct ospf6_nexthop *b);
d62a17ae 275extern void ospf6_nexthop_delete(struct ospf6_nexthop *nh);
d62a17ae 276extern void ospf6_clear_nexthops(struct list *nh_list);
277extern int ospf6_num_nexthops(struct list *nh_list);
278extern void ospf6_copy_nexthops(struct list *dst, struct list *src);
279extern void ospf6_merge_nexthops(struct list *dst, struct list *src);
280extern void ospf6_add_nexthop(struct list *nh_list, int ifindex,
281 struct in6_addr *addr);
282extern int ospf6_num_nexthops(struct list *nh_list);
283extern int ospf6_route_cmp_nexthops(struct ospf6_route *a,
284 struct ospf6_route *b);
285extern void ospf6_route_zebra_copy_nexthops(struct ospf6_route *route,
5afa1c6b 286 struct zapi_nexthop nexthops[],
1fa58587 287 int entries, vrf_id_t vrf_id);
d62a17ae 288extern int ospf6_route_get_first_nh_index(struct ospf6_route *route);
c3c0ac83
DS
289
290/* Hide abstraction of nexthop implementation in route from outsiders */
291#define ospf6_route_copy_nexthops(dst, src) ospf6_copy_nexthops(dst->nh_list, src->nh_list)
292#define ospf6_route_merge_nexthops(dst, src) ospf6_merge_nexthops(dst->nh_list, src->nh_list)
293#define ospf6_route_num_nexthops(route) ospf6_num_nexthops(route->nh_list)
d62a17ae 294#define ospf6_route_add_nexthop(route, ifindex, addr) \
295 ospf6_add_nexthop(route->nh_list, ifindex, addr)
296
297extern struct ospf6_route *ospf6_route_create(void);
298extern void ospf6_route_delete(struct ospf6_route *);
299extern struct ospf6_route *ospf6_route_copy(struct ospf6_route *route);
300extern int ospf6_route_cmp(struct ospf6_route *ra, struct ospf6_route *rb);
301
302extern void ospf6_route_lock(struct ospf6_route *route);
303extern void ospf6_route_unlock(struct ospf6_route *route);
d62a17ae 304extern struct ospf6_route *ospf6_route_lookup(struct prefix *prefix,
305 struct ospf6_route_table *table);
306extern struct ospf6_route *
307ospf6_route_lookup_identical(struct ospf6_route *route,
308 struct ospf6_route_table *table);
309extern struct ospf6_route *
310ospf6_route_lookup_bestmatch(struct prefix *prefix,
311 struct ospf6_route_table *table);
312
313extern struct ospf6_route *ospf6_route_add(struct ospf6_route *route,
e285b70d 314 struct ospf6_route_table *table);
d62a17ae 315extern void ospf6_route_remove(struct ospf6_route *route,
e285b70d 316 struct ospf6_route_table *table);
d62a17ae 317
318extern struct ospf6_route *ospf6_route_head(struct ospf6_route_table *table);
319extern struct ospf6_route *ospf6_route_next(struct ospf6_route *route);
320extern struct ospf6_route *ospf6_route_best_next(struct ospf6_route *route);
321
322extern struct ospf6_route *
323ospf6_route_match_head(struct prefix *prefix, struct ospf6_route_table *table);
324extern struct ospf6_route *ospf6_route_match_next(struct prefix *prefix,
325 struct ospf6_route *route);
326
e285b70d 327extern void ospf6_route_remove_all(struct ospf6_route_table *table);
d62a17ae 328extern struct ospf6_route_table *ospf6_route_table_create(int s, int t);
e285b70d 329extern void ospf6_route_table_delete(struct ospf6_route_table *table);
d62a17ae 330extern void ospf6_route_dump(struct ospf6_route_table *table);
331
332
eacd0828
YR
333extern void ospf6_route_show(struct vty *vty, struct ospf6_route *route,
334 json_object *json, bool use_json);
335extern void ospf6_route_show_detail(struct vty *vty, struct ospf6_route *route,
336 json_object *json, bool use_json);
337
d62a17ae 338
339extern int ospf6_route_table_show(struct vty *, int, int, struct cmd_token **,
eacd0828 340 struct ospf6_route_table *, bool use_json);
d62a17ae 341extern int ospf6_linkstate_table_show(struct vty *vty, int idx_ipv4, int argc,
342 struct cmd_token **argv,
343 struct ospf6_route_table *table);
344
345extern void ospf6_brouter_show_header(struct vty *vty);
346extern void ospf6_brouter_show(struct vty *vty, struct ospf6_route *route);
347
348extern int config_write_ospf6_debug_route(struct vty *vty);
349extern void install_element_ospf6_debug_route(void);
350extern void ospf6_route_init(void);
064d4355
CS
351extern void ospf6_path_free(struct ospf6_path *op);
352extern struct ospf6_path *ospf6_path_dup(struct ospf6_path *path);
03f3c1c1 353extern void ospf6_copy_paths(struct list *dst, struct list *src);
718e3744 354
355#endif /* OSPF6_ROUTE_H */