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