]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_neighbor.c
Merge pull request #12521 from patrasar/issue_11347_fix
[mirror_frr.git] / ospf6d / ospf6_neighbor.c
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 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
19 */
20
21 #include <zebra.h>
22
23 #include "log.h"
24 #include "memory.h"
25 #include "thread.h"
26 #include "linklist.h"
27 #include "vty.h"
28 #include "command.h"
29 #include "lib/bfd.h"
30
31 #include "ospf6_proto.h"
32 #include "ospf6_lsa.h"
33 #include "ospf6_lsdb.h"
34 #include "ospf6_message.h"
35 #include "ospf6_top.h"
36 #include "ospf6_area.h"
37 #include "ospf6_interface.h"
38 #include "ospf6_neighbor.h"
39 #include "ospf6_intra.h"
40 #include "ospf6_flood.h"
41 #include "ospf6d.h"
42 #include "ospf6_bfd.h"
43 #include "ospf6_abr.h"
44 #include "ospf6_asbr.h"
45 #include "ospf6_lsa.h"
46 #include "ospf6_spf.h"
47 #include "ospf6_zebra.h"
48 #include "ospf6_gr.h"
49 #include "lib/json.h"
50
51 DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_NEIGHBOR, "OSPF6 neighbor");
52
53 DEFINE_HOOK(ospf6_neighbor_change,
54 (struct ospf6_neighbor * on, int state, int next_state),
55 (on, state, next_state));
56
57 unsigned char conf_debug_ospf6_neighbor = 0;
58
59 const char *const ospf6_neighbor_state_str[] = {
60 "None", "Down", "Attempt", "Init", "Twoway",
61 "ExStart", "ExChange", "Loading", "Full", NULL};
62
63 const char *const ospf6_neighbor_event_str[] = {
64 "NoEvent", "HelloReceived", "2-WayReceived", "NegotiationDone",
65 "ExchangeDone", "LoadingDone", "AdjOK?", "SeqNumberMismatch",
66 "BadLSReq", "1-WayReceived", "InactivityTimer",
67 };
68
69 int ospf6_neighbor_cmp(void *va, void *vb)
70 {
71 struct ospf6_neighbor *ona = (struct ospf6_neighbor *)va;
72 struct ospf6_neighbor *onb = (struct ospf6_neighbor *)vb;
73
74 if (ona->router_id == onb->router_id)
75 return 0;
76
77 return (ntohl(ona->router_id) < ntohl(onb->router_id)) ? -1 : 1;
78 }
79
80 struct ospf6_neighbor *ospf6_neighbor_lookup(uint32_t router_id,
81 struct ospf6_interface *oi)
82 {
83 struct listnode *n;
84 struct ospf6_neighbor *on;
85
86 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, n, on))
87 if (on->router_id == router_id)
88 return on;
89
90 return (struct ospf6_neighbor *)NULL;
91 }
92
93 struct ospf6_neighbor *ospf6_area_neighbor_lookup(struct ospf6_area *area,
94 uint32_t router_id)
95 {
96 struct ospf6_interface *oi;
97 struct ospf6_neighbor *nbr;
98 struct listnode *node;
99
100 for (ALL_LIST_ELEMENTS_RO(area->if_list, node, oi)) {
101 nbr = ospf6_neighbor_lookup(router_id, oi);
102 if (nbr)
103 return nbr;
104 }
105
106 return NULL;
107 }
108
109 static void ospf6_neighbor_clear_ls_lists(struct ospf6_neighbor *on)
110 {
111 struct ospf6_lsa *lsa;
112 struct ospf6_lsa *lsanext;
113
114 ospf6_lsdb_remove_all(on->summary_list);
115 if (on->last_ls_req) {
116 ospf6_lsa_unlock(on->last_ls_req);
117 on->last_ls_req = NULL;
118 }
119 ospf6_lsdb_remove_all(on->request_list);
120 for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
121 ospf6_decrement_retrans_count(lsa);
122 ospf6_lsdb_remove(lsa, on->retrans_list);
123 }
124 }
125
126 /* create ospf6_neighbor */
127 struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id,
128 struct ospf6_interface *oi)
129 {
130 struct ospf6_neighbor *on;
131 char buf[16];
132 int type;
133
134 on = XCALLOC(MTYPE_OSPF6_NEIGHBOR, sizeof(struct ospf6_neighbor));
135 inet_ntop(AF_INET, &router_id, buf, sizeof(buf));
136 snprintf(on->name, sizeof(on->name), "%s%%%s", buf,
137 oi->interface->name);
138 on->ospf6_if = oi;
139 on->state = OSPF6_NEIGHBOR_DOWN;
140 on->state_change = 0;
141 monotime(&on->last_changed);
142 on->router_id = router_id;
143
144 on->summary_list = ospf6_lsdb_create(on);
145 on->request_list = ospf6_lsdb_create(on);
146 on->retrans_list = ospf6_lsdb_create(on);
147
148 on->dbdesc_list = ospf6_lsdb_create(on);
149 on->lsupdate_list = ospf6_lsdb_create(on);
150 on->lsack_list = ospf6_lsdb_create(on);
151
152 for (type = 0; type < OSPF6_MESSAGE_TYPE_MAX; type++) {
153 on->seqnum_l[type] = 0;
154 on->seqnum_h[type] = 0;
155 }
156
157 on->auth_present = false;
158
159 listnode_add_sort(oi->neighbor_list, on);
160
161 ospf6_bfd_info_nbr_create(oi, on);
162 return on;
163 }
164
165 void ospf6_neighbor_delete(struct ospf6_neighbor *on)
166 {
167 ospf6_neighbor_clear_ls_lists(on);
168
169 ospf6_lsdb_remove_all(on->dbdesc_list);
170 ospf6_lsdb_remove_all(on->lsupdate_list);
171 ospf6_lsdb_remove_all(on->lsack_list);
172
173 ospf6_lsdb_delete(on->summary_list);
174 ospf6_lsdb_delete(on->request_list);
175 ospf6_lsdb_delete(on->retrans_list);
176
177 ospf6_lsdb_delete(on->dbdesc_list);
178 ospf6_lsdb_delete(on->lsupdate_list);
179 ospf6_lsdb_delete(on->lsack_list);
180
181 THREAD_OFF(on->inactivity_timer);
182
183 THREAD_OFF(on->last_dbdesc_release_timer);
184
185 THREAD_OFF(on->thread_send_dbdesc);
186 THREAD_OFF(on->thread_send_lsreq);
187 THREAD_OFF(on->thread_send_lsupdate);
188 THREAD_OFF(on->thread_send_lsack);
189 THREAD_OFF(on->thread_exchange_done);
190 THREAD_OFF(on->thread_adj_ok);
191
192 THREAD_OFF(on->gr_helper_info.t_grace_timer);
193
194 bfd_sess_free(&on->bfd_session);
195 XFREE(MTYPE_OSPF6_NEIGHBOR, on);
196 }
197
198 static void ospf6_neighbor_state_change(uint8_t next_state,
199 struct ospf6_neighbor *on, int event)
200 {
201 uint8_t prev_state;
202
203 prev_state = on->state;
204 on->state = next_state;
205
206 if (prev_state == next_state)
207 return;
208
209 on->state_change++;
210 monotime(&on->last_changed);
211
212 /* log */
213 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE)) {
214 zlog_debug("Neighbor state change %s: [%s]->[%s] (%s)",
215 on->name, ospf6_neighbor_state_str[prev_state],
216 ospf6_neighbor_state_str[next_state],
217 ospf6_neighbor_event_string(event));
218 }
219
220 /* Optionally notify about adjacency changes */
221 if (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
222 OSPF6_LOG_ADJACENCY_CHANGES)
223 && (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
224 OSPF6_LOG_ADJACENCY_DETAIL)
225 || (next_state == OSPF6_NEIGHBOR_FULL)
226 || (next_state < prev_state)))
227 zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on->name,
228 ospf6_neighbor_state_str[prev_state],
229 ospf6_neighbor_state_str[next_state],
230 ospf6_neighbor_event_string(event));
231
232 if (prev_state == OSPF6_NEIGHBOR_FULL
233 || next_state == OSPF6_NEIGHBOR_FULL) {
234 if (!OSPF6_GR_IS_ACTIVE_HELPER(on)) {
235 OSPF6_ROUTER_LSA_SCHEDULE(on->ospf6_if->area);
236 if (on->ospf6_if->state == OSPF6_INTERFACE_DR) {
237 OSPF6_NETWORK_LSA_SCHEDULE(on->ospf6_if);
238 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(
239 on->ospf6_if);
240 }
241 }
242 if (next_state == OSPF6_NEIGHBOR_FULL)
243 on->ospf6_if->area->intra_prefix_originate = 1;
244
245 if (!OSPF6_GR_IS_ACTIVE_HELPER(on))
246 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(
247 on->ospf6_if->area);
248
249 if ((prev_state == OSPF6_NEIGHBOR_LOADING
250 || prev_state == OSPF6_NEIGHBOR_EXCHANGE)
251 && next_state == OSPF6_NEIGHBOR_FULL) {
252 OSPF6_AS_EXTERN_LSA_SCHEDULE(on->ospf6_if);
253 on->ospf6_if->area->full_nbrs++;
254 }
255
256 if (prev_state == OSPF6_NEIGHBOR_FULL)
257 on->ospf6_if->area->full_nbrs--;
258 }
259
260 if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE
261 || prev_state == OSPF6_NEIGHBOR_LOADING)
262 && (next_state != OSPF6_NEIGHBOR_EXCHANGE
263 && next_state != OSPF6_NEIGHBOR_LOADING))
264 ospf6_maxage_remove(on->ospf6_if->area->ospf6);
265
266 hook_call(ospf6_neighbor_change, on, next_state, prev_state);
267 ospf6_bfd_trigger_event(on, prev_state, next_state);
268 }
269
270 /* RFC2328 section 10.4 */
271 static int need_adjacency(struct ospf6_neighbor *on)
272 {
273 if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT
274 || on->ospf6_if->state == OSPF6_INTERFACE_DR
275 || on->ospf6_if->state == OSPF6_INTERFACE_BDR)
276 return 1;
277
278 if (on->ospf6_if->drouter == on->router_id
279 || on->ospf6_if->bdrouter == on->router_id)
280 return 1;
281
282 return 0;
283 }
284
285 void hello_received(struct thread *thread)
286 {
287 struct ospf6_neighbor *on;
288
289 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
290 assert(on);
291
292 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
293 zlog_debug("Neighbor Event %s: *HelloReceived*", on->name);
294
295 /* reset Inactivity Timer */
296 THREAD_OFF(on->inactivity_timer);
297 thread_add_timer(master, inactivity_timer, on,
298 on->ospf6_if->dead_interval, &on->inactivity_timer);
299
300 if (on->state <= OSPF6_NEIGHBOR_DOWN)
301 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on,
302 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD);
303 }
304
305 void twoway_received(struct thread *thread)
306 {
307 struct ospf6_neighbor *on;
308
309 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
310 assert(on);
311
312 if (on->state > OSPF6_NEIGHBOR_INIT)
313 return;
314
315 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
316 zlog_debug("Neighbor Event %s: *2Way-Received*", on->name);
317
318 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
319
320 if (!need_adjacency(on)) {
321 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
322 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
323 return;
324 }
325
326 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
327 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
328 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
329 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
330 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
331
332 THREAD_OFF(on->thread_send_dbdesc);
333 thread_add_event(master, ospf6_dbdesc_send, on, 0,
334 &on->thread_send_dbdesc);
335 }
336
337 void negotiation_done(struct thread *thread)
338 {
339 struct ospf6_neighbor *on;
340 struct ospf6_lsa *lsa, *lsanext;
341
342 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
343 assert(on);
344
345 if (on->state != OSPF6_NEIGHBOR_EXSTART)
346 return;
347
348 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
349 zlog_debug("Neighbor Event %s: *NegotiationDone*", on->name);
350
351 /* clear ls-list */
352 ospf6_neighbor_clear_ls_lists(on);
353
354 /* Interface scoped LSAs */
355 for (ALL_LSDB(on->ospf6_if->lsdb, lsa, lsanext)) {
356 if (OSPF6_LSA_IS_MAXAGE(lsa)) {
357 ospf6_increment_retrans_count(lsa);
358 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->retrans_list);
359 } else
360 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->summary_list);
361 }
362
363 /* Area scoped LSAs */
364 for (ALL_LSDB(on->ospf6_if->area->lsdb, lsa, lsanext)) {
365 if (OSPF6_LSA_IS_MAXAGE(lsa)) {
366 ospf6_increment_retrans_count(lsa);
367 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->retrans_list);
368 } else
369 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->summary_list);
370 }
371
372 /* AS scoped LSAs */
373 for (ALL_LSDB(on->ospf6_if->area->ospf6->lsdb, lsa, lsanext)) {
374 if (OSPF6_LSA_IS_MAXAGE(lsa)) {
375 ospf6_increment_retrans_count(lsa);
376 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->retrans_list);
377 } else
378 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->summary_list);
379 }
380
381 UNSET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
382 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE, on,
383 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE);
384 }
385
386 static void ospf6_neighbor_last_dbdesc_release(struct thread *thread)
387 {
388 struct ospf6_neighbor *on = THREAD_ARG(thread);
389
390 assert(on);
391 memset(&on->dbdesc_last, 0, sizeof(struct ospf6_dbdesc));
392 }
393
394 void exchange_done(struct thread *thread)
395 {
396 struct ospf6_neighbor *on;
397
398 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
399 assert(on);
400
401 if (on->state != OSPF6_NEIGHBOR_EXCHANGE)
402 return;
403
404 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
405 zlog_debug("Neighbor Event %s: *ExchangeDone*", on->name);
406
407 THREAD_OFF(on->thread_send_dbdesc);
408 ospf6_lsdb_remove_all(on->dbdesc_list);
409
410 /* RFC 2328 (10.8): Release the last dbdesc after dead_interval */
411 if (!CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT)) {
412 THREAD_OFF(on->last_dbdesc_release_timer);
413 thread_add_timer(master, ospf6_neighbor_last_dbdesc_release, on,
414 on->ospf6_if->dead_interval,
415 &on->last_dbdesc_release_timer);
416 }
417
418 if (on->request_list->count == 0)
419 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL, on,
420 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
421 else {
422 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING, on,
423 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
424
425 thread_add_event(master, ospf6_lsreq_send, on, 0,
426 &on->thread_send_lsreq);
427 }
428 }
429
430 /* Check loading state. */
431 void ospf6_check_nbr_loading(struct ospf6_neighbor *on)
432 {
433
434 /* RFC2328 Section 10.9: When the neighbor responds to these requests
435 with the proper Link State Update packet(s), the Link state request
436 list is truncated and a new Link State Request packet is sent.
437 */
438 if ((on->state == OSPF6_NEIGHBOR_LOADING)
439 || (on->state == OSPF6_NEIGHBOR_EXCHANGE)) {
440 if (on->request_list->count == 0)
441 thread_add_event(master, loading_done, on, 0, NULL);
442 else if (on->last_ls_req == NULL) {
443 THREAD_OFF(on->thread_send_lsreq);
444 thread_add_event(master, ospf6_lsreq_send, on, 0,
445 &on->thread_send_lsreq);
446 }
447 }
448 }
449
450 void loading_done(struct thread *thread)
451 {
452 struct ospf6_neighbor *on;
453
454 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
455 assert(on);
456
457 if (on->state != OSPF6_NEIGHBOR_LOADING)
458 return;
459
460 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
461 zlog_debug("Neighbor Event %s: *LoadingDone*", on->name);
462
463 assert(on->request_list->count == 0);
464
465 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL, on,
466 OSPF6_NEIGHBOR_EVENT_LOADING_DONE);
467 }
468
469 void adj_ok(struct thread *thread)
470 {
471 struct ospf6_neighbor *on;
472
473 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
474 assert(on);
475
476 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
477 zlog_debug("Neighbor Event %s: *AdjOK?*", on->name);
478
479 if (on->state == OSPF6_NEIGHBOR_TWOWAY && need_adjacency(on)) {
480 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
481 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
482 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
483 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
484 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
485
486 THREAD_OFF(on->thread_send_dbdesc);
487 thread_add_event(master, ospf6_dbdesc_send, on, 0,
488 &on->thread_send_dbdesc);
489
490 } else if (on->state >= OSPF6_NEIGHBOR_EXSTART && !need_adjacency(on)) {
491 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
492 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
493 ospf6_neighbor_clear_ls_lists(on);
494 }
495 }
496
497 void seqnumber_mismatch(struct thread *thread)
498 {
499 struct ospf6_neighbor *on;
500
501 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
502 assert(on);
503
504 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
505 return;
506
507 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
508 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on->name);
509
510 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
511 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH);
512 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
513 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
514 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
515
516 ospf6_neighbor_clear_ls_lists(on);
517
518 THREAD_OFF(on->thread_send_dbdesc);
519 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
520
521 thread_add_event(master, ospf6_dbdesc_send, on, 0,
522 &on->thread_send_dbdesc);
523 }
524
525 void bad_lsreq(struct thread *thread)
526 {
527 struct ospf6_neighbor *on;
528
529 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
530 assert(on);
531
532 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
533 return;
534
535 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
536 zlog_debug("Neighbor Event %s: *BadLSReq*", on->name);
537
538 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
539 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ);
540 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
541 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
542 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
543
544 ospf6_neighbor_clear_ls_lists(on);
545
546 THREAD_OFF(on->thread_send_dbdesc);
547 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
548
549 thread_add_event(master, ospf6_dbdesc_send, on, 0,
550 &on->thread_send_dbdesc);
551
552 }
553
554 void oneway_received(struct thread *thread)
555 {
556 struct ospf6_neighbor *on;
557
558 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
559 assert(on);
560
561 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
562 return;
563
564 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
565 zlog_debug("Neighbor Event %s: *1Way-Received*", on->name);
566
567 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on,
568 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD);
569 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
570
571 ospf6_neighbor_clear_ls_lists(on);
572
573 THREAD_OFF(on->thread_send_dbdesc);
574 THREAD_OFF(on->thread_send_lsreq);
575 THREAD_OFF(on->thread_send_lsupdate);
576 THREAD_OFF(on->thread_send_lsack);
577 THREAD_OFF(on->thread_exchange_done);
578 THREAD_OFF(on->thread_adj_ok);
579 }
580
581 void inactivity_timer(struct thread *thread)
582 {
583 struct ospf6_neighbor *on;
584
585 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
586 assert(on);
587
588 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
589 zlog_debug("Neighbor Event %s: *InactivityTimer*", on->name);
590
591 on->drouter = on->prev_drouter = 0;
592 on->bdrouter = on->prev_bdrouter = 0;
593
594 if (!OSPF6_GR_IS_ACTIVE_HELPER(on)) {
595 on->drouter = on->prev_drouter = 0;
596 on->bdrouter = on->prev_bdrouter = 0;
597
598 ospf6_neighbor_state_change(
599 OSPF6_NEIGHBOR_DOWN, on,
600 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
601 thread_add_event(master, neighbor_change, on->ospf6_if, 0,
602 NULL);
603
604 listnode_delete(on->ospf6_if->neighbor_list, on);
605 ospf6_neighbor_delete(on);
606
607 } else {
608 if (IS_DEBUG_OSPF6_GR)
609 zlog_debug(
610 "%s, Acting as HELPER for this neighbour, So restart the dead timer.",
611 __PRETTY_FUNCTION__);
612
613 thread_add_timer(master, inactivity_timer, on,
614 on->ospf6_if->dead_interval,
615 &on->inactivity_timer);
616 }
617 }
618
619
620 /* vty functions */
621 /* show neighbor structure */
622 static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on,
623 json_object *json_array, bool use_json)
624 {
625 char router_id[16];
626 char duration[64];
627 struct timeval res;
628 char nstate[16];
629 char deadtime[64];
630 long h, m, s;
631 json_object *json_route;
632
633 /* Router-ID (Name) */
634 inet_ntop(AF_INET, &on->router_id, router_id, sizeof(router_id));
635 #ifdef HAVE_GETNAMEINFO
636 {
637 }
638 #endif /*HAVE_GETNAMEINFO*/
639
640 /* Dead time */
641 h = m = s = 0;
642 if (on->inactivity_timer) {
643 s = monotime_until(&on->inactivity_timer->u.sands, NULL)
644 / 1000000LL;
645 h = s / 3600;
646 s -= h * 3600;
647 m = s / 60;
648 s -= m * 60;
649 }
650 snprintf(deadtime, sizeof(deadtime), "%02ld:%02ld:%02ld", h, m, s);
651
652 /* Neighbor State */
653 if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT)
654 snprintf(nstate, sizeof(nstate), "PointToPoint");
655 else {
656 if (on->router_id == on->drouter)
657 snprintf(nstate, sizeof(nstate), "DR");
658 else if (on->router_id == on->bdrouter)
659 snprintf(nstate, sizeof(nstate), "BDR");
660 else
661 snprintf(nstate, sizeof(nstate), "DROther");
662 }
663
664 /* Duration */
665 monotime_since(&on->last_changed, &res);
666 timerstring(&res, duration, sizeof(duration));
667
668 /*
669 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
670 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
671 "Duration", "I/F", "State");
672 */
673 if (use_json) {
674 json_route = json_object_new_object();
675
676 json_object_string_add(json_route, "neighborId", router_id);
677 json_object_int_add(json_route, "priority", on->priority);
678 json_object_string_add(json_route, "deadTime", deadtime);
679 json_object_string_add(json_route, "state",
680 ospf6_neighbor_state_str[on->state]);
681 json_object_string_add(json_route, "ifState", nstate);
682 json_object_string_add(json_route, "duration", duration);
683 json_object_string_add(json_route, "interfaceName",
684 on->ospf6_if->interface->name);
685 json_object_string_add(
686 json_route, "interfaceState",
687 ospf6_interface_state_str[on->ospf6_if->state]);
688
689 json_object_array_add(json_array, json_route);
690 } else
691 vty_out(vty, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n",
692 router_id, on->priority, deadtime,
693 ospf6_neighbor_state_str[on->state], nstate, duration,
694 on->ospf6_if->interface->name,
695 ospf6_interface_state_str[on->ospf6_if->state]);
696 }
697
698 static void ospf6_neighbor_show_drchoice(struct vty *vty,
699 struct ospf6_neighbor *on,
700 json_object *json_array, bool use_json)
701 {
702 char router_id[16];
703 char drouter[16], bdrouter[16];
704 char duration[64];
705 struct timeval now, res;
706 json_object *json_route;
707
708 /*
709 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
710 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
711 "State");
712 */
713
714 inet_ntop(AF_INET, &on->router_id, router_id, sizeof(router_id));
715 inet_ntop(AF_INET, &on->drouter, drouter, sizeof(drouter));
716 inet_ntop(AF_INET, &on->bdrouter, bdrouter, sizeof(bdrouter));
717
718 monotime(&now);
719 timersub(&now, &on->last_changed, &res);
720 timerstring(&res, duration, sizeof(duration));
721
722 if (use_json) {
723 json_route = json_object_new_object();
724 json_object_string_add(json_route, "routerId", router_id);
725 json_object_string_add(json_route, "state",
726 ospf6_neighbor_state_str[on->state]);
727 json_object_string_add(json_route, "duration", duration);
728 json_object_string_add(json_route, "dRouter", drouter);
729 json_object_string_add(json_route, "bdRouter", bdrouter);
730 json_object_string_add(json_route, "interfaceName",
731 on->ospf6_if->interface->name);
732 json_object_string_add(
733 json_route, "interfaceState",
734 ospf6_interface_state_str[on->ospf6_if->state]);
735
736 json_object_array_add(json_array, json_route);
737 } else
738 vty_out(vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id,
739 ospf6_neighbor_state_str[on->state], duration, drouter,
740 bdrouter, on->ospf6_if->interface->name,
741 ospf6_interface_state_str[on->ospf6_if->state]);
742 }
743
744 static void ospf6_neighbor_show_detail(struct vty *vty,
745 struct ospf6_neighbor *on,
746 json_object *json, bool use_json)
747 {
748 char drouter[16], bdrouter[16];
749 char linklocal_addr[64], duration[32];
750 struct timeval now, res;
751 struct ospf6_lsa *lsa, *lsanext;
752 json_object *json_neighbor;
753 json_object *json_array;
754 char db_desc_str[20];
755
756 inet_ntop(AF_INET6, &on->linklocal_addr, linklocal_addr,
757 sizeof(linklocal_addr));
758 inet_ntop(AF_INET, &on->drouter, drouter, sizeof(drouter));
759 inet_ntop(AF_INET, &on->bdrouter, bdrouter, sizeof(bdrouter));
760
761 monotime(&now);
762 timersub(&now, &on->last_changed, &res);
763 timerstring(&res, duration, sizeof(duration));
764
765 if (use_json) {
766 json_neighbor = json_object_new_object();
767 json_object_string_add(json_neighbor, "area",
768 on->ospf6_if->area->name);
769 json_object_string_add(json_neighbor, "interface",
770 on->ospf6_if->interface->name);
771 json_object_int_add(json_neighbor, "interfaceIndex",
772 on->ospf6_if->interface->ifindex);
773 json_object_int_add(json_neighbor, "neighborInterfaceIndex",
774 on->ifindex);
775 json_object_string_add(json_neighbor, "linkLocalAddress",
776 linklocal_addr);
777 json_object_string_add(json_neighbor, "neighborState",
778 ospf6_neighbor_state_str[on->state]);
779 json_object_string_add(json_neighbor, "neighborStateDuration",
780 duration);
781 json_object_string_add(json_neighbor, "neighborDRouter",
782 drouter);
783 json_object_string_add(json_neighbor, "neighborBdRouter",
784 bdrouter);
785 snprintf(db_desc_str, sizeof(db_desc_str), "%s%s%s",
786 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT)
787 ? "Initial "
788 : ""),
789 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT)
790 ? "More"
791 : ""),
792 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT)
793 ? "Master"
794 : "Slave"));
795 json_object_string_add(json_neighbor, "dbDescStatus",
796 db_desc_str);
797
798 json_object_int_add(json_neighbor, "dbDescSeqNumber",
799 (unsigned long)ntohl(on->dbdesc_seqnum));
800
801 json_array = json_object_new_array();
802 json_object_int_add(json_neighbor, "summaryListCount",
803 on->summary_list->count);
804 for (ALL_LSDB(on->summary_list, lsa, lsanext))
805 json_object_array_add(
806 json_array, json_object_new_string(lsa->name));
807 json_object_object_add(json_neighbor, "summaryListLsa",
808 json_array);
809
810 json_array = json_object_new_array();
811 json_object_int_add(json_neighbor, "requestListCount",
812 on->request_list->count);
813 for (ALL_LSDB(on->request_list, lsa, lsanext))
814 json_object_array_add(
815 json_array, json_object_new_string(lsa->name));
816 json_object_object_add(json_neighbor, "requestListLsa",
817 json_array);
818
819 json_array = json_object_new_array();
820 json_object_int_add(json_neighbor, "reTransListCount",
821 on->retrans_list->count);
822 for (ALL_LSDB(on->retrans_list, lsa, lsanext))
823 json_object_array_add(
824 json_array, json_object_new_string(lsa->name));
825 json_object_object_add(json_neighbor, "reTransListLsa",
826 json_array);
827
828
829 timerclear(&res);
830 if (thread_is_scheduled(on->thread_send_dbdesc))
831 timersub(&on->thread_send_dbdesc->u.sands, &now, &res);
832 timerstring(&res, duration, sizeof(duration));
833 json_object_int_add(json_neighbor, "pendingLsaDbDescCount",
834 on->dbdesc_list->count);
835 json_object_string_add(json_neighbor, "pendingLsaDbDescTime",
836 duration);
837 json_object_string_add(
838 json_neighbor, "dbDescSendThread",
839 (thread_is_scheduled(on->thread_send_dbdesc) ? "on"
840 : "off"));
841 json_array = json_object_new_array();
842 for (ALL_LSDB(on->dbdesc_list, lsa, lsanext))
843 json_object_array_add(
844 json_array, json_object_new_string(lsa->name));
845 json_object_object_add(json_neighbor, "pendingLsaDbDesc",
846 json_array);
847
848 timerclear(&res);
849 if (thread_is_scheduled(on->thread_send_lsreq))
850 timersub(&on->thread_send_lsreq->u.sands, &now, &res);
851 timerstring(&res, duration, sizeof(duration));
852 json_object_int_add(json_neighbor, "pendingLsaLsReqCount",
853 on->request_list->count);
854 json_object_string_add(json_neighbor, "pendingLsaLsReqTime",
855 duration);
856 json_object_string_add(
857 json_neighbor, "lsReqSendThread",
858 (thread_is_scheduled(on->thread_send_lsreq) ? "on"
859 : "off"));
860 json_array = json_object_new_array();
861 for (ALL_LSDB(on->request_list, lsa, lsanext))
862 json_object_array_add(
863 json_array, json_object_new_string(lsa->name));
864 json_object_object_add(json_neighbor, "pendingLsaLsReq",
865 json_array);
866
867
868 timerclear(&res);
869 if (thread_is_scheduled(on->thread_send_lsupdate))
870 timersub(&on->thread_send_lsupdate->u.sands, &now,
871 &res);
872 timerstring(&res, duration, sizeof(duration));
873 json_object_int_add(json_neighbor, "pendingLsaLsUpdateCount",
874 on->lsupdate_list->count);
875 json_object_string_add(json_neighbor, "pendingLsaLsUpdateTime",
876 duration);
877 json_object_string_add(
878 json_neighbor, "lsUpdateSendThread",
879 (thread_is_scheduled(on->thread_send_lsupdate)
880 ? "on"
881 : "off"));
882 json_array = json_object_new_array();
883 for (ALL_LSDB(on->lsupdate_list, lsa, lsanext))
884 json_object_array_add(
885 json_array, json_object_new_string(lsa->name));
886 json_object_object_add(json_neighbor, "pendingLsaLsUpdate",
887 json_array);
888
889 timerclear(&res);
890 if (thread_is_scheduled(on->thread_send_lsack))
891 timersub(&on->thread_send_lsack->u.sands, &now, &res);
892 timerstring(&res, duration, sizeof(duration));
893 json_object_int_add(json_neighbor, "pendingLsaLsAckCount",
894 on->lsack_list->count);
895 json_object_string_add(json_neighbor, "pendingLsaLsAckTime",
896 duration);
897 json_object_string_add(
898 json_neighbor, "lsAckSendThread",
899 (thread_is_scheduled(on->thread_send_lsack) ? "on"
900 : "off"));
901 json_array = json_object_new_array();
902 for (ALL_LSDB(on->lsack_list, lsa, lsanext))
903 json_object_array_add(
904 json_array, json_object_new_string(lsa->name));
905 json_object_object_add(json_neighbor, "pendingLsaLsAck",
906 json_array);
907
908 bfd_sess_show(vty, json_neighbor, on->bfd_session);
909
910 if (on->auth_present == true) {
911 json_object_string_add(json_neighbor, "authStatus",
912 "enabled");
913 json_object_int_add(
914 json_neighbor, "recvdHelloHigherSeqNo",
915 on->seqnum_h[OSPF6_MESSAGE_TYPE_HELLO]);
916 json_object_int_add(
917 json_neighbor, "recvdHelloLowerSeqNo",
918 on->seqnum_l[OSPF6_MESSAGE_TYPE_HELLO]);
919 json_object_int_add(
920 json_neighbor, "recvdDBDescHigherSeqNo",
921 on->seqnum_h[OSPF6_MESSAGE_TYPE_DBDESC]);
922 json_object_int_add(
923 json_neighbor, "recvdDBDescLowerSeqNo",
924 on->seqnum_l[OSPF6_MESSAGE_TYPE_DBDESC]);
925 json_object_int_add(
926 json_neighbor, "recvdLSReqHigherSeqNo",
927 on->seqnum_h[OSPF6_MESSAGE_TYPE_LSREQ]);
928 json_object_int_add(
929 json_neighbor, "recvdLSReqLowerSeqNo",
930 on->seqnum_l[OSPF6_MESSAGE_TYPE_LSREQ]);
931 json_object_int_add(
932 json_neighbor, "recvdLSUpdHigherSeqNo",
933 on->seqnum_h[OSPF6_MESSAGE_TYPE_LSUPDATE]);
934 json_object_int_add(
935 json_neighbor, "recvdLSUpdLowerSeqNo",
936 on->seqnum_l[OSPF6_MESSAGE_TYPE_LSUPDATE]);
937 json_object_int_add(
938 json_neighbor, "recvdLSAckHigherSeqNo",
939 on->seqnum_h[OSPF6_MESSAGE_TYPE_LSACK]);
940 json_object_int_add(
941 json_neighbor, "recvdLSAckLowerSeqNo",
942 on->seqnum_l[OSPF6_MESSAGE_TYPE_LSACK]);
943 } else
944 json_object_string_add(json_neighbor, "authStatus",
945 "disabled");
946
947 json_object_object_add(json, on->name, json_neighbor);
948
949 } else {
950 vty_out(vty, " Neighbor %s\n", on->name);
951 vty_out(vty, " Area %s via interface %s (ifindex %d)\n",
952 on->ospf6_if->area->name, on->ospf6_if->interface->name,
953 on->ospf6_if->interface->ifindex);
954 vty_out(vty, " His IfIndex: %d Link-local address: %s\n",
955 on->ifindex, linklocal_addr);
956 vty_out(vty, " State %s for a duration of %s\n",
957 ospf6_neighbor_state_str[on->state], duration);
958 vty_out(vty, " His choice of DR/BDR %s/%s, Priority %d\n",
959 drouter, bdrouter, on->priority);
960 vty_out(vty, " DbDesc status: %s%s%s SeqNum: %#lx\n",
961 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT)
962 ? "Initial "
963 : ""),
964 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT)
965 ? "More "
966 : ""),
967 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT)
968 ? "Master"
969 : "Slave"),
970 (unsigned long)ntohl(on->dbdesc_seqnum));
971
972 vty_out(vty, " Summary-List: %d LSAs\n",
973 on->summary_list->count);
974 for (ALL_LSDB(on->summary_list, lsa, lsanext))
975 vty_out(vty, " %s\n", lsa->name);
976
977 vty_out(vty, " Request-List: %d LSAs\n",
978 on->request_list->count);
979 for (ALL_LSDB(on->request_list, lsa, lsanext))
980 vty_out(vty, " %s\n", lsa->name);
981
982 vty_out(vty, " Retrans-List: %d LSAs\n",
983 on->retrans_list->count);
984 for (ALL_LSDB(on->retrans_list, lsa, lsanext))
985 vty_out(vty, " %s\n", lsa->name);
986
987 timerclear(&res);
988 if (thread_is_scheduled(on->thread_send_dbdesc))
989 timersub(&on->thread_send_dbdesc->u.sands, &now, &res);
990 timerstring(&res, duration, sizeof(duration));
991 vty_out(vty,
992 " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
993 on->dbdesc_list->count, duration,
994 (thread_is_scheduled(on->thread_send_dbdesc) ? "on"
995 : "off"));
996 for (ALL_LSDB(on->dbdesc_list, lsa, lsanext))
997 vty_out(vty, " %s\n", lsa->name);
998
999 timerclear(&res);
1000 if (thread_is_scheduled(on->thread_send_lsreq))
1001 timersub(&on->thread_send_lsreq->u.sands, &now, &res);
1002 timerstring(&res, duration, sizeof(duration));
1003 vty_out(vty,
1004 " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
1005 on->request_list->count, duration,
1006 (thread_is_scheduled(on->thread_send_lsreq) ? "on"
1007 : "off"));
1008 for (ALL_LSDB(on->request_list, lsa, lsanext))
1009 vty_out(vty, " %s\n", lsa->name);
1010
1011 timerclear(&res);
1012 if (thread_is_scheduled(on->thread_send_lsupdate))
1013 timersub(&on->thread_send_lsupdate->u.sands, &now,
1014 &res);
1015 timerstring(&res, duration, sizeof(duration));
1016 vty_out(vty,
1017 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
1018 on->lsupdate_list->count, duration,
1019 (thread_is_scheduled(on->thread_send_lsupdate)
1020 ? "on"
1021 : "off"));
1022 for (ALL_LSDB(on->lsupdate_list, lsa, lsanext))
1023 vty_out(vty, " %s\n", lsa->name);
1024
1025 timerclear(&res);
1026 if (thread_is_scheduled(on->thread_send_lsack))
1027 timersub(&on->thread_send_lsack->u.sands, &now, &res);
1028 timerstring(&res, duration, sizeof(duration));
1029 vty_out(vty,
1030 " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
1031 on->lsack_list->count, duration,
1032 (thread_is_scheduled(on->thread_send_lsack) ? "on"
1033 : "off"));
1034 for (ALL_LSDB(on->lsack_list, lsa, lsanext))
1035 vty_out(vty, " %s\n", lsa->name);
1036
1037 bfd_sess_show(vty, NULL, on->bfd_session);
1038
1039 if (on->auth_present == true) {
1040 vty_out(vty, " Authentication header present\n");
1041 vty_out(vty,
1042 "\t\t\t hello DBDesc LSReq LSUpd LSAck\n");
1043 vty_out(vty,
1044 " Higher sequence no 0x%-10X 0x%-10X 0x%-10X 0x%-10X 0x%-10X\n",
1045 on->seqnum_h[OSPF6_MESSAGE_TYPE_HELLO],
1046 on->seqnum_h[OSPF6_MESSAGE_TYPE_DBDESC],
1047 on->seqnum_h[OSPF6_MESSAGE_TYPE_LSREQ],
1048 on->seqnum_h[OSPF6_MESSAGE_TYPE_LSUPDATE],
1049 on->seqnum_h[OSPF6_MESSAGE_TYPE_LSACK]);
1050 vty_out(vty,
1051 " Lower sequence no 0x%-10X 0x%-10X 0x%-10X 0x%-10X 0x%-10X\n",
1052 on->seqnum_l[OSPF6_MESSAGE_TYPE_HELLO],
1053 on->seqnum_l[OSPF6_MESSAGE_TYPE_DBDESC],
1054 on->seqnum_l[OSPF6_MESSAGE_TYPE_LSREQ],
1055 on->seqnum_l[OSPF6_MESSAGE_TYPE_LSUPDATE],
1056 on->seqnum_l[OSPF6_MESSAGE_TYPE_LSACK]);
1057 } else
1058 vty_out(vty, " Authentication header not present\n");
1059 }
1060 }
1061
1062 static void ospf6_neighbor_show_detail_common(struct vty *vty,
1063 struct ospf6 *ospf6, bool uj,
1064 bool detail, bool drchoice)
1065 {
1066 struct ospf6_neighbor *on;
1067 struct ospf6_interface *oi;
1068 struct ospf6_area *oa;
1069 struct listnode *i, *j, *k;
1070 json_object *json = NULL;
1071 json_object *json_array = NULL;
1072 void (*showfunc)(struct vty *, struct ospf6_neighbor *,
1073 json_object *json, bool use_json);
1074
1075 if (detail)
1076 showfunc = ospf6_neighbor_show_detail;
1077 else if (drchoice)
1078 showfunc = ospf6_neighbor_show_drchoice;
1079 else
1080 showfunc = ospf6_neighbor_show;
1081
1082 if (uj) {
1083 json = json_object_new_object();
1084 json_array = json_object_new_array();
1085 } else {
1086 if (showfunc == ospf6_neighbor_show)
1087 vty_out(vty, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
1088 "Neighbor ID", "Pri", "DeadTime", "State",
1089 "IfState", "Duration", "I/F", "State");
1090 else if (showfunc == ospf6_neighbor_show_drchoice)
1091 vty_out(vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n",
1092 "RouterID", "State", "Duration", "DR", "BDR",
1093 "I/F", "State");
1094 }
1095
1096 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa))
1097 for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi))
1098 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, k, on)) {
1099 if (showfunc == ospf6_neighbor_show_detail)
1100 (*showfunc)(vty, on, json, uj);
1101 else
1102 (*showfunc)(vty, on, json_array, uj);
1103 }
1104
1105 if (uj) {
1106 if (showfunc != ospf6_neighbor_show_detail)
1107 json_object_object_add(json, "neighbors", json_array);
1108 else
1109 json_object_free(json_array);
1110 vty_json(vty, json);
1111 }
1112 }
1113
1114 DEFUN(show_ipv6_ospf6_neighbor, show_ipv6_ospf6_neighbor_cmd,
1115 "show ipv6 ospf6 [vrf <NAME|all>] neighbor [<detail|drchoice>] [json]",
1116 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1117 "All VRFs\n"
1118 "Neighbor list\n"
1119 "Display details\n"
1120 "Display DR choices\n" JSON_STR)
1121 {
1122 struct ospf6 *ospf6;
1123 struct listnode *node;
1124 const char *vrf_name = NULL;
1125 bool all_vrf = false;
1126 int idx_vrf = 0;
1127 int idx_type = 4;
1128 bool uj = use_json(argc, argv);
1129 bool detail = false;
1130 bool drchoice = false;
1131
1132 OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1133
1134 if (argv_find(argv, argc, "detail", &idx_type))
1135 detail = true;
1136 else if (argv_find(argv, argc, "drchoice", &idx_type))
1137 drchoice = true;
1138
1139 for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) {
1140 if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) {
1141 ospf6_neighbor_show_detail_common(vty, ospf6, uj,
1142 detail, drchoice);
1143 if (!all_vrf)
1144 break;
1145 }
1146 }
1147
1148 OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
1149
1150 return CMD_SUCCESS;
1151 }
1152
1153 static int ospf6_neighbor_show_common(struct vty *vty, int argc,
1154 struct cmd_token **argv,
1155 struct ospf6 *ospf6, int idx_ipv4,
1156 bool uj)
1157 {
1158 struct ospf6_neighbor *on;
1159 struct ospf6_interface *oi;
1160 struct ospf6_area *oa;
1161 struct listnode *i, *j, *k;
1162 void (*showfunc)(struct vty *, struct ospf6_neighbor *,
1163 json_object *json, bool use_json);
1164 uint32_t router_id;
1165 json_object *json = NULL;
1166
1167 showfunc = ospf6_neighbor_show_detail;
1168 if (uj)
1169 json = json_object_new_object();
1170
1171 if ((inet_pton(AF_INET, argv[idx_ipv4]->arg, &router_id)) != 1) {
1172 vty_out(vty, "Router-ID is not parsable: %s\n",
1173 argv[idx_ipv4]->arg);
1174 return CMD_SUCCESS;
1175 }
1176
1177 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa))
1178 for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi))
1179 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, k, on)) {
1180 if (router_id == on->router_id)
1181 (*showfunc)(vty, on, json, uj);
1182 }
1183
1184 if (uj)
1185 vty_json(vty, json);
1186
1187 return CMD_SUCCESS;
1188 }
1189
1190 DEFUN(show_ipv6_ospf6_neighbor_one, show_ipv6_ospf6_neighbor_one_cmd,
1191 "show ipv6 ospf6 [vrf <NAME|all>] neighbor A.B.C.D [json]",
1192 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1193 "All VRFs\n"
1194 "Neighbor list\n"
1195 "Specify Router-ID as IPv4 address notation\n" JSON_STR)
1196 {
1197 int idx_ipv4 = 4;
1198 struct ospf6 *ospf6;
1199 struct listnode *node;
1200 const char *vrf_name = NULL;
1201 bool all_vrf = false;
1202 int idx_vrf = 0;
1203 bool uj = use_json(argc, argv);
1204
1205 OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1206 if (idx_vrf > 0)
1207 idx_ipv4 += 2;
1208
1209 for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) {
1210 if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) {
1211 ospf6_neighbor_show_common(vty, argc, argv, ospf6,
1212 idx_ipv4, uj);
1213
1214 if (!all_vrf)
1215 break;
1216 }
1217 }
1218
1219 OSPF6_CMD_CHECK_VRF(uj, all_vrf, ospf6);
1220
1221 return CMD_SUCCESS;
1222 }
1223
1224 void ospf6_neighbor_init(void)
1225 {
1226 install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
1227 install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_one_cmd);
1228 }
1229
1230 DEFUN (debug_ospf6_neighbor,
1231 debug_ospf6_neighbor_cmd,
1232 "debug ospf6 neighbor [<state|event>]",
1233 DEBUG_STR
1234 OSPF6_STR
1235 "Debug OSPFv3 Neighbor\n"
1236 "Debug OSPFv3 Neighbor State Change\n"
1237 "Debug OSPFv3 Neighbor Event\n")
1238 {
1239 int idx_type = 3;
1240 unsigned char level = 0;
1241
1242 if (argc == 4) {
1243 if (!strncmp(argv[idx_type]->arg, "s", 1))
1244 level = OSPF6_DEBUG_NEIGHBOR_STATE;
1245 else if (!strncmp(argv[idx_type]->arg, "e", 1))
1246 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
1247 } else
1248 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
1249
1250 OSPF6_DEBUG_NEIGHBOR_ON(level);
1251 return CMD_SUCCESS;
1252 }
1253
1254
1255 DEFUN (no_debug_ospf6_neighbor,
1256 no_debug_ospf6_neighbor_cmd,
1257 "no debug ospf6 neighbor [<state|event>]",
1258 NO_STR
1259 DEBUG_STR
1260 OSPF6_STR
1261 "Debug OSPFv3 Neighbor\n"
1262 "Debug OSPFv3 Neighbor State Change\n"
1263 "Debug OSPFv3 Neighbor Event\n")
1264 {
1265 int idx_type = 4;
1266 unsigned char level = 0;
1267
1268 if (argc == 5) {
1269 if (!strncmp(argv[idx_type]->arg, "s", 1))
1270 level = OSPF6_DEBUG_NEIGHBOR_STATE;
1271 if (!strncmp(argv[idx_type]->arg, "e", 1))
1272 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
1273 } else
1274 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
1275
1276 OSPF6_DEBUG_NEIGHBOR_OFF(level);
1277 return CMD_SUCCESS;
1278 }
1279
1280
1281 DEFUN (no_debug_ospf6,
1282 no_debug_ospf6_cmd,
1283 "no debug ospf6",
1284 NO_STR
1285 DEBUG_STR
1286 OSPF6_STR)
1287 {
1288 unsigned int i;
1289
1290 OSPF6_DEBUG_ABR_OFF();
1291 OSPF6_DEBUG_ASBR_OFF();
1292 OSPF6_DEBUG_BROUTER_OFF();
1293 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
1294 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
1295 OSPF6_DEBUG_FLOODING_OFF();
1296 OSPF6_DEBUG_INTERFACE_OFF();
1297
1298 ospf6_lsa_debug_set_all(false);
1299
1300 for (i = 0; i < 6; i++)
1301 OSPF6_DEBUG_MESSAGE_OFF(i,
1302 OSPF6_DEBUG_NEIGHBOR_STATE
1303 | OSPF6_DEBUG_NEIGHBOR_EVENT);
1304
1305 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
1306 | OSPF6_DEBUG_NEIGHBOR_EVENT);
1307 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE);
1308 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA);
1309 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER);
1310 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY);
1311 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS);
1312 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME);
1313 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE);
1314 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV);
1315
1316 return CMD_SUCCESS;
1317 }
1318
1319 int config_write_ospf6_debug_neighbor(struct vty *vty)
1320 {
1321 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
1322 vty_out(vty, "debug ospf6 neighbor\n");
1323 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE))
1324 vty_out(vty, "debug ospf6 neighbor state\n");
1325 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
1326 vty_out(vty, "debug ospf6 neighbor event\n");
1327 return 0;
1328 }
1329
1330 void install_element_ospf6_debug_neighbor(void)
1331 {
1332 install_element(ENABLE_NODE, &debug_ospf6_neighbor_cmd);
1333 install_element(ENABLE_NODE, &no_debug_ospf6_neighbor_cmd);
1334 install_element(ENABLE_NODE, &no_debug_ospf6_cmd);
1335 install_element(CONFIG_NODE, &debug_ospf6_neighbor_cmd);
1336 install_element(CONFIG_NODE, &no_debug_ospf6_neighbor_cmd);
1337 install_element(CONFIG_NODE, &no_debug_ospf6_cmd);
1338 }