]>
Commit | Line | Data |
---|---|---|
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 | #include <zebra.h> | |
22 | ||
23 | #include "log.h" | |
24 | #include "memory.h" | |
25 | #include "vty.h" | |
26 | #include "linklist.h" | |
27 | #include "prefix.h" | |
28 | #include "table.h" | |
29 | #include "thread.h" | |
30 | #include "command.h" | |
8efe88ea | 31 | #include "defaults.h" |
35a45dea | 32 | #include "lib/json.h" |
7df1f362 | 33 | #include "lib_errors.h" |
718e3744 | 34 | |
718e3744 | 35 | #include "ospf6_proto.h" |
508e53e2 | 36 | #include "ospf6_message.h" |
718e3744 | 37 | #include "ospf6_lsa.h" |
38 | #include "ospf6_lsdb.h" | |
718e3744 | 39 | #include "ospf6_route.h" |
40 | #include "ospf6_zebra.h" | |
41 | ||
508e53e2 | 42 | #include "ospf6_top.h" |
43 | #include "ospf6_area.h" | |
44 | #include "ospf6_interface.h" | |
45 | #include "ospf6_neighbor.h" | |
7df1f362 | 46 | #include "ospf6_network.h" |
718e3744 | 47 | |
6452df09 | 48 | #include "ospf6_flood.h" |
508e53e2 | 49 | #include "ospf6_asbr.h" |
049207c3 | 50 | #include "ospf6_abr.h" |
6452df09 | 51 | #include "ospf6_intra.h" |
3810e06e | 52 | #include "ospf6_spf.h" |
049207c3 | 53 | #include "ospf6d.h" |
eacd0828 | 54 | #include "lib/json.h" |
ad500b22 | 55 | #include "ospf6_nssa.h" |
718e3744 | 56 | |
30043e4c DL |
57 | DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_TOP, "OSPF6 top"); |
58 | ||
96244aca | 59 | DEFINE_QOBJ_TYPE(ospf6); |
ae19c240 | 60 | |
c572fbfe | 61 | FRR_CFG_DEFAULT_BOOL(OSPF6_LOG_ADJACENCY_CHANGES, |
4c1458b5 DL |
62 | { .val_bool = true, .match_profile = "datacenter", }, |
63 | { .val_bool = false }, | |
67b0f40c | 64 | ); |
c572fbfe | 65 | |
718e3744 | 66 | /* global ospf6d variable */ |
78c6ba61 CS |
67 | static struct ospf6_master ospf6_master; |
68 | struct ospf6_master *om6; | |
718e3744 | 69 | |
d62a17ae | 70 | static void ospf6_disable(struct ospf6 *o); |
ae2254aa | 71 | |
beadc736 | 72 | static void ospf6_add(struct ospf6 *ospf6) |
73 | { | |
74 | listnode_add(om6->ospf6, ospf6); | |
75 | } | |
76 | ||
77 | static void ospf6_del(struct ospf6 *ospf6) | |
78 | { | |
79 | listnode_delete(om6->ospf6, ospf6); | |
80 | } | |
81 | ||
82 | const char *ospf6_vrf_id_to_name(vrf_id_t vrf_id) | |
83 | { | |
84 | struct vrf *vrf = vrf_lookup_by_id(vrf_id); | |
85 | ||
86 | return vrf ? vrf->name : "NIL"; | |
87 | } | |
88 | ||
89 | /* Link OSPF instance to VRF. */ | |
90 | void ospf6_vrf_link(struct ospf6 *ospf6, struct vrf *vrf) | |
91 | { | |
92 | ospf6->vrf_id = vrf->vrf_id; | |
93 | if (vrf->info != (void *)ospf6) | |
94 | vrf->info = (void *)ospf6; | |
95 | } | |
96 | ||
97 | /* Unlink OSPF instance from VRF. */ | |
98 | void ospf6_vrf_unlink(struct ospf6 *ospf6, struct vrf *vrf) | |
99 | { | |
100 | if (vrf->info == (void *)ospf6) | |
101 | vrf->info = NULL; | |
102 | ospf6->vrf_id = VRF_UNKNOWN; | |
103 | } | |
104 | ||
105 | struct ospf6 *ospf6_lookup_by_vrf_id(vrf_id_t vrf_id) | |
106 | { | |
107 | struct vrf *vrf = NULL; | |
108 | ||
109 | vrf = vrf_lookup_by_id(vrf_id); | |
110 | if (!vrf) | |
111 | return NULL; | |
112 | return (vrf->info) ? (struct ospf6 *)vrf->info : NULL; | |
113 | } | |
114 | ||
115 | struct ospf6 *ospf6_lookup_by_vrf_name(const char *name) | |
116 | { | |
117 | struct ospf6 *o = NULL; | |
118 | struct listnode *node, *nnode; | |
119 | ||
120 | for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, o)) { | |
121 | if (((o->name == NULL && name == NULL) | |
122 | || (o->name && name && strcmp(o->name, name) == 0))) | |
123 | return o; | |
124 | } | |
125 | return NULL; | |
126 | } | |
127 | ||
4e8ccd92 | 128 | /* This is hook function for vrf create called as part of vrf_init */ |
129 | static int ospf6_vrf_new(struct vrf *vrf) | |
130 | { | |
131 | return 0; | |
132 | } | |
133 | ||
134 | /* This is hook function for vrf delete call as part of vrf_init */ | |
135 | static int ospf6_vrf_delete(struct vrf *vrf) | |
136 | { | |
137 | return 0; | |
138 | } | |
139 | ||
140 | static void ospf6_set_redist_vrf_bitmaps(struct ospf6 *ospf6, bool set) | |
141 | { | |
142 | int type; | |
143 | struct list *red_list; | |
144 | ||
145 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
146 | red_list = ospf6->redist[type]; | |
147 | if (!red_list) | |
148 | continue; | |
149 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) | |
150 | zlog_debug( | |
151 | "%s: setting redist vrf %d bitmap for type %d", | |
152 | __func__, ospf6->vrf_id, type); | |
153 | if (set) | |
154 | vrf_bitmap_set(zclient->redist[AFI_IP6][type], | |
155 | ospf6->vrf_id); | |
156 | else | |
157 | vrf_bitmap_unset(zclient->redist[AFI_IP6][type], | |
158 | ospf6->vrf_id); | |
159 | } | |
82bc4b8a IR |
160 | |
161 | red_list = ospf6->redist[DEFAULT_ROUTE]; | |
162 | if (red_list) { | |
163 | if (set) | |
164 | vrf_bitmap_set(zclient->default_information[AFI_IP6], | |
165 | ospf6->vrf_id); | |
166 | else | |
167 | vrf_bitmap_unset(zclient->default_information[AFI_IP6], | |
168 | ospf6->vrf_id); | |
169 | } | |
4e8ccd92 | 170 | } |
171 | ||
172 | /* Disable OSPF6 VRF instance */ | |
173 | static int ospf6_vrf_disable(struct vrf *vrf) | |
174 | { | |
175 | struct ospf6 *ospf6 = NULL; | |
176 | ||
177 | if (vrf->vrf_id == VRF_DEFAULT) | |
178 | return 0; | |
179 | ||
180 | ospf6 = ospf6_lookup_by_vrf_name(vrf->name); | |
181 | if (ospf6) { | |
182 | ospf6_zebra_vrf_deregister(ospf6); | |
183 | ||
184 | ospf6_set_redist_vrf_bitmaps(ospf6, false); | |
185 | ||
186 | /* We have instance configured, unlink | |
187 | * from VRF and make it "down". | |
188 | */ | |
189 | ospf6_vrf_unlink(ospf6, vrf); | |
190 | thread_cancel(&ospf6->t_ospf6_receive); | |
191 | close(ospf6->fd); | |
192 | ospf6->fd = -1; | |
193 | } | |
194 | ||
195 | /* Note: This is a callback, the VRF will be deleted by the caller. */ | |
196 | return 0; | |
197 | } | |
198 | ||
199 | /* Enable OSPF6 VRF instance */ | |
200 | static int ospf6_vrf_enable(struct vrf *vrf) | |
201 | { | |
202 | struct ospf6 *ospf6 = NULL; | |
203 | vrf_id_t old_vrf_id; | |
204 | int ret = 0; | |
205 | ||
206 | ospf6 = ospf6_lookup_by_vrf_name(vrf->name); | |
207 | if (ospf6) { | |
208 | old_vrf_id = ospf6->vrf_id; | |
209 | /* We have instance configured, link to VRF and make it "up". */ | |
210 | ospf6_vrf_link(ospf6, vrf); | |
211 | ||
212 | if (old_vrf_id != ospf6->vrf_id) { | |
213 | ospf6_set_redist_vrf_bitmaps(ospf6, true); | |
214 | ||
215 | /* start zebra redist to us for new vrf */ | |
216 | ospf6_zebra_vrf_register(ospf6); | |
217 | ||
218 | ret = ospf6_serv_sock(ospf6); | |
219 | if (ret < 0 || ospf6->fd <= 0) | |
220 | return 0; | |
221 | thread_add_read(master, ospf6_receive, ospf6, ospf6->fd, | |
222 | &ospf6->t_ospf6_receive); | |
223 | ||
224 | ospf6_router_id_update(ospf6); | |
225 | } | |
226 | } | |
227 | ||
228 | return 0; | |
229 | } | |
230 | ||
231 | void ospf6_vrf_init(void) | |
232 | { | |
233 | vrf_init(ospf6_vrf_new, ospf6_vrf_enable, ospf6_vrf_disable, | |
234 | ospf6_vrf_delete, ospf6_vrf_enable); | |
235 | } | |
beadc736 | 236 | |
d62a17ae | 237 | static void ospf6_top_lsdb_hook_add(struct ospf6_lsa *lsa) |
718e3744 | 238 | { |
d62a17ae | 239 | switch (ntohs(lsa->header->type)) { |
240 | case OSPF6_LSTYPE_AS_EXTERNAL: | |
f5f26b8f | 241 | ospf6_asbr_lsa_add(lsa); |
d62a17ae | 242 | break; |
243 | ||
244 | default: | |
245 | break; | |
246 | } | |
718e3744 | 247 | } |
248 | ||
d62a17ae | 249 | static void ospf6_top_lsdb_hook_remove(struct ospf6_lsa *lsa) |
718e3744 | 250 | { |
d62a17ae | 251 | switch (ntohs(lsa->header->type)) { |
252 | case OSPF6_LSTYPE_AS_EXTERNAL: | |
07b37f93 | 253 | ospf6_asbr_lsa_remove(lsa, NULL); |
d62a17ae | 254 | break; |
255 | ||
256 | default: | |
257 | break; | |
258 | } | |
718e3744 | 259 | } |
260 | ||
e285b70d | 261 | static void ospf6_top_route_hook_add(struct ospf6_route *route) |
049207c3 | 262 | { |
ad500b22 K |
263 | struct ospf6 *ospf6 = NULL; |
264 | struct ospf6_area *oa = NULL; | |
265 | ||
266 | if (route->table->scope_type == OSPF6_SCOPE_TYPE_GLOBAL) | |
267 | ospf6 = route->table->scope; | |
268 | else if (route->table->scope_type == OSPF6_SCOPE_TYPE_AREA) { | |
269 | oa = (struct ospf6_area *)route->table->scope; | |
270 | ospf6 = oa->ospf6; | |
271 | } | |
e285b70d | 272 | |
beadc736 | 273 | ospf6_abr_originate_summary(route, ospf6); |
274 | ospf6_zebra_route_update_add(route, ospf6); | |
049207c3 | 275 | } |
276 | ||
e285b70d | 277 | static void ospf6_top_route_hook_remove(struct ospf6_route *route) |
049207c3 | 278 | { |
ad500b22 K |
279 | struct ospf6 *ospf6 = NULL; |
280 | struct ospf6_area *oa = NULL; | |
281 | ||
282 | if (route->table->scope_type == OSPF6_SCOPE_TYPE_GLOBAL) | |
283 | ospf6 = route->table->scope; | |
284 | else if (route->table->scope_type == OSPF6_SCOPE_TYPE_AREA) { | |
285 | oa = (struct ospf6_area *)route->table->scope; | |
286 | ospf6 = oa->ospf6; | |
287 | } | |
e285b70d | 288 | |
d62a17ae | 289 | route->flag |= OSPF6_ROUTE_REMOVE; |
beadc736 | 290 | ospf6_abr_originate_summary(route, ospf6); |
291 | ospf6_zebra_route_update_remove(route, ospf6); | |
049207c3 | 292 | } |
293 | ||
e285b70d | 294 | static void ospf6_top_brouter_hook_add(struct ospf6_route *route) |
6452df09 | 295 | { |
e285b70d IR |
296 | struct ospf6 *ospf6 = route->table->scope; |
297 | ||
99ab28cb CS |
298 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL) || |
299 | IS_OSPF6_DEBUG_BROUTER) { | |
07b37f93 CS |
300 | uint32_t brouter_id; |
301 | char brouter_name[16]; | |
302 | ||
303 | brouter_id = ADV_ROUTER_IN_PREFIX(&route->prefix); | |
304 | inet_ntop(AF_INET, &brouter_id, brouter_name, | |
305 | sizeof(brouter_name)); | |
306 | zlog_debug("%s: brouter %s add with adv router %x nh count %u", | |
15569c58 | 307 | __func__, brouter_name, |
07b37f93 CS |
308 | route->path.origin.adv_router, |
309 | listcount(route->nh_list)); | |
064d4355 | 310 | } |
beadc736 | 311 | ospf6_abr_examin_brouter(ADV_ROUTER_IN_PREFIX(&route->prefix), route, |
312 | ospf6); | |
313 | ospf6_asbr_lsentry_add(route, ospf6); | |
314 | ospf6_abr_originate_summary(route, ospf6); | |
6452df09 | 315 | } |
316 | ||
e285b70d | 317 | static void ospf6_top_brouter_hook_remove(struct ospf6_route *route) |
6452df09 | 318 | { |
e285b70d IR |
319 | struct ospf6 *ospf6 = route->table->scope; |
320 | ||
99ab28cb CS |
321 | if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL) || |
322 | IS_OSPF6_DEBUG_BROUTER) { | |
07b37f93 CS |
323 | uint32_t brouter_id; |
324 | char brouter_name[16]; | |
064d4355 | 325 | |
07b37f93 CS |
326 | brouter_id = ADV_ROUTER_IN_PREFIX(&route->prefix); |
327 | inet_ntop(AF_INET, &brouter_id, brouter_name, | |
328 | sizeof(brouter_name)); | |
99ab28cb | 329 | zlog_debug("%s: brouter %p %s del with adv router %x nh %u", |
15569c58 | 330 | __func__, (void *)route, brouter_name, |
99ab28cb | 331 | route->path.origin.adv_router, |
07b37f93 | 332 | listcount(route->nh_list)); |
064d4355 | 333 | } |
d62a17ae | 334 | route->flag |= OSPF6_ROUTE_REMOVE; |
beadc736 | 335 | ospf6_abr_examin_brouter(ADV_ROUTER_IN_PREFIX(&route->prefix), route, |
336 | ospf6); | |
337 | ospf6_asbr_lsentry_remove(route, ospf6); | |
338 | ospf6_abr_originate_summary(route, ospf6); | |
6452df09 | 339 | } |
340 | ||
7df1f362 | 341 | static struct ospf6 *ospf6_create(const char *name) |
718e3744 | 342 | { |
d62a17ae | 343 | struct ospf6 *o; |
7df1f362 | 344 | struct vrf *vrf = NULL; |
718e3744 | 345 | |
d62a17ae | 346 | o = XCALLOC(MTYPE_OSPF6_TOP, sizeof(struct ospf6)); |
718e3744 | 347 | |
7df1f362 K |
348 | vrf = vrf_lookup_by_name(name); |
349 | if (vrf) { | |
350 | o->vrf_id = vrf->vrf_id; | |
beadc736 | 351 | } else |
352 | o->vrf_id = VRF_UNKNOWN; | |
353 | ||
354 | /* Freed in ospf6_delete */ | |
355 | o->name = XSTRDUP(MTYPE_OSPF6_TOP, name); | |
356 | if (vrf) | |
357 | ospf6_vrf_link(o, vrf); | |
358 | ||
359 | ospf6_zebra_vrf_register(o); | |
360 | ||
d62a17ae | 361 | /* initialize */ |
362 | monotime(&o->starttime); | |
363 | o->area_list = list_new(); | |
364 | o->area_list->cmp = ospf6_area_cmp; | |
365 | o->lsdb = ospf6_lsdb_create(o); | |
366 | o->lsdb_self = ospf6_lsdb_create(o); | |
367 | o->lsdb->hook_add = ospf6_top_lsdb_hook_add; | |
368 | o->lsdb->hook_remove = ospf6_top_lsdb_hook_remove; | |
718e3744 | 369 | |
d62a17ae | 370 | o->spf_delay = OSPF_SPF_DELAY_DEFAULT; |
371 | o->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT; | |
372 | o->spf_max_holdtime = OSPF_SPF_MAX_HOLDTIME_DEFAULT; | |
373 | o->spf_hold_multiplier = 1; | |
3810e06e | 374 | |
b19502d3 | 375 | o->default_originate = DEFAULT_ORIGINATE_NONE; |
b8212e03 | 376 | o->redistribute = 0; |
d62a17ae | 377 | /* LSA timers value init */ |
378 | o->lsa_minarrival = OSPF_MIN_LS_ARRIVAL; | |
b6927875 | 379 | |
d62a17ae | 380 | o->route_table = OSPF6_ROUTE_TABLE_CREATE(GLOBAL, ROUTES); |
381 | o->route_table->scope = o; | |
382 | o->route_table->hook_add = ospf6_top_route_hook_add; | |
383 | o->route_table->hook_remove = ospf6_top_route_hook_remove; | |
718e3744 | 384 | |
d62a17ae | 385 | o->brouter_table = OSPF6_ROUTE_TABLE_CREATE(GLOBAL, BORDER_ROUTERS); |
386 | o->brouter_table->scope = o; | |
387 | o->brouter_table->hook_add = ospf6_top_brouter_hook_add; | |
388 | o->brouter_table->hook_remove = ospf6_top_brouter_hook_remove; | |
049207c3 | 389 | |
d62a17ae | 390 | o->external_table = OSPF6_ROUTE_TABLE_CREATE(GLOBAL, EXTERNAL_ROUTES); |
391 | o->external_table->scope = o; | |
cf1ce250 | 392 | |
d62a17ae | 393 | o->external_id_table = route_table_init(); |
718e3744 | 394 | |
d62a17ae | 395 | o->ref_bandwidth = OSPF6_REFERENCE_BANDWIDTH; |
fd500689 | 396 | |
d62a17ae | 397 | o->distance_table = route_table_init(); |
7df1f362 | 398 | o->fd = -1; |
baff583e | 399 | |
1958143e MR |
400 | o->max_multipath = MULTIPATH_NUM; |
401 | ||
d62a17ae | 402 | QOBJ_REG(o, ospf6); |
692c7954 | 403 | |
7df1f362 K |
404 | /* Make ospf protocol socket. */ |
405 | ospf6_serv_sock(o); | |
406 | ||
d62a17ae | 407 | return o; |
718e3744 | 408 | } |
409 | ||
beadc736 | 410 | struct ospf6 *ospf6_instance_create(const char *name) |
7df1f362 | 411 | { |
beadc736 | 412 | struct ospf6 *ospf6; |
413 | ||
7df1f362 K |
414 | ospf6 = ospf6_create(name); |
415 | if (DFLT_OSPF6_LOG_ADJACENCY_CHANGES) | |
416 | SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES); | |
417 | if (ospf6->router_id == 0) | |
beadc736 | 418 | ospf6_router_id_update(ospf6); |
419 | ospf6_add(ospf6); | |
4e8ccd92 | 420 | if (ospf6->fd < 0) |
421 | return ospf6; | |
422 | ||
7df1f362 K |
423 | thread_add_read(master, ospf6_receive, ospf6, ospf6->fd, |
424 | &ospf6->t_ospf6_receive); | |
beadc736 | 425 | |
426 | return ospf6; | |
7df1f362 K |
427 | } |
428 | ||
d62a17ae | 429 | void ospf6_delete(struct ospf6 *o) |
718e3744 | 430 | { |
d62a17ae | 431 | struct listnode *node, *nnode; |
432 | struct ospf6_area *oa; | |
92699b9b | 433 | struct vrf *vrf; |
718e3744 | 434 | |
d62a17ae | 435 | QOBJ_UNREG(o); |
76249532 | 436 | |
beadc736 | 437 | ospf6_flush_self_originated_lsas_now(o); |
438 | ospf6_disable(o); | |
439 | ospf6_del(o); | |
ae2254aa | 440 | |
4e8ccd92 | 441 | ospf6_zebra_vrf_deregister(o); |
442 | ||
d3136990 IR |
443 | ospf6_serv_close(&o->fd); |
444 | ||
d62a17ae | 445 | for (ALL_LIST_ELEMENTS(o->area_list, node, nnode, oa)) |
446 | ospf6_area_delete(oa); | |
d9628728 CF |
447 | |
448 | ||
6a154c88 | 449 | list_delete(&o->area_list); |
718e3744 | 450 | |
d62a17ae | 451 | ospf6_lsdb_delete(o->lsdb); |
452 | ospf6_lsdb_delete(o->lsdb_self); | |
718e3744 | 453 | |
e285b70d IR |
454 | ospf6_route_table_delete(o->route_table); |
455 | ospf6_route_table_delete(o->brouter_table); | |
718e3744 | 456 | |
e285b70d | 457 | ospf6_route_table_delete(o->external_table); |
d62a17ae | 458 | route_table_finish(o->external_id_table); |
718e3744 | 459 | |
d62a17ae | 460 | ospf6_distance_reset(o); |
461 | route_table_finish(o->distance_table); | |
baff583e | 462 | |
92699b9b IR |
463 | if (o->vrf_id != VRF_UNKNOWN) { |
464 | vrf = vrf_lookup_by_id(o->vrf_id); | |
465 | if (vrf) | |
466 | ospf6_vrf_unlink(o, vrf); | |
467 | } | |
468 | ||
7df1f362 | 469 | XFREE(MTYPE_OSPF6_TOP, o->name); |
d62a17ae | 470 | XFREE(MTYPE_OSPF6_TOP, o); |
508e53e2 | 471 | } |
718e3744 | 472 | |
d62a17ae | 473 | static void ospf6_disable(struct ospf6 *o) |
718e3744 | 474 | { |
d62a17ae | 475 | struct listnode *node, *nnode; |
476 | struct ospf6_area *oa; | |
477 | ||
478 | if (!CHECK_FLAG(o->flag, OSPF6_DISABLED)) { | |
479 | SET_FLAG(o->flag, OSPF6_DISABLED); | |
480 | ||
481 | for (ALL_LIST_ELEMENTS(o->area_list, node, nnode, oa)) | |
482 | ospf6_area_disable(oa); | |
483 | ||
484 | /* XXX: This also changes persistent settings */ | |
a069482f K |
485 | /* Unregister redistribution */ |
486 | ospf6_asbr_redistribute_reset(o); | |
d62a17ae | 487 | |
488 | ospf6_lsdb_remove_all(o->lsdb); | |
e285b70d IR |
489 | ospf6_route_remove_all(o->route_table); |
490 | ospf6_route_remove_all(o->brouter_table); | |
d62a17ae | 491 | |
492 | THREAD_OFF(o->maxage_remover); | |
493 | THREAD_OFF(o->t_spf_calc); | |
494 | THREAD_OFF(o->t_ase_calc); | |
856ae1eb | 495 | THREAD_OFF(o->t_distribute_update); |
7df1f362 | 496 | THREAD_OFF(o->t_ospf6_receive); |
d62a17ae | 497 | } |
508e53e2 | 498 | } |
718e3744 | 499 | |
beadc736 | 500 | void ospf6_master_init(struct thread_master *master) |
78c6ba61 CS |
501 | { |
502 | memset(&ospf6_master, 0, sizeof(struct ospf6_master)); | |
503 | ||
504 | om6 = &ospf6_master; | |
beadc736 | 505 | om6->ospf6 = list_new(); |
506 | om6->master = master; | |
78c6ba61 CS |
507 | } |
508 | ||
d62a17ae | 509 | static int ospf6_maxage_remover(struct thread *thread) |
508e53e2 | 510 | { |
d62a17ae | 511 | struct ospf6 *o = (struct ospf6 *)THREAD_ARG(thread); |
512 | struct ospf6_area *oa; | |
513 | struct ospf6_interface *oi; | |
514 | struct ospf6_neighbor *on; | |
515 | struct listnode *i, *j, *k; | |
516 | int reschedule = 0; | |
517 | ||
518 | o->maxage_remover = (struct thread *)NULL; | |
519 | ||
520 | for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) { | |
521 | for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) { | |
522 | for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, k, on)) { | |
523 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE | |
524 | && on->state != OSPF6_NEIGHBOR_LOADING) | |
525 | continue; | |
526 | ||
527 | ospf6_maxage_remove(o); | |
528 | return 0; | |
529 | } | |
530 | } | |
2449fcd6 | 531 | } |
d62a17ae | 532 | |
533 | for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) { | |
534 | for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) { | |
535 | if (ospf6_lsdb_maxage_remover(oi->lsdb)) { | |
536 | reschedule = 1; | |
537 | } | |
538 | } | |
539 | ||
540 | if (ospf6_lsdb_maxage_remover(oa->lsdb)) { | |
541 | reschedule = 1; | |
542 | } | |
2449fcd6 | 543 | } |
2449fcd6 | 544 | |
d62a17ae | 545 | if (ospf6_lsdb_maxage_remover(o->lsdb)) { |
546 | reschedule = 1; | |
547 | } | |
2449fcd6 | 548 | |
d62a17ae | 549 | if (reschedule) { |
550 | ospf6_maxage_remove(o); | |
551 | } | |
508e53e2 | 552 | |
d62a17ae | 553 | return 0; |
718e3744 | 554 | } |
555 | ||
d62a17ae | 556 | void ospf6_maxage_remove(struct ospf6 *o) |
718e3744 | 557 | { |
d62a17ae | 558 | if (o) |
559 | thread_add_timer(master, ospf6_maxage_remover, o, | |
560 | OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT, | |
561 | &o->maxage_remover); | |
718e3744 | 562 | } |
563 | ||
beadc736 | 564 | void ospf6_router_id_update(struct ospf6 *ospf6) |
78c6ba61 CS |
565 | { |
566 | if (!ospf6) | |
567 | return; | |
568 | ||
569 | if (ospf6->router_id_static != 0) | |
570 | ospf6->router_id = ospf6->router_id_static; | |
571 | else | |
572 | ospf6->router_id = om6->zebra_router_id; | |
573 | } | |
574 | ||
508e53e2 | 575 | /* start ospf6 */ |
d48ef099 | 576 | DEFUN_NOSH(router_ospf6, router_ospf6_cmd, "router ospf6 [vrf NAME]", |
577 | ROUTER_STR OSPF6_STR VRF_CMD_HELP_STR) | |
718e3744 | 578 | { |
beadc736 | 579 | struct ospf6 *ospf6; |
d48ef099 | 580 | const char *vrf_name = VRF_DEFAULT_NAME; |
581 | int idx_vrf = 0; | |
beadc736 | 582 | |
d48ef099 | 583 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
584 | vrf_name = argv[idx_vrf + 1]->arg; | |
585 | } | |
586 | ||
587 | ospf6 = ospf6_lookup_by_vrf_name(vrf_name); | |
7df1f362 | 588 | if (ospf6 == NULL) |
d48ef099 | 589 | ospf6 = ospf6_instance_create(vrf_name); |
7df1f362 | 590 | |
d62a17ae | 591 | /* set current ospf point. */ |
592 | VTY_PUSH_CONTEXT(OSPF6_NODE, ospf6); | |
508e53e2 | 593 | |
d62a17ae | 594 | return CMD_SUCCESS; |
718e3744 | 595 | } |
596 | ||
508e53e2 | 597 | /* stop ospf6 */ |
d48ef099 | 598 | DEFUN(no_router_ospf6, no_router_ospf6_cmd, "no router ospf6 [vrf NAME]", |
599 | NO_STR ROUTER_STR OSPF6_STR VRF_CMD_HELP_STR) | |
718e3744 | 600 | { |
beadc736 | 601 | struct ospf6 *ospf6; |
d48ef099 | 602 | const char *vrf_name = VRF_DEFAULT_NAME; |
603 | int idx_vrf = 0; | |
beadc736 | 604 | |
d48ef099 | 605 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
606 | vrf_name = argv[idx_vrf + 1]->arg; | |
607 | } | |
608 | ||
609 | ospf6 = ospf6_lookup_by_vrf_name(vrf_name); | |
d62a17ae | 610 | if (ospf6 == NULL) |
611 | vty_out(vty, "OSPFv3 is not configured\n"); | |
612 | else { | |
613 | ospf6_delete(ospf6); | |
614 | ospf6 = NULL; | |
615 | } | |
34288970 | 616 | |
d62a17ae | 617 | /* return to config node . */ |
618 | VTY_PUSH_CONTEXT_NULL(CONFIG_NODE); | |
508e53e2 | 619 | |
d62a17ae | 620 | return CMD_SUCCESS; |
718e3744 | 621 | } |
622 | ||
508e53e2 | 623 | /* change Router_ID commands. */ |
60466a63 QY |
624 | DEFUN(ospf6_router_id, |
625 | ospf6_router_id_cmd, | |
626 | "ospf6 router-id A.B.C.D", | |
627 | OSPF6_STR | |
628 | "Configure OSPF6 Router-ID\n" | |
629 | V4NOTATION_STR) | |
718e3744 | 630 | { |
d62a17ae | 631 | VTY_DECLVAR_CONTEXT(ospf6, o); |
5d1a2ee8 | 632 | int idx = 0; |
d62a17ae | 633 | int ret; |
5d1a2ee8 | 634 | const char *router_id_str; |
d7c0a89a | 635 | uint32_t router_id; |
d6927cf3 CS |
636 | struct ospf6_area *oa; |
637 | struct listnode *node; | |
d62a17ae | 638 | |
5d1a2ee8 QY |
639 | argv_find(argv, argc, "A.B.C.D", &idx); |
640 | router_id_str = argv[idx]->arg; | |
641 | ||
642 | ret = inet_pton(AF_INET, router_id_str, &router_id); | |
d62a17ae | 643 | if (ret == 0) { |
60466a63 | 644 | vty_out(vty, "malformed OSPF Router-ID: %s\n", router_id_str); |
d62a17ae | 645 | return CMD_SUCCESS; |
646 | } | |
508e53e2 | 647 | |
d62a17ae | 648 | o->router_id_static = router_id; |
d6927cf3 CS |
649 | |
650 | for (ALL_LIST_ELEMENTS_RO(o->area_list, node, oa)) { | |
651 | if (oa->full_nbrs) { | |
652 | vty_out(vty, | |
3efd0893 | 653 | "For this router-id change to take effect, save config and restart ospf6d\n"); |
d6927cf3 CS |
654 | return CMD_SUCCESS; |
655 | } | |
656 | } | |
657 | ||
658 | o->router_id = router_id; | |
c8a440ec | 659 | |
d62a17ae | 660 | return CMD_SUCCESS; |
718e3744 | 661 | } |
662 | ||
60466a63 QY |
663 | DEFUN(no_ospf6_router_id, |
664 | no_ospf6_router_id_cmd, | |
665 | "no ospf6 router-id [A.B.C.D]", | |
666 | NO_STR OSPF6_STR | |
667 | "Configure OSPF6 Router-ID\n" | |
668 | V4NOTATION_STR) | |
5d1a2ee8 QY |
669 | { |
670 | VTY_DECLVAR_CONTEXT(ospf6, o); | |
d6927cf3 CS |
671 | struct ospf6_area *oa; |
672 | struct listnode *node; | |
673 | ||
5d1a2ee8 | 674 | o->router_id_static = 0; |
d6927cf3 CS |
675 | |
676 | for (ALL_LIST_ELEMENTS_RO(o->area_list, node, oa)) { | |
677 | if (oa->full_nbrs) { | |
678 | vty_out(vty, | |
3efd0893 | 679 | "For this router-id change to take effect, save config and restart ospf6d\n"); |
d6927cf3 CS |
680 | return CMD_SUCCESS; |
681 | } | |
682 | } | |
5d1a2ee8 | 683 | o->router_id = 0; |
d6927cf3 CS |
684 | if (o->router_id_zebra.s_addr) |
685 | o->router_id = (uint32_t)o->router_id_zebra.s_addr; | |
5d1a2ee8 QY |
686 | |
687 | return CMD_SUCCESS; | |
688 | } | |
689 | ||
3d35ca48 DD |
690 | DEFUN (ospf6_log_adjacency_changes, |
691 | ospf6_log_adjacency_changes_cmd, | |
692 | "log-adjacency-changes", | |
693 | "Log changes in adjacency state\n") | |
694 | { | |
d62a17ae | 695 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
3d35ca48 | 696 | |
d62a17ae | 697 | SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES); |
698 | UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL); | |
699 | return CMD_SUCCESS; | |
3d35ca48 DD |
700 | } |
701 | ||
702 | DEFUN (ospf6_log_adjacency_changes_detail, | |
703 | ospf6_log_adjacency_changes_detail_cmd, | |
704 | "log-adjacency-changes detail", | |
692c7954 | 705 | "Log changes in adjacency state\n" |
3d35ca48 DD |
706 | "Log all state changes\n") |
707 | { | |
d62a17ae | 708 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
3d35ca48 | 709 | |
d62a17ae | 710 | SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES); |
711 | SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL); | |
712 | return CMD_SUCCESS; | |
3d35ca48 DD |
713 | } |
714 | ||
715 | DEFUN (no_ospf6_log_adjacency_changes, | |
716 | no_ospf6_log_adjacency_changes_cmd, | |
717 | "no log-adjacency-changes", | |
692c7954 | 718 | NO_STR |
3d35ca48 DD |
719 | "Log changes in adjacency state\n") |
720 | { | |
d62a17ae | 721 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
3d35ca48 | 722 | |
d62a17ae | 723 | UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL); |
724 | UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES); | |
725 | return CMD_SUCCESS; | |
3d35ca48 DD |
726 | } |
727 | ||
728 | DEFUN (no_ospf6_log_adjacency_changes_detail, | |
729 | no_ospf6_log_adjacency_changes_detail_cmd, | |
730 | "no log-adjacency-changes detail", | |
692c7954 DW |
731 | NO_STR |
732 | "Log changes in adjacency state\n" | |
3d35ca48 DD |
733 | "Log all state changes\n") |
734 | { | |
d62a17ae | 735 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
3d35ca48 | 736 | |
d62a17ae | 737 | UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL); |
738 | return CMD_SUCCESS; | |
3d35ca48 DD |
739 | } |
740 | ||
b6927875 DS |
741 | DEFUN (ospf6_timers_lsa, |
742 | ospf6_timers_lsa_cmd, | |
6147e2c6 | 743 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
744 | "Adjust routing timers\n" |
745 | "OSPF6 LSA timers\n" | |
746 | "Minimum delay in receiving new version of a LSA\n" | |
747 | "Delay in milliseconds\n") | |
748 | { | |
d62a17ae | 749 | VTY_DECLVAR_CONTEXT(ospf6, ospf); |
750 | int idx_number = 3; | |
751 | unsigned int minarrival; | |
b6927875 | 752 | |
d62a17ae | 753 | minarrival = strtoul(argv[idx_number]->arg, NULL, 10); |
754 | ospf->lsa_minarrival = minarrival; | |
b6927875 | 755 | |
d62a17ae | 756 | return CMD_SUCCESS; |
b6927875 DS |
757 | } |
758 | ||
759 | DEFUN (no_ospf6_timers_lsa, | |
760 | no_ospf6_timers_lsa_cmd, | |
1d68dbfe | 761 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
762 | NO_STR |
763 | "Adjust routing timers\n" | |
764 | "OSPF6 LSA timers\n" | |
3a2d747c QY |
765 | "Minimum delay in receiving new version of a LSA\n" |
766 | "Delay in milliseconds\n") | |
b6927875 | 767 | { |
d62a17ae | 768 | VTY_DECLVAR_CONTEXT(ospf6, ospf); |
769 | int idx_number = 4; | |
770 | unsigned int minarrival; | |
b6927875 | 771 | |
d62a17ae | 772 | if (argc == 5) { |
773 | minarrival = strtoul(argv[idx_number]->arg, NULL, 10); | |
b6927875 | 774 | |
d62a17ae | 775 | if (ospf->lsa_minarrival != minarrival |
776 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
777 | return CMD_SUCCESS; | |
778 | } | |
b6927875 | 779 | |
d62a17ae | 780 | ospf->lsa_minarrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 781 | |
d62a17ae | 782 | return CMD_SUCCESS; |
b6927875 DS |
783 | } |
784 | ||
b6927875 | 785 | |
baff583e MZ |
786 | DEFUN (ospf6_distance, |
787 | ospf6_distance_cmd, | |
39e92c06 | 788 | "distance (1-255)", |
baff583e MZ |
789 | "Administrative distance\n" |
790 | "OSPF6 Administrative distance\n") | |
791 | { | |
d62a17ae | 792 | VTY_DECLVAR_CONTEXT(ospf6, o); |
baff583e | 793 | |
d62a17ae | 794 | o->distance_all = atoi(argv[1]->arg); |
baff583e | 795 | |
d62a17ae | 796 | return CMD_SUCCESS; |
baff583e MZ |
797 | } |
798 | ||
799 | DEFUN (no_ospf6_distance, | |
800 | no_ospf6_distance_cmd, | |
39e92c06 | 801 | "no distance (1-255)", |
baff583e MZ |
802 | NO_STR |
803 | "Administrative distance\n" | |
804 | "OSPF6 Administrative distance\n") | |
805 | { | |
d62a17ae | 806 | VTY_DECLVAR_CONTEXT(ospf6, o); |
baff583e | 807 | |
d62a17ae | 808 | o->distance_all = 0; |
baff583e | 809 | |
d62a17ae | 810 | return CMD_SUCCESS; |
baff583e MZ |
811 | } |
812 | ||
813 | DEFUN (ospf6_distance_ospf6, | |
814 | ospf6_distance_ospf6_cmd, | |
eaa1ae0d | 815 | "distance ospf6 {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
baff583e | 816 | "Administrative distance\n" |
eaa1ae0d | 817 | "OSPF6 administrative distance\n" |
39e92c06 QY |
818 | "Intra-area routes\n" |
819 | "Distance for intra-area routes\n" | |
820 | "Inter-area routes\n" | |
821 | "Distance for inter-area routes\n" | |
822 | "External routes\n" | |
baff583e MZ |
823 | "Distance for external routes\n") |
824 | { | |
d62a17ae | 825 | VTY_DECLVAR_CONTEXT(ospf6, o); |
826 | int idx = 0; | |
827 | ||
f89a449b CS |
828 | o->distance_intra = 0; |
829 | o->distance_inter = 0; | |
830 | o->distance_external = 0; | |
831 | ||
d62a17ae | 832 | if (argv_find(argv, argc, "intra-area", &idx)) |
833 | o->distance_intra = atoi(argv[idx + 1]->arg); | |
834 | idx = 0; | |
835 | if (argv_find(argv, argc, "inter-area", &idx)) | |
836 | o->distance_inter = atoi(argv[idx + 1]->arg); | |
837 | idx = 0; | |
838 | if (argv_find(argv, argc, "external", &idx)) | |
839 | o->distance_external = atoi(argv[idx + 1]->arg); | |
39e92c06 | 840 | |
d62a17ae | 841 | return CMD_SUCCESS; |
baff583e MZ |
842 | } |
843 | ||
844 | DEFUN (no_ospf6_distance_ospf6, | |
845 | no_ospf6_distance_ospf6_cmd, | |
eaa1ae0d | 846 | "no distance ospf6 [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
baff583e MZ |
847 | NO_STR |
848 | "Administrative distance\n" | |
849 | "OSPF6 distance\n" | |
850 | "Intra-area routes\n" | |
851 | "Distance for intra-area routes\n" | |
852 | "Inter-area routes\n" | |
853 | "Distance for inter-area routes\n" | |
854 | "External routes\n" | |
855 | "Distance for external routes\n") | |
856 | { | |
d62a17ae | 857 | VTY_DECLVAR_CONTEXT(ospf6, o); |
858 | int idx = 0; | |
baff583e | 859 | |
d62a17ae | 860 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
861 | idx = o->distance_intra = 0; | |
862 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
863 | idx = o->distance_inter = 0; | |
864 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
865 | o->distance_external = 0; | |
baff583e | 866 | |
d62a17ae | 867 | return CMD_SUCCESS; |
baff583e MZ |
868 | } |
869 | ||
508e53e2 | 870 | DEFUN (ospf6_interface_area, |
871 | ospf6_interface_area_cmd, | |
de842255 | 872 | "interface IFNAME area <A.B.C.D|(0-4294967295)>", |
508e53e2 | 873 | "Enable routing on an IPv6 interface\n" |
874 | IFNAME_STR | |
875 | "Specify the OSPF6 area ID\n" | |
876 | "OSPF6 area ID in IPv4 address notation\n" | |
de842255 | 877 | "OSPF6 area ID in decimal notation\n" |
508e53e2 | 878 | ) |
718e3744 | 879 | { |
d48ef099 | 880 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
d62a17ae | 881 | int idx_ifname = 1; |
882 | int idx_ipv4 = 3; | |
883 | struct ospf6_area *oa; | |
884 | struct ospf6_interface *oi; | |
885 | struct interface *ifp; | |
d48ef099 | 886 | vrf_id_t vrf_id = VRF_DEFAULT; |
f85b7619 | 887 | int ipv6_count = 0; |
d62a17ae | 888 | |
d48ef099 | 889 | if (ospf6->vrf_id != VRF_UNKNOWN) |
890 | vrf_id = ospf6->vrf_id; | |
beadc736 | 891 | |
d62a17ae | 892 | /* find/create ospf6 interface */ |
d48ef099 | 893 | ifp = if_get_by_name(argv[idx_ifname]->arg, vrf_id); |
d62a17ae | 894 | oi = (struct ospf6_interface *)ifp->info; |
895 | if (oi == NULL) | |
896 | oi = ospf6_interface_create(ifp); | |
897 | if (oi->area) { | |
898 | vty_out(vty, "%s already attached to Area %s\n", | |
899 | oi->interface->name, oi->area->name); | |
900 | return CMD_SUCCESS; | |
901 | } | |
6452df09 | 902 | |
f85b7619 | 903 | /* if more than OSPF6_MAX_IF_ADDRS are configured on this interface |
904 | * then don't allow ospfv3 to be configured | |
905 | */ | |
906 | ipv6_count = connected_count_by_family(ifp, AF_INET6); | |
907 | if (oi->ifmtu == OSPF6_DEFAULT_MTU && ipv6_count > OSPF6_MAX_IF_ADDRS) { | |
908 | vty_out(vty, | |
909 | "can not configure OSPFv3 on if %s, must have less than %d interface addresses but has %d addresses\n", | |
910 | ifp->name, OSPF6_MAX_IF_ADDRS, ipv6_count); | |
911 | return CMD_WARNING_CONFIG_FAILED; | |
912 | } else if (oi->ifmtu >= OSPF6_JUMBO_MTU | |
913 | && ipv6_count > OSPF6_MAX_IF_ADDRS_JUMBO) { | |
914 | vty_out(vty, | |
915 | "can not configure OSPFv3 on if %s, must have less than %d interface addresses but has %d addresses\n", | |
916 | ifp->name, OSPF6_MAX_IF_ADDRS_JUMBO, ipv6_count); | |
917 | return CMD_WARNING_CONFIG_FAILED; | |
918 | } | |
919 | ||
d62a17ae | 920 | /* parse Area-ID */ |
beadc736 | 921 | OSPF6_CMD_AREA_GET(argv[idx_ipv4]->arg, oa, ospf6); |
d62a17ae | 922 | |
923 | /* attach interface to area */ | |
924 | listnode_add(oa->if_list, oi); /* sort ?? */ | |
925 | oi->area = oa; | |
926 | ||
927 | SET_FLAG(oa->flag, OSPF6_AREA_ENABLE); | |
928 | ||
929 | /* ospf6 process is currently disabled, not much more to do */ | |
beadc736 | 930 | if (CHECK_FLAG(ospf6->flag, OSPF6_DISABLED)) |
d62a17ae | 931 | return CMD_SUCCESS; |
932 | ||
933 | /* start up */ | |
934 | ospf6_interface_enable(oi); | |
935 | ||
936 | /* If the router is ABR, originate summary routes */ | |
ad500b22 | 937 | if (ospf6_is_router_abr(ospf6)) { |
d62a17ae | 938 | ospf6_abr_enable_area(oa); |
ad500b22 K |
939 | ospf6_schedule_abr_task(oa->ospf6); |
940 | } | |
d62a17ae | 941 | |
942 | return CMD_SUCCESS; | |
718e3744 | 943 | } |
944 | ||
508e53e2 | 945 | DEFUN (no_ospf6_interface_area, |
946 | no_ospf6_interface_area_cmd, | |
de842255 | 947 | "no interface IFNAME area <A.B.C.D|(0-4294967295)>", |
508e53e2 | 948 | NO_STR |
949 | "Disable routing on an IPv6 interface\n" | |
950 | IFNAME_STR | |
951 | "Specify the OSPF6 area ID\n" | |
952 | "OSPF6 area ID in IPv4 address notation\n" | |
de842255 | 953 | "OSPF6 area ID in decimal notation\n" |
508e53e2 | 954 | ) |
718e3744 | 955 | { |
d48ef099 | 956 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
d62a17ae | 957 | int idx_ifname = 2; |
958 | int idx_ipv4 = 4; | |
959 | struct ospf6_interface *oi; | |
960 | struct ospf6_area *oa; | |
961 | struct interface *ifp; | |
d7c0a89a | 962 | uint32_t area_id; |
d48ef099 | 963 | vrf_id_t vrf_id = VRF_DEFAULT; |
964 | ||
965 | if (ospf6->vrf_id != VRF_UNKNOWN) | |
966 | vrf_id = ospf6->vrf_id; | |
967 | ||
968 | /* find/create ospf6 interface */ | |
969 | ifp = if_get_by_name(argv[idx_ifname]->arg, vrf_id); | |
d62a17ae | 970 | |
d62a17ae | 971 | if (ifp == NULL) { |
972 | vty_out(vty, "No such interface %s\n", argv[idx_ifname]->arg); | |
973 | return CMD_SUCCESS; | |
974 | } | |
6452df09 | 975 | |
d62a17ae | 976 | oi = (struct ospf6_interface *)ifp->info; |
977 | if (oi == NULL) { | |
978 | vty_out(vty, "Interface %s not enabled\n", ifp->name); | |
979 | return CMD_SUCCESS; | |
980 | } | |
981 | ||
982 | /* parse Area-ID */ | |
de842255 PR |
983 | if (inet_pton(AF_INET, argv[idx_ipv4]->arg, &area_id) != 1) |
984 | area_id = htonl(strtoul(argv[idx_ipv4]->arg, NULL, 10)); | |
d62a17ae | 985 | |
986 | /* Verify Area */ | |
987 | if (oi->area == NULL) { | |
800cc918 | 988 | vty_out(vty, "%s not attached to area %s\n", |
f85a4112 | 989 | oi->interface->name, argv[idx_ipv4]->arg); |
d62a17ae | 990 | return CMD_SUCCESS; |
991 | } | |
992 | ||
993 | if (oi->area->area_id != area_id) { | |
994 | vty_out(vty, "Wrong Area-ID: %s is attached to area %s\n", | |
995 | oi->interface->name, oi->area->name); | |
996 | return CMD_SUCCESS; | |
997 | } | |
998 | ||
4a30f056 | 999 | ospf6_interface_disable(oi); |
d62a17ae | 1000 | |
1001 | oa = oi->area; | |
1002 | listnode_delete(oi->area->if_list, oi); | |
1003 | oi->area = (struct ospf6_area *)NULL; | |
1004 | ||
1005 | /* Withdraw inter-area routes from this area, if necessary */ | |
1006 | if (oa->if_list->count == 0) { | |
1007 | UNSET_FLAG(oa->flag, OSPF6_AREA_ENABLE); | |
1008 | ospf6_abr_disable_area(oa); | |
1009 | } | |
1010 | ||
1011 | return CMD_SUCCESS; | |
718e3744 | 1012 | } |
1013 | ||
f41b4a02 DD |
1014 | DEFUN (ospf6_stub_router_admin, |
1015 | ospf6_stub_router_admin_cmd, | |
1016 | "stub-router administrative", | |
1017 | "Make router a stub router\n" | |
f41b4a02 DD |
1018 | "Administratively applied, for an indefinite period\n") |
1019 | { | |
d62a17ae | 1020 | struct listnode *node; |
1021 | struct ospf6_area *oa; | |
1022 | ||
beadc736 | 1023 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
1024 | ||
d62a17ae | 1025 | if (!CHECK_FLAG(ospf6->flag, OSPF6_STUB_ROUTER)) { |
1026 | for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) { | |
1027 | OSPF6_OPT_CLEAR(oa->options, OSPF6_OPT_V6); | |
1028 | OSPF6_OPT_CLEAR(oa->options, OSPF6_OPT_R); | |
1029 | OSPF6_ROUTER_LSA_SCHEDULE(oa); | |
1030 | } | |
1031 | SET_FLAG(ospf6->flag, OSPF6_STUB_ROUTER); | |
f41b4a02 | 1032 | } |
f41b4a02 | 1033 | |
d62a17ae | 1034 | return CMD_SUCCESS; |
f41b4a02 DD |
1035 | } |
1036 | ||
1037 | DEFUN (no_ospf6_stub_router_admin, | |
1038 | no_ospf6_stub_router_admin_cmd, | |
1039 | "no stub-router administrative", | |
1040 | NO_STR | |
1041 | "Make router a stub router\n" | |
f41b4a02 DD |
1042 | "Administratively applied, for an indefinite period\n") |
1043 | { | |
d62a17ae | 1044 | struct listnode *node; |
1045 | struct ospf6_area *oa; | |
1046 | ||
beadc736 | 1047 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); |
d62a17ae | 1048 | if (CHECK_FLAG(ospf6->flag, OSPF6_STUB_ROUTER)) { |
1049 | for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) { | |
1050 | OSPF6_OPT_SET(oa->options, OSPF6_OPT_V6); | |
1051 | OSPF6_OPT_SET(oa->options, OSPF6_OPT_R); | |
1052 | OSPF6_ROUTER_LSA_SCHEDULE(oa); | |
1053 | } | |
1054 | UNSET_FLAG(ospf6->flag, OSPF6_STUB_ROUTER); | |
f41b4a02 | 1055 | } |
f41b4a02 | 1056 | |
d62a17ae | 1057 | return CMD_SUCCESS; |
f41b4a02 DD |
1058 | } |
1059 | ||
1958143e MR |
1060 | /* Restart OSPF SPF algorithm*/ |
1061 | static void ospf6_restart_spf(struct ospf6 *ospf6) | |
1062 | { | |
1063 | ospf6_route_remove_all(ospf6->route_table); | |
1064 | ospf6_route_remove_all(ospf6->brouter_table); | |
1958143e MR |
1065 | |
1066 | /* Trigger SPF */ | |
1067 | ospf6_spf_schedule(ospf6, OSPF6_SPF_FLAGS_CONFIG_CHANGE); | |
1068 | } | |
1069 | ||
1070 | /* Set the max paths */ | |
1071 | static void ospf6_maxpath_set(struct ospf6 *ospf6, uint16_t paths) | |
1072 | { | |
1073 | if (ospf6->max_multipath == paths) | |
1074 | return; | |
1075 | ||
1076 | ospf6->max_multipath = paths; | |
1077 | ||
1078 | /* Send deletion to zebra to delete all | |
1079 | * ospf specific routes and reinitiate | |
1080 | * SPF to reflect the new max multipath. | |
1081 | */ | |
1082 | ospf6_restart_spf(ospf6); | |
1083 | } | |
1084 | ||
1085 | /* Ospf Maximum-paths config support */ | |
1086 | DEFUN(ospf6_max_multipath, | |
1087 | ospf6_max_multipath_cmd, | |
1088 | "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM), | |
1089 | "Max no of multiple paths for ECMP support\n" | |
1090 | "Number of paths\n") | |
1091 | { | |
1092 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); | |
1093 | int idx_number = 1; | |
1094 | int maximum_paths = strtol(argv[idx_number]->arg, NULL, 10); | |
1095 | ||
1096 | ospf6_maxpath_set(ospf6, maximum_paths); | |
1097 | ||
1098 | return CMD_SUCCESS; | |
1099 | } | |
1100 | ||
1101 | DEFUN(no_ospf6_max_multipath, | |
1102 | no_ospf6_max_multipath_cmd, | |
1103 | "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM)"]", | |
1104 | NO_STR | |
1105 | "Max no of multiple paths for ECMP support\n" | |
1106 | "Number of paths\n") | |
1107 | { | |
1108 | VTY_DECLVAR_CONTEXT(ospf6, ospf6); | |
1109 | ||
1110 | ospf6_maxpath_set(ospf6, MULTIPATH_NUM); | |
1111 | ||
1112 | return CMD_SUCCESS; | |
1113 | } | |
1114 | ||
35a45dea | 1115 | static void ospf6_show(struct vty *vty, struct ospf6 *o, json_object *json, |
1116 | bool use_json) | |
718e3744 | 1117 | { |
d62a17ae | 1118 | struct listnode *n; |
1119 | struct ospf6_area *oa; | |
1120 | char router_id[16], duration[32]; | |
1121 | struct timeval now, running, result; | |
1122 | char buf[32], rbuf[32]; | |
35a45dea | 1123 | json_object *json_areas = NULL; |
1124 | const char *adjacency; | |
1125 | ||
1126 | if (use_json) { | |
1127 | json_areas = json_object_new_object(); | |
1128 | ||
1129 | /* process id, router id */ | |
1130 | inet_ntop(AF_INET, &o->router_id, router_id, sizeof(router_id)); | |
1131 | json_object_string_add(json, "routerId", router_id); | |
1132 | ||
1133 | /* running time */ | |
1134 | monotime(&now); | |
1135 | timersub(&now, &o->starttime, &running); | |
1136 | timerstring(&running, duration, sizeof(duration)); | |
1137 | json_object_string_add(json, "running", duration); | |
1138 | ||
1139 | /* Redistribute configuration */ | |
1140 | /* XXX */ | |
1141 | json_object_int_add(json, "lsaMinimumArrivalMsecs", | |
1142 | o->lsa_minarrival); | |
1143 | ||
1144 | /* Show SPF parameters */ | |
1145 | json_object_int_add(json, "spfScheduleDelayMsecs", | |
1146 | o->spf_delay); | |
1147 | json_object_int_add(json, "holdTimeMinMsecs", o->spf_holdtime); | |
1148 | json_object_int_add(json, "holdTimeMaxMsecs", | |
1149 | o->spf_max_holdtime); | |
1150 | json_object_int_add(json, "holdTimeMultiplier", | |
1151 | o->spf_hold_multiplier); | |
1152 | ||
1958143e | 1153 | json_object_int_add(json, "maximumPaths", o->max_multipath); |
35a45dea | 1154 | |
1155 | if (o->ts_spf.tv_sec || o->ts_spf.tv_usec) { | |
1156 | timersub(&now, &o->ts_spf, &result); | |
1157 | timerstring(&result, buf, sizeof(buf)); | |
1158 | ospf6_spf_reason_string(o->last_spf_reason, rbuf, | |
1159 | sizeof(rbuf)); | |
1160 | json_object_boolean_true_add(json, "spfHasRun"); | |
1161 | json_object_string_add(json, "spfLastExecutedMsecs", | |
1162 | buf); | |
1163 | json_object_string_add(json, "spfLastExecutedReason", | |
1164 | rbuf); | |
1165 | ||
1166 | json_object_int_add( | |
1167 | json, "spfLastDurationSecs", | |
1168 | (long long)o->ts_spf_duration.tv_sec); | |
1169 | ||
1170 | json_object_int_add( | |
1171 | json, "spfLastDurationMsecs", | |
1172 | (long long)o->ts_spf_duration.tv_usec); | |
1173 | } else | |
1174 | json_object_boolean_false_add(json, "spfHasRun"); | |
1175 | ||
1176 | ||
1177 | threadtimer_string(now, o->t_spf_calc, buf, sizeof(buf)); | |
1178 | if (o->t_spf_calc) { | |
1179 | long time_store; | |
1180 | ||
1181 | json_object_boolean_true_add(json, "spfTimerActive"); | |
1182 | time_store = | |
1183 | monotime_until(&o->t_spf_calc->u.sands, NULL) | |
1184 | / 1000LL; | |
1185 | json_object_int_add(json, "spfTimerDueInMsecs", | |
1186 | time_store); | |
1187 | } else | |
1188 | json_object_boolean_false_add(json, "spfTimerActive"); | |
1189 | ||
1190 | json_object_boolean_add(json, "routerIsStubRouter", | |
1191 | CHECK_FLAG(o->flag, OSPF6_STUB_ROUTER)); | |
1192 | ||
1193 | /* LSAs */ | |
1194 | json_object_int_add(json, "numberOfAsScopedLsa", | |
1195 | o->lsdb->count); | |
1196 | /* Areas */ | |
1197 | json_object_int_add(json, "numberOfAreaInRouter", | |
1198 | listcount(o->area_list)); | |
1199 | ||
1200 | if (CHECK_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_CHANGES)) { | |
1201 | if (CHECK_FLAG(o->config_flags, | |
1202 | OSPF6_LOG_ADJACENCY_DETAIL)) | |
1203 | adjacency = "LoggedAll"; | |
1204 | else | |
1205 | adjacency = "Logged"; | |
1206 | } else | |
1207 | adjacency = "NotLogged"; | |
1208 | json_object_string_add(json, "adjacencyChanges", adjacency); | |
1209 | ||
1210 | for (ALL_LIST_ELEMENTS_RO(o->area_list, n, oa)) | |
1211 | ospf6_area_show(vty, oa, json_areas, use_json); | |
1212 | ||
1213 | json_object_object_add(json, "areas", json_areas); | |
1214 | ||
1215 | vty_out(vty, "%s\n", | |
1216 | json_object_to_json_string_ext( | |
1217 | json, JSON_C_TO_STRING_PRETTY)); | |
1218 | ||
1219 | } else { | |
1220 | /* process id, router id */ | |
1221 | inet_ntop(AF_INET, &o->router_id, router_id, sizeof(router_id)); | |
1222 | vty_out(vty, " OSPFv3 Routing Process (0) with Router-ID %s\n", | |
1223 | router_id); | |
1224 | ||
1225 | /* running time */ | |
1226 | monotime(&now); | |
1227 | timersub(&now, &o->starttime, &running); | |
1228 | timerstring(&running, duration, sizeof(duration)); | |
1229 | vty_out(vty, " Running %s\n", duration); | |
1230 | ||
1231 | /* Redistribute configuration */ | |
1232 | /* XXX */ | |
1233 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
1234 | o->lsa_minarrival); | |
1235 | ||
1958143e | 1236 | vty_out(vty, " Maximum-paths %u\n", o->max_multipath); |
35a45dea | 1237 | |
1238 | /* Show SPF parameters */ | |
1239 | vty_out(vty, | |
1240 | " Initial SPF scheduling delay %d millisec(s)\n" | |
1241 | " Minimum hold time between consecutive SPFs %d millsecond(s)\n" | |
1242 | " Maximum hold time between consecutive SPFs %d millsecond(s)\n" | |
1243 | " Hold time multiplier is currently %d\n", | |
1244 | o->spf_delay, o->spf_holdtime, o->spf_max_holdtime, | |
1245 | o->spf_hold_multiplier); | |
1246 | ||
1247 | ||
1248 | vty_out(vty, " SPF algorithm "); | |
1249 | if (o->ts_spf.tv_sec || o->ts_spf.tv_usec) { | |
1250 | timersub(&now, &o->ts_spf, &result); | |
1251 | timerstring(&result, buf, sizeof(buf)); | |
1252 | ospf6_spf_reason_string(o->last_spf_reason, rbuf, | |
1253 | sizeof(rbuf)); | |
1254 | vty_out(vty, "last executed %s ago, reason %s\n", buf, | |
1255 | rbuf); | |
1256 | vty_out(vty, " Last SPF duration %lld sec %lld usec\n", | |
1257 | (long long)o->ts_spf_duration.tv_sec, | |
1258 | (long long)o->ts_spf_duration.tv_usec); | |
1259 | } else | |
1260 | vty_out(vty, "has not been run\n"); | |
1261 | ||
1262 | threadtimer_string(now, o->t_spf_calc, buf, sizeof(buf)); | |
1263 | vty_out(vty, " SPF timer %s%s\n", | |
1264 | (o->t_spf_calc ? "due in " : "is "), buf); | |
1265 | ||
1266 | if (CHECK_FLAG(o->flag, OSPF6_STUB_ROUTER)) | |
1267 | vty_out(vty, " Router Is Stub Router\n"); | |
1268 | ||
1269 | /* LSAs */ | |
1270 | vty_out(vty, " Number of AS scoped LSAs is %u\n", | |
1271 | o->lsdb->count); | |
1272 | ||
1273 | /* Areas */ | |
1274 | vty_out(vty, " Number of areas in this router is %u\n", | |
1275 | listcount(o->area_list)); | |
1276 | ||
1277 | if (CHECK_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_CHANGES)) { | |
1278 | if (CHECK_FLAG(o->config_flags, | |
1279 | OSPF6_LOG_ADJACENCY_DETAIL)) | |
1280 | vty_out(vty, | |
1281 | " All adjacency changes are logged\n"); | |
1282 | else | |
1283 | vty_out(vty, " Adjacency changes are logged\n"); | |
1284 | } | |
d62a17ae | 1285 | |
d62a17ae | 1286 | |
35a45dea | 1287 | vty_out(vty, "\n"); |
d62a17ae | 1288 | |
35a45dea | 1289 | for (ALL_LIST_ELEMENTS_RO(o->area_list, n, oa)) |
1290 | ospf6_area_show(vty, oa, json_areas, use_json); | |
1291 | } | |
718e3744 | 1292 | } |
1293 | ||
dd7fb1db PG |
1294 | DEFUN(show_ipv6_ospf6_vrfs, show_ipv6_ospf6_vrfs_cmd, |
1295 | "show ipv6 ospf6 vrfs [json]", | |
1296 | SHOW_STR IP6_STR OSPF6_STR "Show OSPF6 VRFs \n" JSON_STR) | |
1297 | { | |
1298 | bool uj = use_json(argc, argv); | |
1299 | json_object *json = NULL; | |
1300 | json_object *json_vrfs = NULL; | |
1301 | struct ospf6 *ospf6 = NULL; | |
1302 | struct listnode *node = NULL; | |
1303 | int count = 0; | |
1304 | char buf[PREFIX_STRLEN]; | |
1305 | static const char header[] = | |
1306 | "Name Id RouterId "; | |
1307 | ||
1308 | if (uj) { | |
1309 | json = json_object_new_object(); | |
1310 | json_vrfs = json_object_new_object(); | |
1311 | } | |
1312 | ||
1313 | for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { | |
1314 | json_object *json_vrf = NULL; | |
1315 | const char *name = NULL; | |
1316 | int64_t vrf_id_ui = 0; | |
1317 | struct in_addr router_id; | |
1318 | ||
1319 | router_id.s_addr = ospf6->router_id; | |
1320 | count++; | |
1321 | ||
1322 | if (!uj && count == 1) | |
1323 | vty_out(vty, "%s\n", header); | |
1324 | if (uj) | |
1325 | json_vrf = json_object_new_object(); | |
1326 | ||
1327 | if (ospf6->vrf_id == VRF_DEFAULT) | |
1328 | name = VRF_DEFAULT_NAME; | |
1329 | else | |
1330 | name = ospf6->name; | |
1331 | ||
1332 | vrf_id_ui = (ospf6->vrf_id == VRF_UNKNOWN) | |
1333 | ? -1 | |
1334 | : (int64_t)ospf6->vrf_id; | |
1335 | ||
1336 | if (uj) { | |
1337 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
1338 | json_object_string_add(json_vrf, "routerId", | |
1339 | inet_ntop(AF_INET, &router_id, | |
1340 | buf, sizeof(buf))); | |
1341 | json_object_object_add(json_vrfs, name, json_vrf); | |
1342 | ||
1343 | } else { | |
1344 | vty_out(vty, "%-25s %-5d %-16s \n", name, | |
1345 | ospf6->vrf_id, | |
1346 | inet_ntop(AF_INET, &router_id, buf, | |
1347 | sizeof(buf))); | |
1348 | } | |
1349 | } | |
1350 | ||
1351 | if (uj) { | |
1352 | json_object_object_add(json, "vrfs", json_vrfs); | |
1353 | json_object_int_add(json, "totalVrfs", count); | |
1354 | ||
1355 | vty_out(vty, "%s\n", | |
1356 | json_object_to_json_string_ext( | |
1357 | json, JSON_C_TO_STRING_PRETTY)); | |
1358 | json_object_free(json); | |
1359 | } else { | |
1360 | if (count) | |
1361 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", | |
1362 | count); | |
1363 | } | |
1364 | ||
1365 | return CMD_SUCCESS; | |
1366 | } | |
1367 | ||
508e53e2 | 1368 | /* show top level structures */ |
d48ef099 | 1369 | DEFUN(show_ipv6_ospf6, show_ipv6_ospf6_cmd, |
1370 | "show ipv6 ospf6 [vrf <NAME|all>] [json]", | |
1371 | SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR "All VRFs\n" JSON_STR) | |
718e3744 | 1372 | { |
beadc736 | 1373 | struct ospf6 *ospf6; |
d48ef099 | 1374 | struct listnode *node; |
1375 | const char *vrf_name = NULL; | |
1376 | bool all_vrf = false; | |
1377 | int idx_vrf = 0; | |
1378 | ||
35a45dea | 1379 | bool uj = use_json(argc, argv); |
1380 | json_object *json = NULL; | |
508e53e2 | 1381 | |
d48ef099 | 1382 | OSPF6_CMD_CHECK_RUNNING(); |
1383 | OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
35a45dea | 1384 | |
d48ef099 | 1385 | for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { |
1386 | if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { | |
1387 | if (uj) | |
1388 | json = json_object_new_object(); | |
1389 | ospf6_show(vty, ospf6, json, uj); | |
35a45dea | 1390 | |
d48ef099 | 1391 | if (!all_vrf) |
1392 | break; | |
1393 | } | |
1394 | } | |
35a45dea | 1395 | |
1396 | if (uj) | |
1397 | json_object_free(json); | |
d48ef099 | 1398 | |
d62a17ae | 1399 | return CMD_SUCCESS; |
718e3744 | 1400 | } |
1401 | ||
d48ef099 | 1402 | DEFUN(show_ipv6_ospf6_route, show_ipv6_ospf6_route_cmd, |
1403 | "show ipv6 ospf6 [vrf <NAME|all>] route [<intra-area|inter-area|external-1|external-2|X:X::X:X|X:X::X:X/M|detail|summary>] [json]", | |
1404 | SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR | |
1405 | "All VRFs\n" ROUTE_STR | |
1406 | "Display Intra-Area routes\n" | |
1407 | "Display Inter-Area routes\n" | |
1408 | "Display Type-1 External routes\n" | |
1409 | "Display Type-2 External routes\n" | |
1410 | "Specify IPv6 address\n" | |
1411 | "Specify IPv6 prefix\n" | |
1412 | "Detailed information\n" | |
1413 | "Summary of route table\n" JSON_STR) | |
718e3744 | 1414 | { |
beadc736 | 1415 | struct ospf6 *ospf6; |
d48ef099 | 1416 | struct listnode *node; |
1417 | const char *vrf_name = NULL; | |
1418 | bool all_vrf = false; | |
1419 | int idx_vrf = 0; | |
1420 | int idx_arg_start = 4; | |
eacd0828 | 1421 | bool uj = use_json(argc, argv); |
beadc736 | 1422 | |
d48ef099 | 1423 | OSPF6_CMD_CHECK_RUNNING(); |
1424 | OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
1425 | if (idx_vrf > 0) | |
1426 | idx_arg_start += 2; | |
1427 | ||
1428 | for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { | |
1429 | if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { | |
1430 | ospf6_route_table_show(vty, idx_arg_start, argc, argv, | |
1431 | ospf6->route_table, uj); | |
1432 | ||
1433 | if (!all_vrf) | |
1434 | break; | |
1435 | } | |
1436 | } | |
b52a8a52 | 1437 | |
d62a17ae | 1438 | return CMD_SUCCESS; |
718e3744 | 1439 | } |
1440 | ||
d48ef099 | 1441 | DEFUN(show_ipv6_ospf6_route_match, show_ipv6_ospf6_route_match_cmd, |
1442 | "show ipv6 ospf6 [vrf <NAME|all>] route X:X::X:X/M <match|longer> [json]", | |
1443 | SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR | |
1444 | "All VRFs\n" ROUTE_STR | |
1445 | "Specify IPv6 prefix\n" | |
1446 | "Display routes which match the specified route\n" | |
1447 | "Display routes longer than the specified route\n" JSON_STR) | |
718e3744 | 1448 | { |
beadc736 | 1449 | struct ospf6 *ospf6; |
d48ef099 | 1450 | struct listnode *node; |
1451 | const char *vrf_name = NULL; | |
1452 | bool all_vrf = false; | |
1453 | int idx_vrf = 0; | |
1454 | int idx_start_arg = 4; | |
eacd0828 | 1455 | bool uj = use_json(argc, argv); |
beadc736 | 1456 | |
d48ef099 | 1457 | OSPF6_CMD_CHECK_RUNNING(); |
1458 | OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
1459 | if (idx_vrf > 0) | |
1460 | idx_start_arg += 2; | |
1461 | ||
1462 | for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { | |
1463 | if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { | |
1464 | ospf6_route_table_show(vty, idx_start_arg, argc, argv, | |
1465 | ospf6->route_table, uj); | |
1466 | ||
1467 | if (!all_vrf) | |
1468 | break; | |
1469 | } | |
1470 | } | |
b52a8a52 | 1471 | |
d62a17ae | 1472 | return CMD_SUCCESS; |
718e3744 | 1473 | } |
1474 | ||
d48ef099 | 1475 | DEFUN(show_ipv6_ospf6_route_match_detail, |
1476 | show_ipv6_ospf6_route_match_detail_cmd, | |
1477 | "show ipv6 ospf6 [vrf <NAME|all>] route X:X::X:X/M match detail [json]", | |
1478 | SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR | |
1479 | "All VRFs\n" ROUTE_STR | |
1480 | "Specify IPv6 prefix\n" | |
1481 | "Display routes which match the specified route\n" | |
1482 | "Detailed information\n" JSON_STR) | |
508e53e2 | 1483 | { |
beadc736 | 1484 | struct ospf6 *ospf6; |
d48ef099 | 1485 | struct listnode *node; |
1486 | const char *vrf_name = NULL; | |
1487 | bool all_vrf = false; | |
1488 | int idx_vrf = 0; | |
1489 | int idx_start_arg = 4; | |
eacd0828 | 1490 | bool uj = use_json(argc, argv); |
beadc736 | 1491 | |
d48ef099 | 1492 | OSPF6_CMD_CHECK_RUNNING(); |
1493 | OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
1494 | if (idx_vrf > 0) | |
1495 | idx_start_arg += 2; | |
1496 | ||
1497 | for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { | |
1498 | if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { | |
1499 | ospf6_route_table_show(vty, idx_start_arg, argc, argv, | |
1500 | ospf6->route_table, uj); | |
1501 | ||
1502 | if (!all_vrf) | |
1503 | break; | |
1504 | } | |
1505 | } | |
b52a8a52 | 1506 | |
d62a17ae | 1507 | return CMD_SUCCESS; |
508e53e2 | 1508 | } |
718e3744 | 1509 | |
d48ef099 | 1510 | DEFUN(show_ipv6_ospf6_route_type_detail, show_ipv6_ospf6_route_type_detail_cmd, |
1511 | "show ipv6 ospf6 [vrf <NAME|all>] route <intra-area|inter-area|external-1|external-2> detail [json]", | |
1512 | SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR | |
1513 | "All VRFs\n" ROUTE_STR | |
1514 | "Display Intra-Area routes\n" | |
1515 | "Display Inter-Area routes\n" | |
1516 | "Display Type-1 External routes\n" | |
1517 | "Display Type-2 External routes\n" | |
1518 | "Detailed information\n" JSON_STR) | |
4846ef64 | 1519 | { |
beadc736 | 1520 | struct ospf6 *ospf6; |
d48ef099 | 1521 | struct listnode *node; |
1522 | const char *vrf_name = NULL; | |
1523 | bool all_vrf = false; | |
1524 | int idx_vrf = 0; | |
1525 | int idx_start_arg = 4; | |
eacd0828 | 1526 | bool uj = use_json(argc, argv); |
beadc736 | 1527 | |
d48ef099 | 1528 | OSPF6_CMD_CHECK_RUNNING(); |
1529 | OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
1530 | if (idx_vrf > 0) | |
1531 | idx_start_arg += 2; | |
1532 | ||
1533 | for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) { | |
1534 | if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) { | |
1535 | ospf6_route_table_show(vty, idx_start_arg, argc, argv, | |
1536 | ospf6->route_table, uj); | |
1537 | ||
1538 | if (!all_vrf) | |
1539 | break; | |
1540 | } | |
1541 | } | |
b52a8a52 | 1542 | |
d62a17ae | 1543 | return CMD_SUCCESS; |
4846ef64 | 1544 | } |
718e3744 | 1545 | |
beadc736 | 1546 | static void ospf6_stub_router_config_write(struct vty *vty, struct ospf6 *ospf6) |
f41b4a02 | 1547 | { |
d62a17ae | 1548 | if (CHECK_FLAG(ospf6->flag, OSPF6_STUB_ROUTER)) { |
1549 | vty_out(vty, " stub-router administrative\n"); | |
1550 | } | |
1551 | return; | |
f41b4a02 DD |
1552 | } |
1553 | ||
beadc736 | 1554 | static int ospf6_distance_config_write(struct vty *vty, struct ospf6 *ospf6) |
baff583e | 1555 | { |
d62a17ae | 1556 | struct route_node *rn; |
1557 | struct ospf6_distance *odistance; | |
1558 | ||
1559 | if (ospf6->distance_all) | |
1560 | vty_out(vty, " distance %u\n", ospf6->distance_all); | |
1561 | ||
1562 | if (ospf6->distance_intra || ospf6->distance_inter | |
1563 | || ospf6->distance_external) { | |
1564 | vty_out(vty, " distance ospf6"); | |
1565 | ||
1566 | if (ospf6->distance_intra) | |
1567 | vty_out(vty, " intra-area %u", ospf6->distance_intra); | |
1568 | if (ospf6->distance_inter) | |
1569 | vty_out(vty, " inter-area %u", ospf6->distance_inter); | |
1570 | if (ospf6->distance_external) | |
1571 | vty_out(vty, " external %u", ospf6->distance_external); | |
1572 | ||
1573 | vty_out(vty, "\n"); | |
1574 | } | |
1575 | ||
1576 | for (rn = route_top(ospf6->distance_table); rn; rn = route_next(rn)) | |
2dbe669b DA |
1577 | if ((odistance = rn->info) != NULL) |
1578 | vty_out(vty, " distance %u %pFX %s\n", | |
1579 | odistance->distance, &rn->p, | |
d62a17ae | 1580 | odistance->access_list ? odistance->access_list |
1581 | : ""); | |
d62a17ae | 1582 | return 0; |
baff583e MZ |
1583 | } |
1584 | ||
508e53e2 | 1585 | /* OSPF configuration write function. */ |
d62a17ae | 1586 | static int config_write_ospf6(struct vty *vty) |
508e53e2 | 1587 | { |
d62a17ae | 1588 | struct listnode *j, *k; |
1589 | struct ospf6_area *oa; | |
1590 | struct ospf6_interface *oi; | |
beadc736 | 1591 | struct ospf6 *ospf6; |
1592 | struct listnode *node, *nnode; | |
d62a17ae | 1593 | |
1594 | /* OSPFv3 configuration. */ | |
beadc736 | 1595 | if (om6 == NULL) |
d62a17ae | 1596 | return CMD_SUCCESS; |
1597 | ||
beadc736 | 1598 | for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) { |
d48ef099 | 1599 | if (ospf6->name && strcmp(ospf6->name, VRF_DEFAULT_NAME)) |
1600 | vty_out(vty, "router ospf6 vrf %s\n", ospf6->name); | |
1601 | else | |
1602 | vty_out(vty, "router ospf6\n"); | |
1603 | ||
beadc736 | 1604 | if (ospf6->router_id_static != 0) |
1605 | vty_out(vty, " ospf6 router-id %pI4\n", | |
1606 | &ospf6->router_id_static); | |
1607 | ||
1608 | /* log-adjacency-changes flag print. */ | |
1609 | if (CHECK_FLAG(ospf6->config_flags, | |
1610 | OSPF6_LOG_ADJACENCY_CHANGES)) { | |
1611 | if (CHECK_FLAG(ospf6->config_flags, | |
1612 | OSPF6_LOG_ADJACENCY_DETAIL)) | |
1613 | vty_out(vty, " log-adjacency-changes detail\n"); | |
1614 | else if (!SAVE_OSPF6_LOG_ADJACENCY_CHANGES) | |
1615 | vty_out(vty, " log-adjacency-changes\n"); | |
1616 | } else if (SAVE_OSPF6_LOG_ADJACENCY_CHANGES) { | |
1617 | vty_out(vty, " no log-adjacency-changes\n"); | |
1618 | } | |
d62a17ae | 1619 | |
beadc736 | 1620 | if (ospf6->ref_bandwidth != OSPF6_REFERENCE_BANDWIDTH) |
1621 | vty_out(vty, " auto-cost reference-bandwidth %d\n", | |
1622 | ospf6->ref_bandwidth); | |
1623 | ||
1624 | /* LSA timers print. */ | |
1625 | if (ospf6->lsa_minarrival != OSPF_MIN_LS_ARRIVAL) | |
1626 | vty_out(vty, " timers lsa min-arrival %d\n", | |
1627 | ospf6->lsa_minarrival); | |
1628 | ||
1958143e MR |
1629 | /* ECMP max path config */ |
1630 | if (ospf6->max_multipath != MULTIPATH_NUM) | |
1631 | vty_out(vty, " maximum-paths %d\n", | |
1632 | ospf6->max_multipath); | |
1633 | ||
beadc736 | 1634 | ospf6_stub_router_config_write(vty, ospf6); |
1635 | ospf6_redistribute_config_write(vty, ospf6); | |
1636 | ospf6_area_config_write(vty, ospf6); | |
1637 | ospf6_spf_config_write(vty, ospf6); | |
1638 | ospf6_distance_config_write(vty, ospf6); | |
b19502d3 | 1639 | ospf6_distribute_config_write(vty, ospf6); |
beadc736 | 1640 | |
1641 | for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, j, oa)) { | |
1642 | for (ALL_LIST_ELEMENTS_RO(oa->if_list, k, oi)) | |
1643 | vty_out(vty, " interface %s area %s\n", | |
1644 | oi->interface->name, oa->name); | |
1645 | } | |
1646 | vty_out(vty, "!\n"); | |
d62a17ae | 1647 | } |
d62a17ae | 1648 | return 0; |
508e53e2 | 1649 | } |
1650 | ||
612c2c15 | 1651 | static int config_write_ospf6(struct vty *vty); |
508e53e2 | 1652 | /* OSPF6 node structure. */ |
d62a17ae | 1653 | static struct cmd_node ospf6_node = { |
f4b8291f | 1654 | .name = "ospf6", |
62b346ee | 1655 | .node = OSPF6_NODE, |
24389580 | 1656 | .parent_node = CONFIG_NODE, |
62b346ee | 1657 | .prompt = "%s(config-ospf6)# ", |
612c2c15 | 1658 | .config_write = config_write_ospf6, |
508e53e2 | 1659 | }; |
1660 | ||
1661 | /* Install ospf related commands. */ | |
d62a17ae | 1662 | void ospf6_top_init(void) |
718e3744 | 1663 | { |
d62a17ae | 1664 | /* Install ospf6 top node. */ |
612c2c15 | 1665 | install_node(&ospf6_node); |
d62a17ae | 1666 | |
1667 | install_element(VIEW_NODE, &show_ipv6_ospf6_cmd); | |
dd7fb1db | 1668 | install_element(VIEW_NODE, &show_ipv6_ospf6_vrfs_cmd); |
d62a17ae | 1669 | install_element(CONFIG_NODE, &router_ospf6_cmd); |
1670 | install_element(CONFIG_NODE, &no_router_ospf6_cmd); | |
1671 | ||
1672 | install_element(VIEW_NODE, &show_ipv6_ospf6_route_cmd); | |
1673 | install_element(VIEW_NODE, &show_ipv6_ospf6_route_match_cmd); | |
1674 | install_element(VIEW_NODE, &show_ipv6_ospf6_route_match_detail_cmd); | |
1675 | install_element(VIEW_NODE, &show_ipv6_ospf6_route_type_detail_cmd); | |
1676 | ||
1677 | install_default(OSPF6_NODE); | |
1678 | install_element(OSPF6_NODE, &ospf6_router_id_cmd); | |
5d1a2ee8 | 1679 | install_element(OSPF6_NODE, &no_ospf6_router_id_cmd); |
d62a17ae | 1680 | install_element(OSPF6_NODE, &ospf6_log_adjacency_changes_cmd); |
1681 | install_element(OSPF6_NODE, &ospf6_log_adjacency_changes_detail_cmd); | |
1682 | install_element(OSPF6_NODE, &no_ospf6_log_adjacency_changes_cmd); | |
1683 | install_element(OSPF6_NODE, &no_ospf6_log_adjacency_changes_detail_cmd); | |
1684 | ||
1685 | /* LSA timers commands */ | |
1686 | install_element(OSPF6_NODE, &ospf6_timers_lsa_cmd); | |
1687 | install_element(OSPF6_NODE, &no_ospf6_timers_lsa_cmd); | |
1688 | ||
1689 | install_element(OSPF6_NODE, &ospf6_interface_area_cmd); | |
1690 | install_element(OSPF6_NODE, &no_ospf6_interface_area_cmd); | |
1691 | install_element(OSPF6_NODE, &ospf6_stub_router_admin_cmd); | |
1692 | install_element(OSPF6_NODE, &no_ospf6_stub_router_admin_cmd); | |
508e53e2 | 1693 | |
1958143e MR |
1694 | /* maximum-paths command */ |
1695 | install_element(OSPF6_NODE, &ospf6_max_multipath_cmd); | |
1696 | install_element(OSPF6_NODE, &no_ospf6_max_multipath_cmd); | |
1697 | ||
d62a17ae | 1698 | install_element(OSPF6_NODE, &ospf6_distance_cmd); |
1699 | install_element(OSPF6_NODE, &no_ospf6_distance_cmd); | |
1700 | install_element(OSPF6_NODE, &ospf6_distance_ospf6_cmd); | |
1701 | install_element(OSPF6_NODE, &no_ospf6_distance_ospf6_cmd); | |
718e3744 | 1702 | } |