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