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